1 /* 2 * Copyright (C) 1997 Martin Jones (mjones (at) kde.org) 3 * (C) 1997 Torben Weis (weis (at) kde.org) 4 * (C) 1998 Waldo Bastian (bastian (at) kde.org) 5 * (C) 1999 Lars Knoll (knoll (at) kde.org) 6 * (C) 1999 Antti Koivisto (koivisto (at) 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 int firstLineBoxBaseline() const; 47 48 void addCell(RenderTableCell*, RenderTableRow* row); 49 50 void setCellLogicalWidths(); 51 int calcRowLogicalHeight(); 52 int layoutRows(int 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 int 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 int calcOuterBorderBefore() const; 97 int calcOuterBorderAfter() const; 98 int calcOuterBorderStart() const; 99 int calcOuterBorderEnd() const; 100 void recalcOuterBorder(); 101 102 int outerBorderBefore() const { return m_outerBorderBefore; } 103 int outerBorderAfter() const { return m_outerBorderAfter; } 104 int outerBorderStart() const { return m_outerBorderStart; } 105 int 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 int getBaseline(int row) { return m_grid[row].baseline; } 120 121 private: 122 virtual RenderObjectChildList* virtualChildren() { return children(); } 123 virtual const RenderObjectChildList* virtualChildren() const { return children(); } 124 125 virtual const char* renderName() const { return isAnonymous() ? "RenderTableSection (anonymous)" : "RenderTableSection"; } 126 127 virtual bool isTableSection() const { return true; } 128 129 virtual void destroy(); 130 131 virtual void layout(); 132 133 virtual void removeChild(RenderObject* oldChild); 134 135 virtual void paint(PaintInfo&, int tx, int ty); 136 virtual void paintCell(RenderTableCell*, PaintInfo&, int tx, int ty); 137 virtual void paintObject(PaintInfo&, int tx, int ty); 138 139 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0); 140 141 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction); 142 143 bool ensureRows(int); 144 void clearGrid(); 145 146 RenderObjectChildList m_children; 147 148 Vector<RowStruct> m_grid; 149 Vector<int> m_rowPos; 150 151 int m_gridRows; 152 153 // the current insertion position 154 int m_cCol; 155 int m_cRow; 156 157 int m_outerBorderStart; 158 int m_outerBorderEnd; 159 int m_outerBorderBefore; 160 int m_outerBorderAfter; 161 162 bool m_needsCellRecalc; 163 bool m_hasOverflowingCell; 164 165 bool m_hasMultipleCellLevels; 166 }; 167 168 inline RenderTableSection* toRenderTableSection(RenderObject* object) 169 { 170 ASSERT(!object || object->isTableSection()); 171 return static_cast<RenderTableSection*>(object); 172 } 173 174 inline const RenderTableSection* toRenderTableSection(const RenderObject* object) 175 { 176 ASSERT(!object || object->isTableSection()); 177 return static_cast<const RenderTableSection*>(object); 178 } 179 180 // This will catch anyone doing an unnecessary cast. 181 void toRenderTableSection(const RenderTableSection*); 182 183 } // namespace WebCore 184 185 #endif // RenderTableSection_h 186