root/trunk/WebCore/rendering/RenderTable.h

Revision 46647, 6.5 KB (checked in by darin@apple.com, 4 months ago)

WebCore:

2009-07-30 Darin Adler < darin@apple.com>

Reviewed by David Levin.

Use checked casts for render tree
 https://bugs.webkit.org/show_bug.cgi?id=23522

Next step: Add casts for all the RenderTable classes and use them everywhere.

Also added a few uses in places that were still using static_cast.
Also made some virtual member functions private.
Also changed RenderTable::m_tableLayout to use OwnPtr.

  • accessibility/AccessibilityTable.cpp: (WebCore::AccessibilityTable::isTableExposableThroughAccessibility): (WebCore::AccessibilityTable::addChildren): (WebCore::AccessibilityTable::cellForColumnAndRow):
  • accessibility/AccessibilityTableCell.cpp: (WebCore::AccessibilityTableCell::parentTable): (WebCore::AccessibilityTableCell::rowIndexRange): (WebCore::AccessibilityTableCell::columnIndexRange): (WebCore::AccessibilityTableCell::titleUIElement):
  • accessibility/AccessibilityTableColumn.cpp: (WebCore::AccessibilityTableColumn::headerObject):
  • accessibility/AccessibilityTableRow.cpp: (WebCore::AccessibilityTableRow::parentTable):
  • editing/DeleteSelectionCommand.cpp: (WebCore::DeleteSelectionCommand::removeNode):
  • editing/TextIterator.cpp: (WebCore::shouldEmitTabBeforeNode): (WebCore::shouldEmitNewlinesBeforeAndAfterNode):
  • html/HTMLTableCellElement.cpp: (WebCore::HTMLTableCellElement::parseMappedAttribute):
  • html/HTMLTableColElement.cpp: (WebCore::HTMLTableColElement::parseMappedAttribute):
  • page/Frame.cpp: (WebCore::Frame::searchForLabelsAboveCell):
  • page/mac/FrameMac.mm: (WebCore::Frame::searchForNSLabelsAboveCell):
  • rendering/AutoTableLayout.cpp: (WebCore::AutoTableLayout::recalcColumn): (WebCore::AutoTableLayout::fullRecalc): (WebCore::shouldScaleColumns):
  • rendering/FixedTableLayout.cpp: (WebCore::FixedTableLayout::calcWidthArray):
  • rendering/RenderBlock.cpp: (WebCore::RenderBlock::calcPrefWidths):
  • rendering/RenderBox.cpp: (WebCore::RenderBox::calcPercentageHeight):
  • rendering/RenderObject.cpp: (WebCore::RenderObject::addChild): (WebCore::RenderObject::containingBlock):
  • rendering/RenderTableCell.cpp: (WebCore::RenderTableCell::collapsedBottomBorder):
  • rendering/RenderTableCol.cpp: (WebCore::RenderTableCol::table):
  • rendering/RenderTableRow.cpp: (WebCore::RenderTableRow::addChild): (WebCore::RenderTableRow::layout): (WebCore::RenderTableRow::paint):
  • rendering/RenderTableSection.cpp: (WebCore::RenderTableSection::addChild): (WebCore::RenderTableSection::layoutRows): (WebCore::RenderTableSection::lowestPosition): (WebCore::RenderTableSection::rightmostPosition): (WebCore::RenderTableSection::leftmostPosition): (WebCore::RenderTableSection::paintObject): (WebCore::RenderTableSection::recalcCells):
  • rendering/RenderTreeAsText.cpp: (WebCore::operator<<): (WebCore::writeTextRun): Use checked casts.
  • rendering/RenderTable.cpp: (WebCore::RenderTable::styleDidChange): Updated to use OwnPtr. (WebCore::RenderTable::addChild): Use checked cast. (WebCore::RenderTable::layout): Ditto. (WebCore::RenderTable::setCellWidths): Ditto. (WebCore::RenderTable::paintObject): Ditto. (WebCore::RenderTable::splitColumn): Ditto. (WebCore::RenderTable::appendColumn): Ditto. (WebCore::RenderTable::colElement): Ditto. (WebCore::RenderTable::recalcSections): Ditto. (WebCore::RenderTable::outerBorderBottom): Ditto. (WebCore::RenderTable::outerBorderLeft): Ditto. (WebCore::RenderTable::outerBorderRight): Ditto. (WebCore::RenderTable::sectionAbove): Ditto. (WebCore::RenderTable::sectionBelow): Ditto.
  • rendering/RenderTable.h: Added checked cast. Made virtual functions private. Changed m_tableLayout to be a OwnPtr.
  • rendering/RenderTableCell.h: Added checked cast.
  • rendering/RenderTableCol.h: Ditto. Made virtual functions private.
  • rendering/RenderTableRow.h: Ditto.
  • rendering/RenderTableSection.h: Ditto.

WebKit/mac:

2009-07-30 Darin Adler < darin@apple.com>

Reviewed by David Levin.

Use checked casts for render tree
 https://bugs.webkit.org/show_bug.cgi?id=23522

  • Misc/WebNSAttributedStringExtras.mm: (fileWrapperForElement):
  • Misc/WebNSPasteboardExtras.mm: (imageFromElement): (-[NSPasteboard _web_declareAndWriteDragImageForElement:URL:title:archive:source:]):
  • WebView/WebFrame.mm: (-[WebFrame _computePageRectsWithPrintWidthScaleFactor:printHeight:]): (-[WebFrame _accessibilityTree]):
  • WebView/WebRenderNode.mm: (copyRenderNode): Use checked casts.

WebKit/win:

2009-07-30 Darin Adler < darin@apple.com>

Reviewed by David Levin.

Use checked casts for render tree
 https://bugs.webkit.org/show_bug.cgi?id=23522

  • DOMHTMLClasses.cpp: (DOMHTMLInputElement::isUserEdited): (DOMHTMLTextAreaElement::isUserEdited): Use checked casts.
  • Property svn:eol-style set to native
Line 
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
31namespace WebCore {
32
33class RenderTableCol;
34class RenderTableCell;
35class RenderTableSection;
36class TableLayout;
37
38class RenderTable : public RenderBlock {
39public:
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
144protected:
145    virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
146
147private:
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
198inline RenderTable* toRenderTable(RenderObject* object)
199{
200    ASSERT(!object || object->isTable());
201    return static_cast<RenderTable*>(object);
202}
203
204inline 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.
211void toRenderTable(const RenderTable*);
212
213} // namespace WebCore
214
215#endif // RenderTable_h
Note: See TracBrowser for help on using the browser.