Changeset 197887 in webkit


Ignore:
Timestamp:
Mar 9, 2016 2:29:33 PM (8 years ago)
Author:
rniwa@webkit.org
Message:

Rename Node.treeRoot to rootNode and turn it on by default
https://bugs.webkit.org/show_bug.cgi?id=155226

Reviewed by Antonio Gomes.
Source/WebCore:

Node.prototype.treeRoot has been merged into DOM spec from Shadow DOM spec and renamed to rootNode:
https://dom.spec.whatwg.org/#dom-node-rootnode

Rename the method and expose it unconditionally on Node.prototype.

Tests: fast/dom/Node/rootNode.html

fast/shadow-dom/Node-interface-rootNode.html

  • dom/ContainerNode.h:

(WebCore::Node::highestAncestor): Deleted. There is no need for this function to be inlined.

  • dom/Document.h: Now that both TreeScope and Node defines rootNode, we need to pick either.

Here, we pick TreeScope's definition since Document is by definition always in a document so there is
no need to even check inTreeScope().

  • dom/Node.cpp:

(WebCore::Node::rootNode): Moved here. Also added a fast path for when "this" node is in a document
or a shadow root since TreeScope stores its root node as a member variable (m_rootNode).

  • dom/Node.h:
  • dom/Node.idl: Renamed the method and removed Conditional=SHADOW_DOM.
  • dom/ShadowRoot.h: Similar to the change in Document.h. See above.
  • editing/Editor.cpp:

(WebCore::correctSpellcheckingPreservingTextCheckingParagraph): Use rootNode instead of free function
defined in htmlediting.cpp, which was removed in this patch.

  • editing/htmlediting.cpp:

(WebCore::highestAncestor): Deleted.

  • editing/htmlediting.h:
  • html/FormAssociatedElement.cpp:

(WebCore::computeRootNode): Added.
(WebCore::FormAssociatedElement::removedFrom): We can't use Node::rootNode here because this function
is called in the middle of removing a subtree, and some associated form element's inDocument flag may
not have been updated yet. So use computeRootNode to manually find the highest ancestor.
(WebCore::FormAssociatedElement::formRemovedFromTree): Ditto.

  • xml/XPathPath.cpp:

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

LayoutTests:


Split Node-interface-treeRoot.html into two pieces, the one that doesn't invoke shadow DOM and the other that tests
shadow DOM related cases. I intend to upstream these tests to W3C at some point so keep them in testharness.js form.

  • fast/dom/Node/rootNode-expected.txt: Added.
  • fast/dom/Node/rootNode.html: Copied from LayoutTests/fast/shadow-dom/Node-interface-treeRoot.html.
  • fast/shadow-dom/Node-interface-rootNode-expected.txt: Renamed from Node-interface-treeRoot-expected.txt.
  • fast/shadow-dom/Node-interface-rootNode.html: Renamed from LayoutTests/fast/shadow-dom/Node-interface-treeRoot.html.
  • js/dom/dom-static-property-for-in-iteration-expected.txt:
  • platform/efl/js/dom/dom-static-property-for-in-iteration-expected.txt:
  • platform/gtk/js/dom/dom-static-property-for-in-iteration-expected.txt:
Location:
trunk
Files:
1 added
16 edited
1 copied
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r197869 r197887  
     12016-03-09  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Rename Node.treeRoot to rootNode and turn it on by default
     4        https://bugs.webkit.org/show_bug.cgi?id=155226
     5
     6        Reviewed by Antonio Gomes.
     7       
     8        Split Node-interface-treeRoot.html into two pieces, the one that doesn't invoke shadow DOM and the other that tests
     9        shadow DOM related cases. I intend to upstream these tests to W3C at some point so keep them in testharness.js form.
     10
     11        * fast/dom/Node/rootNode-expected.txt: Added.
     12        * fast/dom/Node/rootNode.html: Copied from LayoutTests/fast/shadow-dom/Node-interface-treeRoot.html.
     13        * fast/shadow-dom/Node-interface-rootNode-expected.txt: Renamed from Node-interface-treeRoot-expected.txt.
     14        * fast/shadow-dom/Node-interface-rootNode.html: Renamed from LayoutTests/fast/shadow-dom/Node-interface-treeRoot.html.
     15        * js/dom/dom-static-property-for-in-iteration-expected.txt:
     16        * platform/efl/js/dom/dom-static-property-for-in-iteration-expected.txt:
     17        * platform/gtk/js/dom/dom-static-property-for-in-iteration-expected.txt:
     18
    1192016-03-09  Michael Saboff  <msaboff@apple.com>
    220
  • trunk/LayoutTests/fast/dom/Node/rootNode.html

    r197834 r197887  
    22<html>
    33<head>
    4 <title>Shadow DOM: Extensions to Node interface</title>
     4<title>DOM: 4.4. Interface Node</title>
    55<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
    6 <meta name="assert" content="Node interface must have treeRoot attribute">
    7 <link rel="help" href="http://w3c.github.io/webcomponents/spec/shadow/#extensions-to-node-interface">
    8 <script src="../../resources/testharness.js"></script>
    9 <script src="../../resources/testharnessreport.js"></script>
    10 <link rel='stylesheet' href='../../resources/testharness.css'>
     6<meta name="assert" content="Node interface must have rootNode attribute">
     7<link rel="help" href="https://dom.spec.whatwg.org/#dom-node-rootnode">
     8<script src="../../../resources/testharness.js"></script>
     9<script src="../../../resources/testharnessreport.js"></script>
     10<link rel='stylesheet' href='../../../resources/testharness.css'>
    1111</head>
    1212<body>
     
    1515
    1616test(function () {
    17     assert_true('treeRoot' in Node.prototype, 'treeRoot must be defined on Node.prototype');
    18     assert_true('treeRoot' in document.createElement('div'), 'treeRoot must be defined on a div element');
    19     assert_true('treeRoot' in document.createTextNode(''), 'assignedSlot must be defined on a text node');
    20     assert_true('treeRoot' in document.createComment(''), 'assignedSlot must be defined on a comment node');
    21     assert_true('treeRoot' in document.createProcessingInstruction('target', 'data'), 'assignedSlot must be defined on a processing instruction node');
    22     assert_true('treeRoot' in document, 'assignedSlot must be defined on a document node');
    23     assert_true('treeRoot' in document.createElement('div').attachShadow({mode: 'closed'}), 'treeRoot must be defined on a closed shadow root element');
    24     assert_true('treeRoot' in document.createElement('div').attachShadow({mode: 'open'}), 'treeRoot must be defined on a open shadow root element');
    25 }, 'treeRoot attribute must be defined on Node interface');
     17    assert_true('rootNode' in Node.prototype, 'rootNode must be defined on Node.prototype');
     18    assert_true('rootNode' in document.createElement('div'), 'rootNode must be defined on a div element');
     19    assert_true('rootNode' in document.createTextNode(''), 'rootNode must be defined on a text node');
     20    assert_true('rootNode' in document.createComment(''), 'rootNode must be defined on a comment node');
     21    assert_true('rootNode' in document.createProcessingInstruction('target', 'data'), 'rootNode must be defined on a processing instruction node');
     22    assert_true('rootNode' in document, 'rootNode must be defined on a document node');
     23}, 'rootNode attribute must be defined on Node interface');
    2624
    2725test(function () {
    2826    var element = document.createElement('div');
    29     assert_equals(element.treeRoot, element, 'treeRoot on an element without a parent must return the element itself');
     27    assert_equals(element.rootNode, element, 'rootNode on an element without a parent must return the element itself');
    3028
    3129    var text = document.createTextNode('');
    32     assert_equals(text.treeRoot, text, 'treeRoot on a text node without a parent must return the text node itself');
     30    assert_equals(text.rootNode, text, 'rootNode on a text node without a parent must return the text node itself');
    3331
    3432    var processingInstruction = document.createProcessingInstruction('target', 'data');
    35     assert_equals(processingInstruction.treeRoot, processingInstruction, 'treeRoot on a processing instruction node without a parent must return the processing instruction node itself');
     33    assert_equals(processingInstruction.rootNode, processingInstruction, 'rootNode on a processing instruction node without a parent must return the processing instruction node itself');
    3634
    37     assert_equals(document.treeRoot, document, 'treeRoot on a document node must return the document itself');
     35    assert_equals(document.rootNode, document, 'rootNode on a document node must return the document itself');
    3836
    39     var closedShadowRoot = document.createElement('div').attachShadow({mode: 'closed'});
    40     assert_equals(closedShadowRoot.treeRoot, closedShadowRoot, 'treeRoot on a closed shadow root must return the shadow root itself');
    41 
    42     var openShadowRoot = document.createElement('div').attachShadow({mode: 'open'});
    43     assert_equals(openShadowRoot.treeRoot, openShadowRoot, 'treeRoot on a open shadow root must return the shadow root itself');
    44 }, 'treeRoot attribute must return the context object when it does not have any parent');
     37}, 'rootNode attribute must return the context object when it does not have any parent');
    4538
    4639test(function () {
     
    4942    var element = document.createElement('div');
    5043    parent.appendChild(element);
    51     assert_equals(element.treeRoot, parent, 'treeRoot on an element with a single ancestor must return the parent node');
     44    assert_equals(element.rootNode, parent, 'rootNode on an element with a single ancestor must return the parent node');
    5245
    5346    var text = document.createTextNode('');
    5447    parent.appendChild(text);
    55     assert_equals(text.treeRoot, parent, 'treeRoot on a text node with a single ancestor must return the parent node');
     48    assert_equals(text.rootNode, parent, 'rootNode on a text node with a single ancestor must return the parent node');
    5649
    5750    var processingInstruction = document.createProcessingInstruction('target', 'data');
    5851    parent.appendChild(processingInstruction)
    59     assert_equals(processingInstruction.treeRoot, parent, 'treeRoot on a processing instruction node with a single ancestor must return the parent node');
     52    assert_equals(processingInstruction.rootNode, parent, 'rootNode on a processing instruction node with a single ancestor must return the parent node');
    6053
    61     var hostWithClosedShadowRoot = document.createElement('div');
    62     parent.appendChild(hostWithClosedShadowRoot);
    63     var closedShadowRoot = hostWithClosedShadowRoot.attachShadow({mode: 'closed'});
    64     assert_equals(closedShadowRoot.treeRoot, closedShadowRoot, 'treeRoot on a closed shadow root with a single ancestor on its host must return the shadow root itself');
    65 
    66     var hostWithOpenShadowRoot = document.createElement('div');
    67     parent.appendChild(hostWithOpenShadowRoot);
    68     var openShadowRoot = hostWithOpenShadowRoot.attachShadow({mode: 'open'});
    69     assert_equals(openShadowRoot.treeRoot, openShadowRoot, 'treeRoot on a open shadow root with a single ancestor on its host must return the shadow root itself');
    70 }, 'treeRoot attribute must return the parent node of the context object when the context object has a single ancestor not in a document');
     54}, 'rootNode attribute must return the parent node of the context object when the context object has a single ancestor not in a document');
    7155
    7256test(function () {
     
    7660    var element = document.createElement('div');
    7761    parent.appendChild(element);
    78     assert_equals(element.treeRoot, document, 'treeRoot on an element inside a document must return the document');
     62    assert_equals(element.rootNode, document, 'rootNode on an element inside a document must return the document');
    7963
    8064    var text = document.createTextNode('');
    8165    parent.appendChild(text);
    82     assert_equals(text.treeRoot, document, 'treeRoot on a text node inside a document must return the document');
     66    assert_equals(text.rootNode, document, 'rootNode on a text node inside a document must return the document');
    8367
    8468    var processingInstruction = document.createProcessingInstruction('target', 'data');
    8569    parent.appendChild(processingInstruction)
    86     assert_equals(processingInstruction.treeRoot, document, 'treeRoot on a processing instruction node inside a document must return the document');
    87 }, 'treeRoot attribute must return the document when a node is in document and not in a shadow tree');
     70    assert_equals(processingInstruction.rootNode, document, 'rootNode on a processing instruction node inside a document must return the document');
     71}, 'rootNode attribute must return the document when a node is in document');
    8872
    89 function testTreeRootOnNodeInsideShadowTree(mode) {
    90     test(function () {
    91         var host = document.createElement('div');
    92         document.body.appendChild(host);
     73test(function () {
     74    var fragment = document.createDocumentFragment();
     75    var parent = document.createElement('div');
     76    fragment.appendChild(parent);
    9377
    94         var shadowRoot = host.attachShadow({mode: mode});
    95         var parent = document.createElement('p');
    96         shadowRoot.appendChild(parent);
     78    var element = document.createElement('div');
     79    parent.appendChild(element);
     80    assert_equals(element.rootNode, fragment, 'rootNode on an element inside a document fragment must return the fragment');
    9781
    98         var element = document.createElement('span');
    99         parent.appendChild(element);
    100         assert_equals(element.treeRoot, shadowRoot, 'treeRoot on an element inside a shadow tree must return the shadow root');
     82    var text = document.createTextNode('');
     83    parent.appendChild(text);
     84    assert_equals(text.rootNode, fragment, 'rootNode on a text node inside a document fragment must return the fragment');
    10185
    102         var text = document.createTextNode('');
    103         parent.appendChild(text);
    104         assert_equals(text.treeRoot, shadowRoot, 'treeRoot on a text node inside a shadow tree must return the shadow root');
    105 
    106         var processingInstruction = document.createProcessingInstruction('target', 'data');
    107         parent.appendChild(processingInstruction);
    108         assert_equals(processingInstruction.treeRoot, shadowRoot, 'treeRoot on a processing instruction node inside a shadow tree must return the shadow root');
    109     }, 'treeRoot attribute must return the ' + mode + ' shadow root of the context object when the shadow host is in a document');
    110 }
    111 
    112 testTreeRootOnNodeInsideShadowTree('open');
    113 testTreeRootOnNodeInsideShadowTree('closed');
    114 
    115 function testTreeRootOnNodeInsideNestedShadowTree(outerMode, innerMode) {
    116     test(function () {
    117         var outerHost = document.createElement('div');
    118         document.body.appendChild(outerHost);
    119         var outerShadowRoot = outerHost.attachShadow({mode: outerMode});
    120 
    121         var innerHost = document.createElement('section');
    122         outerShadowRoot.appendChild(innerHost);
    123         var innerShadowRoot = innerHost.attachShadow({mode: innerMode});
    124 
    125         var parent = document.createElement('p');
    126         innerShadowRoot.appendChild(parent);
    127 
    128         var element = document.createElement('span');
    129         parent.appendChild(element);
    130         assert_equals(element.treeRoot, innerShadowRoot, 'treeRoot on an element inside a shadow tree must return its root node');
    131 
    132         var text = document.createTextNode('');
    133         parent.appendChild(text);
    134         assert_equals(text.treeRoot, innerShadowRoot, 'treeRoot on a text node inside a shadow tree must return its root node');
    135 
    136         var processingInstruction = document.createProcessingInstruction('target', 'data');
    137         parent.appendChild(processingInstruction);
    138         assert_equals(processingInstruction.treeRoot, innerShadowRoot, 'treeRoot on a processing instruction node inside a shadow tree must return its root node');
    139     }, 'treeRoot attribute must return the root node of the context object when the context object is inside a ' + innerMode
    140         + ' shadow root whose shadow host is in another ' + outerMode + ' shadow root');
    141 }
    142 
    143 testTreeRootOnNodeInsideNestedShadowTree('open', 'open');
    144 testTreeRootOnNodeInsideNestedShadowTree('open', 'closed');
    145 testTreeRootOnNodeInsideNestedShadowTree('closed', 'open');
    146 testTreeRootOnNodeInsideNestedShadowTree('closed', 'closed');
     86    var processingInstruction = document.createProcessingInstruction('target', 'data');
     87    parent.appendChild(processingInstruction)
     88    assert_equals(processingInstruction.rootNode, fragment,
     89        'rootNode on a processing instruction node inside a document fragment must return the fragment');
     90}, 'rootNode attribute must return a document fragment when a node is in the fragment');
    14791
    14892</script>
  • trunk/LayoutTests/fast/shadow-dom/Node-interface-rootNode-expected.txt

    r197834 r197887  
    11
    2 PASS treeRoot attribute must be defined on Node interface
    3 PASS treeRoot attribute must return the context object when it does not have any parent
    4 PASS treeRoot attribute must return the parent node of the context object when the context object has a single ancestor not in a document
    5 PASS treeRoot attribute must return the document when a node is in document and not in a shadow tree
    6 PASS treeRoot attribute must return the open shadow root of the context object when the shadow host is in a document
    7 PASS treeRoot attribute must return the closed shadow root of the context object when the shadow host is in a document
    8 PASS treeRoot attribute must return the root node of the context object when the context object is inside a open shadow root whose shadow host is in another open shadow root
    9 PASS treeRoot attribute must return the root node of the context object when the context object is inside a closed shadow root whose shadow host is in another open shadow root
    10 PASS treeRoot attribute must return the root node of the context object when the context object is inside a open shadow root whose shadow host is in another closed shadow root
    11 PASS treeRoot attribute must return the root node of the context object when the context object is inside a closed shadow root whose shadow host is in another closed shadow root
     2PASS rootNode attribute must be defined on ShadowRoot interface
     3PASS rootNode attribute must return the context object when it does not have any parent
     4PASS rootNode attribute must return the parent node of the context object when the context object has a single ancestor not in a document
     5PASS rootNode attribute must return the document when a node is in document and not in a shadow tree
     6PASS rootNode attribute must return the open shadow root of the context object when the shadow host is in a document
     7PASS rootNode attribute must return the closed shadow root of the context object when the shadow host is in a document
     8PASS rootNode attribute must return the root node of the context object when the context object is inside a open shadow root whose shadow host is in another open shadow root
     9PASS rootNode attribute must return the root node of the context object when the context object is inside a closed shadow root whose shadow host is in another open shadow root
     10PASS rootNode attribute must return the root node of the context object when the context object is inside a open shadow root whose shadow host is in another closed shadow root
     11PASS rootNode attribute must return the root node of the context object when the context object is inside a closed shadow root whose shadow host is in another closed shadow root
    1212
  • trunk/LayoutTests/fast/shadow-dom/Node-interface-rootNode.html

    r197834 r197887  
    44<title>Shadow DOM: Extensions to Node interface</title>
    55<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
    6 <meta name="assert" content="Node interface must have treeRoot attribute">
     6<meta name="assert" content="Node interface must have rootNode attribute">
    77<link rel="help" href="http://w3c.github.io/webcomponents/spec/shadow/#extensions-to-node-interface">
    88<script src="../../resources/testharness.js"></script>
     
    1515
    1616test(function () {
    17     assert_true('treeRoot' in Node.prototype, 'treeRoot must be defined on Node.prototype');
    18     assert_true('treeRoot' in document.createElement('div'), 'treeRoot must be defined on a div element');
    19     assert_true('treeRoot' in document.createTextNode(''), 'assignedSlot must be defined on a text node');
    20     assert_true('treeRoot' in document.createComment(''), 'assignedSlot must be defined on a comment node');
    21     assert_true('treeRoot' in document.createProcessingInstruction('target', 'data'), 'assignedSlot must be defined on a processing instruction node');
    22     assert_true('treeRoot' in document, 'assignedSlot must be defined on a document node');
    23     assert_true('treeRoot' in document.createElement('div').attachShadow({mode: 'closed'}), 'treeRoot must be defined on a closed shadow root element');
    24     assert_true('treeRoot' in document.createElement('div').attachShadow({mode: 'open'}), 'treeRoot must be defined on a open shadow root element');
    25 }, 'treeRoot attribute must be defined on Node interface');
     17    assert_true('rootNode' in document.createElement('div').attachShadow({mode: 'closed'}), 'rootNode must be defined on a closed shadow root element');
     18    assert_true('rootNode' in document.createElement('div').attachShadow({mode: 'open'}), 'rootNode must be defined on a open shadow root element');
     19}, 'rootNode attribute must be defined on ShadowRoot interface');
    2620
    2721test(function () {
    28     var element = document.createElement('div');
    29     assert_equals(element.treeRoot, element, 'treeRoot on an element without a parent must return the element itself');
    30 
    31     var text = document.createTextNode('');
    32     assert_equals(text.treeRoot, text, 'treeRoot on a text node without a parent must return the text node itself');
    33 
    34     var processingInstruction = document.createProcessingInstruction('target', 'data');
    35     assert_equals(processingInstruction.treeRoot, processingInstruction, 'treeRoot on a processing instruction node without a parent must return the processing instruction node itself');
    36 
    37     assert_equals(document.treeRoot, document, 'treeRoot on a document node must return the document itself');
    38 
    3922    var closedShadowRoot = document.createElement('div').attachShadow({mode: 'closed'});
    40     assert_equals(closedShadowRoot.treeRoot, closedShadowRoot, 'treeRoot on a closed shadow root must return the shadow root itself');
     23    assert_equals(closedShadowRoot.rootNode, closedShadowRoot, 'rootNode on a closed shadow root must return the shadow root itself');
    4124
    4225    var openShadowRoot = document.createElement('div').attachShadow({mode: 'open'});
    43     assert_equals(openShadowRoot.treeRoot, openShadowRoot, 'treeRoot on a open shadow root must return the shadow root itself');
    44 }, 'treeRoot attribute must return the context object when it does not have any parent');
     26    assert_equals(openShadowRoot.rootNode, openShadowRoot, 'rootNode on a open shadow root must return the shadow root itself');
     27}, 'rootNode attribute must return the context object when it does not have any parent');
    4528
    4629test(function () {
    4730    var parent = document.createElement('div');
    4831
    49     var element = document.createElement('div');
    50     parent.appendChild(element);
    51     assert_equals(element.treeRoot, parent, 'treeRoot on an element with a single ancestor must return the parent node');
    52 
    53     var text = document.createTextNode('');
    54     parent.appendChild(text);
    55     assert_equals(text.treeRoot, parent, 'treeRoot on a text node with a single ancestor must return the parent node');
    56 
    57     var processingInstruction = document.createProcessingInstruction('target', 'data');
    58     parent.appendChild(processingInstruction)
    59     assert_equals(processingInstruction.treeRoot, parent, 'treeRoot on a processing instruction node with a single ancestor must return the parent node');
    60 
    6132    var hostWithClosedShadowRoot = document.createElement('div');
    6233    parent.appendChild(hostWithClosedShadowRoot);
    6334    var closedShadowRoot = hostWithClosedShadowRoot.attachShadow({mode: 'closed'});
    64     assert_equals(closedShadowRoot.treeRoot, closedShadowRoot, 'treeRoot on a closed shadow root with a single ancestor on its host must return the shadow root itself');
     35    assert_equals(closedShadowRoot.rootNode, closedShadowRoot, 'rootNode on a closed shadow root with a single ancestor on its host must return the shadow root itself');
    6536
    6637    var hostWithOpenShadowRoot = document.createElement('div');
    6738    parent.appendChild(hostWithOpenShadowRoot);
    6839    var openShadowRoot = hostWithOpenShadowRoot.attachShadow({mode: 'open'});
    69     assert_equals(openShadowRoot.treeRoot, openShadowRoot, 'treeRoot on a open shadow root with a single ancestor on its host must return the shadow root itself');
    70 }, 'treeRoot attribute must return the parent node of the context object when the context object has a single ancestor not in a document');
     40    assert_equals(openShadowRoot.rootNode, openShadowRoot, 'rootNode on a open shadow root with a single ancestor on its host must return the shadow root itself');
     41}, 'rootNode attribute must return the parent node of the context object when the context object has a single ancestor not in a document');
    7142
    7243test(function () {
     
    7647    var element = document.createElement('div');
    7748    parent.appendChild(element);
    78     assert_equals(element.treeRoot, document, 'treeRoot on an element inside a document must return the document');
     49    assert_equals(element.rootNode, document, 'rootNode on an element inside a document must return the document');
    7950
    8051    var text = document.createTextNode('');
    8152    parent.appendChild(text);
    82     assert_equals(text.treeRoot, document, 'treeRoot on a text node inside a document must return the document');
     53    assert_equals(text.rootNode, document, 'rootNode on a text node inside a document must return the document');
    8354
    8455    var processingInstruction = document.createProcessingInstruction('target', 'data');
    8556    parent.appendChild(processingInstruction)
    86     assert_equals(processingInstruction.treeRoot, document, 'treeRoot on a processing instruction node inside a document must return the document');
    87 }, 'treeRoot attribute must return the document when a node is in document and not in a shadow tree');
     57    assert_equals(processingInstruction.rootNode, document, 'rootNode on a processing instruction node inside a document must return the document');
     58}, 'rootNode attribute must return the document when a node is in document and not in a shadow tree');
    8859
    89 function testTreeRootOnNodeInsideShadowTree(mode) {
     60function testrootNodeOnNodeInsideShadowTree(mode) {
    9061    test(function () {
    9162        var host = document.createElement('div');
     
    9869        var element = document.createElement('span');
    9970        parent.appendChild(element);
    100         assert_equals(element.treeRoot, shadowRoot, 'treeRoot on an element inside a shadow tree must return the shadow root');
     71        assert_equals(element.rootNode, shadowRoot, 'rootNode on an element inside a shadow tree must return the shadow root');
    10172
    10273        var text = document.createTextNode('');
    10374        parent.appendChild(text);
    104         assert_equals(text.treeRoot, shadowRoot, 'treeRoot on a text node inside a shadow tree must return the shadow root');
     75        assert_equals(text.rootNode, shadowRoot, 'rootNode on a text node inside a shadow tree must return the shadow root');
    10576
    10677        var processingInstruction = document.createProcessingInstruction('target', 'data');
    10778        parent.appendChild(processingInstruction);
    108         assert_equals(processingInstruction.treeRoot, shadowRoot, 'treeRoot on a processing instruction node inside a shadow tree must return the shadow root');
    109     }, 'treeRoot attribute must return the ' + mode + ' shadow root of the context object when the shadow host is in a document');
     79        assert_equals(processingInstruction.rootNode, shadowRoot, 'rootNode on a processing instruction node inside a shadow tree must return the shadow root');
     80    }, 'rootNode attribute must return the ' + mode + ' shadow root of the context object when the shadow host is in a document');
    11081}
    11182
    112 testTreeRootOnNodeInsideShadowTree('open');
    113 testTreeRootOnNodeInsideShadowTree('closed');
     83testrootNodeOnNodeInsideShadowTree('open');
     84testrootNodeOnNodeInsideShadowTree('closed');
    11485
    115 function testTreeRootOnNodeInsideNestedShadowTree(outerMode, innerMode) {
     86function testrootNodeOnNodeInsideNestedShadowTree(outerMode, innerMode) {
    11687    test(function () {
    11788        var outerHost = document.createElement('div');
     
    12899        var element = document.createElement('span');
    129100        parent.appendChild(element);
    130         assert_equals(element.treeRoot, innerShadowRoot, 'treeRoot on an element inside a shadow tree must return its root node');
     101        assert_equals(element.rootNode, innerShadowRoot, 'rootNode on an element inside a shadow tree must return its root node');
    131102
    132103        var text = document.createTextNode('');
    133104        parent.appendChild(text);
    134         assert_equals(text.treeRoot, innerShadowRoot, 'treeRoot on a text node inside a shadow tree must return its root node');
     105        assert_equals(text.rootNode, innerShadowRoot, 'rootNode on a text node inside a shadow tree must return its root node');
    135106
    136107        var processingInstruction = document.createProcessingInstruction('target', 'data');
    137108        parent.appendChild(processingInstruction);
    138         assert_equals(processingInstruction.treeRoot, innerShadowRoot, 'treeRoot on a processing instruction node inside a shadow tree must return its root node');
    139     }, 'treeRoot attribute must return the root node of the context object when the context object is inside a ' + innerMode
     109        assert_equals(processingInstruction.rootNode, innerShadowRoot, 'rootNode on a processing instruction node inside a shadow tree must return its root node');
     110    }, 'rootNode attribute must return the root node of the context object when the context object is inside a ' + innerMode
    140111        + ' shadow root whose shadow host is in another ' + outerMode + ' shadow root');
    141112}
    142113
    143 testTreeRootOnNodeInsideNestedShadowTree('open', 'open');
    144 testTreeRootOnNodeInsideNestedShadowTree('open', 'closed');
    145 testTreeRootOnNodeInsideNestedShadowTree('closed', 'open');
    146 testTreeRootOnNodeInsideNestedShadowTree('closed', 'closed');
     114testrootNodeOnNodeInsideNestedShadowTree('open', 'open');
     115testrootNodeOnNodeInsideNestedShadowTree('open', 'closed');
     116testrootNodeOnNodeInsideNestedShadowTree('closed', 'open');
     117testrootNodeOnNodeInsideNestedShadowTree('closed', 'closed');
    147118
    148119</script>
  • trunk/LayoutTests/js/dom/dom-static-property-for-in-iteration-expected.txt

    r196890 r197887  
    143143PASS a["nextSibling"] is [object Text]
    144144PASS a["ownerDocument"] is [object HTMLDocument]
    145 PASS a["treeRoot"] is [object HTMLDocument]
     145PASS a["rootNode"] is [object HTMLDocument]
    146146PASS a["namespaceURI"] is http://www.w3.org/1999/xhtml
    147147PASS a["prefix"] is null
  • trunk/LayoutTests/platform/efl/js/dom/dom-static-property-for-in-iteration-expected.txt

    r162202 r197887  
    7878PASS a["nextSibling"] is [object Text]
    7979PASS a["ownerDocument"] is [object HTMLDocument]
     80PASS a["rootNode"] is [object HTMLDocument]
    8081PASS a["namespaceURI"] is http://www.w3.org/1999/xhtml
    8182PASS a["localName"] is a
  • trunk/LayoutTests/platform/gtk/js/dom/dom-static-property-for-in-iteration-expected.txt

    r167050 r197887  
    8282PASS a["nextSibling"] is [object Text]
    8383PASS a["ownerDocument"] is [object HTMLDocument]
     84PASS a["rootNode"] is [object HTMLDocument]
    8485PASS a["namespaceURI"] is http://www.w3.org/1999/xhtml
    8586PASS a["prefix"] is null
  • trunk/Source/WebCore/ChangeLog

    r197886 r197887  
     12016-03-09  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Rename Node.treeRoot to rootNode and turn it on by default
     4        https://bugs.webkit.org/show_bug.cgi?id=155226
     5
     6        Reviewed by Antonio Gomes.
     7
     8        Node.prototype.treeRoot has been merged into DOM spec from Shadow DOM spec and renamed to rootNode:
     9        https://dom.spec.whatwg.org/#dom-node-rootnode
     10
     11        Rename the method and expose it unconditionally on Node.prototype.
     12
     13        Tests: fast/dom/Node/rootNode.html
     14               fast/shadow-dom/Node-interface-rootNode.html
     15
     16        * dom/ContainerNode.h:
     17        (WebCore::Node::highestAncestor): Deleted. There is no need for this function to be inlined.
     18        * dom/Document.h: Now that both TreeScope and Node defines rootNode, we need to pick either.
     19        Here, we pick TreeScope's definition since Document is by definition always in a document so there is
     20        no need to even check inTreeScope().
     21        * dom/Node.cpp:
     22        (WebCore::Node::rootNode): Moved here. Also added a fast path for when "this" node is in a document
     23        or a shadow root since TreeScope stores its root node as a member variable (m_rootNode).
     24        * dom/Node.h:
     25        * dom/Node.idl: Renamed the method and removed Conditional=SHADOW_DOM.
     26        * dom/ShadowRoot.h: Similar to the change in Document.h. See above.
     27        * editing/Editor.cpp:
     28        (WebCore::correctSpellcheckingPreservingTextCheckingParagraph): Use rootNode instead of free function
     29        defined in htmlediting.cpp, which was removed in this patch.
     30        * editing/htmlediting.cpp:
     31        (WebCore::highestAncestor): Deleted.
     32        * editing/htmlediting.h:
     33        * html/FormAssociatedElement.cpp:
     34        (WebCore::computeRootNode): Added.
     35        (WebCore::FormAssociatedElement::removedFrom): We can't use Node::rootNode here because this function
     36        is called in the middle of removing a subtree, and some associated form element's inDocument flag may
     37        not have been updated yet. So use computeRootNode to manually find the highest ancestor.
     38        (WebCore::FormAssociatedElement::formRemovedFromTree): Ditto.
     39        * xml/XPathPath.cpp:
     40        (WebCore::XPath::LocationPath::evaluate):
     41
    1422016-03-09  Konstantin Tokarev  <annulen@yandex.ru>
    243
  • trunk/Source/WebCore/dom/ContainerNode.h

    r196888 r197887  
    213213}
    214214
    215 inline Node* Node::highestAncestor() const
    216 {
    217     Node* node = const_cast<Node*>(this);
    218     Node* highest = node;
    219     for (; node; node = node->parentNode())
    220         highest = node;
    221     return highest;
    222 }
    223 
    224215inline bool Node::isTreeScope() const
    225216{
  • trunk/Source/WebCore/dom/Document.h

    r197690 r197887  
    341341    using ContainerNode::ref;
    342342    using ContainerNode::deref;
     343    using TreeScope::rootNode;
    343344
    344345    bool canContainRangeEndPoint() const final { return true; }
  • trunk/Source/WebCore/dom/Node.cpp

    r196998 r197887  
    11111111}
    11121112
     1113Node* Node::rootNode() const
     1114{
     1115    if (isInTreeScope())
     1116        return &treeScope().rootNode();
     1117
     1118    Node* node = const_cast<Node*>(this);
     1119    Node* highest = node;
     1120    for (; node; node = node->parentNode())
     1121        highest = node;
     1122    return highest;
     1123}
     1124
    11131125Node::InsertionNotificationRequest Node::insertedInto(ContainerNode& insertionPoint)
    11141126{
  • trunk/Source/WebCore/dom/Node.h

    r197566 r197887  
    277277    Element* parentOrShadowHostElement() const;
    278278    void setParentNode(ContainerNode*);
    279     Node* highestAncestor() const;
     279    Node* rootNode() const;
    280280
    281281    // Use when it's guaranteed to that shadowHost is null.
  • trunk/Source/WebCore/dom/Node.idl

    r197634 r197887  
    6161    readonly attribute Document         ownerDocument;
    6262
    63     [Conditional=SHADOW_DOM, ImplementedAs=highestAncestor] readonly attribute Node treeRoot;
     63    readonly attribute Node rootNode;
    6464
    6565    [ObjCLegacyUnnamedParameters, Custom, RaisesException] Node insertBefore([CustomReturn] Node newChild,
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r197563 r197887  
    6262
    6363    virtual ~ShadowRoot();
     64
     65    using TreeScope::rootNode;
    6466
    6567    StyleResolver& styleResolver();
  • trunk/Source/WebCore/editing/Editor.cpp

    r197605 r197887  
    24282428static void correctSpellcheckingPreservingTextCheckingParagraph(TextCheckingParagraph& paragraph, PassRefPtr<Range> rangeToReplace, const String& replacement, int resultLocation, int resultLength)
    24292429{
    2430     ContainerNode* scope = downcast<ContainerNode>(highestAncestor(&paragraph.paragraphRange()->startContainer()));
     2430    ContainerNode* scope = downcast<ContainerNode>(paragraph.paragraphRange()->startContainer().rootNode());
    24312431
    24322432    size_t paragraphLocation;
  • trunk/Source/WebCore/editing/htmlediting.cpp

    r194819 r197887  
    796796}
    797797
    798 Node* highestAncestor(Node* node)
    799 {
    800     ASSERT(node);
    801     Node* parent = node;
    802     while ((node = node->parentNode()))
    803         parent = node;
    804     return parent;
    805 }
    806 
    807798static Node* previousNodeConsideringAtomicNodes(const Node* node)
    808799{
  • trunk/Source/WebCore/editing/htmlediting.h

    r192043 r197887  
    5454// Functions returning Node
    5555
    56 Node* highestAncestor(Node*);
    5756Node* highestEditableRoot(const Position&, EditableType = ContentIsEditable);
    5857
  • trunk/Source/WebCore/html/FormAssociatedElement.cpp

    r197563 r197887  
    8383}
    8484
     85// Compute the highest ancestor instead of calling Node::rootNode in removedFrom / formRemovedFromTree
     86// since inDocument flag on some form associated elements may not have been updated yet.
     87static Node* computeRootNode(Node& node)
     88{
     89    Node* current = &node;
     90    Node* parent = current;
     91    while ((current = current->parentNode()))
     92        parent = current;
     93    return parent;
     94}
     95
    8596void FormAssociatedElement::removedFrom(ContainerNode& insertionPoint)
    8697{
     
    90101    // If the form and element are both in the same tree, preserve the connection to the form.
    91102    // Otherwise, null out our form and remove ourselves from the form's list of elements.
    92     if (m_form && element.highestAncestor() != m_form->highestAncestor())
     103    if (m_form && computeRootNode(element) != computeRootNode(*m_form))
    93104        setForm(nullptr);
    94105}
     
    118129{
    119130    ASSERT(m_form);
    120     if (asHTMLElement().highestAncestor() != formRoot)
     131    if (computeRootNode(asHTMLElement()) != formRoot)
    121132        setForm(nullptr);
    122133}
  • trunk/Source/WebCore/xml/XPathPath.cpp

    r194496 r197887  
    8989    // logical treatment of where you would expect the "root" to be.
    9090    Node* context = evaluationContext.node.get();
    91     if (m_isAbsolute && !context->isDocumentNode())  {
    92         if (context->inDocument())
    93             context = context->ownerDocument();
    94         else
    95             context = context->highestAncestor();
    96     }
     91    if (m_isAbsolute && !context->isDocumentNode())
     92        context = context->rootNode();
    9793
    9894    NodeSet nodes;
Note: See TracChangeset for help on using the changeset viewer.