Changeset 164156 in webkit


Ignore:
Timestamp:
Feb 14, 2014, 8:52:38 PM (12 years ago)
Author:
rniwa@webkit.org
Message:

setSelectionRange shouldn't trigger a synchronous layout to check focusability when text field is already focused
https://bugs.webkit.org/show_bug.cgi?id=128804

Reviewed by Enrica Casucci.

Don't trigger a synchronous layout at the beginning of setSelectionRange if the element is already focused
since we don't have to check the size of render box in that case.

We should be able to get rid of this synchronous layout entirely once we fix https://webkit.org/b/128797
but that's somewhat risky behavioral change so we'll do that in a separate patch.

  • editing/FrameSelection.cpp:

(WebCore::FrameSelection::selectAll): Fixed the bug where selectAll selects the entire document even if the text
form contol is focused if the selection is none (i.e. not anchored to any node).

  • html/HTMLTextFormControlElement.cpp:

(WebCore::HTMLTextFormControlElement::setSelectionRange): Only update the layout if the element is not focused
already. Also pass in DoNotSetFocus option to setSelection since we already have the focus in that case.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r164145 r164156  
     12014-02-14  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        setSelectionRange shouldn't trigger a synchronous layout to check focusability when text field is already focused
     4        https://bugs.webkit.org/show_bug.cgi?id=128804
     5
     6        Reviewed by Enrica Casucci.
     7
     8        Don't trigger a synchronous layout at the beginning of setSelectionRange if the element is already focused
     9        since we don't have to check the size of render box in that case.
     10
     11        We should be able to get rid of this synchronous layout entirely once we fix https://webkit.org/b/128797
     12        but that's somewhat risky behavioral change so we'll do that in a separate patch.
     13
     14        * editing/FrameSelection.cpp:
     15        (WebCore::FrameSelection::selectAll): Fixed the bug where selectAll selects the entire document even if the text
     16        form contol is focused if the selection is none (i.e. not anchored to any node).
     17        * html/HTMLTextFormControlElement.cpp:
     18        (WebCore::HTMLTextFormControlElement::setSelectionRange): Only update the layout if the element is not focused
     19        already. Also pass in DoNotSetFocus option to setSelection since we already have the focus in that case.
     20
    1212014-02-14  Dan Bernstein  <mitz@apple.com>
    222
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r164133 r164156  
    16411641    Document* document = m_frame->document();
    16421642
    1643     if (document->focusedElement() && document->focusedElement()->hasTagName(selectTag)) {
     1643    Element* focusedElement = document->focusedElement();
     1644    if (focusedElement && focusedElement->hasTagName(selectTag)) {
    16441645        HTMLSelectElement* selectElement = toHTMLSelectElement(document->focusedElement());
    16451646        if (selectElement->canSelectAll()) {
     
    16581659            selectStartTarget = root.get();
    16591660    } else {
    1660         root = m_selection.nonBoundaryShadowTreeRootNode();
     1661        if (m_selection.isNone() && focusedElement) {
     1662            if (focusedElement->isTextFormControl()) {
     1663                toHTMLTextFormControlElement(focusedElement)->select();
     1664                return;
     1665            }
     1666            root = focusedElement->nonBoundaryShadowTreeRootNode();
     1667        } else
     1668            root = m_selection.nonBoundaryShadowTreeRootNode();
     1669
    16611670        if (root)
    16621671            selectStartTarget = root->shadowHost();
  • trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp

    r163846 r164156  
    214214}
    215215
    216 static inline bool hasVisibleTextArea(RenderElement& textControl, TextControlInnerTextElement* innerText)
    217 {
    218     return textControl.style().visibility() != HIDDEN && innerText && innerText->renderer() && innerText->renderBox()->height();
    219 }
    220 
    221216void HTMLTextFormControlElement::setRangeText(const String& replacement, ExceptionCode& ec)
    222217{
     
    291286void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextFieldSelectionDirection direction)
    292287{
    293     document().updateLayoutIgnorePendingStylesheets();
    294 
    295     if (!renderer() || !renderer()->isTextControl())
     288    if (!isTextFormControl())
    296289        return;
    297290
     
    300293
    301294    TextControlInnerTextElement* innerText = innerTextElement();
    302     if (!hasVisibleTextArea(*renderer(), innerText)) {
    303         cacheSelection(start, end, direction);
    304         return;
    305     }
     295    bool hasFocus = document().focusedElement() == this;
     296    if (!hasFocus && innerText) {
     297        // FIXME: Removing this synchronous layout requires fixing <https://webkit.org/b/128797>
     298        document().updateLayoutIgnorePendingStylesheets();
     299        if (RenderElement* rendererTextControl = renderer()) {
     300            if (rendererTextControl->style().visibility() == HIDDEN || !innerText->renderBox()->height()) {
     301                cacheSelection(start, end, direction);
     302                return;
     303            }
     304        }
     305    }
     306
    306307    Position startPosition = positionForIndex(innerText, start);
    307308    Position endPosition;
     
    318319    newSelection.setIsDirectional(direction != SelectionHasNoDirection);
    319320
     321    FrameSelection::SetSelectionOptions options = FrameSelection::defaultSetSelectionOptions();
     322    if (hasFocus)
     323        options |= FrameSelection::DoNotSetFocus;
    320324    if (Frame* frame = document().frame())
    321         frame->selection().setSelection(newSelection);
     325        frame->selection().setSelection(newSelection, options);
    322326}
    323327
Note: See TracChangeset for help on using the changeset viewer.