KHtml

counter_tree.h
1 /*
2  * This file is part of the HTML rendering engine for KDE.
3  *
4  * Copyright (C) 2005 Allan Sandfeld Jensen ([email protected])
5  *
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.
10  *
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.
15  *
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.
20  *
21  */
22 #ifndef _Counter_Tree_h_
23 #define _Counter_Tree_h_
24 
25 #include "misc/shared.h"
26 #include "rendering/render_object.h"
27 
28 namespace khtml
29 {
30 
31 class CounterReset;
32 
33 // This file implements a counter-tree that is used for finding all parents in counters() lookup,
34 // and for propagating count-changes when nodes are added or removed.
35 // Please note that only counter-reset and root can be parents here, and that render-tree parents
36 // are just counter-tree siblings
37 
38 // Implementation of counter-increment and counter-content
39 class CounterNode
40 {
41 public:
42  CounterNode(RenderObject *o);
43  virtual ~CounterNode();
44 
45  CounterReset *parent() const
46  {
47  return m_parent;
48  }
49  CounterNode *previousSibling() const
50  {
51  return m_previous;
52  }
53  CounterNode *nextSibling() const
54  {
55  return m_next;
56  }
57  virtual CounterNode *firstChild() const
58  {
59  return nullptr;
60  }
61  virtual CounterNode *lastChild() const
62  {
63  return nullptr;
64  }
65  virtual void insertAfter(CounterNode *newChild, CounterNode *refChild);
66  virtual void removeChild(CounterNode *oldChild);
67  // Convenient self-referring version of the above
68  void remove();
69 
70  int value() const
71  {
72  return m_value;
73  }
74  void setValue(short v)
75  {
76  m_value = v;
77  }
78  int count() const
79  {
80  return m_count;
81  }
82 
83  virtual bool isReset()
84  {
85  return false;
86  }
87  virtual void recount(bool first = false);
88  virtual void setSelfDirty();
89  virtual void setParentDirty();
90 
91  bool hasCounters() const
92  {
93  return m_hasCounters;
94  }
95  bool isVisual() const
96  {
97  return m_isVisual;
98  }
99  void setHasCounters();
100  void setIsVisual()
101  {
102  m_isVisual = true;
103  }
104  bool isRoot()
105  {
106  return m_renderer && m_renderer->isRoot();
107  }
108 
109  void setRenderer(RenderObject *o)
110  {
111  m_renderer = o;
112  }
113  RenderObject *renderer() const
114  {
115  return m_renderer;
116  }
117 
118  friend class CounterReset;
119 protected:
120  bool m_hasCounters : 1;
121  bool m_isVisual : 1;
122  short m_value;
123  short m_count;
124  CounterReset *m_parent;
125  CounterNode *m_previous;
126  CounterNode *m_next;
127  RenderObject *m_renderer;
128 };
129 
130 // Implementation of counter-reset and root
131 class CounterReset : public CounterNode
132 {
133 public:
134  CounterReset(RenderObject *o);
135  virtual ~CounterReset();
136 
137  CounterNode *firstChild() const override
138  {
139  return m_first;
140  }
141  CounterNode *lastChild() const override
142  {
143  return m_last;
144  }
145  void insertAfter(CounterNode *newChild, CounterNode *refChild) override;
146  void removeChild(CounterNode *oldChild) override;
147 
148  bool isReset() override
149  {
150  return true;
151  }
152  void recount(bool first = false) override;
153  void setSelfDirty() override;
154  void setParentDirty() override;
155 
156  void updateTotal(int value);
157  // The highest value among children
158  int total() const
159  {
160  return m_total;
161  }
162 
163 protected:
164  int m_total;
165  CounterNode *m_first;
166  CounterNode *m_last;
167 };
168 
169 } // namespace
170 
171 #endif
172 
This file is part of the HTML rendering engine for KDE.
MESSAGECORE_EXPORT KMime::Content * firstChild(const KMime::Content *node)
MESSAGECORE_EXPORT KMime::Content * nextSibling(const KMime::Content *node)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:47:59 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.