Changeset 245286 in webkit


Ignore:
Timestamp:
May 14, 2019 9:50:37 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

[Pointer Events] The pointerenter and pointerleave events target the wrong element on iOS
https://bugs.webkit.org/show_bug.cgi?id=197881
<rdar://problem/50187657>

Patch by Antoine Quint <Antoine Quint> on 2019-05-14
Reviewed by Dean Jackson.

Source/WebCore:

Test: pointerevents/ios/enter-leave-target.html

The "pointerenter" and "pointerleave" should target the element on which the event listener was added and not
the element that would otherwise hit test. This matches the behavior of "mouseenter" and "mouseleave" on macOS.

  • page/PointerCaptureController.cpp:

(WebCore::PointerCaptureController::dispatchEventForTouchAtIndex):

LayoutTests:

Add a test where we tap an element that is the child of another element where the parent is the element with the "pointerenter"
and "pointerleave" events registered. The test shows that we correctly set the target to the parent element and not the child.

  • pointerevents/ios/enter-leave-target-expected.txt: Added.
  • pointerevents/ios/enter-leave-target.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r245285 r245286  
     12019-05-14  Antoine Quint  <graouts@apple.com>
     2
     3        [Pointer Events] The pointerenter and pointerleave events target the wrong element on iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=197881
     5        <rdar://problem/50187657>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Add a test where we tap an element that is the child of another element where the parent is the element with the "pointerenter"
     10        and "pointerleave" events registered. The test shows that we correctly set the target to the parent element and not the child.
     11
     12        * pointerevents/ios/enter-leave-target-expected.txt: Added.
     13        * pointerevents/ios/enter-leave-target.html: Added.
     14
    1152019-05-14  Daniel Bates  <dabates@apple.com>
    216
  • trunk/Source/WebCore/ChangeLog

    r245280 r245286  
     12019-05-14  Antoine Quint  <graouts@apple.com>
     2
     3        [Pointer Events] The pointerenter and pointerleave events target the wrong element on iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=197881
     5        <rdar://problem/50187657>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Test: pointerevents/ios/enter-leave-target.html
     10
     11        The "pointerenter" and "pointerleave" should target the element on which the event listener was added and not
     12        the element that would otherwise hit test. This matches the behavior of "mouseenter" and "mouseleave" on macOS.
     13
     14        * page/PointerCaptureController.cpp:
     15        (WebCore::PointerCaptureController::dispatchEventForTouchAtIndex):
     16
    1172019-05-14  Said Abou-Hallawa  <sabouhallawa@apple.com>
    218
  • trunk/Source/WebCore/page/PointerCaptureController.cpp

    r245020 r245286  
    165165    };
    166166
     167    auto dispatchEnterOrLeaveEvent = [&](const String& type) {
     168        if (!is<Element>(&target))
     169            return;
     170
     171        auto* targetElement = &downcast<Element>(target);
     172
     173        bool hasCapturingListenerInHierarchy = false;
     174        for (ContainerNode* curr = targetElement; curr; curr = curr->parentInComposedTree()) {
     175            if (curr->hasCapturingEventListeners(type)) {
     176                hasCapturingListenerInHierarchy = true;
     177                break;
     178            }
     179        }
     180
     181        for (Element* element = &downcast<Element>(target); element; element = element->parentElementInComposedTree()) {
     182            if (hasCapturingListenerInHierarchy || element->hasEventListeners(type))
     183                element->dispatchEvent(PointerEvent::create(type, platformTouchEvent, index, isPrimary, view));
     184        }
     185    };
     186
    167187    auto pointerEvent = PointerEvent::create(platformTouchEvent, index, isPrimary, view);
    168188
     
    172192        // pointerenter prior to dispatching the pointerdown event.
    173193        dispatchEvent(eventNames().pointeroverEvent);
    174         dispatchEvent(eventNames().pointerenterEvent);
     194        dispatchEnterOrLeaveEvent(eventNames().pointerenterEvent);
    175195    }
    176196
     
    184204        // pointer event named pointerleave after dispatching the pointerup event.
    185205        dispatchEvent(eventNames().pointeroutEvent);
    186         dispatchEvent(eventNames().pointerleaveEvent);
     206        dispatchEnterOrLeaveEvent(eventNames().pointerleaveEvent);
    187207    }
    188208}
Note: See TracChangeset for help on using the changeset viewer.