initial import
[vuplus_webkit] / Source / WebCore / rendering / RenderTableSection.h
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
41     const RenderObjectChildList* children() const { return &m_children; }
42     RenderObjectChildList* children() { return &m_children; }
43
44     virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0);
45
46     virtual LayoutUnit firstLineBoxBaseline() const;
47
48     void addCell(RenderTableCell*, RenderTableRow* row);
49
50     void setCellLogicalWidths();
51     LayoutUnit calcRowLogicalHeight();
52     LayoutUnit layoutRows(LayoutUnit logicalHeight);
53
54     RenderTable* table() const { return toRenderTable(parent()); }
55
56     struct CellStruct {
57         Vector<RenderTableCell*, 1> cells; 
58         bool inColSpan; // true for columns after the first in a colspan
59
60         CellStruct():
61           inColSpan(false) {}
62         
63         RenderTableCell* primaryCell()
64         {
65             return hasCells() ? cells[cells.size() - 1] : 0;
66         }
67
68         const RenderTableCell* primaryCell() const
69         {
70             return hasCells() ? cells[cells.size() - 1] : 0;
71         }
72
73         bool hasCells() const { return cells.size() > 0; }
74     };
75
76     typedef Vector<CellStruct> Row;
77
78     struct RowStruct {
79         Row* row;
80         RenderTableRow* rowRenderer;
81         LayoutUnit baseline;
82         Length logicalHeight;
83     };
84
85     CellStruct& cellAt(int row,  int col) { return (*m_grid[row].row)[col]; }
86     const CellStruct& cellAt(int row, int col) const { return (*m_grid[row].row)[col]; }
87     RenderTableCell* primaryCellAt(int row, int col)
88     {
89         CellStruct& c = (*m_grid[row].row)[col];
90         return c.primaryCell();
91     }
92
93     void appendColumn(int pos);
94     void splitColumn(int pos, int first);
95
96     LayoutUnit calcOuterBorderBefore() const;
97     LayoutUnit calcOuterBorderAfter() const;
98     LayoutUnit calcOuterBorderStart() const;
99     LayoutUnit calcOuterBorderEnd() const;
100     void recalcOuterBorder();
101
102     LayoutUnit outerBorderBefore() const { return m_outerBorderBefore; }
103     LayoutUnit outerBorderAfter() const { return m_outerBorderAfter; }
104     LayoutUnit outerBorderStart() const { return m_outerBorderStart; }
105     LayoutUnit outerBorderEnd() const { return m_outerBorderEnd; }
106
107     int numRows() const { return m_gridRows; }
108     int numColumns() const;
109     void recalcCells();
110     void recalcCellsIfNeeded()
111     {
112         if (m_needsCellRecalc)
113             recalcCells();
114     }
115
116     bool needsCellRecalc() const { return m_needsCellRecalc; }
117     void setNeedsCellRecalc();
118
119     LayoutUnit getBaseline(int row) { return m_grid[row].baseline; }
120
121 protected:
122     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
123
124 private:
125     virtual RenderObjectChildList* virtualChildren() { return children(); }
126     virtual const RenderObjectChildList* virtualChildren() const { return children(); }
127
128     virtual const char* renderName() const { return isAnonymous() ? "RenderTableSection (anonymous)" : "RenderTableSection"; }
129
130     virtual bool isTableSection() const { return true; }
131
132     virtual void willBeDestroyed();
133
134     virtual void layout();
135
136     virtual void removeChild(RenderObject* oldChild);
137
138     virtual void paint(PaintInfo&, const LayoutPoint&);
139     virtual void paintCell(RenderTableCell*, PaintInfo&, const LayoutPoint&);
140     virtual void paintObject(PaintInfo&, const LayoutPoint&);
141
142     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
143
144     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
145
146     bool ensureRows(int);
147     void clearGrid();
148
149     bool hasOverflowingCell() const { return m_overflowingCells.size() || m_forceSlowPaintPathWithOverflowingCell; }
150
151     RenderObjectChildList m_children;
152
153     Vector<RowStruct> m_grid;
154     Vector<LayoutUnit> m_rowPos;
155
156     int m_gridRows;
157
158     // the current insertion position
159     int m_cCol;
160     int m_cRow;
161
162     LayoutUnit m_outerBorderStart;
163     LayoutUnit m_outerBorderEnd;
164     LayoutUnit m_outerBorderBefore;
165     LayoutUnit m_outerBorderAfter;
166
167     bool m_needsCellRecalc;
168
169     // This HashSet holds the overflowing cells for faster painting.
170     // If we have more than gMaxAllowedOverflowingCellRatio * total cells, it will be empty
171     // and m_forceSlowPaintPathWithOverflowingCell will be set to save memory.
172     HashSet<RenderTableCell*> m_overflowingCells;
173     bool m_forceSlowPaintPathWithOverflowingCell;
174
175     bool m_hasMultipleCellLevels;
176 };
177
178 inline RenderTableSection* toRenderTableSection(RenderObject* object)
179 {
180     ASSERT(!object || object->isTableSection());
181     return static_cast<RenderTableSection*>(object);
182 }
183
184 inline const RenderTableSection* toRenderTableSection(const RenderObject* object)
185 {
186     ASSERT(!object || object->isTableSection());
187     return static_cast<const RenderTableSection*>(object);
188 }
189
190 // This will catch anyone doing an unnecessary cast.
191 void toRenderTableSection(const RenderTableSection*);
192
193 } // namespace WebCore
194
195 #endif // RenderTableSection_h