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.
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.
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.
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.
25 #ifndef RenderTableSection_h
26 #define RenderTableSection_h
28 #include "RenderTable.h"
29 #include <wtf/Vector.h>
33 class RenderTableCell;
36 class RenderTableSection : public RenderBox {
38 RenderTableSection(Node*);
39 virtual ~RenderTableSection();
41 const RenderObjectChildList* children() const { return &m_children; }
42 RenderObjectChildList* children() { return &m_children; }
44 virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0);
46 virtual LayoutUnit firstLineBoxBaseline() const;
48 void addCell(RenderTableCell*, RenderTableRow* row);
50 void setCellLogicalWidths();
51 LayoutUnit calcRowLogicalHeight();
52 LayoutUnit layoutRows(LayoutUnit logicalHeight);
54 RenderTable* table() const { return toRenderTable(parent()); }
57 Vector<RenderTableCell*, 1> cells;
58 bool inColSpan; // true for columns after the first in a colspan
63 RenderTableCell* primaryCell()
65 return hasCells() ? cells[cells.size() - 1] : 0;
68 const RenderTableCell* primaryCell() const
70 return hasCells() ? cells[cells.size() - 1] : 0;
73 bool hasCells() const { return cells.size() > 0; }
76 typedef Vector<CellStruct> Row;
80 RenderTableRow* rowRenderer;
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)
89 CellStruct& c = (*m_grid[row].row)[col];
90 return c.primaryCell();
93 void appendColumn(int pos);
94 void splitColumn(int pos, int first);
96 LayoutUnit calcOuterBorderBefore() const;
97 LayoutUnit calcOuterBorderAfter() const;
98 LayoutUnit calcOuterBorderStart() const;
99 LayoutUnit calcOuterBorderEnd() const;
100 void recalcOuterBorder();
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; }
107 int numRows() const { return m_gridRows; }
108 int numColumns() const;
110 void recalcCellsIfNeeded()
112 if (m_needsCellRecalc)
116 bool needsCellRecalc() const { return m_needsCellRecalc; }
117 void setNeedsCellRecalc();
119 LayoutUnit getBaseline(int row) { return m_grid[row].baseline; }
122 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
125 virtual RenderObjectChildList* virtualChildren() { return children(); }
126 virtual const RenderObjectChildList* virtualChildren() const { return children(); }
128 virtual const char* renderName() const { return isAnonymous() ? "RenderTableSection (anonymous)" : "RenderTableSection"; }
130 virtual bool isTableSection() const { return true; }
132 virtual void willBeDestroyed();
134 virtual void layout();
136 virtual void removeChild(RenderObject* oldChild);
138 virtual void paint(PaintInfo&, const LayoutPoint&);
139 virtual void paintCell(RenderTableCell*, PaintInfo&, const LayoutPoint&);
140 virtual void paintObject(PaintInfo&, const LayoutPoint&);
142 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
144 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
146 bool ensureRows(int);
149 bool hasOverflowingCell() const { return m_overflowingCells.size() || m_forceSlowPaintPathWithOverflowingCell; }
151 RenderObjectChildList m_children;
153 Vector<RowStruct> m_grid;
154 Vector<LayoutUnit> m_rowPos;
158 // the current insertion position
162 LayoutUnit m_outerBorderStart;
163 LayoutUnit m_outerBorderEnd;
164 LayoutUnit m_outerBorderBefore;
165 LayoutUnit m_outerBorderAfter;
167 bool m_needsCellRecalc;
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;
175 bool m_hasMultipleCellLevels;
178 inline RenderTableSection* toRenderTableSection(RenderObject* object)
180 ASSERT(!object || object->isTableSection());
181 return static_cast<RenderTableSection*>(object);
184 inline const RenderTableSection* toRenderTableSection(const RenderObject* object)
186 ASSERT(!object || object->isTableSection());
187 return static_cast<const RenderTableSection*>(object);
190 // This will catch anyone doing an unnecessary cast.
191 void toRenderTableSection(const RenderTableSection*);
193 } // namespace WebCore
195 #endif // RenderTableSection_h