InsertionPoint::attach should be consistent with Element.
authorshinyak@chromium.org <shinyak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Mar 2012 06:59:02 +0000 (06:59 +0000)
committershinyak@chromium.org <shinyak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Mar 2012 06:59:02 +0000 (06:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=80373

Reviewed by Hajime Morita.

This patch is preparation for coming <shadow> patches.

InsertionPoint used to attach fallback elements before attaching distributed elements.
To be consistent with Element::attach behavior, attaching distributed elements first is
natural, because Element attaches a shadow tree first.

Also, this patch extracts a few methods form InsretionPoint::attach() and detach()
to keep code clean. They will become messy without this refactoring when adding
<shadow> patch.

No new tests. Should be covered by existing tests.

* html/shadow/InsertionPoint.cpp:
(WebCore::InsertionPoint::attach):
(WebCore::InsertionPoint::detach):
(WebCore::InsertionPoint::distributeHostChildren):
(WebCore):
(WebCore::InsertionPoint::clearDistribution):
(WebCore::InsertionPoint::attachDistributedNode):
* html/shadow/InsertionPoint.h:
(InsertionPoint):

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

Source/WebCore/ChangeLog
Source/WebCore/html/shadow/InsertionPoint.cpp
Source/WebCore/html/shadow/InsertionPoint.h

index 945ee25..f69b611 100644 (file)
@@ -1,3 +1,32 @@
+2012-03-05  Shinya Kawanaka  <shinyak@chromium.org>
+
+        InsertionPoint::attach should be consistent with Element.
+        https://bugs.webkit.org/show_bug.cgi?id=80373
+
+        Reviewed by Hajime Morita.
+
+        This patch is preparation for coming <shadow> patches.
+
+        InsertionPoint used to attach fallback elements before attaching distributed elements.
+        To be consistent with Element::attach behavior, attaching distributed elements first is
+        natural, because Element attaches a shadow tree first.
+
+        Also, this patch extracts a few methods form InsretionPoint::attach() and detach()
+        to keep code clean. They will become messy without this refactoring when adding
+        <shadow> patch.
+
+        No new tests. Should be covered by existing tests.
+
+        * html/shadow/InsertionPoint.cpp:
+        (WebCore::InsertionPoint::attach):
+        (WebCore::InsertionPoint::detach):
+        (WebCore::InsertionPoint::distributeHostChildren):
+        (WebCore):
+        (WebCore::InsertionPoint::clearDistribution):
+        (WebCore::InsertionPoint::attachDistributedNode):
+        * html/shadow/InsertionPoint.h:
+        (InsertionPoint):
+
 2012-03-05  Adam Barth  <abarth@webkit.org>
 
         Attempt to fix a number of GTK tests.
index 365695d..39fa720 100644 (file)
@@ -48,31 +48,23 @@ InsertionPoint::~InsertionPoint()
 
 void InsertionPoint::attach()
 {
-    ShadowRoot* root = toShadowRoot(shadowTreeRootNode());
-
-    if (root) {
-        HTMLContentSelector* selector = root->tree()->ensureSelector();
-        selector->unselect(&m_selections);
-        selector->select(this, &m_selections);
+    if (ShadowRoot* root = toShadowRoot(shadowTreeRootNode())) {
+        distributeHostChildren(root->tree());
+        attachDistributedNode();
     }
 
     HTMLElement::attach();
-
-    if (root) {
-        for (HTMLContentSelection* selection = m_selections.first(); selection; selection = selection->next())
-            selection->node()->attach();
-    }
 }
 
 void InsertionPoint::detach()
 {
     if (ShadowRoot* root = toShadowRoot(shadowTreeRootNode())) {
-        if (HTMLContentSelector* selector = root->tree()->selector())
-            selector->unselect(&m_selections);
+        ShadowTree* tree = root->tree();
+        clearDistribution(tree);
 
         // When shadow element is detached, shadow tree should be recreated to re-calculate selector for
         // other insertion points.
-        root->tree()->setNeedsReattachHostChildrenAndShadow();
+        tree->setNeedsReattachHostChildrenAndShadow();
     }
 
     ASSERT(m_selections.isEmpty());
@@ -91,4 +83,23 @@ bool InsertionPoint::rendererIsNeeded(const NodeRenderingContext& context)
     return !isShadowBoundary() && HTMLElement::rendererIsNeeded(context);
 }
 
+inline void InsertionPoint::distributeHostChildren(ShadowTree* tree)
+{
+    HTMLContentSelector* selector = tree->ensureSelector();
+    selector->unselect(&m_selections);
+    selector->select(this, &m_selections);
+}
+
+inline void InsertionPoint::clearDistribution(ShadowTree* tree)
+{
+    if (HTMLContentSelector* selector = tree->selector())
+        selector->unselect(&m_selections);
+}
+
+inline void InsertionPoint::attachDistributedNode()
+{
+    for (HTMLContentSelection* selection = m_selections.first(); selection; selection = selection->next())
+        selection->node()->attach();
+}
+
 } // namespace WebCore
index 3228ade..7e5ade9 100644 (file)
@@ -54,6 +54,11 @@ protected:
     InsertionPoint(const QualifiedName&, Document*);
     virtual bool rendererIsNeeded(const NodeRenderingContext&) OVERRIDE;
 
+private:
+    void distributeHostChildren(ShadowTree*);
+    void clearDistribution(ShadowTree*);
+    void attachDistributedNode();
+
     HTMLContentSelectionList m_selections;
 };