| 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 #ifndef NDEBUG | 36 #ifndef NDEBUG |
| 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 RenderObject*, OwnPtr<CounterMap> > CounterMaps; | 45 typedef HashMap<const LayoutObject*, OwnPtr<CounterMap>> CounterMaps; |
| 46 | 46 |
| 47 static CounterNode* makeCounterNode(RenderObject&, const AtomicString& identifie
r, bool alwaysCreateCounter); | 47 static CounterNode* makeCounterNode(LayoutObject&, const AtomicString& identifie
r, bool alwaysCreateCounter); |
| 48 | 48 |
| 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 // This function processes the renderer tree in the order of the DOM tree | 55 // This function processes the renderer tree in the order of the DOM tree |
| 56 // including pseudo elements as defined in CSS 2.1. | 56 // including pseudo elements as defined in CSS 2.1. |
| 57 static RenderObject* previousInPreOrder(const RenderObject& object) | 57 static LayoutObject* previousInPreOrder(const LayoutObject& object) |
| 58 { | 58 { |
| 59 Element* self = toElement(object.node()); | 59 Element* self = toElement(object.node()); |
| 60 ASSERT(self); | 60 ASSERT(self); |
| 61 Element* previous = ElementTraversal::previousIncludingPseudo(*self); | 61 Element* previous = ElementTraversal::previousIncludingPseudo(*self); |
| 62 while (previous && !previous->renderer()) | 62 while (previous && !previous->renderer()) |
| 63 previous = ElementTraversal::previousIncludingPseudo(*previous); | 63 previous = ElementTraversal::previousIncludingPseudo(*previous); |
| 64 return previous ? previous->renderer() : 0; | 64 return previous ? previous->renderer() : 0; |
| 65 } | 65 } |
| 66 | 66 |
| 67 // This function processes the renderer tree in the order of the DOM tree | 67 // This function processes the renderer tree in the order of the DOM tree |
| 68 // including pseudo elements as defined in CSS 2.1. | 68 // including pseudo elements as defined in CSS 2.1. |
| 69 static RenderObject* previousSiblingOrParent(const RenderObject& object) | 69 static LayoutObject* previousSiblingOrParent(const LayoutObject& object) |
| 70 { | 70 { |
| 71 Element* self = toElement(object.node()); | 71 Element* self = toElement(object.node()); |
| 72 ASSERT(self); | 72 ASSERT(self); |
| 73 Element* previous = ElementTraversal::pseudoAwarePreviousSibling(*self); | 73 Element* previous = ElementTraversal::pseudoAwarePreviousSibling(*self); |
| 74 while (previous && !previous->renderer()) | 74 while (previous && !previous->renderer()) |
| 75 previous = ElementTraversal::pseudoAwarePreviousSibling(*previous); | 75 previous = ElementTraversal::pseudoAwarePreviousSibling(*previous); |
| 76 if (previous) | 76 if (previous) |
| 77 return previous->renderer(); | 77 return previous->renderer(); |
| 78 previous = self->parentElement(); | 78 previous = self->parentElement(); |
| 79 return previous ? previous->renderer() : 0; | 79 return previous ? previous->renderer() : 0; |
| 80 } | 80 } |
| 81 | 81 |
| 82 static inline Element* parentElement(RenderObject& object) | 82 static inline Element* parentElement(LayoutObject& object) |
| 83 { | 83 { |
| 84 return toElement(object.node())->parentElement(); | 84 return toElement(object.node())->parentElement(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 static inline bool areRenderersElementsSiblings(RenderObject& first, RenderObjec
t& second) | 87 static inline bool areRenderersElementsSiblings(LayoutObject& first, LayoutObjec
t& second) |
| 88 { | 88 { |
| 89 return parentElement(first) == parentElement(second); | 89 return parentElement(first) == parentElement(second); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // This function processes the renderer tree in the order of the DOM tree | 92 // This function processes the renderer tree in the order of the DOM tree |
| 93 // including pseudo elements as defined in CSS 2.1. | 93 // including pseudo elements as defined in CSS 2.1. |
| 94 static RenderObject* nextInPreOrder(const RenderObject& object, const Element* s
tayWithin, bool skipDescendants = false) | 94 static LayoutObject* nextInPreOrder(const LayoutObject& object, const Element* s
tayWithin, bool skipDescendants = false) |
| 95 { | 95 { |
| 96 Element* self = toElement(object.node()); | 96 Element* self = toElement(object.node()); |
| 97 ASSERT(self); | 97 ASSERT(self); |
| 98 Element* next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkipp
ingChildren(*self, stayWithin) : ElementTraversal::nextIncludingPseudo(*self, st
ayWithin); | 98 Element* next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkipp
ingChildren(*self, stayWithin) : ElementTraversal::nextIncludingPseudo(*self, st
ayWithin); |
| 99 while (next && !next->renderer()) | 99 while (next && !next->renderer()) |
| 100 next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingCh
ildren(*next, stayWithin) : ElementTraversal::nextIncludingPseudo(*next, stayWit
hin); | 100 next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingCh
ildren(*next, stayWithin) : ElementTraversal::nextIncludingPseudo(*next, stayWit
hin); |
| 101 return next ? next->renderer() : 0; | 101 return next ? next->renderer() : 0; |
| 102 } | 102 } |
| 103 | 103 |
| 104 static bool planCounter(RenderObject& object, const AtomicString& identifier, bo
ol& isReset, int& value) | 104 static bool planCounter(LayoutObject& object, const AtomicString& identifier, bo
ol& isReset, int& value) |
| 105 { | 105 { |
| 106 // Real text nodes don't have their own style so they can't have counters. | 106 // 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! | 107 // We can't even look at their styles or we'll see extra resets and incremen
ts! |
| 108 if (object.isText() && !object.isBR()) | 108 if (object.isText() && !object.isBR()) |
| 109 return false; | 109 return false; |
| 110 Node* generatingNode = object.generatingNode(); | 110 Node* generatingNode = object.generatingNode(); |
| 111 // We must have a generating node or else we cannot have a counter. | 111 // We must have a generating node or else we cannot have a counter. |
| 112 if (!generatingNode) | 112 if (!generatingNode) |
| 113 return false; | 113 return false; |
| 114 RenderStyle* style = object.style(); | 114 RenderStyle* style = object.style(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // counter with the same identifier. | 172 // counter with the same identifier. |
| 173 // - All the counter references with the same identifier as this one that are in | 173 // - All the counter references with the same identifier as this one that are in |
| 174 // children or subsequent siblings of the renderer that owns the root of the tre
e | 174 // children or subsequent siblings of the renderer that owns the root of the tre
e |
| 175 // form the rest of of the nodes of the tree. | 175 // form the rest of of the nodes of the tree. |
| 176 // - The root of the tree is always a reset type reference. | 176 // - 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 | 177 // - 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 | 178 // references that are in the scope of the counter or nested counter defined by
that |
| 179 // reset node. | 179 // reset node. |
| 180 // - Non-reset CounterNodes cannot have descendants. | 180 // - Non-reset CounterNodes cannot have descendants. |
| 181 | 181 |
| 182 static bool findPlaceForCounter(RenderObject& counterOwner, const AtomicString&
identifier, bool isReset, RefPtr<CounterNode>& parent, RefPtr<CounterNode>& prev
iousSibling) | 182 static bool findPlaceForCounter(LayoutObject& counterOwner, const AtomicString&
identifier, bool isReset, RefPtr<CounterNode>& parent, RefPtr<CounterNode>& prev
iousSibling) |
| 183 { | 183 { |
| 184 // We cannot stop searching for counters with the same identifier before we
also | 184 // We cannot stop searching for counters with the same identifier before we
also |
| 185 // check this renderer, because it may affect the positioning in the tree of
our counter. | 185 // check this renderer, because it may affect the positioning in the tree of
our counter. |
| 186 RenderObject* searchEndRenderer = previousSiblingOrParent(counterOwner); | 186 LayoutObject* searchEndRenderer = previousSiblingOrParent(counterOwner); |
| 187 // We check renderers in preOrder from the renderer that our counter is atta
ched to | 187 // We check renderers in preOrder from the renderer that our counter is atta
ched to |
| 188 // towards the begining of the document for counters with the same identifie
r as the one | 188 // 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 renderer to be checke
d. | 189 // we are trying to find a place for. This is the next renderer to be checke
d. |
| 190 RenderObject* currentRenderer = previousInPreOrder(counterOwner); | 190 LayoutObject* currentRenderer = previousInPreOrder(counterOwner); |
| 191 previousSibling = nullptr; | 191 previousSibling = nullptr; |
| 192 RefPtr<CounterNode> previousSiblingProtector = nullptr; | 192 RefPtr<CounterNode> previousSiblingProtector = nullptr; |
| 193 | 193 |
| 194 while (currentRenderer) { | 194 while (currentRenderer) { |
| 195 CounterNode* currentCounter = makeCounterNode(*currentRenderer, identifi
er, false); | 195 CounterNode* currentCounter = makeCounterNode(*currentRenderer, identifi
er, false); |
| 196 if (searchEndRenderer == currentRenderer) { | 196 if (searchEndRenderer == currentRenderer) { |
| 197 // We may be at the end of our search. | 197 // We may be at the end of our search. |
| 198 if (currentCounter) { | 198 if (currentCounter) { |
| 199 // We have a suitable counter on the EndSearchRenderer. | 199 // We have a suitable counter on the EndSearchRenderer. |
| 200 if (previousSiblingProtector) { // But we already found another
counter that we come after. | 200 if (previousSiblingProtector) { // But we already found another
counter that we come after. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 // 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 |
| 287 // impede the readability of this already complex algorithm. | 287 // impede the readability of this already complex algorithm. |
| 288 if (previousSiblingProtector) | 288 if (previousSiblingProtector) |
| 289 currentRenderer = previousSiblingOrParent(*currentRenderer); | 289 currentRenderer = previousSiblingOrParent(*currentRenderer); |
| 290 else | 290 else |
| 291 currentRenderer = previousInPreOrder(*currentRenderer); | 291 currentRenderer = previousInPreOrder(*currentRenderer); |
| 292 } | 292 } |
| 293 return false; | 293 return false; |
| 294 } | 294 } |
| 295 | 295 |
| 296 static CounterNode* makeCounterNode(RenderObject& object, const AtomicString& id
entifier, bool alwaysCreateCounter) | 296 static CounterNode* makeCounterNode(LayoutObject& object, const AtomicString& id
entifier, bool alwaysCreateCounter) |
| 297 { | 297 { |
| 298 if (object.hasCounterNodeMap()) { | 298 if (object.hasCounterNodeMap()) { |
| 299 if (CounterMap* nodeMap = counterMaps().get(&object)) { | 299 if (CounterMap* nodeMap = counterMaps().get(&object)) { |
| 300 if (CounterNode* node = nodeMap->get(identifier)) | 300 if (CounterNode* node = nodeMap->get(identifier)) |
| 301 return node; | 301 return node; |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 | 304 |
| 305 bool isReset = false; | 305 bool isReset = false; |
| 306 int value = 0; | 306 int value = 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 321 object.setHasCounterNodeMap(true); | 321 object.setHasCounterNodeMap(true); |
| 322 } | 322 } |
| 323 nodeMap->set(identifier, newNode); | 323 nodeMap->set(identifier, newNode); |
| 324 if (newNode->parent()) | 324 if (newNode->parent()) |
| 325 return newNode.get(); | 325 return newNode.get(); |
| 326 // Checking if some nodes that were previously counter tree root nodes | 326 // Checking if some nodes that were previously counter tree root nodes |
| 327 // should become children of this node now. | 327 // should become children of this node now. |
| 328 CounterMaps& maps = counterMaps(); | 328 CounterMaps& maps = counterMaps(); |
| 329 Element* stayWithin = parentElement(object); | 329 Element* stayWithin = parentElement(object); |
| 330 bool skipDescendants; | 330 bool skipDescendants; |
| 331 for (RenderObject* currentRenderer = nextInPreOrder(object, stayWithin); cur
rentRenderer; currentRenderer = nextInPreOrder(*currentRenderer, stayWithin, ski
pDescendants)) { | 331 for (LayoutObject* currentRenderer = nextInPreOrder(object, stayWithin); cur
rentRenderer; currentRenderer = nextInPreOrder(*currentRenderer, stayWithin, ski
pDescendants)) { |
| 332 skipDescendants = false; | 332 skipDescendants = false; |
| 333 if (!currentRenderer->hasCounterNodeMap()) | 333 if (!currentRenderer->hasCounterNodeMap()) |
| 334 continue; | 334 continue; |
| 335 CounterNode* currentCounter = maps.get(currentRenderer)->get(identifier)
; | 335 CounterNode* currentCounter = maps.get(currentRenderer)->get(identifier)
; |
| 336 if (!currentCounter) | 336 if (!currentCounter) |
| 337 continue; | 337 continue; |
| 338 skipDescendants = true; | 338 skipDescendants = true; |
| 339 if (currentCounter->parent()) | 339 if (currentCounter->parent()) |
| 340 continue; | 340 continue; |
| 341 if (stayWithin == parentElement(*currentRenderer) && currentCounter->has
ResetType()) | 341 if (stayWithin == parentElement(*currentRenderer) && currentCounter->has
ResetType()) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 } | 375 } |
| 376 | 376 |
| 377 const char* LayoutCounter::renderName() const | 377 const char* LayoutCounter::renderName() const |
| 378 { | 378 { |
| 379 return "LayoutCounter"; | 379 return "LayoutCounter"; |
| 380 } | 380 } |
| 381 | 381 |
| 382 PassRefPtr<StringImpl> LayoutCounter::originalText() const | 382 PassRefPtr<StringImpl> LayoutCounter::originalText() const |
| 383 { | 383 { |
| 384 if (!m_counterNode) { | 384 if (!m_counterNode) { |
| 385 RenderObject* beforeAfterContainer = parent(); | 385 LayoutObject* beforeAfterContainer = parent(); |
| 386 while (true) { | 386 while (true) { |
| 387 if (!beforeAfterContainer) | 387 if (!beforeAfterContainer) |
| 388 return nullptr; | 388 return nullptr; |
| 389 if (!beforeAfterContainer->isAnonymous() && !beforeAfterContainer->i
sPseudoElement()) | 389 if (!beforeAfterContainer->isAnonymous() && !beforeAfterContainer->i
sPseudoElement()) |
| 390 return nullptr; // LayoutCounters are restricted to before and a
fter pseudo elements | 390 return nullptr; // LayoutCounters are restricted to before and a
fter pseudo elements |
| 391 PseudoId containerStyle = beforeAfterContainer->style()->styleType()
; | 391 PseudoId containerStyle = beforeAfterContainer->style()->styleType()
; |
| 392 if ((containerStyle == BEFORE) || (containerStyle == AFTER)) | 392 if ((containerStyle == BEFORE) || (containerStyle == AFTER)) |
| 393 break; | 393 break; |
| 394 beforeAfterContainer = beforeAfterContainer->parent(); | 394 beforeAfterContainer = beforeAfterContainer->parent(); |
| 395 } | 395 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 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) { |
| 435 previous = child->previousInPreOrder(); | 435 previous = child->previousInPreOrder(); |
| 436 child->parent()->removeChild(child.get()); | 436 child->parent()->removeChild(child.get()); |
| 437 ASSERT(counterMaps().get(&child->owner())->get(identifier) == child); | 437 ASSERT(counterMaps().get(&child->owner())->get(identifier) == child); |
| 438 counterMaps().get(&child->owner())->remove(identifier); | 438 counterMaps().get(&child->owner())->remove(identifier); |
| 439 } | 439 } |
| 440 if (CounterNode* parent = node->parent()) | 440 if (CounterNode* parent = node->parent()) |
| 441 parent->removeChild(node); | 441 parent->removeChild(node); |
| 442 } | 442 } |
| 443 | 443 |
| 444 void LayoutCounter::destroyCounterNodes(RenderObject& owner) | 444 void LayoutCounter::destroyCounterNodes(LayoutObject& owner) |
| 445 { | 445 { |
| 446 CounterMaps& maps = counterMaps(); | 446 CounterMaps& maps = counterMaps(); |
| 447 CounterMaps::iterator mapsIterator = maps.find(&owner); | 447 CounterMaps::iterator mapsIterator = maps.find(&owner); |
| 448 if (mapsIterator == maps.end()) | 448 if (mapsIterator == maps.end()) |
| 449 return; | 449 return; |
| 450 CounterMap* map = mapsIterator->value.get(); | 450 CounterMap* map = mapsIterator->value.get(); |
| 451 CounterMap::const_iterator end = map->end(); | 451 CounterMap::const_iterator end = map->end(); |
| 452 for (CounterMap::const_iterator it = map->begin(); it != end; ++it) { | 452 for (CounterMap::const_iterator it = map->begin(); it != end; ++it) { |
| 453 destroyCounterNodeWithoutMapRemoval(it->key, it->value.get()); | 453 destroyCounterNodeWithoutMapRemoval(it->key, it->value.get()); |
| 454 } | 454 } |
| 455 maps.remove(mapsIterator); | 455 maps.remove(mapsIterator); |
| 456 owner.setHasCounterNodeMap(false); | 456 owner.setHasCounterNodeMap(false); |
| 457 } | 457 } |
| 458 | 458 |
| 459 void LayoutCounter::destroyCounterNode(RenderObject& owner, const AtomicString&
identifier) | 459 void LayoutCounter::destroyCounterNode(LayoutObject& owner, const AtomicString&
identifier) |
| 460 { | 460 { |
| 461 CounterMap* map = counterMaps().get(&owner); | 461 CounterMap* map = counterMaps().get(&owner); |
| 462 if (!map) | 462 if (!map) |
| 463 return; | 463 return; |
| 464 CounterMap::iterator mapIterator = map->find(identifier); | 464 CounterMap::iterator mapIterator = map->find(identifier); |
| 465 if (mapIterator == map->end()) | 465 if (mapIterator == map->end()) |
| 466 return; | 466 return; |
| 467 destroyCounterNodeWithoutMapRemoval(identifier, mapIterator->value.get()); | 467 destroyCounterNodeWithoutMapRemoval(identifier, mapIterator->value.get()); |
| 468 map->remove(mapIterator); | 468 map->remove(mapIterator); |
| 469 // 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 |
| 470 // 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, |
| 471 // a style change for the renderer involving removal of all counter | 471 // a style change for the renderer involving removal of all counter |
| 472 // directives must occur, in which case, LayoutCounter::destroyCounterNodes(
) | 472 // directives must occur, in which case, LayoutCounter::destroyCounterNodes(
) |
| 473 // must be called. | 473 // must be called. |
| 474 // 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 |
| 475 // 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 |
| 476 // destruction of all counters attached to a Renderer. In this case | 476 // destruction of all counters attached to a Renderer. In this case |
| 477 // LayoutCounter::destroyCounterNodes() must be and is now called, too. | 477 // LayoutCounter::destroyCounterNodes() must be and is now called, too. |
| 478 // LayoutCounter::destroyCounterNodes() handles destruction of the counter | 478 // LayoutCounter::destroyCounterNodes() handles destruction of the counter |
| 479 // 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. |
| 480 } | 480 } |
| 481 | 481 |
| 482 void LayoutCounter::rendererRemovedFromTree(RenderObject* renderer) | 482 void LayoutCounter::rendererRemovedFromTree(LayoutObject* renderer) |
| 483 { | 483 { |
| 484 ASSERT(renderer->view()); | 484 ASSERT(renderer->view()); |
| 485 if (!renderer->view()->hasLayoutCounters()) | 485 if (!renderer->view()->hasLayoutCounters()) |
| 486 return; | 486 return; |
| 487 RenderObject* currentRenderer = renderer->lastLeafChild(); | 487 LayoutObject* currentRenderer = renderer->lastLeafChild(); |
| 488 if (!currentRenderer) | 488 if (!currentRenderer) |
| 489 currentRenderer = renderer; | 489 currentRenderer = renderer; |
| 490 while (true) { | 490 while (true) { |
| 491 destroyCounterNodes(*currentRenderer); | 491 destroyCounterNodes(*currentRenderer); |
| 492 if (currentRenderer == renderer) | 492 if (currentRenderer == renderer) |
| 493 break; | 493 break; |
| 494 currentRenderer = currentRenderer->previousInPreOrder(); | 494 currentRenderer = currentRenderer->previousInPreOrder(); |
| 495 } | 495 } |
| 496 } | 496 } |
| 497 | 497 |
| 498 static void updateCounters(RenderObject& renderer) | 498 static void updateCounters(LayoutObject& renderer) |
| 499 { | 499 { |
| 500 ASSERT(renderer.style()); | 500 ASSERT(renderer.style()); |
| 501 const CounterDirectiveMap* directiveMap = renderer.style()->counterDirective
s(); | 501 const CounterDirectiveMap* directiveMap = renderer.style()->counterDirective
s(); |
| 502 if (!directiveMap) | 502 if (!directiveMap) |
| 503 return; | 503 return; |
| 504 CounterDirectiveMap::const_iterator end = directiveMap->end(); | 504 CounterDirectiveMap::const_iterator end = directiveMap->end(); |
| 505 if (!renderer.hasCounterNodeMap()) { | 505 if (!renderer.hasCounterNodeMap()) { |
| 506 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it
!= end; ++it) | 506 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it
!= end; ++it) |
| 507 makeCounterNode(renderer, it->key, false); | 507 makeCounterNode(renderer, it->key, false); |
| 508 return; | 508 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 524 CounterNode* parent = node->parent(); | 524 CounterNode* parent = node->parent(); |
| 525 if (newParent == parent && newPreviousSibling == node->previousSibling()
) | 525 if (newParent == parent && newPreviousSibling == node->previousSibling()
) |
| 526 continue; | 526 continue; |
| 527 if (parent) | 527 if (parent) |
| 528 parent->removeChild(node.get()); | 528 parent->removeChild(node.get()); |
| 529 if (newParent) | 529 if (newParent) |
| 530 newParent->insertAfter(node.get(), newPreviousSibling.get(), it->key
); | 530 newParent->insertAfter(node.get(), newPreviousSibling.get(), it->key
); |
| 531 } | 531 } |
| 532 } | 532 } |
| 533 | 533 |
| 534 void LayoutCounter::rendererSubtreeAttached(RenderObject* renderer) | 534 void LayoutCounter::rendererSubtreeAttached(LayoutObject* renderer) |
| 535 { | 535 { |
| 536 ASSERT(renderer->view()); | 536 ASSERT(renderer->view()); |
| 537 if (!renderer->view()->hasLayoutCounters()) | 537 if (!renderer->view()->hasLayoutCounters()) |
| 538 return; | 538 return; |
| 539 Node* node = renderer->node(); | 539 Node* node = renderer->node(); |
| 540 if (node) | 540 if (node) |
| 541 node = node->parentNode(); | 541 node = node->parentNode(); |
| 542 else | 542 else |
| 543 node = renderer->generatingNode(); | 543 node = renderer->generatingNode(); |
| 544 if (node && node->needsAttach()) | 544 if (node && node->needsAttach()) |
| 545 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 |
| 546 for (RenderObject* descendant = renderer; descendant; descendant = descendan
t->nextInPreOrder(renderer)) | 546 for (LayoutObject* descendant = renderer; descendant; descendant = descendan
t->nextInPreOrder(renderer)) |
| 547 updateCounters(*descendant); | 547 updateCounters(*descendant); |
| 548 } | 548 } |
| 549 | 549 |
| 550 void LayoutCounter::rendererStyleChanged(RenderObject& renderer, const RenderSty
le* oldStyle, const RenderStyle* newStyle) | 550 void LayoutCounter::rendererStyleChanged(LayoutObject& renderer, const RenderSty
le* oldStyle, const RenderStyle* newStyle) |
| 551 { | 551 { |
| 552 Node* node = renderer.generatingNode(); | 552 Node* node = renderer.generatingNode(); |
| 553 if (!node || node->needsAttach()) | 553 if (!node || node->needsAttach()) |
| 554 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 |
| 555 const CounterDirectiveMap* oldCounterDirectives = oldStyle ? oldStyle->count
erDirectives() : 0; | 555 const CounterDirectiveMap* oldCounterDirectives = oldStyle ? oldStyle->count
erDirectives() : 0; |
| 556 const CounterDirectiveMap* newCounterDirectives = newStyle ? newStyle->count
erDirectives() : 0; | 556 const CounterDirectiveMap* newCounterDirectives = newStyle ? newStyle->count
erDirectives() : 0; |
| 557 if (oldCounterDirectives) { | 557 if (oldCounterDirectives) { |
| 558 if (newCounterDirectives) { | 558 if (newCounterDirectives) { |
| 559 CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives
->end(); | 559 CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives
->end(); |
| 560 CounterDirectiveMap::const_iterator oldMapEnd = oldCounterDirectives
->end(); | 560 CounterDirectiveMap::const_iterator oldMapEnd = oldCounterDirectives
->end(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 587 // not catch the change if the node had no children. | 587 // not catch the change if the node had no children. |
| 588 makeCounterNode(renderer, it->key, false); | 588 makeCounterNode(renderer, it->key, false); |
| 589 } | 589 } |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 | 592 |
| 593 } // namespace blink | 593 } // namespace blink |
| 594 | 594 |
| 595 #ifndef NDEBUG | 595 #ifndef NDEBUG |
| 596 | 596 |
| 597 void showCounterRendererTree(const blink::RenderObject* renderer, const char* co
unterName) | 597 void showCounterRendererTree(const blink::LayoutObject* renderer, const char* co
unterName) |
| 598 { | 598 { |
| 599 if (!renderer) | 599 if (!renderer) |
| 600 return; | 600 return; |
| 601 const blink::RenderObject* root = renderer; | 601 const blink::LayoutObject* root = renderer; |
| 602 while (root->parent()) | 602 while (root->parent()) |
| 603 root = root->parent(); | 603 root = root->parent(); |
| 604 | 604 |
| 605 AtomicString identifier(counterName); | 605 AtomicString identifier(counterName); |
| 606 for (const blink::RenderObject* current = root; current; current = current->
nextInPreOrder()) { | 606 for (const blink::LayoutObject* current = root; current; current = current->
nextInPreOrder()) { |
| 607 fprintf(stderr, "%c", (current == renderer) ? '*' : ' '); | 607 fprintf(stderr, "%c", (current == renderer) ? '*' : ' '); |
| 608 for (const blink::RenderObject* parent = current; parent && parent != ro
ot; parent = parent->parent()) | 608 for (const blink::LayoutObject* parent = current; parent && parent != ro
ot; parent = parent->parent()) |
| 609 fprintf(stderr, " "); | 609 fprintf(stderr, " "); |
| 610 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", |
| 611 current, current->node(), current->parent(), current->previousSiblin
g(), | 611 current, current->node(), current->parent(), current->previousSiblin
g(), |
| 612 current->nextSibling(), current->hasCounterNodeMap() ? | 612 current->nextSibling(), current->hasCounterNodeMap() ? |
| 613 counterName ? blink::counterMaps().get(current)->get(identifier) : (
blink::CounterNode*)1 : (blink::CounterNode*)0); | 613 counterName ? blink::counterMaps().get(current)->get(identifier) : (
blink::CounterNode*)1 : (blink::CounterNode*)0); |
| 614 } | 614 } |
| 615 fflush(stderr); | 615 fflush(stderr); |
| 616 } | 616 } |
| 617 | 617 |
| 618 #endif // NDEBUG | 618 #endif // NDEBUG |
| OLD | NEW |