Changeset 288162 in webkit


Ignore:
Timestamp:
Jan 18, 2022 4:27:43 PM (6 months ago)
Author:
Chris Dumez
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:
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r288143 r288162  
     12022-01-18  Chris Dumez  <cdumez@apple.com>
     2
     3        input.labels doesn't work inside shadow DOM
     4        https://bugs.webkit.org/show_bug.cgi?id=235326
     5
     6        Reviewed by Darin Adler.
     7
     8        Rebaseline test that now has one extra passing subtest. This subtest was already passing in both
     9        Gecko and Blink.
     10
     11        * web-platform-tests/html/semantics/forms/the-label-element/label-attributes.sub-expected.txt:
     12
    1132022-01-18  Sam Weinig  <weinig@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-label-element/label-attributes.sub-expected.txt

    r267646 r288162  
    1313FAIL 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
    1414FAIL 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
    15 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
     15PASS A labelable element inside the shadow DOM.
    1616PASS A form control has an implicit label.
    1717PASS A form control has no label 1.
  • trunk/Source/WebCore/ChangeLog

    r288159 r288162  
     12022-01-18  Chris Dumez  <cdumez@apple.com>
     2
     3        input.labels doesn't work inside shadow DOM
     4        https://bugs.webkit.org/show_bug.cgi?id=235326
     5
     6        Reviewed by Darin Adler.
     7
     8        HTMLCollection and LiveNodeList had the concept of "isRootedAtDocument" which meant that
     9        we used the document as root when doing the traversal to find Nodes that belong to the
     10        list/collection. However, when the list's owner is inside a shadow tree, this didn't
     11        work as expected since we would traverse the main document's DOM tree instead of the
     12        shadow tree. To address the issue, I now renamed "isRootedAtDocument" to
     13        "isRootedAtTreeScope" and updated rootNode() to return the owner's tree scope's root
     14        node, instead of the owner's document.
     15
     16        No new tests, rebaselined existing test.
     17
     18        * dom/Document.cpp:
     19        (WebCore::Document::registerNodeListForInvalidation):
     20        (WebCore::Document::registerCollection):
     21        (WebCore::Document::unregisterCollection):
     22        * dom/LiveNodeList.h:
     23        (WebCore::LiveNodeList::rootNode const):
     24        * dom/NameNodeList.h:
     25        * dom/NodeRareData.h:
     26        (WebCore::NodeListsNodeData::adoptDocument):
     27        * html/HTMLCollection.cpp:
     28        (WebCore::HTMLCollection::rootTypeFromCollectionType):
     29        * html/HTMLCollection.h:
     30        (WebCore::HTMLCollection::rootNode const):
     31        (WebCore::HTMLCollection::isRootedAtTreeScope const):
     32        (WebCore::HTMLCollection::isRootedAtDocument const): Deleted.
     33        * html/LabelsNodeList.h:
     34        * html/RadioNodeList.cpp:
     35        (WebCore::RadioNodeList::RadioNodeList):
     36        * html/RadioNodeList.h:
     37
    1382022-01-18  Alan Bujtas  <zalan@apple.com>
    239
  • trunk/Source/WebCore/dom/Document.cpp

    r288087 r288162  
    48354835{
    48364836    m_nodeListAndCollectionCounts[list.invalidationType()]++;
    4837     if (!list.isRootedAtDocument())
     4837    if (!list.isRootedAtTreeScope())
    48384838        return;
    48394839    ASSERT(!list.isRegisteredForInvalidationAtDocument());
     
    48564856{
    48574857    m_nodeListAndCollectionCounts[collection.invalidationType()]++;
    4858     if (collection.isRootedAtDocument())
     4858    if (collection.isRootedAtTreeScope())
    48594859        m_collectionsInvalidatedAtDocument.add(&collection);
    48604860}
     
    48644864    ASSERT(m_nodeListAndCollectionCounts[collection.invalidationType()]);
    48654865    m_nodeListAndCollectionCounts[collection.invalidationType()]--;
    4866     if (!collection.isRootedAtDocument())
     4866    if (!collection.isRootedAtTreeScope())
    48674867        return;
    48684868
  • trunk/Source/WebCore/dom/LiveNodeList.h

    r257192 r288162  
    4444
    4545    virtual bool elementMatches(Element&) const = 0;
    46     virtual bool isRootedAtDocument() const = 0;
     46    virtual bool isRootedAtTreeScope() const = 0;
    4747
    4848    NodeListInvalidationType invalidationType() const { return m_invalidationType; }
     
    140140inline ContainerNode& LiveNodeList::rootNode() const
    141141{
    142     if (isRootedAtDocument() && m_ownerNode->isConnected())
    143         return document();
    144 
     142    if (isRootedAtTreeScope() && m_ownerNode->isInTreeScope())
     143        return m_ownerNode->treeScope().rootNode();
    145144    return m_ownerNode;
    146145}
  • trunk/Source/WebCore/dom/NameNodeList.h

    r257192 r288162  
    3535
    3636    bool elementMatches(Element&) const final;
    37     bool isRootedAtDocument() const final { return false; }
     37    bool isRootedAtTreeScope() const final { return false; }
    3838
    3939private:
  • trunk/Source/WebCore/dom/NodeRareData.h

    r285478 r288162  
    199199
    200200        for (auto& list : m_tagCollectionNSCache.values()) {
    201             ASSERT(!list->isRootedAtDocument());
     201            ASSERT(!list->isRootedAtTreeScope());
    202202            list->invalidateCacheForDocument(oldDocument);
    203203        }
  • trunk/Source/WebCore/html/HTMLCollection.cpp

    r277908 r288162  
    4949    case DocumentAllNamedItems:
    5050    case FormControls:
    51         return HTMLCollection::IsRootedAtDocument;
     51        return HTMLCollection::IsRootedAtTreeScope;
    5252    case AllDescendants:
    5353    case ByClass:
  • trunk/Source/WebCore/html/HTMLCollection.h

    r277908 r288162  
    7676    size_t memoryCost() const override;
    7777
    78     bool isRootedAtDocument() const;
     78    bool isRootedAtTreeScope() const;
    7979    NodeListInvalidationType invalidationType() const;
    8080    CollectionType type() const;
     
    100100    void invalidateNamedElementCache(Document&) const;
    101101
    102     enum RootType { IsRootedAtNode, IsRootedAtDocument };
     102    enum RootType { IsRootedAtNode, IsRootedAtTreeScope };
    103103    static RootType rootTypeFromCollectionType(CollectionType);
    104104
     
    116116inline ContainerNode& HTMLCollection::rootNode() const
    117117{
    118     if (isRootedAtDocument() && ownerNode().isConnected())
    119         return ownerNode().document();
    120 
     118    if (isRootedAtTreeScope() && ownerNode().isInTreeScope())
     119        return ownerNode().treeScope().rootNode();
    121120    return ownerNode();
    122121}
     
    180179}
    181180
    182 inline bool HTMLCollection::isRootedAtDocument() const
    183 {
    184     return m_rootType == IsRootedAtDocument;
     181inline bool HTMLCollection::isRootedAtTreeScope() const
     182{
     183    return m_rootType == IsRootedAtTreeScope;
    185184}
    186185
  • trunk/Source/WebCore/html/LabelsNodeList.h

    r257192 r288162  
    3838
    3939    bool elementMatches(Element&) const final;
    40     bool isRootedAtDocument() const final { return true; }
     40    bool isRootedAtTreeScope() const final { return true; }
    4141
    4242private:
  • trunk/Source/WebCore/html/RadioNodeList.cpp

    r257192 r288162  
    4343    : CachedLiveNodeList(rootNode, InvalidateForFormControls)
    4444    , m_name(name)
    45     , m_isRootedAtDocument(is<HTMLFormElement>(rootNode))
     45    , m_isRootedAtTreeScope(is<HTMLFormElement>(rootNode))
    4646{
    4747}
  • trunk/Source/WebCore/html/RadioNodeList.h

    r257192 r288162  
    4343private:
    4444    RadioNodeList(ContainerNode&, const AtomString& name);
    45     bool isRootedAtDocument() const final { return m_isRootedAtDocument; }
     45    bool isRootedAtTreeScope() const final { return m_isRootedAtTreeScope; }
    4646
    4747    AtomString m_name;
    48     bool m_isRootedAtDocument;
     48    bool m_isRootedAtTreeScope;
    4949};
    5050
Note: See TracChangeset for help on using the changeset viewer.