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