Title: [246844] trunk
Revision
246844
Author
[email protected]
Date
2019-06-26 11:36:41 -0700 (Wed, 26 Jun 2019)

Log Message

[Pointer Events] Respect pointer capture when dispatching mouse boundary events and updating :hover
https://bugs.webkit.org/show_bug.cgi?id=198999
<rdar://problem/51979477>

Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

Mark the progressions in 3 WPT tests.

* web-platform-tests/pointerevents/pointerevent_boundary_events_at_implicit_release_hoverable_pointers-expected.txt:
* web-platform-tests/pointerevents/pointerevent_mouse_capture_change_hover-expected.txt:
* web-platform-tests/pointerevents/pointerevent_setpointercapture_relatedtarget-expected.txt:

Source/WebCore:

Up until now, we would not account for pointer capture (see ​https://w3c.github.io/pointerevents/#pointer-capture) when dispatching
mouse boundary events (mouseover, mouseout, mouseenter, mouseleave) and their counterpart pointer events. We would also not account
for it when updating :hover styles.

Now, when pointer capture changes for an element, we call setCapturingMouseEventsElement() on the EventHandler such that the element
that would naturally hit-test is overridden by the pointer capture element when identifying which target to use for the dispatch of
boundary mouse events. Additionally, when calling Document::prepareMouseEvent(), we also use the pointer capture element to
pass down to Document::updateHoverActiveState() such that :hover styles are applied to the correct element.

* dom/Document.cpp:
(WebCore::Document::prepareMouseEvent): When a new event is going to be dispatched, we must run the Process Pending Capture Element
steps as mandated by the Pointer Events spec. Calling this will dispatch the appropriate pointer capture change events and also
required boundary events since EventHandler::setCapturingMouseEventsElement() calls into EventHandler::updateMouseEventTargetNode().
Since this may update the capturing mouse events element, we ensure that we call updateHoverActiveState() with a flag that indicates that.
Finally, we use the capturing mouse events element instead of the hit-testing element to pass to updateHoverActiveState() to ensure
that is has :hover styles applied.
(WebCore::Document::updateHoverActiveState): Account for the new CaptureChange flag to force the invalidation of the :hover and :active
elements chain at all times when the capturing mouse events element changed.
* dom/Document.h:
* dom/PointerEvent.h: Update PointerEvent::createForPointerCapture() to take specific parameters rather than a single PointerEvent to
set the pointerId, isPrimary and pointerType properties of the generated event. This is required to call processPendingPointerCapture()
outside of PointerEvent dispatch logic since we now call it from Document::prepareMouseEvent() where we haven't yet generated such an
event.
* page/EventHandler.cpp:
(WebCore::EventHandler::pointerCaptureElementDidChange): When a new pointer capture element is set, call updateMouseEventTargetNode()
to ensure that boundary events are fired to indicate the pointer capture state change.
(WebCore::EventHandler::prepareMouseEvent): Keep track of the last PlatformMouseEvent used to prepare a mouse event so that we can use
it when setCapturingMouseEventsElement() is called.
* page/EventHandler.h:
* page/PointerCaptureController.cpp:
(WebCore::PointerCaptureController::pointerCaptureElement): Since Document::prepareMouseEvent() needs to know the current pointer capture
element, add a new public method that indicates the pointer capture element if that element is contained in the provided document. We need
to provide the document since PointerCaptureController is owned by the Page and may manage several documents.
(WebCore::PointerCaptureController::dispatchEvent): Only run the Process Pending Capture Element steps when dealing with a touch or pen
event since those steps are already ran for mouse events in Document::prepareMouseEvent(). Additionally, since the element target is already
set to be the pointer capture element with the changes made to processPendingPointerCapture(), and because on iOS pointer capture is always
active, we can remove the code that would retarget the event to the pointer capture element.
(WebCore::PointerCaptureController::pointerEventWasDispatched):
(WebCore::PointerCaptureController::cancelPointer):
(WebCore::PointerCaptureController::processPendingPointerCapture): We now call into EventHandler::setCapturingMouseEventsElement() when the
capture target element changes. We must be careful to call this method prior to dispatching the "gotpointercapture" event and after dispatching
the "lostpointercapture" event so that boundary events are fired at the right time.
* page/PointerCaptureController.h:

LayoutTests:

Update some WK1-specific expectations.

* platform/mac-wk1/imported/w3c/web-platform-tests/pointerevents/pointerevent_boundary_events_at_implicit_release_hoverable_pointers-expected.txt:
* platform/mac-wk1/imported/w3c/web-platform-tests/pointerevents/pointerevent_setpointercapture_relatedtarget-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (246843 => 246844)


--- trunk/LayoutTests/ChangeLog	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/LayoutTests/ChangeLog	2019-06-26 18:36:41 UTC (rev 246844)
@@ -1,3 +1,16 @@
+2019-06-26  Antoine Quint  <[email protected]>
+
+        [Pointer Events] Respect pointer capture when dispatching mouse boundary events and updating :hover
+        https://bugs.webkit.org/show_bug.cgi?id=198999
+        <rdar://problem/51979477>
+
+        Reviewed by Dean Jackson.
+
+        Update some WK1-specific expectations.
+
+        * platform/mac-wk1/imported/w3c/web-platform-tests/pointerevents/pointerevent_boundary_events_at_implicit_release_hoverable_pointers-expected.txt:
+        * platform/mac-wk1/imported/w3c/web-platform-tests/pointerevents/pointerevent_setpointercapture_relatedtarget-expected.txt:
+
 2019-06-26  Russell Epstein  <[email protected]>
 
         Layout Test imported/mozilla/svg/text/selectSubString-2.svg is failing.

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (246843 => 246844)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2019-06-26 18:36:41 UTC (rev 246844)
@@ -1,3 +1,17 @@
+2019-06-26  Antoine Quint  <[email protected]>
+
+        [Pointer Events] Respect pointer capture when dispatching mouse boundary events and updating :hover
+        https://bugs.webkit.org/show_bug.cgi?id=198999
+        <rdar://problem/51979477>
+
+        Reviewed by Dean Jackson.
+
+        Mark the progressions in 3 WPT tests.
+
+        * web-platform-tests/pointerevents/pointerevent_boundary_events_at_implicit_release_hoverable_pointers-expected.txt:
+        * web-platform-tests/pointerevents/pointerevent_mouse_capture_change_hover-expected.txt:
+        * web-platform-tests/pointerevents/pointerevent_setpointercapture_relatedtarget-expected.txt:
+
 2019-06-24  Antoine Quint  <[email protected]>
 
         [Pointer Events WPT] Unskip imported/w3c/web-platform-tests/pointerevents/pointerlock/pointerevent_coordinates_when_locked.html

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_boundary_events_at_implicit_release_hoverable_pointers-expected.txt (246843 => 246844)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_boundary_events_at_implicit_release_hoverable_pointers-expected.txt	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_boundary_events_at_implicit_release_hoverable_pointers-expected.txt	2019-06-26 18:36:41 UTC (rev 246844)
@@ -1,10 +1,8 @@
 Pointer Event: Boundary event sequence at implicit capture release
 
-Follow the test instructions with mouse. If you don't have the device skip it.
-
 When a captured pointer is implicitly released after a click, the boundary events should follow the lostpointercapture event.
 
 Click on the black box with mouse and do not move the mouse after or during the click.
 
-FAIL mouse Event sequence at implicit release on click assert_equals: expected "pointerout@target, pointerleave@target, pointerover@capture-target, pointerenter@capture-target, gotpointercapture@capture-target, pointerup@capture-target, lostpointercapture@capture-target, pointerout@capture-target, pointerleave@capture-target, pointerover@target, pointerenter@target" but got "gotpointercapture@capture-target, pointerup@capture-target, lostpointercapture@capture-target"
+PASS mouse Event sequence at implicit release on click 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_mouse_capture_change_hover-expected.txt (246843 => 246844)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_mouse_capture_change_hover-expected.txt	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_mouse_capture_change_hover-expected.txt	2019-06-26 18:36:41 UTC (rev 246844)
@@ -1,5 +1,5 @@
 
-FAIL Mouse down and capture to green. assert_array_equals: Received events: green received pointerover,green received pointerenter,green received pointermove,green received pointerdown,green received gotpointercapture,green received pointermove,green received pointerout,green received pointerleave,green received pointerover,green received pointerenter,green received pointermove lengths differ, expected 7 got 11
-FAIL Mouse down at green and capture to blue. assert_array_equals: Received events: green received pointerout,green received pointerover,green received pointerenter,green received pointermove,green received pointermove,green received pointermove,green received pointermove lengths differ, expected 11 got 7
-FAIL Mouse down and capture to green, move to blue and release capture assert_array_equals: Received events: green received pointerout,green received pointerover,green received pointerenter,green received pointermove,green received lostpointercapture,green received pointermove,green received pointerout,green received pointerleave,blue received pointerover,blue received pointerenter,blue received pointermove,blue received pointermove property 0, expected "green received pointerover" but got "green received pointerout"
+PASS Mouse down and capture to green. 
+PASS Mouse down at green and capture to blue. 
+PASS Mouse down and capture to green, move to blue and release capture 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_setpointercapture_relatedtarget-expected.txt (246843 => 246844)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_setpointercapture_relatedtarget-expected.txt	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_setpointercapture_relatedtarget-expected.txt	2019-06-26 18:36:41 UTC (rev 246844)
@@ -16,14 +16,11 @@
 
 The following pointer types were detected: mouse.
 
-The following events were logged: pointerover@target1, gotpointercapture@target0, pointerover@target0, pointerover@target0, lostpointercapture@target0.
+The following events were logged: pointerover@target1, pointerover@target0, gotpointercapture@target0, lostpointercapture@target0.
 
 Refresh the page to run the tests again with a different pointer type.
 
 
-Harness Error (FAIL), message = 1 duplicate test name: "relatedTarget should not be null even when the capture is set."
-
 PASS pointerover shouldn't trigger for the purple rectangle while the black rectangle has capture 
 PASS relatedTarget should not be null even when the capture is set. 
-PASS relatedTarget should not be null even when the capture is set. 
 

Modified: trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/pointerevents/pointerevent_boundary_events_at_implicit_release_hoverable_pointers-expected.txt (246843 => 246844)


--- trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/pointerevents/pointerevent_boundary_events_at_implicit_release_hoverable_pointers-expected.txt	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/pointerevents/pointerevent_boundary_events_at_implicit_release_hoverable_pointers-expected.txt	2019-06-26 18:36:41 UTC (rev 246844)
@@ -6,5 +6,5 @@
 
 Click on the black box with mouse and do not move the mouse after or during the click.
 
-FAIL mouse Event sequence at implicit release on click assert_equals: expected "pointerout@target, pointerleave@target, pointerover@capture-target, pointerenter@capture-target, gotpointercapture@capture-target, pointerup@capture-target, lostpointercapture@capture-target, pointerout@capture-target, pointerleave@capture-target, pointerover@target, pointerenter@target" but got "gotpointercapture@capture-target, pointerup@capture-target, lostpointercapture@capture-target, pointermove@target"
+FAIL mouse Event sequence at implicit release on click assert_equals: expected "pointerout@target, pointerleave@target, pointerover@capture-target, pointerenter@capture-target, gotpointercapture@capture-target, pointerup@capture-target, lostpointercapture@capture-target, pointerout@capture-target, pointerleave@capture-target, pointerover@target, pointerenter@target" but got "pointerout@target, pointerleave@target, pointerover@capture-target, pointerenter@capture-target, gotpointercapture@capture-target, pointerup@capture-target, lostpointercapture@capture-target, pointerout@capture-target, pointerleave@capture-target, pointerover@target, pointerenter@target, pointermove@target"
 

Modified: trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/pointerevents/pointerevent_setpointercapture_relatedtarget-expected.txt (246843 => 246844)


--- trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/pointerevents/pointerevent_setpointercapture_relatedtarget-expected.txt	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/pointerevents/pointerevent_setpointercapture_relatedtarget-expected.txt	2019-06-26 18:36:41 UTC (rev 246844)
@@ -16,14 +16,11 @@
 
 The following pointer types were detected: mouse.
 
-The following events were logged: pointerover@target1, gotpointercapture@target0, pointerover@target0, pointerover@target0, lostpointercapture@target0, pointerover@target0.
+The following events were logged: pointerover@target1, pointerover@target0, gotpointercapture@target0, lostpointercapture@target0, pointerover@target0.
 
 Refresh the page to run the tests again with a different pointer type.
 
 
-Harness Error (FAIL), message = 1 duplicate test name: "relatedTarget should not be null even when the capture is set."
-
 PASS pointerover shouldn't trigger for the purple rectangle while the black rectangle has capture 
 PASS relatedTarget should not be null even when the capture is set. 
-PASS relatedTarget should not be null even when the capture is set. 
 

Modified: trunk/Source/WebCore/ChangeLog (246843 => 246844)


--- trunk/Source/WebCore/ChangeLog	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/Source/WebCore/ChangeLog	2019-06-26 18:36:41 UTC (rev 246844)
@@ -1,3 +1,55 @@
+2019-06-26  Antoine Quint  <[email protected]>
+
+        [Pointer Events] Respect pointer capture when dispatching mouse boundary events and updating :hover
+        https://bugs.webkit.org/show_bug.cgi?id=198999
+        <rdar://problem/51979477>
+
+        Reviewed by Dean Jackson.
+
+        Up until now, we would not account for pointer capture (see ​https://w3c.github.io/pointerevents/#pointer-capture) when dispatching
+        mouse boundary events (mouseover, mouseout, mouseenter, mouseleave) and their counterpart pointer events. We would also not account
+        for it when updating :hover styles.
+
+        Now, when pointer capture changes for an element, we call setCapturingMouseEventsElement() on the EventHandler such that the element
+        that would naturally hit-test is overridden by the pointer capture element when identifying which target to use for the dispatch of
+        boundary mouse events. Additionally, when calling Document::prepareMouseEvent(), we also use the pointer capture element to
+        pass down to Document::updateHoverActiveState() such that :hover styles are applied to the correct element.
+
+        * dom/Document.cpp:
+        (WebCore::Document::prepareMouseEvent): When a new event is going to be dispatched, we must run the Process Pending Capture Element
+        steps as mandated by the Pointer Events spec. Calling this will dispatch the appropriate pointer capture change events and also
+        required boundary events since EventHandler::setCapturingMouseEventsElement() calls into EventHandler::updateMouseEventTargetNode().
+        Since this may update the capturing mouse events element, we ensure that we call updateHoverActiveState() with a flag that indicates that.
+        Finally, we use the capturing mouse events element instead of the hit-testing element to pass to updateHoverActiveState() to ensure
+        that is has :hover styles applied.
+        (WebCore::Document::updateHoverActiveState): Account for the new CaptureChange flag to force the invalidation of the :hover and :active
+        elements chain at all times when the capturing mouse events element changed.
+        * dom/Document.h:
+        * dom/PointerEvent.h: Update PointerEvent::createForPointerCapture() to take specific parameters rather than a single PointerEvent to
+        set the pointerId, isPrimary and pointerType properties of the generated event. This is required to call processPendingPointerCapture()
+        outside of PointerEvent dispatch logic since we now call it from Document::prepareMouseEvent() where we haven't yet generated such an
+        event.
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::pointerCaptureElementDidChange): When a new pointer capture element is set, call updateMouseEventTargetNode()
+        to ensure that boundary events are fired to indicate the pointer capture state change.
+        (WebCore::EventHandler::prepareMouseEvent): Keep track of the last PlatformMouseEvent used to prepare a mouse event so that we can use
+        it when setCapturingMouseEventsElement() is called.
+        * page/EventHandler.h:
+        * page/PointerCaptureController.cpp:
+        (WebCore::PointerCaptureController::pointerCaptureElement): Since Document::prepareMouseEvent() needs to know the current pointer capture
+        element, add a new public method that indicates the pointer capture element if that element is contained in the provided document. We need
+        to provide the document since PointerCaptureController is owned by the Page and may manage several documents.
+        (WebCore::PointerCaptureController::dispatchEvent): Only run the Process Pending Capture Element steps when dealing with a touch or pen
+        event since those steps are already ran for mouse events in Document::prepareMouseEvent(). Additionally, since the element target is already
+        set to be the pointer capture element with the changes made to processPendingPointerCapture(), and because on iOS pointer capture is always
+        active, we can remove the code that would retarget the event to the pointer capture element.
+        (WebCore::PointerCaptureController::pointerEventWasDispatched):
+        (WebCore::PointerCaptureController::cancelPointer):
+        (WebCore::PointerCaptureController::processPendingPointerCapture): We now call into EventHandler::setCapturingMouseEventsElement() when the
+        capture target element changes. We must be careful to call this method prior to dispatching the "gotpointercapture" event and after dispatching
+        the "lostpointercapture" event so that boundary events are fired at the right time.
+        * page/PointerCaptureController.h:
+
 2019-06-25  Fujii Hironori  <[email protected]>
 
         [WinCairo] incorrect font height for 'Google Sans Display' font

Modified: trunk/Source/WebCore/dom/Document.cpp (246843 => 246844)


--- trunk/Source/WebCore/dom/Document.cpp	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/Source/WebCore/dom/Document.cpp	2019-06-26 18:36:41 UTC (rev 246844)
@@ -320,6 +320,10 @@
 #include "GPUCanvasContext.h"
 #endif
 
+#if ENABLE(POINTER_EVENTS)
+#include "PointerCaptureController.h"
+#endif
+
 namespace WebCore {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(Document);
@@ -3732,8 +3736,29 @@
     HitTestResult result(documentPoint);
     hitTest(request, result);
 
-    if (!request.readOnly())
-        updateHoverActiveState(request, result.targetElement());
+    auto captureElementChanged = CaptureChange::No;
+    if (!request.readOnly()) {
+        auto targetElement = makeRefPtr(result.targetElement());
+#if ENABLE(POINTER_EVENTS)
+        if (auto* page = this->page()) {
+            // Before we dispatch a new mouse event, we must run the Process Pending Capture Element steps as defined
+            // in https://w3c.github.io/pointerevents/#process-pending-pointer-capture.
+            auto& pointerCaptureController = page->pointerCaptureController();
+            auto* previousCaptureElement = pointerCaptureController.pointerCaptureElement(this, event.pointerId());
+            pointerCaptureController.processPendingPointerCapture(event.pointerId());
+            auto* captureElement = pointerCaptureController.pointerCaptureElement(this, event.pointerId());
+            // If the capture element has changed while running the Process Pending Capture Element steps then
+            // we need to indicate that when calling updateHoverActiveState to be sure that the :active and :hover
+            // element chains are updated.
+            if (previousCaptureElement != captureElement)
+                captureElementChanged = CaptureChange::Yes;
+            // If we have a capture element, we must target it instead of what would normally hit-test for this event.
+            if (captureElement)
+                targetElement = captureElement;
+        }
+#endif
+        updateHoverActiveState(request, targetElement.get(), captureElementChanged);
+    }
 
     return MouseEventWithHitTestResults(event, result);
 }
@@ -6737,7 +6762,7 @@
     return nullptr;
 }
 
-void Document::updateHoverActiveState(const HitTestRequest& request, Element* innerElement)
+void Document::updateHoverActiveState(const HitTestRequest& request, Element* innerElement, CaptureChange captureElementChanged)
 {
     ASSERT(!request.readOnly());
 
@@ -6776,8 +6801,8 @@
 
     // If the mouse is down and if this is a mouse move event, we want to restrict changes in
     // :hover/:active to only apply to elements that are in the :active chain that we froze
-    // at the time the mouse went down.
-    bool mustBeInActiveChain = request.active() && request.move();
+    // at the time the mouse went down, unless the capture element changed.
+    bool mustBeInActiveChain = request.active() && request.move() && captureElementChanged == CaptureChange::No;
 
     RefPtr<Element> oldHoveredElement = WTFMove(m_hoveredElement);
 

Modified: trunk/Source/WebCore/dom/Document.h (246843 => 246844)


--- trunk/Source/WebCore/dom/Document.h	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/Source/WebCore/dom/Document.h	2019-06-26 18:36:41 UTC (rev 246844)
@@ -760,7 +760,8 @@
     void hoveredElementDidDetach(Element&);
     void elementInActiveChainDidDetach(Element&);
 
-    void updateHoverActiveState(const HitTestRequest&, Element*);
+    enum class CaptureChange : uint8_t { Yes, No };
+    void updateHoverActiveState(const HitTestRequest&, Element*, CaptureChange = CaptureChange::No);
 
     // Updates for :target (CSS3 selector).
     void setCSSTarget(Element*);

Modified: trunk/Source/WebCore/dom/PointerEvent.h (246843 => 246844)


--- trunk/Source/WebCore/dom/PointerEvent.h	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/Source/WebCore/dom/PointerEvent.h	2019-06-26 18:36:41 UTC (rev 246844)
@@ -61,13 +61,13 @@
         return adoptRef(*new PointerEvent(type, WTFMove(initializer)));
     }
 
-    static Ref<PointerEvent> createForPointerCapture(const AtomString& type, const PointerEvent& pointerEvent)
+    static Ref<PointerEvent> createForPointerCapture(const AtomString& type, PointerID pointerId, bool isPrimary, String pointerType)
     {
         Init initializer;
         initializer.bubbles = true;
-        initializer.pointerId = pointerEvent.pointerId();
-        initializer.isPrimary = pointerEvent.isPrimary();
-        initializer.pointerType = pointerEvent.pointerType();
+        initializer.pointerId = pointerId;
+        initializer.isPrimary = isPrimary;
+        initializer.pointerType = pointerType;
         return adoptRef(*new PointerEvent(type, WTFMove(initializer)));
     }
 

Modified: trunk/Source/WebCore/page/EventHandler.cpp (246843 => 246844)


--- trunk/Source/WebCore/page/EventHandler.cpp	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2019-06-26 18:36:41 UTC (rev 246844)
@@ -127,6 +127,10 @@
 #include "PointerLockController.h"
 #endif
 
+#if ENABLE(POINTER_EVENTS)
+#include "RuntimeEnabledFeatures.h"
+#endif
+
 namespace WebCore {
 
 using namespace HTMLNames;
@@ -2482,8 +2486,24 @@
     m_eventHandlerWillResetCapturingMouseEventsElement = false;
 }
 
+#if ENABLE(POINTER_EVENTS)
+void EventHandler::pointerCaptureElementDidChange(Element* element)
+{
+    if (m_capturingMouseEventsElement == element)
+        return;
+
+    setCapturingMouseEventsElement(element);
+
+    // Now that we have a new capture element, we need to dispatch boundary mouse events.
+    updateMouseEventTargetNode(element, m_lastPlatformMouseEvent, FireMouseOverOut::Yes);
+}
+#endif
+
 MouseEventWithHitTestResults EventHandler::prepareMouseEvent(const HitTestRequest& request, const PlatformMouseEvent& mouseEvent)
 {
+#if ENABLE(POINTER_EVENTS)
+    m_lastPlatformMouseEvent = mouseEvent;
+#endif
     Ref<Frame> protectedFrame(m_frame);
     ASSERT(m_frame.document());
     return m_frame.document()->prepareMouseEvent(request, documentPointForWindowPoint(m_frame, mouseEvent.position()), mouseEvent);

Modified: trunk/Source/WebCore/page/EventHandler.h (246843 => 246844)


--- trunk/Source/WebCore/page/EventHandler.h	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/Source/WebCore/page/EventHandler.h	2019-06-26 18:36:41 UTC (rev 246844)
@@ -158,6 +158,9 @@
     Node* mousePressNode() const { return m_mousePressNode.get(); }
 
     WEBCORE_EXPORT void setCapturingMouseEventsElement(Element*);
+#if ENABLE(POINTER_EVENTS)
+    void pointerCaptureElementDidChange(Element*);
+#endif
 
 #if ENABLE(DRAG_SUPPORT)
     struct DragTargetResponse {
@@ -592,6 +595,9 @@
     IntPoint m_mouseDownPos; // In our view's coords.
     WallTime m_mouseDownTimestamp;
     PlatformMouseEvent m_mouseDown;
+#if ENABLE(POINTER_EVENTS)
+    PlatformMouseEvent m_lastPlatformMouseEvent;
+#endif
 
 #if PLATFORM(COCOA)
     NSView *m_mouseDownView { nullptr };

Modified: trunk/Source/WebCore/page/PointerCaptureController.cpp (246843 => 246844)


--- trunk/Source/WebCore/page/PointerCaptureController.cpp	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/Source/WebCore/page/PointerCaptureController.cpp	2019-06-26 18:36:41 UTC (rev 246844)
@@ -48,6 +48,17 @@
     reset();
 }
 
+Element* PointerCaptureController::pointerCaptureElement(Document* document, PointerID pointerId)
+{
+    auto iterator = m_activePointerIdsToCapturingData.find(pointerId);
+    if (iterator != m_activePointerIdsToCapturingData.end()) {
+        auto pointerCaptureElement = iterator->value.targetOverride;
+        if (pointerCaptureElement && &pointerCaptureElement->document() == document)
+            return pointerCaptureElement.get();
+    }
+    return nullptr;
+}
+
 ExceptionOr<void> PointerCaptureController::setPointerCapture(Element* capturingTarget, PointerID pointerId)
 {
     // https://w3c.github.io/pointerevents/#setting-pointer-capture
@@ -271,16 +282,10 @@
 
     // https://w3c.github.io/pointerevents/#firing-events-using-the-pointerevent-interface
     // If the event is not gotpointercapture or lostpointercapture, run Process Pending Pointer Capture steps for this PointerEvent.
-    processPendingPointerCapture(event);
+    // We only need to do this for non-mouse type since for mouse events this method will be called in Document::prepareMouseEvent().
+    if (event.pointerType() != PointerEvent::mousePointerType())
+        processPendingPointerCapture(event.pointerId());
 
-    // If the pointer capture target override has been set for the pointer, set the target to pointer capture target override object.
-    auto iterator = m_activePointerIdsToCapturingData.find(event.pointerId());
-    if (iterator != m_activePointerIdsToCapturingData.end()) {
-        auto& capturingData = iterator->value;
-        if (capturingData.targetOverride)
-            target = capturingData.targetOverride.get();
-    }
-
     pointerEventWillBeDispatched(event, target);
     target->dispatchEvent(event);
     pointerEventWasDispatched(event);
@@ -340,7 +345,7 @@
         // https://w3c.github.io/pointerevents/#implicit-release-of-pointer-capture
         if (event.type() == eventNames().pointerupEvent) {
             capturingData.pendingTargetOverride = nullptr;
-            processPendingPointerCapture(event);
+            processPendingPointerCapture(event.pointerId());
         }
 
         // If a mouse pointer has moved while it isn't pressed, make sure we reset the preventsCompatibilityMouseEvents flag since
@@ -399,14 +404,17 @@
     target->dispatchEvent(cancelEvent);
     target->dispatchEvent(PointerEvent::create(eventNames().pointeroutEvent, pointerId, capturingData.pointerType, isPrimary));
     target->dispatchEvent(PointerEvent::create(eventNames().pointerleaveEvent, pointerId, capturingData.pointerType, isPrimary));
-    processPendingPointerCapture(WTFMove(cancelEvent));
+    processPendingPointerCapture(pointerId);
 }
 
-void PointerCaptureController::processPendingPointerCapture(const PointerEvent& event)
+void PointerCaptureController::processPendingPointerCapture(PointerID pointerId)
 {
-    // https://w3c.github.io/pointerevents/#process-pending-pointer-capture
+    if (m_processingPendingPointerCapture)
+        return;
 
-    auto iterator = m_activePointerIdsToCapturingData.find(event.pointerId());
+    m_processingPendingPointerCapture = true;
+
+    auto iterator = m_activePointerIdsToCapturingData.find(pointerId);
     if (iterator == m_activePointerIdsToCapturingData.end())
         return;
 
@@ -415,19 +423,32 @@
     // Cache the pending target override since it could be modified during the dispatch of events in this function.
     auto pendingTargetOverride = capturingData.pendingTargetOverride;
 
+    // https://w3c.github.io/pointerevents/#process-pending-pointer-capture
     // 1. If the pointer capture target override for this pointer is set and is not equal to the pending pointer capture target override,
     // then fire a pointer event named lostpointercapture at the pointer capture target override node.
-    if (capturingData.targetOverride && capturingData.targetOverride->isConnected() && capturingData.targetOverride != pendingTargetOverride)
-        capturingData.targetOverride->dispatchEvent(PointerEvent::createForPointerCapture(eventNames().lostpointercaptureEvent, event));
+    if (capturingData.targetOverride && capturingData.targetOverride->isConnected() && capturingData.targetOverride != pendingTargetOverride) {
+        capturingData.targetOverride->dispatchEvent(PointerEvent::createForPointerCapture(eventNames().lostpointercaptureEvent, pointerId, capturingData.isPrimary, capturingData.pointerType));
+        if (capturingData.pointerType == PointerEvent::mousePointerType()) {
+            if (auto* frame = capturingData.targetOverride->document().frame())
+                frame->eventHandler().pointerCaptureElementDidChange(nullptr);
+        }
+    }
 
     // 2. If the pending pointer capture target override for this pointer is set and is not equal to the pointer capture target override,
     // then fire a pointer event named gotpointercapture at the pending pointer capture target override.
-    if (capturingData.pendingTargetOverride && capturingData.targetOverride != pendingTargetOverride)
-        pendingTargetOverride->dispatchEvent(PointerEvent::createForPointerCapture(eventNames().gotpointercaptureEvent, event));
+    if (capturingData.pendingTargetOverride && capturingData.targetOverride != pendingTargetOverride) {
+        if (capturingData.pointerType == PointerEvent::mousePointerType()) {
+            if (auto* frame = pendingTargetOverride->document().frame())
+                frame->eventHandler().pointerCaptureElementDidChange(pendingTargetOverride.get());
+        }
+        pendingTargetOverride->dispatchEvent(PointerEvent::createForPointerCapture(eventNames().gotpointercaptureEvent, pointerId, capturingData.isPrimary, capturingData.pointerType));
+    }
 
     // 3. Set the pointer capture target override to the pending pointer capture target override, if set. Otherwise, clear the pointer
     // capture target override.
     capturingData.targetOverride = pendingTargetOverride;
+
+    m_processingPendingPointerCapture = false;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/PointerCaptureController.h (246843 => 246844)


--- trunk/Source/WebCore/page/PointerCaptureController.h	2019-06-26 18:36:36 UTC (rev 246843)
+++ trunk/Source/WebCore/page/PointerCaptureController.h	2019-06-26 18:36:41 UTC (rev 246844)
@@ -41,6 +41,7 @@
 public:
     explicit PointerCaptureController(Page&);
 
+    Element* pointerCaptureElement(Document*, PointerID);
     ExceptionOr<void> setPointerCapture(Element*, PointerID);
     ExceptionOr<void> releasePointerCapture(Element*, PointerID);
     bool hasPointerCapture(Element*, PointerID);
@@ -60,6 +61,7 @@
     bool preventsCompatibilityMouseEventsForIdentifier(PointerID);
     void dispatchEvent(PointerEvent&, EventTarget*);
     WEBCORE_EXPORT void cancelPointer(PointerID, const IntPoint&);
+    void processPendingPointerCapture(PointerID);
 
 private:
     struct CapturingData {
@@ -75,7 +77,6 @@
 
     void pointerEventWillBeDispatched(const PointerEvent&, EventTarget*);
     void pointerEventWasDispatched(const PointerEvent&);
-    void processPendingPointerCapture(const PointerEvent&);
 
     Page& m_page;
     // While PointerID is defined as int32_t, we use int64_t here so that we may use a value outside of the int32_t range to have safe
@@ -82,6 +83,7 @@
     // empty and removed values, allowing any int32_t to be provided through the API for lookup in this hashmap.
     using PointerIdToCapturingDataMap = HashMap<int64_t, CapturingData, WTF::IntHash<int64_t>, WTF::SignedWithZeroKeyHashTraits<int64_t>>;
     PointerIdToCapturingDataMap m_activePointerIdsToCapturingData;
+    bool m_processingPendingPointerCapture;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to