Changeset 117033 in webkit
- Timestamp:
- May 14, 2012, 11:30:25 PM (14 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
-
ChangeLog (modified) (1 diff)
-
dom/ComposedShadowTreeWalker.cpp (modified) (2 diffs)
-
dom/ElementShadow.cpp (modified) (1 diff)
-
dom/ElementShadow.h (modified) (1 diff)
-
dom/NodeRenderingContext.cpp (modified) (4 diffs)
-
html/shadow/ContentDistributor.cpp (modified) (3 diffs)
-
html/shadow/ContentDistributor.h (modified) (5 diffs)
-
html/shadow/InsertionPoint.cpp (modified) (4 diffs)
-
html/shadow/InsertionPoint.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r117032 r117033 1 2012-05-14 MORITA Hajime <morrita@google.com> 2 3 [Refactoring] Get rid of ContentDistribution::Item 4 https://bugs.webkit.org/show_bug.cgi?id=86350 5 6 This change replaces the linked list on ContentDistribution with a Vector. 7 We no longer link item class ContentDistribution::Item. 8 This simplification also allows ContentDistribution to go. 9 ContentDistribution is now just a typedef of Vector<RefPtr<Node> >. 10 11 Reviewed by Dimitri Glazkov. 12 13 No new tests. Covered by existing tests. 14 15 * dom/ComposedShadowTreeWalker.cpp: 16 (WebCore::ComposedShadowTreeWalker::traverseNode): 17 (WebCore::ComposedShadowTreeWalker::traverseSiblingOrBackToInsertionPoint): 18 * dom/ElementShadow.cpp: 19 * dom/ElementShadow.h: 20 (ElementShadow): 21 * dom/NodeRenderingContext.cpp: 22 (WebCore::nextRendererOfInsertionPoint): 23 (WebCore::previousRendererOfInsertionPoint): 24 (WebCore::firstRendererOfInsertionPoint): 25 (WebCore::lastRendererOfInsertionPoint): 26 * html/shadow/ContentDistributor.cpp: 27 (WebCore::ContentDistributor::distribute): 28 (WebCore::ContentDistributor::clearDistribution): 29 (WebCore::ContentDistributor::findInsertionPointFor): 30 * html/shadow/ContentDistributor.h: 31 (WebCore): 32 (ContentDistributor): 33 * html/shadow/InsertionPoint.cpp: 34 (WebCore::InsertionPoint::InsertionPoint): 35 (WebCore::InsertionPoint::attachDistributedNode): 36 (WebCore::InsertionPoint::assignShadowRoot): 37 (WebCore::InsertionPoint::nextTo): 38 (WebCore): 39 (WebCore::InsertionPoint::previousTo): 40 * html/shadow/InsertionPoint.h: Added a set of delegate method to m_distribution. 41 (WebCore::InsertionPoint::hasDistribution): 42 (WebCore::InsertionPoint::indexOf): 43 (WebCore::InsertionPoint::size): 44 (WebCore::InsertionPoint::at): 45 (WebCore::InsertionPoint::first): 46 (WebCore::InsertionPoint::last): 47 (InsertionPoint): 48 1 49 2012-05-14 Tim Horton <timothy_horton@apple.com> 2 50 -
trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp
r116974 r117033 114 114 ASSERT(node); 115 115 if (isInsertionPoint(node)) { 116 const ContentDistribution* distribution = toInsertionPoint(node)->distribution();117 if (Node* next = (direction == TraversalDirectionForward ? distribution->firstNode() : distribution->lastNode()))116 const InsertionPoint* insertionPoint = toInsertionPoint(node); 117 if (Node* next = (direction == TraversalDirectionForward ? insertionPoint->first() : insertionPoint->last())) 118 118 return traverseNode(next, direction); 119 119 return traverseLightChildren(node, direction); … … 142 142 if (!shadow) 143 143 return traverseSiblingInCurrentTree(node, direction); 144 ContentDistribution::Item* item = shadow->distributionItemFor(node);145 if (!i tem)144 InsertionPoint* insertionPoint = shadow->insertionPointFor(node); 145 if (!insertionPoint) 146 146 return traverseSiblingInCurrentTree(node, direction); 147 if ( ContentDistribution::Item* nextItem = (direction == TraversalDirectionForward ? item->next() : item->previous()))148 return traverseNode(next Item->node(), direction);149 return traverseSiblingOrBackToInsertionPoint(i tem->insertionPoint(), direction);147 if (Node* next = (direction == TraversalDirectionForward ? insertionPoint->nextTo(node) : insertionPoint->previousTo(node))) 148 return traverseNode(next, direction); 149 return traverseSiblingOrBackToInsertionPoint(insertionPoint, direction); 150 150 } 151 151 -
trunk/Source/WebCore/dom/ElementShadow.cpp
r116974 r117033 168 168 } 169 169 170 ContentDistribution::Item* ElementShadow::distributionItemFor(const Node* node) const171 {172 return m_distributor.findFor(node);173 }174 175 170 void ElementShadow::reattach() 176 171 { -
trunk/Source/WebCore/dom/ElementShadow.h
r116974 r117033 71 71 72 72 InsertionPoint* insertionPointFor(const Node*) const; 73 ContentDistribution::Item* distributionItemFor(const Node*) const;74 73 75 74 ContentDistributor& distributor(); -
trunk/Source/WebCore/dom/NodeRenderingContext.cpp
r116974 r117033 143 143 static inline RenderObject* nextRendererOfInsertionPoint(InsertionPoint* parent, Node* current) 144 144 { 145 ContentDistribution::Item* currentItem = parent->distribution()->find(current);146 if ( !currentItem)145 size_t start = parent->indexOf(current); 146 if (notFound == start) 147 147 return 0; 148 148 149 for ( ContentDistribution::Item* item = currentItem->next(); item; item = item->next()) {150 if (RenderObject* renderer = item->node()->renderer())149 for (size_t i = start + 1; i < parent->size(); ++i) { 150 if (RenderObject* renderer = parent->at(i)->renderer()) 151 151 return renderer; 152 152 } … … 159 159 RenderObject* lastRenderer = 0; 160 160 161 for ( ContentDistribution::Item* item = parent->distribution()->first(); item; item = item->next()) {162 if ( item->node() == current)161 for (size_t i = 0; i < parent->size(); ++i) { 162 if (parent->at(i) == current) 163 163 break; 164 if (RenderObject* renderer = item->node()->renderer())164 if (RenderObject* renderer = parent->at(i)->renderer()) 165 165 lastRenderer = renderer; 166 166 } … … 171 171 static inline RenderObject* firstRendererOfInsertionPoint(InsertionPoint* parent) 172 172 { 173 if (parent->hasDistribution()) { 174 for (ContentDistribution::Item* item = parent->distribution()->first(); item; item = item->next()) { 175 if (RenderObject* renderer = item->node()->renderer()) 176 return renderer; 177 } 178 179 return 0; 173 size_t size = parent->size(); 174 for (size_t i = 0; i < size; ++i) { 175 if (RenderObject* renderer = parent->at(i)->renderer()) 176 return renderer; 180 177 } 181 178 … … 185 182 static inline RenderObject* lastRendererOfInsertionPoint(InsertionPoint* parent) 186 183 { 187 if (parent->hasDistribution()) { 188 for (ContentDistribution::Item* item = parent->distribution()->last(); item; item = item->previous()) { 189 if (RenderObject* renderer = item->node()->renderer()) 190 return renderer; 191 } 192 193 return 0; 184 size_t size = parent->size(); 185 for (size_t i = 0; i < size; ++i) { 186 if (RenderObject* renderer = parent->at(size - 1 - i)->renderer()) 187 return renderer; 194 188 } 195 189 -
trunk/Source/WebCore/html/shadow/ContentDistributor.cpp
r116974 r117033 35 35 namespace WebCore { 36 36 37 ContentDistribution::ContentDistribution()38 {39 }40 41 ContentDistribution::~ContentDistribution()42 {43 ASSERT(isEmpty());44 }45 46 ContentDistribution::Item* ContentDistribution::find(Node* node) const47 {48 for (ContentDistribution::Item* item = first(); item; item = item->next()) {49 if (node == item->node())50 return item;51 }52 53 return 0;54 }55 56 void ContentDistribution::clear()57 {58 if (isEmpty()) {59 ASSERT(!m_last);60 return;61 }62 63 RefPtr<ContentDistribution::Item> item = m_first;64 while (item) {65 ASSERT(!item->previous());66 RefPtr<ContentDistribution::Item> nextItem = item->m_next;67 item->m_next.clear();68 if (nextItem)69 nextItem->m_previous.clear();70 item = nextItem;71 }72 73 m_first.clear();74 m_last.clear();75 }76 77 void ContentDistribution::append(InsertionPoint* insertionPoint, Node* node)78 {79 RefPtr<Item> child = Item::create(insertionPoint, node);80 81 if (isEmpty()) {82 ASSERT(!m_last);83 m_first = m_last = child;84 return;85 }86 87 ASSERT(!m_last->next());88 ASSERT(!child->previous());89 m_last->m_next = child;90 child->m_previous = m_last;91 m_last = m_last->next();92 }93 94 37 ContentDistributor::ContentDistributor() 95 38 : m_phase(Prevented) … … 116 59 continue; 117 60 118 distribution->append( insertionPoint,child);119 m_nodeToInsertionPoint.add( distribution->last());61 distribution->append(child); 62 m_nodeToInsertionPoint.add(child, insertionPoint); 120 63 m_pool[i] = 0; 121 64 } … … 124 67 void ContentDistributor::clearDistribution(ContentDistribution* list) 125 68 { 126 for (ContentDistribution::Item* item = list->first(); item; item = item->next()) 127 m_nodeToInsertionPoint.remove(item); 128 69 for (size_t i = 0; i < list->size(); ++i) 70 m_nodeToInsertionPoint.remove(list->at(i).get()); 129 71 list->clear(); 130 }131 132 ContentDistribution::Item* ContentDistributor::findFor(const Node* key) const133 {134 InvertedTable::iterator found = m_nodeToInsertionPoint.find<const Node*, Translator>(key);135 return found != m_nodeToInsertionPoint.end() ? *found : 0;136 72 } 137 73 138 74 InsertionPoint* ContentDistributor::findInsertionPointFor(const Node* key) const 139 75 { 140 InvertedTable::iterator found = m_nodeToInsertionPoint.find<const Node*, Translator>(key); 141 return found != m_nodeToInsertionPoint.end() ? (*found)->insertionPoint() : 0; 76 return m_nodeToInsertionPoint.get(key); 142 77 } 143 78 -
trunk/Source/WebCore/html/shadow/ContentDistributor.h
r116974 r117033 33 33 34 34 #include <wtf/Forward.h> 35 #include <wtf/Hash Set.h>35 #include <wtf/HashMap.h> 36 36 #include <wtf/RefCounted.h> 37 37 #include <wtf/Vector.h> … … 44 44 class ShadowRoot; 45 45 46 class ContentDistribution { 47 public: 48 // TODO: The class should be reduced into simple Node* which is kept in a vector: https://bugs.webkit.org/show_bug.cgi?id=86350 49 class Item : public RefCounted<Item> { 50 public: 51 friend class ContentDistribution; 52 53 InsertionPoint* insertionPoint() const { return m_insertionPoint; } 54 Node* node() const { return m_node.get(); } 55 Item* next() const { return m_next.get(); } 56 Item* previous() const { return m_previous.get(); } 57 58 private: 59 static PassRefPtr<Item> create(InsertionPoint* insertionPoint, Node* node) { return adoptRef(new Item(insertionPoint, node)); } 60 61 Item(InsertionPoint* insertionPoint, Node* node) 62 : m_insertionPoint(insertionPoint) 63 , m_node(node) 64 { } 65 66 InsertionPoint* m_insertionPoint; 67 RefPtr<Node> m_node; 68 RefPtr<Item> m_next; 69 RefPtr<Item> m_previous; 70 }; 71 72 ContentDistribution(); 73 ~ContentDistribution(); 74 75 Item* first() const { return m_first.get(); } 76 Item* last() const { return m_last.get(); } 77 Node* firstNode() const { return m_first ? m_first->node() : 0; } 78 Node* lastNode() const { return m_first ? m_last->node() : 0; } 79 80 Item* find(Node*) const; 81 bool isEmpty() const { return !m_first; } 82 83 void clear(); 84 void append(InsertionPoint*, Node*); 85 86 private: 87 88 RefPtr<Item> m_first; 89 RefPtr<Item> m_last; 90 }; 46 typedef Vector<RefPtr<Node> > ContentDistribution; 91 47 92 48 class ContentDistributor { … … 98 54 void distribute(InsertionPoint*, ContentDistribution*); 99 55 void clearDistribution(ContentDistribution*); 100 ContentDistribution::Item* findFor(const Node* key) const;101 56 InsertionPoint* findInsertionPointFor(const Node* key) const; 102 57 … … 109 64 110 65 private: 111 struct Translator {112 public:113 static unsigned hash(const Node* key) { return PtrHash<const Node*>::hash(key); }114 static bool equal(const ContentDistribution::Item* item, const Node* node) { return item->node() == node; }115 };116 117 struct Hash {118 static unsigned hash(ContentDistribution::Item* key) { return PtrHash<const Node*>::hash(key->node()); }119 static bool equal(ContentDistribution::Item* a, ContentDistribution::Item* b) { return a->node() == b->node(); }120 static const bool safeToCompareToEmptyOrDeleted = false;121 };122 123 // Used as a table from Node to InseretionPoint124 typedef HashSet<ContentDistribution::Item*, Hash> InvertedTable;125 126 66 enum DistributionPhase { 127 67 Prevented, … … 132 72 Vector<RefPtr<Node> > m_pool; 133 73 DistributionPhase m_phase; 134 InvertedTablem_nodeToInsertionPoint;74 HashMap<const Node*, InsertionPoint*> m_nodeToInsertionPoint; 135 75 }; 136 76 -
trunk/Source/WebCore/html/shadow/InsertionPoint.cpp
r116974 r117033 39 39 InsertionPoint::InsertionPoint(const QualifiedName& tagName, Document* document) 40 40 : HTMLElement(tagName, document) 41 , m_distribution()42 41 { 43 42 } … … 139 138 inline void InsertionPoint::attachDistributedNode() 140 139 { 141 for ( ContentDistribution::Item* item = m_distribution.first(); item; item = item->next())142 item->node()->attach();140 for (size_t i = 0; i < m_distribution.size(); ++i) 141 m_distribution.at(i)->attach(); 143 142 } 144 143 … … 148 147 m_distribution.clear(); 149 148 for (Node* node = shadowRoot->firstChild(); node; node = node->nextSibling()) 150 m_distribution.append( this,node);149 m_distribution.append(node); 151 150 } 152 151 … … 157 156 } 158 157 158 Node* InsertionPoint::nextTo(const Node* node) const 159 { 160 size_t index = m_distribution.find(node); 161 if (index == notFound || index + 1 == m_distribution.size()) 162 return 0; 163 return m_distribution.at(index + 1).get(); 164 } 165 166 Node* InsertionPoint::previousTo(const Node* node) const 167 { 168 size_t index = m_distribution.find(node); 169 if (index == notFound || !index) 170 return 0; 171 return m_distribution.at(index - 1).get(); 172 } 173 174 159 175 } // namespace WebCore -
trunk/Source/WebCore/html/shadow/InsertionPoint.h
r116974 r117033 43 43 virtual ~InsertionPoint(); 44 44 45 const ContentDistribution* distribution() const { return &m_distribution; } 46 bool hasDistribution() const { return m_distribution.first(); } 45 bool hasDistribution() const { return !m_distribution.isEmpty(); } 47 46 bool isShadowBoundary() const; 48 47 bool isActive() const; … … 57 56 virtual bool isInsertionPoint() const OVERRIDE { return true; } 58 57 ShadowRoot* assignedFrom() const; 58 59 size_t indexOf(Node* node) const { return m_distribution.find(node); } 60 size_t size() const { return m_distribution.size(); } 61 Node* at(size_t index) const { return m_distribution.at(index).get(); } 62 Node* first() const { return m_distribution.isEmpty() ? 0 : m_distribution.first().get(); } 63 Node* last() const { return m_distribution.isEmpty() ? 0 : m_distribution.last().get(); } 64 Node* nextTo(const Node*) const; 65 Node* previousTo(const Node*) const; 59 66 60 67 protected:
Note:
See TracChangeset
for help on using the changeset viewer.