Fix the issue that Web Audio test case fails on PR3.
[framework/web/webkit-efl.git] / 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 enum CollapsedBorderSide {
34     CBSBefore,
35     CBSAfter,
36     CBSStart,
37     CBSEnd
38 };
39
40 // Helper class for paintObject.
41 class CellSpan {
42 public:
43     CellSpan(unsigned start, unsigned end)
44         : m_start(start)
45         , m_end(end)
46     {
47     }
48
49     unsigned start() const { return m_start; }
50     unsigned end() const { return m_end; }
51
52     unsigned& start() { return m_start; }
53     unsigned& end() { return m_end; }
54
55 private:
56     unsigned m_start;
57     unsigned m_end;
58 };
59
60 class RenderTableCell;
61 class RenderTableRow;
62
63 class RenderTableSection : public RenderBox {
64 public:
65     RenderTableSection(Node*);
66     virtual ~RenderTableSection();
67
68     const RenderObjectChildList* children() const { return &m_children; }
69     RenderObjectChildList* children() { return &m_children; }
70
71     virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0);
72
73     virtual LayoutUnit firstLineBoxBaseline() const;
74
75     void addCell(RenderTableCell*, RenderTableRow* row);
76
77     void setCellLogicalWidths();
78     int calcRowLogicalHeight();
79     void layoutRows();
80
81     RenderTable* table() const { return toRenderTable(parent()); }
82
83     struct CellStruct {
84         Vector<RenderTableCell*, 1> cells; 
85         bool inColSpan; // true for columns after the first in a colspan
86
87         CellStruct()
88             : inColSpan(false)
89         {
90         }
91
92         RenderTableCell* primaryCell()
93         {
94             return hasCells() ? cells[cells.size() - 1] : 0;
95         }
96
97         const RenderTableCell* primaryCell() const
98         {
99             return hasCells() ? cells[cells.size() - 1] : 0;
100         }
101
102         bool hasCells() const { return cells.size() > 0; }
103     };
104
105     typedef Vector<CellStruct> Row;
106
107     struct RowStruct {
108         RowStruct()
109             : rowRenderer(0)
110             , baseline()
111         {
112         }
113
114         Row row;
115         RenderTableRow* rowRenderer;
116         LayoutUnit baseline;
117         Length logicalHeight;
118     };
119
120     bool hasSameDirectionAsTable() const
121     {
122         return table()->style()->direction() == style()->direction();
123     }
124
125     const BorderValue& borderAdjoiningTableStart() const
126     {
127         if (hasSameDirectionAsTable())
128             return style()->borderStart();
129
130         return style()->borderEnd();
131     }
132
133     const BorderValue& borderAdjoiningTableEnd() const
134     {
135         if (hasSameDirectionAsTable())
136             return style()->borderEnd();
137
138         return style()->borderStart();
139     }
140
141     const RenderTableCell* firstRowCellAdjoiningTableStart() const;
142     const RenderTableCell* firstRowCellAdjoiningTableEnd() const;
143
144     CellStruct& cellAt(unsigned row,  unsigned col) { return m_grid[row].row[col]; }
145     const CellStruct& cellAt(unsigned row, unsigned col) const { return m_grid[row].row[col]; }
146     RenderTableCell* primaryCellAt(unsigned row, unsigned col)
147     {
148         CellStruct& c = m_grid[row].row[col];
149         return c.primaryCell();
150     }
151
152     void appendColumn(unsigned pos);
153     void splitColumn(unsigned pos, unsigned first);
154
155     int calcOuterBorderBefore() const;
156     int calcOuterBorderAfter() const;
157     int calcOuterBorderStart() const;
158     int calcOuterBorderEnd() const;
159     void recalcOuterBorder();
160
161     int outerBorderBefore() const { return m_outerBorderBefore; }
162     int outerBorderAfter() const { return m_outerBorderAfter; }
163     int outerBorderStart() const { return m_outerBorderStart; }
164     int outerBorderEnd() const { return m_outerBorderEnd; }
165
166     unsigned numRows() const { return m_grid.size(); }
167     unsigned numColumns() const;
168     void recalcCells();
169     void recalcCellsIfNeeded()
170     {
171         if (m_needsCellRecalc)
172             recalcCells();
173     }
174
175     bool needsCellRecalc() const { return m_needsCellRecalc; }
176     void setNeedsCellRecalc();
177
178     LayoutUnit getBaseline(unsigned row) { return m_grid[row].baseline; }
179
180     void rowLogicalHeightChanged(unsigned rowIndex);
181
182     void removeCachedCollapsedBorders(const RenderTableCell*);
183     void setCachedCollapsedBorder(const RenderTableCell*, CollapsedBorderSide, CollapsedBorderValue);
184     CollapsedBorderValue& cachedCollapsedBorder(const RenderTableCell*, CollapsedBorderSide);
185
186     // distributeExtraLogicalHeightToRows methods return the *consumed* extra logical height.
187     // FIXME: We may want to introduce a structure holding the in-flux layout information.
188     int distributeExtraLogicalHeightToRows(int extraLogicalHeight);
189
190     static RenderTableSection* createAnonymousWithParentRenderer(const RenderObject*);
191     virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject* parent) const OVERRIDE
192     {
193         return createAnonymousWithParentRenderer(parent);
194     }
195     
196     virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
197
198 protected:
199     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
200
201 private:
202     virtual RenderObjectChildList* virtualChildren() { return children(); }
203     virtual const RenderObjectChildList* virtualChildren() const { return children(); }
204
205     virtual const char* renderName() const { return isAnonymous() ? "RenderTableSection (anonymous)" : "RenderTableSection"; }
206
207     virtual bool isTableSection() const { return true; }
208
209     virtual void willBeDestroyed();
210
211     virtual void layout();
212
213     virtual void removeChild(RenderObject* oldChild);
214
215     virtual void paintCell(RenderTableCell*, PaintInfo&, const LayoutPoint&);
216     virtual void paintObject(PaintInfo&, const LayoutPoint&);
217
218     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
219
220     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
221
222     void ensureRows(unsigned);
223
224     void distributeExtraLogicalHeightToPercentRows(int& extraLogicalHeight, int totalPercent);
225     void distributeExtraLogicalHeightToAutoRows(int& extraLogicalHeight, unsigned autoRowsCount);
226     void distributeRemainingExtraLogicalHeight(int& extraLogicalHeight);
227
228     bool hasOverflowingCell() const { return m_overflowingCells.size() || m_forceSlowPaintPathWithOverflowingCell; }
229
230     CellSpan fullTableRowSpan() const { return CellSpan(0, m_grid.size()); }
231     CellSpan fullTableColumnSpan() const { return CellSpan(0, table()->columns().size()); }
232
233     // Flip the rect so it aligns with the coordinates used by the rowPos and columnPos vectors.
234     LayoutRect logicalRectForWritingModeAndDirection(const LayoutRect&) const;
235
236     CellSpan dirtiedRows(const LayoutRect& repaintRect) const;
237     CellSpan dirtiedColumns(const LayoutRect& repaintRect) const;
238
239     // These two functions take a rectangle as input that has been flipped by logicalRectForWritingModeAndDirection.
240     // The returned span of rows or columns is end-exclusive, and empty if start==end.
241     CellSpan spannedRows(const LayoutRect& flippedRect) const;
242     CellSpan spannedColumns(const LayoutRect& flippedRect) const;
243
244     void setLogicalPositionForCell(RenderTableCell*, unsigned effectiveColumn) const;
245
246     RenderObjectChildList m_children;
247
248     Vector<RowStruct> m_grid;
249     Vector<int> m_rowPos;
250
251     // the current insertion position
252     unsigned m_cCol;
253     unsigned m_cRow;
254
255     int m_outerBorderStart;
256     int m_outerBorderEnd;
257     int m_outerBorderBefore;
258     int m_outerBorderAfter;
259
260     bool m_needsCellRecalc;
261
262     // This HashSet holds the overflowing cells for faster painting.
263     // If we have more than gMaxAllowedOverflowingCellRatio * total cells, it will be empty
264     // and m_forceSlowPaintPathWithOverflowingCell will be set to save memory.
265     HashSet<RenderTableCell*> m_overflowingCells;
266     bool m_forceSlowPaintPathWithOverflowingCell;
267
268     bool m_hasMultipleCellLevels;
269
270     // This map holds the collapsed border values for cells with collapsed borders.
271     // It is held at RenderTableSection level to spare memory consumption by table cells.
272     HashMap<pair<const RenderTableCell*, int>, CollapsedBorderValue > m_cellsCollapsedBorders;
273 };
274
275 inline RenderTableSection* toRenderTableSection(RenderObject* object)
276 {
277     ASSERT(!object || object->isTableSection());
278     return static_cast<RenderTableSection*>(object);
279 }
280
281 inline const RenderTableSection* toRenderTableSection(const RenderObject* object)
282 {
283     ASSERT(!object || object->isTableSection());
284     return static_cast<const RenderTableSection*>(object);
285 }
286
287 // This will catch anyone doing an unnecessary cast.
288 void toRenderTableSection(const RenderTableSection*);
289
290 } // namespace WebCore
291
292 #endif // RenderTableSection_h