2 * This file is part of the HTML rendering engine for KDE.
4 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #ifndef _Counter_Tree_h_
23 #define _Counter_Tree_h_
25 #include "misc/shared.h"
26 #include "rendering/render_object.h"
32 // This file implements a counter-tree that is used for finding all parents in counters() lookup,
33 // and for propagating count-changes when nodes are added or removed.
34 // Please note that only counter-reset and root can be parents here, and that render-tree parents
35 // are just counter-tree siblings
37 // Implementation of counter-increment and counter-content
41 CounterNode(RenderObject
*o
);
42 virtual ~CounterNode();
44 CounterReset
* parent() const { return m_parent
; }
45 CounterNode
* previousSibling() const { return m_previous
; }
46 CounterNode
* nextSibling() const { return m_next
; }
47 virtual CounterNode
* firstChild() const { return 0; }
48 virtual CounterNode
* lastChild() const { return 0; }
49 virtual void insertAfter ( CounterNode
*newChild
, CounterNode
*refChild
);
50 virtual void removeChild ( CounterNode
*oldChild
);
51 // Convenient self-referring version of the above
54 int value() const { return m_value
; }
55 void setValue(short v
) { m_value
= v
; }
56 int count() const { return m_count
; }
58 virtual bool isReset() { return false; }
59 virtual void recount( bool first
= false );
60 virtual void setSelfDirty();
61 virtual void setParentDirty();
63 bool hasCounters() const { return m_hasCounters
; }
64 bool isVisual() const { return m_isVisual
; }
65 void setHasCounters();
66 void setIsVisual() { m_isVisual
= true; }
67 bool isRoot() { return m_renderer
&& m_renderer
->isRoot(); }
69 void setRenderer(RenderObject
*o
) { m_renderer
= o
; }
70 RenderObject
* renderer() const { return m_renderer
; }
72 friend class CounterReset
;
74 bool m_hasCounters
: 1;
78 CounterReset
*m_parent
;
79 CounterNode
*m_previous
;
81 RenderObject
*m_renderer
;
84 // Implementation of counter-reset and root
85 class CounterReset
: public CounterNode
88 CounterReset(RenderObject
*o
);
89 virtual ~CounterReset();
91 virtual CounterNode
*firstChild() const { return m_first
; }
92 virtual CounterNode
*lastChild() const { return m_last
; }
93 virtual void insertAfter ( CounterNode
*newChild
, CounterNode
*refChild
);
94 virtual void removeChild ( CounterNode
*oldChild
);
96 virtual bool isReset() { return true; }
97 virtual void recount( bool first
= false );
98 virtual void setSelfDirty();
99 virtual void setParentDirty();
101 void updateTotal(int value
);
102 // The highest value among children
103 int total() const { return m_total
; }
107 CounterNode
*m_first
;