Changeset 206285 in webkit


Ignore:
Timestamp:
Sep 22, 2016 6:54:05 PM (8 years ago)
Author:
Chris Dumez
Message:

[ShadowDOM] Add support for Node.getRootNode(options)
https://bugs.webkit.org/show_bug.cgi?id=162457

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline existing W3C DOM tests now that more checks are passing.

  • web-platform-tests/dom/interfaces-expected.txt:
  • web-platform-tests/dom/nodes/rootNode-expected.txt:

Source/WebCore:

Add support for Node.getRootNode(options):

No new tests, rebaselined existing tests.

  • dom/EventPath.cpp:

(WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter):
(WebCore::RelatedNodeRetargeter::checkConsistency):

  • dom/Node.cpp:

(WebCore::Node::rootNode):
(WebCore::Node::shadowIncludingRoot):
(WebCore::Node::getRootNode):

  • dom/Node.h:
  • dom/Node.idl:
  • editing/Editor.cpp:

(WebCore::correctSpellcheckingPreservingTextCheckingParagraph):

  • xml/XPathPath.cpp:

(WebCore::XPath::LocationPath::evaluate):

Location:
trunk
Files:
10 edited

Legend:

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

    r206266 r206285  
     12016-09-22  Chris Dumez  <cdumez@apple.com>
     2
     3        [ShadowDOM] Add support for Node.getRootNode(options)
     4        https://bugs.webkit.org/show_bug.cgi?id=162457
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Rebaseline existing W3C DOM tests now that more checks are passing.
     9
     10        * web-platform-tests/dom/interfaces-expected.txt:
     11        * web-platform-tests/dom/nodes/rootNode-expected.txt:
     12
    1132016-09-22  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt

    r206260 r206285  
    193193PASS Node interface: attribute isConnected
    194194PASS Node interface: attribute ownerDocument
    195 FAIL Node interface: operation getRootNode(GetRootNodeOptions) assert_own_property: interface prototype object missing non-static operation expected property "getRootNode" missing
     195PASS Node interface: operation getRootNode(GetRootNodeOptions)
    196196PASS Node interface: attribute parentNode
    197197PASS Node interface: attribute parentElement
     
    350350PASS Node interface: new Document() must inherit property "isConnected" with the proper type (15)
    351351PASS Node interface: new Document() must inherit property "ownerDocument" with the proper type (16)
    352 FAIL Node interface: new Document() must inherit property "getRootNode" with the proper type (17) assert_inherits: property "getRootNode" not found in prototype chain
    353 FAIL Node interface: calling getRootNode(GetRootNodeOptions) on new Document() with too few arguments must throw TypeError assert_inherits: property "getRootNode" not found in prototype chain
     352PASS Node interface: new Document() must inherit property "getRootNode" with the proper type (17)
     353PASS Node interface: calling getRootNode(GetRootNodeOptions) on new Document() with too few arguments must throw TypeError
    354354PASS Node interface: new Document() must inherit property "parentNode" with the proper type (18)
    355355PASS Node interface: new Document() must inherit property "parentElement" with the proper type (19)
     
    482482PASS Node interface: xmlDoc must inherit property "isConnected" with the proper type (15)
    483483PASS Node interface: xmlDoc must inherit property "ownerDocument" with the proper type (16)
    484 FAIL Node interface: xmlDoc must inherit property "getRootNode" with the proper type (17) assert_inherits: property "getRootNode" not found in prototype chain
    485 FAIL Node interface: calling getRootNode(GetRootNodeOptions) on xmlDoc with too few arguments must throw TypeError assert_inherits: property "getRootNode" not found in prototype chain
     484PASS Node interface: xmlDoc must inherit property "getRootNode" with the proper type (17)
     485PASS Node interface: calling getRootNode(GetRootNodeOptions) on xmlDoc with too few arguments must throw TypeError
    486486PASS Node interface: xmlDoc must inherit property "parentNode" with the proper type (18)
    487487PASS Node interface: xmlDoc must inherit property "parentElement" with the proper type (19)
     
    590590PASS Node interface: document.doctype must inherit property "isConnected" with the proper type (15)
    591591PASS Node interface: document.doctype must inherit property "ownerDocument" with the proper type (16)
    592 FAIL Node interface: document.doctype must inherit property "getRootNode" with the proper type (17) assert_inherits: property "getRootNode" not found in prototype chain
    593 FAIL Node interface: calling getRootNode(GetRootNodeOptions) on document.doctype with too few arguments must throw TypeError assert_inherits: property "getRootNode" not found in prototype chain
     592PASS Node interface: document.doctype must inherit property "getRootNode" with the proper type (17)
     593PASS Node interface: calling getRootNode(GetRootNodeOptions) on document.doctype with too few arguments must throw TypeError
    594594PASS Node interface: document.doctype must inherit property "parentNode" with the proper type (18)
    595595PASS Node interface: document.doctype must inherit property "parentElement" with the proper type (19)
     
    686686PASS Node interface: document.createDocumentFragment() must inherit property "isConnected" with the proper type (15)
    687687PASS Node interface: document.createDocumentFragment() must inherit property "ownerDocument" with the proper type (16)
    688 FAIL Node interface: document.createDocumentFragment() must inherit property "getRootNode" with the proper type (17) assert_inherits: property "getRootNode" not found in prototype chain
    689 FAIL Node interface: calling getRootNode(GetRootNodeOptions) on document.createDocumentFragment() with too few arguments must throw TypeError assert_inherits: property "getRootNode" not found in prototype chain
     688PASS Node interface: document.createDocumentFragment() must inherit property "getRootNode" with the proper type (17)
     689PASS Node interface: calling getRootNode(GetRootNodeOptions) on document.createDocumentFragment() with too few arguments must throw TypeError
    690690PASS Node interface: document.createDocumentFragment() must inherit property "parentNode" with the proper type (18)
    691691PASS Node interface: document.createDocumentFragment() must inherit property "parentElement" with the proper type (19)
     
    893893PASS Node interface: element must inherit property "isConnected" with the proper type (15)
    894894PASS Node interface: element must inherit property "ownerDocument" with the proper type (16)
    895 FAIL Node interface: element must inherit property "getRootNode" with the proper type (17) assert_inherits: property "getRootNode" not found in prototype chain
    896 FAIL Node interface: calling getRootNode(GetRootNodeOptions) on element with too few arguments must throw TypeError assert_inherits: property "getRootNode" not found in prototype chain
     895PASS Node interface: element must inherit property "getRootNode" with the proper type (17)
     896PASS Node interface: calling getRootNode(GetRootNodeOptions) on element with too few arguments must throw TypeError
    897897PASS Node interface: element must inherit property "parentNode" with the proper type (18)
    898898PASS Node interface: element must inherit property "parentElement" with the proper type (19)
     
    993993PASS Node interface: document.querySelector("[id]").attributes[0] must inherit property "isConnected" with the proper type (15)
    994994PASS Node interface: document.querySelector("[id]").attributes[0] must inherit property "ownerDocument" with the proper type (16)
    995 FAIL Node interface: document.querySelector("[id]").attributes[0] must inherit property "getRootNode" with the proper type (17) assert_inherits: property "getRootNode" not found in prototype chain
    996 FAIL Node interface: calling getRootNode(GetRootNodeOptions) on document.querySelector("[id]").attributes[0] with too few arguments must throw TypeError assert_inherits: property "getRootNode" not found in prototype chain
     995PASS Node interface: document.querySelector("[id]").attributes[0] must inherit property "getRootNode" with the proper type (17)
     996PASS Node interface: calling getRootNode(GetRootNodeOptions) on document.querySelector("[id]").attributes[0] with too few arguments must throw TypeError
    997997PASS Node interface: document.querySelector("[id]").attributes[0] must inherit property "parentNode" with the proper type (18)
    998998PASS Node interface: document.querySelector("[id]").attributes[0] must inherit property "parentElement" with the proper type (19)
     
    11121112PASS Node interface: document.createTextNode("abc") must inherit property "isConnected" with the proper type (15)
    11131113PASS Node interface: document.createTextNode("abc") must inherit property "ownerDocument" with the proper type (16)
    1114 FAIL Node interface: document.createTextNode("abc") must inherit property "getRootNode" with the proper type (17) assert_inherits: property "getRootNode" not found in prototype chain
    1115 FAIL Node interface: calling getRootNode(GetRootNodeOptions) on document.createTextNode("abc") with too few arguments must throw TypeError assert_inherits: property "getRootNode" not found in prototype chain
     1114PASS Node interface: document.createTextNode("abc") must inherit property "getRootNode" with the proper type (17)
     1115PASS Node interface: calling getRootNode(GetRootNodeOptions) on document.createTextNode("abc") with too few arguments must throw TypeError
    11161116PASS Node interface: document.createTextNode("abc") must inherit property "parentNode" with the proper type (18)
    11171117PASS Node interface: document.createTextNode("abc") must inherit property "parentElement" with the proper type (19)
     
    12131213PASS Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "isConnected" with the proper type (15)
    12141214PASS Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "ownerDocument" with the proper type (16)
    1215 FAIL Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "getRootNode" with the proper type (17) assert_inherits: property "getRootNode" not found in prototype chain
    1216 FAIL Node interface: calling getRootNode(GetRootNodeOptions) on xmlDoc.createProcessingInstruction("abc", "def") with too few arguments must throw TypeError assert_inherits: property "getRootNode" not found in prototype chain
     1215PASS Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "getRootNode" with the proper type (17)
     1216PASS Node interface: calling getRootNode(GetRootNodeOptions) on xmlDoc.createProcessingInstruction("abc", "def") with too few arguments must throw TypeError
    12171217PASS Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "parentNode" with the proper type (18)
    12181218PASS Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "parentElement" with the proper type (19)
     
    13071307PASS Node interface: document.createComment("abc") must inherit property "isConnected" with the proper type (15)
    13081308PASS Node interface: document.createComment("abc") must inherit property "ownerDocument" with the proper type (16)
    1309 FAIL Node interface: document.createComment("abc") must inherit property "getRootNode" with the proper type (17) assert_inherits: property "getRootNode" not found in prototype chain
    1310 FAIL Node interface: calling getRootNode(GetRootNodeOptions) on document.createComment("abc") with too few arguments must throw TypeError assert_inherits: property "getRootNode" not found in prototype chain
     1309PASS Node interface: document.createComment("abc") must inherit property "getRootNode" with the proper type (17)
     1310PASS Node interface: calling getRootNode(GetRootNodeOptions) on document.createComment("abc") with too few arguments must throw TypeError
    13111311PASS Node interface: document.createComment("abc") must inherit property "parentNode" with the proper type (18)
    13121312PASS Node interface: document.createComment("abc") must inherit property "parentElement" with the proper type (19)
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/rootNode-expected.txt

    r206260 r206285  
    11
    2 FAIL getRootNode() must return the context object when it does not have any parent element.getRootNode is not a function. (In 'element.getRootNode()', 'element.getRootNode' is undefined)
    3 FAIL getRootNode() must return the parent node of the context object when the context object has a single ancestor not in a document element.getRootNode is not a function. (In 'element.getRootNode()', 'element.getRootNode' is undefined)
    4 FAIL getRootNode() must return the document when a node is in document element.getRootNode is not a function. (In 'element.getRootNode()', 'element.getRootNode' is undefined)
    5 FAIL getRootNode() must return a document fragment when a node is in the fragment element.getRootNode is not a function. (In 'element.getRootNode()', 'element.getRootNode' is undefined)
     2PASS getRootNode() must return the context object when it does not have any parent
     3PASS getRootNode() must return the parent node of the context object when the context object has a single ancestor not in a document
     4PASS getRootNode() must return the document when a node is in document
     5PASS getRootNode() must return a document fragment when a node is in the fragment
    66
  • trunk/Source/WebCore/ChangeLog

    r206280 r206285  
     12016-09-22  Chris Dumez  <cdumez@apple.com>
     2
     3        [ShadowDOM] Add support for Node.getRootNode(options)
     4        https://bugs.webkit.org/show_bug.cgi?id=162457
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Add support for Node.getRootNode(options):
     9        - https://dom.spec.whatwg.org/#dom-node-getrootnode
     10
     11        No new tests, rebaselined existing tests.
     12
     13        * dom/EventPath.cpp:
     14        (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter):
     15        (WebCore::RelatedNodeRetargeter::checkConsistency):
     16        * dom/Node.cpp:
     17        (WebCore::Node::rootNode):
     18        (WebCore::Node::shadowIncludingRoot):
     19        (WebCore::Node::getRootNode):
     20        * dom/Node.h:
     21        * dom/Node.idl:
     22        * editing/Editor.cpp:
     23        (WebCore::correctSpellcheckingPreservingTextCheckingParagraph):
     24        * xml/XPathPath.cpp:
     25        (WebCore::XPath::LocationPath::evaluate):
     26
    1272016-09-22  Brady Eidson  <beidson@apple.com>
    228
  • trunk/Source/WebCore/dom/EventPath.cpp

    r202953 r206285  
    291291        Node& targetAncestorInDocumentScope = i ? *downcast<ShadowRoot>(m_ancestorTreeScopes[i - 1]->rootNode()).shadowHost() : target;
    292292        Node& relatedNodeAncestorInDocumentScope = j ? *downcast<ShadowRoot>(targetTreeScopeAncestors[j - 1]->rootNode()).shadowHost() : relatedNode;
    293         if (targetAncestorInDocumentScope.rootNode() != relatedNodeAncestorInDocumentScope.rootNode()) {
     293        if (&targetAncestorInDocumentScope.rootNode() != &relatedNodeAncestorInDocumentScope.rootNode()) {
    294294            m_hasDifferentTreeRoot = true;
    295295            m_retargetedRelatedNode = moveOutOfAllShadowRoots(relatedNode);
     
    366366    Node& base = currentTarget;
    367367    for (Node* targetAncestor = &m_relatedNode; targetAncestor; targetAncestor = targetAncestor->parentOrShadowHostNode()) {
    368         if (targetAncestor->rootNode()->containsIncludingShadowDOM(&base)) {
     368        if (targetAncestor->rootNode().containsIncludingShadowDOM(&base)) {
    369369            ASSERT(m_retargetedRelatedNode == targetAncestor);
    370370            return;
  • trunk/Source/WebCore/dom/Node.cpp

    r205468 r206285  
    11641164}
    11651165
    1166 Node* Node::rootNode() const
     1166Node& Node::rootNode() const
    11671167{
    11681168    if (isInTreeScope())
    1169         return &treeScope().rootNode();
     1169        return treeScope().rootNode();
    11701170
    11711171    Node* node = const_cast<Node*>(this);
     
    11731173    for (; node; node = node->parentNode())
    11741174        highest = node;
    1175     return highest;
     1175    return *highest;
     1176}
     1177
     1178// https://dom.spec.whatwg.org/#concept-shadow-including-root
     1179Node& Node::shadowIncludingRoot() const
     1180{
     1181    auto& root = rootNode();
     1182    if (!is<ShadowRoot>(root))
     1183        return root;
     1184    auto* host = downcast<ShadowRoot>(root).host();
     1185    return host ? host->shadowIncludingRoot() : root;
     1186}
     1187
     1188Node& Node::getRootNode(const GetRootNodeOptions& options) const
     1189{
     1190    return options.composed ? shadowIncludingRoot() : rootNode();
    11761191}
    11771192
  • trunk/Source/WebCore/dom/Node.h

    r205468 r206285  
    274274    Element* parentOrShadowHostElement() const;
    275275    void setParentNode(ContainerNode*);
    276     Node* rootNode() const;
     276    Node& rootNode() const;
     277    Node& shadowIncludingRoot() const;
     278
     279    struct GetRootNodeOptions {
     280        bool composed;
     281    };
     282    Node& getRootNode(const GetRootNodeOptions&) const;
    277283
    278284    // Use when it's guaranteed to that shadowHost is null.
  • trunk/Source/WebCore/dom/Node.idl

    r205280 r206285  
    9191    boolean contains(Node? other);
    9292
     93    [EnabledAtRuntime=ShadowDOM] Node getRootNode(optional GetRootNodeOptions options);
    9394    [EnabledAtRuntime=ShadowDOM, ImplementedAs=inDocument] readonly attribute boolean isConnected;
    9495
    9596    readonly attribute Element parentElement;
    9697};
     98
     99dictionary GetRootNodeOptions {
     100  boolean composed = false;
     101};
  • trunk/Source/WebCore/editing/Editor.cpp

    r205870 r206285  
    24712471static void correctSpellcheckingPreservingTextCheckingParagraph(TextCheckingParagraph& paragraph, PassRefPtr<Range> rangeToReplace, const String& replacement, int resultLocation, int resultLength)
    24722472{
    2473     ContainerNode* scope = downcast<ContainerNode>(paragraph.paragraphRange()->startContainer().rootNode());
     2473    auto& scope = downcast<ContainerNode>(paragraph.paragraphRange()->startContainer().rootNode());
    24742474
    24752475    size_t paragraphLocation;
    24762476    size_t paragraphLength;
    2477     TextIterator::getLocationAndLengthFromRange(scope, paragraph.paragraphRange().get(), paragraphLocation, paragraphLength);
     2477    TextIterator::getLocationAndLengthFromRange(&scope, paragraph.paragraphRange().get(), paragraphLocation, paragraphLength);
    24782478
    24792479    applyCommand(SpellingCorrectionCommand::create(rangeToReplace, replacement));
     
    24822482    // See <rdar://10305315>, http://webkit.org/b/89526.
    24832483
    2484     RefPtr<Range> newParagraphRange = TextIterator::rangeFromLocationAndLength(scope, paragraphLocation, paragraphLength + replacement.length() - resultLength);
     2484    RefPtr<Range> newParagraphRange = TextIterator::rangeFromLocationAndLength(&scope, paragraphLocation, paragraphLength + replacement.length() - resultLength);
    24852485
    24862486    paragraph = TextCheckingParagraph(TextIterator::subrange(newParagraphRange.get(), resultLocation, replacement.length()), newParagraphRange);
  • trunk/Source/WebCore/xml/XPathPath.cpp

    r197887 r206285  
    9090    Node* context = evaluationContext.node.get();
    9191    if (m_isAbsolute && !context->isDocumentNode())
    92         context = context->rootNode();
     92        context = &context->rootNode();
    9393
    9494    NodeSet nodes;
Note: See TracChangeset for help on using the changeset viewer.