Title: [108713] trunk/Source/WebCore
Revision
108713
Author
[email protected]
Date
2012-02-23 18:37:02 -0800 (Thu, 23 Feb 2012)

Log Message

ShadowRootList should have recalculation flag instead of ShadowRoot.
https://bugs.webkit.org/show_bug.cgi?id=79071

Reviewed by Hajime Morita.

When light children or shadow children are changed, we currently re-construct a shadow subtree.
However, when supporting multiple shadow subtrees, all shadow subtrees should be re-constructed.
So ShadowRootList should have re-construction flag instead of ShadowRoot.

Also, re-construction methods in ShadowRoot should be moved to ShadowRootList.

No new tests, should be convered by existing tests.

* dom/Element.cpp:
(WebCore::Element::recalcStyle):
(WebCore::Element::childrenChanged):
* dom/NodeRenderingContext.cpp:
(WebCore::NodeRenderingContext::hostChildrenChanged):
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::ShadowRoot):
(WebCore::ShadowRoot::list):
* dom/ShadowRoot.h:
(WebCore):
(ShadowRoot):
* dom/ShadowRootList.cpp:
(WebCore::ShadowRootList::ShadowRootList):
(WebCore::ShadowRootList::reattach):
(WebCore):
(WebCore::ShadowRootList::childNeedsStyleRecalc):
(WebCore::ShadowRootList::needsStyleRecalc):
(WebCore::ShadowRootList::recalcShadowTreeStyle):
(WebCore::ShadowRootList::needsReattachHostChildrenAndShadow):
(WebCore::ShadowRootList::hostChildrenChanged):
(WebCore::ShadowRootList::setNeedsReattachHostChildrenAndShadow):
(WebCore::ShadowRootList::reattachHostChildrenAndShadow):
* dom/ShadowRootList.h:
(WebCore):
(ShadowRootList):
(WebCore::ShadowRootList::clearNeedsReattachHostChildrenAndShadow):
* html/shadow/HTMLContentElement.cpp:
(WebCore::HTMLContentElement::attach):
(WebCore::HTMLContentElement::detach):
(WebCore::HTMLContentElement::parseAttribute):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (108712 => 108713)


--- trunk/Source/WebCore/ChangeLog	2012-02-24 02:20:19 UTC (rev 108712)
+++ trunk/Source/WebCore/ChangeLog	2012-02-24 02:37:02 UTC (rev 108713)
@@ -1,3 +1,49 @@
+2012-02-23  Shinya Kawanaka  <[email protected]>
+
+        ShadowRootList should have recalculation flag instead of ShadowRoot.
+        https://bugs.webkit.org/show_bug.cgi?id=79071
+
+        Reviewed by Hajime Morita.
+
+        When light children or shadow children are changed, we currently re-construct a shadow subtree.
+        However, when supporting multiple shadow subtrees, all shadow subtrees should be re-constructed.
+        So ShadowRootList should have re-construction flag instead of ShadowRoot.
+
+        Also, re-construction methods in ShadowRoot should be moved to ShadowRootList.
+
+        No new tests, should be convered by existing tests.
+
+        * dom/Element.cpp:
+        (WebCore::Element::recalcStyle):
+        (WebCore::Element::childrenChanged):
+        * dom/NodeRenderingContext.cpp:
+        (WebCore::NodeRenderingContext::hostChildrenChanged):
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::ShadowRoot):
+        (WebCore::ShadowRoot::list):
+        * dom/ShadowRoot.h:
+        (WebCore):
+        (ShadowRoot):
+        * dom/ShadowRootList.cpp:
+        (WebCore::ShadowRootList::ShadowRootList):
+        (WebCore::ShadowRootList::reattach):
+        (WebCore):
+        (WebCore::ShadowRootList::childNeedsStyleRecalc):
+        (WebCore::ShadowRootList::needsStyleRecalc):
+        (WebCore::ShadowRootList::recalcShadowTreeStyle):
+        (WebCore::ShadowRootList::needsReattachHostChildrenAndShadow):
+        (WebCore::ShadowRootList::hostChildrenChanged):
+        (WebCore::ShadowRootList::setNeedsReattachHostChildrenAndShadow):
+        (WebCore::ShadowRootList::reattachHostChildrenAndShadow):
+        * dom/ShadowRootList.h:
+        (WebCore):
+        (ShadowRootList):
+        (WebCore::ShadowRootList::clearNeedsReattachHostChildrenAndShadow):
+        * html/shadow/HTMLContentElement.cpp:
+        (WebCore::HTMLContentElement::attach):
+        (WebCore::HTMLContentElement::detach):
+        (WebCore::HTMLContentElement::parseAttribute):
+
 2012-02-23  Roland Steiner  <[email protected]>
 
         Unreviewed: add clause in ASSERT missing from r108474.

Modified: trunk/Source/WebCore/dom/Element.cpp (108712 => 108713)


--- trunk/Source/WebCore/dom/Element.cpp	2012-02-24 02:20:19 UTC (rev 108712)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-02-24 02:37:02 UTC (rev 108713)
@@ -1126,10 +1126,10 @@
     }
     // FIXME: This does not care about sibling combinators. Will be necessary in XBL2 world.
     if (hasShadowRoot()) {
-        ShadowRoot* shadow = shadowRootList()->youngestShadowRoot();
-        if (change >= Inherit || shadow->childNeedsStyleRecalc() || shadow->needsStyleRecalc()) {
+        ShadowRootList* list = shadowRootList();
+        if (change >= Inherit || list->childNeedsStyleRecalc() || list->needsStyleRecalc()) {
             parentPusher.push();
-            shadow->recalcShadowTreeStyle(change);
+            list->recalcShadowTreeStyle(change);
         }
     }
 
@@ -1360,8 +1360,8 @@
         checkForSiblingStyleChanges(this, renderStyle(), false, beforeChange, afterChange, childCountDelta);
 
     if (hasRareData()) {
-        if (ShadowRootList* list = shadowRootList())
-            list->hostChildrenChanged();
+        if (hasShadowRoot())
+            shadowRootList()->hostChildrenChanged();
     }
 }
 

Modified: trunk/Source/WebCore/dom/NodeRenderingContext.cpp (108712 => 108713)


--- trunk/Source/WebCore/dom/NodeRenderingContext.cpp	2012-02-24 02:20:19 UTC (rev 108712)
+++ trunk/Source/WebCore/dom/NodeRenderingContext.cpp	2012-02-24 02:37:02 UTC (rev 108713)
@@ -264,7 +264,7 @@
 void NodeRenderingContext::hostChildrenChanged()
 {
     if (m_phase == AttachingNotDistributed)
-        m_visualParentShadowRoot->hostChildrenChanged();
+        m_visualParentShadowRoot->host()->shadowRootList()->hostChildrenChanged();
 }
 
 bool NodeRenderingContext::shouldCreateRenderer() const

Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (108712 => 108713)


--- trunk/Source/WebCore/dom/ShadowRoot.cpp	2012-02-24 02:20:19 UTC (rev 108712)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp	2012-02-24 02:37:02 UTC (rev 108713)
@@ -36,7 +36,6 @@
 #include "NodeRareData.h"
 #include "ShadowRootList.h"
 #include "SVGNames.h"
-#include "Text.h"
 
 #if ENABLE(SHADOW_DOM)
 #include "RuntimeEnabledFeatures.h"
@@ -50,7 +49,6 @@
     , m_prev(0)
     , m_next(0)
     , m_applyAuthorSheets(false)
-    , m_needsRecalculateContent(false)
 {
     ASSERT(document);
     
@@ -159,40 +157,13 @@
     }
 }
 
-void ShadowRoot::recalcShadowTreeStyle(StyleChange change)
+ShadowRootList* ShadowRoot::list() const
 {
-    if (needsReattachHostChildrenAndShadow())
-        reattachHostChildrenAndShadow();
-    else {
-        for (Node* n = firstChild(); n; n = n->nextSibling()) {
-            if (n->isElementNode())
-                static_cast<Element*>(n)->recalcStyle(change);
-            else if (n->isTextNode())
-                toText(n)->recalcTextStyle(change);
-        }
-    }
-
-    clearNeedsReattachHostChildrenAndShadow();
-    clearNeedsStyleRecalc();
-    clearChildNeedsStyleRecalc();
+    if (host())
+        return host()->shadowRootList();
+    return 0;
 }
 
-void ShadowRoot::setNeedsReattachHostChildrenAndShadow()
-{
-    m_needsRecalculateContent = true;
-    if (shadowHost())
-        shadowHost()->setNeedsStyleRecalc();
-}
-
-void ShadowRoot::hostChildrenChanged()
-{
-    if (!hasContentElement())
-        return;
-
-    // This results in forced detaching/attaching of the shadow render tree. See ShadowRoot::recalcStyle().
-    setNeedsReattachHostChildrenAndShadow();
-}
-
 bool ShadowRoot::hasContentElement() const
 {
     for (Node* n = firstChild(); n; n = n->traverseNextNode(this)) {
@@ -226,23 +197,4 @@
         selector->didSelect();
 }
 
-void ShadowRoot::reattachHostChildrenAndShadow()
-{
-    Node* hostNode = host();
-    if (!hostNode)
-        return;
-
-    for (Node* child = hostNode->firstChild(); child; child = child->nextSibling()) {
-        if (child->attached())
-            child->detach();
-    }
-
-    reattach();
-
-    for (Node* child = hostNode->firstChild(); child; child = child->nextSibling()) {
-        if (!child->attached())
-            child->attach();
-    }
 }
-
-} // namespace

Modified: trunk/Source/WebCore/dom/ShadowRoot.h (108712 => 108713)


--- trunk/Source/WebCore/dom/ShadowRoot.h	2012-02-24 02:20:19 UTC (rev 108712)
+++ trunk/Source/WebCore/dom/ShadowRoot.h	2012-02-24 02:37:02 UTC (rev 108713)
@@ -38,6 +38,7 @@
 class HTMLContentElement;
 class HTMLContentSelector;
 class InsertionPoint;
+class ShadowRootList;
 
 class ShadowRoot : public DocumentFragment, public TreeScope, public DoublyLinkedListNode<ShadowRoot> {
     friend class WTF::DoublyLinkedListNode<ShadowRoot>;
@@ -64,16 +65,18 @@
     void hostChildrenChanged();
 
     virtual void attach();
-    void reattachHostChildrenAndShadow();
 
     virtual bool applyAuthorSheets() const;
     void setApplyAuthorSheets(bool);
 
     Element* host() const { return shadowHost(); }
+    ShadowRootList* list() const;
 
     ShadowRoot* youngerShadowRoot() { return prev(); }
     ShadowRoot* olderShadowRoot() { return next(); }
 
+    bool hasContentElement() const;
+
 private:
     ShadowRoot(Document*);
     virtual ~ShadowRoot();
@@ -82,24 +85,11 @@
     virtual PassRefPtr<Node> cloneNode(bool deep);
     virtual bool childTypeAllowed(NodeType) const;
 
-    bool hasContentElement() const;
-
     ShadowRoot* m_prev;
     ShadowRoot* m_next;
     bool m_applyAuthorSheets : 1;
-    bool m_needsRecalculateContent : 1;
 };
 
-inline void ShadowRoot::clearNeedsReattachHostChildrenAndShadow()
-{
-    m_needsRecalculateContent = false;
-}
-
-inline bool ShadowRoot::needsReattachHostChildrenAndShadow()
-{
-    return m_needsRecalculateContent || hasContentElement();
-}
-
 inline ShadowRoot* toShadowRoot(Node* node)
 {
     ASSERT(!node || node->isShadowRoot());

Modified: trunk/Source/WebCore/dom/ShadowRootList.cpp (108712 => 108713)


--- trunk/Source/WebCore/dom/ShadowRootList.cpp	2012-02-24 02:20:19 UTC (rev 108712)
+++ trunk/Source/WebCore/dom/ShadowRootList.cpp	2012-02-24 02:37:02 UTC (rev 108713)
@@ -32,10 +32,12 @@
 #include "HTMLContentSelector.h"
 #include "RuntimeEnabledFeatures.h"
 #include "ShadowRoot.h"
+#include "Text.h"
 
 namespace WebCore {
 
 ShadowRootList::ShadowRootList()
+    : m_needsRecalculateContent(false)
 {
 }
 
@@ -94,12 +96,6 @@
         root->willRemove();
 }
 
-void ShadowRootList::hostChildrenChanged()
-{
-    for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot())
-        root->hostChildrenChanged();
-}
-
 void ShadowRootList::attach()
 {
     // FIXME: Currently we only support the case that the shadow root list has at most one shadow root.
@@ -139,6 +135,98 @@
     return m_selector && m_selector->hasCandidates();
 }
 
+void ShadowRootList::reattach()
+{
+    detach();
+    attach();
+}
+
+bool ShadowRootList::childNeedsStyleRecalc()
+{
+    ASSERT(youngestShadowRoot());
+    if (!youngestShadowRoot())
+        return false;
+
+    return youngestShadowRoot()->childNeedsStyleRecalc();
+}
+
+bool ShadowRootList::needsStyleRecalc()
+{
+    ASSERT(youngestShadowRoot());
+    if (!youngestShadowRoot())
+        return false;
+
+    return youngestShadowRoot()->needsStyleRecalc();
+}
+
+void ShadowRootList::recalcShadowTreeStyle(Node::StyleChange change)
+{
+    ShadowRoot* youngest = youngestShadowRoot();
+    if (!youngest)
+        return;
+
+    if (needsReattachHostChildrenAndShadow())
+        reattachHostChildrenAndShadow();
+    else {
+        for (Node* n = youngest->firstChild(); n; n = n->nextSibling()) {
+            if (n->isElementNode())
+                static_cast<Element*>(n)->recalcStyle(change);
+            else if (n->isTextNode())
+                toText(n)->recalcTextStyle(change);
+        }
+    }
+
+    clearNeedsReattachHostChildrenAndShadow();
+    for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot()) {
+        root->clearNeedsStyleRecalc();
+        root->clearChildNeedsStyleRecalc();
+    }
+}
+
+bool ShadowRootList::needsReattachHostChildrenAndShadow()
+{
+    return m_needsRecalculateContent || (youngestShadowRoot() && youngestShadowRoot()->hasContentElement());
+}
+
+void ShadowRootList::hostChildrenChanged()
+{
+    ASSERT(youngestShadowRoot());
+
+    if (!youngestShadowRoot()->hasContentElement())
+        return;
+
+    // This results in forced detaching/attaching of the shadow render tree. See ShadowRoot::recalcStyle().
+    setNeedsReattachHostChildrenAndShadow();
+}
+
+void ShadowRootList::setNeedsReattachHostChildrenAndShadow()
+{
+    m_needsRecalculateContent = true;
+
+    host()->setNeedsStyleRecalc();
+}
+
+void ShadowRootList::reattachHostChildrenAndShadow()
+{
+    ASSERT(youngestShadowRoot());
+
+    Node* hostNode = youngestShadowRoot()->host();
+    if (!hostNode)
+        return;
+
+    for (Node* child = hostNode->firstChild(); child; child = child->nextSibling()) {
+        if (child->attached())
+            child->detach();
+    }
+
+    reattach();
+
+    for (Node* child = hostNode->firstChild(); child; child = child->nextSibling()) {
+        if (!child->attached())
+            child->attach();
+    }
+}
+
 HTMLContentSelector* ShadowRootList::ensureSelector()
 {
     if (!m_selector)

Modified: trunk/Source/WebCore/dom/ShadowRootList.h (108712 => 108713)


--- trunk/Source/WebCore/dom/ShadowRootList.h	2012-02-24 02:20:19 UTC (rev 108712)
+++ trunk/Source/WebCore/dom/ShadowRootList.h	2012-02-24 02:37:02 UTC (rev 108713)
@@ -37,8 +37,8 @@
 
 class Node;
 class Element;
-class HTMLContentElement;
 class HTMLContentSelector;
+class InsertionPoint;
 
 class ShadowRootList {
 public:
@@ -58,11 +58,19 @@
     void removedFromTree(bool deep);
     void willRemove();
 
-    void hostChildrenChanged();
-
     void attach();
     void detach();
+    void reattach();
 
+    bool childNeedsStyleRecalc();
+    bool needsStyleRecalc();
+    void recalcShadowTreeStyle(Node::StyleChange);
+    void setNeedsReattachHostChildrenAndShadow();
+    void clearNeedsReattachHostChildrenAndShadow();
+    bool needsReattachHostChildrenAndShadow();
+    void reattachHostChildrenAndShadow();
+    void hostChildrenChanged();
+
     InsertionPoint* insertionPointFor(Node*) const;
 
     HTMLContentSelector* selector() const;
@@ -75,6 +83,7 @@
 
     DoublyLinkedList<ShadowRoot> m_shadowRoots;
     OwnPtr<HTMLContentSelector> m_selector;
+    bool m_needsRecalculateContent : 1;
     WTF_MAKE_NONCOPYABLE(ShadowRootList);
 };
 
@@ -98,6 +107,11 @@
     return m_selector.get();
 }
 
+inline void ShadowRootList::clearNeedsReattachHostChildrenAndShadow()
+{
+    m_needsRecalculateContent = false;
+}
+
 inline Element* ShadowRootList::host() const
 {
     ASSERT(hasShadowRoot());

Modified: trunk/Source/WebCore/html/shadow/HTMLContentElement.cpp (108712 => 108713)


--- trunk/Source/WebCore/html/shadow/HTMLContentElement.cpp	2012-02-24 02:20:19 UTC (rev 108712)
+++ trunk/Source/WebCore/html/shadow/HTMLContentElement.cpp	2012-02-24 02:37:02 UTC (rev 108713)
@@ -74,7 +74,7 @@
 
     // Before calling StyledElement::attach, selector must be calculated.
     if (root) {
-        HTMLContentSelector* selector = root->host()->shadowRootList()->ensureSelector();
+        HTMLContentSelector* selector = root->list()->ensureSelector();
         selector->unselect(&m_selections);
         selector->select(this, &m_selections);
     }
@@ -90,12 +90,12 @@
 void HTMLContentElement::detach()
 {
     if (ShadowRoot* root = toShadowRoot(shadowTreeRootNode())) {
-        if (HTMLContentSelector* selector = root->host()->shadowRootList()->selector())
+        if (HTMLContentSelector* selector = root->list()->selector())
             selector->unselect(&m_selections);
 
         // When content element is detached, shadow tree should be recreated to re-calculate selector for
         // other content elements.
-        root->setNeedsReattachHostChildrenAndShadow();
+        root->list()->setNeedsReattachHostChildrenAndShadow();
     }
 
     ASSERT(m_selections.isEmpty());
@@ -122,7 +122,7 @@
 {
     if (attr->name() == selectAttr) {
         if (ShadowRoot* root = toShadowRoot(shadowTreeRootNode()))
-            root->setNeedsReattachHostChildrenAndShadow();
+            root->list()->setNeedsReattachHostChildrenAndShadow();
     } else
         InsertionPoint::parseAttribute(attr);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to