Title: [154746] trunk/Source/WebCore
Revision
154746
Author
[email protected]
Date
2013-08-28 07:41:12 -0700 (Wed, 28 Aug 2013)

Log Message

Share attach loops between Elements and ShadowRoots
https://bugs.webkit.org/show_bug.cgi?id=120414

Reviewed Andreas Kling.

* style/StyleResolveTree.cpp:
(WebCore::Style::attachChildren):
(WebCore::Style::attachShadowRoot):
(WebCore::Style::detachChildren):
(WebCore::Style::detachShadowRoot):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (154745 => 154746)


--- trunk/Source/WebCore/ChangeLog	2013-08-28 14:31:16 UTC (rev 154745)
+++ trunk/Source/WebCore/ChangeLog	2013-08-28 14:41:12 UTC (rev 154746)
@@ -1,3 +1,16 @@
+2013-08-28  Antti Koivisto  <[email protected]>
+
+        Share attach loops between Elements and ShadowRoots
+        https://bugs.webkit.org/show_bug.cgi?id=120414
+
+        Reviewed Andreas Kling.
+
+        * style/StyleResolveTree.cpp:
+        (WebCore::Style::attachChildren):
+        (WebCore::Style::attachShadowRoot):
+        (WebCore::Style::detachChildren):
+        (WebCore::Style::detachShadowRoot):
+
 2013-08-28  Anders Carlsson  <[email protected]>
 
         Clean up XPathExpressionNode and XPath::Function

Modified: trunk/Source/WebCore/style/StyleResolveTree.cpp (154745 => 154746)


--- trunk/Source/WebCore/style/StyleResolveTree.cpp	2013-08-28 14:31:16 UTC (rev 154745)
+++ trunk/Source/WebCore/style/StyleResolveTree.cpp	2013-08-28 14:41:12 UTC (rev 154746)
@@ -287,49 +287,25 @@
     textRenderer->setTextWithOffset(textNode.dataImpl(), offsetOfReplacedData, lengthOfReplacedData);
 }
 
-
-static void attachShadowRoot(ShadowRoot* shadowRoot, const AttachContext& context)
-{
-    if (shadowRoot->attached())
-        return;
-    StyleResolver& styleResolver = shadowRoot->document()->ensureStyleResolver();
-    styleResolver.pushParentShadowRoot(shadowRoot);
-
-    Style::AttachContext childrenContext(context);
-    childrenContext.resolvedStyle = 0;
-    for (Node* child = shadowRoot->firstChild(); child; child = child->nextSibling()) {
-        if (child->isTextNode()) {
-            attachTextRenderer(*toText(child));
-            continue;
-        }
-        if (child->isElementNode())
-            attachRenderTree(toElement(child), childrenContext);
-    }
-    styleResolver.popParentShadowRoot(shadowRoot);
-
-    shadowRoot->clearNeedsStyleRecalc();
-    shadowRoot->setAttached(true);
-}
-
 #ifndef NDEBUG
-static bool childAttachedAllowedWhenAttachingChildren(ContainerNode* node)
+static bool childAttachedAllowedWhenAttachingChildren(ContainerNode& node)
 {
-    if (node->isShadowRoot())
+    if (node.isShadowRoot())
         return true;
-    if (node->isInsertionPoint())
+    if (node.isInsertionPoint())
         return true;
-    if (node->isElementNode() && toElement(node)->shadowRoot())
+    if (node.isElementNode() && toElement(&node)->shadowRoot())
         return true;
     return false;
 }
 #endif
 
-static void attachChildren(Element* current, const AttachContext& context)
+static void attachChildren(ContainerNode& current, const AttachContext& context)
 {
     AttachContext childrenContext(context);
     childrenContext.resolvedStyle = 0;
 
-    for (Node* child = current->firstChild(); child; child = child->nextSibling()) {
+    for (Node* child = current.firstChild(); child; child = child->nextSibling()) {
         ASSERT(!child->attached() || childAttachedAllowedWhenAttachingChildren(current));
         if (child->attached())
             continue;
@@ -342,6 +318,21 @@
     }
 }
 
+static void attachShadowRoot(ShadowRoot& shadowRoot, const AttachContext& context)
+{
+    if (shadowRoot.attached())
+        return;
+    StyleResolver& styleResolver = shadowRoot.document()->ensureStyleResolver();
+    styleResolver.pushParentShadowRoot(&shadowRoot);
+
+    attachChildren(shadowRoot, context);
+
+    styleResolver.popParentShadowRoot(&shadowRoot);
+
+    shadowRoot.clearNeedsStyleRecalc();
+    shadowRoot.setAttached(true);
+}
+
 void attachRenderTree(Element* current, const AttachContext& context)
 {
     PostAttachCallbackDisabler callbackDisabler(current);
@@ -362,11 +353,11 @@
     // When a shadow root exists, it does the work of attaching the children.
     if (ShadowRoot* shadowRoot = current->shadowRoot()) {
         parentPusher.push();
-        attachShadowRoot(shadowRoot, context);
+        attachShadowRoot(*shadowRoot, context);
     } else if (current->firstChild())
         parentPusher.push();
 
-    attachChildren(current, context);
+    attachChildren(*current, context);
 
     Node* sibling = current->nextSibling();
     if (current->renderer() && sibling && !sibling->renderer() && sibling->attached())
@@ -388,38 +379,29 @@
         current->didAttachRenderers();
 }
 
-static void detachShadowRoot(ShadowRoot* shadowRoot, const AttachContext& context)
+static void detachChildren(ContainerNode& current, const AttachContext& context)
 {
-    if (!shadowRoot->attached())
-        return;
-    Style::AttachContext childrenContext(context);
+    AttachContext childrenContext(context);
     childrenContext.resolvedStyle = 0;
-    for (Node* child = shadowRoot->firstChild(); child; child = child->nextSibling()) {
+
+    for (Node* child = current.firstChild(); child; child = child->nextSibling()) {
         if (child->isTextNode()) {
             Style::detachTextRenderer(*toText(child));
             continue;
         }
         if (child->isElementNode())
-            detachRenderTree(toElement(child), context);
+            detachRenderTree(toElement(child), childrenContext);
     }
-    shadowRoot->clearChildNeedsStyleRecalc();
-    shadowRoot->setAttached(false);
+    current.clearChildNeedsStyleRecalc();
 }
 
-static void detachChildren(Element* current, const AttachContext& context)
+static void detachShadowRoot(ShadowRoot& shadowRoot, const AttachContext& context)
 {
-    AttachContext childrenContext(context);
-    childrenContext.resolvedStyle = 0;
+    if (!shadowRoot.attached())
+        return;
+    detachChildren(shadowRoot, context);
 
-    for (Node* child = current->firstChild(); child; child = child->nextSibling()) {
-        if (child->isTextNode()) {
-            Style::detachTextRenderer(*toText(child));
-            continue;
-        }
-        if (child->isElementNode())
-            detachRenderTree(toElement(child), childrenContext);
-    }
-    current->clearChildNeedsStyleRecalc();
+    shadowRoot.setAttached(false);
 }
 
 void detachRenderTree(Element* current, const AttachContext& context)
@@ -437,9 +419,9 @@
         current->clearHoverAndActiveStatusBeforeDetachingRenderer();
 
     if (ShadowRoot* shadowRoot = current->shadowRoot())
-        detachShadowRoot(shadowRoot, context);
+        detachShadowRoot(*shadowRoot, context);
 
-    detachChildren(current, context);
+    detachChildren(*current, context);
 
     if (current->renderer())
         current->renderer()->destroyAndCleanupAnonymousWrappers();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to