Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 37 #include <stdio.h> | 37 #include <stdio.h> |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 using namespace HTMLNames; | 42 using namespace HTMLNames; |
| 43 | 43 |
| 44 typedef HashMap<AtomicString, RefPtr<CounterNode>> CounterMap; | 44 typedef HashMap<AtomicString, RefPtr<CounterNode>> CounterMap; |
| 45 typedef HashMap<const LayoutObject*, OwnPtr<CounterMap>> CounterMaps; | 45 typedef HashMap<const LayoutObject*, OwnPtr<CounterMap>> CounterMaps; |
| 46 | 46 |
| 47 static CounterNode* makeCounterNode(LayoutObject&, const AtomicString& identifie r, bool alwaysCreateCounter); | 47 static CounterNode* makeCounterNodeIfNeeded(LayoutObject&, const AtomicString& i dentifier, bool alwaysCreateCounter); |
| 48 | 48 |
| 49 // See class definition as to why we have this map. | 49 // See class definition as to why we have this map. |
| 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 LayoutObject* ancestorStyleContainmentObject(const LayoutObject& object) | |
|
esprehn
2016/01/20 08:33:01
static
| |
| 57 { | |
| 58 for (LayoutObject* ancestor = object.parent(); ancestor; ancestor = ancestor ->parent()) { | |
|
esprehn
2016/01/20 08:33:01
I don't think this is right, this is walking the l
| |
| 59 if (ancestor->style()->containsStyle()) | |
| 60 return ancestor; | |
| 61 } | |
| 62 return nullptr; | |
| 63 } | |
| 64 | |
| 56 // This function processes the layoutObject tree in the order of the DOM tree | 65 // This function processes the layoutObject tree in the order of the DOM tree |
| 57 // including pseudo elements as defined in CSS 2.1. | 66 // including pseudo elements as defined in CSS 2.1. This method will always retu rn |
| 58 static LayoutObject* previousInPreOrder(const LayoutObject& object) | 67 // either a previous object within the same contain: style scope or nullptr. |
| 68 static LayoutObject* previousInPreOrderRespectingContainment(const LayoutObject& object) | |
| 59 { | 69 { |
| 60 Element* self = toElement(object.node()); | 70 Element* self = toElement(object.node()); |
| 61 ASSERT(self); | 71 ASSERT(self); |
| 62 Element* previous = ElementTraversal::previousIncludingPseudo(*self); | 72 Element* previous = ElementTraversal::previousIncludingPseudo(*self); |
| 63 while (previous && !previous->layoutObject()) | 73 LayoutObject* styleContainAncestor = ancestorStyleContainmentObject(object); |
| 64 previous = ElementTraversal::previousIncludingPseudo(*previous); | 74 |
| 65 return previous ? previous->layoutObject() : 0; | 75 while (1) { |
| 76 while (previous && !previous->layoutObject()) | |
| 77 previous = ElementTraversal::previousIncludingPseudo(*previous); | |
| 78 if (!previous) | |
| 79 return nullptr; | |
| 80 LayoutObject* previousStyleContainAncestor = ancestorStyleContainmentObj ect(*previous->layoutObject()); | |
| 81 if (previousStyleContainAncestor == styleContainAncestor) | |
| 82 return previous->layoutObject(); | |
| 83 if (!previousStyleContainAncestor) | |
| 84 return nullptr; | |
| 85 previous = toElement(previousStyleContainAncestor->node()); | |
| 86 } | |
| 66 } | 87 } |
| 67 | 88 |
| 68 // This function processes the layoutObject tree in the order of the DOM tree | 89 // This function processes the layoutObject tree in the order of the DOM tree |
| 69 // including pseudo elements as defined in CSS 2.1. | 90 // including pseudo elements as defined in CSS 2.1. This method avoids crossing |
| 70 static LayoutObject* previousSiblingOrParent(const LayoutObject& object) | 91 // contain: style boundaries. |
| 92 static LayoutObject* previousSiblingOrParentRespectingContainment(const LayoutOb ject& object) | |
| 71 { | 93 { |
| 72 Element* self = toElement(object.node()); | 94 Element* self = toElement(object.node()); |
| 73 ASSERT(self); | 95 ASSERT(self); |
| 74 Element* previous = ElementTraversal::pseudoAwarePreviousSibling(*self); | 96 Element* previous = ElementTraversal::pseudoAwarePreviousSibling(*self); |
| 75 while (previous && !previous->layoutObject()) | 97 while (previous && !previous->layoutObject()) |
| 76 previous = ElementTraversal::pseudoAwarePreviousSibling(*previous); | 98 previous = ElementTraversal::pseudoAwarePreviousSibling(*previous); |
| 77 if (previous) | 99 if (previous) |
| 78 return previous->layoutObject(); | 100 return previous->layoutObject(); |
| 79 previous = self->parentElement(); | 101 previous = self->parentElement(); |
| 80 return previous ? previous->layoutObject() : 0; | 102 return previous && previous->layoutObject() && !(previous->layoutObject()->s tyle()->contain() & ContainsStyle) ? previous->layoutObject() : nullptr; |
| 81 } | 103 } |
| 82 | 104 |
| 83 static inline Element* parentElement(LayoutObject& object) | 105 static inline Element* parentElement(LayoutObject& object) |
| 84 { | 106 { |
| 85 return toElement(object.node())->parentElement(); | 107 return toElement(object.node())->parentElement(); |
| 86 } | 108 } |
| 87 | 109 |
| 88 static inline bool areLayoutObjectsElementsSiblings(LayoutObject& first, LayoutO bject& second) | 110 static inline bool areLayoutObjectsElementsSiblings(LayoutObject& first, LayoutO bject& second) |
| 89 { | 111 { |
| 90 return parentElement(first) == parentElement(second); | 112 return parentElement(first) == parentElement(second); |
| 91 } | 113 } |
| 92 | 114 |
| 93 // This function processes the layoutObject tree in the order of the DOM tree | 115 // This function processes the layoutObject tree in the order of the DOM tree |
| 94 // including pseudo elements as defined in CSS 2.1. | 116 // including pseudo elements as defined in CSS 2.1. |
| 95 static LayoutObject* nextInPreOrder(const LayoutObject& object, const Element* s tayWithin, bool skipDescendants = false) | 117 static LayoutObject* nextInPreOrder(const LayoutObject& object, const Element* s tayWithin, bool skipDescendants = false) |
| 96 { | 118 { |
| 97 Element* self = toElement(object.node()); | 119 Element* self = toElement(object.node()); |
| 98 ASSERT(self); | 120 ASSERT(self); |
| 99 Element* next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkipp ingChildren(*self, stayWithin) : ElementTraversal::nextIncludingPseudo(*self, st ayWithin); | 121 Element* next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkipp ingChildren(*self, stayWithin) : ElementTraversal::nextIncludingPseudo(*self, st ayWithin); |
| 100 while (next && !next->layoutObject()) | 122 while (next && !next->layoutObject()) |
| 101 next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingCh ildren(*next, stayWithin) : ElementTraversal::nextIncludingPseudo(*next, stayWit hin); | 123 next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingCh ildren(*next, stayWithin) : ElementTraversal::nextIncludingPseudo(*next, stayWit hin); |
| 102 return next ? next->layoutObject() : 0; | 124 return next ? next->layoutObject() : nullptr; |
| 103 } | 125 } |
| 104 | 126 |
| 105 static bool planCounter(LayoutObject& object, const AtomicString& identifier, bo ol& isReset, int& value) | 127 static bool planCounter(LayoutObject& object, const AtomicString& identifier, bo ol& isReset, int& value) |
| 106 { | 128 { |
| 107 // Real text nodes don't have their own style so they can't have counters. | 129 // Real text nodes don't have their own style so they can't have counters. |
| 108 // We can't even look at their styles or we'll see extra resets and incremen ts! | 130 // We can't even look at their styles or we'll see extra resets and incremen ts! |
| 109 if (object.isText() && !object.isBR()) | 131 if (object.isText() && !object.isBR()) |
| 110 return false; | 132 return false; |
| 111 Node* generatingNode = object.generatingNode(); | 133 Node* generatingNode = object.generatingNode(); |
| 112 // We must have a generating node or else we cannot have a counter. | 134 // 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... | |
| 176 // - The root of the tree is always a reset type reference. | 198 // - The root of the tree is always a reset type reference. |
| 177 // - A subtree rooted at any reset node in the tree is equivalent to all counter | 199 // - A subtree rooted at any reset node in the tree is equivalent to all counter |
| 178 // references that are in the scope of the counter or nested counter defined by that | 200 // references that are in the scope of the counter or nested counter defined by that |
| 179 // reset node. | 201 // reset node. |
| 180 // - Non-reset CounterNodes cannot have descendants. | 202 // - Non-reset CounterNodes cannot have descendants. |
| 181 | 203 |
| 182 static bool findPlaceForCounter(LayoutObject& counterOwner, const AtomicString& identifier, bool isReset, RefPtr<CounterNode>& parent, RefPtr<CounterNode>& prev iousSibling) | 204 static bool findPlaceForCounter(LayoutObject& counterOwner, const AtomicString& identifier, bool isReset, RefPtr<CounterNode>& parent, RefPtr<CounterNode>& prev iousSibling) |
| 183 { | 205 { |
| 184 // We cannot stop searching for counters with the same identifier before we also | 206 // We cannot stop searching for counters with the same identifier before we also |
| 185 // check this layoutObject, because it may affect the positioning in the tre e of our counter. | 207 // check this layoutObject, because it may affect the positioning in the tre e of our counter. |
| 186 LayoutObject* searchEndLayoutObject = previousSiblingOrParent(counterOwner); | 208 LayoutObject* searchEndLayoutObject = previousSiblingOrParentRespectingConta inment(counterOwner); |
| 187 // We check layoutObjects in preOrder from the layoutObject that our counter is attached to | 209 // We check layoutObjects in preOrder from the layoutObject that our counter is attached to |
| 188 // towards the begining of the document for counters with the same identifie r as the one | 210 // towards the begining of the document for counters with the same identifie r as the one |
| 189 // we are trying to find a place for. This is the next layoutObject to be ch ecked. | 211 // we are trying to find a place for. This is the next layoutObject to be ch ecked. |
| 190 LayoutObject* currentLayoutObject = previousInPreOrder(counterOwner); | 212 LayoutObject* currentLayoutObject = previousInPreOrderRespectingContainment( counterOwner); |
| 191 previousSibling = nullptr; | 213 previousSibling = nullptr; |
| 192 RefPtr<CounterNode> previousSiblingProtector = nullptr; | 214 RefPtr<CounterNode> previousSiblingProtector = nullptr; |
| 193 | 215 |
| 194 while (currentLayoutObject) { | 216 while (currentLayoutObject) { |
| 195 CounterNode* currentCounter = makeCounterNode(*currentLayoutObject, iden tifier, false); | 217 CounterNode* currentCounter = makeCounterNodeIfNeeded(*currentLayoutObje ct, identifier, false); |
| 196 if (searchEndLayoutObject == currentLayoutObject) { | 218 if (searchEndLayoutObject == currentLayoutObject) { |
| 197 // We may be at the end of our search. | 219 // We may be at the end of our search. |
| 198 if (currentCounter) { | 220 if (currentCounter) { |
| 199 // We have a suitable counter on the EndSearchLayoutObject. | 221 // We have a suitable counter on the EndSearchLayoutObject. |
| 200 if (previousSiblingProtector) { // But we already found another counter that we come after. | 222 if (previousSiblingProtector) { // But we already found another counter that we come after. |
| 201 if (currentCounter->actsAsReset()) { | 223 if (currentCounter->actsAsReset()) { |
| 202 // We found a reset counter that is on a layoutObject th at is a sibling of ours or a parent. | 224 // We found a reset counter that is on a layoutObject th at is a sibling of ours or a parent. |
| 203 if (isReset && areLayoutObjectsElementsSiblings(*current LayoutObject, counterOwner)) { | 225 if (isReset && areLayoutObjectsElementsSiblings(*current LayoutObject, counterOwner)) { |
| 204 // We are also a reset counter and the previous rese t was on a sibling layoutObject | 226 // We are also a reset counter and the previous rese t was on a sibling layoutObject |
| 205 // hence we are the next sibling of that counter if that reset is not a root or | 227 // hence we are the next sibling of that counter if that reset is not a root or |
| 206 // we are a root node if that reset is a root. | 228 // we are a root node if that reset is a root. |
| 207 parent = currentCounter->parent(); | 229 parent = currentCounter->parent(); |
| 208 previousSibling = parent ? currentCounter : 0; | 230 previousSibling = parent ? currentCounter : nullptr; |
| 209 return parent; | 231 return parent; |
| 210 } | 232 } |
| 211 // We are not a reset node or the previous reset must be on an ancestor of our owner layoutObject | 233 // We are not a reset node or the previous reset must be on an ancestor of our owner layoutObject |
| 212 // hence we must be a child of that reset counter. | 234 // hence we must be a child of that reset counter. |
| 213 parent = currentCounter; | 235 parent = currentCounter; |
| 214 // In some cases layoutObjects can be reparented (ex. no des inside a table but not in a column or row). | 236 // In some cases layoutObjects can be reparented (ex. no des inside a table but not in a column or row). |
| 215 // In these cases the identified previousSibling will be invalid as its parent is different from | 237 // In these cases the identified previousSibling will be invalid as its parent is different from |
| 216 // our identified parent. | 238 // our identified parent. |
| 217 if (previousSiblingProtector->parent() != currentCounter ) | 239 if (previousSiblingProtector->parent() != currentCounter ) |
| 218 previousSiblingProtector = nullptr; | 240 previousSiblingProtector = nullptr; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 previousSibling = currentCounter; | 273 previousSibling = currentCounter; |
| 252 return true; | 274 return true; |
| 253 } | 275 } |
| 254 previousSiblingProtector = currentCounter; | 276 previousSiblingProtector = currentCounter; |
| 255 } | 277 } |
| 256 } | 278 } |
| 257 // We come here if the previous sibling or parent of our owner layou tObject had no | 279 // We come here if the previous sibling or parent of our owner layou tObject had no |
| 258 // good counter, or we are a reset node and the counter on the previ ous sibling | 280 // good counter, or we are a reset node and the counter on the previ ous sibling |
| 259 // of our owner layoutObject was not a reset counter. | 281 // of our owner layoutObject was not a reset counter. |
| 260 // Set a new goal for the end of the search. | 282 // Set a new goal for the end of the search. |
| 261 searchEndLayoutObject = previousSiblingOrParent(*currentLayoutObject ); | 283 searchEndLayoutObject = previousSiblingOrParentRespectingContainment (*currentLayoutObject); |
| 262 } else { | 284 } else { |
| 263 // We are searching descendants of a previous sibling of the layoutO bject that the | 285 // We are searching descendants of a previous sibling of the layoutO bject that the |
| 264 // counter being placed is attached to. | 286 // counter being placed is attached to. |
| 265 if (currentCounter) { | 287 if (currentCounter) { |
| 266 // We found a suitable counter. | 288 // We found a suitable counter. |
| 267 if (previousSiblingProtector) { | 289 if (previousSiblingProtector) { |
| 268 // Since we had a suitable previous counter before, we shoul d only consider this one as our | 290 // Since we had a suitable previous counter before, we shoul d only consider this one as our |
| 269 // previousSibling if it is a reset counter and hence the cu rrent previousSibling is its child. | 291 // previousSibling if it is a reset counter and hence the cu rrent previousSibling is its child. |
| 270 if (currentCounter->actsAsReset()) { | 292 if (currentCounter->actsAsReset()) { |
| 271 previousSiblingProtector = currentCounter; | 293 previousSiblingProtector = currentCounter; |
| 272 // We are no longer interested in previous siblings of t he currentLayoutObject or their children | 294 // We are no longer interested in previous siblings of t he currentLayoutObject or their children |
| 273 // as counters they may have attached cannot be the prev ious sibling of the counter we are placing. | 295 // as counters they may have attached cannot be the prev ious sibling of the counter we are placing. |
| 274 currentLayoutObject = parentElement(*currentLayoutObject )->layoutObject(); | 296 currentLayoutObject = parentElement(*currentLayoutObject )->layoutObject(); |
| 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 oppinion 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 |