Changeset 90888 in webkit
- Timestamp:
- Jul 12, 2011 10:43:08 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r90887 r90888 1 2011-07-12 MORITA Hajime <morrita@google.com> 2 3 [Refactoring][ShadowContentElement] Forwarded node list should be a linked-list. 4 https://bugs.webkit.org/show_bug.cgi?id=64252 5 6 Reviewed by Dimitri Glazkov. 7 8 Introduced ShadowInclusionList and ShadowInclusion for maintaining 9 forwarded content children. ShadowInclusion is doubly-linked list. 10 ShadowContentElement::m_inclusions is replaced by ShadowInclusionList. 11 12 This change is a prepration for bug 64251, which will introduce 13 forwarded-children to content-element table. 14 15 No new tests. No behavioral change. 16 17 * dom/NodeRenderingContext.cpp: 18 (WebCore::nextRendererOf): 19 (WebCore::previousRendererOf): 20 (WebCore::firstRendererOf): 21 (WebCore::lastRendererOf): 22 * dom/ShadowContentElement.cpp: 23 (WebCore::ShadowInclusion::append): 24 (WebCore::ShadowInclusion::unlink): 25 (WebCore::ShadowInclusionList::ShadowInclusionList): 26 (WebCore::ShadowInclusionList::~ShadowInclusionList): 27 (WebCore::ShadowInclusionList::find): 28 (WebCore::ShadowInclusionList::clear): 29 (WebCore::ShadowInclusionList::append): 30 (WebCore::ShadowContentElement::attach): 31 * dom/ShadowContentElement.h: 32 (WebCore::ShadowInclusion::includer): 33 (WebCore::ShadowInclusion::content): 34 (WebCore::ShadowInclusion::next): 35 (WebCore::ShadowInclusion::previous): 36 (WebCore::ShadowInclusion::ShadowInclusion): 37 (WebCore::ShadowInclusion::create): 38 (WebCore::ShadowInclusionList::first): 39 (WebCore::ShadowInclusionList::last): 40 (WebCore::ShadowInclusionList::isEmpty): 41 (WebCore::ShadowInclusionList::append): 42 (WebCore::ShadowContentElement::inclusions): 43 * dom/ShadowContentSelector.cpp: 44 (WebCore::ShadowContentSelector::selectInclusion): 45 * dom/ShadowContentSelector.h: 46 1 47 2011-07-12 David Reveman <reveman@chromium.org> 2 48 -
trunk/Source/WebCore/dom/NodeRenderingContext.cpp
r90691 r90888 103 103 static RenderObject* nextRendererOf(ShadowContentElement* parent, Node* current) 104 104 { 105 size_t currentIndex = parent->inclusionIndexOf(current); 106 if (currentIndex == notFound) 107 return 0; 108 109 for (size_t i = currentIndex + 1; i < parent->inclusionCount(); ++i) { 110 Node* candidate = parent->inclusionAt(i); 111 if (RenderObject* renderer = candidate->renderer()) 105 ShadowInclusion* currentInclusion = parent->inclusions()->find(current); 106 if (!currentInclusion) 107 return 0; 108 109 for (ShadowInclusion* inclusion = currentInclusion->next(); inclusion; inclusion = inclusion->next()) { 110 if (RenderObject* renderer = inclusion->content()->renderer()) 112 111 return renderer; 113 112 } … … 120 119 RenderObject* lastRenderer = 0; 121 120 122 for (size_t i = 0; i < parent->inclusionCount(); ++i) { 123 Node* candidate = parent->inclusionAt(i); 124 if (current == candidate) 121 for (ShadowInclusion* inclusion = parent->inclusions()->first(); inclusion; inclusion = inclusion->next()) { 122 if (inclusion->content() == current) 125 123 break; 126 if (RenderObject* renderer = candidate->renderer())124 if (RenderObject* renderer = inclusion->content()->renderer()) 127 125 lastRenderer = renderer; 128 126 } … … 133 131 static RenderObject* firstRendererOf(ShadowContentElement* parent) 134 132 { 135 size_t inclusionCount = parent->inclusionCount(); 136 for (size_t i = 0; i < inclusionCount; ++i) { 137 Node* candidate = parent->inclusionAt(i); 138 if (RenderObject* renderer = candidate->renderer()) 133 for (ShadowInclusion* inclusion = parent->inclusions()->first(); inclusion; inclusion = inclusion->next()) { 134 if (RenderObject* renderer = inclusion->content()->renderer()) 139 135 return renderer; 140 136 } … … 145 141 static RenderObject* lastRendererOf(ShadowContentElement* parent) 146 142 { 147 size_t inclusionCount = parent->inclusionCount(); 148 for (size_t i = 0; i < inclusionCount; ++i) { 149 Node* candidate = parent->inclusionAt(inclusionCount - i - 1); 150 if (RenderObject* renderer = candidate->renderer()) 143 for (ShadowInclusion* inclusion = parent->inclusions()->last(); inclusion; inclusion = inclusion->previous()) { 144 if (RenderObject* renderer = inclusion->content()->renderer()) 151 145 return renderer; 152 146 } -
trunk/Source/WebCore/dom/ShadowContentElement.cpp
r89230 r90888 33 33 namespace WebCore { 34 34 35 void ShadowInclusion::append(PassRefPtr<ShadowInclusion> next) 36 { 37 ASSERT(!m_next); 38 ASSERT(!next->previous()); 39 m_next = next; 40 m_next->m_previous = this; 41 } 42 43 void ShadowInclusion::unlink() 44 { 45 ASSERT(!m_previous); // Can be called only for a head. 46 RefPtr<ShadowInclusion> item = this; 47 while (item) { 48 ASSERT(!item->previous()); 49 RefPtr<ShadowInclusion> nextItem = item->m_next; 50 item->m_next.clear(); 51 if (nextItem) 52 nextItem->m_previous.clear(); 53 item = nextItem; 54 } 55 } 56 57 ShadowInclusionList::ShadowInclusionList() 58 { 59 } 60 61 ShadowInclusionList::~ShadowInclusionList() 62 { 63 ASSERT(isEmpty()); 64 } 65 66 ShadowInclusion* ShadowInclusionList::find(Node* content) const 67 { 68 for (ShadowInclusion* item = first(); item; item = item->next()) { 69 if (content == item->content()) 70 return item; 71 } 72 73 return 0; 74 } 75 76 void ShadowInclusionList::clear() 77 { 78 if (isEmpty()) { 79 ASSERT(!m_last); 80 return; 81 } 82 83 m_first->unlink(); 84 m_first.clear(); 85 m_last.clear(); 86 } 87 88 void ShadowInclusionList::append(PassRefPtr<ShadowInclusion> child) 89 { 90 if (isEmpty()) { 91 ASSERT(!m_last); 92 m_first = m_last = child; 93 return; 94 } 95 96 m_last->append(child); 97 m_last = m_last->next(); 98 } 99 100 35 101 PassRefPtr<ShadowContentElement> ShadowContentElement::create(Document* document) 36 102 { … … 54 120 if (ShadowContentSelector* selector = ShadowContentSelector::currentInstance()) { 55 121 selector->willAttachContentFor(this); 56 selector->selectInclusion( m_inclusions);57 for ( size_t i = 0; i < m_inclusions.size(); ++i)58 m_inclusions[i]->detach();59 for ( size_t i = 0; i < m_inclusions.size(); ++i)60 m_inclusions[i]->attach();122 selector->selectInclusion(&m_inclusions); 123 for (ShadowInclusion* inclusion = m_inclusions.first(); inclusion; inclusion = inclusion->next()) 124 inclusion->content()->detach(); 125 for (ShadowInclusion* inclusion = m_inclusions.first(); inclusion; inclusion = inclusion->next()) 126 inclusion->content()->attach(); 61 127 selector->didAttachContent(); 62 128 } … … 74 140 } 75 141 142 76 143 } -
trunk/Source/WebCore/dom/ShadowContentElement.h
r89649 r90888 37 37 namespace WebCore { 38 38 39 class ShadowContentElement; 40 41 class ShadowInclusion : public RefCounted<ShadowInclusion> { 42 public: 43 static PassRefPtr<ShadowInclusion> create(ShadowContentElement*, Node*); 44 45 ShadowContentElement* includer() const { return m_includer; } 46 Node* content() const { return m_content.get(); } 47 ShadowInclusion* next() const { return m_next.get(); } 48 ShadowInclusion* previous() const { return m_previous.get(); } 49 50 void append(PassRefPtr<ShadowInclusion>); 51 void unlink(); 52 53 private: 54 explicit ShadowInclusion(ShadowContentElement* includer, Node* content) 55 : m_includer(includer), m_content(content) 56 { } 57 58 ShadowContentElement* m_includer; 59 RefPtr<Node> m_content; 60 RefPtr<ShadowInclusion> m_next; 61 RefPtr<ShadowInclusion> m_previous; 62 }; 63 64 inline PassRefPtr<ShadowInclusion> ShadowInclusion::create(ShadowContentElement* includer, Node* content) 65 { 66 return adoptRef(new ShadowInclusion(includer, content)); 67 } 68 69 70 class ShadowInclusionList { 71 public: 72 ShadowInclusionList(); 73 ~ShadowInclusionList(); 74 75 ShadowInclusion* first() const { return m_first.get(); } 76 ShadowInclusion* last() const { return m_last.get(); } 77 ShadowInclusion* find(Node*) const; 78 bool isEmpty() const { return !m_first; } 79 80 void clear(); 81 void append(PassRefPtr<ShadowInclusion>); 82 void append(ShadowContentElement*, Node*); 83 84 private: 85 RefPtr<ShadowInclusion> m_first; 86 RefPtr<ShadowInclusion> m_last; 87 }; 88 89 inline void ShadowInclusionList::append(ShadowContentElement* includer, Node* node) 90 { 91 append(ShadowInclusion::create(includer, node)); 92 } 93 94 39 95 // NOTE: Current implementation doesn't support dynamic insertion/deletion of ShadowContentElement. 40 96 // You should create ShadowContentElement during the host construction. … … 48 104 virtual void detach(); 49 105 50 Node* inclusionAt(size_t) const; 51 size_t inclusionCount() const; 52 size_t inclusionIndexOf(Node*) const; 106 const ShadowInclusionList* inclusions() const { return &m_inclusions; } 53 107 54 108 protected: … … 60 114 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) { return 0; } 61 115 62 Vector<RefPtr<Node> >m_inclusions;116 ShadowInclusionList m_inclusions; 63 117 }; 64 65 inline Node* ShadowContentElement::inclusionAt(size_t index) const66 {67 return m_inclusions.at(index).get();68 }69 70 inline size_t ShadowContentElement::inclusionCount() const71 {72 return m_inclusions.size();73 }74 75 inline size_t ShadowContentElement::inclusionIndexOf(Node* node) const76 {77 return m_inclusions.find(node);78 }79 118 80 119 inline ShadowContentElement* toShadowContentElement(Node* node) -
trunk/Source/WebCore/dom/ShadowContentSelector.cpp
r89649 r90888 52 52 } 53 53 54 void ShadowContentSelector::selectInclusion( Vector<RefPtr<Node> >&inclusions)54 void ShadowContentSelector::selectInclusion(ShadowInclusionList* inclusions) 55 55 { 56 inclusions .clear();56 inclusions->clear(); 57 57 58 58 for (size_t i = 0; i < m_children.size(); ++i) { … … 63 63 continue; 64 64 65 inclusions .append(child);65 inclusions->append(m_activeElement, child); 66 66 m_children[i] = 0; 67 67 } 68 68 69 } 69 70 -
trunk/Source/WebCore/dom/ShadowContentSelector.h
r89649 r90888 40 40 class Node; 41 41 class ShadowRoot; 42 class ShadowInclusionList; 42 43 class ShadowContentElement; 43 44 class RenderObject; … … 51 52 void willAttachContentFor(ShadowContentElement*); 52 53 void didAttachContent(); 53 void selectInclusion( Vector<RefPtr<Node> >& inclusions);54 void selectInclusion(ShadowInclusionList*); 54 55 55 56 ShadowRoot* shadowRoot() const { return m_shadowRoot; }
Note: See TracChangeset
for help on using the changeset viewer.