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/Noncopyable.h>
27 // This implements a counter tree that is used for finding parents in counters() lookup,
28 // and for propagating count changes when nodes are added or removed.
30 // Parents represent unique counters and their scope, which are created either explicitly
31 // by "counter-reset" style rules or implicitly by referring to a counter that is not in scope.
32 // Such nodes are tagged as "reset" nodes, although they are not all due to "counter-reset".
34 // Not that render tree children are often counter tree siblings due to counter scoping rules.
41 class CounterNode : public Noncopyable {
43 CounterNode(RenderObject*, bool isReset, int value);
45 bool isReset() const { return m_isReset; }
46 int value() const { return m_value; }
47 int countInParent() const { return m_countInParent; }
48 RenderObject* renderer() const { return m_renderer; }
50 CounterNode* parent() const { return m_parent; }
51 CounterNode* previousSibling() const { return m_previousSibling; }
52 CounterNode* nextSibling() const { return m_nextSibling; }
53 CounterNode* firstChild() const { return m_firstChild; }
54 CounterNode* lastChild() const { return m_lastChild; }
55 CounterNode* lastDescendant() const;
56 CounterNode* previousInPreOrder() const;
57 CounterNode* nextInPreOrder(const CounterNode* stayWithin = 0) const;
58 CounterNode* nextInPreOrderAfterChildren(const CounterNode* stayWithin = 0) const;
60 void insertAfter(CounterNode* newChild, CounterNode* beforeChild, const AtomicString& identifier);
61 void removeChild(CounterNode*, const AtomicString& identifier);
64 int computeCountInParent() const;
65 void recount(const AtomicString& identifier);
66 void resetRenderer(const AtomicString& identifier) const;
67 void resetRenderers(const AtomicString& identifier) const;
72 RenderObject* m_renderer;
74 CounterNode* m_parent;
75 CounterNode* m_previousSibling;
76 CounterNode* m_nextSibling;
77 CounterNode* m_firstChild;
78 CounterNode* m_lastChild;
81 } // namespace WebCore
84 // Outside the WebCore namespace for ease of invocation from gdb.
85 void showTree(const WebCore::CounterNode*);
88 #endif // CounterNode_h