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 enum CollapsedBorderSide {
40 // Helper class for paintObject.
43 CellSpan(unsigned start, unsigned end)
49 unsigned start() const { return m_start; }
50 unsigned end() const { return m_end; }
52 unsigned& start() { return m_start; }
53 unsigned& end() { return m_end; }
60 class RenderTableCell;
63 class RenderTableSection : public RenderBox {
65 RenderTableSection(Node*);
66 virtual ~RenderTableSection();
68 const RenderObjectChildList* children() const { return &m_children; }
69 RenderObjectChildList* children() { return &m_children; }
71 virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0);
73 virtual LayoutUnit firstLineBoxBaseline() const;
75 void addCell(RenderTableCell*, RenderTableRow* row);
77 void setCellLogicalWidths();
78 int calcRowLogicalHeight();
81 RenderTable* table() const { return toRenderTable(parent()); }
84 Vector<RenderTableCell*, 1> cells;
85 bool inColSpan; // true for columns after the first in a colspan
92 RenderTableCell* primaryCell()
94 return hasCells() ? cells[cells.size() - 1] : 0;
97 const RenderTableCell* primaryCell() const
99 return hasCells() ? cells[cells.size() - 1] : 0;
102 bool hasCells() const { return cells.size() > 0; }
105 typedef Vector<CellStruct> Row;
115 RenderTableRow* rowRenderer;
117 Length logicalHeight;
120 bool hasSameDirectionAsTable() const
122 return table()->style()->direction() == style()->direction();
125 const BorderValue& borderAdjoiningTableStart() const
127 if (hasSameDirectionAsTable())
128 return style()->borderStart();
130 return style()->borderEnd();
133 const BorderValue& borderAdjoiningTableEnd() const
135 if (hasSameDirectionAsTable())
136 return style()->borderEnd();
138 return style()->borderStart();
141 const RenderTableCell* firstRowCellAdjoiningTableStart() const;
142 const RenderTableCell* firstRowCellAdjoiningTableEnd() const;
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)
148 CellStruct& c = m_grid[row].row[col];
149 return c.primaryCell();
152 void appendColumn(unsigned pos);
153 void splitColumn(unsigned pos, unsigned first);
155 int calcOuterBorderBefore() const;
156 int calcOuterBorderAfter() const;
157 int calcOuterBorderStart() const;
158 int calcOuterBorderEnd() const;
159 void recalcOuterBorder();
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; }
166 unsigned numRows() const { return m_grid.size(); }
167 unsigned numColumns() const;
169 void recalcCellsIfNeeded()
171 if (m_needsCellRecalc)
175 bool needsCellRecalc() const { return m_needsCellRecalc; }
176 void setNeedsCellRecalc();
178 LayoutUnit getBaseline(unsigned row) { return m_grid[row].baseline; }
180 void rowLogicalHeightChanged(unsigned rowIndex);
182 void removeCachedCollapsedBorders(const RenderTableCell*);
183 void setCachedCollapsedBorder(const RenderTableCell*, CollapsedBorderSide, CollapsedBorderValue);
184 CollapsedBorderValue& cachedCollapsedBorder(const RenderTableCell*, CollapsedBorderSide);
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);
190 static RenderTableSection* createAnonymousWithParentRenderer(const RenderObject*);
191 virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject* parent) const OVERRIDE
193 return createAnonymousWithParentRenderer(parent);
196 virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
199 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
202 virtual RenderObjectChildList* virtualChildren() { return children(); }
203 virtual const RenderObjectChildList* virtualChildren() const { return children(); }
205 virtual const char* renderName() const { return isAnonymous() ? "RenderTableSection (anonymous)" : "RenderTableSection"; }
207 virtual bool isTableSection() const { return true; }
209 virtual void willBeDestroyed();
211 virtual void layout();
213 virtual void removeChild(RenderObject* oldChild);
215 virtual void paintCell(RenderTableCell*, PaintInfo&, const LayoutPoint&);
216 virtual void paintObject(PaintInfo&, const LayoutPoint&);
218 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
220 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
222 void ensureRows(unsigned);
224 void distributeExtraLogicalHeightToPercentRows(int& extraLogicalHeight, int totalPercent);
225 void distributeExtraLogicalHeightToAutoRows(int& extraLogicalHeight, unsigned autoRowsCount);
226 void distributeRemainingExtraLogicalHeight(int& extraLogicalHeight);
228 bool hasOverflowingCell() const { return m_overflowingCells.size() || m_forceSlowPaintPathWithOverflowingCell; }
230 CellSpan fullTableRowSpan() const { return CellSpan(0, m_grid.size()); }
231 CellSpan fullTableColumnSpan() const { return CellSpan(0, table()->columns().size()); }
233 // Flip the rect so it aligns with the coordinates used by the rowPos and columnPos vectors.
234 LayoutRect logicalRectForWritingModeAndDirection(const LayoutRect&) const;
236 CellSpan dirtiedRows(const LayoutRect& repaintRect) const;
237 CellSpan dirtiedColumns(const LayoutRect& repaintRect) const;
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;
244 void setLogicalPositionForCell(RenderTableCell*, unsigned effectiveColumn) const;
246 RenderObjectChildList m_children;
248 Vector<RowStruct> m_grid;
249 Vector<int> m_rowPos;
251 // the current insertion position
255 int m_outerBorderStart;
256 int m_outerBorderEnd;
257 int m_outerBorderBefore;
258 int m_outerBorderAfter;
260 bool m_needsCellRecalc;
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;
268 bool m_hasMultipleCellLevels;
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;
275 inline RenderTableSection* toRenderTableSection(RenderObject* object)
277 ASSERT(!object || object->isTableSection());
278 return static_cast<RenderTableSection*>(object);
281 inline const RenderTableSection* toRenderTableSection(const RenderObject* object)
283 ASSERT(!object || object->isTableSection());
284 return static_cast<const RenderTableSection*>(object);
287 // This will catch anyone doing an unnecessary cast.
288 void toRenderTableSection(const RenderTableSection*);
290 } // namespace WebCore
292 #endif // RenderTableSection_h