• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  
children()41      const RenderObjectChildList* children() const { return &m_children; }
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  
table()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  
CellStructCellStruct60          CellStruct():
61            inColSpan(false) {}
62  
primaryCellCellStruct63          RenderTableCell* primaryCell()
64          {
65              return hasCells() ? cells[cells.size() - 1] : 0;
66          }
67  
primaryCellCellStruct68          const RenderTableCell* primaryCell() const
69          {
70              return hasCells() ? cells[cells.size() - 1] : 0;
71          }
72  
hasCellsCellStruct73          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  
cellAt(int row,int col)85      CellStruct& cellAt(int row,  int col) { return (*m_grid[row].row)[col]; }
cellAt(int row,int col)86      const CellStruct& cellAt(int row, int col) const { return (*m_grid[row].row)[col]; }
primaryCellAt(int row,int 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  
outerBorderBefore()102      int outerBorderBefore() const { return m_outerBorderBefore; }
outerBorderAfter()103      int outerBorderAfter() const { return m_outerBorderAfter; }
outerBorderStart()104      int outerBorderStart() const { return m_outerBorderStart; }
outerBorderEnd()105      int outerBorderEnd() const { return m_outerBorderEnd; }
106  
numRows()107      int numRows() const { return m_gridRows; }
108      int numColumns() const;
109      void recalcCells();
recalcCellsIfNeeded()110      void recalcCellsIfNeeded()
111      {
112          if (m_needsCellRecalc)
113              recalcCells();
114      }
115  
needsCellRecalc()116      bool needsCellRecalc() const { return m_needsCellRecalc; }
117      void setNeedsCellRecalc();
118  
getBaseline(int row)119      int getBaseline(int row) { return m_grid[row].baseline; }
120  
121  protected:
122      virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
123  
124  private:
virtualChildren()125      virtual RenderObjectChildList* virtualChildren() { return children(); }
virtualChildren()126      virtual const RenderObjectChildList* virtualChildren() const { return children(); }
127  
renderName()128      virtual const char* renderName() const { return isAnonymous() ? "RenderTableSection (anonymous)" : "RenderTableSection"; }
129  
isTableSection()130      virtual bool isTableSection() const { return true; }
131  
132      virtual void destroy();
133  
134      virtual void layout();
135  
136      virtual void removeChild(RenderObject* oldChild);
137  
138      virtual void paint(PaintInfo&, int tx, int ty);
139      virtual void paintCell(RenderTableCell*, PaintInfo&, int tx, int ty);
140      virtual void paintObject(PaintInfo&, int tx, int ty);
141  
142      virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
143  
144      virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
145  
146      bool ensureRows(int);
147      void clearGrid();
148  
149      RenderObjectChildList m_children;
150  
151      Vector<RowStruct> m_grid;
152      Vector<int> m_rowPos;
153  
154      int m_gridRows;
155  
156      // the current insertion position
157      int m_cCol;
158      int m_cRow;
159  
160      int m_outerBorderStart;
161      int m_outerBorderEnd;
162      int m_outerBorderBefore;
163      int m_outerBorderAfter;
164  
165      bool m_needsCellRecalc;
166      bool m_hasOverflowingCell;
167  
168      bool m_hasMultipleCellLevels;
169  };
170  
toRenderTableSection(RenderObject * object)171  inline RenderTableSection* toRenderTableSection(RenderObject* object)
172  {
173      ASSERT(!object || object->isTableSection());
174      return static_cast<RenderTableSection*>(object);
175  }
176  
toRenderTableSection(const RenderObject * object)177  inline const RenderTableSection* toRenderTableSection(const RenderObject* object)
178  {
179      ASSERT(!object || object->isTableSection());
180      return static_cast<const RenderTableSection*>(object);
181  }
182  
183  // This will catch anyone doing an unnecessary cast.
184  void toRenderTableSection(const RenderTableSection*);
185  
186  } // namespace WebCore
187  
188  #endif // RenderTableSection_h
189