Title: [108605] trunk/Source/WebCore
Revision
108605
Author
[email protected]
Date
2012-02-22 21:14:17 -0800 (Wed, 22 Feb 2012)

Log Message

Make ShadowRootList manage a node distribution.
https://bugs.webkit.org/show_bug.cgi?id=79008

Reviewed by Dimitri Glazkov.

The result of node distributions is currently stored in
ShadowRoot. To support multiple ShadowRoots, such node distribution
information should be managed in one place per shadow host. Now
ShadowRootList takes this responsibility on behalf of owing
multiple ShadowRoots. Clients should ask ShadowRootList for such
information, not for each ShadowRoot.

No tests. No change in behavior.

* dom/NodeRenderingContext.cpp:
(WebCore::NodeRenderingContext::NodeRenderingContext):
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::create):
(WebCore::ShadowRoot::attach):
* dom/ShadowRoot.h:
(ShadowRoot):
* dom/ShadowRootList.cpp:
(WebCore::ShadowRootList::insertionPointFor):
(WebCore):
(WebCore::ShadowRootList::isSelectorActive):
(WebCore::ShadowRootList::ensureSelector):
* dom/ShadowRootList.h:
(WebCore):
(ShadowRootList):
(WebCore::ShadowRootList::hasShadowRoot):
(WebCore::ShadowRootList::youngestShadowRoot):
(WebCore::ShadowRootList::oldestShadowRoot):
(WebCore::ShadowRootList::selector):
(WebCore::ShadowRootList::host):
* html/shadow/HTMLContentElement.cpp:
(WebCore::HTMLContentElement::attach):
(WebCore::HTMLContentElement::detach):
* html/shadow/HTMLContentSelector.cpp:
(WebCore::HTMLContentSelector::willSelectOver):
* html/shadow/HTMLContentSelector.h:
(HTMLContentSelector):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (108604 => 108605)


--- trunk/Source/WebCore/ChangeLog	2012-02-23 04:51:43 UTC (rev 108604)
+++ trunk/Source/WebCore/ChangeLog	2012-02-23 05:14:17 UTC (rev 108605)
@@ -1,3 +1,47 @@
+2012-02-22  Hayato Ito  <[email protected]>
+
+        Make ShadowRootList manage a node distribution.
+        https://bugs.webkit.org/show_bug.cgi?id=79008
+
+        Reviewed by Dimitri Glazkov.
+
+        The result of node distributions is currently stored in
+        ShadowRoot. To support multiple ShadowRoots, such node distribution
+        information should be managed in one place per shadow host. Now
+        ShadowRootList takes this responsibility on behalf of owing
+        multiple ShadowRoots. Clients should ask ShadowRootList for such
+        information, not for each ShadowRoot.
+
+        No tests. No change in behavior.
+
+        * dom/NodeRenderingContext.cpp:
+        (WebCore::NodeRenderingContext::NodeRenderingContext):
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::create):
+        (WebCore::ShadowRoot::attach):
+        * dom/ShadowRoot.h:
+        (ShadowRoot):
+        * dom/ShadowRootList.cpp:
+        (WebCore::ShadowRootList::insertionPointFor):
+        (WebCore):
+        (WebCore::ShadowRootList::isSelectorActive):
+        (WebCore::ShadowRootList::ensureSelector):
+        * dom/ShadowRootList.h:
+        (WebCore):
+        (ShadowRootList):
+        (WebCore::ShadowRootList::hasShadowRoot):
+        (WebCore::ShadowRootList::youngestShadowRoot):
+        (WebCore::ShadowRootList::oldestShadowRoot):
+        (WebCore::ShadowRootList::selector):
+        (WebCore::ShadowRootList::host):
+        * html/shadow/HTMLContentElement.cpp:
+        (WebCore::HTMLContentElement::attach):
+        (WebCore::HTMLContentElement::detach):
+        * html/shadow/HTMLContentSelector.cpp:
+        (WebCore::HTMLContentSelector::willSelectOver):
+        * html/shadow/HTMLContentSelector.h:
+        (HTMLContentSelector):
+
 2012-02-22  Wei James  <[email protected]>
 
         Add multi channels support in AudioBus and AudioBufferSourceNode

Modified: trunk/Source/WebCore/dom/Node.cpp (108604 => 108605)


--- trunk/Source/WebCore/dom/Node.cpp	2012-02-23 04:51:43 UTC (rev 108604)
+++ trunk/Source/WebCore/dom/Node.cpp	2012-02-23 05:14:17 UTC (rev 108605)
@@ -809,9 +809,9 @@
     return false;
 }
 
-inline static ShadowRoot* shadowRoot(Node* node)
+inline static ShadowRoot* oldestShadowRoot(Node* node)
 {
-    return node->isElementNode() && toElement(node)->hasShadowRoot() ? toElement(node)->shadowRootList()->youngestShadowRoot() : 0;
+    return node->isElementNode() && toElement(node)->hasShadowRoot() ? toElement(node)->shadowRootList()->oldestShadowRoot() : 0;
 }
 
 inline void Node::setStyleChange(StyleChangeType changeType)
@@ -2270,12 +2270,11 @@
         fprintf(stderr, "%s", indent.utf8().data());
         node->showNode();
 
-        ContainerNode* rootNode = shadowRoot(const_cast<Node*>(node));
-
-        if (rootNode) {
-            indent += "\t";
-            traverseTreeAndMark(indent, rootNode, markedNode1, markedLabel1, markedNode2, markedLabel2);
-        }
+        if (node->isShadowRoot()) {
+            if (ShadowRoot* youngerShadowRoot = toShadowRoot(const_cast<Node*>(node))->youngerShadowRoot())
+                traverseTreeAndMark(indent + "\t", youngerShadowRoot, markedNode1, markedLabel1, markedNode2, markedLabel2);
+        } else if (ShadowRoot* rootNode = oldestShadowRoot(const_cast<Node*>(node)))
+            traverseTreeAndMark(indent + "\t", rootNode, markedNode1, markedLabel1, markedNode2, markedLabel2);
     }
 }
 
@@ -2321,8 +2320,11 @@
     node->showNode();
     if (node->isFrameOwnerElement())
         showSubTreeAcrossFrame(static_cast<HTMLFrameOwnerElement*>(node)->contentDocument(), markedNode, indent + "\t");
-    if (ShadowRoot* shadow = shadowRoot(node))
-        showSubTreeAcrossFrame(shadow, markedNode, indent + "\t");
+    if (node->isShadowRoot()) {
+        if (ShadowRoot* youngerShadowRoot = toShadowRoot(node)->youngerShadowRoot())
+            showSubTreeAcrossFrame(youngerShadowRoot, markedNode, indent + "\t");
+    } else if (ShadowRoot* shadowRoot = oldestShadowRoot(node))
+        showSubTreeAcrossFrame(shadowRoot, markedNode, indent + "\t");
     for (Node* child = node->firstChild(); child; child = child->nextSibling())
         showSubTreeAcrossFrame(child, markedNode, indent + "\t");
 }

Modified: trunk/Source/WebCore/dom/NodeRenderingContext.cpp (108604 => 108605)


--- trunk/Source/WebCore/dom/NodeRenderingContext.cpp	2012-02-23 04:51:43 UTC (rev 108604)
+++ trunk/Source/WebCore/dom/NodeRenderingContext.cpp	2012-02-23 05:14:17 UTC (rev 108605)
@@ -67,8 +67,9 @@
             m_visualParentShadowRoot = toElement(parent)->shadowRootList()->youngestShadowRoot();
 
         if (m_visualParentShadowRoot) {
-            if ((m_insertionPoint = m_visualParentShadowRoot->insertionPointFor(m_node))
-                && m_visualParentShadowRoot->isSelectorActive()) {
+            ShadowRootList* shadowRootList = m_visualParentShadowRoot->host()->shadowRootList();
+            if ((m_insertionPoint = shadowRootList->insertionPointFor(m_node))
+                && shadowRootList->isSelectorActive()) {
                 m_phase = AttachingDistributed;
                 m_parentNodeForRenderingAndStyle = NodeRenderingContext(m_insertionPoint).parentNodeForRenderingAndStyle();
                 return;

Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (108604 => 108605)


--- trunk/Source/WebCore/dom/ShadowRoot.cpp	2012-02-23 04:51:43 UTC (rev 108604)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp	2012-02-23 05:14:17 UTC (rev 108605)
@@ -128,7 +128,8 @@
     element->setShadowRoot(shadowRoot, ec);
     if (ec)
         return 0;
-
+    ASSERT(element == shadowRoot->host());
+    ASSERT(element->hasShadowRoot());
     return shadowRoot.release();
 }
 
@@ -183,16 +184,6 @@
         shadowHost()->setNeedsStyleRecalc();
 }
 
-InsertionPoint* ShadowRoot::insertionPointFor(Node* node) const
-{
-    if (!m_selector)
-        return 0;
-    HTMLContentSelection* found = m_selector->findFor(node);
-    if (!found)
-        return 0;
-    return found->insertionPoint();
-}
-
 void ShadowRoot::hostChildrenChanged()
 {
     if (!hasContentElement())
@@ -202,11 +193,6 @@
     setNeedsReattachHostChildrenAndShadow();
 }
 
-bool ShadowRoot::isSelectorActive() const
-{
-    return m_selector && m_selector->hasCandidates();
-}
-
 bool ShadowRoot::hasContentElement() const
 {
     for (Node* n = firstChild(); n; n = n->traverseNextNode(this)) {
@@ -232,10 +218,12 @@
     // Children of m_selector is populated lazily in
     // ensureSelector(), and here we just ensure that
     // it is in clean state.
-    ASSERT(!m_selector || !m_selector->hasCandidates());
+    // FIXME: This assertion breaks if multiple shadow roots are being attached.
+    // ShadowRootList should have responsibility of side effect of selector in attaching/detaching.
+    ASSERT(!host()->shadowRootList()->selector() || !host()->shadowRootList()->selector()->hasCandidates());
     DocumentFragment::attach();
-    if (m_selector)
-        m_selector->didSelect();
+    if (HTMLContentSelector* selector = host()->shadowRootList()->selector())
+        selector->didSelect();
 }
 
 void ShadowRoot::reattachHostChildrenAndShadow()
@@ -257,18 +245,4 @@
     }
 }
 
-HTMLContentSelector* ShadowRoot::selector() const
-{
-    return m_selector.get();
-}
-
-HTMLContentSelector* ShadowRoot::ensureSelector()
-{
-    if (!m_selector)
-        m_selector = adoptPtr(new HTMLContentSelector());
-    m_selector->willSelectOver(this);
-    return m_selector.get();
-}
-
-
-}
+} // namespace

Modified: trunk/Source/WebCore/dom/ShadowRoot.h (108604 => 108605)


--- trunk/Source/WebCore/dom/ShadowRoot.h	2012-02-23 04:51:43 UTC (rev 108604)
+++ trunk/Source/WebCore/dom/ShadowRoot.h	2012-02-23 05:14:17 UTC (rev 108605)
@@ -62,7 +62,6 @@
 
     InsertionPoint* insertionPointFor(Node*) const;
     void hostChildrenChanged();
-    bool isSelectorActive() const;
 
     virtual void attach();
     void reattachHostChildrenAndShadow();
@@ -72,12 +71,9 @@
 
     Element* host() const { return shadowHost(); }
 
-    HTMLContentSelector* selector() const;
-    HTMLContentSelector* ensureSelector();
+    ShadowRoot* youngerShadowRoot() { return prev(); }
+    ShadowRoot* olderShadowRoot() { return next(); }
 
-    ShadowRoot* youngerShadowRoot() const { return prev(); }
-    ShadowRoot* olderShadowRoot() const { return next(); }
-
 private:
     ShadowRoot(Document*);
     virtual ~ShadowRoot();
@@ -92,7 +88,6 @@
     ShadowRoot* m_next;
     bool m_applyAuthorSheets : 1;
     bool m_needsRecalculateContent : 1;
-    OwnPtr<HTMLContentSelector> m_selector;
 };
 
 inline void ShadowRoot::clearNeedsReattachHostChildrenAndShadow()

Modified: trunk/Source/WebCore/dom/ShadowRootList.cpp (108604 => 108605)


--- trunk/Source/WebCore/dom/ShadowRootList.cpp	2012-02-23 04:51:43 UTC (rev 108604)
+++ trunk/Source/WebCore/dom/ShadowRootList.cpp	2012-02-23 05:14:17 UTC (rev 108605)
@@ -29,6 +29,7 @@
 
 #include "Document.h"
 #include "Element.h"
+#include "HTMLContentSelector.h"
 #include "RuntimeEnabledFeatures.h"
 #include "ShadowRoot.h"
 
@@ -123,4 +124,27 @@
     }
 }
 
+InsertionPoint* ShadowRootList::insertionPointFor(Node* node) const
+{
+    if (!m_selector)
+        return 0;
+    HTMLContentSelection* found = m_selector->findFor(node);
+    if (!found)
+        return 0;
+    return found->insertionPoint();
 }
+
+bool ShadowRootList::isSelectorActive() const
+{
+    return m_selector && m_selector->hasCandidates();
+}
+
+HTMLContentSelector* ShadowRootList::ensureSelector()
+{
+    if (!m_selector)
+        m_selector = adoptPtr(new HTMLContentSelector());
+    m_selector->willSelectOver(host());
+    return m_selector.get();
+}
+
+} // namespace

Modified: trunk/Source/WebCore/dom/ShadowRootList.h (108604 => 108605)


--- trunk/Source/WebCore/dom/ShadowRootList.h	2012-02-23 04:51:43 UTC (rev 108604)
+++ trunk/Source/WebCore/dom/ShadowRootList.h	2012-02-23 05:14:17 UTC (rev 108605)
@@ -27,23 +27,27 @@
 #ifndef ShadowRootList_h
 #define ShadowRootList_h
 
+#include "ShadowRoot.h"
 #include <wtf/DoublyLinkedList.h>
 #include <wtf/Noncopyable.h>
+#include <wtf/OwnPtr.h>
 #include <wtf/PassRefPtr.h>
 
 namespace WebCore {
 
-class ShadowRoot;
+class Node;
 class Element;
+class HTMLContentElement;
+class HTMLContentSelector;
 
 class ShadowRootList {
 public:
     ShadowRootList();
     ~ShadowRootList();
 
-    bool hasShadowRoot();
-    ShadowRoot* youngestShadowRoot();
-    ShadowRoot* oldestShadowRoot();
+    bool hasShadowRoot() const;
+    ShadowRoot* youngestShadowRoot() const;
+    ShadowRoot* oldestShadowRoot() const;
 
     void pushShadowRoot(ShadowRoot*);
     ShadowRoot* popShadowRoot();
@@ -59,26 +63,47 @@
     void attach();
     void detach();
 
+    InsertionPoint* insertionPointFor(Node*) const;
+
+    HTMLContentSelector* selector() const;
+    HTMLContentSelector* ensureSelector();
+
+    bool isSelectorActive() const;
+
 private:
+    Element* host() const;
+
     DoublyLinkedList<ShadowRoot> m_shadowRoots;
+    OwnPtr<HTMLContentSelector> m_selector;
     WTF_MAKE_NONCOPYABLE(ShadowRootList);
 };
 
-inline bool ShadowRootList::hasShadowRoot()
+inline bool ShadowRootList::hasShadowRoot() const
 {
     return !m_shadowRoots.isEmpty();
 }
 
-inline ShadowRoot* ShadowRootList::youngestShadowRoot()
+inline ShadowRoot* ShadowRootList::youngestShadowRoot() const
 {
     return m_shadowRoots.head();
 }
 
-inline ShadowRoot* ShadowRootList::oldestShadowRoot()
+inline ShadowRoot* ShadowRootList::oldestShadowRoot() const
 {
     return m_shadowRoots.tail();
 }
 
+inline HTMLContentSelector* ShadowRootList::selector() const
+{
+    return m_selector.get();
+}
+
+inline Element* ShadowRootList::host() const
+{
+    ASSERT(hasShadowRoot());
+    return youngestShadowRoot()->host();
+}
+
 } // namespace
 
 #endif

Modified: trunk/Source/WebCore/html/shadow/HTMLContentElement.cpp (108604 => 108605)


--- trunk/Source/WebCore/html/shadow/HTMLContentElement.cpp	2012-02-23 04:51:43 UTC (rev 108604)
+++ trunk/Source/WebCore/html/shadow/HTMLContentElement.cpp	2012-02-23 05:14:17 UTC (rev 108605)
@@ -32,6 +32,7 @@
 #include "HTMLNames.h"
 #include "QualifiedName.h"
 #include "ShadowRoot.h"
+#include "ShadowRootList.h"
 #include <wtf/StdLibExtras.h>
 
 namespace WebCore {
@@ -73,7 +74,7 @@
 
     // Before calling StyledElement::attach, selector must be calculated.
     if (root) {
-        HTMLContentSelector* selector = root->ensureSelector();
+        HTMLContentSelector* selector = root->host()->shadowRootList()->ensureSelector();
         selector->unselect(&m_selections);
         selector->select(this, &m_selections);
     }
@@ -89,7 +90,7 @@
 void HTMLContentElement::detach()
 {
     if (ShadowRoot* root = toShadowRoot(shadowTreeRootNode())) {
-        if (HTMLContentSelector* selector = root->selector())
+        if (HTMLContentSelector* selector = root->host()->shadowRootList()->selector())
             selector->unselect(&m_selections);
 
         // When content element is detached, shadow tree should be recreated to re-calculate selector for

Modified: trunk/Source/WebCore/html/shadow/HTMLContentSelector.cpp (108604 => 108605)


--- trunk/Source/WebCore/html/shadow/HTMLContentSelector.cpp	2012-02-23 04:51:43 UTC (rev 108604)
+++ trunk/Source/WebCore/html/shadow/HTMLContentSelector.cpp	2012-02-23 05:14:17 UTC (rev 108605)
@@ -145,11 +145,12 @@
     m_candidates.clear();
 }
 
-void HTMLContentSelector::willSelectOver(ShadowRoot* scope)
+void HTMLContentSelector::willSelectOver(Element* shadowHost)
 {
     if (!m_candidates.isEmpty())
         return;
-    for (Node* node = scope->shadowHost()->firstChild(); node; node = node->nextSibling())
+    ASSERT(shadowHost);
+    for (Node* node = shadowHost->firstChild(); node; node = node->nextSibling())
         m_candidates.append(node);
 }
 

Modified: trunk/Source/WebCore/html/shadow/HTMLContentSelector.h (108604 => 108605)


--- trunk/Source/WebCore/html/shadow/HTMLContentSelector.h	2012-02-23 04:51:43 UTC (rev 108604)
+++ trunk/Source/WebCore/html/shadow/HTMLContentSelector.h	2012-02-23 05:14:17 UTC (rev 108605)
@@ -134,7 +134,7 @@
     void unselect(HTMLContentSelectionList*);
     HTMLContentSelection* findFor(Node* key) const;
 
-    void willSelectOver(ShadowRoot*);
+    void willSelectOver(Element* shadowHost);
     void didSelect();
     bool hasCandidates() const { return !m_candidates.isEmpty(); }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to