Title: [269582] trunk
Revision
269582
Author
cdu...@apple.com
Date
2020-11-09 09:26:43 -0800 (Mon, 09 Nov 2020)

Log Message

Look at parents when event bubbles for input element activation behavior
https://bugs.webkit.org/show_bug.cgi?id=218660

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline WPT test that is now fully passing.

* web-platform-tests/dom/events/Event-dispatch-click-expected.txt:

Source/WebCore:

When a click event is dispatched at a node that is not an HTMLInputElement, and if the
event bubbles, we should look up the tree to see if there is an HTMLInputElement that
we should trigger activation behavior for. Prevously, we were failing to do this.

The new behavior is consistent with Blink.

No new tests, rebaselined existing test.

* dom/EventDispatcher.cpp:
(WebCore::findInputElementInEventPath):
(WebCore::EventDispatcher::dispatchEvent):

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (269581 => 269582)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-11-09 16:41:21 UTC (rev 269581)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-11-09 17:26:43 UTC (rev 269582)
@@ -1,3 +1,14 @@
+2020-11-09  Chris Dumez  <cdu...@apple.com>
+
+        Look at parents when event bubbles for input element activation behavior
+        https://bugs.webkit.org/show_bug.cgi?id=218660
+
+        Reviewed by Ryosuke Niwa.
+
+        Rebaseline WPT test that is now fully passing.
+
+        * web-platform-tests/dom/events/Event-dispatch-click-expected.txt:
+
 2020-11-06  Dmitry Bezhetskov  <dbezhets...@igalia.com>
 
         [WASM-References] Rename anyref to externref

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-click-expected.txt (269581 => 269582)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-click-expected.txt	2020-11-09 16:41:21 UTC (rev 269581)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-click-expected.txt	2020-11-09 17:26:43 UTC (rev 269582)
@@ -3,7 +3,7 @@
 PASS basic with dispatchEvent()
 PASS basic with wrong event class
 PASS look at parents only when event bubbles
-FAIL look at parents when event bubbles assert_true: expected true got false
+PASS look at parents when event bubbles
 PASS pick the first with activation behavior <input type=checkbox>
 PASS pick the first with activation behavior <a href>
 PASS event state during post-click handling

Modified: trunk/Source/WebCore/ChangeLog (269581 => 269582)


--- trunk/Source/WebCore/ChangeLog	2020-11-09 16:41:21 UTC (rev 269581)
+++ trunk/Source/WebCore/ChangeLog	2020-11-09 17:26:43 UTC (rev 269582)
@@ -1,3 +1,22 @@
+2020-11-09  Chris Dumez  <cdu...@apple.com>
+
+        Look at parents when event bubbles for input element activation behavior
+        https://bugs.webkit.org/show_bug.cgi?id=218660
+
+        Reviewed by Ryosuke Niwa.
+
+        When a click event is dispatched at a node that is not an HTMLInputElement, and if the
+        event bubbles, we should look up the tree to see if there is an HTMLInputElement that
+        we should trigger activation behavior for. Prevously, we were failing to do this.
+
+        The new behavior is consistent with Blink.
+
+        No new tests, rebaselined existing test.
+
+        * dom/EventDispatcher.cpp:
+        (WebCore::findInputElementInEventPath):
+        (WebCore::EventDispatcher::dispatchEvent):
+
 2020-11-09  Chris Lord  <cl...@igalia.com>
 
         [GTK][WPE] Scrolling with mouse wheel doesn't work on iframes with async scrolling enabled

Modified: trunk/Source/WebCore/dom/EventDispatcher.cpp (269581 => 269582)


--- trunk/Source/WebCore/dom/EventDispatcher.cpp	2020-11-09 16:41:21 UTC (rev 269581)
+++ trunk/Source/WebCore/dom/EventDispatcher.cpp	2020-11-09 17:26:43 UTC (rev 269582)
@@ -128,6 +128,17 @@
     return is<CompositionEvent>(event) || is<InputEvent>(event) || is<KeyboardEvent>(event);
 }
 
+static HTMLInputElement* findInputElementInEventPath(const EventPath& path)
+{
+    size_t size = path.size();
+    for (size_t i = 0; i < size; ++i) {
+        const EventContext& eventContext = path.contextAt(i);
+        if (is<HTMLInputElement>(eventContext.currentTarget()))
+            return downcast<HTMLInputElement>(eventContext.currentTarget());
+    }
+    return nullptr;
+}
+
 void EventDispatcher::dispatchEvent(Node& node, Event& event)
 {
     ASSERT_WITH_SECURITY_IMPLICATION(ScriptDisallowedScope::InMainThread::isEventDispatchAllowedInSubtree(node));
@@ -159,9 +170,14 @@
         return;
 
     InputElementClickState clickHandlingState;
-    if (is<HTMLInputElement>(node))
-        downcast<HTMLInputElement>(node).willDispatchEvent(event, clickHandlingState);
 
+    bool isActivationEvent = event.type() == eventNames().clickEvent;
+    RefPtr<HTMLInputElement> inputForLegacyPreActivationBehavior = is<HTMLInputElement>(node) ? &downcast<HTMLInputElement>(node) : nullptr;
+    if (!inputForLegacyPreActivationBehavior && isActivationEvent && event.bubbles())
+        inputForLegacyPreActivationBehavior = findInputElementInEventPath(eventPath);
+    if (inputForLegacyPreActivationBehavior)
+        inputForLegacyPreActivationBehavior->willDispatchEvent(event, clickHandlingState);
+
     if (shouldSuppressEventDispatchInDOM(node, event))
         event.stopPropagation();
 
@@ -173,7 +189,7 @@
     event.resetAfterDispatch();
 
     if (clickHandlingState.stateful)
-        downcast<HTMLInputElement>(node).didDispatchClickEvent(event, clickHandlingState);
+        inputForLegacyPreActivationBehavior->didDispatchClickEvent(event, clickHandlingState);
 
     // Call default event handlers. While the DOM does have a concept of preventing
     // default handling, the detail of which handlers are called is an internal
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to