ff1b355e39fb0f6f702761eab24f98c67149d355
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderCounter.cpp
1 /**
2  * Copyright (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com)
3  * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
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
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  */
21
22 #include "config.h"
23 #include "core/rendering/RenderCounter.h"
24
25 #include "core/HTMLNames.h"
26 #include "core/dom/Element.h"
27 #include "core/dom/ElementTraversal.h"
28 #include "core/html/HTMLOListElement.h"
29 #include "core/rendering/CounterNode.h"
30 #include "core/rendering/RenderListItem.h"
31 #include "core/rendering/RenderListMarker.h"
32 #include "core/rendering/RenderView.h"
33 #include "core/rendering/style/RenderStyle.h"
34 #include "wtf/StdLibExtras.h"
35
36 #ifndef NDEBUG
37 #include <stdio.h>
38 #endif
39
40 namespace blink {
41
42 using namespace HTMLNames;
43
44 typedef HashMap<AtomicString, RefPtr<CounterNode> > CounterMap;
45 typedef HashMap<const RenderObject*, OwnPtr<CounterMap> > CounterMaps;
46
47 static CounterNode* makeCounterNode(RenderObject&, const AtomicString& identifier, bool alwaysCreateCounter);
48
49 static CounterMaps& counterMaps()
50 {
51     DEFINE_STATIC_LOCAL(CounterMaps, staticCounterMaps, ());
52     return staticCounterMaps;
53 }
54
55 // This function processes the renderer tree in the order of the DOM tree
56 // including pseudo elements as defined in CSS 2.1.
57 static RenderObject* previousInPreOrder(const RenderObject& object)
58 {
59     Element* self = toElement(object.node());
60     ASSERT(self);
61     Element* previous = ElementTraversal::previousIncludingPseudo(*self);
62     while (previous && !previous->renderer())
63         previous = ElementTraversal::previousIncludingPseudo(*previous);
64     return previous ? previous->renderer() : 0;
65 }
66
67 // This function processes the renderer tree in the order of the DOM tree
68 // including pseudo elements as defined in CSS 2.1.
69 static RenderObject* previousSiblingOrParent(const RenderObject& object)
70 {
71     Element* self = toElement(object.node());
72     ASSERT(self);
73     Element* previous = ElementTraversal::pseudoAwarePreviousSibling(*self);
74     while (previous && !previous->renderer())
75         previous = ElementTraversal::pseudoAwarePreviousSibling(*previous);
76     if (previous)
77         return previous->renderer();
78     previous = self->parentElement();
79     return previous ? previous->renderer() : 0;
80 }
81
82 static inline Element* parentElement(RenderObject& object)
83 {
84     return toElement(object.node())->parentElement();
85 }
86
87 static inline bool areRenderersElementsSiblings(RenderObject& first, RenderObject& second)
88 {
89     return parentElement(first) == parentElement(second);
90 }
91
92 // This function processes the renderer tree in the order of the DOM tree
93 // including pseudo elements as defined in CSS 2.1.
94 static RenderObject* nextInPreOrder(const RenderObject& object, const Element* stayWithin, bool skipDescendants = false)
95 {
96     Element* self = toElement(object.node());
97     ASSERT(self);
98     Element* next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingChildren(*self, stayWithin) : ElementTraversal::nextIncludingPseudo(*self, stayWithin);
99     while (next && !next->renderer())
100         next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingChildren(*next, stayWithin) : ElementTraversal::nextIncludingPseudo(*next, stayWithin);
101     return next ? next->renderer() : 0;
102 }
103
104 static bool planCounter(RenderObject& object, const AtomicString& identifier, bool& isReset, int& value)
105 {
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 increments!
108     if (object.isText() && !object.isBR())
109         return false;
110     Node* generatingNode = object.generatingNode();
111     // We must have a generating node or else we cannot have a counter.
112     if (!generatingNode)
113         return false;
114     RenderStyle* style = object.style();
115     ASSERT(style);
116
117     switch (style->styleType()) {
118     case NOPSEUDO:
119         // Sometimes nodes have more then one renderer. Only the first one gets the counter
120         // LayoutTests/http/tests/css/counter-crash.html
121         if (generatingNode->renderer() != &object)
122             return false;
123         break;
124     case BEFORE:
125     case AFTER:
126         break;
127     default:
128         return false; // Counters are forbidden from all other pseudo elements.
129     }
130
131     const CounterDirectives directives = style->getCounterDirectives(identifier);
132     if (directives.isDefined()) {
133         value = directives.combinedValue();
134         isReset = directives.isReset();
135         return true;
136     }
137
138     if (identifier == "list-item") {
139         if (object.isListItem()) {
140             if (toRenderListItem(object).hasExplicitValue()) {
141                 value = toRenderListItem(object).explicitValue();
142                 isReset = true;
143                 return true;
144             }
145             value = 1;
146             isReset = false;
147             return true;
148         }
149         if (Node* e = object.node()) {
150             if (isHTMLOListElement(*e)) {
151                 value = toHTMLOListElement(e)->start();
152                 isReset = true;
153                 return true;
154             }
155             if (isHTMLUListElement(*e) || isHTMLMenuElement(*e) || isHTMLDirectoryElement(*e)) {
156                 value = 0;
157                 isReset = true;
158                 return true;
159             }
160         }
161     }
162
163     return false;
164 }
165
166 // - Finds the insertion point for the counter described by counterOwner, isReset and
167 // identifier in the CounterNode tree for identifier and sets parent and
168 // previousSibling accordingly.
169 // - The function returns true if the counter whose insertion point is searched is NOT
170 // the root of the tree.
171 // - The root of the tree is a counter reference that is not in the scope of any other
172 // counter with the same identifier.
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 tree
175 // form the rest of of the nodes of the tree.
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
178 // references that are in the scope of the counter or nested counter defined by that
179 // reset node.
180 // - Non-reset CounterNodes cannot have descendants.
181
182 static bool findPlaceForCounter(RenderObject& counterOwner, const AtomicString& identifier, bool isReset, RefPtr<CounterNode>& parent, RefPtr<CounterNode>& previousSibling)
183 {
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.
186     RenderObject* searchEndRenderer = previousSiblingOrParent(counterOwner);
187     // We check renderers in preOrder from the renderer that our counter is attached to
188     // towards the begining of the document for counters with the same identifier as the one
189     // we are trying to find a place for. This is the next renderer to be checked.
190     RenderObject* currentRenderer = previousInPreOrder(counterOwner);
191     previousSibling = nullptr;
192     RefPtr<CounterNode> previousSiblingProtector = nullptr;
193
194     while (currentRenderer) {
195         CounterNode* currentCounter = makeCounterNode(*currentRenderer, identifier, false);
196         if (searchEndRenderer == currentRenderer) {
197             // We may be at the end of our search.
198             if (currentCounter) {
199                 // We have a suitable counter on the EndSearchRenderer.
200                 if (previousSiblingProtector) { // But we already found another counter that we come after.
201                     if (currentCounter->actsAsReset()) {
202                         // We found a reset counter that is on a renderer that is a sibling of ours or a parent.
203                         if (isReset && areRenderersElementsSiblings(*currentRenderer, counterOwner)) {
204                             // We are also a reset counter and the previous reset was on a sibling renderer
205                             // 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.
207                             parent = currentCounter->parent();
208                             previousSibling = parent ? currentCounter : 0;
209                             return parent;
210                         }
211                         // We are not a reset node or the previous reset must be on an ancestor of our owner renderer
212                         // hence we must be a child of that reset counter.
213                         parent = currentCounter;
214                         // In some cases renders can be reparented (ex. nodes 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
216                         // our identified parent.
217                         if (previousSiblingProtector->parent() != currentCounter)
218                             previousSiblingProtector = nullptr;
219
220                         previousSibling = previousSiblingProtector.get();
221                         return true;
222                     }
223                     // CurrentCounter, the counter at the EndSearchRenderer, is not reset.
224                     if (!isReset || !areRenderersElementsSiblings(*currentRenderer, counterOwner)) {
225                         // If the node we are placing is not reset or we have found a counter that is attached
226                         // to an ancestor of the placed counter's owner renderer we know we are a sibling of that node.
227                         if (currentCounter->parent() != previousSiblingProtector->parent())
228                             return false;
229
230                         parent = currentCounter->parent();
231                         previousSibling = previousSiblingProtector.get();
232                         return true;
233                     }
234                 } else {
235                     // We are at the potential end of the search, but we had no previous sibling candidate
236                     // In this case we follow pretty much the same logic as above but no ASSERTs about
237                     // previousSibling, and when we are a sibling of the end counter we must set previousSibling
238                     // to currentCounter.
239                     if (currentCounter->actsAsReset()) {
240                         if (isReset && areRenderersElementsSiblings(*currentRenderer, counterOwner)) {
241                             parent = currentCounter->parent();
242                             previousSibling = currentCounter;
243                             return parent;
244                         }
245                         parent = currentCounter;
246                         previousSibling = previousSiblingProtector.get();
247                         return true;
248                     }
249                     if (!isReset || !areRenderersElementsSiblings(*currentRenderer, counterOwner)) {
250                         parent = currentCounter->parent();
251                         previousSibling = currentCounter;
252                         return true;
253                     }
254                     previousSiblingProtector = currentCounter;
255                 }
256             }
257             // We come here if the previous sibling or parent of our owner renderer had no
258             // good counter, or we are a reset node and the counter on the previous sibling
259             // of our owner renderer was not a reset counter.
260             // Set a new goal for the end of the search.
261             searchEndRenderer = previousSiblingOrParent(*currentRenderer);
262         } else {
263             // We are searching descendants of a previous sibling of the renderer that the
264             // counter being placed is attached to.
265             if (currentCounter) {
266                 // We found a suitable counter.
267                 if (previousSiblingProtector) {
268                     // Since we had a suitable previous counter before, we should only consider this one as our
269                     // previousSibling if it is a reset counter and hence the current previousSibling is its child.
270                     if (currentCounter->actsAsReset()) {
271                         previousSiblingProtector = currentCounter;
272                         // We are no longer interested in previous siblings of the currentRenderer or their children
273                         // as counters they may have attached cannot be the previous sibling of the counter we are placing.
274                         currentRenderer = parentElement(*currentRenderer)->renderer();
275                         continue;
276                     }
277                 } else
278                     previousSiblingProtector = currentCounter;
279                 currentRenderer = previousSiblingOrParent(*currentRenderer);
280                 continue;
281             }
282         }
283         // 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 points though, to accommodate this
285         // performance improvement would create more code duplication than is worthwhile in my oppinion and may further
286         // impede the readability of this already complex algorithm.
287         if (previousSiblingProtector)
288             currentRenderer = previousSiblingOrParent(*currentRenderer);
289         else
290             currentRenderer = previousInPreOrder(*currentRenderer);
291     }
292     return false;
293 }
294
295 static CounterNode* makeCounterNode(RenderObject& object, const AtomicString& identifier, bool alwaysCreateCounter)
296 {
297     if (object.hasCounterNodeMap()) {
298         if (CounterMap* nodeMap = counterMaps().get(&object)) {
299             if (CounterNode* node = nodeMap->get(identifier))
300                 return node;
301         }
302     }
303
304     bool isReset = false;
305     int value = 0;
306     if (!planCounter(object, identifier, isReset, value) && !alwaysCreateCounter)
307         return 0;
308
309     RefPtr<CounterNode> newParent = nullptr;
310     RefPtr<CounterNode> newPreviousSibling = nullptr;
311     RefPtr<CounterNode> newNode = CounterNode::create(object, isReset, value);
312     if (findPlaceForCounter(object, identifier, isReset, newParent, newPreviousSibling))
313         newParent->insertAfter(newNode.get(), newPreviousSibling.get(), identifier);
314     CounterMap* nodeMap;
315     if (object.hasCounterNodeMap())
316         nodeMap = counterMaps().get(&object);
317     else {
318         nodeMap = new CounterMap;
319         counterMaps().set(&object, adoptPtr(nodeMap));
320         object.setHasCounterNodeMap(true);
321     }
322     nodeMap->set(identifier, newNode);
323     if (newNode->parent())
324         return newNode.get();
325     // Checking if some nodes that were previously counter tree root nodes
326     // should become children of this node now.
327     CounterMaps& maps = counterMaps();
328     Element* stayWithin = parentElement(object);
329     bool skipDescendants;
330     for (RenderObject* currentRenderer = nextInPreOrder(object, stayWithin); currentRenderer; currentRenderer = nextInPreOrder(*currentRenderer, stayWithin, skipDescendants)) {
331         skipDescendants = false;
332         if (!currentRenderer->hasCounterNodeMap())
333             continue;
334         CounterNode* currentCounter = maps.get(currentRenderer)->get(identifier);
335         if (!currentCounter)
336             continue;
337         skipDescendants = true;
338         if (currentCounter->parent())
339             continue;
340         if (stayWithin == parentElement(*currentRenderer) && currentCounter->hasResetType())
341             break;
342         newNode->insertAfter(currentCounter, newNode->lastChild(), identifier);
343     }
344     return newNode.get();
345 }
346
347 RenderCounter::RenderCounter(Document* node, const CounterContent& counter)
348     : RenderText(node, StringImpl::empty())
349     , m_counter(counter)
350     , m_counterNode(0)
351     , m_nextForSameCounter(0)
352 {
353     view()->addRenderCounter();
354 }
355
356 RenderCounter::~RenderCounter()
357 {
358     if (m_counterNode) {
359         m_counterNode->removeRenderer(this);
360         ASSERT(!m_counterNode);
361     }
362 }
363
364 void RenderCounter::willBeDestroyed()
365 {
366     if (view())
367         view()->removeRenderCounter();
368     RenderText::willBeDestroyed();
369 }
370
371 const char* RenderCounter::renderName() const
372 {
373     return "RenderCounter";
374 }
375
376 bool RenderCounter::isCounter() const
377 {
378     return true;
379 }
380
381 PassRefPtr<StringImpl> RenderCounter::originalText() const
382 {
383     if (!m_counterNode) {
384         RenderObject* beforeAfterContainer = parent();
385         while (true) {
386             if (!beforeAfterContainer)
387                 return nullptr;
388             if (!beforeAfterContainer->isAnonymous() && !beforeAfterContainer->isPseudoElement())
389                 return nullptr; // RenderCounters are restricted to before and after pseudo elements
390             PseudoId containerStyle = beforeAfterContainer->style()->styleType();
391             if ((containerStyle == BEFORE) || (containerStyle == AFTER))
392                 break;
393             beforeAfterContainer = beforeAfterContainer->parent();
394         }
395         makeCounterNode(*beforeAfterContainer, m_counter.identifier(), true)->addRenderer(const_cast<RenderCounter*>(this));
396         ASSERT(m_counterNode);
397     }
398     CounterNode* child = m_counterNode;
399     int value = child->actsAsReset() ? child->value() : child->countInParent();
400
401     String text = listMarkerText(m_counter.listStyle(), value);
402
403     if (!m_counter.separator().isNull()) {
404         if (!child->actsAsReset())
405             child = child->parent();
406         while (CounterNode* parent = child->parent()) {
407             text = listMarkerText(m_counter.listStyle(), child->countInParent())
408                 + m_counter.separator() + text;
409             child = parent;
410         }
411     }
412
413     return text.impl();
414 }
415
416 void RenderCounter::updateCounter()
417 {
418     setTextInternal(originalText());
419 }
420
421 void RenderCounter::invalidate()
422 {
423     m_counterNode->removeRenderer(this);
424     ASSERT(!m_counterNode);
425     if (documentBeingDestroyed())
426         return;
427     setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
428 }
429
430 static void destroyCounterNodeWithoutMapRemoval(const AtomicString& identifier, CounterNode* node)
431 {
432     CounterNode* previous;
433     for (RefPtr<CounterNode> child = node->lastDescendant(); child && child != node; child = previous) {
434         previous = child->previousInPreOrder();
435         child->parent()->removeChild(child.get());
436         ASSERT(counterMaps().get(&child->owner())->get(identifier) == child);
437         counterMaps().get(&child->owner())->remove(identifier);
438     }
439     if (CounterNode* parent = node->parent())
440         parent->removeChild(node);
441 }
442
443 void RenderCounter::destroyCounterNodes(RenderObject& owner)
444 {
445     CounterMaps& maps = counterMaps();
446     CounterMaps::iterator mapsIterator = maps.find(&owner);
447     if (mapsIterator == maps.end())
448         return;
449     CounterMap* map = mapsIterator->value.get();
450     CounterMap::const_iterator end = map->end();
451     for (CounterMap::const_iterator it = map->begin(); it != end; ++it) {
452         destroyCounterNodeWithoutMapRemoval(it->key, it->value.get());
453     }
454     maps.remove(mapsIterator);
455     owner.setHasCounterNodeMap(false);
456 }
457
458 void RenderCounter::destroyCounterNode(RenderObject& owner, const AtomicString& identifier)
459 {
460     CounterMap* map = counterMaps().get(&owner);
461     if (!map)
462         return;
463     CounterMap::iterator mapIterator = map->find(identifier);
464     if (mapIterator == map->end())
465         return;
466     destroyCounterNodeWithoutMapRemoval(identifier, mapIterator->value.get());
467     map->remove(mapIterator);
468     // 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     // a style change for the renderer involving removal of all counter
471     // directives must occur, in which case, RenderCounter::destroyCounterNodes()
472     // must be called.
473     // 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     // destruction of all counters attached to a Renderer. In this case
476     // RenderCounter::destroyCounterNodes() must be and is now called, too.
477     // RenderCounter::destroyCounterNodes() handles destruction of the counter
478     // map associated with a renderer, so there is no risk in leaking the map.
479 }
480
481 void RenderCounter::rendererRemovedFromTree(RenderObject* renderer)
482 {
483     ASSERT(renderer->view());
484     if (!renderer->view()->hasRenderCounters())
485         return;
486     RenderObject* currentRenderer = renderer->lastLeafChild();
487     if (!currentRenderer)
488         currentRenderer = renderer;
489     while (true) {
490         destroyCounterNodes(*currentRenderer);
491         if (currentRenderer == renderer)
492             break;
493         currentRenderer = currentRenderer->previousInPreOrder();
494     }
495 }
496
497 static void updateCounters(RenderObject& renderer)
498 {
499     ASSERT(renderer.style());
500     const CounterDirectiveMap* directiveMap = renderer.style()->counterDirectives();
501     if (!directiveMap)
502         return;
503     CounterDirectiveMap::const_iterator end = directiveMap->end();
504     if (!renderer.hasCounterNodeMap()) {
505         for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it != end; ++it)
506             makeCounterNode(renderer, it->key, false);
507         return;
508     }
509     CounterMap* counterMap = counterMaps().get(&renderer);
510     ASSERT(counterMap);
511     for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it != end; ++it) {
512         RefPtr<CounterNode> node = counterMap->get(it->key);
513         if (!node) {
514             makeCounterNode(renderer, it->key, false);
515             continue;
516         }
517         RefPtr<CounterNode> newParent = nullptr;
518         RefPtr<CounterNode> newPreviousSibling = nullptr;
519
520         findPlaceForCounter(renderer, it->key, node->hasResetType(), newParent, newPreviousSibling);
521         if (node != counterMap->get(it->key))
522             continue;
523         CounterNode* parent = node->parent();
524         if (newParent == parent && newPreviousSibling == node->previousSibling())
525             continue;
526         if (parent)
527             parent->removeChild(node.get());
528         if (newParent)
529             newParent->insertAfter(node.get(), newPreviousSibling.get(), it->key);
530     }
531 }
532
533 void RenderCounter::rendererSubtreeAttached(RenderObject* renderer)
534 {
535     ASSERT(renderer->view());
536     if (!renderer->view()->hasRenderCounters())
537         return;
538     Node* node = renderer->node();
539     if (node)
540         node = node->parentNode();
541     else
542         node = renderer->generatingNode();
543     if (node && node->needsAttach())
544         return; // No need to update if the parent is not attached yet
545     for (RenderObject* descendant = renderer; descendant; descendant = descendant->nextInPreOrder(renderer))
546         updateCounters(*descendant);
547 }
548
549 void RenderCounter::rendererStyleChanged(RenderObject& renderer, const RenderStyle* oldStyle, const RenderStyle* newStyle)
550 {
551     Node* node = renderer.generatingNode();
552     if (!node || node->needsAttach())
553         return; // cannot have generated content or if it can have, it will be handled during attaching
554     const CounterDirectiveMap* oldCounterDirectives = oldStyle ? oldStyle->counterDirectives() : 0;
555     const CounterDirectiveMap* newCounterDirectives = newStyle ? newStyle->counterDirectives() : 0;
556     if (oldCounterDirectives) {
557         if (newCounterDirectives) {
558             CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives->end();
559             CounterDirectiveMap::const_iterator oldMapEnd = oldCounterDirectives->end();
560             for (CounterDirectiveMap::const_iterator it = newCounterDirectives->begin(); it != newMapEnd; ++it) {
561                 CounterDirectiveMap::const_iterator oldMapIt = oldCounterDirectives->find(it->key);
562                 if (oldMapIt != oldMapEnd) {
563                     if (oldMapIt->value == it->value)
564                         continue;
565                     RenderCounter::destroyCounterNode(renderer, it->key);
566                 }
567                 // We must create this node here, because the changed node may be 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                 // not catch the change if the node had no children.
570                 makeCounterNode(renderer, it->key, false);
571             }
572             // Destroying old counters that do not exist in the new counterDirective map.
573             for (CounterDirectiveMap::const_iterator it = oldCounterDirectives->begin(); it !=oldMapEnd; ++it) {
574                 if (!newCounterDirectives->contains(it->key))
575                     RenderCounter::destroyCounterNode(renderer, it->key);
576             }
577         } else {
578             if (renderer.hasCounterNodeMap())
579                 RenderCounter::destroyCounterNodes(renderer);
580         }
581     } else if (newCounterDirectives) {
582         CounterDirectiveMap::const_iterator newMapEnd = newCounterDirectives->end();
583         for (CounterDirectiveMap::const_iterator it = newCounterDirectives->begin(); it != newMapEnd; ++it) {
584             // We must create this node here, because the added node may be a node with no display such as
585             // 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             makeCounterNode(renderer, it->key, false);
588         }
589     }
590 }
591
592 } // namespace blink
593
594 #ifndef NDEBUG
595
596 void showCounterRendererTree(const blink::RenderObject* renderer, const char* counterName)
597 {
598     if (!renderer)
599         return;
600     const blink::RenderObject* root = renderer;
601     while (root->parent())
602         root = root->parent();
603
604     AtomicString identifier(counterName);
605     for (const blink::RenderObject* current = root; current; current = current->nextInPreOrder()) {
606         fprintf(stderr, "%c", (current == renderer) ? '*' : ' ');
607         for (const blink::RenderObject* parent = current; parent && parent != root; parent = parent->parent())
608             fprintf(stderr, "    ");
609         fprintf(stderr, "%p N:%p P:%p PS:%p NS:%p C:%p\n",
610             current, current->node(), current->parent(), current->previousSibling(),
611             current->nextSibling(), current->hasCounterNodeMap() ?
612             counterName ? blink::counterMaps().get(current)->get(identifier) : (blink::CounterNode*)1 : (blink::CounterNode*)0);
613     }
614     fflush(stderr);
615 }
616
617 #endif // NDEBUG