| 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 currentLayoutObject = | 363 currentLayoutObject = |
| 364 previousInPreOrderRespectingContainment(*currentLayoutObject); | 364 previousInPreOrderRespectingContainment(*currentLayoutObject); |
| 365 } | 365 } |
| 366 return false; | 366 return false; |
| 367 } | 367 } |
| 368 | 368 |
| 369 static CounterNode* makeCounterNodeIfNeeded(LayoutObject& object, | 369 static CounterNode* makeCounterNodeIfNeeded(LayoutObject& object, |
| 370 const AtomicString& identifier, | 370 const AtomicString& identifier, |
| 371 bool alwaysCreateCounter) { | 371 bool alwaysCreateCounter) { |
| 372 if (object.hasCounterNodeMap()) { | 372 if (object.hasCounterNodeMap()) { |
| 373 if (CounterMap* nodeMap = counterMaps().get(&object)) { | 373 if (CounterMap* nodeMap = counterMaps().at(&object)) { |
| 374 if (CounterNode* node = nodeMap->get(identifier)) | 374 if (CounterNode* node = nodeMap->at(identifier)) |
| 375 return node; | 375 return node; |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 | 378 |
| 379 bool isReset = false; | 379 bool isReset = false; |
| 380 int value = 0; | 380 int value = 0; |
| 381 if (!planCounter(object, identifier, isReset, value) && !alwaysCreateCounter) | 381 if (!planCounter(object, identifier, isReset, value) && !alwaysCreateCounter) |
| 382 return nullptr; | 382 return nullptr; |
| 383 | 383 |
| 384 RefPtr<CounterNode> newParent = nullptr; | 384 RefPtr<CounterNode> newParent = nullptr; |
| 385 RefPtr<CounterNode> newPreviousSibling = nullptr; | 385 RefPtr<CounterNode> newPreviousSibling = nullptr; |
| 386 RefPtr<CounterNode> newNode = CounterNode::create(object, isReset, value); | 386 RefPtr<CounterNode> newNode = CounterNode::create(object, isReset, value); |
| 387 if (findPlaceForCounter(object, identifier, isReset, newParent, | 387 if (findPlaceForCounter(object, identifier, isReset, newParent, |
| 388 newPreviousSibling)) | 388 newPreviousSibling)) |
| 389 newParent->insertAfter(newNode.get(), newPreviousSibling.get(), identifier); | 389 newParent->insertAfter(newNode.get(), newPreviousSibling.get(), identifier); |
| 390 CounterMap* nodeMap; | 390 CounterMap* nodeMap; |
| 391 if (object.hasCounterNodeMap()) { | 391 if (object.hasCounterNodeMap()) { |
| 392 nodeMap = counterMaps().get(&object); | 392 nodeMap = counterMaps().at(&object); |
| 393 } else { | 393 } else { |
| 394 nodeMap = new CounterMap; | 394 nodeMap = new CounterMap; |
| 395 counterMaps().set(&object, WTF::wrapUnique(nodeMap)); | 395 counterMaps().set(&object, WTF::wrapUnique(nodeMap)); |
| 396 object.setHasCounterNodeMap(true); | 396 object.setHasCounterNodeMap(true); |
| 397 } | 397 } |
| 398 nodeMap->set(identifier, newNode); | 398 nodeMap->set(identifier, newNode); |
| 399 if (newNode->parent()) | 399 if (newNode->parent()) |
| 400 return newNode.get(); | 400 return newNode.get(); |
| 401 // Checking if some nodes that were previously counter tree root nodes | 401 // Checking if some nodes that were previously counter tree root nodes |
| 402 // should become children of this node now. | 402 // should become children of this node now. |
| 403 CounterMaps& maps = counterMaps(); | 403 CounterMaps& maps = counterMaps(); |
| 404 Element* stayWithin = parentElement(object); | 404 Element* stayWithin = parentElement(object); |
| 405 bool skipDescendants; | 405 bool skipDescendants; |
| 406 for (LayoutObject* currentLayoutObject = nextInPreOrder(object, stayWithin); | 406 for (LayoutObject* currentLayoutObject = nextInPreOrder(object, stayWithin); |
| 407 currentLayoutObject; | 407 currentLayoutObject; |
| 408 currentLayoutObject = | 408 currentLayoutObject = |
| 409 nextInPreOrder(*currentLayoutObject, stayWithin, skipDescendants)) { | 409 nextInPreOrder(*currentLayoutObject, stayWithin, skipDescendants)) { |
| 410 skipDescendants = false; | 410 skipDescendants = false; |
| 411 if (!currentLayoutObject->hasCounterNodeMap()) | 411 if (!currentLayoutObject->hasCounterNodeMap()) |
| 412 continue; | 412 continue; |
| 413 CounterNode* currentCounter = | 413 CounterNode* currentCounter = maps.at(currentLayoutObject)->at(identifier); |
| 414 maps.get(currentLayoutObject)->get(identifier); | |
| 415 if (!currentCounter) | 414 if (!currentCounter) |
| 416 continue; | 415 continue; |
| 417 skipDescendants = true; | 416 skipDescendants = true; |
| 418 if (currentCounter->parent()) | 417 if (currentCounter->parent()) |
| 419 continue; | 418 continue; |
| 420 if (stayWithin == parentElement(*currentLayoutObject) && | 419 if (stayWithin == parentElement(*currentLayoutObject) && |
| 421 currentCounter->hasResetType()) | 420 currentCounter->hasResetType()) |
| 422 break; | 421 break; |
| 423 newNode->insertAfter(currentCounter, newNode->lastChild(), identifier); | 422 newNode->insertAfter(currentCounter, newNode->lastChild(), identifier); |
| 424 } | 423 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 LayoutInvalidationReason::CountersChanged); | 496 LayoutInvalidationReason::CountersChanged); |
| 498 } | 497 } |
| 499 | 498 |
| 500 static void destroyCounterNodeWithoutMapRemoval(const AtomicString& identifier, | 499 static void destroyCounterNodeWithoutMapRemoval(const AtomicString& identifier, |
| 501 CounterNode* node) { | 500 CounterNode* node) { |
| 502 CounterNode* previous; | 501 CounterNode* previous; |
| 503 for (RefPtr<CounterNode> child = node->lastDescendant(); | 502 for (RefPtr<CounterNode> child = node->lastDescendant(); |
| 504 child && child != node; child = previous) { | 503 child && child != node; child = previous) { |
| 505 previous = child->previousInPreOrder(); | 504 previous = child->previousInPreOrder(); |
| 506 child->parent()->removeChild(child.get()); | 505 child->parent()->removeChild(child.get()); |
| 507 ASSERT(counterMaps().get(&child->owner())->get(identifier) == child); | 506 ASSERT(counterMaps().at(&child->owner())->at(identifier) == child); |
| 508 counterMaps().get(&child->owner())->erase(identifier); | 507 counterMaps().at(&child->owner())->erase(identifier); |
| 509 } | 508 } |
| 510 if (CounterNode* parent = node->parent()) | 509 if (CounterNode* parent = node->parent()) |
| 511 parent->removeChild(node); | 510 parent->removeChild(node); |
| 512 } | 511 } |
| 513 | 512 |
| 514 void LayoutCounter::destroyCounterNodes(LayoutObject& owner) { | 513 void LayoutCounter::destroyCounterNodes(LayoutObject& owner) { |
| 515 CounterMaps& maps = counterMaps(); | 514 CounterMaps& maps = counterMaps(); |
| 516 CounterMaps::iterator mapsIterator = maps.find(&owner); | 515 CounterMaps::iterator mapsIterator = maps.find(&owner); |
| 517 if (mapsIterator == maps.end()) | 516 if (mapsIterator == maps.end()) |
| 518 return; | 517 return; |
| 519 CounterMap* map = mapsIterator->value.get(); | 518 CounterMap* map = mapsIterator->value.get(); |
| 520 CounterMap::const_iterator end = map->end(); | 519 CounterMap::const_iterator end = map->end(); |
| 521 for (CounterMap::const_iterator it = map->begin(); it != end; ++it) { | 520 for (CounterMap::const_iterator it = map->begin(); it != end; ++it) { |
| 522 destroyCounterNodeWithoutMapRemoval(it->key, it->value.get()); | 521 destroyCounterNodeWithoutMapRemoval(it->key, it->value.get()); |
| 523 } | 522 } |
| 524 maps.remove(mapsIterator); | 523 maps.remove(mapsIterator); |
| 525 owner.setHasCounterNodeMap(false); | 524 owner.setHasCounterNodeMap(false); |
| 526 } | 525 } |
| 527 | 526 |
| 528 void LayoutCounter::destroyCounterNode(LayoutObject& owner, | 527 void LayoutCounter::destroyCounterNode(LayoutObject& owner, |
| 529 const AtomicString& identifier) { | 528 const AtomicString& identifier) { |
| 530 CounterMap* map = counterMaps().get(&owner); | 529 CounterMap* map = counterMaps().at(&owner); |
| 531 if (!map) | 530 if (!map) |
| 532 return; | 531 return; |
| 533 CounterMap::iterator mapIterator = map->find(identifier); | 532 CounterMap::iterator mapIterator = map->find(identifier); |
| 534 if (mapIterator == map->end()) | 533 if (mapIterator == map->end()) |
| 535 return; | 534 return; |
| 536 destroyCounterNodeWithoutMapRemoval(identifier, mapIterator->value.get()); | 535 destroyCounterNodeWithoutMapRemoval(identifier, mapIterator->value.get()); |
| 537 map->remove(mapIterator); | 536 map->remove(mapIterator); |
| 538 // We do not delete "map" here even if empty because we expect to reuse | 537 // We do not delete "map" here even if empty because we expect to reuse |
| 539 // it soon. In order for a layoutObject to lose all its counters permanently, | 538 // it soon. In order for a layoutObject to lose all its counters permanently, |
| 540 // a style change for the layoutObject involving removal of all counter | 539 // a style change for the layoutObject involving removal of all counter |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 layoutObject.style()->counterDirectives(); | 571 layoutObject.style()->counterDirectives(); |
| 573 if (!directiveMap) | 572 if (!directiveMap) |
| 574 return; | 573 return; |
| 575 CounterDirectiveMap::const_iterator end = directiveMap->end(); | 574 CounterDirectiveMap::const_iterator end = directiveMap->end(); |
| 576 if (!layoutObject.hasCounterNodeMap()) { | 575 if (!layoutObject.hasCounterNodeMap()) { |
| 577 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); | 576 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); |
| 578 it != end; ++it) | 577 it != end; ++it) |
| 579 makeCounterNodeIfNeeded(layoutObject, it->key, false); | 578 makeCounterNodeIfNeeded(layoutObject, it->key, false); |
| 580 return; | 579 return; |
| 581 } | 580 } |
| 582 CounterMap* counterMap = counterMaps().get(&layoutObject); | 581 CounterMap* counterMap = counterMaps().at(&layoutObject); |
| 583 ASSERT(counterMap); | 582 ASSERT(counterMap); |
| 584 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); | 583 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); |
| 585 it != end; ++it) { | 584 it != end; ++it) { |
| 586 RefPtr<CounterNode> node = counterMap->get(it->key); | 585 RefPtr<CounterNode> node = counterMap->at(it->key); |
| 587 if (!node) { | 586 if (!node) { |
| 588 makeCounterNodeIfNeeded(layoutObject, it->key, false); | 587 makeCounterNodeIfNeeded(layoutObject, it->key, false); |
| 589 continue; | 588 continue; |
| 590 } | 589 } |
| 591 RefPtr<CounterNode> newParent = nullptr; | 590 RefPtr<CounterNode> newParent = nullptr; |
| 592 RefPtr<CounterNode> newPreviousSibling = nullptr; | 591 RefPtr<CounterNode> newPreviousSibling = nullptr; |
| 593 | 592 |
| 594 findPlaceForCounter(layoutObject, it->key, node->hasResetType(), newParent, | 593 findPlaceForCounter(layoutObject, it->key, node->hasResetType(), newParent, |
| 595 newPreviousSibling); | 594 newPreviousSibling); |
| 596 if (node != counterMap->get(it->key)) | 595 if (node != counterMap->at(it->key)) |
| 597 continue; | 596 continue; |
| 598 CounterNode* parent = node->parent(); | 597 CounterNode* parent = node->parent(); |
| 599 if (newParent == parent && newPreviousSibling == node->previousSibling()) | 598 if (newParent == parent && newPreviousSibling == node->previousSibling()) |
| 600 continue; | 599 continue; |
| 601 if (parent) | 600 if (parent) |
| 602 parent->removeChild(node.get()); | 601 parent->removeChild(node.get()); |
| 603 if (newParent) | 602 if (newParent) |
| 604 newParent->insertAfter(node.get(), newPreviousSibling.get(), it->key); | 603 newParent->insertAfter(node.get(), newPreviousSibling.get(), it->key); |
| 605 } | 604 } |
| 606 } | 605 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 while (root->parent()) | 692 while (root->parent()) |
| 694 root = root->parent(); | 693 root = root->parent(); |
| 695 | 694 |
| 696 AtomicString identifier(counterName); | 695 AtomicString identifier(counterName); |
| 697 for (const blink::LayoutObject* current = root; current; | 696 for (const blink::LayoutObject* current = root; current; |
| 698 current = current->nextInPreOrder()) { | 697 current = current->nextInPreOrder()) { |
| 699 fprintf(stderr, "%c", (current == layoutObject) ? '*' : ' '); | 698 fprintf(stderr, "%c", (current == layoutObject) ? '*' : ' '); |
| 700 for (const blink::LayoutObject* parent = current; parent && parent != root; | 699 for (const blink::LayoutObject* parent = current; parent && parent != root; |
| 701 parent = parent->parent()) | 700 parent = parent->parent()) |
| 702 fprintf(stderr, " "); | 701 fprintf(stderr, " "); |
| 703 fprintf( | 702 fprintf(stderr, "%p N:%p P:%p PS:%p NS:%p C:%p\n", current, current->node(), |
| 704 stderr, "%p N:%p P:%p PS:%p NS:%p C:%p\n", current, current->node(), | 703 current->parent(), current->previousSibling(), |
| 705 current->parent(), current->previousSibling(), current->nextSibling(), | 704 current->nextSibling(), |
| 706 current->hasCounterNodeMap() | 705 current->hasCounterNodeMap() |
| 707 ? counterName ? blink::counterMaps().get(current)->get(identifier) | 706 ? counterName ? blink::counterMaps().at(current)->at(identifier) |
| 708 : (blink::CounterNode*)1 | 707 : (blink::CounterNode*)1 |
| 709 : (blink::CounterNode*)0); | 708 : (blink::CounterNode*)0); |
| 710 } | 709 } |
| 711 fflush(stderr); | 710 fflush(stderr); |
| 712 } | 711 } |
| 713 | 712 |
| 714 #endif // NDEBUG | 713 #endif // NDEBUG |
| OLD | NEW |