| 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 RenderTable_h |
|---|
| 26 | #define RenderTable_h |
|---|
| 27 | |
|---|
| 28 | #include "RenderBlock.h" |
|---|
| 29 | #include <wtf/Vector.h> |
|---|
| 30 | |
|---|
| 31 | namespace WebCore { |
|---|
| 32 | |
|---|
| 33 | class RenderTableCol; |
|---|
| 34 | class RenderTableCell; |
|---|
| 35 | class RenderTableSection; |
|---|
| 36 | class TableLayout; |
|---|
| 37 | |
|---|
| 38 | class RenderTable : public RenderBlock { |
|---|
| 39 | public: |
|---|
| 40 | RenderTable(Node*); |
|---|
| 41 | |
|---|
| 42 | int getColumnPos(int col) const { return m_columnPos[col]; } |
|---|
| 43 | |
|---|
| 44 | int hBorderSpacing() const { return m_hSpacing; } |
|---|
| 45 | int vBorderSpacing() const { return m_vSpacing; } |
|---|
| 46 | |
|---|
| 47 | bool collapseBorders() const { return style()->borderCollapse(); } |
|---|
| 48 | int borderLeft() const { return m_borderLeft; } |
|---|
| 49 | int borderRight() const { return m_borderRight; } |
|---|
| 50 | int borderTop() const; |
|---|
| 51 | int borderBottom() const; |
|---|
| 52 | |
|---|
| 53 | const Color& bgColor() const { return style()->backgroundColor(); } |
|---|
| 54 | |
|---|
| 55 | int outerBorderTop() const; |
|---|
| 56 | int outerBorderBottom() const; |
|---|
| 57 | int outerBorderLeft() const; |
|---|
| 58 | int outerBorderRight() const; |
|---|
| 59 | |
|---|
| 60 | int calcBorderLeft() const; |
|---|
| 61 | int calcBorderRight() const; |
|---|
| 62 | void recalcHorizontalBorders(); |
|---|
| 63 | |
|---|
| 64 | virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0); |
|---|
| 65 | |
|---|
| 66 | struct ColumnStruct { |
|---|
| 67 | enum { |
|---|
| 68 | WidthUndefined = 0xffff |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | ColumnStruct() |
|---|
| 72 | : span(1) |
|---|
| 73 | , width(WidthUndefined) |
|---|
| 74 | { |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | unsigned short span; |
|---|
| 78 | unsigned width; // the calculated position of the column |
|---|
| 79 | }; |
|---|
| 80 | |
|---|
| 81 | Vector<ColumnStruct>& columns() { return m_columns; } |
|---|
| 82 | Vector<int>& columnPositions() { return m_columnPos; } |
|---|
| 83 | RenderTableSection* header() const { return m_head; } |
|---|
| 84 | RenderTableSection* footer() const { return m_foot; } |
|---|
| 85 | RenderTableSection* firstBody() const { return m_firstBody; } |
|---|
| 86 | |
|---|
| 87 | void splitColumn(int pos, int firstSpan); |
|---|
| 88 | void appendColumn(int span); |
|---|
| 89 | int numEffCols() const { return m_columns.size(); } |
|---|
| 90 | int spanOfEffCol(int effCol) const { return m_columns[effCol].span; } |
|---|
| 91 | |
|---|
| 92 | int colToEffCol(int col) const |
|---|
| 93 | { |
|---|
| 94 | int i = 0; |
|---|
| 95 | int effCol = numEffCols(); |
|---|
| 96 | for (int c = 0; c < col && i < effCol; ++i) |
|---|
| 97 | c += m_columns[i].span; |
|---|
| 98 | return i; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | int effColToCol(int effCol) const |
|---|
| 102 | { |
|---|
| 103 | int c = 0; |
|---|
| 104 | for (int i = 0; i < effCol; i++) |
|---|
| 105 | c += m_columns[i].span; |
|---|
| 106 | return c; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | int bordersPaddingAndSpacing() const |
|---|
| 110 | { |
|---|
| 111 | return borderLeft() + borderRight() + |
|---|
| 112 | (collapseBorders() ? 0 : (paddingLeft() + paddingRight() + (numEffCols() + 1) * hBorderSpacing())); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | RenderTableCol* colElement(int col, bool* startEdge = 0, bool* endEdge = 0) const; |
|---|
| 116 | |
|---|
| 117 | bool needsSectionRecalc() const { return m_needsSectionRecalc; } |
|---|
| 118 | void setNeedsSectionRecalc() |
|---|
| 119 | { |
|---|
| 120 | if (documentBeingDestroyed()) |
|---|
| 121 | return; |
|---|
| 122 | m_needsSectionRecalc = true; |
|---|
| 123 | setNeedsLayout(true); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | RenderTableSection* sectionAbove(const RenderTableSection*, bool skipEmptySections = false) const; |
|---|
| 127 | RenderTableSection* sectionBelow(const RenderTableSection*, bool skipEmptySections = false) const; |
|---|
| 128 | |
|---|
| 129 | RenderTableCell* cellAbove(const RenderTableCell*) const; |
|---|
| 130 | RenderTableCell* cellBelow(const RenderTableCell*) const; |
|---|
| 131 | RenderTableCell* cellBefore(const RenderTableCell*) const; |
|---|
| 132 | RenderTableCell* cellAfter(const RenderTableCell*) const; |
|---|
| 133 | |
|---|
| 134 | const CollapsedBorderValue* currentBorderStyle() const { return m_currentBorder; } |
|---|
| 135 | |
|---|
| 136 | bool hasSections() const { return m_head || m_foot || m_firstBody; } |
|---|
| 137 | |
|---|
| 138 | void recalcSectionsIfNeeded() const |
|---|
| 139 | { |
|---|
| 140 | if (m_needsSectionRecalc) |
|---|
| 141 | recalcSections(); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | protected: |
|---|
| 145 | virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle); |
|---|
| 146 | |
|---|
| 147 | private: |
|---|
| 148 | virtual const char* renderName() const { return "RenderTable"; } |
|---|
| 149 | |
|---|
| 150 | virtual bool isTable() const { return true; } |
|---|
| 151 | |
|---|
| 152 | virtual bool avoidsFloats() const { return true; } |
|---|
| 153 | |
|---|
| 154 | virtual void removeChild(RenderObject* oldChild); |
|---|
| 155 | |
|---|
| 156 | virtual void paint(PaintInfo&, int tx, int ty); |
|---|
| 157 | virtual void paintObject(PaintInfo&, int tx, int ty); |
|---|
| 158 | virtual void paintBoxDecorations(PaintInfo&, int tx, int ty); |
|---|
| 159 | virtual void paintMask(PaintInfo&, int tx, int ty); |
|---|
| 160 | virtual void layout(); |
|---|
| 161 | virtual void calcPrefWidths(); |
|---|
| 162 | virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int xPos, int yPos, int tx, int ty, HitTestAction); |
|---|
| 163 | |
|---|
| 164 | virtual int firstLineBoxBaseline() const; |
|---|
| 165 | |
|---|
| 166 | virtual RenderBlock* firstLineBlock() const; |
|---|
| 167 | virtual void updateFirstLetter(); |
|---|
| 168 | |
|---|
| 169 | virtual void setCellWidths(); |
|---|
| 170 | |
|---|
| 171 | virtual void calcWidth(); |
|---|
| 172 | |
|---|
| 173 | virtual IntRect overflowClipRect(int tx, int ty); |
|---|
| 174 | |
|---|
| 175 | void recalcSections() const; |
|---|
| 176 | |
|---|
| 177 | mutable Vector<int> m_columnPos; |
|---|
| 178 | mutable Vector<ColumnStruct> m_columns; |
|---|
| 179 | |
|---|
| 180 | mutable RenderBlock* m_caption; |
|---|
| 181 | mutable RenderTableSection* m_head; |
|---|
| 182 | mutable RenderTableSection* m_foot; |
|---|
| 183 | mutable RenderTableSection* m_firstBody; |
|---|
| 184 | |
|---|
| 185 | OwnPtr<TableLayout> m_tableLayout; |
|---|
| 186 | |
|---|
| 187 | const CollapsedBorderValue* m_currentBorder; |
|---|
| 188 | |
|---|
| 189 | mutable bool m_hasColElements : 1; |
|---|
| 190 | mutable bool m_needsSectionRecalc : 1; |
|---|
| 191 | |
|---|
| 192 | short m_hSpacing; |
|---|
| 193 | short m_vSpacing; |
|---|
| 194 | int m_borderLeft; |
|---|
| 195 | int m_borderRight; |
|---|
| 196 | }; |
|---|
| 197 | |
|---|
| 198 | inline RenderTable* toRenderTable(RenderObject* object) |
|---|
| 199 | { |
|---|
| 200 | ASSERT(!object || object->isTable()); |
|---|
| 201 | return static_cast<RenderTable*>(object); |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | inline const RenderTable* toRenderTable(const RenderObject* object) |
|---|
| 205 | { |
|---|
| 206 | ASSERT(!object || object->isTable()); |
|---|
| 207 | return static_cast<const RenderTable*>(object); |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | // This will catch anyone doing an unnecessary cast. |
|---|
| 211 | void toRenderTable(const RenderTable*); |
|---|
| 212 | |
|---|
| 213 | } // namespace WebCore |
|---|
| 214 | |
|---|
| 215 | #endif // RenderTable_h |
|---|