| 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, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 * | 19 * |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #include "config.h" | 22 #include "config.h" |
| 23 #include "core/rendering/RenderCounter.h" | 23 #include "core/layout/LayoutCounter.h" |
| 24 | 24 |
| 25 #include "core/HTMLNames.h" | 25 #include "core/HTMLNames.h" |
| 26 #include "core/dom/Element.h" | 26 #include "core/dom/Element.h" |
| 27 #include "core/dom/ElementTraversal.h" | 27 #include "core/dom/ElementTraversal.h" |
| 28 #include "core/html/HTMLOListElement.h" | 28 #include "core/html/HTMLOListElement.h" |
| 29 #include "core/rendering/CounterNode.h" | 29 #include "core/layout/CounterNode.h" |
| 30 #include "core/rendering/RenderListItem.h" | 30 #include "core/rendering/RenderListItem.h" |
| 31 #include "core/rendering/RenderListMarker.h" | 31 #include "core/rendering/RenderListMarker.h" |
| 32 #include "core/rendering/RenderView.h" | 32 #include "core/rendering/RenderView.h" |
| 33 #include "core/rendering/style/RenderStyle.h" | 33 #include "core/rendering/style/RenderStyle.h" |
| 34 #include "wtf/StdLibExtras.h" | 34 #include "wtf/StdLibExtras.h" |
| 35 | 35 |
| 36 #ifndef NDEBUG | 36 #ifndef NDEBUG |
| 37 #include <stdio.h> | 37 #include <stdio.h> |
| 38 #endif | 38 #endif |
| 39 | 39 |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 if (previousSiblingProtector) { | 267 if (previousSiblingProtector) { |
| 268 // Since we had a suitable previous counter before, we shoul
d only consider this one as our | 268 // 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. | 269 // previousSibling if it is a reset counter and hence the cu
rrent previousSibling is its child. |
| 270 if (currentCounter->actsAsReset()) { | 270 if (currentCounter->actsAsReset()) { |
| 271 previousSiblingProtector = currentCounter; | 271 previousSiblingProtector = currentCounter; |
| 272 // We are no longer interested in previous siblings of t
he currentRenderer or their children | 272 // We are no longer interested in previous siblings of t
he currentRenderer or their children |
| 273 // as counters they may have attached cannot be the prev
ious sibling of the counter we are placing. | 273 // as counters they may have attached cannot be the prev
ious sibling of the counter we are placing. |
| 274 currentRenderer = parentElement(*currentRenderer)->rende
rer(); | 274 currentRenderer = parentElement(*currentRenderer)->rende
rer(); |
| 275 continue; | 275 continue; |
| 276 } | 276 } |
| 277 } else | 277 } else { |
| 278 previousSiblingProtector = currentCounter; | 278 previousSiblingProtector = currentCounter; |
| 279 } |
| 279 currentRenderer = previousSiblingOrParent(*currentRenderer); | 280 currentRenderer = previousSiblingOrParent(*currentRenderer); |
| 280 continue; | 281 continue; |
| 281 } | 282 } |
| 282 } | 283 } |
| 283 // 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 |
| 284 // 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 |
| 285 // 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 |
| 286 // impede the readability of this already complex algorithm. | 287 // impede the readability of this already complex algorithm. |
| 287 if (previousSiblingProtector) | 288 if (previousSiblingProtector) |
| 288 currentRenderer = previousSiblingOrParent(*currentRenderer); | 289 currentRenderer = previousSiblingOrParent(*currentRenderer); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 305 int value = 0; | 306 int value = 0; |
| 306 if (!planCounter(object, identifier, isReset, value) && !alwaysCreateCounter
) | 307 if (!planCounter(object, identifier, isReset, value) && !alwaysCreateCounter
) |
| 307 return 0; | 308 return 0; |
| 308 | 309 |
| 309 RefPtr<CounterNode> newParent = nullptr; | 310 RefPtr<CounterNode> newParent = nullptr; |
| 310 RefPtr<CounterNode> newPreviousSibling = nullptr; | 311 RefPtr<CounterNode> newPreviousSibling = nullptr; |
| 311 RefPtr<CounterNode> newNode = CounterNode::create(object, isReset, value); | 312 RefPtr<CounterNode> newNode = CounterNode::create(object, isReset, value); |
| 312 if (findPlaceForCounter(object, identifier, isReset, newParent, newPreviousS
ibling)) | 313 if (findPlaceForCounter(object, identifier, isReset, newParent, newPreviousS
ibling)) |
| 313 newParent->insertAfter(newNode.get(), newPreviousSibling.get(), identifi
er); | 314 newParent->insertAfter(newNode.get(), newPreviousSibling.get(), identifi
er); |
| 314 CounterMap* nodeMap; | 315 CounterMap* nodeMap; |
| 315 if (object.hasCounterNodeMap()) | 316 if (object.hasCounterNodeMap()) { |
| 316 nodeMap = counterMaps().get(&object); | 317 nodeMap = counterMaps().get(&object); |
| 317 else { | 318 } else { |
| 318 nodeMap = new CounterMap; | 319 nodeMap = new CounterMap; |
| 319 counterMaps().set(&object, adoptPtr(nodeMap)); | 320 counterMaps().set(&object, adoptPtr(nodeMap)); |
| 320 object.setHasCounterNodeMap(true); | 321 object.setHasCounterNodeMap(true); |
| 321 } | 322 } |
| 322 nodeMap->set(identifier, newNode); | 323 nodeMap->set(identifier, newNode); |
| 323 if (newNode->parent()) | 324 if (newNode->parent()) |
| 324 return newNode.get(); | 325 return newNode.get(); |
| 325 // Checking if some nodes that were previously counter tree root nodes | 326 // Checking if some nodes that were previously counter tree root nodes |
| 326 // should become children of this node now. | 327 // should become children of this node now. |
| 327 CounterMaps& maps = counterMaps(); | 328 CounterMaps& maps = counterMaps(); |
| 328 Element* stayWithin = parentElement(object); | 329 Element* stayWithin = parentElement(object); |
| 329 bool skipDescendants; | 330 bool skipDescendants; |
| 330 for (RenderObject* currentRenderer = nextInPreOrder(object, stayWithin); cur
rentRenderer; currentRenderer = nextInPreOrder(*currentRenderer, stayWithin, ski
pDescendants)) { | 331 for (RenderObject* currentRenderer = nextInPreOrder(object, stayWithin); cur
rentRenderer; currentRenderer = nextInPreOrder(*currentRenderer, stayWithin, ski
pDescendants)) { |
| 331 skipDescendants = false; | 332 skipDescendants = false; |
| 332 if (!currentRenderer->hasCounterNodeMap()) | 333 if (!currentRenderer->hasCounterNodeMap()) |
| 333 continue; | 334 continue; |
| 334 CounterNode* currentCounter = maps.get(currentRenderer)->get(identifier)
; | 335 CounterNode* currentCounter = maps.get(currentRenderer)->get(identifier)
; |
| 335 if (!currentCounter) | 336 if (!currentCounter) |
| 336 continue; | 337 continue; |
| 337 skipDescendants = true; | 338 skipDescendants = true; |
| 338 if (currentCounter->parent()) | 339 if (currentCounter->parent()) |
| 339 continue; | 340 continue; |
| 340 if (stayWithin == parentElement(*currentRenderer) && currentCounter->has
ResetType()) | 341 if (stayWithin == parentElement(*currentRenderer) && currentCounter->has
ResetType()) |
| 341 break; | 342 break; |
| 342 newNode->insertAfter(currentCounter, newNode->lastChild(), identifier); | 343 newNode->insertAfter(currentCounter, newNode->lastChild(), identifier); |
| 343 } | 344 } |
| 344 return newNode.get(); | 345 return newNode.get(); |
| 345 } | 346 } |
| 346 | 347 |
| 347 RenderCounter::RenderCounter(Document* node, const CounterContent& counter) | 348 LayoutCounter::LayoutCounter(Document* node, const CounterContent& counter) |
| 348 : RenderText(node, StringImpl::empty()) | 349 : RenderText(node, StringImpl::empty()) |
| 349 , m_counter(counter) | 350 , m_counter(counter) |
| 350 , m_counterNode(0) | 351 , m_counterNode(0) |
| 351 , m_nextForSameCounter(0) | 352 , m_nextForSameCounter(0) |
| 352 { | 353 { |
| 353 view()->addRenderCounter(); | 354 view()->addLayoutCounter(); |
| 354 } | 355 } |
| 355 | 356 |
| 356 RenderCounter::~RenderCounter() | 357 LayoutCounter::~LayoutCounter() |
| 357 { | 358 { |
| 358 } | 359 } |
| 359 | 360 |
| 360 void RenderCounter::destroy() | 361 void LayoutCounter::destroy() |
| 361 { | 362 { |
| 362 if (m_counterNode) { | 363 if (m_counterNode) { |
| 363 m_counterNode->removeRenderer(this); | 364 m_counterNode->removeRenderer(this); |
| 364 ASSERT(!m_counterNode); | 365 ASSERT(!m_counterNode); |
| 365 } | 366 } |
| 366 RenderText::destroy(); | 367 RenderText::destroy(); |
| 367 } | 368 } |
| 368 | 369 |
| 369 void RenderCounter::willBeDestroyed() | 370 void LayoutCounter::willBeDestroyed() |
| 370 { | 371 { |
| 371 if (view()) | 372 if (view()) |
| 372 view()->removeRenderCounter(); | 373 view()->removeLayoutCounter(); |
| 373 RenderText::willBeDestroyed(); | 374 RenderText::willBeDestroyed(); |
| 374 } | 375 } |
| 375 | 376 |
| 376 const char* RenderCounter::renderName() const | 377 const char* LayoutCounter::renderName() const |
| 377 { | 378 { |
| 378 return "RenderCounter"; | 379 return "LayoutCounter"; |
| 379 } | 380 } |
| 380 | 381 |
| 381 PassRefPtr<StringImpl> RenderCounter::originalText() const | 382 PassRefPtr<StringImpl> LayoutCounter::originalText() const |
| 382 { | 383 { |
| 383 if (!m_counterNode) { | 384 if (!m_counterNode) { |
| 384 RenderObject* beforeAfterContainer = parent(); | 385 RenderObject* beforeAfterContainer = parent(); |
| 385 while (true) { | 386 while (true) { |
| 386 if (!beforeAfterContainer) | 387 if (!beforeAfterContainer) |
| 387 return nullptr; | 388 return nullptr; |
| 388 if (!beforeAfterContainer->isAnonymous() && !beforeAfterContainer->i
sPseudoElement()) | 389 if (!beforeAfterContainer->isAnonymous() && !beforeAfterContainer->i
sPseudoElement()) |
| 389 return nullptr; // RenderCounters are restricted to before and a
fter pseudo elements | 390 return nullptr; // LayoutCounters are restricted to before and a
fter pseudo elements |
| 390 PseudoId containerStyle = beforeAfterContainer->style()->styleType()
; | 391 PseudoId containerStyle = beforeAfterContainer->style()->styleType()
; |
| 391 if ((containerStyle == BEFORE) || (containerStyle == AFTER)) | 392 if ((containerStyle == BEFORE) || (containerStyle == AFTER)) |
| 392 break; | 393 break; |
| 393 beforeAfterContainer = beforeAfterContainer->parent(); | 394 beforeAfterContainer = beforeAfterContainer->parent(); |
| 394 } | 395 } |
| 395 makeCounterNode(*beforeAfterContainer, m_counter.identifier(), true)->ad
dRenderer(const_cast<RenderCounter*>(this)); | 396 makeCounterNode(*beforeAfterContainer, m_counter.identifier(), true)->ad
dRenderer(const_cast<LayoutCounter*>(this)); |
| 396 ASSERT(m_counterNode); | 397 ASSERT(m_counterNode); |
| 397 } | 398 } |
| 398 CounterNode* child = m_counterNode; | 399 CounterNode* child = m_counterNode; |
| 399 int value = child->actsAsReset() ? child->value() : child->countInParent(); | 400 int value = child->actsAsReset() ? child->value() : child->countInParent(); |
| 400 | 401 |
| 401 String text = listMarkerText(m_counter.listStyle(), value); | 402 String text = listMarkerText(m_counter.listStyle(), value); |
| 402 | 403 |
| 403 if (!m_counter.separator().isNull()) { | 404 if (!m_counter.separator().isNull()) { |
| 404 if (!child->actsAsReset()) | 405 if (!child->actsAsReset()) |
| 405 child = child->parent(); | 406 child = child->parent(); |
| 406 while (CounterNode* parent = child->parent()) { | 407 while (CounterNode* parent = child->parent()) { |
| 407 text = listMarkerText(m_counter.listStyle(), child->countInParent()) | 408 text = listMarkerText(m_counter.listStyle(), child->countInParent()) |
| 408 + m_counter.separator() + text; | 409 + m_counter.separator() + text; |
| 409 child = parent; | 410 child = parent; |
| 410 } | 411 } |
| 411 } | 412 } |
| 412 | 413 |
| 413 return text.impl(); | 414 return text.impl(); |
| 414 } | 415 } |
| 415 | 416 |
| 416 void RenderCounter::updateCounter() | 417 void LayoutCounter::updateCounter() |
| 417 { | 418 { |
| 418 setText(originalText()); | 419 setText(originalText()); |
| 419 } | 420 } |
| 420 | 421 |
| 421 void RenderCounter::invalidate() | 422 void LayoutCounter::invalidate() |
| 422 { | 423 { |
| 423 m_counterNode->removeRenderer(this); | 424 m_counterNode->removeRenderer(this); |
| 424 ASSERT(!m_counterNode); | 425 ASSERT(!m_counterNode); |
| 425 if (documentBeingDestroyed()) | 426 if (documentBeingDestroyed()) |
| 426 return; | 427 return; |
| 427 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(); | 428 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(); |
| 428 } | 429 } |
| 429 | 430 |
| 430 static void destroyCounterNodeWithoutMapRemoval(const AtomicString& identifier,
CounterNode* node) | 431 static void destroyCounterNodeWithoutMapRemoval(const AtomicString& identifier,
CounterNode* node) |
| 431 { | 432 { |
| 432 CounterNode* previous; | 433 CounterNode* previous; |
| 433 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) { |
| 434 previous = child->previousInPreOrder(); | 435 previous = child->previousInPreOrder(); |
| 435 child->parent()->removeChild(child.get()); | 436 child->parent()->removeChild(child.get()); |
| 436 ASSERT(counterMaps().get(&child->owner())->get(identifier) == child); | 437 ASSERT(counterMaps().get(&child->owner())->get(identifier) == child); |
| 437 counterMaps().get(&child->owner())->remove(identifier); | 438 counterMaps().get(&child->owner())->remove(identifier); |
| 438 } | 439 } |
| 439 if (CounterNode* parent = node->parent()) | 440 if (CounterNode* parent = node->parent()) |
| 440 parent->removeChild(node); | 441 parent->removeChild(node); |
| 441 } | 442 } |
| 442 | 443 |
| 443 void RenderCounter::destroyCounterNodes(RenderObject& owner) | 444 void LayoutCounter::destroyCounterNodes(RenderObject& owner) |
| 444 { | 445 { |
| 445 CounterMaps& maps = counterMaps(); | 446 CounterMaps& maps = counterMaps(); |
| 446 CounterMaps::iterator mapsIterator = maps.find(&owner); | 447 CounterMaps::iterator mapsIterator = maps.find(&owner); |
| 447 if (mapsIterator == maps.end()) | 448 if (mapsIterator == maps.end()) |
| 448 return; | 449 return; |
| 449 CounterMap* map = mapsIterator->value.get(); | 450 CounterMap* map = mapsIterator->value.get(); |
| 450 CounterMap::const_iterator end = map->end(); | 451 CounterMap::const_iterator end = map->end(); |
| 451 for (CounterMap::const_iterator it = map->begin(); it != end; ++it) { | 452 for (CounterMap::const_iterator it = map->begin(); it != end; ++it) { |
| 452 destroyCounterNodeWithoutMapRemoval(it->key, it->value.get()); | 453 destroyCounterNodeWithoutMapRemoval(it->key, it->value.get()); |
| 453 } | 454 } |
| 454 maps.remove(mapsIterator); | 455 maps.remove(mapsIterator); |
| 455 owner.setHasCounterNodeMap(false); | 456 owner.setHasCounterNodeMap(false); |
| 456 } | 457 } |
| 457 | 458 |
| 458 void RenderCounter::destroyCounterNode(RenderObject& owner, const AtomicString&
identifier) | 459 void LayoutCounter::destroyCounterNode(RenderObject& owner, const AtomicString&
identifier) |
| 459 { | 460 { |
| 460 CounterMap* map = counterMaps().get(&owner); | 461 CounterMap* map = counterMaps().get(&owner); |
| 461 if (!map) | 462 if (!map) |
| 462 return; | 463 return; |
| 463 CounterMap::iterator mapIterator = map->find(identifier); | 464 CounterMap::iterator mapIterator = map->find(identifier); |
| 464 if (mapIterator == map->end()) | 465 if (mapIterator == map->end()) |
| 465 return; | 466 return; |
| 466 destroyCounterNodeWithoutMapRemoval(identifier, mapIterator->value.get()); | 467 destroyCounterNodeWithoutMapRemoval(identifier, mapIterator->value.get()); |
| 467 map->remove(mapIterator); | 468 map->remove(mapIterator); |
| 468 // 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 |
| 469 // 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, |
| 470 // a style change for the renderer involving removal of all counter | 471 // a style change for the renderer involving removal of all counter |
| 471 // directives must occur, in which case, RenderCounter::destroyCounterNodes(
) | 472 // directives must occur, in which case, LayoutCounter::destroyCounterNodes(
) |
| 472 // must be called. | 473 // must be called. |
| 473 // 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 |
| 474 // 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 |
| 475 // destruction of all counters attached to a Renderer. In this case | 476 // destruction of all counters attached to a Renderer. In this case |
| 476 // RenderCounter::destroyCounterNodes() must be and is now called, too. | 477 // LayoutCounter::destroyCounterNodes() must be and is now called, too. |
| 477 // RenderCounter::destroyCounterNodes() handles destruction of the counter | 478 // LayoutCounter::destroyCounterNodes() handles destruction of the counter |
| 478 // 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. |
| 479 } | 480 } |
| 480 | 481 |
| 481 void RenderCounter::rendererRemovedFromTree(RenderObject* renderer) | 482 void LayoutCounter::rendererRemovedFromTree(RenderObject* renderer) |
| 482 { | 483 { |
| 483 ASSERT(renderer->view()); | 484 ASSERT(renderer->view()); |
| 484 if (!renderer->view()->hasRenderCounters()) | 485 if (!renderer->view()->hasLayoutCounters()) |
| 485 return; | 486 return; |
| 486 RenderObject* currentRenderer = renderer->lastLeafChild(); | 487 RenderObject* currentRenderer = renderer->lastLeafChild(); |
| 487 if (!currentRenderer) | 488 if (!currentRenderer) |
| 488 currentRenderer = renderer; | 489 currentRenderer = renderer; |
| 489 while (true) { | 490 while (true) { |
| 490 destroyCounterNodes(*currentRenderer); | 491 destroyCounterNodes(*currentRenderer); |
| 491 if (currentRenderer == renderer) | 492 if (currentRenderer == renderer) |
| 492 break; | 493 break; |
| 493 currentRenderer = currentRenderer->previousInPreOrder(); | 494 currentRenderer = currentRenderer->previousInPreOrder(); |
| 494 } | 495 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 523 CounterNode* parent = node->parent(); | 524 CounterNode* parent = node->parent(); |
| 524 if (newParent == parent && newPreviousSibling == node->previousSibling()
) | 525 if (newParent == parent && newPreviousSibling == node->previousSibling()
) |
| 525 continue; | 526 continue; |
| 526 if (parent) | 527 if (parent) |
| 527 parent->removeChild(node.get()); | 528 parent->removeChild(node.get()); |
| 528 if (newParent) | 529 if (newParent) |
| 529 newParent->insertAfter(node.get(), newPreviousSibling.get(), it->key
); | 530 newParent->insertAfter(node.get(), newPreviousSibling.get(), it->key
); |
| 530 } | 531 } |
| 531 } | 532 } |
| 532 | 533 |
| 533 void RenderCounter::rendererSubtreeAttached(RenderObject* renderer) | 534 void LayoutCounter::rendererSubtreeAttached(RenderObject* renderer) |
| 534 { | 535 { |
| 535 ASSERT(renderer->view()); | 536 ASSERT(renderer->view()); |
| 536 if (!renderer->view()->hasRenderCounters()) | 537 if (!renderer->view()->hasLayoutCounters()) |
| 537 return; | 538 return; |
| 538 Node* node = renderer->node(); | 539 Node* node = renderer->node(); |
| 539 if (node) | 540 if (node) |
| 540 node = node->parentNode(); | 541 node = node->parentNode(); |
| 541 else | 542 else |
| 542 node = renderer->generatingNode(); | 543 node = renderer->generatingNode(); |
| 543 if (node && node->needsAttach()) | 544 if (node && node->needsAttach()) |
| 544 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 |
| 545 for (RenderObject* descendant = renderer; descendant; descendant = descendan
t->nextInPreOrder(renderer)) | 546 for (RenderObject* descendant = renderer; descendant; descendant = descendan
t->nextInPreOrder(renderer)) |
| 546 updateCounters(*descendant); | 547 updateCounters(*descendant); |
| 547 } | 548 } |
| 548 | 549 |
| 549 void RenderCounter::rendererStyleChanged(RenderObject& renderer, const RenderSty
le* oldStyle, const RenderStyle* newStyle) | 550 void LayoutCounter::rendererStyleChanged(RenderObject& renderer, const RenderSty
le* oldStyle, const RenderStyle* newStyle) |
| 550 { | 551 { |
| 551 Node* node = renderer.generatingNode(); | 552 Node* node = renderer.generatingNode(); |
| 552 if (!node || node->needsAttach()) | 553 if (!node || node->needsAttach()) |
| 553 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 |
| 554 const CounterDirectiveMap* oldCounterDirectives = oldStyle ? oldStyle->count
erDirectives() : 0; | 555 const CounterDirectiveMap* oldCounterDirectives = oldStyle ? oldStyle->count
erDirectives() : 0; |
| 555 const CounterDirectiveMap* newCounterDirectives = newStyle ? newStyle->count
erDirectives() : 0; | 556 const CounterDirectiveMap* newCounterDirectives = newStyle ? newStyle->count
erDirectives() : 0; |
| 556 if (oldCounterDirectives) { | 557 if (oldCounterDirectives) { |
| 557 if (newCounterDirectives) { | 558 if (newCounterDirectives) { |
| 558 CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives
->end(); | 559 CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives
->end(); |
| 559 CounterDirectiveMap::const_iterator oldMapEnd = oldCounterDirectives
->end(); | 560 CounterDirectiveMap::const_iterator oldMapEnd = oldCounterDirectives
->end(); |
| 560 for (CounterDirectiveMap::const_iterator it = newCounterDirectives->
begin(); it != newMapEnd; ++it) { | 561 for (CounterDirectiveMap::const_iterator it = newCounterDirectives->
begin(); it != newMapEnd; ++it) { |
| 561 CounterDirectiveMap::const_iterator oldMapIt = oldCounterDirecti
ves->find(it->key); | 562 CounterDirectiveMap::const_iterator oldMapIt = oldCounterDirecti
ves->find(it->key); |
| 562 if (oldMapIt != oldMapEnd) { | 563 if (oldMapIt != oldMapEnd) { |
| 563 if (oldMapIt->value == it->value) | 564 if (oldMapIt->value == it->value) |
| 564 continue; | 565 continue; |
| 565 RenderCounter::destroyCounterNode(renderer, it->key); | 566 LayoutCounter::destroyCounterNode(renderer, it->key); |
| 566 } | 567 } |
| 567 // 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 |
| 568 // 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 |
| 569 // not catch the change if the node had no children. | 570 // not catch the change if the node had no children. |
| 570 makeCounterNode(renderer, it->key, false); | 571 makeCounterNode(renderer, it->key, false); |
| 571 } | 572 } |
| 572 // 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. |
| 573 for (CounterDirectiveMap::const_iterator it = oldCounterDirectives->
begin(); it !=oldMapEnd; ++it) { | 574 for (CounterDirectiveMap::const_iterator it = oldCounterDirectives->
begin(); it !=oldMapEnd; ++it) { |
| 574 if (!newCounterDirectives->contains(it->key)) | 575 if (!newCounterDirectives->contains(it->key)) |
| 575 RenderCounter::destroyCounterNode(renderer, it->key); | 576 LayoutCounter::destroyCounterNode(renderer, it->key); |
| 576 } | 577 } |
| 577 } else { | 578 } else { |
| 578 if (renderer.hasCounterNodeMap()) | 579 if (renderer.hasCounterNodeMap()) |
| 579 RenderCounter::destroyCounterNodes(renderer); | 580 LayoutCounter::destroyCounterNodes(renderer); |
| 580 } | 581 } |
| 581 } else if (newCounterDirectives) { | 582 } else if (newCounterDirectives) { |
| 582 CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives->en
d(); | 583 CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives->en
d(); |
| 583 for (CounterDirectiveMap::const_iterator it = newCounterDirectives->begi
n(); it != newMapEnd; ++it) { | 584 for (CounterDirectiveMap::const_iterator it = newCounterDirectives->begi
n(); it != newMapEnd; ++it) { |
| 584 // 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 |
| 585 // 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 |
| 586 // not catch the change if the node had no children. | 587 // not catch the change if the node had no children. |
| 587 makeCounterNode(renderer, it->key, false); | 588 makeCounterNode(renderer, it->key, false); |
| 588 } | 589 } |
| 589 } | 590 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 608 fprintf(stderr, " "); | 609 fprintf(stderr, " "); |
| 609 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", |
| 610 current, current->node(), current->parent(), current->previousSiblin
g(), | 611 current, current->node(), current->parent(), current->previousSiblin
g(), |
| 611 current->nextSibling(), current->hasCounterNodeMap() ? | 612 current->nextSibling(), current->hasCounterNodeMap() ? |
| 612 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); |
| 613 } | 614 } |
| 614 fflush(stderr); | 615 fflush(stderr); |
| 615 } | 616 } |
| 616 | 617 |
| 617 #endif // NDEBUG | 618 #endif // NDEBUG |
| OLD | NEW |