DeviceOrientation.absolute should return false when it was not initialized.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / RenderTable.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, 2009, 2010 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 "CSSPropertyNames.h"
29 #include "CollapsedBorderValue.h"
30 #include "RenderBlock.h"
31 #include <wtf/Vector.h>
32
33 namespace WebCore {
34
35 class RenderTableCol;
36 class RenderTableCaption;
37 class RenderTableCell;
38 class RenderTableSection;
39 class TableLayout;
40
41 enum SkipEmptySectionsValue { DoNotSkipEmptySections, SkipEmptySections };
42
43 class RenderTable : public RenderBlock {
44 public:
45     explicit RenderTable(Node*);
46     virtual ~RenderTable();
47
48     int getColumnPos(unsigned col) const { return m_columnPos[col]; }
49
50     int hBorderSpacing() const { return m_hSpacing; }
51     int vBorderSpacing() const { return m_vSpacing; }
52     
53     bool collapseBorders() const { return style()->borderCollapse(); }
54
55     int borderStart() const { return m_borderStart; }
56     int borderEnd() const { return m_borderEnd; }
57     int borderBefore() const;
58     int borderAfter() const;
59
60     int borderLeft() const
61     {
62         if (style()->isHorizontalWritingMode())
63             return style()->isLeftToRightDirection() ? borderStart() : borderEnd();
64         return style()->isFlippedBlocksWritingMode() ? borderAfter() : borderBefore();
65     }
66
67     int borderRight() const
68     {
69         if (style()->isHorizontalWritingMode())
70             return style()->isLeftToRightDirection() ? borderEnd() : borderStart();
71         return style()->isFlippedBlocksWritingMode() ? borderBefore() : borderAfter();
72     }
73
74     int borderTop() const
75     {
76         if (style()->isHorizontalWritingMode())
77             return style()->isFlippedBlocksWritingMode() ? borderAfter() : borderBefore();
78         return style()->isLeftToRightDirection() ? borderStart() : borderEnd();
79     }
80
81     int borderBottom() const
82     {
83         if (style()->isHorizontalWritingMode())
84             return style()->isFlippedBlocksWritingMode() ? borderBefore() : borderAfter();
85         return style()->isLeftToRightDirection() ? borderEnd() : borderStart();
86     }
87
88     Color bgColor() const { return style()->visitedDependentColor(CSSPropertyBackgroundColor); }
89
90     int outerBorderBefore() const;
91     int outerBorderAfter() const;
92     int outerBorderStart() const;
93     int outerBorderEnd() const;
94
95     int outerBorderLeft() const
96     {
97         if (style()->isHorizontalWritingMode())
98             return style()->isLeftToRightDirection() ? outerBorderStart() : outerBorderEnd();
99         return style()->isFlippedBlocksWritingMode() ? outerBorderAfter() : outerBorderBefore();
100     }
101
102     int outerBorderRight() const
103     {
104         if (style()->isHorizontalWritingMode())
105             return style()->isLeftToRightDirection() ? outerBorderEnd() : outerBorderStart();
106         return style()->isFlippedBlocksWritingMode() ? outerBorderBefore() : outerBorderAfter();
107     }
108
109     int outerBorderTop() const
110     {
111         if (style()->isHorizontalWritingMode())
112             return style()->isFlippedBlocksWritingMode() ? outerBorderAfter() : outerBorderBefore();
113         return style()->isLeftToRightDirection() ? outerBorderStart() : outerBorderEnd();
114     }
115
116     int outerBorderBottom() const
117     {
118         if (style()->isHorizontalWritingMode())
119             return style()->isFlippedBlocksWritingMode() ? outerBorderBefore() : outerBorderAfter();
120         return style()->isLeftToRightDirection() ? outerBorderEnd() : outerBorderStart();
121     }
122
123     int calcBorderStart() const;
124     int calcBorderEnd() const;
125     void recalcBordersInRowDirection();
126
127     virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0);
128
129     struct ColumnStruct {
130         ColumnStruct()
131             : span(1)
132         {
133         }
134
135         unsigned span;
136     };
137
138     void forceSectionsRecalc()
139     {
140         setNeedsSectionRecalc();
141         recalcSections();
142     }
143
144     Vector<ColumnStruct>& columns() { return m_columns; }
145     Vector<int>& columnPositions() { return m_columnPos; }
146     RenderTableSection* header() const { return m_head; }
147     RenderTableSection* footer() const { return m_foot; }
148     RenderTableSection* firstBody() const { return m_firstBody; }
149
150     // This function returns 0 if the table has no section.
151     RenderTableSection* topSection() const;
152     RenderTableSection* bottomSection() const;
153
154     // This function returns 0 if the table has no non-empty sections.
155     RenderTableSection* topNonEmptySection() const;
156
157     unsigned lastColumnIndex() const { return numEffCols() - 1; }
158
159     void splitColumn(unsigned position, unsigned firstSpan);
160     void appendColumn(unsigned span);
161     unsigned numEffCols() const { return m_columns.size(); }
162     unsigned spanOfEffCol(unsigned effCol) const { return m_columns[effCol].span; }
163     
164     unsigned colToEffCol(unsigned column) const
165     {
166         unsigned effColumn = 0;
167         unsigned numColumns = numEffCols();
168         for (unsigned c = 0; effColumn < numColumns && c + m_columns[effColumn].span - 1 < column; ++effColumn)
169             c += m_columns[effColumn].span;
170         return effColumn;
171     }
172     
173     unsigned effColToCol(unsigned effCol) const
174     {
175         unsigned c = 0;
176         for (unsigned i = 0; i < effCol; i++)
177             c += m_columns[i].span;
178         return c;
179     }
180
181     LayoutUnit bordersPaddingAndSpacingInRowDirection() const
182     {
183         return borderStart() + borderEnd() +
184                (collapseBorders() ? ZERO_LAYOUT_UNIT : (paddingStart() + paddingEnd() + static_cast<LayoutUnit>(numEffCols() + 1) * hBorderSpacing()));
185     }
186
187     // Return the first column or column-group.
188     RenderTableCol* firstColumn() const;
189
190     RenderTableCol* colElement(unsigned col, bool* startEdge = 0, bool* endEdge = 0) const;
191
192     bool needsSectionRecalc() const { return m_needsSectionRecalc; }
193     void setNeedsSectionRecalc()
194     {
195         if (documentBeingDestroyed())
196             return;
197         m_needsSectionRecalc = true;
198         setNeedsLayout(true);
199     }
200
201     RenderTableSection* sectionAbove(const RenderTableSection*, SkipEmptySectionsValue = DoNotSkipEmptySections) const;
202     RenderTableSection* sectionBelow(const RenderTableSection*, SkipEmptySectionsValue = DoNotSkipEmptySections) const;
203
204     RenderTableCell* cellAbove(const RenderTableCell*) const;
205     RenderTableCell* cellBelow(const RenderTableCell*) const;
206     RenderTableCell* cellBefore(const RenderTableCell*) const;
207     RenderTableCell* cellAfter(const RenderTableCell*) const;
208  
209     typedef Vector<CollapsedBorderValue> CollapsedBorderValues;
210     void invalidateCollapsedBorders()
211     {
212         m_collapsedBordersValid = false;
213         m_collapsedBorders.clear();
214     }
215     const CollapsedBorderValue* currentBorderValue() const { return m_currentBorder; }
216     
217     bool hasSections() const { return m_head || m_foot || m_firstBody; }
218
219     void recalcSectionsIfNeeded() const
220     {
221         if (m_needsSectionRecalc)
222             recalcSections();
223     }
224
225     static RenderTable* createAnonymousWithParentRenderer(const RenderObject*);
226     virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject* parent) const OVERRIDE
227     {
228         return createAnonymousWithParentRenderer(parent);
229     }
230
231     const BorderValue& tableStartBorderAdjoiningCell(const RenderTableCell*) const;
232     const BorderValue& tableEndBorderAdjoiningCell(const RenderTableCell*) const;
233
234 protected:
235     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
236
237 private:
238     virtual const char* renderName() const { return "RenderTable"; }
239
240     virtual bool isTable() const { return true; }
241
242     virtual bool avoidsFloats() const { return true; }
243
244     virtual void removeChild(RenderObject* oldChild);
245
246     virtual void paint(PaintInfo&, const LayoutPoint&);
247     virtual void paintObject(PaintInfo&, const LayoutPoint&);
248     virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
249     virtual void paintMask(PaintInfo&, const LayoutPoint&);
250     virtual void layout();
251     virtual void computePreferredLogicalWidths();
252     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
253
254     virtual LayoutUnit firstLineBoxBaseline() const OVERRIDE;
255     virtual LayoutUnit lastLineBoxBaseline() const OVERRIDE;
256
257     virtual RenderBlock* firstLineBlock() const;
258     virtual void updateFirstLetter();
259     
260     virtual void setCellLogicalWidths();
261
262     virtual void computeLogicalWidth();
263
264     LayoutUnit convertStyleLogicalWidthToComputedWidth(const Length& styleLogicalWidth, LayoutUnit availableWidth);
265
266     virtual LayoutRect overflowClipRect(const LayoutPoint& location, RenderRegion*, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
267
268     virtual void addOverflowFromChildren();
269
270     void subtractCaptionRect(LayoutRect&) const;
271
272     void recalcCollapsedBorders();
273     void recalcSections() const;
274     void layoutCaption(RenderTableCaption*);
275
276     void distributeExtraLogicalHeight(int extraLogicalHeight);
277
278     mutable Vector<int> m_columnPos;
279     mutable Vector<ColumnStruct> m_columns;
280     mutable Vector<RenderTableCaption*> m_captions;
281
282     mutable RenderTableSection* m_head;
283     mutable RenderTableSection* m_foot;
284     mutable RenderTableSection* m_firstBody;
285
286     OwnPtr<TableLayout> m_tableLayout;
287
288     CollapsedBorderValues m_collapsedBorders;
289     const CollapsedBorderValue* m_currentBorder;
290     bool m_collapsedBordersValid : 1;
291     
292     mutable bool m_hasColElements : 1;
293     mutable bool m_needsSectionRecalc : 1;
294     
295     short m_hSpacing;
296     short m_vSpacing;
297     int m_borderStart;
298     int m_borderEnd;
299 };
300
301 inline RenderTableSection* RenderTable::topSection() const
302 {
303     ASSERT(!needsSectionRecalc());
304     if (m_head)
305         return m_head;
306     if (m_firstBody)
307         return m_firstBody;
308     return m_foot;
309 }
310
311 inline RenderTable* toRenderTable(RenderObject* object)
312 {
313     ASSERT(!object || object->isTable());
314     return static_cast<RenderTable*>(object);
315 }
316
317 inline const RenderTable* toRenderTable(const RenderObject* object)
318 {
319     ASSERT(!object || object->isTable());
320     return static_cast<const RenderTable*>(object);
321 }
322
323 // This will catch anyone doing an unnecessary cast.
324 void toRenderTable(const RenderTable*);
325
326 } // namespace WebCore
327
328 #endif // RenderTable_h