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, 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
     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 styleOrColWidth() const;
     55 
     56     virtual void calcPrefWidths();
     57 
     58 #if PLATFORM(ANDROID)
     59 #ifdef ANDROID_LAYOUT
     60     // RenderTableSection needs to access this in setCellWidths()
     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 
     96     void setIntrinsicPaddingTop(int p) { m_intrinsicPaddingTop = p; }
     97     void setIntrinsicPaddingBottom(int p) { m_intrinsicPaddingBottom = p; }
     98     void setIntrinsicPadding(int top, int bottom) { setIntrinsicPaddingTop(top); setIntrinsicPaddingBottom(bottom); }
     99     void clearIntrinsicPadding() { setIntrinsicPadding(0, 0); }
    100 
    101     int intrinsicPaddingTop() const { return m_intrinsicPaddingTop; }
    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     bool hasVisibleOverflow() const { return m_overflow; }
    110 
    111 protected:
    112     virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
    113     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
    114 
    115 private:
    116     virtual const char* renderName() const { return isAnonymous() ? "RenderTableCell (anonymous)" : "RenderTableCell"; }
    117 
    118     virtual bool isTableCell() const { return true; }
    119 
    120     virtual void destroy();
    121 
    122     virtual bool requiresLayer() const { return isPositioned() || isTransparent() || hasOverflowClip() || hasTransform() || hasMask() || hasReflection(); }
    123 
    124     virtual void calcWidth();
    125 
    126     virtual void paintBoxDecorations(PaintInfo&, int tx, int ty);
    127     virtual void paintMask(PaintInfo&, int tx, int ty);
    128 
    129     virtual IntSize offsetFromContainer(RenderObject*) const;
    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 
    144 inline RenderTableCell* toRenderTableCell(RenderObject* object)
    145 {
    146     ASSERT(!object || object->isTableCell());
    147     return static_cast<RenderTableCell*>(object);
    148 }
    149 
    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