2 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
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.
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.
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.
25 #include <wtf/Forward.h>
26 #include <wtf/Noncopyable.h>
27 #include <wtf/RefCounted.h>
29 // This implements a counter tree that is used for finding parents in counters() lookup,
30 // and for propagating count changes when nodes are added or removed.
32 // Parents represent unique counters and their scope, which are created either explicitly
33 // by "counter-reset" style rules or implicitly by referring to a counter that is not in scope.
34 // Such nodes are tagged as "reset" nodes, although they are not all due to "counter-reset".
36 // Not that render tree children are often counter tree siblings due to counter scoping rules.
43 class CounterNode : public RefCounted<CounterNode> {
45 static PassRefPtr<CounterNode> create(RenderObject*, bool isReset, int value);
47 bool actsAsReset() const { return m_hasResetType || !m_parent; }
48 bool hasResetType() const { return m_hasResetType; }
49 int value() const { return m_value; }
50 int countInParent() const { return m_countInParent; }
51 RenderObject* owner() const { return m_owner; }
52 void addRenderer(RenderCounter*);
53 void removeRenderer(RenderCounter*);
55 // Invalidates the text in the renderers of this counter, if any.
56 void resetRenderers();
58 CounterNode* parent() const { return m_parent; }
59 CounterNode* previousSibling() const { return m_previousSibling; }
60 CounterNode* nextSibling() const { return m_nextSibling; }
61 CounterNode* firstChild() const { return m_firstChild; }
62 CounterNode* lastChild() const { return m_lastChild; }
63 CounterNode* lastDescendant() const;
64 CounterNode* previousInPreOrder() const;
65 CounterNode* nextInPreOrder(const CounterNode* stayWithin = 0) const;
66 CounterNode* nextInPreOrderAfterChildren(const CounterNode* stayWithin = 0) const;
68 void insertAfter(CounterNode* newChild, CounterNode* beforeChild, const AtomicString& identifier);
70 // identifier must match the identifier of this counter.
71 void removeChild(CounterNode*);
74 CounterNode(RenderObject*, bool isReset, int value);
75 int computeCountInParent() const;
76 // Invalidates the text in the renderer of this counter, if any,
77 // and in the renderers of all descendants of this counter, if any.
78 void resetThisAndDescendantsRenderers();
84 RenderObject* m_owner;
85 RenderCounter* m_rootRenderer;
87 CounterNode* m_parent;
88 CounterNode* m_previousSibling;
89 CounterNode* m_nextSibling;
90 CounterNode* m_firstChild;
91 CounterNode* m_lastChild;
94 } // namespace WebCore
97 // Outside the WebCore namespace for ease of invocation from gdb.
98 void showCounterTree(const WebCore::CounterNode*);
101 #endif // CounterNode_h