initial import
[vuplus_webkit] / Source / WebCore / rendering / RenderTableCell.h
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, 2007, 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 RenderTableCell_h
26 #define RenderTableCell_h
27
28 #include "RenderTableSection.h"
29
30 namespace WebCore {
31
32 class RenderTableCell : public RenderBlock {
33 public:
34     explicit RenderTableCell(Node*);
35
36     // FIXME: need to implement cellIndex
37     int cellIndex() const { return 0; }
38     void setCellIndex(int) { }
39
40     int colSpan() const { return m_columnSpan; }
41     void setColSpan(int c) { m_columnSpan = c; }
42
43     int rowSpan() const { return m_rowSpan; }
44     void setRowSpan(int r) { m_rowSpan = r; }
45
46     int col() const { return m_column; }
47     void setCol(int col) { m_column = col; }
48     int row() const { return m_row; }
49     void setRow(int row) { m_row = row; }
50
51     RenderTableSection* section() const { return toRenderTableSection(parent()->parent()); }
52     RenderTable* table() const { return toRenderTable(parent()->parent()->parent()); }
53
54     Length styleOrColLogicalWidth() const;
55
56     virtual void computePreferredLogicalWidths();
57
58     void updateLogicalWidth(int);
59
60     virtual LayoutUnit borderLeft() const;
61     virtual LayoutUnit borderRight() const;
62     virtual LayoutUnit borderTop() const;
63     virtual LayoutUnit borderBottom() const;
64     virtual LayoutUnit borderStart() const;
65     virtual LayoutUnit borderEnd() const;
66     virtual LayoutUnit borderBefore() const;
67     virtual LayoutUnit borderAfter() const;
68
69     LayoutUnit borderHalfLeft(bool outer) const;
70     LayoutUnit borderHalfRight(bool outer) const;
71     LayoutUnit borderHalfTop(bool outer) const;
72     LayoutUnit borderHalfBottom(bool outer) const;
73
74     LayoutUnit borderHalfStart(bool outer) const;
75     LayoutUnit borderHalfEnd(bool outer) const;
76     LayoutUnit borderHalfBefore(bool outer) const;
77     LayoutUnit borderHalfAfter(bool outer) const;
78
79     CollapsedBorderValue collapsedStartBorder() const;
80     CollapsedBorderValue collapsedEndBorder() const;
81     CollapsedBorderValue collapsedBeforeBorder() const;
82     CollapsedBorderValue collapsedAfterBorder() const;
83
84     CollapsedBorderValue collapsedLeftBorder() const;
85     CollapsedBorderValue collapsedRightBorder() const;
86     CollapsedBorderValue collapsedTopBorder() const;
87     CollapsedBorderValue collapsedBottomBorder() const;
88
89     typedef Vector<CollapsedBorderValue, 100> CollapsedBorderStyles;
90     void collectBorderStyles(CollapsedBorderStyles&) const;
91     static void sortBorderStyles(CollapsedBorderStyles&);
92
93     virtual void updateFromElement();
94
95     virtual void layout();
96
97     virtual void paint(PaintInfo&, const LayoutPoint&);
98
99     void paintBackgroundsBehindCell(PaintInfo&, const LayoutPoint&, RenderObject* backgroundObject);
100
101     int cellBaselinePosition() const;
102
103     void setIntrinsicPaddingBefore(int p) { m_intrinsicPaddingBefore = p; }
104     void setIntrinsicPaddingAfter(int p) { m_intrinsicPaddingAfter = p; }
105     void setIntrinsicPadding(int before, int after) { setIntrinsicPaddingBefore(before); setIntrinsicPaddingAfter(after); }
106     void clearIntrinsicPadding() { setIntrinsicPadding(0, 0); }
107
108     int intrinsicPaddingBefore() const { return m_intrinsicPaddingBefore; }
109     int intrinsicPaddingAfter() const { return m_intrinsicPaddingAfter; }
110
111     virtual LayoutUnit paddingTop(bool includeIntrinsicPadding = true) const;
112     virtual LayoutUnit paddingBottom(bool includeIntrinsicPadding = true) const;
113     virtual LayoutUnit paddingLeft(bool includeIntrinsicPadding = true) const;
114     virtual LayoutUnit paddingRight(bool includeIntrinsicPadding = true) const;
115     
116     // FIXME: For now we just assume the cell has the same block flow direction as the table.  It's likely we'll
117     // create an extra anonymous RenderBlock to handle mixing directionality anyway, in which case we can lock
118     // the block flow directionality of the cells to the table's directionality.
119     virtual LayoutUnit paddingBefore(bool includeIntrinsicPadding = true) const;
120     virtual LayoutUnit paddingAfter(bool includeIntrinsicPadding = true) const;
121
122     void setOverrideHeightFromRowHeight(int);
123
124     bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
125
126     virtual void scrollbarsChanged(bool horizontalScrollbarChanged, bool verticalScrollbarChanged);
127
128     bool cellWidthChanged() const { return m_cellWidthChanged; }
129     void setCellWidthChanged(bool b = true) { m_cellWidthChanged = b; }
130
131 protected:
132     virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
133     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
134
135 private:
136     virtual const char* renderName() const { return isAnonymous() ? "RenderTableCell (anonymous)" : "RenderTableCell"; }
137
138     virtual bool isTableCell() const { return true; }
139
140     virtual RenderBlock* containingBlock() const;
141
142     virtual void willBeDestroyed();
143
144     virtual void computeLogicalWidth();
145
146     virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
147     virtual void paintMask(PaintInfo&, const LayoutPoint&);
148
149     virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&) const;
150     virtual IntRect clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer) const;
151     virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect&, bool fixed = false) const;
152
153     void paintCollapsedBorder(GraphicsContext*, const LayoutRect&);
154
155     int m_row;
156     int m_column;
157     int m_rowSpan;
158     int m_columnSpan : 31;
159     bool m_cellWidthChanged : 1;
160     int m_intrinsicPaddingBefore;
161     int m_intrinsicPaddingAfter;
162 };
163
164 inline RenderTableCell* toRenderTableCell(RenderObject* object)
165 {
166     ASSERT(!object || object->isTableCell());
167     return static_cast<RenderTableCell*>(object);
168 }
169
170 inline const RenderTableCell* toRenderTableCell(const RenderObject* object)
171 {
172     ASSERT(!object || object->isTableCell());
173     return static_cast<const RenderTableCell*>(object);
174 }
175
176 // This will catch anyone doing an unnecessary cast.
177 void toRenderTableCell(const RenderTableCell*);
178
179 } // namespace WebCore
180
181 #endif // RenderTableCell_h