Remove AttachContext
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Aug 2013 12:33:15 +0000 (12:33 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Aug 2013 12:33:15 +0000 (12:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=120518

Reviewed by Andreas Kling.

This type is not useful anymore. Just pass the precomputed style to attachRenderTree and reattach-or-not flag to detachRenderTree.

* style/StyleResolveTree.cpp:
(WebCore::Style::createRendererIfNeeded):
(WebCore::Style::attachChildren):
(WebCore::Style::attachShadowRoot):
(WebCore::Style::attachRenderTree):
(WebCore::Style::detachChildren):
(WebCore::Style::detachShadowRoot):
(WebCore::Style::detachRenderTree):
(WebCore::Style::reattachRenderTree):
(WebCore::Style::resolveLocal):
* style/StyleResolveTree.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154873 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp
Source/WebCore/style/StyleResolveTree.cpp
Source/WebCore/style/StyleResolveTree.h

index 2290433b53043183cf393aa748d930876b4bd5e3..36d395630b3d5adb2d027291eb14f7ad3ed793ee 100644 (file)
@@ -1,3 +1,24 @@
+2013-08-30  Antti Koivisto  <antti@apple.com>
+
+        Remove AttachContext
+        https://bugs.webkit.org/show_bug.cgi?id=120518
+
+        Reviewed by Andreas Kling.
+
+        This type is not useful anymore. Just pass the precomputed style to attachRenderTree and reattach-or-not flag to detachRenderTree.
+
+        * style/StyleResolveTree.cpp:
+        (WebCore::Style::createRendererIfNeeded):
+        (WebCore::Style::attachChildren):
+        (WebCore::Style::attachShadowRoot):
+        (WebCore::Style::attachRenderTree):
+        (WebCore::Style::detachChildren):
+        (WebCore::Style::detachShadowRoot):
+        (WebCore::Style::detachRenderTree):
+        (WebCore::Style::reattachRenderTree):
+        (WebCore::Style::resolveLocal):
+        * style/StyleResolveTree.h:
+
 2013-08-30  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r154826.
index 0ab05963124df6052d4c5644464a160c77007ec1..000c441190bd93d0612baf97371c6b60ef85697b 100644 (file)
@@ -1375,11 +1375,8 @@ void Element::unregisterNamedFlowContentNode()
 
 void Element::lazyReattach(ShouldSetAttached shouldSetAttached)
 {
-    Style::AttachContext context;
-    context.performingReattach = true;
-
     if (attached())
-        Style::detachRenderTree(this, context);
+        Style::detachRenderTreeInReattachMode(this);
     lazyAttach(shouldSetAttached);
 }
 
index 66010152aa012d2637910ea29a8c0f2d9a226608..337f9f54657a6549fad1628490f4445bf24aaeb4 100644 (file)
@@ -54,6 +54,11 @@ namespace WebCore {
 
 namespace Style {
 
+enum DetachType { NormalDetach, ReattachDetach };
+
+static void attachRenderTree(Element*, RenderStyle* resolvedStyle);
+static void detachRenderTree(Element*, DetachType);
+
 Change determineChange(const RenderStyle* s1, const RenderStyle* s2, Settings* settings)
 {
     if (!s1 || !s2)
@@ -188,14 +193,14 @@ static RenderNamedFlowThread* moveToFlowThreadIfNeeded(Element& element, const R
 }
 #endif
 
-static void createRendererIfNeeded(Element& element, const AttachContext& context)
+static void createRendererIfNeeded(Element& element, RenderStyle* resolvedStyle)
 {
     ASSERT(!element.renderer());
 
     Document& document = *element.document();
     ContainerNode* renderingParentNode = NodeRenderingTraversal::parent(&element);
 
-    RefPtr<RenderStyle> style = context.resolvedStyle;
+    RefPtr<RenderStyle> style = resolvedStyle;
 
     element.setIsInsideRegion(false);
 
@@ -431,11 +436,8 @@ static bool childAttachedAllowedWhenAttachingChildren(ContainerNode& node)
 }
 #endif
 
-static void attachChildren(ContainerNode& current, const AttachContext& context)
+static void attachChildren(ContainerNode& current)
 {
-    AttachContext childrenContext(context);
-    childrenContext.resolvedStyle = 0;
-
     for (Node* child = current.firstChild(); child; child = child->nextSibling()) {
         ASSERT(!child->attached() || childAttachedAllowedWhenAttachingChildren(current));
         if (child->attached())
@@ -445,18 +447,18 @@ static void attachChildren(ContainerNode& current, const AttachContext& context)
             continue;
         }
         if (child->isElementNode())
-            attachRenderTree(toElement(child), childrenContext);
+            attachRenderTree(toElement(child), nullptr);
     }
 }
 
-static void attachShadowRoot(ShadowRoot& shadowRoot, const AttachContext& context)
+static void attachShadowRoot(ShadowRoot& shadowRoot)
 {
     if (shadowRoot.attached())
         return;
     StyleResolver& styleResolver = shadowRoot.document()->ensureStyleResolver();
     styleResolver.pushParentShadowRoot(&shadowRoot);
 
-    attachChildren(shadowRoot, context);
+    attachChildren(shadowRoot);
 
     styleResolver.popParentShadowRoot(&shadowRoot);
 
@@ -464,7 +466,7 @@ static void attachShadowRoot(ShadowRoot& shadowRoot, const AttachContext& contex
     shadowRoot.setAttached(true);
 }
 
-void attachRenderTree(Element* current, const AttachContext& context)
+static void attachRenderTree(Element* current, RenderStyle* resolvedStyle)
 {
     PostAttachCallbackDisabler callbackDisabler(current);
     WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
@@ -472,7 +474,7 @@ void attachRenderTree(Element* current, const AttachContext& context)
     if (current->hasCustomStyleResolveCallbacks())
         current->willAttachRenderers();
 
-    createRendererIfNeeded(*current, context);
+    createRendererIfNeeded(*current, resolvedStyle);
 
     if (current->parentElement() && current->parentElement()->isInCanvasSubtree())
         current->setIsInCanvasSubtree(true);
@@ -484,11 +486,11 @@ void attachRenderTree(Element* current, const AttachContext& context)
     // 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);
     } else if (current->firstChild())
         parentPusher.push();
 
-    attachChildren(*current, context);
+    attachChildren(*current);
 
     Node* sibling = current->nextSibling();
     if (current->renderer() && sibling && !sibling->renderer() && sibling->attached())
@@ -510,32 +512,29 @@ void attachRenderTree(Element* current, const AttachContext& context)
         current->didAttachRenderers();
 }
 
-static void detachChildren(ContainerNode& current, const AttachContext& context)
+static void detachChildren(ContainerNode& current, DetachType detachType)
 {
-    AttachContext childrenContext(context);
-    childrenContext.resolvedStyle = 0;
-
     for (Node* child = current.firstChild(); child; child = child->nextSibling()) {
         if (child->isTextNode()) {
             Style::detachTextRenderer(*toText(child));
             continue;
         }
         if (child->isElementNode())
-            detachRenderTree(toElement(child), childrenContext);
+            detachRenderTree(toElement(child), detachType);
     }
     current.clearChildNeedsStyleRecalc();
 }
 
-static void detachShadowRoot(ShadowRoot& shadowRoot, const AttachContext& context)
+static void detachShadowRoot(ShadowRoot& shadowRoot, DetachType detachType)
 {
     if (!shadowRoot.attached())
         return;
-    detachChildren(shadowRoot, context);
+    detachChildren(shadowRoot, detachType);
 
     shadowRoot.setAttached(false);
 }
 
-void detachRenderTree(Element* current, const AttachContext& context)
+static void detachRenderTree(Element* current, DetachType detachType)
 {
     WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
 
@@ -546,13 +545,13 @@ void detachRenderTree(Element* current, const AttachContext& context)
 
     // Do not remove the element's hovered and active status
     // if performing a reattach.
-    if (!context.performingReattach)
+    if (detachType != ReattachDetach)
         current->clearHoverAndActiveStatusBeforeDetachingRenderer();
 
     if (ShadowRoot* shadowRoot = current->shadowRoot())
-        detachShadowRoot(*shadowRoot, context);
+        detachShadowRoot(*shadowRoot, detachType);
 
-    detachChildren(*current, context);
+    detachChildren(*current, detachType);
 
     if (current->renderer())
         current->renderer()->destroyAndCleanupAnonymousWrappers();
@@ -564,17 +563,6 @@ void detachRenderTree(Element* current, const AttachContext& context)
         current->didDetachRenderers();
 }
 
-void reattachRenderTree(Element* current, const AttachContext& context)
-{
-    AttachContext reattachContext(context);
-    reattachContext.performingReattach = true;
-
-    if (current->attached())
-        detachRenderTree(current, reattachContext);
-
-    attachRenderTree(current, reattachContext);
-}
-
 static bool pseudoStyleCacheIsInvalid(RenderObject* renderer, RenderStyle* newStyle)
 {
     const RenderStyle* currentStyle = renderer->style();
@@ -621,9 +609,9 @@ static Change resolveLocal(Element* current, Change inheritedChange)
         localChange = determineChange(currentStyle.get(), newStyle.get(), document->settings());
     }
     if (localChange == Detach) {
-        AttachContext reattachContext;
-        reattachContext.resolvedStyle = newStyle.get();
-        reattachRenderTree(current, reattachContext);
+        if (current->attached())
+            detachRenderTree(current, ReattachDetach);
+        attachRenderTree(current, newStyle.get());
         return Detach;
     }
 
@@ -844,5 +832,27 @@ void resolveTree(Document* document, Change change)
     }
 }
 
+void attachRenderTree(Element* element)
+{
+    attachRenderTree(element, nullptr);
+}
+
+void detachRenderTree(Element* element)
+{
+    detachRenderTree(element, NormalDetach);
+}
+
+void detachRenderTreeInReattachMode(Element* element)
+{
+    detachRenderTree(element, ReattachDetach);
+}
+
+void reattachRenderTree(Element* current)
+{
+    if (current->attached())
+        detachRenderTree(current, ReattachDetach);
+    attachRenderTree(current, nullptr);
+}
+
 }
 }
index 1e9c23c4b8d8b3512f285270288165204a2cc717..990ccb37865615c76f38c6a4f5b2d9736a1640aa 100644 (file)
@@ -41,15 +41,11 @@ enum Change { NoChange, NoInherit, Inherit, Detach, Force };
 void resolveTree(Element*, Change);
 void resolveTree(Document*, Change);
 
-struct AttachContext {
-    RenderStyle* resolvedStyle;
-    bool performingReattach;
-
-    AttachContext() : resolvedStyle(0), performingReattach(false) { }
-};
-void attachRenderTree(Element*, const AttachContext& = AttachContext());
-void detachRenderTree(Element*, const AttachContext& = AttachContext());
-void reattachRenderTree(Element*, const AttachContext& = AttachContext());
+void attachRenderTree(Element*);
+void detachRenderTree(Element*);
+void reattachRenderTree(Element*);
+// FIXME: This is only used for "lazy reattach" for shadow trees.
+void detachRenderTreeInReattachMode(Element*);
 
 void attachTextRenderer(Text&);
 void detachTextRenderer(Text&);