Title: [288162] trunk
Revision
288162
Author
[email protected]
Date
2022-01-18 16:27:43 -0800 (Tue, 18 Jan 2022)

Log Message

input.labels doesn't work inside shadow DOM
https://bugs.webkit.org/show_bug.cgi?id=235326

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Rebaseline test that now has one extra passing subtest. This subtest was already passing in both
Gecko and Blink.

* web-platform-tests/html/semantics/forms/the-label-element/label-attributes.sub-expected.txt:

Source/WebCore:

HTMLCollection and LiveNodeList had the concept of "isRootedAtDocument" which meant that
we used the document as root when doing the traversal to find Nodes that belong to the
list/collection. However, when the list's owner is inside a shadow tree, this didn't
work as expected since we would traverse the main document's DOM tree instead of the
shadow tree. To address the issue, I now renamed "isRootedAtDocument" to
"isRootedAtTreeScope" and updated rootNode() to return the owner's tree scope's root
node, instead of the owner's document.

No new tests, rebaselined existing test.

* dom/Document.cpp:
(WebCore::Document::registerNodeListForInvalidation):
(WebCore::Document::registerCollection):
(WebCore::Document::unregisterCollection):
* dom/LiveNodeList.h:
(WebCore::LiveNodeList::rootNode const):
* dom/NameNodeList.h:
* dom/NodeRareData.h:
(WebCore::NodeListsNodeData::adoptDocument):
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::rootTypeFromCollectionType):
* html/HTMLCollection.h:
(WebCore::HTMLCollection::rootNode const):
(WebCore::HTMLCollection::isRootedAtTreeScope const):
(WebCore::HTMLCollection::isRootedAtDocument const): Deleted.
* html/LabelsNodeList.h:
* html/RadioNodeList.cpp:
(WebCore::RadioNodeList::RadioNodeList):
* html/RadioNodeList.h:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (288161 => 288162)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-19 00:25:40 UTC (rev 288161)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-19 00:27:43 UTC (rev 288162)
@@ -1,3 +1,15 @@
+2022-01-18  Chris Dumez  <[email protected]>
+
+        input.labels doesn't work inside shadow DOM
+        https://bugs.webkit.org/show_bug.cgi?id=235326
+
+        Reviewed by Darin Adler.
+
+        Rebaseline test that now has one extra passing subtest. This subtest was already passing in both
+        Gecko and Blink.
+
+        * web-platform-tests/html/semantics/forms/the-label-element/label-attributes.sub-expected.txt:
+
 2022-01-18  Sam Weinig  <[email protected]>
 
         [CSS Color 4] Add support for "Missing"/"none" color components

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-label-element/label-attributes.sub-expected.txt (288161 => 288162)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-label-element/label-attributes.sub-expected.txt	2022-01-19 00:25:40 UTC (rev 288161)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-label-element/label-attributes.sub-expected.txt	2022-01-19 00:27:43 UTC (rev 288162)
@@ -12,7 +12,7 @@
 PASS A labelable element is moved to iframe.
 FAIL A div element which contains labelable element is removed. assert_equals: The number of labels should be 1 after the labelable element is removed but label element is still in the same tree. expected 1 but got 0
 FAIL A labelable element not in a document can label element in the same tree. assert_equals: The number of labels associated with a form control should be the number of label elements for which it is a labeled control. expected 2 but got 0
-FAIL A labelable element inside the shadow DOM. assert_equals: The form control has an ancestor with no explicit associated label, and it is the first labelable descendant. expected 1 but got 0
+PASS A labelable element inside the shadow DOM.
 PASS A form control has an implicit label.
 PASS A form control has no label 1.
 PASS A form control has no label 2.

Modified: trunk/Source/WebCore/ChangeLog (288161 => 288162)


--- trunk/Source/WebCore/ChangeLog	2022-01-19 00:25:40 UTC (rev 288161)
+++ trunk/Source/WebCore/ChangeLog	2022-01-19 00:27:43 UTC (rev 288162)
@@ -1,3 +1,40 @@
+2022-01-18  Chris Dumez  <[email protected]>
+
+        input.labels doesn't work inside shadow DOM
+        https://bugs.webkit.org/show_bug.cgi?id=235326
+
+        Reviewed by Darin Adler.
+
+        HTMLCollection and LiveNodeList had the concept of "isRootedAtDocument" which meant that
+        we used the document as root when doing the traversal to find Nodes that belong to the
+        list/collection. However, when the list's owner is inside a shadow tree, this didn't
+        work as expected since we would traverse the main document's DOM tree instead of the
+        shadow tree. To address the issue, I now renamed "isRootedAtDocument" to
+        "isRootedAtTreeScope" and updated rootNode() to return the owner's tree scope's root
+        node, instead of the owner's document.
+
+        No new tests, rebaselined existing test.
+
+        * dom/Document.cpp:
+        (WebCore::Document::registerNodeListForInvalidation):
+        (WebCore::Document::registerCollection):
+        (WebCore::Document::unregisterCollection):
+        * dom/LiveNodeList.h:
+        (WebCore::LiveNodeList::rootNode const):
+        * dom/NameNodeList.h:
+        * dom/NodeRareData.h:
+        (WebCore::NodeListsNodeData::adoptDocument):
+        * html/HTMLCollection.cpp:
+        (WebCore::HTMLCollection::rootTypeFromCollectionType):
+        * html/HTMLCollection.h:
+        (WebCore::HTMLCollection::rootNode const):
+        (WebCore::HTMLCollection::isRootedAtTreeScope const):
+        (WebCore::HTMLCollection::isRootedAtDocument const): Deleted.
+        * html/LabelsNodeList.h:
+        * html/RadioNodeList.cpp:
+        (WebCore::RadioNodeList::RadioNodeList):
+        * html/RadioNodeList.h:
+
 2022-01-18  Alan Bujtas  <[email protected]>
 
         [LFC][Integration] Use IFC for preferred width computation for inline boxes

Modified: trunk/Source/WebCore/dom/Document.cpp (288161 => 288162)


--- trunk/Source/WebCore/dom/Document.cpp	2022-01-19 00:25:40 UTC (rev 288161)
+++ trunk/Source/WebCore/dom/Document.cpp	2022-01-19 00:27:43 UTC (rev 288162)
@@ -4834,7 +4834,7 @@
 void Document::registerNodeListForInvalidation(LiveNodeList& list)
 {
     m_nodeListAndCollectionCounts[list.invalidationType()]++;
-    if (!list.isRootedAtDocument())
+    if (!list.isRootedAtTreeScope())
         return;
     ASSERT(!list.isRegisteredForInvalidationAtDocument());
     list.setRegisteredForInvalidationAtDocument(true);
@@ -4855,7 +4855,7 @@
 void Document::registerCollection(HTMLCollection& collection)
 {
     m_nodeListAndCollectionCounts[collection.invalidationType()]++;
-    if (collection.isRootedAtDocument())
+    if (collection.isRootedAtTreeScope())
         m_collectionsInvalidatedAtDocument.add(&collection);
 }
 
@@ -4863,7 +4863,7 @@
 {
     ASSERT(m_nodeListAndCollectionCounts[collection.invalidationType()]);
     m_nodeListAndCollectionCounts[collection.invalidationType()]--;
-    if (!collection.isRootedAtDocument())
+    if (!collection.isRootedAtTreeScope())
         return;
 
     m_collectionsInvalidatedAtDocument.remove(&collection);

Modified: trunk/Source/WebCore/dom/LiveNodeList.h (288161 => 288162)


--- trunk/Source/WebCore/dom/LiveNodeList.h	2022-01-19 00:25:40 UTC (rev 288161)
+++ trunk/Source/WebCore/dom/LiveNodeList.h	2022-01-19 00:27:43 UTC (rev 288162)
@@ -43,7 +43,7 @@
     virtual ~LiveNodeList();
 
     virtual bool elementMatches(Element&) const = 0;
-    virtual bool isRootedAtDocument() const = 0;
+    virtual bool isRootedAtTreeScope() const = 0;
 
     NodeListInvalidationType invalidationType() const { return m_invalidationType; }
     ContainerNode& ownerNode() const { return m_ownerNode; }
@@ -139,9 +139,8 @@
 
 inline ContainerNode& LiveNodeList::rootNode() const
 {
-    if (isRootedAtDocument() && m_ownerNode->isConnected())
-        return document();
-
+    if (isRootedAtTreeScope() && m_ownerNode->isInTreeScope())
+        return m_ownerNode->treeScope().rootNode();
     return m_ownerNode;
 }
 

Modified: trunk/Source/WebCore/dom/NameNodeList.h (288161 => 288162)


--- trunk/Source/WebCore/dom/NameNodeList.h	2022-01-19 00:25:40 UTC (rev 288161)
+++ trunk/Source/WebCore/dom/NameNodeList.h	2022-01-19 00:27:43 UTC (rev 288162)
@@ -34,7 +34,7 @@
     virtual ~NameNodeList();
 
     bool elementMatches(Element&) const final;
-    bool isRootedAtDocument() const final { return false; }
+    bool isRootedAtTreeScope() const final { return false; }
 
 private:
     NameNodeList(ContainerNode& rootNode, const AtomString& name);

Modified: trunk/Source/WebCore/dom/NodeRareData.h (288161 => 288162)


--- trunk/Source/WebCore/dom/NodeRareData.h	2022-01-19 00:25:40 UTC (rev 288161)
+++ trunk/Source/WebCore/dom/NodeRareData.h	2022-01-19 00:27:43 UTC (rev 288162)
@@ -198,7 +198,7 @@
             cache->invalidateCacheForDocument(oldDocument);
 
         for (auto& list : m_tagCollectionNSCache.values()) {
-            ASSERT(!list->isRootedAtDocument());
+            ASSERT(!list->isRootedAtTreeScope());
             list->invalidateCacheForDocument(oldDocument);
         }
 

Modified: trunk/Source/WebCore/html/HTMLCollection.cpp (288161 => 288162)


--- trunk/Source/WebCore/html/HTMLCollection.cpp	2022-01-19 00:25:40 UTC (rev 288161)
+++ trunk/Source/WebCore/html/HTMLCollection.cpp	2022-01-19 00:27:43 UTC (rev 288162)
@@ -48,7 +48,7 @@
     case DocumentNamedItems:
     case DocumentAllNamedItems:
     case FormControls:
-        return HTMLCollection::IsRootedAtDocument;
+        return HTMLCollection::IsRootedAtTreeScope;
     case AllDescendants:
     case ByClass:
     case ByTag:

Modified: trunk/Source/WebCore/html/HTMLCollection.h (288161 => 288162)


--- trunk/Source/WebCore/html/HTMLCollection.h	2022-01-19 00:25:40 UTC (rev 288161)
+++ trunk/Source/WebCore/html/HTMLCollection.h	2022-01-19 00:27:43 UTC (rev 288162)
@@ -75,7 +75,7 @@
     Vector<Ref<Element>> namedItems(const AtomString& name) const;
     size_t memoryCost() const override;
 
-    bool isRootedAtDocument() const;
+    bool isRootedAtTreeScope() const;
     NodeListInvalidationType invalidationType() const;
     CollectionType type() const;
     ContainerNode& ownerNode() const;
@@ -99,7 +99,7 @@
 
     void invalidateNamedElementCache(Document&) const;
 
-    enum RootType { IsRootedAtNode, IsRootedAtDocument };
+    enum RootType { IsRootedAtNode, IsRootedAtTreeScope };
     static RootType rootTypeFromCollectionType(CollectionType);
 
     mutable Lock m_namedElementCacheAssignmentLock;
@@ -115,9 +115,8 @@
 
 inline ContainerNode& HTMLCollection::rootNode() const
 {
-    if (isRootedAtDocument() && ownerNode().isConnected())
-        return ownerNode().document();
-
+    if (isRootedAtTreeScope() && ownerNode().isInTreeScope())
+        return ownerNode().treeScope().rootNode();
     return ownerNode();
 }
 
@@ -179,9 +178,9 @@
     return m_namedElementCache ? m_namedElementCache->memoryCost() : 0;
 }
 
-inline bool HTMLCollection::isRootedAtDocument() const
+inline bool HTMLCollection::isRootedAtTreeScope() const
 {
-    return m_rootType == IsRootedAtDocument;
+    return m_rootType == IsRootedAtTreeScope;
 }
 
 inline NodeListInvalidationType HTMLCollection::invalidationType() const

Modified: trunk/Source/WebCore/html/LabelsNodeList.h (288161 => 288162)


--- trunk/Source/WebCore/html/LabelsNodeList.h	2022-01-19 00:25:40 UTC (rev 288161)
+++ trunk/Source/WebCore/html/LabelsNodeList.h	2022-01-19 00:27:43 UTC (rev 288162)
@@ -37,7 +37,7 @@
     virtual ~LabelsNodeList();
 
     bool elementMatches(Element&) const final;
-    bool isRootedAtDocument() const final { return true; }
+    bool isRootedAtTreeScope() const final { return true; }
 
 private:
     explicit LabelsNodeList(LabelableElement&);

Modified: trunk/Source/WebCore/html/RadioNodeList.cpp (288161 => 288162)


--- trunk/Source/WebCore/html/RadioNodeList.cpp	2022-01-19 00:25:40 UTC (rev 288161)
+++ trunk/Source/WebCore/html/RadioNodeList.cpp	2022-01-19 00:27:43 UTC (rev 288162)
@@ -42,7 +42,7 @@
 RadioNodeList::RadioNodeList(ContainerNode& rootNode, const AtomString& name)
     : CachedLiveNodeList(rootNode, InvalidateForFormControls)
     , m_name(name)
-    , m_isRootedAtDocument(is<HTMLFormElement>(rootNode))
+    , m_isRootedAtTreeScope(is<HTMLFormElement>(rootNode))
 {
 }
 

Modified: trunk/Source/WebCore/html/RadioNodeList.h (288161 => 288162)


--- trunk/Source/WebCore/html/RadioNodeList.h	2022-01-19 00:25:40 UTC (rev 288161)
+++ trunk/Source/WebCore/html/RadioNodeList.h	2022-01-19 00:27:43 UTC (rev 288162)
@@ -42,10 +42,10 @@
 
 private:
     RadioNodeList(ContainerNode&, const AtomString& name);
-    bool isRootedAtDocument() const final { return m_isRootedAtDocument; }
+    bool isRootedAtTreeScope() const final { return m_isRootedAtTreeScope; }
 
     AtomString m_name;
-    bool m_isRootedAtDocument;
+    bool m_isRootedAtTreeScope;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to