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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 // counter with the same identifier. | 294 // counter with the same identifier. |
295 // - All the counter references with the same identifier as this one that are in | 295 // - All the counter references with the same identifier as this one that are in |
296 // children or subsequent siblings of the renderer that owns the root of the tre
e | 296 // children or subsequent siblings of the renderer that owns the root of the tre
e |
297 // form the rest of of the nodes of the tree. | 297 // form the rest of of the nodes of the tree. |
298 // - The root of the tree is always a reset type reference. | 298 // - The root of the tree is always a reset type reference. |
299 // - A subtree rooted at any reset node in the tree is equivalent to all counter
| 299 // - A subtree rooted at any reset node in the tree is equivalent to all counter
|
300 // references that are in the scope of the counter or nested counter defined by
that | 300 // references that are in the scope of the counter or nested counter defined by
that |
301 // reset node. | 301 // reset node. |
302 // - Non-reset CounterNodes cannot have descendants. | 302 // - Non-reset CounterNodes cannot have descendants. |
303 | 303 |
304 static bool findPlaceForCounter(RenderObject* counterOwner, const AtomicString&
identifier, bool isReset, CounterNode*& parent, CounterNode*& previousSibling) | 304 static bool findPlaceForCounter(RenderObject* counterOwner, const AtomicString&
identifier, bool isReset, RefPtr<CounterNode>& parent, RefPtr<CounterNode>& prev
iousSibling) |
305 { | 305 { |
306 // We cannot stop searching for counters with the same identifier before we
also | 306 // We cannot stop searching for counters with the same identifier before we
also |
307 // check this renderer, because it may affect the positioning in the tree of
our counter. | 307 // check this renderer, because it may affect the positioning in the tree of
our counter. |
308 RenderObject* searchEndRenderer = previousSiblingOrParent(counterOwner); | 308 RenderObject* searchEndRenderer = previousSiblingOrParent(counterOwner); |
309 // We check renderers in preOrder from the renderer that our counter is atta
ched to | 309 // We check renderers in preOrder from the renderer that our counter is atta
ched to |
310 // towards the begining of the document for counters with the same identifie
r as the one | 310 // towards the begining of the document for counters with the same identifie
r as the one |
311 // we are trying to find a place for. This is the next renderer to be checke
d. | 311 // we are trying to find a place for. This is the next renderer to be checke
d. |
312 RenderObject* currentRenderer = previousInPreOrder(counterOwner); | 312 RenderObject* currentRenderer = previousInPreOrder(counterOwner); |
313 previousSibling = 0; | 313 previousSibling = 0; |
314 RefPtr<CounterNode> previousSiblingProtector = 0; | 314 RefPtr<CounterNode> previousSiblingProtector = 0; |
(...skipping 24 matching lines...) Expand all Loading... |
339 if (previousSiblingProtector->parent() != currentCounter
) | 339 if (previousSiblingProtector->parent() != currentCounter
) |
340 previousSiblingProtector = 0; | 340 previousSiblingProtector = 0; |
341 | 341 |
342 previousSibling = previousSiblingProtector.get(); | 342 previousSibling = previousSiblingProtector.get(); |
343 return true; | 343 return true; |
344 } | 344 } |
345 // CurrentCounter, the counter at the EndSearchRenderer, is
not reset. | 345 // CurrentCounter, the counter at the EndSearchRenderer, is
not reset. |
346 if (!isReset || !areRenderersElementsSiblings(currentRendere
r, counterOwner)) { | 346 if (!isReset || !areRenderersElementsSiblings(currentRendere
r, counterOwner)) { |
347 // If the node we are placing is not reset or we have fo
und a counter that is attached | 347 // If the node we are placing is not reset or we have fo
und a counter that is attached |
348 // to an ancestor of the placed counter's owner renderer
we know we are a sibling of that node. | 348 // to an ancestor of the placed counter's owner renderer
we know we are a sibling of that node. |
349 ASSERT(currentCounter->parent() == previousSiblingProtec
tor->parent()); | 349 if (currentCounter->parent() != previousSiblingProtector
->parent()) |
| 350 return false; |
| 351 |
350 parent = currentCounter->parent(); | 352 parent = currentCounter->parent(); |
351 previousSibling = previousSiblingProtector.get(); | 353 previousSibling = previousSiblingProtector.get(); |
352 return true; | 354 return true; |
353 } | 355 } |
354 } else { | 356 } else { |
355 // We are at the potential end of the search, but we had no
previous sibling candidate | 357 // We are at the potential end of the search, but we had no
previous sibling candidate |
356 // In this case we follow pretty much the same logic as abov
e but no ASSERTs about | 358 // In this case we follow pretty much the same logic as abov
e but no ASSERTs about |
357 // previousSibling, and when we are a sibling of the end cou
nter we must set previousSibling | 359 // previousSibling, and when we are a sibling of the end cou
nter we must set previousSibling |
358 // to currentCounter. | 360 // to currentCounter. |
359 if (currentCounter->actsAsReset()) { | 361 if (currentCounter->actsAsReset()) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 if (CounterNode* node = nodeMap->get(identifier.impl()).get()) | 423 if (CounterNode* node = nodeMap->get(identifier.impl()).get()) |
422 return node; | 424 return node; |
423 } | 425 } |
424 } | 426 } |
425 | 427 |
426 bool isReset = false; | 428 bool isReset = false; |
427 int value = 0; | 429 int value = 0; |
428 if (!planCounter(object, identifier, isReset, value) && !alwaysCreateCounter
) | 430 if (!planCounter(object, identifier, isReset, value) && !alwaysCreateCounter
) |
429 return 0; | 431 return 0; |
430 | 432 |
431 CounterNode* newParent = 0; | 433 RefPtr<CounterNode> newParent = 0; |
432 CounterNode* newPreviousSibling = 0; | 434 RefPtr<CounterNode> newPreviousSibling = 0; |
433 RefPtr<CounterNode> newNode = CounterNode::create(object, isReset, value); | 435 RefPtr<CounterNode> newNode = CounterNode::create(object, isReset, value); |
434 if (findPlaceForCounter(object, identifier, isReset, newParent, newPreviousS
ibling)) | 436 if (findPlaceForCounter(object, identifier, isReset, newParent, newPreviousS
ibling)) |
435 newParent->insertAfter(newNode.get(), newPreviousSibling, identifier); | 437 newParent->insertAfter(newNode.get(), newPreviousSibling.get(), identifi
er); |
436 CounterMap* nodeMap; | 438 CounterMap* nodeMap; |
437 if (object->hasCounterNodeMap()) | 439 if (object->hasCounterNodeMap()) |
438 nodeMap = counterMaps().get(object); | 440 nodeMap = counterMaps().get(object); |
439 else { | 441 else { |
440 nodeMap = new CounterMap; | 442 nodeMap = new CounterMap; |
441 counterMaps().set(object, nodeMap); | 443 counterMaps().set(object, nodeMap); |
442 object->setHasCounterNodeMap(true); | 444 object->setHasCounterNodeMap(true); |
443 } | 445 } |
444 nodeMap->set(identifier.impl(), newNode); | 446 nodeMap->set(identifier.impl(), newNode); |
445 if (newNode->parent()) | 447 if (newNode->parent()) |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 return; | 623 return; |
622 } | 624 } |
623 CounterMap* counterMap = counterMaps().get(renderer); | 625 CounterMap* counterMap = counterMaps().get(renderer); |
624 ASSERT(counterMap); | 626 ASSERT(counterMap); |
625 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it != e
nd; ++it) { | 627 for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it != e
nd; ++it) { |
626 RefPtr<CounterNode> node = counterMap->get(it->first.get()); | 628 RefPtr<CounterNode> node = counterMap->get(it->first.get()); |
627 if (!node) { | 629 if (!node) { |
628 makeCounterNode(renderer, AtomicString(it->first.get()), false); | 630 makeCounterNode(renderer, AtomicString(it->first.get()), false); |
629 continue; | 631 continue; |
630 } | 632 } |
631 CounterNode* newParent = 0; | 633 RefPtr<CounterNode> newParent = 0; |
632 CounterNode* newPreviousSibling; | 634 RefPtr<CounterNode> newPreviousSibling = 0; |
633 | 635 |
634 findPlaceForCounter(renderer, AtomicString(it->first.get()), node->hasRe
setType(), newParent, newPreviousSibling); | 636 findPlaceForCounter(renderer, AtomicString(it->first.get()), node->hasRe
setType(), newParent, newPreviousSibling); |
635 if (node != counterMap->get(it->first.get())) | 637 if (node != counterMap->get(it->first.get())) |
636 continue; | 638 continue; |
637 CounterNode* parent = node->parent(); | 639 CounterNode* parent = node->parent(); |
638 if (newParent == parent && newPreviousSibling == node->previousSibling()
) | 640 if (newParent == parent && newPreviousSibling == node->previousSibling()
) |
639 continue; | 641 continue; |
640 if (parent) | 642 if (parent) |
641 parent->removeChild(node.get()); | 643 parent->removeChild(node.get()); |
642 if (newParent) | 644 if (newParent) |
643 newParent->insertAfter(node.get(), newPreviousSibling, it->first.get
()); | 645 newParent->insertAfter(node.get(), newPreviousSibling.get(), it->fir
st.get()); |
644 } | 646 } |
645 } | 647 } |
646 | 648 |
647 void RenderCounter::rendererSubtreeAttached(RenderObject* renderer) | 649 void RenderCounter::rendererSubtreeAttached(RenderObject* renderer) |
648 { | 650 { |
649 Node* node = renderer->node(); | 651 Node* node = renderer->node(); |
650 if (node) | 652 if (node) |
651 node = node->parentNode(); | 653 node = node->parentNode(); |
652 else | 654 else |
653 node = renderer->generatingNode(); | 655 node = renderer->generatingNode(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 fprintf(stderr, " "); | 721 fprintf(stderr, " "); |
720 fprintf(stderr, "%p N:%p P:%p PS:%p NS:%p C:%p\n", | 722 fprintf(stderr, "%p N:%p P:%p PS:%p NS:%p C:%p\n", |
721 current, current->node(), current->parent(), current->previousSiblin
g(), | 723 current, current->node(), current->parent(), current->previousSiblin
g(), |
722 current->nextSibling(), current->hasCounterNodeMap() ? | 724 current->nextSibling(), current->hasCounterNodeMap() ? |
723 counterName ? WebCore::counterMaps().get(current)->get(identifier.im
pl()).get() : (WebCore::CounterNode*)1 : (WebCore::CounterNode*)0); | 725 counterName ? WebCore::counterMaps().get(current)->get(identifier.im
pl()).get() : (WebCore::CounterNode*)1 : (WebCore::CounterNode*)0); |
724 } | 726 } |
725 fflush(stderr); | 727 fflush(stderr); |
726 } | 728 } |
727 | 729 |
728 #endif // NDEBUG | 730 #endif // NDEBUG |
OLD | NEW |