Title: [287089] trunk
Revision
287089
Author
shvaikal...@gmail.com
Date
2021-12-15 11:37:58 -0800 (Wed, 15 Dec 2021)

Log Message

[WebIDL] onselectionchange IDL attribute should not Document-reflect event listeners
https://bugs.webkit.org/show_bug.cgi?id=234349

Reviewed by Darin Adler.

Source/WebCore:

onselectionchange IDL attribute should not forward event listeners from <body> to Document because:
  a) the attribute is being standardized as a global event handler [1];
  b) "selectionchange" event should be emitted on Document only for selection changes of ranges [2],
     while it should bubble to <body> only when selection changes occur in <input> / <textarea> elements;
  c) HTML spec has no concept of reflecting event handlers to Document, only to Window [3].

While this patch aligns WebKit with Blink and Gecko, event listener forwarding is preserved for
"onselectionchange" content attribute in order to ensure web-compatibility in the following case:
  * a userland <body onselectionchange> listener that relies on `document.activeElement`
    to handle selection changes, including ones that occur in <input> / <textarea> elements.
This is caught by the fast/events/selectionchange-user-initiated.html test as well.

[1] https://w3c.github.io/selection-api/#extensions-to-globaleventhandlers-interface
[2] https://w3c.github.io/selection-api/#selectionchange-event
[3] https://html.spec.whatwg.org/multipage/webappapis.html#window-reflecting-body-element-event-handler-set

Test: fast/dom/event-handler-attributes.html

* html/HTMLBodyElement.cpp:
(WebCore::HTMLBodyElement::parseAttribute):
* html/HTMLBodyElement.idl:

LayoutTests:

* fast/dom/event-handler-attributes-expected.txt:
* fast/dom/event-handler-attributes.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (287088 => 287089)


--- trunk/LayoutTests/ChangeLog	2021-12-15 18:55:46 UTC (rev 287088)
+++ trunk/LayoutTests/ChangeLog	2021-12-15 19:37:58 UTC (rev 287089)
@@ -1,3 +1,13 @@
+2021-12-15  Alexey Shvayka  <ashva...@apple.com>
+
+        [WebIDL] onselectionchange IDL attribute should not Document-reflect event listeners
+        https://bugs.webkit.org/show_bug.cgi?id=234349
+
+        Reviewed by Darin Adler.
+
+        * fast/dom/event-handler-attributes-expected.txt:
+        * fast/dom/event-handler-attributes.html:
+
 2021-12-15  Yoshiaki Jitsukawa  <yoshiaki.jitsuk...@sony.com>
 
         JPEG XL decoder should support understand color profiles

Modified: trunk/LayoutTests/fast/dom/event-handler-attributes-expected.txt (287088 => 287089)


--- trunk/LayoutTests/fast/dom/event-handler-attributes-expected.txt	2021-12-15 18:55:46 UTC (rev 287088)
+++ trunk/LayoutTests/fast/dom/event-handler-attributes-expected.txt	2021-12-15 19:37:58 UTC (rev 287089)
@@ -581,10 +581,6 @@
 PASS testElementAttribute(bodyElement, "storage") is "window"
 PASS testElementAttribute(bodyElement, "unload") is "window"
 
-Event names we expect to be forwarded from <body> element to document)
-
-PASS testElementAttribute(bodyElement, "selectionchange") is "document"
-
 Non-forwarded event names on <body> element
 
 PASS testElementAttribute(bodyElement, "abort") is "target"
@@ -641,6 +637,7 @@
 PASS testElementAttribute(bodyElement, "seeked") is "target"
 PASS testElementAttribute(bodyElement, "seeking") is "target"
 PASS testElementAttribute(bodyElement, "select") is "target"
+FAIL testElementAttribute(bodyElement, "selectionchange") should be target. Was script: target; content: document.
 PASS testElementAttribute(bodyElement, "selectstart") is "target"
 PASS testElementAttribute(bodyElement, "stalled") is "target"
 PASS testElementAttribute(bodyElement, "submit") is "target"
@@ -680,10 +677,6 @@
 PASS testElementAttribute(framesetElement, "storage") is "window"
 PASS testElementAttribute(framesetElement, "unload") is "window"
 
-Event names we expect to be forwarded from <frameset> element to document)
-
-FAIL testElementAttribute(framesetElement, "selectionchange") should be document. Was target.
-
 Non-forwarded event names on <frameset> element
 
 PASS testElementAttribute(framesetElement, "abort") is "target"
@@ -740,6 +733,7 @@
 PASS testElementAttribute(framesetElement, "seeked") is "target"
 PASS testElementAttribute(framesetElement, "seeking") is "target"
 PASS testElementAttribute(framesetElement, "select") is "target"
+PASS testElementAttribute(framesetElement, "selectionchange") is "target"
 PASS testElementAttribute(framesetElement, "selectstart") is "target"
 PASS testElementAttribute(framesetElement, "stalled") is "target"
 PASS testElementAttribute(framesetElement, "submit") is "target"
@@ -942,6 +936,10 @@
 PASS testElementAttribute(nonHTMLElement, "webkittransitionend") is "none"
 PASS testElementAttribute(nonHTMLElement, "wheel") is "none"
 
+onselectionchange IDL attribute doesn't forward event listeners from <body> element to document
+
+PASS document.onselectionchange is null
+
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/dom/event-handler-attributes.html (287088 => 287089)


--- trunk/LayoutTests/fast/dom/event-handler-attributes.html	2021-12-15 18:55:46 UTC (rev 287088)
+++ trunk/LayoutTests/fast/dom/event-handler-attributes.html	2021-12-15 19:37:58 UTC (rev 287089)
@@ -143,10 +143,6 @@
     "unload",
 ];
 
-const bodyElementDocumentForwardedEvents = [
-    "selectionchange",
-];
-
 const nonEventNames = [
     "noneventname",
 ];
@@ -251,7 +247,7 @@
 const documentEvents = arrayUnion(eventsInGlobalEventHandlers, elementAndDocumentEvents, uniqueDocumentEvents);
 const elementEvents = arrayUnion(eventsInGlobalEventHandlers, elementAndDocumentEvents, elementAndWindowEvents, elementBodyAndFrameSetEvents, uniqueElementEvents);
 
-const allEventNames = arrayUnion(windowEvents, documentEvents, elementEvents, bodyElementWindowForwardedEvents, bodyElementDocumentForwardedEvents, nonEventNames);
+const allEventNames = arrayUnion(windowEvents, documentEvents, elementEvents, bodyElementWindowForwardedEvents, nonEventNames);
 
 var sectionOpen = false;
 
@@ -307,14 +303,12 @@
 testArray(arrayDifference(allEventNames, elementEvents), "testElementAttribute(videoElement", "none", "Event names we expect not to be able to set on an element (tested on the &lt;video> element)");
 
 testArray(bodyElementWindowForwardedEvents, "testElementAttribute(bodyElement", "window", "Event names we expect to be forwarded from &lt;body> element to window object)");
-testArray(bodyElementDocumentForwardedEvents, "testElementAttribute(bodyElement", "document", "Event names we expect to be forwarded from &lt;body> element to document)");
-testArray(arrayDifference(elementEvents, arrayUnion(bodyElementWindowForwardedEvents, bodyElementDocumentForwardedEvents)), "testElementAttribute(bodyElement", "target", "Non-forwarded event names on &lt;body> element");
-testArray(arrayDifference(allEventNames, arrayUnion(elementEvents, bodyElementWindowForwardedEvents, bodyElementDocumentForwardedEvents)), "testElementAttribute(bodyElement", "none", "Event names we expect to not be able to set on &lt;body> element");
+testArray(arrayDifference(elementEvents, bodyElementWindowForwardedEvents), "testElementAttribute(bodyElement", "target", "Non-forwarded event names on &lt;body> element");
+testArray(arrayDifference(allEventNames, arrayUnion(elementEvents, bodyElementWindowForwardedEvents)), "testElementAttribute(bodyElement", "none", "Event names we expect to not be able to set on &lt;body> element");
 
 testArray(bodyElementWindowForwardedEvents, "testElementAttribute(framesetElement", "window", "Event names we expect to be forwarded from &lt;frameset> element to window object)");
-testArray(bodyElementDocumentForwardedEvents, "testElementAttribute(framesetElement", "document", "Event names we expect to be forwarded from &lt;frameset> element to document)");
-testArray(arrayDifference(elementEvents, arrayUnion(bodyElementWindowForwardedEvents, bodyElementDocumentForwardedEvents)), "testElementAttribute(framesetElement", "target", "Non-forwarded event names on &lt;frameset> element");
-testArray(arrayDifference(allEventNames, arrayUnion(elementEvents, bodyElementWindowForwardedEvents, bodyElementDocumentForwardedEvents)), "testElementAttribute(framesetElement", "none", "Event names we expect to not be able to set on &lt;frameset> element");
+testArray(arrayDifference(elementEvents, bodyElementWindowForwardedEvents), "testElementAttribute(framesetElement", "target", "Non-forwarded event names on &lt;frameset> element");
+testArray(arrayDifference(allEventNames, arrayUnion(elementEvents, bodyElementWindowForwardedEvents)), "testElementAttribute(framesetElement", "none", "Event names we expect to not be able to set on &lt;frameset> element");
 
 testArray(elementEvents, "testElementAttribute(rectElement", "target", "Event names we expect to be able to set on an element (tested on the SVG &lt;rect> element)");
 testArray(arrayDifference(allEventNames, elementEvents), "testElementAttribute(rectElement", "none", "Event names we expect not to be able to set on an element (tested on the SVG &lt;rect> element)");
@@ -321,6 +315,11 @@
 
 testArray(allEventNames, "testElementAttribute(nonHTMLElement", "none", "Event names on a non-HTML element");
 
+section("onselectionchange IDL attribute doesn't forward event listeners from &lt;body> element to document");
+
+document.body._onselectionchange_ = function() {};
+shouldBe("document.onselectionchange", "null");
+
 endSection();
 
 /*

Modified: trunk/Source/WebCore/ChangeLog (287088 => 287089)


--- trunk/Source/WebCore/ChangeLog	2021-12-15 18:55:46 UTC (rev 287088)
+++ trunk/Source/WebCore/ChangeLog	2021-12-15 19:37:58 UTC (rev 287089)
@@ -1,3 +1,32 @@
+2021-12-15  Alexey Shvayka  <ashva...@apple.com>
+
+        [WebIDL] onselectionchange IDL attribute should not Document-reflect event listeners
+        https://bugs.webkit.org/show_bug.cgi?id=234349
+
+        Reviewed by Darin Adler.
+
+        onselectionchange IDL attribute should not forward event listeners from <body> to Document because:
+          a) the attribute is being standardized as a global event handler [1];
+          b) "selectionchange" event should be emitted on Document only for selection changes of ranges [2],
+             while it should bubble to <body> only when selection changes occur in <input> / <textarea> elements;
+          c) HTML spec has no concept of reflecting event handlers to Document, only to Window [3].
+
+        While this patch aligns WebKit with Blink and Gecko, event listener forwarding is preserved for
+        "onselectionchange" content attribute in order to ensure web-compatibility in the following case:
+          * a userland <body onselectionchange> listener that relies on `document.activeElement`
+            to handle selection changes, including ones that occur in <input> / <textarea> elements.
+        This is caught by the fast/events/selectionchange-user-initiated.html test as well.
+
+        [1] https://w3c.github.io/selection-api/#extensions-to-globaleventhandlers-interface
+        [2] https://w3c.github.io/selection-api/#selectionchange-event
+        [3] https://html.spec.whatwg.org/multipage/webappapis.html#window-reflecting-body-element-event-handler-set
+
+        Test: fast/dom/event-handler-attributes.html
+
+        * html/HTMLBodyElement.cpp:
+        (WebCore::HTMLBodyElement::parseAttribute):
+        * html/HTMLBodyElement.idl:
+
 2021-12-15  Alex Christensen  <achristen...@webkit.org>
 
         Avoid unnecessary allocation and UTF-8 conversion when calling DFABytecodeInterpreter::interpret

Modified: trunk/Source/WebCore/html/HTMLBodyElement.cpp (287088 => 287089)


--- trunk/Source/WebCore/html/HTMLBodyElement.cpp	2021-12-15 18:55:46 UTC (rev 287088)
+++ trunk/Source/WebCore/html/HTMLBodyElement.cpp	2021-12-15 19:37:58 UTC (rev 287089)
@@ -138,6 +138,8 @@
         return;
     }
 
+    // FIXME: Emit "selectionchange" event at <input> / <textarea> elements and remove this special-case.
+    // https://bugs.webkit.org/show_bug.cgi?id=234348
     if (name == onselectionchangeAttr) {
         document().setAttributeEventListener(eventNames().selectionchangeEvent, name, value, mainThreadNormalWorld());
         return;

Modified: trunk/Source/WebCore/html/HTMLBodyElement.idl (287088 => 287089)


--- trunk/Source/WebCore/html/HTMLBodyElement.idl	2021-12-15 18:55:46 UTC (rev 287088)
+++ trunk/Source/WebCore/html/HTMLBodyElement.idl	2021-12-15 19:37:58 UTC (rev 287089)
@@ -42,7 +42,6 @@
     [NotEnumerable, WindowEventHandler, Conditional=MOUSE_FORCE_EVENTS] attribute EventHandler onwebkitmouseforcedown;
     [NotEnumerable, WindowEventHandler, Conditional=MOUSE_FORCE_EVENTS] attribute EventHandler onwebkitmouseforcewillbegin;
     [NotEnumerable, WindowEventHandler, Conditional=MOUSE_FORCE_EVENTS] attribute EventHandler onwebkitmouseforceup;
-    [NotEnumerable, DocumentEventHandler] attribute EventHandler onselectionchange;
 };
 
 HTMLBodyElement includes WindowEventHandlers;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to