1 /*
2 * Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 * (C) 1997 Torben Weis (weis@kde.org)
4 * (C) 1998 Waldo Bastian (bastian@kde.org)
5 * (C) 1999 Lars Knoll (knoll@kde.org)
6 * (C) 1999 Antti Koivisto (koivisto@kde.org)
7 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
24
25 #ifndef RenderTableSection_h
26 #define RenderTableSection_h
27
28 #include "RenderTable.h"
29 #include <wtf/Vector.h>
30
31 namespace WebCore {
32
33 class RenderTableCell;
34 class RenderTableRow;
35
36 class RenderTableSection : public RenderBox {
37 public:
38 RenderTableSection(Node*);
39 virtual ~RenderTableSection();
40
children()41 const RenderObjectChildList* children() const { return &m_children; }
children()42 RenderObjectChildList* children() { return &m_children; }
43
44 virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0);
45
46 virtual int firstLineBoxBaseline() const;
47
48 void addCell(RenderTableCell*, RenderTableRow* row);
49
50 void setCellWidths();
51 int calcRowHeight();
52 int layoutRows(int height);
53
table()54 RenderTable* table() const { return toRenderTable(parent()); }
55
56 struct CellStruct {
57 RenderTableCell* cell;
58 bool inColSpan; // true for columns after the first in a colspan
59 };
60
61 typedef Vector<CellStruct> Row;
62
63 struct RowStruct {
64 Row* row;
65 RenderTableRow* rowRenderer;
66 int baseline;
67 Length height;
68 };
69
cellAt(int row,int col)70 CellStruct& cellAt(int row, int col) { return (*m_grid[row].row)[col]; }
cellAt(int row,int col)71 const CellStruct& cellAt(int row, int col) const { return (*m_grid[row].row)[col]; }
72
73 void appendColumn(int pos);
74 void splitColumn(int pos, int newSize);
75
76 int calcOuterBorderTop() const;
77 int calcOuterBorderBottom() const;
78 int calcOuterBorderLeft(bool rtl) const;
79 int calcOuterBorderRight(bool rtl) const;
80 void recalcOuterBorder();
81
outerBorderTop()82 int outerBorderTop() const { return m_outerBorderTop; }
outerBorderBottom()83 int outerBorderBottom() const { return m_outerBorderBottom; }
outerBorderLeft()84 int outerBorderLeft() const { return m_outerBorderLeft; }
outerBorderRight()85 int outerBorderRight() const { return m_outerBorderRight; }
86
numRows()87 int numRows() const { return m_gridRows; }
88 int numColumns() const;
89 void recalcCells();
recalcCellsIfNeeded()90 void recalcCellsIfNeeded()
91 {
92 if (m_needsCellRecalc)
93 recalcCells();
94 }
95
needsCellRecalc()96 bool needsCellRecalc() const { return m_needsCellRecalc; }
setNeedsCellRecalc()97 void setNeedsCellRecalc()
98 {
99 m_needsCellRecalc = true;
100 table()->setNeedsSectionRecalc();
101 }
102
getBaseline(int row)103 int getBaseline(int row) { return m_grid[row].baseline; }
104
105 private:
virtualChildren()106 virtual RenderObjectChildList* virtualChildren() { return children(); }
virtualChildren()107 virtual const RenderObjectChildList* virtualChildren() const { return children(); }
108
renderName()109 virtual const char* renderName() const { return isAnonymous() ? "RenderTableSection (anonymous)" : "RenderTableSection"; }
110
isTableSection()111 virtual bool isTableSection() const { return true; }
112
113 virtual void destroy();
114
115 virtual void layout();
116
117 virtual void removeChild(RenderObject* oldChild);
118
119 virtual int lowestPosition(bool includeOverflowInterior, bool includeSelf) const;
120 virtual int rightmostPosition(bool includeOverflowInterior, bool includeSelf) const;
121 virtual int leftmostPosition(bool includeOverflowInterior, bool includeSelf) const;
122
123 virtual void paint(PaintInfo&, int tx, int ty);
124 virtual void paintObject(PaintInfo&, int tx, int ty);
125
126 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
127
128 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
129
lineHeight(bool,bool)130 virtual int lineHeight(bool, bool) const { return 0; }
131
132 bool ensureRows(int);
133 void clearGrid();
134
135 RenderObjectChildList m_children;
136
137 Vector<RowStruct> m_grid;
138 Vector<int> m_rowPos;
139
140 int m_gridRows;
141
142 // the current insertion position
143 int m_cCol;
144 int m_cRow;
145
146 int m_outerBorderLeft;
147 int m_outerBorderRight;
148 int m_outerBorderTop;
149 int m_outerBorderBottom;
150
151 bool m_needsCellRecalc;
152 bool m_hasOverflowingCell;
153 };
154
toRenderTableSection(RenderObject * object)155 inline RenderTableSection* toRenderTableSection(RenderObject* object)
156 {
157 ASSERT(!object || object->isTableSection());
158 return static_cast<RenderTableSection*>(object);
159 }
160
toRenderTableSection(const RenderObject * object)161 inline const RenderTableSection* toRenderTableSection(const RenderObject* object)
162 {
163 ASSERT(!object || object->isTableSection());
164 return static_cast<const RenderTableSection*>(object);
165 }
166
167 // This will catch anyone doing an unnecessary cast.
168 void toRenderTableSection(const RenderTableSection*);
169
170 } // namespace WebCore
171
172 #endif // RenderTableSection_h
173