Title: [90888] trunk/Source/WebCore
Revision
90888
Author
[email protected]
Date
2011-07-12 22:43:08 -0700 (Tue, 12 Jul 2011)

Log Message

[Refactoring][ShadowContentElement] Forwarded node list should be a linked-list.
https://bugs.webkit.org/show_bug.cgi?id=64252

Reviewed by Dimitri Glazkov.

Introduced ShadowInclusionList and ShadowInclusion for maintaining
forwarded content children. ShadowInclusion is doubly-linked list.
ShadowContentElement::m_inclusions is replaced by ShadowInclusionList.

This change is a prepration for bug 64251, which will introduce
forwarded-children to content-element table.

No new tests. No behavioral change.

* dom/NodeRenderingContext.cpp:
(WebCore::nextRendererOf):
(WebCore::previousRendererOf):
(WebCore::firstRendererOf):
(WebCore::lastRendererOf):
* dom/ShadowContentElement.cpp:
(WebCore::ShadowInclusion::append):
(WebCore::ShadowInclusion::unlink):
(WebCore::ShadowInclusionList::ShadowInclusionList):
(WebCore::ShadowInclusionList::~ShadowInclusionList):
(WebCore::ShadowInclusionList::find):
(WebCore::ShadowInclusionList::clear):
(WebCore::ShadowInclusionList::append):
(WebCore::ShadowContentElement::attach):
* dom/ShadowContentElement.h:
(WebCore::ShadowInclusion::includer):
(WebCore::ShadowInclusion::content):
(WebCore::ShadowInclusion::next):
(WebCore::ShadowInclusion::previous):
(WebCore::ShadowInclusion::ShadowInclusion):
(WebCore::ShadowInclusion::create):
(WebCore::ShadowInclusionList::first):
(WebCore::ShadowInclusionList::last):
(WebCore::ShadowInclusionList::isEmpty):
(WebCore::ShadowInclusionList::append):
(WebCore::ShadowContentElement::inclusions):
* dom/ShadowContentSelector.cpp:
(WebCore::ShadowContentSelector::selectInclusion):
* dom/ShadowContentSelector.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (90887 => 90888)


--- trunk/Source/WebCore/ChangeLog	2011-07-13 05:35:15 UTC (rev 90887)
+++ trunk/Source/WebCore/ChangeLog	2011-07-13 05:43:08 UTC (rev 90888)
@@ -1,3 +1,49 @@
+2011-07-12  MORITA Hajime  <[email protected]>
+
+        [Refactoring][ShadowContentElement] Forwarded node list should be a linked-list.
+        https://bugs.webkit.org/show_bug.cgi?id=64252
+
+        Reviewed by Dimitri Glazkov.
+
+        Introduced ShadowInclusionList and ShadowInclusion for maintaining
+        forwarded content children. ShadowInclusion is doubly-linked list.
+        ShadowContentElement::m_inclusions is replaced by ShadowInclusionList.
+        
+        This change is a prepration for bug 64251, which will introduce
+        forwarded-children to content-element table.
+        
+        No new tests. No behavioral change.
+
+        * dom/NodeRenderingContext.cpp:
+        (WebCore::nextRendererOf):
+        (WebCore::previousRendererOf):
+        (WebCore::firstRendererOf):
+        (WebCore::lastRendererOf):
+        * dom/ShadowContentElement.cpp:
+        (WebCore::ShadowInclusion::append):
+        (WebCore::ShadowInclusion::unlink):
+        (WebCore::ShadowInclusionList::ShadowInclusionList):
+        (WebCore::ShadowInclusionList::~ShadowInclusionList):
+        (WebCore::ShadowInclusionList::find):
+        (WebCore::ShadowInclusionList::clear):
+        (WebCore::ShadowInclusionList::append):
+        (WebCore::ShadowContentElement::attach):
+        * dom/ShadowContentElement.h:
+        (WebCore::ShadowInclusion::includer):
+        (WebCore::ShadowInclusion::content):
+        (WebCore::ShadowInclusion::next):
+        (WebCore::ShadowInclusion::previous):
+        (WebCore::ShadowInclusion::ShadowInclusion):
+        (WebCore::ShadowInclusion::create):
+        (WebCore::ShadowInclusionList::first):
+        (WebCore::ShadowInclusionList::last):
+        (WebCore::ShadowInclusionList::isEmpty):
+        (WebCore::ShadowInclusionList::append):
+        (WebCore::ShadowContentElement::inclusions):
+        * dom/ShadowContentSelector.cpp:
+        (WebCore::ShadowContentSelector::selectInclusion):
+        * dom/ShadowContentSelector.h:
+
 2011-07-12  David Reveman  <[email protected]>
 
         [Chromium] Use nearest filter method with pixel aligned transforms.

Modified: trunk/Source/WebCore/dom/NodeRenderingContext.cpp (90887 => 90888)


--- trunk/Source/WebCore/dom/NodeRenderingContext.cpp	2011-07-13 05:35:15 UTC (rev 90887)
+++ trunk/Source/WebCore/dom/NodeRenderingContext.cpp	2011-07-13 05:43:08 UTC (rev 90888)
@@ -102,13 +102,12 @@
 
 static RenderObject* nextRendererOf(ShadowContentElement* parent, Node* current)
 {
-    size_t currentIndex = parent->inclusionIndexOf(current);
-    if (currentIndex == notFound)
+    ShadowInclusion* currentInclusion = parent->inclusions()->find(current);
+    if (!currentInclusion)
         return 0;
 
-    for (size_t i = currentIndex + 1; i < parent->inclusionCount(); ++i) {
-        Node* candidate = parent->inclusionAt(i);
-        if (RenderObject* renderer = candidate->renderer())
+    for (ShadowInclusion* inclusion = currentInclusion->next(); inclusion; inclusion = inclusion->next()) {
+        if (RenderObject* renderer = inclusion->content()->renderer())
             return renderer;
     }
 
@@ -119,11 +118,10 @@
 {
     RenderObject* lastRenderer = 0;
 
-    for (size_t i = 0; i < parent->inclusionCount(); ++i) {
-        Node* candidate = parent->inclusionAt(i);
-        if (current == candidate)
+    for (ShadowInclusion* inclusion = parent->inclusions()->first(); inclusion; inclusion = inclusion->next()) {
+        if (inclusion->content() == current)
             break;
-        if (RenderObject* renderer = candidate->renderer())
+        if (RenderObject* renderer = inclusion->content()->renderer())
             lastRenderer = renderer;
     }
 
@@ -132,10 +130,8 @@
 
 static RenderObject* firstRendererOf(ShadowContentElement* parent)
 {
-    size_t inclusionCount = parent->inclusionCount();
-    for (size_t i = 0; i < inclusionCount; ++i) {
-        Node* candidate = parent->inclusionAt(i);
-        if (RenderObject* renderer = candidate->renderer())
+    for (ShadowInclusion* inclusion = parent->inclusions()->first(); inclusion; inclusion = inclusion->next()) {
+        if (RenderObject* renderer = inclusion->content()->renderer())
             return renderer;
     }
 
@@ -144,10 +140,8 @@
 
 static RenderObject* lastRendererOf(ShadowContentElement* parent)
 {
-    size_t inclusionCount = parent->inclusionCount();
-    for (size_t i = 0; i < inclusionCount; ++i) {
-        Node* candidate = parent->inclusionAt(inclusionCount - i - 1);
-        if (RenderObject* renderer = candidate->renderer())
+    for (ShadowInclusion* inclusion = parent->inclusions()->last(); inclusion; inclusion = inclusion->previous()) {
+        if (RenderObject* renderer = inclusion->content()->renderer())
             return renderer;
     }
 

Modified: trunk/Source/WebCore/dom/ShadowContentElement.cpp (90887 => 90888)


--- trunk/Source/WebCore/dom/ShadowContentElement.cpp	2011-07-13 05:35:15 UTC (rev 90887)
+++ trunk/Source/WebCore/dom/ShadowContentElement.cpp	2011-07-13 05:43:08 UTC (rev 90888)
@@ -32,6 +32,72 @@
 
 namespace WebCore {
 
+void ShadowInclusion::append(PassRefPtr<ShadowInclusion> next)
+{
+    ASSERT(!m_next);
+    ASSERT(!next->previous());
+    m_next = next;
+    m_next->m_previous = this;
+}
+
+void ShadowInclusion::unlink()
+{
+    ASSERT(!m_previous); // Can be called only for a head.
+    RefPtr<ShadowInclusion> item = this;
+    while (item) {
+        ASSERT(!item->previous());
+        RefPtr<ShadowInclusion> nextItem = item->m_next;
+        item->m_next.clear();
+        if (nextItem)
+            nextItem->m_previous.clear();
+        item = nextItem;
+    }
+}
+
+ShadowInclusionList::ShadowInclusionList()
+{
+}
+
+ShadowInclusionList::~ShadowInclusionList()
+{
+    ASSERT(isEmpty());
+}
+
+ShadowInclusion* ShadowInclusionList::find(Node* content) const
+{
+    for (ShadowInclusion* item = first(); item; item = item->next()) {
+        if (content == item->content())
+            return item;
+    }
+    
+    return 0;
+}
+
+void ShadowInclusionList::clear()
+{
+    if (isEmpty()) {
+        ASSERT(!m_last);
+        return;
+    }
+
+    m_first->unlink();
+    m_first.clear();
+    m_last.clear();
+}
+
+void ShadowInclusionList::append(PassRefPtr<ShadowInclusion> child)
+{
+    if (isEmpty()) {
+        ASSERT(!m_last);
+        m_first = m_last = child;
+        return;
+    }
+
+    m_last->append(child);
+    m_last = m_last->next();
+}
+
+
 PassRefPtr<ShadowContentElement> ShadowContentElement::create(Document* document)
 {
     DEFINE_STATIC_LOCAL(QualifiedName, tagName, (nullAtom, "webkitShadowContent", HTMLNames::divTag.namespaceURI()));
@@ -53,11 +119,11 @@
     StyledElement::attach();
     if (ShadowContentSelector* selector = ShadowContentSelector::currentInstance()) {
         selector->willAttachContentFor(this);
-        selector->selectInclusion(m_inclusions);
-        for (size_t i = 0; i < m_inclusions.size(); ++i)
-            m_inclusions[i]->detach();
-        for (size_t i = 0; i < m_inclusions.size(); ++i)
-            m_inclusions[i]->attach();
+        selector->selectInclusion(&m_inclusions);
+        for (ShadowInclusion* inclusion = m_inclusions.first(); inclusion; inclusion = inclusion->next())
+            inclusion->content()->detach();
+        for (ShadowInclusion* inclusion = m_inclusions.first(); inclusion; inclusion = inclusion->next())
+            inclusion->content()->attach();
         selector->didAttachContent();
     }
 }
@@ -73,4 +139,5 @@
     return true;
 }
 
+
 }

Modified: trunk/Source/WebCore/dom/ShadowContentElement.h (90887 => 90888)


--- trunk/Source/WebCore/dom/ShadowContentElement.h	2011-07-13 05:35:15 UTC (rev 90887)
+++ trunk/Source/WebCore/dom/ShadowContentElement.h	2011-07-13 05:43:08 UTC (rev 90888)
@@ -36,6 +36,62 @@
 
 namespace WebCore {
 
+class ShadowContentElement;
+
+class ShadowInclusion : public RefCounted<ShadowInclusion> {
+public:
+    static PassRefPtr<ShadowInclusion> create(ShadowContentElement*, Node*);
+
+    ShadowContentElement* includer() const { return m_includer; }
+    Node* content() const { return m_content.get(); }
+    ShadowInclusion* next() const { return m_next.get(); }
+    ShadowInclusion* previous() const { return m_previous.get(); }
+
+    void append(PassRefPtr<ShadowInclusion>);
+    void unlink();
+
+private:
+    explicit ShadowInclusion(ShadowContentElement* includer, Node* content)
+        : m_includer(includer), m_content(content)
+    { }
+
+    ShadowContentElement* m_includer;
+    RefPtr<Node> m_content;
+    RefPtr<ShadowInclusion> m_next;
+    RefPtr<ShadowInclusion> m_previous;
+};
+
+inline PassRefPtr<ShadowInclusion> ShadowInclusion::create(ShadowContentElement* includer, Node* content)
+{
+    return adoptRef(new ShadowInclusion(includer, content));
+}
+
+
+class ShadowInclusionList {
+public:
+    ShadowInclusionList();
+    ~ShadowInclusionList();
+
+    ShadowInclusion* first() const { return m_first.get(); }
+    ShadowInclusion* last() const { return m_last.get(); }
+    ShadowInclusion* find(Node*) const;
+    bool isEmpty() const { return !m_first; }
+
+    void clear();
+    void append(PassRefPtr<ShadowInclusion>);
+    void append(ShadowContentElement*, Node*);
+
+private:
+    RefPtr<ShadowInclusion> m_first;
+    RefPtr<ShadowInclusion> m_last;
+};
+
+inline void ShadowInclusionList::append(ShadowContentElement* includer, Node* node)
+{
+    append(ShadowInclusion::create(includer, node));
+}
+
+
 // NOTE: Current implementation doesn't support dynamic insertion/deletion of ShadowContentElement.
 // You should create ShadowContentElement during the host construction.
 class ShadowContentElement : public StyledElement {
@@ -47,9 +103,7 @@
     virtual void attach();
     virtual void detach();
 
-    Node* inclusionAt(size_t) const;
-    size_t inclusionCount() const;
-    size_t inclusionIndexOf(Node*) const;
+    const ShadowInclusionList* inclusions() const { return &m_inclusions; }
 
 protected:
     ShadowContentElement(const QualifiedName&, Document*);
@@ -59,24 +113,9 @@
     virtual bool rendererIsNeeded(const NodeRenderingContext&) { return false; }
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) { return 0; }
 
-    Vector<RefPtr<Node> > m_inclusions;
+    ShadowInclusionList m_inclusions;
 };
 
-inline Node* ShadowContentElement::inclusionAt(size_t index) const
-{
-    return m_inclusions.at(index).get();
-}
-
-inline size_t ShadowContentElement::inclusionCount() const
-{
-    return m_inclusions.size();
-}
-
-inline size_t ShadowContentElement::inclusionIndexOf(Node* node) const
-{
-    return m_inclusions.find(node);
-}
-
 inline ShadowContentElement* toShadowContentElement(Node* node)
 {
     ASSERT(!node || node->isContentElement());

Modified: trunk/Source/WebCore/dom/ShadowContentSelector.cpp (90887 => 90888)


--- trunk/Source/WebCore/dom/ShadowContentSelector.cpp	2011-07-13 05:35:15 UTC (rev 90887)
+++ trunk/Source/WebCore/dom/ShadowContentSelector.cpp	2011-07-13 05:43:08 UTC (rev 90888)
@@ -51,9 +51,9 @@
     s_currentInstance = m_parent;
 }
 
-void ShadowContentSelector::selectInclusion(Vector<RefPtr<Node> >& inclusions)
+void ShadowContentSelector::selectInclusion(ShadowInclusionList* inclusions)
 {
-    inclusions.clear();
+    inclusions->clear();
 
     for (size_t i = 0; i < m_children.size(); ++i) {
         Node* child = m_children[i].get();
@@ -62,9 +62,10 @@
         if (!m_activeElement->shouldInclude(child))
             continue;
 
-        inclusions.append(child);
+        inclusions->append(m_activeElement, child);
         m_children[i] = 0;
     }
+
 }
 
 void ShadowContentSelector::willAttachContentFor(ShadowContentElement* element)

Modified: trunk/Source/WebCore/dom/ShadowContentSelector.h (90887 => 90888)


--- trunk/Source/WebCore/dom/ShadowContentSelector.h	2011-07-13 05:35:15 UTC (rev 90887)
+++ trunk/Source/WebCore/dom/ShadowContentSelector.h	2011-07-13 05:43:08 UTC (rev 90888)
@@ -39,6 +39,7 @@
 class Element;
 class Node;
 class ShadowRoot;
+class ShadowInclusionList;
 class ShadowContentElement;
 class RenderObject;
 
@@ -50,7 +51,7 @@
 
     void willAttachContentFor(ShadowContentElement*);
     void didAttachContent();
-    void selectInclusion(Vector<RefPtr<Node> >& inclusions);
+    void selectInclusion(ShadowInclusionList*);
 
     ShadowRoot* shadowRoot() const { return m_shadowRoot; }
     ShadowContentElement* activeElement() const;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to