]> git.saurik.com Git - iphone-api.git/blob - WebCore/RenderTable.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / RenderTable.h
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 bool avoidsFloats() const { return true; }
70
71 int getColumnPos(int col) const { return m_columnPos[col]; }
72
73 int hBorderSpacing() const { return m_hSpacing; }
74 int vBorderSpacing() const { return m_vSpacing; }
75
76 bool collapseBorders() const { return style()->borderCollapse(); }
77 int borderLeft() const { return m_borderLeft; }
78 int borderRight() const { return m_borderRight; }
79 int borderTop() const;
80 int borderBottom() const;
81
82 Rules getRules() const { return static_cast<Rules>(m_rules); }
83
84 const Color& bgColor() const { return style()->backgroundColor(); }
85
86 int outerBorderTop() const;
87 int outerBorderBottom() const;
88 int outerBorderLeft() const;
89 int outerBorderRight() const;
90
91 int calcBorderLeft() const;
92 int calcBorderRight() const;
93 void recalcHorizontalBorders();
94
95 // overrides
96 virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0);
97 virtual void paint(PaintInfo&, int tx, int ty);
98 virtual void paintObject(PaintInfo&, int tx, int ty);
99 virtual void paintBoxDecorations(PaintInfo&, int tx, int ty);
100 virtual void paintMask(PaintInfo& paintInfo, int tx, int ty);
101 virtual void layout();
102 virtual void calcPrefWidths();
103 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int xPos, int yPos, int tx, int ty, HitTestAction);
104
105 virtual int getBaselineOfFirstLineBox() const;
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 protected:
197 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
198
199 private:
200 void recalcSections() const;
201
202 mutable Vector<int> m_columnPos;
203 mutable Vector<ColumnStruct> m_columns;
204
205 mutable RenderBlock* m_caption;
206 mutable RenderTableSection* m_head;
207 mutable RenderTableSection* m_foot;
208 mutable RenderTableSection* m_firstBody;
209
210 TableLayout* m_tableLayout;
211
212 const CollapsedBorderValue* m_currentBorder;
213
214 unsigned m_frame : 4; // Frame
215 unsigned m_rules : 4; // Rules
216
217 mutable bool m_hasColElements : 1;
218 mutable bool m_needsSectionRecalc : 1;
219
220 short m_hSpacing;
221 short m_vSpacing;
222 int m_borderLeft;
223 int m_borderRight;
224 };
225
226 } // namespace WebCore
227
228 #endif // RenderTable_h