void HTMLTextFormControlElement::selectionChanged(bool shouldFireSelectEvent) { if (!isTextFormControl()) return; // FIXME: Don't re-compute selection start and end if this function was called inside setSelectionRange. // selectionStart() or selectionEnd() will return cached selection when this node doesn't have focus cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelectionDirection()); if (shouldFireSelectEvent && m_cachedSelectionStart != m_cachedSelectionEnd) dispatchEvent(Event::create(eventNames().selectEvent, true, false)); }
void HTMLTextFormControlElement::selectionChanged(bool userTriggered) { if (!renderer() || !isTextFormControl()) return; // selectionStart() or selectionEnd() will return cached selection when this node doesn't have focus cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelectionDirection()); if (Frame* frame = document()->frame()) { if (frame->selection()->isRange() && userTriggered) dispatchEvent(Event::create(eventNames().selectEvent, true, false)); } }
void HTMLTextFormControlElement::selectionChanged(bool userTriggered) { if (!renderer() || !isTextFormControl()) return; // selectionStart() or selectionEnd() will return cached selection when this node doesn't have focus cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelectionDirection()); if (LocalFrame* frame = document().frame()) { if (frame->selection().isRange() && userTriggered) dispatchEvent(Event::createBubble(EventTypeNames::select)); } }
void HTMLTextFormControlElement::selectionChanged(bool userTriggered) { if (!isTextFormControl()) return; // FIXME: Don't re-compute selection start and end if this function was called inside setSelectionRange. // selectionStart() or selectionEnd() will return cached selection when this node doesn't have focus cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelectionDirection()); if (Frame* frame = document().frame()) { if (frame->selection().isRange() && userTriggered) dispatchEvent(Event::create(eventNames().selectEvent, true, false)); } }
void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextFieldSelectionDirection direction, NeedToDispatchSelectEvent eventBehaviour, SelectionOption selectionOption) { if (openShadowRoot() || !isTextFormControl()) return; const int editorValueLength = static_cast<int>(innerEditorValue().length()); ASSERT(editorValueLength >= 0); end = std::max(std::min(end, editorValueLength), 0); start = std::min(std::max(start, 0), end); cacheSelection(start, end, direction); if (selectionOption == NotChangeSelection || (selectionOption == ChangeSelectionIfFocused && document().focusedElement() != this) || !inShadowIncludingDocument()) { if (eventBehaviour == DispatchSelectEvent) scheduleSelectEvent(); return; } LocalFrame* frame = document().frame(); HTMLElement* innerEditor = innerEditorElement(); if (!frame || !innerEditor) return; Position startPosition = positionForIndex(innerEditor, start); Position endPosition = start == end ? startPosition : positionForIndex(innerEditor, end); ASSERT(start == indexForPosition(innerEditor, startPosition)); ASSERT(end == indexForPosition(innerEditor, endPosition)); #if ENABLE(ASSERT) // startPosition and endPosition can be null position for example when // "-webkit-user-select: none" style attribute is specified. if (startPosition.isNotNull() && endPosition.isNotNull()) { ASSERT(startPosition.anchorNode()->shadowHost() == this && endPosition.anchorNode()->shadowHost() == this); } #endif // ENABLE(ASSERT) VisibleSelection newSelection; if (direction == SelectionHasBackwardDirection) newSelection.setWithoutValidation(endPosition, startPosition); else newSelection.setWithoutValidation(startPosition, endPosition); newSelection.setIsDirectional(direction != SelectionHasNoDirection); frame->selection().setSelection(newSelection, FrameSelection::DoNotAdjustInFlatTree | FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | (selectionOption == ChangeSelectionAndFocus ? 0 : FrameSelection::DoNotSetFocus)); if (eventBehaviour == DispatchSelectEvent) scheduleSelectEvent(); }
void WMLInputElement::setValue(const String& value, bool) { setFormControlValueMatchesRenderer(false); m_data.setValue(constrainValue(value)); if (inDocument()) document()->updateStyleIfNeeded(); if (renderer()) renderer()->updateFromElement(); setNeedsStyleRecalc(); unsigned max = m_data.value().length(); if (document()->focusedNode() == this) InputElement::updateSelectionRange(this, this, max, max); else cacheSelection(max, max); InputElement::notifyFormStateChanged(this); }
void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextFieldSelectionDirection direction) { document().updateLayoutIgnorePendingStylesheets(); if (!renderer() || !renderer()->isTextControl()) return; end = std::max(end, 0); start = std::min(std::max(start, 0), end); if (!hasVisibleTextArea(*renderer(), innerTextElement())) { cacheSelection(start, end, direction); return; } VisiblePosition startPosition = visiblePositionForIndex(start); VisiblePosition endPosition; if (start == end) endPosition = startPosition; else endPosition = visiblePositionForIndex(end); #if !PLATFORM(IOS) // startPosition and endPosition can be null position for example when // "-webkit-user-select: none" style attribute is specified. if (startPosition.isNotNull() && endPosition.isNotNull()) { ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowHost() == this && endPosition.deepEquivalent().deprecatedNode()->shadowHost() == this); } #endif VisibleSelection newSelection; if (direction == SelectionHasBackwardDirection) newSelection = VisibleSelection(endPosition, startPosition); else newSelection = VisibleSelection(startPosition, endPosition); newSelection.setIsDirectional(direction != SelectionHasNoDirection); if (Frame* frame = document().frame()) frame->selection().setSelection(newSelection); }
void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextFieldSelectionDirection direction) { if (!isTextFormControl()) return; end = std::max(end, 0); start = std::min(std::max(start, 0), end); TextControlInnerTextElement* innerText = innerTextElement(); bool hasFocus = document().focusedElement() == this; if (!hasFocus && innerText) { // FIXME: Removing this synchronous layout requires fixing <https://webkit.org/b/128797> document().updateLayoutIgnorePendingStylesheets(); if (RenderElement* rendererTextControl = renderer()) { if (rendererTextControl->style().visibility() == HIDDEN || !innerText->renderBox()->height()) { cacheSelection(start, end, direction); return; } } } Position startPosition = positionForIndex(innerText, start); Position endPosition; if (start == end) endPosition = startPosition; else { if (direction == SelectionHasBackwardDirection) { endPosition = startPosition; startPosition = positionForIndex(innerText, end); } else endPosition = positionForIndex(innerText, end); } if (Frame* frame = document().frame()) frame->selection().moveWithoutValidationTo(startPosition, endPosition, direction != SelectionHasNoDirection, !hasFocus); }