Title: [109203] trunk/Source/WebCore
Revision
109203
Author
[email protected]
Date
2012-02-29 00:07:16 -0800 (Wed, 29 Feb 2012)

Log Message

[Refactoring] Shadow related attach paths should be in ShadowTree.
https://bugs.webkit.org/show_bug.cgi?id=79854

Reviewed by Ryosuke Niwa.

No new tests. No behavior change.

This change introduces ShadowTree::attachHost() and ShadowTree::detachHost()
and moves shadow-enabled attachment code from Element to ShadowRoot.
This also factored out small ContainerNode method to use it from ShadowTree.

Even after this change, the traveral order in ShadowTree
attachment has some unclear part. Coming changes will clarify
these. This change is aimed to be purely textural.

* dom/ContainerNode.cpp:
(WebCore::ContainerNode::attach):
(WebCore::ContainerNode::detach):
* dom/ContainerNode.h:
(ContainerNode):
(WebCore::ContainerNode::attachAsNode): Added.
(WebCore::ContainerNode::attachChildren): Added.
(WebCore::ContainerNode::attachChildrenIfNeeded): Added.
(WebCore::ContainerNode::attachChildrenLazily): Added.
(WebCore::ContainerNode::detachAsNode): Added.
(WebCore::ContainerNode::detachChildrenIfNeeded): Added.
(WebCore::ContainerNode::detachChildren): Added.
* dom/Element.cpp:
(WebCore::Element::attach):
(WebCore::Element::detach):
* dom/ShadowTree.cpp:
(WebCore::ShadowTree::addShadowRoot):
(WebCore::ShadowTree::removeAllShadowRoots):
(WebCore::ShadowTree::detachHost):
(WebCore):
(WebCore::ShadowTree::attachHost):
(WebCore::ShadowTree::reattachHostChildrenAndShadow):
* dom/ShadowTree.h:
(ShadowTree):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (109202 => 109203)


--- trunk/Source/WebCore/ChangeLog	2012-02-29 08:02:22 UTC (rev 109202)
+++ trunk/Source/WebCore/ChangeLog	2012-02-29 08:07:16 UTC (rev 109203)
@@ -1,3 +1,45 @@
+2012-02-28  MORITA Hajime  <[email protected]>
+
+        [Refactoring] Shadow related attach paths should be in ShadowTree.
+        https://bugs.webkit.org/show_bug.cgi?id=79854
+
+        Reviewed by Ryosuke Niwa.
+
+        No new tests. No behavior change.
+
+        This change introduces ShadowTree::attachHost() and ShadowTree::detachHost()
+        and moves shadow-enabled attachment code from Element to ShadowRoot.
+        This also factored out small ContainerNode method to use it from ShadowTree.
+
+        Even after this change, the traveral order in ShadowTree
+        attachment has some unclear part. Coming changes will clarify
+        these. This change is aimed to be purely textural.
+
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::attach):
+        (WebCore::ContainerNode::detach):
+        * dom/ContainerNode.h:
+        (ContainerNode):
+        (WebCore::ContainerNode::attachAsNode): Added.
+        (WebCore::ContainerNode::attachChildren): Added.
+        (WebCore::ContainerNode::attachChildrenIfNeeded): Added.
+        (WebCore::ContainerNode::attachChildrenLazily): Added.
+        (WebCore::ContainerNode::detachAsNode): Added.
+        (WebCore::ContainerNode::detachChildrenIfNeeded): Added.
+        (WebCore::ContainerNode::detachChildren): Added.
+        * dom/Element.cpp:
+        (WebCore::Element::attach):
+        (WebCore::Element::detach):
+        * dom/ShadowTree.cpp:
+        (WebCore::ShadowTree::addShadowRoot):
+        (WebCore::ShadowTree::removeAllShadowRoots):
+        (WebCore::ShadowTree::detachHost):
+        (WebCore):
+        (WebCore::ShadowTree::attachHost):
+        (WebCore::ShadowTree::reattachHostChildrenAndShadow):
+        * dom/ShadowTree.h:
+        (ShadowTree):
+
 2012-02-28  Arko Saha  <[email protected]>
 
         Microdata: Implement HTMLPropertiesCollection collection.namedItem().

Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (109202 => 109203)


--- trunk/Source/WebCore/dom/ContainerNode.cpp	2012-02-29 08:02:22 UTC (rev 109202)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp	2012-02-29 08:07:16 UTC (rev 109203)
@@ -766,15 +766,13 @@
 
 void ContainerNode::attach()
 {
-    for (Node* child = m_firstChild; child; child = child->nextSibling())
-        child->attach();
+    attachChildren();
     Node::attach();
 }
 
 void ContainerNode::detach()
 {
-    for (Node* child = m_firstChild; child; child = child->nextSibling())
-        child->detach();
+    detachChildren();
     clearChildNeedsStyleRecalc();
     Node::detach();
 }

Modified: trunk/Source/WebCore/dom/ContainerNode.h (109202 => 109203)


--- trunk/Source/WebCore/dom/ContainerNode.h	2012-02-29 08:02:22 UTC (rev 109202)
+++ trunk/Source/WebCore/dom/ContainerNode.h	2012-02-29 08:07:16 UTC (rev 109203)
@@ -94,6 +94,14 @@
     // node that is of the type CDATA_SECTION_NODE, TEXT_NODE or COMMENT_NODE has changed its value.
     virtual void childrenChanged(bool createdByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
 
+    void attachAsNode();
+    void attachChildren();
+    void attachChildrenIfNeeded();
+    void attachChildrenLazily();
+    void detachAsNode();
+    void detachChildren();
+    void detachChildrenIfNeeded();
+
 protected:
     ContainerNode(Document*, ConstructionType = CreateContainer);
 
@@ -146,6 +154,51 @@
 {
 }
 
+inline void ContainerNode::attachAsNode()
+{
+    Node::attach();
+}
+
+inline void ContainerNode::attachChildren()
+{
+    for (Node* child = firstChild(); child; child = child->nextSibling())
+        child->attach();
+}
+
+inline void ContainerNode::attachChildrenIfNeeded()
+{
+    for (Node* child = firstChild(); child; child = child->nextSibling()) {
+        if (!child->attached())
+            child->attach();
+    }
+}
+
+inline void ContainerNode::attachChildrenLazily()
+{
+    for (Node* child = firstChild(); child; child = child->nextSibling())
+        if (!child->attached())
+            child->lazyAttach();
+}
+
+inline void ContainerNode::detachAsNode()
+{
+    Node::detach();
+}
+
+inline void ContainerNode::detachChildrenIfNeeded()
+{
+    for (Node* child = firstChild(); child; child = child->nextSibling()) {
+        if (child->attached())
+            child->detach();
+    }
+}
+
+inline void ContainerNode::detachChildren()
+{
+    for (Node* child = firstChild(); child; child = child->nextSibling())
+        child->detach();
+}
+
 inline unsigned Node::childNodeCount() const
 {
     if (!isContainerNode())

Modified: trunk/Source/WebCore/dom/Element.cpp (109202 => 109203)


--- trunk/Source/WebCore/dom/Element.cpp	2012-02-29 08:02:22 UTC (rev 109202)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-02-29 08:07:16 UTC (rev 109203)
@@ -928,18 +928,9 @@
     StyleSelectorParentPusher parentPusher(this);
 
     // When a shadow root exists, it does the work of attaching the children.
-    if (hasShadowRoot()) {
+    if (ShadowTree* tree = shadowTree()) {
         parentPusher.push();
-        shadowTree()->attach();
-
-        // In a shadow tree, some of light children may be attached by <content> or <shadow>.
-        // However, when there is no content element or content element does not select
-        // all light children, we have to attach the rest of light children here.
-        for (Node* child = firstChild(); child; child = child->nextSibling()) {
-            if (!child->attached())
-                child->attach();
-        }
-        Node::attach();
+        tree->attachHost(this);
     } else {
         if (firstChild())
             parentPusher.push();
@@ -967,18 +958,11 @@
     if (hasRareData())
         rareData()->resetComputedStyle();
 
-    if (hasShadowRoot()) {
-        for (Node* child = firstChild(); child; child = child->nextSibling()) {
-            if (child->attached())
-                child->detach();
-        }
-
-        shadowTree()->detach();
-        Node::detach();
-    } else
+    if (ShadowTree* tree = shadowTree())
+        tree->detachHost(this);
+    else
         ContainerNode::detach();
 
-
     RenderWidget::resumeWidgetHierarchyUpdates();
 }
 

Modified: trunk/Source/WebCore/dom/ShadowTree.cpp (109202 => 109203)


--- trunk/Source/WebCore/dom/ShadowTree.cpp	2012-02-29 08:02:22 UTC (rev 109202)
+++ trunk/Source/WebCore/dom/ShadowTree.cpp	2012-02-29 08:07:16 UTC (rev 109203)
@@ -86,8 +86,7 @@
     if (shadowHost->attached()) {
         shadowRoot->lazyAttach();
         detach();
-        for (Node* child = shadowHost->firstChild(); child; child = child->nextSibling())
-            child->detach();
+        shadowHost->detachChildren();
     }
 
     m_shadowRoots.push(shadowRoot.get());
@@ -118,12 +117,8 @@
             oldRoot->removedFromTree(true);
     }
 
-    if (shadowHost->attached()) {
-        for (Node* child = shadowHost->firstChild(); child; child = child->nextSibling()) {
-            if (!child->attached())
-                child->lazyAttach();
-        }
-    }
+    if (shadowHost->attached())
+        shadowHost->attachChildrenLazily();
 }
 
 void ShadowTree::insertedIntoDocument()
@@ -171,6 +166,14 @@
         contentSelector->didSelect();
 }
 
+void ShadowTree::attachHost(Element* host)
+{
+    attach();
+    host->attachChildrenIfNeeded();
+    host->attachAsNode();
+}
+
+
 void ShadowTree::detach()
 {
     for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot()) {
@@ -179,6 +182,13 @@
     }
 }
 
+void ShadowTree::detachHost(Element* host)
+{
+    host->detachChildrenIfNeeded();
+    detach();
+    host->detachAsNode();
+}
+
 InsertionPoint* ShadowTree::insertionPointFor(Node* node) const
 {
     if (!m_selector)
@@ -269,21 +279,10 @@
 {
     ASSERT(youngestShadowRoot());
 
-    Node* hostNode = youngestShadowRoot()->host();
-    if (!hostNode)
-        return;
-
-    for (Node* child = hostNode->firstChild(); child; child = child->nextSibling()) {
-        if (child->attached())
-            child->detach();
-    }
-
+    Element* hostNode = youngestShadowRoot()->host();
+    hostNode->detachChildrenIfNeeded();
     reattach();
-
-    for (Node* child = hostNode->firstChild(); child; child = child->nextSibling()) {
-        if (!child->attached())
-            child->attach();
-    }
+    hostNode->attachChildrenIfNeeded();
 }
 
 HTMLContentSelector* ShadowTree::ensureSelector()

Modified: trunk/Source/WebCore/dom/ShadowTree.h (109202 => 109203)


--- trunk/Source/WebCore/dom/ShadowTree.h	2012-02-29 08:02:22 UTC (rev 109202)
+++ trunk/Source/WebCore/dom/ShadowTree.h	2012-02-29 08:07:16 UTC (rev 109203)
@@ -62,6 +62,8 @@
     void attach();
     void detach();
     void reattach();
+    void attachHost(Element*);
+    void detachHost(Element*);
 
     bool childNeedsStyleRecalc();
     bool needsStyleRecalc();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to