blob: 7d6def81bdb7b7a36a97c0cb0c3be91e519b2dd8 [file] [log] [blame]
bdakin5d6edd42006-10-02 23:15:31 +00001/*
bdakin5d6edd42006-10-02 23:15:31 +00002 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
darinb5a0e3d2007-01-10 00:08:18 +00003 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
bdakin5d6edd42006-10-02 23:15:31 +00004 *
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
ddkilzerc8eccec2007-09-26 02:29:57 +000017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
bdakin5d6edd42006-10-02 23:15:31 +000019 *
20*/
darinec375482007-01-06 01:36:24 +000021
weinig1497a7e2006-10-26 20:23:55 +000022#ifndef CounterNode_h
23#define CounterNode_h
bdakin5d6edd42006-10-02 23:15:31 +000024
barraclough@apple.comd218c2d2010-08-10 00:38:14 +000025#include <wtf/Forward.h>
darinec375482007-01-06 01:36:24 +000026#include <wtf/Noncopyable.h>
jschuh@chromium.orge94df972010-09-30 20:31:45 +000027#include <wtf/RefCounted.h>
darinec375482007-01-06 01:36:24 +000028
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.
31
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".
35
36// Not that render tree children are often counter tree siblings due to counter scoping rules.
bdakin5d6edd42006-10-02 23:15:31 +000037
38namespace WebCore {
39
darinec375482007-01-06 01:36:24 +000040class RenderObject;
carol.szabo@nokia.com7cf0a552011-03-23 00:04:58 +000041class RenderCounter;
bdakin5d6edd42006-10-02 23:15:31 +000042
jschuh@chromium.orge94df972010-09-30 20:31:45 +000043class CounterNode : public RefCounted<CounterNode> {
bdakin5d6edd42006-10-02 23:15:31 +000044public:
jschuh@chromium.orge94df972010-09-30 20:31:45 +000045 static PassRefPtr<CounterNode> create(RenderObject*, bool isReset, int value);
carol.szabo@nokia.comd7917f72011-03-24 02:25:06 +000046 ~CounterNode();
eric@webkit.orgd8ca5e12009-12-21 20:11:47 +000047 bool actsAsReset() const { return m_hasResetType || !m_parent; }
48 bool hasResetType() const { return m_hasResetType; }
bdakin5d6edd42006-10-02 23:15:31 +000049 int value() const { return m_value; }
darinec375482007-01-06 01:36:24 +000050 int countInParent() const { return m_countInParent; }
carol.szabo@nokia.com7cf0a552011-03-23 00:04:58 +000051 RenderObject* owner() const { return m_owner; }
52 void addRenderer(RenderCounter*);
53 void removeRenderer(RenderCounter*);
54
55 // Invalidates the text in the renderers of this counter, if any.
56 void resetRenderers();
bdakin5d6edd42006-10-02 23:15:31 +000057
darinec375482007-01-06 01:36:24 +000058 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; }
eric@webkit.org02482712009-11-13 20:21:44 +000063 CounterNode* lastDescendant() const;
64 CounterNode* previousInPreOrder() const;
65 CounterNode* nextInPreOrder(const CounterNode* stayWithin = 0) const;
66 CounterNode* nextInPreOrderAfterChildren(const CounterNode* stayWithin = 0) const;
darinec375482007-01-06 01:36:24 +000067
eric@webkit.org02482712009-11-13 20:21:44 +000068 void insertAfter(CounterNode* newChild, CounterNode* beforeChild, const AtomicString& identifier);
eric@webkit.orgd8ca5e12009-12-21 20:11:47 +000069
70 // identifier must match the identifier of this counter.
carol.szabo@nokia.com7cf0a552011-03-23 00:04:58 +000071 void removeChild(CounterNode*);
darinec375482007-01-06 01:36:24 +000072
73private:
jschuh@chromium.orge94df972010-09-30 20:31:45 +000074 CounterNode(RenderObject*, bool isReset, int value);
darinec375482007-01-06 01:36:24 +000075 int computeCountInParent() const;
eric@webkit.orgd8ca5e12009-12-21 20:11:47 +000076 // Invalidates the text in the renderer of this counter, if any,
77 // and in the renderers of all descendants of this counter, if any.
carol.szabo@nokia.com7cf0a552011-03-23 00:04:58 +000078 void resetThisAndDescendantsRenderers();
79 void recount();
darinec375482007-01-06 01:36:24 +000080
eric@webkit.orgd8ca5e12009-12-21 20:11:47 +000081 bool m_hasResetType;
bdakin5d6edd42006-10-02 23:15:31 +000082 int m_value;
darinec375482007-01-06 01:36:24 +000083 int m_countInParent;
carol.szabo@nokia.com7cf0a552011-03-23 00:04:58 +000084 RenderObject* m_owner;
85 RenderCounter* m_rootRenderer;
darinec375482007-01-06 01:36:24 +000086
87 CounterNode* m_parent;
88 CounterNode* m_previousSibling;
89 CounterNode* m_nextSibling;
90 CounterNode* m_firstChild;
91 CounterNode* m_lastChild;
bdakin5d6edd42006-10-02 23:15:31 +000092};
93
94} // namespace WebCore
95
darinec375482007-01-06 01:36:24 +000096#ifndef NDEBUG
97// Outside the WebCore namespace for ease of invocation from gdb.
carol.szabo@nokia.com02635bf2011-02-05 00:28:57 +000098void showCounterTree(const WebCore::CounterNode*);
darinec375482007-01-06 01:36:24 +000099#endif
100
bdakin5d6edd42006-10-02 23:15:31 +0000101#endif // CounterNode_h