Changeset 238409 in webkit


Ignore:
Timestamp:
Nov 20, 2018 4:12:25 PM (5 years ago)
Author:
rniwa@webkit.org
Message:

Input element gains focus when a selectstart event listener on document prevents the default action
https://bugs.webkit.org/show_bug.cgi?id=191714
<rdar://problem/46174389>

Reviewed by Antti Koivisto.

Source/WebCore:

The bug was caused by WebKit keep firing selectstart upon mousemove after the drag had already started
when preventDefault had been called in the previous firings of selectstart event. Because input element
has its own editable element and fires selectstart on the input element itself, which won't be prevented
by selectstart on docuemnt, this allowed the selection to be set inside the input element even though
the mouse cursor was simply passing over the input element after the drag had already started.

Fixed the bug by not firing selectstart if the default action had been prevented by the initial firing
of selectstart by setting m_mouseDownMayStartDrag to false. This also matches the behaviors of Chrome
and Firefox.

Test: fast/events/selectstart-prevent-default-should-not-focus-input.html

  • page/EventHandler.cpp:

(WebCore::EventHandler::updateSelectionForMouseDownDispatchingSelectStart):
(WebCore::EventHandler::updateSelectionForMouseDrag):

LayoutTests:

Added a regression test.

  • fast/events/selectstart-prevent-default-should-not-focus-input-expected.txt: Added.
  • fast/events/selectstart-prevent-default-should-not-focus-input.html: Added.
  • platform/ios/TestExpectations:
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r238393 r238409  
     12018-11-20  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Input element gains focus when a selectstart event listener on document prevents the default action
     4        https://bugs.webkit.org/show_bug.cgi?id=191714
     5        <rdar://problem/46174389>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Added a regression test.
     10
     11        * fast/events/selectstart-prevent-default-should-not-focus-input-expected.txt: Added.
     12        * fast/events/selectstart-prevent-default-should-not-focus-input.html: Added.
     13        * platform/ios/TestExpectations:
     14
    1152018-11-19  Ryosuke Niwa  <rniwa@webkit.org>
    216
  • trunk/LayoutTests/platform/ios/TestExpectations

    r238375 r238409  
    530530fast/events/selectstart-by-single-click-with-shift.html [ Skip ]
    531531fast/events/selectstart-prevent-selection-on-right-click.html [ Skip ]
     532fast/events/selectstart-prevent-default-should-not-focus-input.html [ Skip ]
    532533fast/events/shadow-event-path-2.html [ Skip ]
    533534fast/events/shadow-event-path.html [ Skip ]
  • trunk/Source/WebCore/ChangeLog

    r238406 r238409  
     12018-11-20  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Input element gains focus when a selectstart event listener on document prevents the default action
     4        https://bugs.webkit.org/show_bug.cgi?id=191714
     5        <rdar://problem/46174389>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        The bug was caused by WebKit keep firing selectstart upon mousemove after the drag had already started
     10        when preventDefault had been called in the previous firings of selectstart event. Because input element
     11        has its own editable element and fires selectstart on the input element itself, which won't be prevented
     12        by selectstart on docuemnt, this allowed the selection to be set inside the input element even though
     13        the mouse cursor was simply passing over the input element after the drag had already started.
     14
     15        Fixed the bug by not firing selectstart if the default action had been prevented by the initial firing
     16        of selectstart by setting m_mouseDownMayStartDrag to false. This also matches the behaviors of Chrome
     17        and Firefox.
     18
     19        Test: fast/events/selectstart-prevent-default-should-not-focus-input.html
     20
     21        * page/EventHandler.cpp:
     22        (WebCore::EventHandler::updateSelectionForMouseDownDispatchingSelectStart):
     23        (WebCore::EventHandler::updateSelectionForMouseDrag):
     24
    1252018-11-20  Christopher Reid  <chris.reid@sony.com>
    226
  • trunk/Source/WebCore/page/EventHandler.cpp

    r238393 r238409  
    511511        return false;
    512512
    513     if (!dispatchSelectStart(targetNode))
    514         return false;
     513    if (!dispatchSelectStart(targetNode)) {
     514        m_mouseDownMayStartSelect = false;
     515        return false;
     516    }
    515517
    516518    if (selection.isRange())
     
    954956    // Special case to limit selection to the containing block for SVG text.
    955957    // FIXME: Isn't there a better non-SVG-specific way to do this?
    956     if (Node* selectionBaseNode = newSelection.base().deprecatedNode())
    957         if (RenderObject* selectionBaseRenderer = selectionBaseNode->renderer())
    958             if (selectionBaseRenderer->isSVGText())
     958    if (Node* selectionBaseNode = newSelection.base().deprecatedNode()) {
     959        if (RenderObject* selectionBaseRenderer = selectionBaseNode->renderer()) {
     960            if (selectionBaseRenderer->isSVGText()) {
    959961                if (target->renderer()->containingBlock() != selectionBaseRenderer->containingBlock())
    960962                    return;
    961 
    962     if (m_selectionInitiationState == HaveNotStartedSelection && !dispatchSelectStart(target))
    963         return;
     963            }
     964        }
     965    }
     966
     967
     968    if (m_selectionInitiationState == HaveNotStartedSelection && !dispatchSelectStart(target)) {
     969        m_mouseDownMayStartSelect = false;
     970        return;
     971    }
    964972
    965973    if (m_selectionInitiationState != ExtendedSelection) {
Note: See TracChangeset for help on using the changeset viewer.