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 RenderTableCell(Node*);
35
36 // FIXME: need to implement cellIndex
cellIndex()37 int cellIndex() const { return 0; }
setCellIndex(int)38 void setCellIndex(int) { }
39
colSpan()40 int colSpan() const { return m_columnSpan; }
setColSpan(int c)41 void setColSpan(int c) { m_columnSpan = c; }
42
rowSpan()43 int rowSpan() const { return m_rowSpan; }
setRowSpan(int r)44 void setRowSpan(int r) { m_rowSpan = r; }
45
col()46 int col() const { return m_column; }
setCol(int col)47 void setCol(int col) { m_column = col; }
row()48 int row() const { return m_row; }
setRow(int row)49 void setRow(int row) { m_row = row; }
50
section()51 RenderTableSection* section() const { return toRenderTableSection(parent()->parent()); }
table()52 RenderTable* table() const { return toRenderTable(parent()->parent()->parent()); }
53
54 Length styleOrColWidth() const;
55
56 virtual void calcPrefWidths();
57
58 #if PLATFORM(ANDROID)
59 #ifdef ANDROID_LAYOUT
60 // RenderTableSection needs to access this in setCellWidths()
getVisibleWidth()61 int getVisibleWidth() { return m_visibleWidth; }
62 #endif
63 #endif
64
65 void updateWidth(int);
66
67 int borderLeft() const;
68 int borderRight() const;
69 int borderTop() const;
70 int borderBottom() const;
71
72 int borderHalfLeft(bool outer) const;
73 int borderHalfRight(bool outer) const;
74 int borderHalfTop(bool outer) const;
75 int borderHalfBottom(bool outer) const;
76
77 CollapsedBorderValue collapsedLeftBorder(bool rtl) const;
78 CollapsedBorderValue collapsedRightBorder(bool rtl) const;
79 CollapsedBorderValue collapsedTopBorder() const;
80 CollapsedBorderValue collapsedBottomBorder() const;
81
82 typedef Vector<CollapsedBorderValue, 100> CollapsedBorderStyles;
83 void collectBorderStyles(CollapsedBorderStyles&) const;
84 static void sortBorderStyles(CollapsedBorderStyles&);
85
86 virtual void updateFromElement();
87
88 virtual void layout();
89
90 virtual void paint(PaintInfo&, int tx, int ty);
91
92 void paintBackgroundsBehindCell(PaintInfo&, int tx, int ty, RenderObject* backgroundObject);
93
94 virtual int baselinePosition(bool firstLine = false, bool isRootLineBox = false) const;
95
setIntrinsicPaddingTop(int p)96 void setIntrinsicPaddingTop(int p) { m_intrinsicPaddingTop = p; }
setIntrinsicPaddingBottom(int p)97 void setIntrinsicPaddingBottom(int p) { m_intrinsicPaddingBottom = p; }
setIntrinsicPadding(int top,int bottom)98 void setIntrinsicPadding(int top, int bottom) { setIntrinsicPaddingTop(top); setIntrinsicPaddingBottom(bottom); }
clearIntrinsicPadding()99 void clearIntrinsicPadding() { setIntrinsicPadding(0, 0); }
100
intrinsicPaddingTop()101 int intrinsicPaddingTop() const { return m_intrinsicPaddingTop; }
intrinsicPaddingBottom()102 int intrinsicPaddingBottom() const { return m_intrinsicPaddingBottom; }
103
104 virtual int paddingTop(bool includeIntrinsicPadding = true) const;
105 virtual int paddingBottom(bool includeIntrinsicPadding = true) const;
106
107 virtual void setOverrideSize(int);
108
109 protected:
110 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
111 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
112
113 virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&) const;
114 virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
115
116 private:
renderName()117 virtual const char* renderName() const { return isAnonymous() ? "RenderTableCell (anonymous)" : "RenderTableCell"; }
118
isTableCell()119 virtual bool isTableCell() const { return true; }
120
121 virtual void destroy();
122
requiresLayer()123 virtual bool requiresLayer() const { return isPositioned() || isTransparent() || hasOverflowClip() || hasTransform() || hasMask() || hasReflection(); }
124
125 virtual void calcWidth();
126
127 virtual void paintBoxDecorations(PaintInfo&, int tx, int ty);
128 virtual void paintMask(PaintInfo&, int tx, int ty);
129
130 virtual IntRect clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer);
131 virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect&, bool fixed = false);
132
133 void paintCollapsedBorder(GraphicsContext*, int x, int y, int w, int h);
134
135 int m_row;
136 int m_column;
137 int m_rowSpan;
138 int m_columnSpan;
139 int m_intrinsicPaddingTop;
140 int m_intrinsicPaddingBottom;
141 int m_percentageHeight;
142 };
143
toRenderTableCell(RenderObject * object)144 inline RenderTableCell* toRenderTableCell(RenderObject* object)
145 {
146 ASSERT(!object || object->isTableCell());
147 return static_cast<RenderTableCell*>(object);
148 }
149
toRenderTableCell(const RenderObject * object)150 inline const RenderTableCell* toRenderTableCell(const RenderObject* object)
151 {
152 ASSERT(!object || object->isTableCell());
153 return static_cast<const RenderTableCell*>(object);
154 }
155
156 // This will catch anyone doing an unnecessary cast.
157 void toRenderTableCell(const RenderTableCell*);
158
159 } // namespace WebCore
160
161 #endif // RenderTableCell_h
162