KHtml

html_tableimpl.h
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright (C) 1997 Martin Jones ([email protected])
5  * (C) 1997 Torben Weis ([email protected])
6  * (C) 1998 Waldo Bastian ([email protected])
7  * (C) 1999 Lars Knoll ([email protected])
8  * (C) 1999 Antti Koivisto ([email protected])
9  * (C) 2006 Maksim Orlovich ([email protected])
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public License
22  * along with this library; see the file COPYING.LIB. If not, write to
23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA 02110-1301, USA.
25  *
26  */
27 #ifndef HTML_TABLEIMPL_H
28 #define HTML_TABLEIMPL_H
29 
30 #include "html/html_elementimpl.h"
31 
32 namespace DOM
33 {
34 
35 class HTMLTableElementImpl;
36 class HTMLTableSectionElementImpl;
37 class HTMLTableSectionElement;
38 class HTMLTableRowElementImpl;
39 class HTMLTableRowElement;
40 class HTMLTableCellElementImpl;
41 class HTMLTableCellElement;
42 class HTMLTableColElementImpl;
43 class HTMLTableColElement;
44 class HTMLTableCaptionElementImpl;
45 class HTMLTableCaptionElement;
46 class HTMLElement;
47 
48 // -------------------------------------------------------------------------
49 
50 class HTMLTablePartElementImpl : public HTMLElementImpl
51 
52 {
53 public:
54  HTMLTablePartElementImpl(DocumentImpl *doc)
55  : HTMLElementImpl(doc)
56  { }
57 
58  void parseAttribute(AttributeImpl *attr) override;
59 };
60 
61 // -------------------------------------------------------------------------
62 
63 class HTMLTableSectionElementImpl : public HTMLTablePartElementImpl
64 {
65 public:
66  HTMLTableSectionElementImpl(DocumentImpl *doc, ushort tagid, bool implicit);
67 
68  ~HTMLTableSectionElementImpl();
69 
70  Id id() const override;
71 
72  HTMLElementImpl *insertRow(long index, int &exceptioncode);
73  void deleteRow(long index, int &exceptioncode);
74 
75  int numRows() const;
76 
77 protected:
78  ushort _id;
79 };
80 
81 // -------------------------------------------------------------------------
82 
83 class HTMLTableRowElementImpl : public HTMLTablePartElementImpl
84 {
85 public:
86  HTMLTableRowElementImpl(DocumentImpl *doc)
87  : HTMLTablePartElementImpl(doc) {}
88 
89  Id id() const override;
90 
91  long rowIndex() const;
92  long sectionRowIndex() const;
93 
94  HTMLElementImpl *insertCell(long index, int &exceptioncode);
95  void deleteCell(long index, int &exceptioncode);
96 
97 protected:
98  int ncols;
99 };
100 
101 // -------------------------------------------------------------------------
102 
103 class HTMLTableCellElementImpl : public HTMLTablePartElementImpl
104 {
105 public:
106  HTMLTableCellElementImpl(DocumentImpl *doc, int tagId);
107  ~HTMLTableCellElementImpl();
108 
109  long cellIndex() const;
110 
111  int col() const
112  {
113  return _col;
114  }
115  void setCol(int col)
116  {
117  _col = col;
118  }
119  int row() const
120  {
121  return _row;
122  }
123  void setRow(int r)
124  {
125  _row = r;
126  }
127 
128  int colSpan() const
129  {
130  return cSpan;
131  }
132  int rowSpan() const
133  {
134  return rSpan;
135  }
136 
137  Id id() const override
138  {
139  return _id;
140  }
141  void parseAttribute(AttributeImpl *attr) override;
142  void attach() override;
143 
144 protected:
145  int _row;
146  int _col;
147  int rSpan;
148  int cSpan;
149  int _id;
150  int rowHeight;
151  bool m_solid : 1;
152  bool m_nowrap : 1;
153 };
154 
155 // -------------------------------------------------------------------------
156 
157 class HTMLTableColElementImpl : public HTMLTablePartElementImpl
158 {
159 public:
160  HTMLTableColElementImpl(DocumentImpl *doc, ushort i);
161 
162  Id id() const override;
163 
164  void setTable(HTMLTableElementImpl *t)
165  {
166  table = t;
167  }
168 
169  // overrides
170  void parseAttribute(AttributeImpl *attr) override;
171 
172  int span() const
173  {
174  return _span;
175  }
176 
177 protected:
178  // could be ID_COL or ID_COLGROUP ... The DOM is not quite clear on
179  // this, but since both elements work quite similar, we use one
180  // DOMElement for them...
181  ushort _id;
182  int _span;
183  HTMLTableElementImpl *table;
184 };
185 
186 // -------------------------------------------------------------------------
187 
188 class HTMLTableCaptionElementImpl : public HTMLTablePartElementImpl
189 {
190 public:
191  HTMLTableCaptionElementImpl(DocumentImpl *doc)
192  : HTMLTablePartElementImpl(doc) {}
193 
194  Id id() const override;
195  void parseAttribute(AttributeImpl *attr) override;
196 };
197 
198 // -------------------------------------------------------------------------
199 
200 /*
201 This class helps memorize pointers to child objects that may be
202 yanked around via the DOM. It always picks the first pointer of the
203 given type.
204 
205 The pointer it stores can have 3 meanings:
206 0 -- no child
207 parent -- no idea about the state
208 other -- pointer to the child
209 */
210 template<typename ChildType, int ChildId> class ChildHolder
211 {
212 public:
213  ChildHolder(): ptr(nullptr) {}
214 
215  ChildType *get(const ElementImpl *parent) const
216  {
217  if (static_cast<const NodeImpl *>(ptr) == parent) {
218  //Do lookup.
219  ptr = nullptr;
220  for (NodeImpl *child = parent->firstChild(); child; child = child->nextSibling())
221  if (child->id() == ChildId) {
222  ptr = static_cast<ElementImpl *>(child);
223  break;
224  }
225  }
226  return static_cast<ChildType *>(ptr);
227  }
228 
229  void childAdded(ElementImpl *parent, NodeImpl *child)
230  {
231  if (ptr) {
232  ptr = parent; //No clue now..
233  } else {
234  ptr = child;
235  }
236  }
237 
238  void childAppended(NodeImpl *child)
239  {
240  if (!ptr) {
241  ptr = child;
242  }
243  }
244 
245  void childRemoved(ElementImpl *parent, NodeImpl *child)
246  {
247  if (child == ptr) {
248  ptr = parent; //We removed what was pointing - no clue now..
249  }
250  //else things are unchanged.
251  }
252 
253  void clear()
254  {
255  ptr = nullptr;
256  }
257 
258  void operator =(ChildType *child)
259  {
260  ptr = child;
261  }
262 private:
263  mutable NodeImpl *ptr;
264 };
265 
266 // -------------------------------------------------------------------------
267 class HTMLTableElementImpl : public HTMLElementImpl
268 {
269 public:
270  enum Rules {
271  None = 0x00,
272  RGroups = 0x01,
273  CGroups = 0x02,
274  Groups = 0x03,
275  Rows = 0x05,
276  Cols = 0x0a,
277  All = 0x0f
278  };
279  enum Frame {
280  Void = 0x00,
281  Above = 0x01,
282  Below = 0x02,
283  Lhs = 0x04,
284  Rhs = 0x08,
285  Hsides = 0x03,
286  Vsides = 0x0c,
287  Box = 0x0f
288  };
289 
290  HTMLTableElementImpl(DocumentImpl *doc);
291  ~HTMLTableElementImpl();
292 
293  Id id() const override;
294 
295  HTMLTableCaptionElementImpl *caption() const
296  {
297  return tCaption.get(this);
298  }
299  NodeImpl *setCaption(HTMLTableCaptionElementImpl *);
300 
301  HTMLTableSectionElementImpl *tHead() const
302  {
303  return head.get(this);
304  }
305  NodeImpl *setTHead(HTMLTableSectionElementImpl *);
306 
307  HTMLTableSectionElementImpl *tFoot() const
308  {
309  return foot.get(this);
310  }
311  NodeImpl *setTFoot(HTMLTableSectionElementImpl *);
312 
313  NodeImpl *setTBody(HTMLTableSectionElementImpl *);
314 
315  HTMLElementImpl *createTHead();
316  void deleteTHead();
317  HTMLElementImpl *createTFoot();
318  void deleteTFoot();
319  HTMLElementImpl *createCaption();
320  void deleteCaption();
321  HTMLElementImpl *insertRow(long index, int &exceptioncode);
322  void deleteRow(long index, int &exceptioncode);
323 
324  // overrides
325  NodeImpl *addChild(NodeImpl *child) override;
326  NodeImpl *insertBefore(NodeImpl *newChild, NodeImpl *refChild, int &exceptioncode) override;
327  void replaceChild(NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode) override;
328  void removeChild(NodeImpl *oldChild, int &exceptioncode) override;
329  void removeChildren() override;
330  NodeImpl *appendChild(NodeImpl *newChild, int &exceptioncode) override;
331 
332  void parseAttribute(AttributeImpl *attr) override;
333  void attach() override;
334  void close() override;
335 
336  /* Tries to find the section containing row number outIndex.
337  Returns whether it succeeded or not. negative outIndex values
338  are interpreted as being infinite.
339 
340  On success, outSection, outIndex points to section, and index in that
341  section.
342 
343  On failure, outSection points to the last section of the table, and
344  index is the offset the row would have if there was an additional section.
345  */
346  bool findRowSection(long inIndex,
347  HTMLTableSectionElementImpl *&outSection,
348  long &outIndex) const;
349 protected:
350  //Actual implementations of keeping things in place.
351  void handleChildAdd(NodeImpl *newChild);
352  void handleChildAppend(NodeImpl *newChild);
353  void handleChildRemove(NodeImpl *oldChild);
354 
355  void updateFrame();
356 
357  ChildHolder<HTMLTableSectionElementImpl, ID_THEAD> head;
358  ChildHolder<HTMLTableSectionElementImpl, ID_TFOOT> foot;
359  ChildHolder<HTMLTableSectionElementImpl, ID_TBODY> firstBody;
360  ChildHolder<HTMLTableCaptionElementImpl, ID_CAPTION> tCaption;
361 
362  HTMLTableSectionElementImpl *tFirstBody() const
363  {
364  return firstBody.get(this);
365  }
366 
367  KDE_BF_ENUM(Frame) frame : 4;
368  KDE_BF_ENUM(Rules) rules : 4;
369 
370  bool m_solid : 1;
371  uint unused : 7;
372  ushort padding : 16;
373  friend class HTMLTableCellElementImpl;
374 };
375 
376 } //namespace
377 
378 #endif
379 
QString caption()
const QList< QKeySequence > & close()
int64_t Id
This library provides a full-featured HTML parser and widget.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.