Changeset 240452 in webkit


Ignore:
Timestamp:
Jan 24, 2019 3:30:37 PM (5 years ago)
Author:
Wenson Hsieh
Message:

[iOS] Unable to make a selection in jsfiddle.net using arrow keys when requesting desktop site
https://bugs.webkit.org/show_bug.cgi?id=193758
<rdar://problem/43614978>

Reviewed by Tim Horton.

Source/WebCore:

CodeMirror's script adds a repeating timer that periodically normalizes the logical selection in the editor
(this is distinct from the actual DOM selection, which is inside a hidden textarea element). This script defines
a helper method to select all the text inside of a text form control, called selectInput, which normally
invokes node.select(). However, in the case of iOS, the script works around broken select() behavior by
setting selectionStart and selectionEnd to encompass all the content in the form control. When requesting
the desktop version of the site, CodeMirror no longer attempts to apply its iOS workaround.

This iOS-specific behavior was introduced to fix <rdar://problem/4901923>. However, the original bug no longer
reproduces even without this quirk. To fix CodeMirror, we make two adjustments:

  1. Roll out this ancient demo hack, in favor of standardized behavior.
  2. Note that select() is also used when focusing an input. However, when focusing an input element on iOS, we

want to match the platform (i.e. UITextField behavior) and move focus to the end of the text field. To
achieve this, we introduce a new helper on HTMLInputElement that is called when setting the default
selection of a text input after focus; on iOS, this helper method moves the selection to the end of the
input, but everywhere else, it selects all the text in the input element.

This causes 6 existing layout tests to begin passing on iOS.

  • html/HTMLInputElement.cpp:

(WebCore::HTMLInputElement::updateFocusAppearance):
(WebCore::HTMLInputElement::setDefaultSelectionAfterFocus):

  • html/HTMLInputElement.h:
  • html/HTMLTextFormControlElement.cpp:

(WebCore::HTMLTextFormControlElement::select):

LayoutTests:

Mark some existing layout tests as passing on iOS. Additionally, remove failing expectations for another
existing layout test on iOS.

  • platform/ios/TestExpectations:
  • platform/ios/editing/text-iterator/hidden-textarea-selection-quirk-expected.txt: Removed.
Location:
trunk
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r240444 r240452  
     12019-01-24  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] Unable to make a selection in jsfiddle.net using arrow keys when requesting desktop site
     4        https://bugs.webkit.org/show_bug.cgi?id=193758
     5        <rdar://problem/43614978>
     6
     7        Reviewed by Tim Horton.
     8
     9        Mark some existing layout tests as passing on iOS. Additionally, remove failing expectations for another
     10        existing layout test on iOS.
     11
     12        * platform/ios/TestExpectations:
     13        * platform/ios/editing/text-iterator/hidden-textarea-selection-quirk-expected.txt: Removed.
     14
    1152019-01-24  John Wilander  <wilander@apple.com>
    216
  • trunk/LayoutTests/platform/ios/TestExpectations

    r240324 r240452  
    16831683fast/forms/input-live-pseudo-selectors.html [ Failure ]
    16841684fast/forms/input-no-renderer.html [ Failure ]
    1685 fast/forms/input-select-webkit-user-select-none.html [ Failure ]
    16861685fast/forms/input-set-composition-scroll.html [ Failure ]
    16871686fast/forms/input-textarea-padding-match.html [ ImageOnlyFailure ]
     
    17081707fast/forms/select-overflow-scroll.html [ Failure ]
    17091708fast/forms/select/option-selecting.html [ Failure ]
    1710 fast/forms/shadow-tree-exposure.html [ Failure ]
    17111709fast/forms/textarea-input-event.html [ Failure ]
    17121710fast/forms/textarea-live-pseudo-selectors.html [ Failure ]
    17131711fast/forms/textarea-metrics.html [ Failure ]
    17141712fast/forms/textarea-placeholder-wrapping.html [ ImageOnlyFailure ]
    1715 fast/forms/textarea-set-defaultvalue-after-value.html [ Failure ]
    17161713fast/forms/textfield-overflow-by-value-update.html [ Failure ]
    17171714fast/frames/calculate-fixed.html [ Failure ]
     
    21182115editing/pasteboard/copy-inside-h1-preserves-h1.html [ Failure ]
    21192116editing/pasteboard/copy-text-with-backgroundcolor.html [ Failure ]
    2120 editing/pasteboard/copy-two-pasteboard-types-both-work.html [ Failure ]
    21212117webkit.org/b/177961 editing/pasteboard/data-transfer-items.html [ Skip ]
    21222118editing/pasteboard/dataTransfer-setData-getData.html [ Failure ]
     
    21382134editing/pasteboard/paste-global-selection.html [ Failure ]
    21392135editing/pasteboard/paste-list-004.html [ Failure ]
    2140 editing/pasteboard/paste-placeholder-input.html [ Failure ]
    21412136editing/pasteboard/paste-plaintext-user-select-none.html [ Failure ]
    21422137editing/pasteboard/paste-sanitize-crash-1.html [ Failure ]
  • trunk/Source/WebCore/ChangeLog

    r240451 r240452  
     12019-01-24  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] Unable to make a selection in jsfiddle.net using arrow keys when requesting desktop site
     4        https://bugs.webkit.org/show_bug.cgi?id=193758
     5        <rdar://problem/43614978>
     6
     7        Reviewed by Tim Horton.
     8
     9        CodeMirror's script adds a repeating timer that periodically normalizes the logical selection in the editor
     10        (this is distinct from the actual DOM selection, which is inside a hidden textarea element). This script defines
     11        a helper method to select all the text inside of a text form control, called `selectInput`, which normally
     12        invokes `node.select()`. However, in the case of iOS, the script works around broken `select()` behavior by
     13        setting `selectionStart` and `selectionEnd` to encompass all the content in the form control. When requesting
     14        the desktop version of the site, CodeMirror no longer attempts to apply its iOS workaround.
     15
     16        This iOS-specific behavior was introduced to fix <rdar://problem/4901923>. However, the original bug no longer
     17        reproduces even without this quirk. To fix CodeMirror, we make two adjustments:
     18
     19        1.  Roll out this ancient demo hack, in favor of standardized behavior.
     20        2.  Note that `select()` is also used when focusing an input. However, when focusing an input element on iOS, we
     21            want to match the platform (i.e. UITextField behavior) and move focus to the end of the text field. To
     22            achieve this, we introduce a new helper on HTMLInputElement that is called when setting the default
     23            selection of a text input after focus; on iOS, this helper method moves the selection to the end of the
     24            input, but everywhere else, it selects all the text in the input element.
     25
     26        This causes 6 existing layout tests to begin passing on iOS.
     27
     28        * html/HTMLInputElement.cpp:
     29        (WebCore::HTMLInputElement::updateFocusAppearance):
     30        (WebCore::HTMLInputElement::setDefaultSelectionAfterFocus):
     31        * html/HTMLInputElement.h:
     32        * html/HTMLTextFormControlElement.cpp:
     33        (WebCore::HTMLTextFormControlElement::select):
     34
    1352019-01-24  Jer Noble  <jer.noble@apple.com>
    236
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r240237 r240452  
    460460    if (isTextField()) {
    461461        if (restorationMode == SelectionRestorationMode::SetDefault || !hasCachedSelection())
    462             select(revealMode, Element::defaultFocusTextStateChangeIntent());
     462            setDefaultSelectionAfterFocus(revealMode);
    463463        else
    464464            restoreCachedSelection(revealMode);
    465465    } else
    466466        HTMLTextFormControlElement::updateFocusAppearance(restorationMode, revealMode);
     467}
     468
     469void HTMLInputElement::setDefaultSelectionAfterFocus(SelectionRevealMode revealMode)
     470{
     471    ASSERT(isTextField());
     472#if PLATFORM(IOS_FAMILY)
     473    // We don't want to select all the text on iOS when focusing a field. Instead, match platform behavior by going to the end of the line.
     474    int start = std::numeric_limits<int>::max();
     475    auto direction = SelectionHasForwardDirection;
     476#else
     477    int start = 0;
     478    auto direction = SelectionHasNoDirection;
     479#endif
     480    setSelectionRange(start, std::numeric_limits<int>::max(), direction, revealMode, Element::defaultFocusTextStateChangeIntent());
    467481}
    468482
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r239427 r240452  
    455455    void removeFromRadioButtonGroup();
    456456
     457    void setDefaultSelectionAfterFocus(SelectionRevealMode);
     458
    457459    AtomicString m_name;
    458460    String m_valueIfDirty;
  • trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp

    r237975 r240452  
    190190void HTMLTextFormControlElement::select(SelectionRevealMode revealMode, const AXTextStateChangeIntent& intent)
    191191{
    192     // FIXME: We should abstract the selection behavior into an EditingBehavior function instead
    193     // of hardcoding the behavior using a macro define.
    194 #if PLATFORM(IOS_FAMILY)
    195     // We don't want to select all the text on iOS. Instead use the standard textfield behavior of going to the end of the line.
    196     setSelectionRange(std::numeric_limits<int>::max(), std::numeric_limits<int>::max(), SelectionHasForwardDirection, revealMode, intent);
    197 #else
    198192    setSelectionRange(0, std::numeric_limits<int>::max(), SelectionHasNoDirection, revealMode, intent);
    199 #endif
    200193}
    201194
Note: See TracChangeset for help on using the changeset viewer.