Title: [164251] trunk/Source/WebCore
Revision
164251
Author
[email protected]
Date
2014-02-17 15:29:31 -0800 (Mon, 17 Feb 2014)

Log Message

Make TreeScope::rootNode return a reference
https://bugs.webkit.org/show_bug.cgi?id=128934

Reviewed by Andreas Kling.

It is never null.

* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::collectMatchingRules):
* dom/ContainerNode.h:
(WebCore::Node::isTreeScope):
* dom/Document.cpp:
(WebCore::Document::buildAccessKeyMap):
* dom/DocumentOrderedMap.cpp:
(WebCore::DocumentOrderedMap::add):
(WebCore::DocumentOrderedMap::get):
(WebCore::DocumentOrderedMap::getAllElementsById):
* dom/EventDispatcher.cpp:
(WebCore::EventRelatedNodeResolver::moveToParentOrShadowHost):
(WebCore::eventTargetRespectingTargetRules):
(WebCore::shouldEventCrossShadowBoundary):
* dom/Node.cpp:
(WebCore::Node::containingShadowRoot):
(WebCore::Node::removedFrom):
* dom/ShadowRoot.h:
(WebCore::isShadowRoot):
* dom/TreeScope.h:
(WebCore::TreeScope::rootNode):
* page/DOMSelection.cpp:
(WebCore::DOMSelection::DOMSelection):
* page/DragController.cpp:
(WebCore::asFileInput):
* page/FocusController.cpp:
(WebCore::FocusNavigationScope::rootNode):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (164250 => 164251)


--- trunk/Source/WebCore/ChangeLog	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/ChangeLog	2014-02-17 23:29:31 UTC (rev 164251)
@@ -1,3 +1,40 @@
+2014-02-17  Antti Koivisto  <[email protected]>
+
+        Make TreeScope::rootNode return a reference
+        https://bugs.webkit.org/show_bug.cgi?id=128934
+
+        Reviewed by Andreas Kling.
+
+        It is never null.
+
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::collectMatchingRules):
+        * dom/ContainerNode.h:
+        (WebCore::Node::isTreeScope):
+        * dom/Document.cpp:
+        (WebCore::Document::buildAccessKeyMap):
+        * dom/DocumentOrderedMap.cpp:
+        (WebCore::DocumentOrderedMap::add):
+        (WebCore::DocumentOrderedMap::get):
+        (WebCore::DocumentOrderedMap::getAllElementsById):
+        * dom/EventDispatcher.cpp:
+        (WebCore::EventRelatedNodeResolver::moveToParentOrShadowHost):
+        (WebCore::eventTargetRespectingTargetRules):
+        (WebCore::shouldEventCrossShadowBoundary):
+        * dom/Node.cpp:
+        (WebCore::Node::containingShadowRoot):
+        (WebCore::Node::removedFrom):
+        * dom/ShadowRoot.h:
+        (WebCore::isShadowRoot):
+        * dom/TreeScope.h:
+        (WebCore::TreeScope::rootNode):
+        * page/DOMSelection.cpp:
+        (WebCore::DOMSelection::DOMSelection):
+        * page/DragController.cpp:
+        (WebCore::asFileInput):
+        * page/FocusController.cpp:
+        (WebCore::FocusNavigationScope::rootNode):
+
 2014-02-17  Chris Fleizach  <[email protected]>
 
         AX: Invalid cast in WebCore::AccessibilityTable::isDataTable (CRBug 280352)

Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (164250 => 164251)


--- trunk/Source/WebCore/css/ElementRuleCollector.cpp	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp	2014-02-17 23:29:31 UTC (rev 164251)
@@ -155,7 +155,7 @@
         collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), matchRequest, ruleRange);
 #endif
     // Only match UA rules in shadow tree.
-    if (!MatchingUARulesScope::isMatchingUARules() && m_element.treeScope().rootNode()->isShadowRoot())
+    if (!MatchingUARulesScope::isMatchingUARules() && m_element.treeScope().rootNode().isShadowRoot())
         return;
 
     // We need to collect the rules for id, class, tag, and everything else into a buffer and

Modified: trunk/Source/WebCore/dom/ContainerNode.h (164250 => 164251)


--- trunk/Source/WebCore/dom/ContainerNode.h	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/dom/ContainerNode.h	2014-02-17 23:29:31 UTC (rev 164251)
@@ -236,7 +236,7 @@
 
 inline bool Node::isTreeScope() const
 {
-    return treeScope().rootNode() == this;
+    return &treeScope().rootNode() == this;
 }
 
 // This constant controls how much buffer is initially allocated

Modified: trunk/Source/WebCore/dom/Document.cpp (164250 => 164251)


--- trunk/Source/WebCore/dom/Document.cpp	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/dom/Document.cpp	2014-02-17 23:29:31 UTC (rev 164251)
@@ -712,8 +712,7 @@
 void Document::buildAccessKeyMap(TreeScope* scope)
 {
     ASSERT(scope);
-    ContainerNode* rootNode = scope->rootNode();
-    for (auto& element : descendantsOfType<Element>(*rootNode)) {
+    for (auto& element : descendantsOfType<Element>(scope->rootNode())) {
         const AtomicString& accessKey = element.fastGetAttribute(accesskeyAttr);
         if (!accessKey.isEmpty())
             m_elementsByAccessKey.set(accessKey.impl(), &element);

Modified: trunk/Source/WebCore/dom/DocumentOrderedMap.cpp (164250 => 164251)


--- trunk/Source/WebCore/dom/DocumentOrderedMap.cpp	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/dom/DocumentOrderedMap.cpp	2014-02-17 23:29:31 UTC (rev 164251)
@@ -91,7 +91,7 @@
 {
     UNUSED_PARAM(treeScope);
     ASSERT_WITH_SECURITY_IMPLICATION(element.isInTreeScope());
-    ASSERT_WITH_SECURITY_IMPLICATION(treeScope.rootNode()->containsIncludingShadowDOM(&element));
+    ASSERT_WITH_SECURITY_IMPLICATION(treeScope.rootNode().containsIncludingShadowDOM(&element));
     if (!element.isInTreeScope())
         return;
     Map::AddResult addResult = m_map.add(&key, MapEntry(&element));
@@ -144,7 +144,7 @@
     }
 
     // We know there's at least one node that matches; iterate to find the first one.
-    for (auto& element : descendantsOfType<Element>(*scope.rootNode())) {
+    for (auto& element : descendantsOfType<Element>(scope.rootNode())) {
         if (!keyMatches(key, element))
             continue;
         entry.element = &element;
@@ -211,7 +211,7 @@
 
     if (entry.orderedList.isEmpty()) {
         entry.orderedList.reserveCapacity(entry.count);
-        auto elementDescandents = descendantsOfType<Element>(*scope.rootNode());
+        auto elementDescandents = descendantsOfType<Element>(scope.rootNode());
         auto it = entry.element ? elementDescandents.beginAt(*entry.element) : elementDescandents.begin();
         auto end = elementDescandents.end();
         for (; it != end; ++it) {

Modified: trunk/Source/WebCore/dom/EventDispatcher.cpp (164250 => 164251)


--- trunk/Source/WebCore/dom/EventDispatcher.cpp	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/dom/EventDispatcher.cpp	2014-02-17 23:29:31 UTC (rev 164251)
@@ -143,8 +143,8 @@
             return m_relatedNodeInCurrentTreeScope;
 
         if (m_currentTreeScope) {
-            ASSERT(m_currentTreeScope->rootNode()->isShadowRoot());
-            ASSERT(&newTarget == toShadowRoot(m_currentTreeScope->rootNode())->hostElement());
+            ASSERT(m_currentTreeScope->rootNode().isShadowRoot());
+            ASSERT(&newTarget == toShadowRoot(m_currentTreeScope->rootNode()).hostElement());
             ASSERT(m_currentTreeScope->parentTreeScope() == &newTreeScope);
         }
 
@@ -184,8 +184,8 @@
 
     // Spec: The event handling for the non-exposed tree works as if the referenced element had been textually included
     // as a deeply cloned child of the 'use' element, except that events are dispatched to the SVGElementInstance objects
-    Node* rootNode = referenceNode.treeScope().rootNode();
-    Element* shadowHostElement = rootNode->isShadowRoot() ? toShadowRoot(rootNode)->hostElement() : 0;
+    auto& rootNode = referenceNode.treeScope().rootNode();
+    Element* shadowHostElement = rootNode.isShadowRoot() ? toShadowRoot(rootNode).hostElement() : nullptr;
     // At this time, SVG nodes are not supported in non-<use> shadow trees.
     if (!shadowHostElement || !shadowHostElement->hasTagName(SVGNames::useTag))
         return referenceNode;
@@ -366,7 +366,7 @@
     // Changing this breaks existing sites.
     // See https://bugs.webkit.org/show_bug.cgi?id=52195 for details.
     const AtomicString& eventType = event.type();
-    bool targetIsInShadowRoot = targetNode && targetNode->treeScope().rootNode() == &shadowRoot;
+    bool targetIsInShadowRoot = targetNode && &targetNode->treeScope().rootNode() == &shadowRoot;
     return !targetIsInShadowRoot
         || !(eventType == eventNames().abortEvent
             || eventType == eventNames().changeEvent

Modified: trunk/Source/WebCore/dom/Node.cpp (164250 => 164251)


--- trunk/Source/WebCore/dom/Node.cpp	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/dom/Node.cpp	2014-02-17 23:29:31 UTC (rev 164251)
@@ -951,8 +951,8 @@
 
 ShadowRoot* Node::containingShadowRoot() const
 {
-    ContainerNode* root = treeScope().rootNode();
-    return root && root->isShadowRoot() ? toShadowRoot(root) : 0;
+    ContainerNode& root = treeScope().rootNode();
+    return root.isShadowRoot() ? toShadowRoot(&root) : nullptr;
 }
 
 Node* Node::nonBoundaryShadowTreeRootNode()
@@ -1011,7 +1011,7 @@
     ASSERT(insertionPoint.inDocument() || isContainerNode());
     if (insertionPoint.inDocument())
         clearFlag(InDocumentFlag);
-    if (isInShadowTree() && !treeScope().rootNode()->isShadowRoot())
+    if (isInShadowTree() && !treeScope().rootNode().isShadowRoot())
         clearFlag(IsInShadowTreeFlag);
 }
 

Modified: trunk/Source/WebCore/dom/ShadowRoot.h (164250 => 164251)


--- trunk/Source/WebCore/dom/ShadowRoot.h	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/dom/ShadowRoot.h	2014-02-17 23:29:31 UTC (rev 164251)
@@ -95,16 +95,9 @@
     return treeScope().focusedElement();
 }
 
-inline const ShadowRoot* toShadowRoot(const Node* node)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isShadowRoot());
-    return static_cast<const ShadowRoot*>(node);
-}
+inline bool isShadowRoot(const Node& node) { return node.isShadowRoot(); }
 
-inline ShadowRoot* toShadowRoot(Node* node)
-{
-    return const_cast<ShadowRoot*>(toShadowRoot(static_cast<const Node*>(node)));
-}
+NODE_TYPE_CASTS(ShadowRoot)
 
 inline ShadowRoot* Node::shadowRoot() const
 {

Modified: trunk/Source/WebCore/dom/TreeScope.cpp (164250 => 164251)


--- trunk/Source/WebCore/dom/TreeScope.cpp	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/dom/TreeScope.cpp	2014-02-17 23:29:31 UTC (rev 164251)
@@ -92,7 +92,7 @@
 void TreeScope::setParentTreeScope(TreeScope* newParentScope)
 {
     // A document node cannot be re-parented.
-    ASSERT(!rootNode()->isDocumentNode());
+    ASSERT(!m_rootNode.isDocumentNode());
     // Every scope other than document needs a parent scope.
     ASSERT(newParentScope);
 
@@ -198,7 +198,7 @@
     String name = (hashPos == notFound ? url : url.substring(hashPos + 1)).impl();
     if (name.isEmpty())
         return nullptr;
-    if (rootNode()->document().isHTMLDocument()) {
+    if (m_rootNode.document().isHTMLDocument()) {
         AtomicString lowercasedName = name.lower();
         return m_imageMapsByName->getElementByLowercasedMapName(*lowercasedName.impl(), *this);
     }
@@ -239,7 +239,7 @@
 
 Element* TreeScope::elementFromPoint(int x, int y) const
 {
-    Node* node = nodeFromPoint(&rootNode()->document(), x, y);
+    Node* node = nodeFromPoint(&m_rootNode.document(), x, y);
     while (node && !node->isElementNode())
         node = node->parentNode();
     if (node)
@@ -268,7 +268,7 @@
         // Populate the map on first access.
         m_labelsByForAttribute = std::make_unique<DocumentOrderedMap>();
 
-        for (auto& label : descendantsOfType<HTMLLabelElement>(*rootNode())) {
+        for (auto& label : descendantsOfType<HTMLLabelElement>(m_rootNode)) {
             const AtomicString& forValue = label.fastGetAttribute(forAttr);
             if (!forValue.isEmpty())
                 addLabel(*forValue.impl(), label);
@@ -280,16 +280,16 @@
 
 DOMSelection* TreeScope::getSelection() const
 {
-    if (!rootNode()->document().frame())
+    if (!m_rootNode.document().frame())
         return nullptr;
 
     if (m_selection)
         return m_selection.get();
 
-    if (this != &rootNode()->document())
-        return rootNode()->document().getSelection();
+    if (this != &m_rootNode.document())
+        return m_rootNode.document().getSelection();
 
-    m_selection = DOMSelection::create(&rootNode()->document());
+    m_selection = DOMSelection::create(&m_rootNode.document());
     return m_selection.get();
 }
 
@@ -299,8 +299,8 @@
         return nullptr;
     if (Element* element = getElementById(name))
         return element;
-    for (auto& anchor : descendantsOfType<HTMLAnchorElement>(*rootNode())) {
-        if (rootNode()->document().inQuirksMode()) {
+    for (auto& anchor : descendantsOfType<HTMLAnchorElement>(m_rootNode)) {
+        if (m_rootNode.document().inQuirksMode()) {
             // Quirks mode, case insensitive comparison of names.
             if (equalIgnoringCase(anchor.name(), name))
                 return &anchor;
@@ -335,7 +335,7 @@
 
 Element* TreeScope::focusedElement()
 {
-    Document& document = rootNode()->document();
+    Document& document = m_rootNode.document();
     Element* element = document.focusedElement();
 
     if (!element && document.page())
@@ -344,7 +344,7 @@
         return nullptr;
     TreeScope* treeScope = &element->treeScope();
     while (treeScope != this && treeScope != &document) {
-        element = toShadowRoot(treeScope->rootNode())->hostElement();
+        element = toShadowRoot(treeScope->rootNode()).hostElement();
         treeScope = &element->treeScope();
     }
     if (this != treeScope)

Modified: trunk/Source/WebCore/dom/TreeScope.h (164250 => 164251)


--- trunk/Source/WebCore/dom/TreeScope.h	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/dom/TreeScope.h	2014-02-17 23:29:31 UTC (rev 164251)
@@ -95,7 +95,7 @@
     // Used by the basic DOM mutation methods (e.g., appendChild()).
     void adoptIfNeeded(Node*);
 
-    ContainerNode* rootNode() const { return &m_rootNode; }
+    ContainerNode& rootNode() const { return m_rootNode; }
 
     IdTargetObserverRegistry& idTargetObserverRegistry() const { return *m_idTargetObserverRegistry.get(); }
 

Modified: trunk/Source/WebCore/editing/VisibleSelection.cpp (164250 => 164251)


--- trunk/Source/WebCore/editing/VisibleSelection.cpp	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/editing/VisibleSelection.cpp	2014-02-17 23:29:31 UTC (rev 164251)
@@ -485,7 +485,7 @@
         return positionBeforeNode(ancestor);
     }
 
-    if (Node* lastChild = treeScope.rootNode()->lastChild())
+    if (Node* lastChild = treeScope.rootNode().lastChild())
         return positionAfterNode(lastChild);
 
     return Position();
@@ -503,7 +503,7 @@
         return positionAfterNode(ancestor);
     }
 
-    if (Node* firstChild = treeScope.rootNode()->firstChild())
+    if (Node* firstChild = treeScope.rootNode().firstChild())
         return positionBeforeNode(firstChild);
 
     return Position();

Modified: trunk/Source/WebCore/page/DOMSelection.cpp (164250 => 164251)


--- trunk/Source/WebCore/page/DOMSelection.cpp	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/page/DOMSelection.cpp	2014-02-17 23:29:31 UTC (rev 164251)
@@ -57,7 +57,7 @@
 }
 
 DOMSelection::DOMSelection(const TreeScope* treeScope)
-    : DOMWindowProperty(treeScope->rootNode()->document().frame())
+    : DOMWindowProperty(treeScope->rootNode().document().frame())
     , m_treeScope(treeScope)
 {
 }

Modified: trunk/Source/WebCore/page/DragController.cpp (164250 => 164251)


--- trunk/Source/WebCore/page/DragController.cpp	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/page/DragController.cpp	2014-02-17 23:29:31 UTC (rev 164251)
@@ -272,8 +272,8 @@
     HTMLInputElement* inputElement = node->toInputElement();
 
     // If this is a button inside of the a file input, move up to the file input.
-    if (inputElement && inputElement->isTextButton() && inputElement->treeScope().rootNode()->isShadowRoot())
-        inputElement = toShadowRoot(inputElement->treeScope().rootNode())->hostElement()->toInputElement();
+    if (inputElement && inputElement->isTextButton() && inputElement->treeScope().rootNode().isShadowRoot())
+        inputElement = toShadowRoot(inputElement->treeScope().rootNode()).hostElement()->toInputElement();
 
     return inputElement && inputElement->isFileUpload() ? inputElement : 0;
 }

Modified: trunk/Source/WebCore/page/FocusController.cpp (164250 => 164251)


--- trunk/Source/WebCore/page/FocusController.cpp	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/page/FocusController.cpp	2014-02-17 23:29:31 UTC (rev 164251)
@@ -74,7 +74,7 @@
 
 ContainerNode* FocusNavigationScope::rootNode() const
 {
-    return m_rootTreeScope->rootNode();
+    return &m_rootTreeScope->rootNode();
 }
 
 Element* FocusNavigationScope::owner() const

Modified: trunk/Source/WebCore/svg/SVGElement.cpp (164250 => 164251)


--- trunk/Source/WebCore/svg/SVGElement.cpp	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/svg/SVGElement.cpp	2014-02-17 23:29:31 UTC (rev 164251)
@@ -947,7 +947,7 @@
 
     // Walk up the tree, to find out whether we're inside a <use> shadow tree, to find the right title.
     if (isInShadowTree()) {
-        Element* shadowHostElement = toShadowRoot(treeScope().rootNode())->hostElement();
+        Element* shadowHostElement = toShadowRoot(treeScope().rootNode()).hostElement();
         // At this time, SVG nodes are not allowed in non-<use> shadow trees, so any shadow root we do
         // have should be a use. The assert and following test is here to catch future shadow DOM changes
         // that do enable SVG in a shadow tree.

Modified: trunk/Source/WebCore/testing/Internals.cpp (164250 => 164251)


--- trunk/Source/WebCore/testing/Internals.cpp	2014-02-17 22:44:24 UTC (rev 164250)
+++ trunk/Source/WebCore/testing/Internals.cpp	2014-02-17 23:29:31 UTC (rev 164251)
@@ -365,20 +365,20 @@
 {
     if (!node) {
         ec = INVALID_ACCESS_ERR;
-        return 0;
+        return nullptr;
     }
 
-    return node->treeScope().rootNode();
+    return &node->treeScope().rootNode();
 }
 
 Node* Internals::parentTreeScope(Node* node, ExceptionCode& ec)
 {
     if (!node) {
         ec = INVALID_ACCESS_ERR;
-        return 0;
+        return nullptr;
     }
     const TreeScope* parentTreeScope = node->treeScope().parentTreeScope();
-    return parentTreeScope ? parentTreeScope->rootNode() : 0;
+    return parentTreeScope ? &parentTreeScope->rootNode() : nullptr;
 }
 
 unsigned Internals::lastSpatialNavigationCandidateCount(ExceptionCode& ec) const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to