Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: Source/core/rendering/RenderCounter.cpp

Issue 68523014: Update remaining NodeTraversal / ElementTraversal methods to take references (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix build Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/rendering/RenderCounter.h ('k') | Source/core/rendering/RenderListItem.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * Copyright (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com) 2 * Copyright (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com)
3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 27 matching lines...) Expand all
38 #include <stdio.h> 38 #include <stdio.h>
39 #endif 39 #endif
40 40
41 namespace WebCore { 41 namespace WebCore {
42 42
43 using namespace HTMLNames; 43 using namespace HTMLNames;
44 44
45 typedef HashMap<AtomicString, RefPtr<CounterNode> > CounterMap; 45 typedef HashMap<AtomicString, RefPtr<CounterNode> > CounterMap;
46 typedef HashMap<const RenderObject*, OwnPtr<CounterMap> > CounterMaps; 46 typedef HashMap<const RenderObject*, OwnPtr<CounterMap> > CounterMaps;
47 47
48 static CounterNode* makeCounterNode(RenderObject*, const AtomicString& identifie r, bool alwaysCreateCounter); 48 static CounterNode* makeCounterNode(RenderObject&, const AtomicString& identifie r, bool alwaysCreateCounter);
49 49
50 static CounterMaps& counterMaps() 50 static CounterMaps& counterMaps()
51 { 51 {
52 DEFINE_STATIC_LOCAL(CounterMaps, staticCounterMaps, ()); 52 DEFINE_STATIC_LOCAL(CounterMaps, staticCounterMaps, ());
53 return staticCounterMaps; 53 return staticCounterMaps;
54 } 54 }
55 55
56 // This function processes the renderer tree in the order of the DOM tree 56 // This function processes the renderer tree in the order of the DOM tree
57 // including pseudo elements as defined in CSS 2.1. 57 // including pseudo elements as defined in CSS 2.1.
58 static RenderObject* previousInPreOrder(const RenderObject* object) 58 static RenderObject* previousInPreOrder(const RenderObject& object)
59 { 59 {
60 Element* self = toElement(object->node()); 60 Element* self = toElement(object.node());
61 ASSERT(self); 61 ASSERT(self);
62 Element* previous = ElementTraversal::previousIncludingPseudo(*self); 62 Element* previous = ElementTraversal::previousIncludingPseudo(*self);
63 while (previous && !previous->renderer()) 63 while (previous && !previous->renderer())
64 previous = ElementTraversal::previousIncludingPseudo(*previous); 64 previous = ElementTraversal::previousIncludingPseudo(*previous);
65 return previous ? previous->renderer() : 0; 65 return previous ? previous->renderer() : 0;
66 } 66 }
67 67
68 // This function processes the renderer tree in the order of the DOM tree 68 // This function processes the renderer tree in the order of the DOM tree
69 // including pseudo elements as defined in CSS 2.1. 69 // including pseudo elements as defined in CSS 2.1.
70 static RenderObject* previousSiblingOrParent(const RenderObject* object) 70 static RenderObject* previousSiblingOrParent(const RenderObject& object)
71 { 71 {
72 Element* self = toElement(object->node()); 72 Element* self = toElement(object.node());
73 ASSERT(self); 73 ASSERT(self);
74 Element* previous = ElementTraversal::pseudoAwarePreviousSibling(*self); 74 Element* previous = ElementTraversal::pseudoAwarePreviousSibling(*self);
75 while (previous && !previous->renderer()) 75 while (previous && !previous->renderer())
76 previous = ElementTraversal::pseudoAwarePreviousSibling(*previous); 76 previous = ElementTraversal::pseudoAwarePreviousSibling(*previous);
77 if (previous) 77 if (previous)
78 return previous->renderer(); 78 return previous->renderer();
79 previous = self->parentElement(); 79 previous = self->parentElement();
80 return previous ? previous->renderer() : 0; 80 return previous ? previous->renderer() : 0;
81 } 81 }
82 82
83 static inline Element* parentElement(RenderObject* object) 83 static inline Element* parentElement(RenderObject& object)
84 { 84 {
85 return toElement(object->node())->parentElement(); 85 return toElement(object.node())->parentElement();
86 } 86 }
87 87
88 static inline bool areRenderersElementsSiblings(RenderObject* first, RenderObjec t* second) 88 static inline bool areRenderersElementsSiblings(RenderObject& first, RenderObjec t& second)
89 { 89 {
90 return parentElement(first) == parentElement(second); 90 return parentElement(first) == parentElement(second);
91 } 91 }
92 92
93 // This function processes the renderer tree in the order of the DOM tree 93 // This function processes the renderer tree in the order of the DOM tree
94 // including pseudo elements as defined in CSS 2.1. 94 // including pseudo elements as defined in CSS 2.1.
95 static RenderObject* nextInPreOrder(const RenderObject* object, const Element* s tayWithin, bool skipDescendants = false) 95 static RenderObject* nextInPreOrder(const RenderObject& object, const Element* s tayWithin, bool skipDescendants = false)
96 { 96 {
97 Element* self = toElement(object->node()); 97 Element* self = toElement(object.node());
98 Element* next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkipp ingChildren(self, stayWithin) : ElementTraversal::nextIncludingPseudo(self, stay Within); 98 ASSERT(self);
99 Element* next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkipp ingChildren(*self, stayWithin) : ElementTraversal::nextIncludingPseudo(*self, st ayWithin);
99 while (next && !next->renderer()) 100 while (next && !next->renderer())
100 next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingCh ildren(next, stayWithin) : ElementTraversal::nextIncludingPseudo(next, stayWithi n); 101 next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingCh ildren(*next, stayWithin) : ElementTraversal::nextIncludingPseudo(*next, stayWit hin);
101 return next ? next->renderer() : 0; 102 return next ? next->renderer() : 0;
102 } 103 }
103 104
104 static bool planCounter(RenderObject* object, const AtomicString& identifier, bo ol& isReset, int& value) 105 static bool planCounter(RenderObject& object, const AtomicString& identifier, bo ol& isReset, int& value)
105 { 106 {
106 ASSERT(object);
107
108 // Real text nodes don't have their own style so they can't have counters. 107 // Real text nodes don't have their own style so they can't have counters.
109 // We can't even look at their styles or we'll see extra resets and incremen ts! 108 // We can't even look at their styles or we'll see extra resets and incremen ts!
110 if (object->isText() && !object->isBR()) 109 if (object.isText() && !object.isBR())
111 return false; 110 return false;
112 Node* generatingNode = object->generatingNode(); 111 Node* generatingNode = object.generatingNode();
113 // We must have a generating node or else we cannot have a counter. 112 // We must have a generating node or else we cannot have a counter.
114 if (!generatingNode) 113 if (!generatingNode)
115 return false; 114 return false;
116 RenderStyle* style = object->style(); 115 RenderStyle* style = object.style();
117 ASSERT(style); 116 ASSERT(style);
118 117
119 switch (style->styleType()) { 118 switch (style->styleType()) {
120 case NOPSEUDO: 119 case NOPSEUDO:
121 // Sometimes nodes have more then one renderer. Only the first one gets the counter 120 // Sometimes nodes have more then one renderer. Only the first one gets the counter
122 // LayoutTests/http/tests/css/counter-crash.html 121 // LayoutTests/http/tests/css/counter-crash.html
123 if (generatingNode->renderer() != object) 122 if (generatingNode->renderer() != &object)
124 return false; 123 return false;
125 break; 124 break;
126 case BEFORE: 125 case BEFORE:
127 case AFTER: 126 case AFTER:
128 break; 127 break;
129 default: 128 default:
130 return false; // Counters are forbidden from all other pseudo elements. 129 return false; // Counters are forbidden from all other pseudo elements.
131 } 130 }
132 131
133 const CounterDirectives directives = style->getCounterDirectives(identifier) ; 132 const CounterDirectives directives = style->getCounterDirectives(identifier) ;
134 if (directives.isDefined()) { 133 if (directives.isDefined()) {
135 value = directives.combinedValue(); 134 value = directives.combinedValue();
136 isReset = directives.isReset(); 135 isReset = directives.isReset();
137 return true; 136 return true;
138 } 137 }
139 138
140 if (identifier == "list-item") { 139 if (identifier == "list-item") {
141 if (object->isListItem()) { 140 if (object.isListItem()) {
142 if (toRenderListItem(object)->hasExplicitValue()) { 141 if (toRenderListItem(object).hasExplicitValue()) {
143 value = toRenderListItem(object)->explicitValue(); 142 value = toRenderListItem(object).explicitValue();
144 isReset = true; 143 isReset = true;
145 return true; 144 return true;
146 } 145 }
147 value = 1; 146 value = 1;
148 isReset = false; 147 isReset = false;
149 return true; 148 return true;
150 } 149 }
151 if (Node* e = object->node()) { 150 if (Node* e = object.node()) {
152 if (e->hasTagName(olTag)) { 151 if (e->hasTagName(olTag)) {
153 value = toHTMLOListElement(e)->start(); 152 value = toHTMLOListElement(e)->start();
154 isReset = true; 153 isReset = true;
155 return true; 154 return true;
156 } 155 }
157 if (e->hasTagName(ulTag) || e->hasTagName(menuTag) || e->hasTagName( dirTag)) { 156 if (e->hasTagName(ulTag) || e->hasTagName(menuTag) || e->hasTagName( dirTag)) {
158 value = 0; 157 value = 0;
159 isReset = true; 158 isReset = true;
160 return true; 159 return true;
161 } 160 }
(...skipping 12 matching lines...) Expand all
174 // counter with the same identifier. 173 // counter with the same identifier.
175 // - All the counter references with the same identifier as this one that are in 174 // - All the counter references with the same identifier as this one that are in
176 // children or subsequent siblings of the renderer that owns the root of the tre e 175 // children or subsequent siblings of the renderer that owns the root of the tre e
177 // form the rest of of the nodes of the tree. 176 // form the rest of of the nodes of the tree.
178 // - The root of the tree is always a reset type reference. 177 // - The root of the tree is always a reset type reference.
179 // - A subtree rooted at any reset node in the tree is equivalent to all counter 178 // - A subtree rooted at any reset node in the tree is equivalent to all counter
180 // references that are in the scope of the counter or nested counter defined by that 179 // references that are in the scope of the counter or nested counter defined by that
181 // reset node. 180 // reset node.
182 // - Non-reset CounterNodes cannot have descendants. 181 // - Non-reset CounterNodes cannot have descendants.
183 182
184 static bool findPlaceForCounter(RenderObject* counterOwner, const AtomicString& identifier, bool isReset, RefPtr<CounterNode>& parent, RefPtr<CounterNode>& prev iousSibling) 183 static bool findPlaceForCounter(RenderObject& counterOwner, const AtomicString& identifier, bool isReset, RefPtr<CounterNode>& parent, RefPtr<CounterNode>& prev iousSibling)
185 { 184 {
186 // We cannot stop searching for counters with the same identifier before we also 185 // We cannot stop searching for counters with the same identifier before we also
187 // check this renderer, because it may affect the positioning in the tree of our counter. 186 // check this renderer, because it may affect the positioning in the tree of our counter.
188 RenderObject* searchEndRenderer = previousSiblingOrParent(counterOwner); 187 RenderObject* searchEndRenderer = previousSiblingOrParent(counterOwner);
189 // We check renderers in preOrder from the renderer that our counter is atta ched to 188 // We check renderers in preOrder from the renderer that our counter is atta ched to
190 // towards the begining of the document for counters with the same identifie r as the one 189 // towards the begining of the document for counters with the same identifie r as the one
191 // we are trying to find a place for. This is the next renderer to be checke d. 190 // we are trying to find a place for. This is the next renderer to be checke d.
192 RenderObject* currentRenderer = previousInPreOrder(counterOwner); 191 RenderObject* currentRenderer = previousInPreOrder(counterOwner);
193 previousSibling = 0; 192 previousSibling = 0;
194 RefPtr<CounterNode> previousSiblingProtector = 0; 193 RefPtr<CounterNode> previousSiblingProtector = 0;
195 194
196 while (currentRenderer) { 195 while (currentRenderer) {
197 CounterNode* currentCounter = makeCounterNode(currentRenderer, identifie r, false); 196 CounterNode* currentCounter = makeCounterNode(*currentRenderer, identifi er, false);
198 if (searchEndRenderer == currentRenderer) { 197 if (searchEndRenderer == currentRenderer) {
199 // We may be at the end of our search. 198 // We may be at the end of our search.
200 if (currentCounter) { 199 if (currentCounter) {
201 // We have a suitable counter on the EndSearchRenderer. 200 // We have a suitable counter on the EndSearchRenderer.
202 if (previousSiblingProtector) { // But we already found another counter that we come after. 201 if (previousSiblingProtector) { // But we already found another counter that we come after.
203 if (currentCounter->actsAsReset()) { 202 if (currentCounter->actsAsReset()) {
204 // We found a reset counter that is on a renderer that i s a sibling of ours or a parent. 203 // We found a reset counter that is on a renderer that i s a sibling of ours or a parent.
205 if (isReset && areRenderersElementsSiblings(currentRende rer, counterOwner)) { 204 if (isReset && areRenderersElementsSiblings(*currentRend erer, counterOwner)) {
206 // We are also a reset counter and the previous rese t was on a sibling renderer 205 // We are also a reset counter and the previous rese t was on a sibling renderer
207 // hence we are the next sibling of that counter if that reset is not a root or 206 // hence we are the next sibling of that counter if that reset is not a root or
208 // we are a root node if that reset is a root. 207 // we are a root node if that reset is a root.
209 parent = currentCounter->parent(); 208 parent = currentCounter->parent();
210 previousSibling = parent ? currentCounter : 0; 209 previousSibling = parent ? currentCounter : 0;
211 return parent; 210 return parent;
212 } 211 }
213 // We are not a reset node or the previous reset must be on an ancestor of our owner renderer 212 // We are not a reset node or the previous reset must be on an ancestor of our owner renderer
214 // hence we must be a child of that reset counter. 213 // hence we must be a child of that reset counter.
215 parent = currentCounter; 214 parent = currentCounter;
216 // In some cases renders can be reparented (ex. nodes in side a table but not in a column or row). 215 // In some cases renders can be reparented (ex. nodes in side a table but not in a column or row).
217 // In these cases the identified previousSibling will be invalid as its parent is different from 216 // In these cases the identified previousSibling will be invalid as its parent is different from
218 // our identified parent. 217 // our identified parent.
219 if (previousSiblingProtector->parent() != currentCounter ) 218 if (previousSiblingProtector->parent() != currentCounter )
220 previousSiblingProtector = 0; 219 previousSiblingProtector = 0;
221 220
222 previousSibling = previousSiblingProtector.get(); 221 previousSibling = previousSiblingProtector.get();
223 return true; 222 return true;
224 } 223 }
225 // CurrentCounter, the counter at the EndSearchRenderer, is not reset. 224 // CurrentCounter, the counter at the EndSearchRenderer, is not reset.
226 if (!isReset || !areRenderersElementsSiblings(currentRendere r, counterOwner)) { 225 if (!isReset || !areRenderersElementsSiblings(*currentRender er, counterOwner)) {
227 // If the node we are placing is not reset or we have fo und a counter that is attached 226 // If the node we are placing is not reset or we have fo und a counter that is attached
228 // to an ancestor of the placed counter's owner renderer we know we are a sibling of that node. 227 // to an ancestor of the placed counter's owner renderer we know we are a sibling of that node.
229 if (currentCounter->parent() != previousSiblingProtector ->parent()) 228 if (currentCounter->parent() != previousSiblingProtector ->parent())
230 return false; 229 return false;
231 230
232 parent = currentCounter->parent(); 231 parent = currentCounter->parent();
233 previousSibling = previousSiblingProtector.get(); 232 previousSibling = previousSiblingProtector.get();
234 return true; 233 return true;
235 } 234 }
236 } else { 235 } else {
237 // We are at the potential end of the search, but we had no previous sibling candidate 236 // We are at the potential end of the search, but we had no previous sibling candidate
238 // In this case we follow pretty much the same logic as abov e but no ASSERTs about 237 // In this case we follow pretty much the same logic as abov e but no ASSERTs about
239 // previousSibling, and when we are a sibling of the end cou nter we must set previousSibling 238 // previousSibling, and when we are a sibling of the end cou nter we must set previousSibling
240 // to currentCounter. 239 // to currentCounter.
241 if (currentCounter->actsAsReset()) { 240 if (currentCounter->actsAsReset()) {
242 if (isReset && areRenderersElementsSiblings(currentRende rer, counterOwner)) { 241 if (isReset && areRenderersElementsSiblings(*currentRend erer, counterOwner)) {
243 parent = currentCounter->parent(); 242 parent = currentCounter->parent();
244 previousSibling = currentCounter; 243 previousSibling = currentCounter;
245 return parent; 244 return parent;
246 } 245 }
247 parent = currentCounter; 246 parent = currentCounter;
248 previousSibling = previousSiblingProtector.get(); 247 previousSibling = previousSiblingProtector.get();
249 return true; 248 return true;
250 } 249 }
251 if (!isReset || !areRenderersElementsSiblings(currentRendere r, counterOwner)) { 250 if (!isReset || !areRenderersElementsSiblings(*currentRender er, counterOwner)) {
252 parent = currentCounter->parent(); 251 parent = currentCounter->parent();
253 previousSibling = currentCounter; 252 previousSibling = currentCounter;
254 return true; 253 return true;
255 } 254 }
256 previousSiblingProtector = currentCounter; 255 previousSiblingProtector = currentCounter;
257 } 256 }
258 } 257 }
259 // We come here if the previous sibling or parent of our owner rende rer had no 258 // We come here if the previous sibling or parent of our owner rende rer had no
260 // good counter, or we are a reset node and the counter on the previ ous sibling 259 // good counter, or we are a reset node and the counter on the previ ous sibling
261 // of our owner renderer was not a reset counter. 260 // of our owner renderer was not a reset counter.
262 // Set a new goal for the end of the search. 261 // Set a new goal for the end of the search.
263 searchEndRenderer = previousSiblingOrParent(currentRenderer); 262 searchEndRenderer = previousSiblingOrParent(*currentRenderer);
264 } else { 263 } else {
265 // We are searching descendants of a previous sibling of the rendere r that the 264 // We are searching descendants of a previous sibling of the rendere r that the
266 // counter being placed is attached to. 265 // counter being placed is attached to.
267 if (currentCounter) { 266 if (currentCounter) {
268 // We found a suitable counter. 267 // We found a suitable counter.
269 if (previousSiblingProtector) { 268 if (previousSiblingProtector) {
270 // Since we had a suitable previous counter before, we shoul d only consider this one as our 269 // Since we had a suitable previous counter before, we shoul d only consider this one as our
271 // previousSibling if it is a reset counter and hence the cu rrent previousSibling is its child. 270 // previousSibling if it is a reset counter and hence the cu rrent previousSibling is its child.
272 if (currentCounter->actsAsReset()) { 271 if (currentCounter->actsAsReset()) {
273 previousSiblingProtector = currentCounter; 272 previousSiblingProtector = currentCounter;
274 // We are no longer interested in previous siblings of t he currentRenderer or their children 273 // We are no longer interested in previous siblings of t he currentRenderer or their children
275 // as counters they may have attached cannot be the prev ious sibling of the counter we are placing. 274 // as counters they may have attached cannot be the prev ious sibling of the counter we are placing.
276 currentRenderer = parentElement(currentRenderer)->render er(); 275 currentRenderer = parentElement(*currentRenderer)->rende rer();
277 continue; 276 continue;
278 } 277 }
279 } else 278 } else
280 previousSiblingProtector = currentCounter; 279 previousSiblingProtector = currentCounter;
281 currentRenderer = previousSiblingOrParent(currentRenderer); 280 currentRenderer = previousSiblingOrParent(*currentRenderer);
282 continue; 281 continue;
283 } 282 }
284 } 283 }
285 // This function is designed so that the same test is not done twice in an iteration, except for this one 284 // This function is designed so that the same test is not done twice in an iteration, except for this one
286 // which may be done twice in some cases. Rearranging the decision point s though, to accommodate this 285 // which may be done twice in some cases. Rearranging the decision point s though, to accommodate this
287 // performance improvement would create more code duplication than is wo rthwhile in my oppinion and may further 286 // performance improvement would create more code duplication than is wo rthwhile in my oppinion and may further
288 // impede the readability of this already complex algorithm. 287 // impede the readability of this already complex algorithm.
289 if (previousSiblingProtector) 288 if (previousSiblingProtector)
290 currentRenderer = previousSiblingOrParent(currentRenderer); 289 currentRenderer = previousSiblingOrParent(*currentRenderer);
291 else 290 else
292 currentRenderer = previousInPreOrder(currentRenderer); 291 currentRenderer = previousInPreOrder(*currentRenderer);
293 } 292 }
294 return false; 293 return false;
295 } 294 }
296 295
297 static CounterNode* makeCounterNode(RenderObject* object, const AtomicString& id entifier, bool alwaysCreateCounter) 296 static CounterNode* makeCounterNode(RenderObject& object, const AtomicString& id entifier, bool alwaysCreateCounter)
298 { 297 {
299 ASSERT(object); 298 if (object.hasCounterNodeMap()) {
300 299 if (CounterMap* nodeMap = counterMaps().get(&object)) {
301 if (object->hasCounterNodeMap()) {
302 if (CounterMap* nodeMap = counterMaps().get(object)) {
303 if (CounterNode* node = nodeMap->get(identifier)) 300 if (CounterNode* node = nodeMap->get(identifier))
304 return node; 301 return node;
305 } 302 }
306 } 303 }
307 304
308 bool isReset = false; 305 bool isReset = false;
309 int value = 0; 306 int value = 0;
310 if (!planCounter(object, identifier, isReset, value) && !alwaysCreateCounter ) 307 if (!planCounter(object, identifier, isReset, value) && !alwaysCreateCounter )
311 return 0; 308 return 0;
312 309
313 RefPtr<CounterNode> newParent = 0; 310 RefPtr<CounterNode> newParent = 0;
314 RefPtr<CounterNode> newPreviousSibling = 0; 311 RefPtr<CounterNode> newPreviousSibling = 0;
315 RefPtr<CounterNode> newNode = CounterNode::create(object, isReset, value); 312 RefPtr<CounterNode> newNode = CounterNode::create(object, isReset, value);
316 if (findPlaceForCounter(object, identifier, isReset, newParent, newPreviousS ibling)) 313 if (findPlaceForCounter(object, identifier, isReset, newParent, newPreviousS ibling))
317 newParent->insertAfter(newNode.get(), newPreviousSibling.get(), identifi er); 314 newParent->insertAfter(newNode.get(), newPreviousSibling.get(), identifi er);
318 CounterMap* nodeMap; 315 CounterMap* nodeMap;
319 if (object->hasCounterNodeMap()) 316 if (object.hasCounterNodeMap())
320 nodeMap = counterMaps().get(object); 317 nodeMap = counterMaps().get(&object);
321 else { 318 else {
322 nodeMap = new CounterMap; 319 nodeMap = new CounterMap;
323 counterMaps().set(object, adoptPtr(nodeMap)); 320 counterMaps().set(&object, adoptPtr(nodeMap));
324 object->setHasCounterNodeMap(true); 321 object.setHasCounterNodeMap(true);
325 } 322 }
326 nodeMap->set(identifier, newNode); 323 nodeMap->set(identifier, newNode);
327 if (newNode->parent()) 324 if (newNode->parent())
328 return newNode.get(); 325 return newNode.get();
329 // Checking if some nodes that were previously counter tree root nodes 326 // Checking if some nodes that were previously counter tree root nodes
330 // should become children of this node now. 327 // should become children of this node now.
331 CounterMaps& maps = counterMaps(); 328 CounterMaps& maps = counterMaps();
332 Element* stayWithin = parentElement(object); 329 Element* stayWithin = parentElement(object);
333 bool skipDescendants; 330 bool skipDescendants;
334 for (RenderObject* currentRenderer = nextInPreOrder(object, stayWithin); cur rentRenderer; currentRenderer = nextInPreOrder(currentRenderer, stayWithin, skip Descendants)) { 331 for (RenderObject* currentRenderer = nextInPreOrder(object, stayWithin); cur rentRenderer; currentRenderer = nextInPreOrder(*currentRenderer, stayWithin, ski pDescendants)) {
335 skipDescendants = false; 332 skipDescendants = false;
336 if (!currentRenderer->hasCounterNodeMap()) 333 if (!currentRenderer->hasCounterNodeMap())
337 continue; 334 continue;
338 CounterNode* currentCounter = maps.get(currentRenderer)->get(identifier) ; 335 CounterNode* currentCounter = maps.get(currentRenderer)->get(identifier) ;
339 if (!currentCounter) 336 if (!currentCounter)
340 continue; 337 continue;
341 skipDescendants = true; 338 skipDescendants = true;
342 if (currentCounter->parent()) 339 if (currentCounter->parent())
343 continue; 340 continue;
344 if (stayWithin == parentElement(currentRenderer) && currentCounter->hasR esetType()) 341 if (stayWithin == parentElement(*currentRenderer) && currentCounter->has ResetType())
345 break; 342 break;
346 newNode->insertAfter(currentCounter, newNode->lastChild(), identifier); 343 newNode->insertAfter(currentCounter, newNode->lastChild(), identifier);
347 } 344 }
348 return newNode.get(); 345 return newNode.get();
349 } 346 }
350 347
351 RenderCounter::RenderCounter(Document* node, const CounterContent& counter) 348 RenderCounter::RenderCounter(Document* node, const CounterContent& counter)
352 : RenderText(node, StringImpl::empty()) 349 : RenderText(node, StringImpl::empty())
353 , m_counter(counter) 350 , m_counter(counter)
354 , m_counterNode(0) 351 , m_counterNode(0)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 while (true) { 386 while (true) {
390 if (!beforeAfterContainer) 387 if (!beforeAfterContainer)
391 return 0; 388 return 0;
392 if (!beforeAfterContainer->isAnonymous() && !beforeAfterContainer->i sPseudoElement()) 389 if (!beforeAfterContainer->isAnonymous() && !beforeAfterContainer->i sPseudoElement())
393 return 0; // RenderCounters are restricted to before and after p seudo elements 390 return 0; // RenderCounters are restricted to before and after p seudo elements
394 PseudoId containerStyle = beforeAfterContainer->style()->styleType() ; 391 PseudoId containerStyle = beforeAfterContainer->style()->styleType() ;
395 if ((containerStyle == BEFORE) || (containerStyle == AFTER)) 392 if ((containerStyle == BEFORE) || (containerStyle == AFTER))
396 break; 393 break;
397 beforeAfterContainer = beforeAfterContainer->parent(); 394 beforeAfterContainer = beforeAfterContainer->parent();
398 } 395 }
399 makeCounterNode(beforeAfterContainer, m_counter.identifier(), true)->add Renderer(const_cast<RenderCounter*>(this)); 396 makeCounterNode(*beforeAfterContainer, m_counter.identifier(), true)->ad dRenderer(const_cast<RenderCounter*>(this));
400 ASSERT(m_counterNode); 397 ASSERT(m_counterNode);
401 } 398 }
402 CounterNode* child = m_counterNode; 399 CounterNode* child = m_counterNode;
403 int value = child->actsAsReset() ? child->value() : child->countInParent(); 400 int value = child->actsAsReset() ? child->value() : child->countInParent();
404 401
405 String text = listMarkerText(m_counter.listStyle(), value); 402 String text = listMarkerText(m_counter.listStyle(), value);
406 403
407 if (!m_counter.separator().isNull()) { 404 if (!m_counter.separator().isNull()) {
408 if (!child->actsAsReset()) 405 if (!child->actsAsReset())
409 child = child->parent(); 406 child = child->parent();
(...skipping 20 matching lines...) Expand all
430 return; 427 return;
431 setNeedsLayoutAndPrefWidthsRecalc(); 428 setNeedsLayoutAndPrefWidthsRecalc();
432 } 429 }
433 430
434 static void destroyCounterNodeWithoutMapRemoval(const AtomicString& identifier, CounterNode* node) 431 static void destroyCounterNodeWithoutMapRemoval(const AtomicString& identifier, CounterNode* node)
435 { 432 {
436 CounterNode* previous; 433 CounterNode* previous;
437 for (RefPtr<CounterNode> child = node->lastDescendant(); child && child != n ode; child = previous) { 434 for (RefPtr<CounterNode> child = node->lastDescendant(); child && child != n ode; child = previous) {
438 previous = child->previousInPreOrder(); 435 previous = child->previousInPreOrder();
439 child->parent()->removeChild(child.get()); 436 child->parent()->removeChild(child.get());
440 ASSERT(counterMaps().get(child->owner())->get(identifier) == child); 437 ASSERT(counterMaps().get(&child->owner())->get(identifier) == child);
441 counterMaps().get(child->owner())->remove(identifier); 438 counterMaps().get(&child->owner())->remove(identifier);
442 } 439 }
443 if (CounterNode* parent = node->parent()) 440 if (CounterNode* parent = node->parent())
444 parent->removeChild(node); 441 parent->removeChild(node);
445 } 442 }
446 443
447 void RenderCounter::destroyCounterNodes(RenderObject* owner) 444 void RenderCounter::destroyCounterNodes(RenderObject& owner)
448 { 445 {
449 CounterMaps& maps = counterMaps(); 446 CounterMaps& maps = counterMaps();
450 CounterMaps::iterator mapsIterator = maps.find(owner); 447 CounterMaps::iterator mapsIterator = maps.find(&owner);
451 if (mapsIterator == maps.end()) 448 if (mapsIterator == maps.end())
452 return; 449 return;
453 CounterMap* map = mapsIterator->value.get(); 450 CounterMap* map = mapsIterator->value.get();
454 CounterMap::const_iterator end = map->end(); 451 CounterMap::const_iterator end = map->end();
455 for (CounterMap::const_iterator it = map->begin(); it != end; ++it) { 452 for (CounterMap::const_iterator it = map->begin(); it != end; ++it) {
456 destroyCounterNodeWithoutMapRemoval(it->key, it->value.get()); 453 destroyCounterNodeWithoutMapRemoval(it->key, it->value.get());
457 } 454 }
458 maps.remove(mapsIterator); 455 maps.remove(mapsIterator);
459 owner->setHasCounterNodeMap(false); 456 owner.setHasCounterNodeMap(false);
460 } 457 }
461 458
462 void RenderCounter::destroyCounterNode(RenderObject* owner, const AtomicString& identifier) 459 void RenderCounter::destroyCounterNode(RenderObject& owner, const AtomicString& identifier)
463 { 460 {
464 CounterMap* map = counterMaps().get(owner); 461 CounterMap* map = counterMaps().get(&owner);
465 if (!map) 462 if (!map)
466 return; 463 return;
467 CounterMap::iterator mapIterator = map->find(identifier); 464 CounterMap::iterator mapIterator = map->find(identifier);
468 if (mapIterator == map->end()) 465 if (mapIterator == map->end())
469 return; 466 return;
470 destroyCounterNodeWithoutMapRemoval(identifier, mapIterator->value.get()); 467 destroyCounterNodeWithoutMapRemoval(identifier, mapIterator->value.get());
471 map->remove(mapIterator); 468 map->remove(mapIterator);
472 // We do not delete "map" here even if empty because we expect to reuse 469 // We do not delete "map" here even if empty because we expect to reuse
473 // it soon. In order for a renderer to lose all its counters permanently, 470 // it soon. In order for a renderer to lose all its counters permanently,
474 // a style change for the renderer involving removal of all counter 471 // a style change for the renderer involving removal of all counter
475 // directives must occur, in which case, RenderCounter::destroyCounterNodes( ) 472 // directives must occur, in which case, RenderCounter::destroyCounterNodes( )
476 // must be called. 473 // must be called.
477 // The destruction of the Renderer (possibly caused by the removal of its 474 // The destruction of the Renderer (possibly caused by the removal of its
478 // associated DOM node) is the other case that leads to the permanent 475 // associated DOM node) is the other case that leads to the permanent
479 // destruction of all counters attached to a Renderer. In this case 476 // destruction of all counters attached to a Renderer. In this case
480 // RenderCounter::destroyCounterNodes() must be and is now called, too. 477 // RenderCounter::destroyCounterNodes() must be and is now called, too.
481 // RenderCounter::destroyCounterNodes() handles destruction of the counter 478 // RenderCounter::destroyCounterNodes() handles destruction of the counter
482 // map associated with a renderer, so there is no risk in leaking the map. 479 // map associated with a renderer, so there is no risk in leaking the map.
483 } 480 }
484 481
485 void RenderCounter::rendererRemovedFromTree(RenderObject* renderer) 482 void RenderCounter::rendererRemovedFromTree(RenderObject* renderer)
486 { 483 {
487 ASSERT(renderer->view()); 484 ASSERT(renderer->view());
488 if (!renderer->view()->hasRenderCounters()) 485 if (!renderer->view()->hasRenderCounters())
489 return; 486 return;
490 RenderObject* currentRenderer = renderer->lastLeafChild(); 487 RenderObject* currentRenderer = renderer->lastLeafChild();
491 if (!currentRenderer) 488 if (!currentRenderer)
492 currentRenderer = renderer; 489 currentRenderer = renderer;
493 while (true) { 490 while (true) {
494 destroyCounterNodes(currentRenderer); 491 destroyCounterNodes(*currentRenderer);
495 if (currentRenderer == renderer) 492 if (currentRenderer == renderer)
496 break; 493 break;
497 currentRenderer = currentRenderer->previousInPreOrder(); 494 currentRenderer = currentRenderer->previousInPreOrder();
498 } 495 }
499 } 496 }
500 497
501 static void updateCounters(RenderObject* renderer) 498 static void updateCounters(RenderObject& renderer)
502 { 499 {
503 ASSERT(renderer->style()); 500 ASSERT(renderer.style());
504 const CounterDirectiveMap* directiveMap = renderer->style()->counterDirectiv es(); 501 const CounterDirectiveMap* directiveMap = renderer.style()->counterDirective s();
505 if (!directiveMap) 502 if (!directiveMap)
506 return; 503 return;
507 CounterDirectiveMap::const_iterator end = directiveMap->end(); 504 CounterDirectiveMap::const_iterator end = directiveMap->end();
508 if (!renderer->hasCounterNodeMap()) { 505 if (!renderer.hasCounterNodeMap()) {
509 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it != end; ++it) 506 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it != end; ++it)
510 makeCounterNode(renderer, it->key, false); 507 makeCounterNode(renderer, it->key, false);
511 return; 508 return;
512 } 509 }
513 CounterMap* counterMap = counterMaps().get(renderer); 510 CounterMap* counterMap = counterMaps().get(&renderer);
514 ASSERT(counterMap); 511 ASSERT(counterMap);
515 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it != e nd; ++it) { 512 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it != e nd; ++it) {
516 RefPtr<CounterNode> node = counterMap->get(it->key); 513 RefPtr<CounterNode> node = counterMap->get(it->key);
517 if (!node) { 514 if (!node) {
518 makeCounterNode(renderer, it->key, false); 515 makeCounterNode(renderer, it->key, false);
519 continue; 516 continue;
520 } 517 }
521 RefPtr<CounterNode> newParent = 0; 518 RefPtr<CounterNode> newParent = 0;
522 RefPtr<CounterNode> newPreviousSibling = 0; 519 RefPtr<CounterNode> newPreviousSibling = 0;
523 520
(...skipping 16 matching lines...) Expand all
540 if (!renderer->view()->hasRenderCounters()) 537 if (!renderer->view()->hasRenderCounters())
541 return; 538 return;
542 Node* node = renderer->node(); 539 Node* node = renderer->node();
543 if (node) 540 if (node)
544 node = node->parentNode(); 541 node = node->parentNode();
545 else 542 else
546 node = renderer->generatingNode(); 543 node = renderer->generatingNode();
547 if (node && node->needsAttach()) 544 if (node && node->needsAttach())
548 return; // No need to update if the parent is not attached yet 545 return; // No need to update if the parent is not attached yet
549 for (RenderObject* descendant = renderer; descendant; descendant = descendan t->nextInPreOrder(renderer)) 546 for (RenderObject* descendant = renderer; descendant; descendant = descendan t->nextInPreOrder(renderer))
550 updateCounters(descendant); 547 updateCounters(*descendant);
551 } 548 }
552 549
553 void RenderCounter::rendererStyleChanged(RenderObject* renderer, const RenderSty le* oldStyle, const RenderStyle* newStyle) 550 void RenderCounter::rendererStyleChanged(RenderObject& renderer, const RenderSty le* oldStyle, const RenderStyle* newStyle)
554 { 551 {
555 Node* node = renderer->generatingNode(); 552 Node* node = renderer.generatingNode();
556 if (!node || node->needsAttach()) 553 if (!node || node->needsAttach())
557 return; // cannot have generated content or if it can have, it will be h andled during attaching 554 return; // cannot have generated content or if it can have, it will be h andled during attaching
558 const CounterDirectiveMap* newCounterDirectives; 555 const CounterDirectiveMap* newCounterDirectives;
559 const CounterDirectiveMap* oldCounterDirectives; 556 const CounterDirectiveMap* oldCounterDirectives;
560 if (oldStyle && (oldCounterDirectives = oldStyle->counterDirectives())) { 557 if (oldStyle && (oldCounterDirectives = oldStyle->counterDirectives())) {
561 if (newStyle && (newCounterDirectives = newStyle->counterDirectives())) { 558 if (newStyle && (newCounterDirectives = newStyle->counterDirectives())) {
562 CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives ->end(); 559 CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives ->end();
563 CounterDirectiveMap::const_iterator oldMapEnd = oldCounterDirectives ->end(); 560 CounterDirectiveMap::const_iterator oldMapEnd = oldCounterDirectives ->end();
564 for (CounterDirectiveMap::const_iterator it = newCounterDirectives-> begin(); it != newMapEnd; ++it) { 561 for (CounterDirectiveMap::const_iterator it = newCounterDirectives-> begin(); it != newMapEnd; ++it) {
565 CounterDirectiveMap::const_iterator oldMapIt = oldCounterDirecti ves->find(it->key); 562 CounterDirectiveMap::const_iterator oldMapIt = oldCounterDirecti ves->find(it->key);
566 if (oldMapIt != oldMapEnd) { 563 if (oldMapIt != oldMapEnd) {
567 if (oldMapIt->value == it->value) 564 if (oldMapIt->value == it->value)
568 continue; 565 continue;
569 RenderCounter::destroyCounterNode(renderer, it->key); 566 RenderCounter::destroyCounterNode(renderer, it->key);
570 } 567 }
571 // We must create this node here, because the changed node may b e a node with no display such as 568 // We must create this node here, because the changed node may b e a node with no display such as
572 // as those created by the increment or reset directives and the re-layout that will happen will 569 // as those created by the increment or reset directives and the re-layout that will happen will
573 // not catch the change if the node had no children. 570 // not catch the change if the node had no children.
574 makeCounterNode(renderer, it->key, false); 571 makeCounterNode(renderer, it->key, false);
575 } 572 }
576 // Destroying old counters that do not exist in the new counterDirec tive map. 573 // Destroying old counters that do not exist in the new counterDirec tive map.
577 for (CounterDirectiveMap::const_iterator it = oldCounterDirectives-> begin(); it !=oldMapEnd; ++it) { 574 for (CounterDirectiveMap::const_iterator it = oldCounterDirectives-> begin(); it !=oldMapEnd; ++it) {
578 if (!newCounterDirectives->contains(it->key)) 575 if (!newCounterDirectives->contains(it->key))
579 RenderCounter::destroyCounterNode(renderer, it->key); 576 RenderCounter::destroyCounterNode(renderer, it->key);
580 } 577 }
581 } else { 578 } else {
582 if (renderer->hasCounterNodeMap()) 579 if (renderer.hasCounterNodeMap())
583 RenderCounter::destroyCounterNodes(renderer); 580 RenderCounter::destroyCounterNodes(renderer);
584 } 581 }
585 } else if (newStyle && (newCounterDirectives = newStyle->counterDirectives() )) { 582 } else if (newStyle && (newCounterDirectives = newStyle->counterDirectives() )) {
586 CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives->en d(); 583 CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives->en d();
587 for (CounterDirectiveMap::const_iterator it = newCounterDirectives->begi n(); it != newMapEnd; ++it) { 584 for (CounterDirectiveMap::const_iterator it = newCounterDirectives->begi n(); it != newMapEnd; ++it) {
588 // We must create this node here, because the added node may be a no de with no display such as 585 // We must create this node here, because the added node may be a no de with no display such as
589 // as those created by the increment or reset directives and the re- layout that will happen will 586 // as those created by the increment or reset directives and the re- layout that will happen will
590 // not catch the change if the node had no children. 587 // not catch the change if the node had no children.
591 makeCounterNode(renderer, it->key, false); 588 makeCounterNode(renderer, it->key, false);
592 } 589 }
(...skipping 19 matching lines...) Expand all
612 fprintf(stderr, " "); 609 fprintf(stderr, " ");
613 fprintf(stderr, "%p N:%p P:%p PS:%p NS:%p C:%p\n", 610 fprintf(stderr, "%p N:%p P:%p PS:%p NS:%p C:%p\n",
614 current, current->node(), current->parent(), current->previousSiblin g(), 611 current, current->node(), current->parent(), current->previousSiblin g(),
615 current->nextSibling(), current->hasCounterNodeMap() ? 612 current->nextSibling(), current->hasCounterNodeMap() ?
616 counterName ? WebCore::counterMaps().get(current)->get(identifier) : (WebCore::CounterNode*)1 : (WebCore::CounterNode*)0); 613 counterName ? WebCore::counterMaps().get(current)->get(identifier) : (WebCore::CounterNode*)1 : (WebCore::CounterNode*)0);
617 } 614 }
618 fflush(stderr); 615 fflush(stderr);
619 } 616 }
620 617
621 #endif // NDEBUG 618 #endif // NDEBUG
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderCounter.h ('k') | Source/core/rendering/RenderListItem.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698