OLD | NEW |
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 25 matching lines...) Expand all Loading... |
36 #include <stdio.h> | 36 #include <stdio.h> |
37 #endif | 37 #endif |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 using namespace HTMLNames; | 41 using namespace HTMLNames; |
42 | 42 |
43 typedef HashMap<AtomicString, RefPtr<CounterNode>> CounterMap; | 43 typedef HashMap<AtomicString, RefPtr<CounterNode>> CounterMap; |
44 typedef HashMap<const LayoutObject*, OwnPtr<CounterMap>> CounterMaps; | 44 typedef HashMap<const LayoutObject*, OwnPtr<CounterMap>> CounterMaps; |
45 | 45 |
46 static CounterNode* makeCounterNode(LayoutObject&, const AtomicString& identifie
r, bool alwaysCreateCounter); | 46 static CounterNode* makeCounterNodeIfNeeded(LayoutObject&, const AtomicString& i
dentifier, bool alwaysCreateCounter); |
47 | 47 |
48 // See class definition as to why we have this map. | 48 // See class definition as to why we have this map. |
49 static CounterMaps& counterMaps() | 49 static CounterMaps& counterMaps() |
50 { | 50 { |
51 DEFINE_STATIC_LOCAL(CounterMaps, staticCounterMaps, ()); | 51 DEFINE_STATIC_LOCAL(CounterMaps, staticCounterMaps, ()); |
52 return staticCounterMaps; | 52 return staticCounterMaps; |
53 } | 53 } |
54 | 54 |
| 55 Element* ancestorStyleContainmentObject(const Element& element) |
| 56 { |
| 57 for (Element* ancestor = FlatTreeTraversal::parentElement(element); ancestor
; ancestor = FlatTreeTraversal::parentElement(*ancestor)) { |
| 58 if (ancestor->layoutObject() && ancestor->layoutObject()->style()->conta
insStyle()) |
| 59 return ancestor; |
| 60 } |
| 61 return nullptr; |
| 62 } |
| 63 |
55 // This function processes the layoutObject tree in the order of the DOM tree | 64 // This function processes the layoutObject tree in the order of the DOM tree |
56 // including pseudo elements as defined in CSS 2.1. | 65 // including pseudo elements as defined in CSS 2.1. This method will always retu
rn |
57 static LayoutObject* previousInPreOrder(const LayoutObject& object) | 66 // either a previous object within the same contain: style scope or nullptr. |
| 67 static LayoutObject* previousInPreOrderRespectingContainment(const LayoutObject&
object) |
58 { | 68 { |
59 Element* self = toElement(object.node()); | 69 Element* self = toElement(object.node()); |
60 ASSERT(self); | 70 ASSERT(self); |
61 Element* previous = ElementTraversal::previousIncludingPseudo(*self); | 71 Element* previous = ElementTraversal::previousIncludingPseudo(*self); |
62 while (previous && !previous->layoutObject()) | 72 Element* styleContainAncestor = ancestorStyleContainmentObject(*self); |
63 previous = ElementTraversal::previousIncludingPseudo(*previous); | 73 |
64 return previous ? previous->layoutObject() : 0; | 74 while (1) { |
| 75 while (previous && !previous->layoutObject()) |
| 76 previous = ElementTraversal::previousIncludingPseudo(*previous); |
| 77 if (!previous) |
| 78 return nullptr; |
| 79 Element* previousStyleContainAncestor = ancestorStyleContainmentObject(*
previous); |
| 80 if (previousStyleContainAncestor == styleContainAncestor) |
| 81 return previous->layoutObject(); |
| 82 if (!previousStyleContainAncestor) |
| 83 return nullptr; |
| 84 previous = previousStyleContainAncestor; |
| 85 } |
65 } | 86 } |
66 | 87 |
67 // This function processes the layoutObject tree in the order of the DOM tree | 88 // This function processes the layoutObject tree in the order of the DOM tree |
68 // including pseudo elements as defined in CSS 2.1. | 89 // including pseudo elements as defined in CSS 2.1. This method avoids crossing |
69 static LayoutObject* previousSiblingOrParent(const LayoutObject& object) | 90 // contain: style boundaries. |
| 91 static LayoutObject* previousSiblingOrParentRespectingContainment(const LayoutOb
ject& object) |
70 { | 92 { |
71 Element* self = toElement(object.node()); | 93 Element* self = toElement(object.node()); |
72 ASSERT(self); | 94 ASSERT(self); |
73 Element* previous = ElementTraversal::pseudoAwarePreviousSibling(*self); | 95 Element* previous = ElementTraversal::pseudoAwarePreviousSibling(*self); |
74 while (previous && !previous->layoutObject()) | 96 while (previous && !previous->layoutObject()) |
75 previous = ElementTraversal::pseudoAwarePreviousSibling(*previous); | 97 previous = ElementTraversal::pseudoAwarePreviousSibling(*previous); |
76 if (previous) | 98 if (previous) |
77 return previous->layoutObject(); | 99 return previous->layoutObject(); |
78 previous = self->parentElement(); | 100 previous = self->parentElement(); |
79 return previous ? previous->layoutObject() : 0; | 101 return previous && previous->layoutObject() && !(previous->layoutObject()->s
tyle()->contain() & ContainsStyle) ? previous->layoutObject() : nullptr; |
80 } | 102 } |
81 | 103 |
82 static inline Element* parentElement(LayoutObject& object) | 104 static inline Element* parentElement(LayoutObject& object) |
83 { | 105 { |
84 return toElement(object.node())->parentElement(); | 106 return toElement(object.node())->parentElement(); |
85 } | 107 } |
86 | 108 |
87 static inline bool areLayoutObjectsElementsSiblings(LayoutObject& first, LayoutO
bject& second) | 109 static inline bool areLayoutObjectsElementsSiblings(LayoutObject& first, LayoutO
bject& second) |
88 { | 110 { |
89 return parentElement(first) == parentElement(second); | 111 return parentElement(first) == parentElement(second); |
90 } | 112 } |
91 | 113 |
92 // This function processes the layoutObject tree in the order of the DOM tree | 114 // This function processes the layoutObject tree in the order of the DOM tree |
93 // including pseudo elements as defined in CSS 2.1. | 115 // including pseudo elements as defined in CSS 2.1. |
94 static LayoutObject* nextInPreOrder(const LayoutObject& object, const Element* s
tayWithin, bool skipDescendants = false) | 116 static LayoutObject* nextInPreOrder(const LayoutObject& object, const Element* s
tayWithin, bool skipDescendants = false) |
95 { | 117 { |
96 Element* self = toElement(object.node()); | 118 Element* self = toElement(object.node()); |
97 ASSERT(self); | 119 ASSERT(self); |
98 Element* next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkipp
ingChildren(*self, stayWithin) : ElementTraversal::nextIncludingPseudo(*self, st
ayWithin); | 120 Element* next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkipp
ingChildren(*self, stayWithin) : ElementTraversal::nextIncludingPseudo(*self, st
ayWithin); |
99 while (next && !next->layoutObject()) | 121 while (next && !next->layoutObject()) |
100 next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingCh
ildren(*next, stayWithin) : ElementTraversal::nextIncludingPseudo(*next, stayWit
hin); | 122 next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingCh
ildren(*next, stayWithin) : ElementTraversal::nextIncludingPseudo(*next, stayWit
hin); |
101 return next ? next->layoutObject() : 0; | 123 return next ? next->layoutObject() : nullptr; |
102 } | 124 } |
103 | 125 |
104 static bool planCounter(LayoutObject& object, const AtomicString& identifier, bo
ol& isReset, int& value) | 126 static bool planCounter(LayoutObject& object, const AtomicString& identifier, bo
ol& isReset, int& value) |
105 { | 127 { |
106 // Real text nodes don't have their own style so they can't have counters. | 128 // Real text nodes don't have their own style so they can't have counters. |
107 // We can't even look at their styles or we'll see extra resets and incremen
ts! | 129 // We can't even look at their styles or we'll see extra resets and incremen
ts! |
108 if (object.isText() && !object.isBR()) | 130 if (object.isText() && !object.isBR()) |
109 return false; | 131 return false; |
110 Node* generatingNode = object.generatingNode(); | 132 Node* generatingNode = object.generatingNode(); |
111 // We must have a generating node or else we cannot have a counter. | 133 // We must have a generating node or else we cannot have a counter. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // - The root of the tree is always a reset type reference. | 197 // - The root of the tree is always a reset type reference. |
176 // - A subtree rooted at any reset node in the tree is equivalent to all counter | 198 // - A subtree rooted at any reset node in the tree is equivalent to all counter |
177 // references that are in the scope of the counter or nested counter defined by
that | 199 // references that are in the scope of the counter or nested counter defined by
that |
178 // reset node. | 200 // reset node. |
179 // - Non-reset CounterNodes cannot have descendants. | 201 // - Non-reset CounterNodes cannot have descendants. |
180 | 202 |
181 static bool findPlaceForCounter(LayoutObject& counterOwner, const AtomicString&
identifier, bool isReset, RefPtr<CounterNode>& parent, RefPtr<CounterNode>& prev
iousSibling) | 203 static bool findPlaceForCounter(LayoutObject& counterOwner, const AtomicString&
identifier, bool isReset, RefPtr<CounterNode>& parent, RefPtr<CounterNode>& prev
iousSibling) |
182 { | 204 { |
183 // We cannot stop searching for counters with the same identifier before we
also | 205 // We cannot stop searching for counters with the same identifier before we
also |
184 // check this layoutObject, because it may affect the positioning in the tre
e of our counter. | 206 // check this layoutObject, because it may affect the positioning in the tre
e of our counter. |
185 LayoutObject* searchEndLayoutObject = previousSiblingOrParent(counterOwner); | 207 LayoutObject* searchEndLayoutObject = previousSiblingOrParentRespectingConta
inment(counterOwner); |
186 // We check layoutObjects in preOrder from the layoutObject that our counter
is attached to | 208 // We check layoutObjects in preOrder from the layoutObject that our counter
is attached to |
187 // towards the beginning of the document for counters with the same identifi
er as the one | 209 // towards the beginning of the document for counters with the same identifi
er as the one |
188 // we are trying to find a place for. This is the next layoutObject to be ch
ecked. | 210 // we are trying to find a place for. This is the next layoutObject to be ch
ecked. |
189 LayoutObject* currentLayoutObject = previousInPreOrder(counterOwner); | 211 LayoutObject* currentLayoutObject = previousInPreOrderRespectingContainment(
counterOwner); |
190 previousSibling = nullptr; | 212 previousSibling = nullptr; |
191 RefPtr<CounterNode> previousSiblingProtector = nullptr; | 213 RefPtr<CounterNode> previousSiblingProtector = nullptr; |
192 | 214 |
193 while (currentLayoutObject) { | 215 while (currentLayoutObject) { |
194 CounterNode* currentCounter = makeCounterNode(*currentLayoutObject, iden
tifier, false); | 216 CounterNode* currentCounter = makeCounterNodeIfNeeded(*currentLayoutObje
ct, identifier, false); |
195 if (searchEndLayoutObject == currentLayoutObject) { | 217 if (searchEndLayoutObject == currentLayoutObject) { |
196 // We may be at the end of our search. | 218 // We may be at the end of our search. |
197 if (currentCounter) { | 219 if (currentCounter) { |
198 // We have a suitable counter on the EndSearchLayoutObject. | 220 // We have a suitable counter on the EndSearchLayoutObject. |
199 if (previousSiblingProtector) { // But we already found another
counter that we come after. | 221 if (previousSiblingProtector) { // But we already found another
counter that we come after. |
200 if (currentCounter->actsAsReset()) { | 222 if (currentCounter->actsAsReset()) { |
201 // We found a reset counter that is on a layoutObject th
at is a sibling of ours or a parent. | 223 // We found a reset counter that is on a layoutObject th
at is a sibling of ours or a parent. |
202 if (isReset && areLayoutObjectsElementsSiblings(*current
LayoutObject, counterOwner)) { | 224 if (isReset && areLayoutObjectsElementsSiblings(*current
LayoutObject, counterOwner)) { |
203 // We are also a reset counter and the previous rese
t was on a sibling layoutObject | 225 // We are also a reset counter and the previous rese
t was on a sibling layoutObject |
204 // hence we are the next sibling of that counter if
that reset is not a root or | 226 // hence we are the next sibling of that counter if
that reset is not a root or |
205 // we are a root node if that reset is a root. | 227 // we are a root node if that reset is a root. |
206 parent = currentCounter->parent(); | 228 parent = currentCounter->parent(); |
207 previousSibling = parent ? currentCounter : 0; | 229 previousSibling = parent ? currentCounter : nullptr; |
208 return parent; | 230 return parent; |
209 } | 231 } |
210 // We are not a reset node or the previous reset must be
on an ancestor of our owner layoutObject | 232 // We are not a reset node or the previous reset must be
on an ancestor of our owner layoutObject |
211 // hence we must be a child of that reset counter. | 233 // hence we must be a child of that reset counter. |
212 parent = currentCounter; | 234 parent = currentCounter; |
213 // In some cases layoutObjects can be reparented (ex. no
des inside a table but not in a column or row). | 235 // In some cases layoutObjects can be reparented (ex. no
des inside a table but not in a column or row). |
214 // In these cases the identified previousSibling will be
invalid as its parent is different from | 236 // In these cases the identified previousSibling will be
invalid as its parent is different from |
215 // our identified parent. | 237 // our identified parent. |
216 if (previousSiblingProtector->parent() != currentCounter
) | 238 if (previousSiblingProtector->parent() != currentCounter
) |
217 previousSiblingProtector = nullptr; | 239 previousSiblingProtector = nullptr; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 previousSibling = currentCounter; | 272 previousSibling = currentCounter; |
251 return true; | 273 return true; |
252 } | 274 } |
253 previousSiblingProtector = currentCounter; | 275 previousSiblingProtector = currentCounter; |
254 } | 276 } |
255 } | 277 } |
256 // We come here if the previous sibling or parent of our owner layou
tObject had no | 278 // We come here if the previous sibling or parent of our owner layou
tObject had no |
257 // good counter, or we are a reset node and the counter on the previ
ous sibling | 279 // good counter, or we are a reset node and the counter on the previ
ous sibling |
258 // of our owner layoutObject was not a reset counter. | 280 // of our owner layoutObject was not a reset counter. |
259 // Set a new goal for the end of the search. | 281 // Set a new goal for the end of the search. |
260 searchEndLayoutObject = previousSiblingOrParent(*currentLayoutObject
); | 282 searchEndLayoutObject = previousSiblingOrParentRespectingContainment
(*currentLayoutObject); |
261 } else { | 283 } else { |
262 // We are searching descendants of a previous sibling of the layoutO
bject that the | 284 // We are searching descendants of a previous sibling of the layoutO
bject that the |
263 // counter being placed is attached to. | 285 // counter being placed is attached to. |
264 if (currentCounter) { | 286 if (currentCounter) { |
265 // We found a suitable counter. | 287 // We found a suitable counter. |
266 if (previousSiblingProtector) { | 288 if (previousSiblingProtector) { |
267 // Since we had a suitable previous counter before, we shoul
d only consider this one as our | 289 // Since we had a suitable previous counter before, we shoul
d only consider this one as our |
268 // previousSibling if it is a reset counter and hence the cu
rrent previousSibling is its child. | 290 // previousSibling if it is a reset counter and hence the cu
rrent previousSibling is its child. |
269 if (currentCounter->actsAsReset()) { | 291 if (currentCounter->actsAsReset()) { |
270 previousSiblingProtector = currentCounter; | 292 previousSiblingProtector = currentCounter; |
271 // We are no longer interested in previous siblings of t
he currentLayoutObject or their children | 293 // We are no longer interested in previous siblings of t
he currentLayoutObject or their children |
272 // as counters they may have attached cannot be the prev
ious sibling of the counter we are placing. | 294 // as counters they may have attached cannot be the prev
ious sibling of the counter we are placing. |
273 Element* parent = parentElement(*currentLayoutObject); | 295 Element* parent = parentElement(*currentLayoutObject); |
274 currentLayoutObject = parent ? parent->layoutObject() :
nullptr; | 296 currentLayoutObject = parent ? parent->layoutObject() :
nullptr; |
275 continue; | 297 continue; |
276 } | 298 } |
277 } else { | 299 } else { |
278 previousSiblingProtector = currentCounter; | 300 previousSiblingProtector = currentCounter; |
279 } | 301 } |
280 currentLayoutObject = previousSiblingOrParent(*currentLayoutObje
ct); | 302 currentLayoutObject = previousSiblingOrParentRespectingContainme
nt(*currentLayoutObject); |
281 continue; | 303 continue; |
282 } | 304 } |
283 } | 305 } |
284 // This function is designed so that the same test is not done twice in
an iteration, except for this one | 306 // This function is designed so that the same test is not done twice in
an iteration, except for this one |
285 // which may be done twice in some cases. Rearranging the decision point
s though, to accommodate this | 307 // which may be done twice in some cases. Rearranging the decision point
s though, to accommodate this |
286 // performance improvement would create more code duplication than is wo
rthwhile in my opinion and may further | 308 // performance improvement would create more code duplication than is wo
rthwhile in my opinion and may further |
287 // impede the readability of this already complex algorithm. | 309 // impede the readability of this already complex algorithm. |
288 if (previousSiblingProtector) | 310 if (previousSiblingProtector) |
289 currentLayoutObject = previousSiblingOrParent(*currentLayoutObject); | 311 currentLayoutObject = previousSiblingOrParentRespectingContainment(*
currentLayoutObject); |
290 else | 312 else |
291 currentLayoutObject = previousInPreOrder(*currentLayoutObject); | 313 currentLayoutObject = previousInPreOrderRespectingContainment(*curre
ntLayoutObject); |
292 } | 314 } |
293 return false; | 315 return false; |
294 } | 316 } |
295 | 317 |
296 static CounterNode* makeCounterNode(LayoutObject& object, const AtomicString& id
entifier, bool alwaysCreateCounter) | 318 static CounterNode* makeCounterNodeIfNeeded(LayoutObject& object, const AtomicSt
ring& identifier, bool alwaysCreateCounter) |
297 { | 319 { |
298 if (object.hasCounterNodeMap()) { | 320 if (object.hasCounterNodeMap()) { |
299 if (CounterMap* nodeMap = counterMaps().get(&object)) { | 321 if (CounterMap* nodeMap = counterMaps().get(&object)) { |
300 if (CounterNode* node = nodeMap->get(identifier)) | 322 if (CounterNode* node = nodeMap->get(identifier)) |
301 return node; | 323 return node; |
302 } | 324 } |
303 } | 325 } |
304 | 326 |
305 bool isReset = false; | 327 bool isReset = false; |
306 int value = 0; | 328 int value = 0; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 while (true) { | 398 while (true) { |
377 if (!beforeAfterContainer) | 399 if (!beforeAfterContainer) |
378 return nullptr; | 400 return nullptr; |
379 if (!beforeAfterContainer->isAnonymous() && !beforeAfterContainer->i
sPseudoElement()) | 401 if (!beforeAfterContainer->isAnonymous() && !beforeAfterContainer->i
sPseudoElement()) |
380 return nullptr; // LayoutCounters are restricted to before and a
fter pseudo elements | 402 return nullptr; // LayoutCounters are restricted to before and a
fter pseudo elements |
381 PseudoId containerStyle = beforeAfterContainer->style()->styleType()
; | 403 PseudoId containerStyle = beforeAfterContainer->style()->styleType()
; |
382 if ((containerStyle == BEFORE) || (containerStyle == AFTER)) | 404 if ((containerStyle == BEFORE) || (containerStyle == AFTER)) |
383 break; | 405 break; |
384 beforeAfterContainer = beforeAfterContainer->parent(); | 406 beforeAfterContainer = beforeAfterContainer->parent(); |
385 } | 407 } |
386 makeCounterNode(*beforeAfterContainer, m_counter.identifier(), true)->ad
dLayoutObject(const_cast<LayoutCounter*>(this)); | 408 makeCounterNodeIfNeeded(*beforeAfterContainer, m_counter.identifier(), t
rue)->addLayoutObject(const_cast<LayoutCounter*>(this)); |
387 ASSERT(m_counterNode); | 409 ASSERT(m_counterNode); |
388 } | 410 } |
389 CounterNode* child = m_counterNode; | 411 CounterNode* child = m_counterNode; |
390 int value = child->actsAsReset() ? child->value() : child->countInParent(); | 412 int value = child->actsAsReset() ? child->value() : child->countInParent(); |
391 | 413 |
392 String text = ListMarkerText::text(m_counter.listStyle(), value); | 414 String text = ListMarkerText::text(m_counter.listStyle(), value); |
393 | 415 |
394 if (!m_counter.separator().isNull()) { | 416 if (!m_counter.separator().isNull()) { |
395 if (!child->actsAsReset()) | 417 if (!child->actsAsReset()) |
396 child = child->parent(); | 418 child = child->parent(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 | 511 |
490 static void updateCounters(LayoutObject& layoutObject) | 512 static void updateCounters(LayoutObject& layoutObject) |
491 { | 513 { |
492 ASSERT(layoutObject.style()); | 514 ASSERT(layoutObject.style()); |
493 const CounterDirectiveMap* directiveMap = layoutObject.style()->counterDirec
tives(); | 515 const CounterDirectiveMap* directiveMap = layoutObject.style()->counterDirec
tives(); |
494 if (!directiveMap) | 516 if (!directiveMap) |
495 return; | 517 return; |
496 CounterDirectiveMap::const_iterator end = directiveMap->end(); | 518 CounterDirectiveMap::const_iterator end = directiveMap->end(); |
497 if (!layoutObject.hasCounterNodeMap()) { | 519 if (!layoutObject.hasCounterNodeMap()) { |
498 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it
!= end; ++it) | 520 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it
!= end; ++it) |
499 makeCounterNode(layoutObject, it->key, false); | 521 makeCounterNodeIfNeeded(layoutObject, it->key, false); |
500 return; | 522 return; |
501 } | 523 } |
502 CounterMap* counterMap = counterMaps().get(&layoutObject); | 524 CounterMap* counterMap = counterMaps().get(&layoutObject); |
503 ASSERT(counterMap); | 525 ASSERT(counterMap); |
504 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it != e
nd; ++it) { | 526 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it != e
nd; ++it) { |
505 RefPtr<CounterNode> node = counterMap->get(it->key); | 527 RefPtr<CounterNode> node = counterMap->get(it->key); |
506 if (!node) { | 528 if (!node) { |
507 makeCounterNode(layoutObject, it->key, false); | 529 makeCounterNodeIfNeeded(layoutObject, it->key, false); |
508 continue; | 530 continue; |
509 } | 531 } |
510 RefPtr<CounterNode> newParent = nullptr; | 532 RefPtr<CounterNode> newParent = nullptr; |
511 RefPtr<CounterNode> newPreviousSibling = nullptr; | 533 RefPtr<CounterNode> newPreviousSibling = nullptr; |
512 | 534 |
513 findPlaceForCounter(layoutObject, it->key, node->hasResetType(), newPare
nt, newPreviousSibling); | 535 findPlaceForCounter(layoutObject, it->key, node->hasResetType(), newPare
nt, newPreviousSibling); |
514 if (node != counterMap->get(it->key)) | 536 if (node != counterMap->get(it->key)) |
515 continue; | 537 continue; |
516 CounterNode* parent = node->parent(); | 538 CounterNode* parent = node->parent(); |
517 if (newParent == parent && newPreviousSibling == node->previousSibling()
) | 539 if (newParent == parent && newPreviousSibling == node->previousSibling()
) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 for (CounterDirectiveMap::const_iterator it = newCounterDirectives->
begin(); it != newMapEnd; ++it) { | 575 for (CounterDirectiveMap::const_iterator it = newCounterDirectives->
begin(); it != newMapEnd; ++it) { |
554 CounterDirectiveMap::const_iterator oldMapIt = oldCounterDirecti
ves->find(it->key); | 576 CounterDirectiveMap::const_iterator oldMapIt = oldCounterDirecti
ves->find(it->key); |
555 if (oldMapIt != oldMapEnd) { | 577 if (oldMapIt != oldMapEnd) { |
556 if (oldMapIt->value == it->value) | 578 if (oldMapIt->value == it->value) |
557 continue; | 579 continue; |
558 LayoutCounter::destroyCounterNode(layoutObject, it->key); | 580 LayoutCounter::destroyCounterNode(layoutObject, it->key); |
559 } | 581 } |
560 // We must create this node here, because the changed node may b
e a node with no display such as | 582 // We must create this node here, because the changed node may b
e a node with no display such as |
561 // as those created by the increment or reset directives and the
re-layout that will happen will | 583 // as those created by the increment or reset directives and the
re-layout that will happen will |
562 // not catch the change if the node had no children. | 584 // not catch the change if the node had no children. |
563 makeCounterNode(layoutObject, it->key, false); | 585 makeCounterNodeIfNeeded(layoutObject, it->key, false); |
564 } | 586 } |
565 // Destroying old counters that do not exist in the new counterDirec
tive map. | 587 // Destroying old counters that do not exist in the new counterDirec
tive map. |
566 for (CounterDirectiveMap::const_iterator it = oldCounterDirectives->
begin(); it !=oldMapEnd; ++it) { | 588 for (CounterDirectiveMap::const_iterator it = oldCounterDirectives->
begin(); it !=oldMapEnd; ++it) { |
567 if (!newCounterDirectives->contains(it->key)) | 589 if (!newCounterDirectives->contains(it->key)) |
568 LayoutCounter::destroyCounterNode(layoutObject, it->key); | 590 LayoutCounter::destroyCounterNode(layoutObject, it->key); |
569 } | 591 } |
570 } else { | 592 } else { |
571 if (layoutObject.hasCounterNodeMap()) | 593 if (layoutObject.hasCounterNodeMap()) |
572 LayoutCounter::destroyCounterNodes(layoutObject); | 594 LayoutCounter::destroyCounterNodes(layoutObject); |
573 } | 595 } |
574 } else if (newCounterDirectives) { | 596 } else if (newCounterDirectives) { |
575 if (layoutObject.hasCounterNodeMap()) | 597 if (layoutObject.hasCounterNodeMap()) |
576 LayoutCounter::destroyCounterNodes(layoutObject); | 598 LayoutCounter::destroyCounterNodes(layoutObject); |
577 CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives->en
d(); | 599 CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives->en
d(); |
578 for (CounterDirectiveMap::const_iterator it = newCounterDirectives->begi
n(); it != newMapEnd; ++it) { | 600 for (CounterDirectiveMap::const_iterator it = newCounterDirectives->begi
n(); it != newMapEnd; ++it) { |
579 // We must create this node here, because the added node may be a no
de with no display such as | 601 // We must create this node here, because the added node may be a no
de with no display such as |
580 // as those created by the increment or reset directives and the re-
layout that will happen will | 602 // as those created by the increment or reset directives and the re-
layout that will happen will |
581 // not catch the change if the node had no children. | 603 // not catch the change if the node had no children. |
582 makeCounterNode(layoutObject, it->key, false); | 604 makeCounterNodeIfNeeded(layoutObject, it->key, false); |
583 } | 605 } |
584 } | 606 } |
585 } | 607 } |
586 | 608 |
587 } // namespace blink | 609 } // namespace blink |
588 | 610 |
589 #ifndef NDEBUG | 611 #ifndef NDEBUG |
590 | 612 |
591 void showCounterLayoutObjectTree(const blink::LayoutObject* layoutObject, const
char* counterName) | 613 void showCounterLayoutObjectTree(const blink::LayoutObject* layoutObject, const
char* counterName) |
592 { | 614 { |
(...skipping 10 matching lines...) Expand all Loading... |
603 fprintf(stderr, " "); | 625 fprintf(stderr, " "); |
604 fprintf(stderr, "%p N:%p P:%p PS:%p NS:%p C:%p\n", | 626 fprintf(stderr, "%p N:%p P:%p PS:%p NS:%p C:%p\n", |
605 current, current->node(), current->parent(), current->previousSiblin
g(), | 627 current, current->node(), current->parent(), current->previousSiblin
g(), |
606 current->nextSibling(), current->hasCounterNodeMap() ? | 628 current->nextSibling(), current->hasCounterNodeMap() ? |
607 counterName ? blink::counterMaps().get(current)->get(identifier) : (
blink::CounterNode*)1 : (blink::CounterNode*)0); | 629 counterName ? blink::counterMaps().get(current)->get(identifier) : (
blink::CounterNode*)1 : (blink::CounterNode*)0); |
608 } | 630 } |
609 fflush(stderr); | 631 fflush(stderr); |
610 } | 632 } |
611 | 633 |
612 #endif // NDEBUG | 634 #endif // NDEBUG |
OLD | NEW |