|
1 /* |
|
2 * This file is part of the DOM implementation for KDE. |
|
3 * |
|
4 * Copyright (C) 1997 Martin Jones (mjones@kde.org) |
|
5 * (C) 1997 Torben Weis (weis@kde.org) |
|
6 * (C) 1998 Waldo Bastian (bastian@kde.org) |
|
7 * (C) 1999 Lars Knoll (knoll@kde.org) |
|
8 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
|
9 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. |
|
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 RenderTable_h |
|
28 #define RenderTable_h |
|
29 |
|
30 #include "RenderBlock.h" |
|
31 #include <wtf/Vector.h> |
|
32 |
|
33 namespace WebCore { |
|
34 |
|
35 class RenderTableCol; |
|
36 class RenderTableCell; |
|
37 class RenderTableSection; |
|
38 class TableLayout; |
|
39 |
|
40 class RenderTable : public RenderBlock { |
|
41 public: |
|
42 enum Rules { |
|
43 None = 0x00, |
|
44 RGroups = 0x01, |
|
45 CGroups = 0x02, |
|
46 Groups = 0x03, |
|
47 Rows = 0x05, |
|
48 Cols = 0x0a, |
|
49 All = 0x0f |
|
50 }; |
|
51 enum Frame { |
|
52 Void = 0x00, |
|
53 Above = 0x01, |
|
54 Below = 0x02, |
|
55 Lhs = 0x04, |
|
56 Rhs = 0x08, |
|
57 Hsides = 0x03, |
|
58 Vsides = 0x0c, |
|
59 Box = 0x0f |
|
60 }; |
|
61 |
|
62 RenderTable(Node*); |
|
63 ~RenderTable(); |
|
64 |
|
65 virtual const char* renderName() const { return "RenderTable"; } |
|
66 |
|
67 virtual bool isTable() const { return true; } |
|
68 |
|
69 virtual void setStyle(RenderStyle*); |
|
70 |
|
71 virtual bool avoidsFloats() const { return true; } |
|
72 |
|
73 int getColumnPos(int col) const { return m_columnPos[col]; } |
|
74 |
|
75 int hBorderSpacing() const { return m_hSpacing; } |
|
76 int vBorderSpacing() const { return m_vSpacing; } |
|
77 |
|
78 bool collapseBorders() const { return style()->borderCollapse(); } |
|
79 int borderLeft() const { return m_borderLeft; } |
|
80 int borderRight() const { return m_borderRight; } |
|
81 int borderTop() const; |
|
82 int borderBottom() const; |
|
83 |
|
84 Rules getRules() const { return static_cast<Rules>(m_rules); } |
|
85 |
|
86 const Color& bgColor() const { return style()->backgroundColor(); } |
|
87 |
|
88 unsigned cellPadding() const { return m_padding; } |
|
89 void setCellPadding(unsigned p) { m_padding = p; } |
|
90 |
|
91 int outerBorderTop() const; |
|
92 int outerBorderBottom() const; |
|
93 int outerBorderLeft() const; |
|
94 int outerBorderRight() const; |
|
95 |
|
96 int calcBorderLeft() const; |
|
97 int calcBorderRight() const; |
|
98 void recalcHorizontalBorders(); |
|
99 |
|
100 // overrides |
|
101 virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0); |
|
102 virtual void paint(PaintInfo&, int tx, int ty); |
|
103 virtual void paintBoxDecorations(PaintInfo&, int tx, int ty); |
|
104 virtual void layout(); |
|
105 virtual void calcPrefWidths(); |
|
106 |
|
107 virtual RenderBlock* firstLineBlock() const; |
|
108 virtual void updateFirstLetter(); |
|
109 |
|
110 virtual void setCellWidths(); |
|
111 |
|
112 virtual void calcWidth(); |
|
113 |
|
114 struct ColumnStruct { |
|
115 enum { |
|
116 WidthUndefined = 0xffff |
|
117 }; |
|
118 |
|
119 ColumnStruct() |
|
120 : span(1) |
|
121 , width(WidthUndefined) |
|
122 { |
|
123 } |
|
124 |
|
125 unsigned short span; |
|
126 unsigned width; // the calculated position of the column |
|
127 }; |
|
128 |
|
129 Vector<ColumnStruct>& columns() { return m_columns; } |
|
130 Vector<int>& columnPositions() { return m_columnPos; } |
|
131 RenderTableSection* header() const { return m_head; } |
|
132 RenderTableSection* footer() const { return m_foot; } |
|
133 RenderTableSection* firstBody() const { return m_firstBody; } |
|
134 |
|
135 void splitColumn(int pos, int firstSpan); |
|
136 void appendColumn(int span); |
|
137 int numEffCols() const { return m_columns.size(); } |
|
138 int spanOfEffCol(int effCol) const { return m_columns[effCol].span; } |
|
139 |
|
140 int colToEffCol(int col) const |
|
141 { |
|
142 int i = 0; |
|
143 int effCol = numEffCols(); |
|
144 for (int c = 0; c < col && i < effCol; ++i) |
|
145 c += m_columns[i].span; |
|
146 return i; |
|
147 } |
|
148 |
|
149 int effColToCol(int effCol) const |
|
150 { |
|
151 int c = 0; |
|
152 for (int i = 0; i < effCol; i++) |
|
153 c += m_columns[i].span; |
|
154 return c; |
|
155 } |
|
156 |
|
157 int bordersPaddingAndSpacing() const |
|
158 { |
|
159 return borderLeft() + borderRight() + |
|
160 (collapseBorders() ? 0 : (paddingLeft() + paddingRight() + (numEffCols() + 1) * hBorderSpacing())); |
|
161 } |
|
162 |
|
163 RenderTableCol* colElement(int col, bool* startEdge = 0, bool* endEdge = 0) const; |
|
164 |
|
165 bool needsSectionRecalc() const { return m_needsSectionRecalc; } |
|
166 void setNeedsSectionRecalc() |
|
167 { |
|
168 if (documentBeingDestroyed()) |
|
169 return; |
|
170 m_needsSectionRecalc = true; |
|
171 setNeedsLayout(true); |
|
172 } |
|
173 |
|
174 virtual RenderObject* removeChildNode(RenderObject*, bool fullRemove = true); |
|
175 |
|
176 RenderTableSection* sectionAbove(const RenderTableSection*, bool skipEmptySections = false) const; |
|
177 RenderTableSection* sectionBelow(const RenderTableSection*, bool skipEmptySections = false) const; |
|
178 |
|
179 RenderTableCell* cellAbove(const RenderTableCell*) const; |
|
180 RenderTableCell* cellBelow(const RenderTableCell*) const; |
|
181 RenderTableCell* cellBefore(const RenderTableCell*) const; |
|
182 RenderTableCell* cellAfter(const RenderTableCell*) const; |
|
183 |
|
184 const CollapsedBorderValue* currentBorderStyle() const { return m_currentBorder; } |
|
185 |
|
186 bool hasSections() const { return m_head || m_foot || m_firstBody; } |
|
187 |
|
188 virtual IntRect getOverflowClipRect(int tx, int ty); |
|
189 |
|
190 void recalcSectionsIfNeeded() const |
|
191 { |
|
192 if (m_needsSectionRecalc) |
|
193 recalcSections(); |
|
194 } |
|
195 |
|
196 #ifndef NDEBUG |
|
197 virtual void dump(TextStream*, DeprecatedString ind = "") const; |
|
198 #endif |
|
199 |
|
200 private: |
|
201 void recalcSections() const; |
|
202 |
|
203 mutable Vector<int> m_columnPos; |
|
204 mutable Vector<ColumnStruct> m_columns; |
|
205 |
|
206 mutable RenderBlock* m_caption; |
|
207 mutable RenderTableSection* m_head; |
|
208 mutable RenderTableSection* m_foot; |
|
209 mutable RenderTableSection* m_firstBody; |
|
210 |
|
211 TableLayout* m_tableLayout; |
|
212 |
|
213 const CollapsedBorderValue* m_currentBorder; |
|
214 |
|
215 unsigned m_frame : 4; // Frame |
|
216 unsigned m_rules : 4; // Rules |
|
217 |
|
218 mutable bool m_hasColElements : 1; |
|
219 unsigned m_padding : 22; |
|
220 mutable bool m_needsSectionRecalc : 1; |
|
221 |
|
222 short m_hSpacing; |
|
223 short m_vSpacing; |
|
224 int m_borderLeft; |
|
225 int m_borderRight; |
|
226 }; |
|
227 |
|
228 } // namespace WebCore |
|
229 |
|
230 #endif // RenderTable_h |