Title: [117796] trunk/Source/WebCore
Revision
117796
Author
[email protected]
Date
2012-05-21 09:59:02 -0700 (Mon, 21 May 2012)

Log Message

[Refactoring] Node should have youngestShadowRoot.
https://bugs.webkit.org/show_bug.cgi?id=86427

Reviewed by Dimitri Glazkov.

This change adds Node::youngestShadowRoot() and replaced
ElementShadow::youngestShadowRoot() with it if appropriate.

By introducing this, traversal across node and its shadow tree can
look more fluent and idiomatic. There are a few non-trivial traversal
remaining like ElementShadow::recalcStyle() and attach().
But they should be flattened out eventually.

No new tests. Refactoring.

* dom/ContainerNodeAlgorithms.cpp:
(WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree):
* dom/Document.cpp:
(WebCore::Document::buildAccessKeyMap):
* dom/ElementShadow.cpp:
* dom/ElementShadow.h:
(ElementShadow):
(WebCore::Node::youngestShadowRoot):
(WebCore):
* dom/Node.h:
(Node):
* dom/TreeScopeAdopter.cpp:
(WebCore::TreeScopeAdopter::moveTreeToNewScope):
(WebCore::TreeScopeAdopter::moveTreeToNewDocument):
* dom/TreeScopeAdopter.h:
(TreeScopeAdopter):
* html/shadow/TextFieldDecorationElement.cpp:
(WebCore::getDecorationRootAndDecoratedRoot):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (117795 => 117796)


--- trunk/Source/WebCore/ChangeLog	2012-05-21 16:43:24 UTC (rev 117795)
+++ trunk/Source/WebCore/ChangeLog	2012-05-21 16:59:02 UTC (rev 117796)
@@ -1,3 +1,39 @@
+2012-05-21  MORITA Hajime  <[email protected]>
+
+        [Refactoring] Node should have youngestShadowRoot.
+        https://bugs.webkit.org/show_bug.cgi?id=86427
+
+        Reviewed by Dimitri Glazkov.
+
+        This change adds Node::youngestShadowRoot() and replaced
+        ElementShadow::youngestShadowRoot() with it if appropriate.
+
+        By introducing this, traversal across node and its shadow tree can
+        look more fluent and idiomatic. There are a few non-trivial traversal
+        remaining like ElementShadow::recalcStyle() and attach().
+        But they should be flattened out eventually.
+
+        No new tests. Refactoring.
+
+        * dom/ContainerNodeAlgorithms.cpp:
+        (WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree):
+        * dom/Document.cpp:
+        (WebCore::Document::buildAccessKeyMap):
+        * dom/ElementShadow.cpp:
+        * dom/ElementShadow.h:
+        (ElementShadow):
+        (WebCore::Node::youngestShadowRoot):
+        (WebCore):
+        * dom/Node.h:
+        (Node):
+        * dom/TreeScopeAdopter.cpp:
+        (WebCore::TreeScopeAdopter::moveTreeToNewScope):
+        (WebCore::TreeScopeAdopter::moveTreeToNewDocument):
+        * dom/TreeScopeAdopter.h:
+        (TreeScopeAdopter):
+        * html/shadow/TextFieldDecorationElement.cpp:
+        (WebCore::getDecorationRootAndDecoratedRoot):
+
 2012-05-21  Christophe Dumez  <[email protected]>
 
         Add support for MessagePortArray type to JSC

Modified: trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp (117795 => 117796)


--- trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp	2012-05-21 16:43:24 UTC (rev 117795)
+++ trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp	2012-05-21 16:59:02 UTC (rev 117796)
@@ -61,13 +61,8 @@
             notifyNodeInsertedIntoTree(toContainerNode(child));
     }
 
-    if (!node->isElementNode())
-        return;
-
-    if (ElementShadow* shadow = toElement(node)->shadow()) {
-        for (ShadowRoot* root = shadow->youngestShadowRoot(); root; root = root->olderShadowRoot())
-            notifyNodeInsertedIntoTree(root);
-    }
+    for (ShadowRoot* root = node->youngestShadowRoot(); root; root = root->olderShadowRoot())
+        notifyNodeInsertedIntoTree(root);
 }
 
 void ChildNodeRemovalNotifier::notifyDescendantRemovedFromDocument(ContainerNode* node)

Modified: trunk/Source/WebCore/dom/Document.cpp (117795 => 117796)


--- trunk/Source/WebCore/dom/Document.cpp	2012-05-21 16:43:24 UTC (rev 117795)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-05-21 16:59:02 UTC (rev 117796)
@@ -719,10 +719,8 @@
         if (!accessKey.isEmpty())
             m_elementsByAccessKey.set(accessKey.impl(), element);
 
-        if (ElementShadow* shadow = element->shadow()) {
-            for (ShadowRoot* root = shadow->youngestShadowRoot(); root; root = root->olderShadowRoot())
-                buildAccessKeyMap(root);
-        }
+        for (ShadowRoot* root = node->youngestShadowRoot(); root; root = root->olderShadowRoot())
+            buildAccessKeyMap(root);
     }
 }
 

Modified: trunk/Source/WebCore/dom/ElementShadow.cpp (117795 => 117796)


--- trunk/Source/WebCore/dom/ElementShadow.cpp	2012-05-21 16:43:24 UTC (rev 117795)
+++ trunk/Source/WebCore/dom/ElementShadow.cpp	2012-05-21 16:59:02 UTC (rev 117796)
@@ -110,12 +110,6 @@
         shadowHost->attachChildrenLazily();
 }
 
-void ElementShadow::setParentTreeScope(TreeScope* scope)
-{
-    for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot())
-        root->setParentTreeScope(scope);
-}
-
 void ElementShadow::attach()
 {
     // The pool nodes are populated lazily in

Modified: trunk/Source/WebCore/dom/ElementShadow.h (117795 => 117796)


--- trunk/Source/WebCore/dom/ElementShadow.h	2012-05-21 16:43:24 UTC (rev 117795)
+++ trunk/Source/WebCore/dom/ElementShadow.h	2012-05-21 16:59:02 UTC (rev 117796)
@@ -28,6 +28,7 @@
 #define ElementShadow_h
 
 #include "ContentDistributor.h"
+#include "Element.h"
 #include "ExceptionCode.h"
 #include "ShadowRoot.h"
 #include <wtf/DoublyLinkedList.h>
@@ -53,8 +54,6 @@
 
     void addShadowRoot(Element* shadowHost, PassRefPtr<ShadowRoot>, ExceptionCode&);
 
-    void setParentTreeScope(TreeScope*);
-
     void attach();
     void detach();
     void reattach();
@@ -115,6 +114,15 @@
     return youngestShadowRoot()->host();
 }
 
+inline ShadowRoot* Node::youngestShadowRoot() const
+{
+    if (!this->isElementNode())
+        return 0;
+    if (ElementShadow* shadow = toElement(this)->shadow())
+        return shadow->youngestShadowRoot();
+    return 0;
+}
+
 class ShadowRootVector : public Vector<RefPtr<ShadowRoot> > {
 public:
     explicit ShadowRootVector(ElementShadow* tree)

Modified: trunk/Source/WebCore/dom/Node.h (117795 => 117796)


--- trunk/Source/WebCore/dom/Node.h	2012-05-21 16:43:24 UTC (rev 117795)
+++ trunk/Source/WebCore/dom/Node.h	2012-05-21 16:59:02 UTC (rev 117796)
@@ -223,6 +223,8 @@
 
     Node* shadowAncestorNode() const;
     ShadowRoot* shadowRoot() const;
+    ShadowRoot* youngestShadowRoot() const;
+
     // Returns 0, a child of ShadowRoot, or a legacy shadow root.
     Node* nonBoundaryShadowTreeRootNode();
     bool isInShadowTree() const;

Modified: trunk/Source/WebCore/dom/TreeScopeAdopter.cpp (117795 => 117796)


--- trunk/Source/WebCore/dom/TreeScopeAdopter.cpp	2012-05-21 16:43:24 UTC (rev 117795)
+++ trunk/Source/WebCore/dom/TreeScopeAdopter.cpp	2012-05-21 16:59:02 UTC (rev 117796)
@@ -63,10 +63,10 @@
         if (willMoveToNewDocument)
             moveNodeToNewDocument(node, oldDocument, newDocument);
 
-        if (ElementShadow* shadow = shadowFor(node)) {
+        for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = shadow->olderShadowRoot()) {
             shadow->setParentTreeScope(m_newScope);
             if (willMoveToNewDocument)
-                moveShadowToNewDocument(shadow, oldDocument, newDocument);
+                moveTreeToNewDocument(shadow, oldDocument, newDocument);
         }
     }
 }
@@ -75,17 +75,11 @@
 {
     for (Node* node = root; node; node = node->traverseNextNode(root)) {
         moveNodeToNewDocument(node, oldDocument, newDocument);
-        if (ElementShadow* shadow = shadowFor(node))
-            moveShadowToNewDocument(shadow, oldDocument, newDocument);
+        for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = shadow->olderShadowRoot())
+            moveTreeToNewDocument(shadow, oldDocument, newDocument);
     }
 }
 
-inline void TreeScopeAdopter::moveShadowToNewDocument(ElementShadow* shadow, Document* oldDocument, Document* newDocument) const
-{
-    for (ShadowRoot* root = shadow->youngestShadowRoot(); root; root = root->olderShadowRoot())
-        moveTreeToNewDocument(root, oldDocument, newDocument);
-}
-
 #ifndef NDEBUG
 static bool didMoveToNewDocumentWasCalled = false;
 static Document* oldDocumentDidMoveToNewDocumentWasCalledWith = 0;

Modified: trunk/Source/WebCore/dom/TreeScopeAdopter.h (117795 => 117796)


--- trunk/Source/WebCore/dom/TreeScopeAdopter.h	2012-05-21 16:43:24 UTC (rev 117795)
+++ trunk/Source/WebCore/dom/TreeScopeAdopter.h	2012-05-21 16:59:02 UTC (rev 117796)
@@ -46,7 +46,6 @@
     void moveTreeToNewScope(Node*) const;
     void moveTreeToNewDocument(Node*, Document* oldDocument, Document* newDocument) const;
     void moveNodeToNewDocument(Node*, Document* oldDocument, Document* newDocument) const;
-    void moveShadowToNewDocument(ElementShadow*, Document* oldDocument, Document* newDocument) const;
 
     Node* m_toAdopt;
     TreeScope* m_newScope;

Modified: trunk/Source/WebCore/html/shadow/TextFieldDecorationElement.cpp (117795 => 117796)


--- trunk/Source/WebCore/html/shadow/TextFieldDecorationElement.cpp	2012-05-21 16:43:24 UTC (rev 117795)
+++ trunk/Source/WebCore/html/shadow/TextFieldDecorationElement.cpp	2012-05-21 16:59:02 UTC (rev 117796)
@@ -68,7 +68,7 @@
 
 static inline void getDecorationRootAndDecoratedRoot(HTMLInputElement* input, ShadowRoot*& decorationRoot, ShadowRoot*& decoratedRoot)
 {
-    ShadowRoot* existingRoot = input->shadow()->youngestShadowRoot();
+    ShadowRoot* existingRoot = input->youngestShadowRoot();
     ShadowRoot* newRoot = 0;
     while (existingRoot->childNodeCount() == 1 && existingRoot->firstChild()->hasTagName(shadowTag)) {
         newRoot = existingRoot;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to