Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 1997 Martin Jones (mjones (at) kde.org)
      3  *           (C) 1997 Torben Weis (weis (at) kde.org)
      4  *           (C) 1998 Waldo Bastian (bastian (at) kde.org)
      5  *           (C) 1999 Lars Knoll (knoll (at) kde.org)
      6  *           (C) 1999 Antti Koivisto (koivisto (at) 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 #ifdef ANDROID_LAYOUT
    145     void clearSingleColumn() { m_singleColumn = false; }
    146     bool isSingleColumn() const { return m_singleColumn; }
    147 #endif
    148 
    149 protected:
    150     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
    151 
    152 private:
    153     virtual const char* renderName() const { return "RenderTable"; }
    154 
    155     virtual bool isTable() const { return true; }
    156 
    157     virtual bool avoidsFloats() const { return true; }
    158 
    159     virtual void removeChild(RenderObject* oldChild);
    160 
    161     virtual void paint(PaintInfo&, int tx, int ty);
    162     virtual void paintObject(PaintInfo&, int tx, int ty);
    163     virtual void paintBoxDecorations(PaintInfo&, int tx, int ty);
    164     virtual void paintMask(PaintInfo&, int tx, int ty);
    165     virtual void layout();
    166     virtual void calcPrefWidths();
    167     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int xPos, int yPos, int tx, int ty, HitTestAction);
    168 
    169     virtual int firstLineBoxBaseline() const;
    170 
    171     virtual RenderBlock* firstLineBlock() const;
    172     virtual void updateFirstLetter();
    173 
    174     virtual void setCellWidths();
    175 
    176     virtual void calcWidth();
    177 
    178     virtual IntRect overflowClipRect(int tx, int ty);
    179 
    180     void recalcSections() const;
    181 
    182     mutable Vector<int> m_columnPos;
    183     mutable Vector<ColumnStruct> m_columns;
    184 
    185     mutable RenderBlock* m_caption;
    186     mutable RenderTableSection* m_head;
    187     mutable RenderTableSection* m_foot;
    188     mutable RenderTableSection* m_firstBody;
    189 
    190     OwnPtr<TableLayout> m_tableLayout;
    191 
    192     const CollapsedBorderValue* m_currentBorder;
    193 
    194     mutable bool m_hasColElements : 1;
    195     mutable bool m_needsSectionRecalc : 1;
    196 
    197 #ifdef ANDROID_LAYOUT
    198     bool m_singleColumn;        // BS(Grace): should I use compact version?
    199 #endif
    200     short m_hSpacing;
    201     short m_vSpacing;
    202     int m_borderLeft;
    203     int m_borderRight;
    204 };
    205 
    206 inline RenderTable* toRenderTable(RenderObject* object)
    207 {
    208     ASSERT(!object || object->isTable());
    209     return static_cast<RenderTable*>(object);
    210 }
    211 
    212 inline const RenderTable* toRenderTable(const RenderObject* object)
    213 {
    214     ASSERT(!object || object->isTable());
    215     return static_cast<const RenderTable*>(object);
    216 }
    217 
    218 // This will catch anyone doing an unnecessary cast.
    219 void toRenderTable(const RenderTable*);
    220 
    221 } // namespace WebCore
    222 
    223 #endif // RenderTable_h
    224