bool RenderTheme::paintBorderOnly(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r) { if (paintInfo.context->paintingDisabled()) return false; #if PLATFORM(IOS) UNUSED_PARAM(r); return o->style().appearance() != NoControlPart; #else // Call the appropriate paint method based off the appearance value. switch (o->style().appearance()) { case TextFieldPart: return paintTextField(o, paintInfo, r); case ListboxPart: case TextAreaPart: return paintTextArea(o, paintInfo, r); case MenulistButtonPart: case SearchFieldPart: return true; case CheckboxPart: case RadioPart: case PushButtonPart: case SquareButtonPart: case DefaultButtonPart: case ButtonPart: case MenulistPart: #if ENABLE(METER_ELEMENT) case MeterPart: case RelevancyLevelIndicatorPart: case ContinuousCapacityLevelIndicatorPart: case DiscreteCapacityLevelIndicatorPart: case RatingLevelIndicatorPart: #endif #if ENABLE(PROGRESS_ELEMENT) case ProgressBarPart: #endif case SliderHorizontalPart: case SliderVerticalPart: case SliderThumbHorizontalPart: case SliderThumbVerticalPart: case SearchFieldCancelButtonPart: case SearchFieldDecorationPart: case SearchFieldResultsDecorationPart: case SearchFieldResultsButtonPart: #if ENABLE(INPUT_SPEECH) case InputSpeechButtonPart: #endif default: break; } return false; #endif }
bool RenderTheme::paintBorderOnly(const RenderBox& box, const PaintInfo& paintInfo, const LayoutRect& rect) { if (paintInfo.context().paintingDisabled()) return false; #if PLATFORM(IOS) UNUSED_PARAM(rect); return box.style().appearance() != NoControlPart; #else FloatRect devicePixelSnappedRect = snapRectToDevicePixels(rect, box.document().deviceScaleFactor()); // Call the appropriate paint method based off the appearance value. switch (box.style().appearance()) { case TextFieldPart: return paintTextField(box, paintInfo, devicePixelSnappedRect); case ListboxPart: case TextAreaPart: return paintTextArea(box, paintInfo, devicePixelSnappedRect); case MenulistButtonPart: case SearchFieldPart: return true; case CheckboxPart: case RadioPart: case PushButtonPart: case SquareButtonPart: case DefaultButtonPart: case ButtonPart: case MenulistPart: #if ENABLE(METER_ELEMENT) case MeterPart: case RelevancyLevelIndicatorPart: case ContinuousCapacityLevelIndicatorPart: case DiscreteCapacityLevelIndicatorPart: case RatingLevelIndicatorPart: #endif case ProgressBarPart: case SliderHorizontalPart: case SliderVerticalPart: case SliderThumbHorizontalPart: case SliderThumbVerticalPart: case SearchFieldCancelButtonPart: case SearchFieldDecorationPart: case SearchFieldResultsDecorationPart: case SearchFieldResultsButtonPart: #if ENABLE(SERVICE_CONTROLS) case ImageControlsButtonPart: #endif default: break; } return false; #endif }
void WMSetTextFieldFont(WMTextField * tPtr, WMFont * font) { CHECK_CLASS(tPtr, WC_TextField); if (tPtr->font) WMReleaseFont(tPtr->font); tPtr->font = WMRetainFont(font); tPtr->offsetWidth = WMAX((tPtr->view->size.height - WMFontHeight(tPtr->font)) / 2, 1); if (tPtr->view->flags.realized) { paintTextField(tPtr); } }
bool RenderThemeWin::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) { // FIXME: All these inflate() calls are bogus, causing painting problems, // as well as sizing wackiness in Classic mode IntRect editRect(r); paintTextField(o, i, editRect); const int buttonWidth = GetSystemMetrics(SM_CXVSCROLL); IntRect buttonRect(r.right() - buttonWidth - 1, r.y(), buttonWidth, r.height()); buttonRect.inflateY(-1); paintMenuListButton(o, i, buttonRect); return false; }
void WMSetTextFieldCursorPosition(WMTextField * tPtr, unsigned int position) { CHECK_CLASS(tPtr, WC_TextField); if (tPtr->flags.enabled) { if (position > tPtr->textLen) position = tPtr->textLen; tPtr->cursorPosition = position; if (tPtr->view->flags.realized) { paintTextField(tPtr); } } }
void WMSetTextFieldAlignment(WMTextField * tPtr, WMAlignment alignment) { CHECK_CLASS(tPtr, WC_TextField); tPtr->flags.alignment = alignment; if (alignment != WALeft) { wwarning("only left alignment is supported in textfields"); return; } if (tPtr->view->flags.realized) { paintTextField(tPtr); } }
static void lostSelection(WMView * view, Atom selection, void *cdata) { TextField *tPtr = (WMTextField *) view->self; /* Parameter not used, but tell the compiler that it is ok */ (void) cdata; if (tPtr->flags.ownsSelection) { WMDeleteSelectionHandler(view, selection, CurrentTime); tPtr->flags.ownsSelection = 0; } if (tPtr->selection.count != 0) { tPtr->selection.count = 0; paintTextField(tPtr); } }
void WMSelectTextFieldRange(WMTextField * tPtr, WMRange range) { CHECK_CLASS(tPtr, WC_TextField); if (tPtr->flags.enabled) { normalizeRange(tPtr, &range); tPtr->selection = range; tPtr->cursorPosition = range.position + range.count; if (tPtr->view->flags.realized) { paintTextField(tPtr); } } }
bool RenderTheme::paintBorderOnly(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) { if (paintInfo.context->paintingDisabled()) return false; // Call the appropriate paint method based off the appearance value. switch (o->style()->appearance()) { case TextFieldPart: return paintTextField(o, paintInfo, r); case ListboxPart: case TextAreaPart: return paintTextArea(o, paintInfo, r); case MenulistButtonPart: case SearchFieldPart: return true; case CheckboxPart: case RadioPart: case PushButtonPart: case SquareButtonPart: case ListButtonPart: case DefaultButtonPart: case ButtonPart: case MenulistPart: #if ENABLE(METER_TAG) case MeterPart: #endif #if ENABLE(PROGRESS_TAG) case ProgressBarPart: #endif case SliderHorizontalPart: case SliderVerticalPart: case SliderThumbHorizontalPart: case SliderThumbVerticalPart: case SearchFieldCancelButtonPart: case SearchFieldDecorationPart: case SearchFieldResultsDecorationPart: case SearchFieldResultsButtonPart: default: break; } return false; }
void WMInsertTextFieldText(WMTextField * tPtr, const char *text, int position) { int len; CHECK_CLASS(tPtr, WC_TextField); if (!text) return; len = strlen(text); /* check if buffer will hold the text */ if (len + tPtr->textLen >= tPtr->bufferSize) { tPtr->bufferSize = tPtr->textLen + len + TEXT_BUFFER_INCR; tPtr->text = wrealloc(tPtr->text, tPtr->bufferSize); } if (position < 0 || position >= tPtr->textLen) { /* append the text at the end */ wstrlcat(tPtr->text, text, tPtr->bufferSize); tPtr->textLen += len; tPtr->cursorPosition += len; incrToFit(tPtr); } else { /* insert text at position */ memmv(&(tPtr->text[position + len]), &(tPtr->text[position]), tPtr->textLen - position + 1); memcpy(&(tPtr->text[position]), text, len); tPtr->textLen += len; if (position >= tPtr->cursorPosition) { tPtr->cursorPosition += len; incrToFit2(tPtr); } else { incrToFit(tPtr); } } paintTextField(tPtr); }
void WMDeleteTextFieldRange(WMTextField * tPtr, WMRange range) { CHECK_CLASS(tPtr, WC_TextField); normalizeRange(tPtr, &range); if (!range.count) return; memmv(&(tPtr->text[range.position]), &(tPtr->text[range.position + range.count]), tPtr->textLen - (range.position + range.count) + 1); /* better than nothing ;) */ if (tPtr->cursorPosition > range.position) tPtr->viewPosition += oneUTF8CharBackward(&tPtr->text[tPtr->viewPosition], tPtr->viewPosition); tPtr->textLen -= range.count; tPtr->cursorPosition = range.position; decrToFit(tPtr); paintTextField(tPtr); }
bool RenderThemeWinCE::paintSearchField(RenderObject* o, const PaintInfo& i, const IntRect& r) { return paintTextField(o, i, r); }
bool RenderThemeWinCE::paintMenuList(RenderObject* o, const PaintInfo& i, const IntRect& r) { paintTextField(o, i, r); paintMenuListButton(o, i, r); return true; }
static void handleTextFieldActionEvents(XEvent * event, void *data) { TextField *tPtr = (TextField *) data; static Time lastButtonReleasedEvent = 0; static Time lastButtonReleasedEvent2 = 0; Display *dpy = event->xany.display; CHECK_CLASS(data, WC_TextField); switch (event->type) { case KeyPress: if (tPtr->flags.waitingSelection) { return; } if (tPtr->flags.enabled && tPtr->flags.focused) { handleTextFieldKeyPress(tPtr, event); XDefineCursor(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->screen->invisibleCursor); tPtr->flags.pointerGrabbed = 1; } break; case MotionNotify: if (tPtr->flags.pointerGrabbed) { tPtr->flags.pointerGrabbed = 0; XDefineCursor(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->screen->textCursor); } if (tPtr->flags.waitingSelection) { return; } if (tPtr->flags.enabled && (event->xmotion.state & Button1Mask)) { if (tPtr->viewPosition < tPtr->textLen && event->xmotion.x > tPtr->usableWidth) { if (WMWidthOfString(tPtr->font, &(tPtr->text[tPtr->viewPosition]), tPtr->cursorPosition - tPtr->viewPosition) > tPtr->usableWidth) { tPtr->viewPosition += oneUTF8CharForward(&tPtr->text[tPtr->viewPosition], tPtr->textLen - tPtr->viewPosition); } } else if (tPtr->viewPosition > 0 && event->xmotion.x < 0) { paintCursor(tPtr); tPtr->viewPosition += oneUTF8CharBackward(&tPtr->text[tPtr->viewPosition], tPtr->viewPosition); } tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x); /* Do not allow text selection in secure textfields */ if (tPtr->flags.secure) { tPtr->selection.position = tPtr->cursorPosition; } tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position; paintCursor(tPtr); paintTextField(tPtr); } break; case ButtonPress: if (tPtr->flags.pointerGrabbed) { tPtr->flags.pointerGrabbed = 0; XDefineCursor(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->screen->textCursor); break; } if (tPtr->flags.waitingSelection) { break; } switch (tPtr->flags.alignment) { int textWidth; case WARight: textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen); if (tPtr->flags.enabled && !tPtr->flags.focused) { WMSetFocusToWidget(tPtr); } if (tPtr->flags.focused) { tPtr->selection.position = tPtr->cursorPosition; tPtr->selection.count = 0; } if (textWidth < tPtr->usableWidth) { tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x - tPtr->usableWidth + textWidth); } else tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x); paintTextField(tPtr); break; case WALeft: if (tPtr->flags.enabled && !tPtr->flags.focused) { WMSetFocusToWidget(tPtr); } if (tPtr->flags.focused && event->xbutton.button == Button1) { tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x); tPtr->selection.position = tPtr->cursorPosition; tPtr->selection.count = 0; paintTextField(tPtr); } if (event->xbutton.button == Button2 && tPtr->flags.enabled) { char *text; int n; if (!WMRequestSelection(tPtr->view, XA_PRIMARY, XA_STRING, event->xbutton.time, pasteText, NULL)) { text = XFetchBuffer(tPtr->view->screen->display, &n, 0); if (text) { text[n] = 0; WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition); XFree(text); NOTIFY(tPtr, didChange, WMTextDidChangeNotification, (void *)WMInsertTextEvent); } } else { tPtr->flags.waitingSelection = 1; } } break; default: break; } break; case ButtonRelease: if (tPtr->flags.pointerGrabbed) { tPtr->flags.pointerGrabbed = 0; XDefineCursor(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->screen->textCursor); } if (tPtr->flags.waitingSelection) { break; } if (!tPtr->flags.secure && tPtr->selection.count != 0) { int start, count; XRotateBuffers(dpy, 1); count = abs(tPtr->selection.count); if (tPtr->selection.count < 0) start = tPtr->selection.position - count; else start = tPtr->selection.position; XStoreBuffer(dpy, &tPtr->text[start], count, 0); } if (!tPtr->flags.secure && event->xbutton.time - lastButtonReleasedEvent <= WINGsConfiguration.doubleClickDelay) { if (event->xbutton.time - lastButtonReleasedEvent2 <= 2 * WINGsConfiguration.doubleClickDelay) { tPtr->selection.position = 0; tPtr->selection.count = tPtr->textLen; } else { int pos, cnt; char *txt; pos = tPtr->selection.position; cnt = tPtr->selection.count; txt = tPtr->text; while (pos >= 0) { if (txt[pos] == ' ' || txt[pos] == '\t') break; pos--; } pos++; while (pos + cnt < tPtr->textLen) { if (txt[pos + cnt] == ' ' || txt[pos + cnt] == '\t') break; cnt++; } tPtr->selection.position = pos; tPtr->selection.count = cnt; } paintTextField(tPtr); if (!tPtr->flags.ownsSelection) { tPtr->flags.ownsSelection = WMCreateSelectionHandler(tPtr->view, XA_PRIMARY, event->xbutton.time, &selectionHandler, NULL); } } else if (!tPtr->flags.secure && tPtr->selection.count != 0 && !tPtr->flags.ownsSelection) { tPtr->flags.ownsSelection = WMCreateSelectionHandler(tPtr->view, XA_PRIMARY, event->xbutton.time, &selectionHandler, NULL); } lastButtonReleasedEvent2 = lastButtonReleasedEvent; lastButtonReleasedEvent = event->xbutton.time; break; } }
bool RenderThemeGtk::paintSearchField(const RenderObject& o, const PaintInfo& i, const IntRect& rect) { return paintTextField(o, i, rect); }
bool RenderThemeGtk::paintTextArea(const RenderObject& o, const PaintInfo& i, const FloatRect& r) { return paintTextField(o, i, r); }
bool ThemePainterDefault::paintSearchField(const LayoutObject& o, const PaintInfo& i, const IntRect& r) { return paintTextField(o, i, r); }
bool RenderThemeBal::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect) { return paintTextField(o, i, rect); }
bool RenderThemeChromiumSkia::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) { return paintTextField(o, i, r); }
static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event) { char buffer[64]; KeySym ksym; char *textEvent = NULL; void *data = NULL; int count, refresh = 0; int control_pressed = 0; int cancelSelection = 1; Bool shifted, controled, modified; Bool relay = True; /*printf("(%d,%d) -> ", tPtr->selection.position, tPtr->selection.count); */ if (((XKeyEvent *) event)->state & WM_EMACSKEYMASK) control_pressed = 1; shifted = (event->xkey.state & ShiftMask ? True : False); controled = (event->xkey.state & ControlMask ? True : False); modified = shifted || controled; count = W_LookupString(tPtr->view, &event->xkey, buffer, 63, &ksym, NULL); //count = XLookupString(&event->xkey, buffer, 63, &ksym, NULL); buffer[count] = '\0'; switch (ksym) { case XK_Tab: #ifdef XK_ISO_Left_Tab case XK_ISO_Left_Tab: #endif if (!controled) { if (shifted) { if (tPtr->view->prevFocusChain) { W_SetFocusOfTopLevel(W_TopLevelOfView(tPtr->view), tPtr->view->prevFocusChain); tPtr->flags.notIllegalMovement = 1; } data = (void *)WMBacktabTextMovement; } else { if (tPtr->view->nextFocusChain) { W_SetFocusOfTopLevel(W_TopLevelOfView(tPtr->view), tPtr->view->nextFocusChain); tPtr->flags.notIllegalMovement = 1; } data = (void *)WMTabTextMovement; } textEvent = WMTextDidEndEditingNotification; cancelSelection = 0; relay = False; } break; case XK_Escape: if (!modified) { data = (void *)WMEscapeTextMovement; textEvent = WMTextDidEndEditingNotification; relay = False; } break; case XK_Return: if (!modified) { data = (void *)WMReturnTextMovement; textEvent = WMTextDidEndEditingNotification; relay = False; } break; case WM_EMACSKEY_LEFT: if (!control_pressed) goto normal_key; else controled = False; #ifdef XK_KP_Left case XK_KP_Left: #endif case XK_Left: if (tPtr->cursorPosition > 0) { int i; paintCursor(tPtr); i = tPtr->cursorPosition; i += oneUTF8CharBackward(&tPtr->text[i], i); if (controled) { while (i > 0 && tPtr->text[i] != ' ') i--; while (i > 0 && tPtr->text[i] == ' ') i--; tPtr->cursorPosition = (i > 0) ? i + 1 : 0; } else tPtr->cursorPosition = i; if (tPtr->cursorPosition < tPtr->viewPosition) { tPtr->viewPosition = tPtr->cursorPosition; refresh = 1; } else paintCursor(tPtr); } if (shifted) cancelSelection = 0; relay = False; break; case WM_EMACSKEY_RIGHT: if (!control_pressed) goto normal_key; else controled = False; #ifdef XK_KP_Right case XK_KP_Right: #endif case XK_Right: if (tPtr->cursorPosition < tPtr->textLen) { int i; paintCursor(tPtr); i = tPtr->cursorPosition; if (controled) { while (tPtr->text[i] && tPtr->text[i] != ' ') i++; while (tPtr->text[i] == ' ') i++; } else { i += oneUTF8CharForward(&tPtr->text[i], tPtr->textLen - i); } tPtr->cursorPosition = i; refresh = incrToFit2(tPtr); if (!refresh) paintCursor(tPtr); } if (shifted) cancelSelection = 0; relay = False; break; case WM_EMACSKEY_HOME: if (!control_pressed) goto normal_key; else controled = False; #ifdef XK_KP_Home case XK_KP_Home: #endif case XK_Home: if (!controled) { if (tPtr->cursorPosition > 0) { paintCursor(tPtr); tPtr->cursorPosition = 0; if (tPtr->viewPosition > 0) { tPtr->viewPosition = 0; refresh = 1; } else paintCursor(tPtr); } if (shifted) cancelSelection = 0; relay = False; } break; case WM_EMACSKEY_END: if (!control_pressed) goto normal_key; else controled = False; #ifdef XK_KP_End case XK_KP_End: #endif case XK_End: if (!controled) { if (tPtr->cursorPosition < tPtr->textLen) { paintCursor(tPtr); tPtr->cursorPosition = tPtr->textLen; tPtr->viewPosition = 0; refresh = incrToFit(tPtr); if (!refresh) paintCursor(tPtr); } if (shifted) cancelSelection = 0; relay = False; } break; case WM_EMACSKEY_BS: if (!control_pressed) goto normal_key; else modified = False; case XK_BackSpace: if (!modified) { if (tPtr->selection.count) { WMDeleteTextFieldRange(tPtr, tPtr->selection); data = (void *)WMDeleteTextEvent; textEvent = WMTextDidChangeNotification; } else if (tPtr->cursorPosition > 0) { int i = oneUTF8CharBackward(&tPtr->text[tPtr->cursorPosition], tPtr->cursorPosition); WMRange range; range.position = tPtr->cursorPosition + i; range.count = -i; WMDeleteTextFieldRange(tPtr, range); data = (void *)WMDeleteTextEvent; textEvent = WMTextDidChangeNotification; } relay = False; } break; case WM_EMACSKEY_DEL: if (!control_pressed) goto normal_key; else modified = False; #ifdef XK_KP_Delete case XK_KP_Delete: #endif case XK_Delete: if (!modified) { if (tPtr->selection.count) { WMDeleteTextFieldRange(tPtr, tPtr->selection); data = (void *)WMDeleteTextEvent; textEvent = WMTextDidChangeNotification; } else if (tPtr->cursorPosition < tPtr->textLen) { WMRange range; range.position = tPtr->cursorPosition; range.count = oneUTF8CharForward(&tPtr->text[tPtr->cursorPosition], tPtr->textLen - tPtr->cursorPosition); WMDeleteTextFieldRange(tPtr, range); data = (void *)WMDeleteTextEvent; textEvent = WMTextDidChangeNotification; } relay = False; } break; normal_key: default: if (!controled) { if (count > 0 && !iscntrl(buffer[0])) { if (tPtr->selection.count) WMDeleteTextFieldRange(tPtr, tPtr->selection); WMInsertTextFieldText(tPtr, buffer, tPtr->cursorPosition); data = (void *)WMInsertTextEvent; textEvent = WMTextDidChangeNotification; relay = False; } } break; } if (relay) { WMRelayToNextResponder(W_VIEW(tPtr), event); return; } /* Do not allow text selection in secure text fields */ if (cancelSelection || tPtr->flags.secure) { lostSelection(tPtr->view, XA_PRIMARY, NULL); if (tPtr->selection.count) { tPtr->selection.count = 0; refresh = 1; } tPtr->selection.position = tPtr->cursorPosition; } else { if (tPtr->selection.count != tPtr->cursorPosition - tPtr->selection.position) { tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position; refresh = 1; } } /*printf("(%d,%d)\n", tPtr->selection.position, tPtr->selection.count); */ if (textEvent) { WMNotification *notif = WMCreateNotification(textEvent, tPtr, data); if (tPtr->delegate) { if (textEvent == WMTextDidBeginEditingNotification && tPtr->delegate->didBeginEditing) (*tPtr->delegate->didBeginEditing) (tPtr->delegate, notif); else if (textEvent == WMTextDidEndEditingNotification && tPtr->delegate->didEndEditing) (*tPtr->delegate->didEndEditing) (tPtr->delegate, notif); else if (textEvent == WMTextDidChangeNotification && tPtr->delegate->didChange) (*tPtr->delegate->didChange) (tPtr->delegate, notif); } WMPostNotification(notif); WMReleaseNotification(notif); } if (refresh) paintTextField(tPtr); /*printf("(%d,%d)\n", tPtr->selection.position, tPtr->selection.count); */ }
bool RenderThemeBal::paintTextArea(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) { return paintTextField(o, i, r); }
bool RenderThemeNix::paintTextArea(RenderObject* o, const PaintInfo& i, const IntRect& rect) { return paintTextField(o, i, rect); }
void DefaultWebThemeEngine::paintTextArea(Canvas* canvas, State state, const Rect& rect) const { paintTextField(canvas, state, rect); }
bool RenderThemeQt::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& pi, const IntRect& r) { paintTextField(o, pi, r); return false; }