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 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public License
21 * along with this library; see the file COPYING.LIB.  If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24 */
25
26#ifndef RenderTableCol_h
27#define RenderTableCol_h
28
29#include "core/rendering/RenderBox.h"
30
31namespace WebCore {
32
33class RenderTable;
34class RenderTableCell;
35
36class RenderTableCol FINAL : public RenderBox {
37public:
38    explicit RenderTableCol(Element*);
39
40    RenderObject* firstChild() const { ASSERT(children() == virtualChildren()); return children()->firstChild(); }
41    RenderObject* lastChild() const { ASSERT(children() == virtualChildren()); return children()->lastChild(); }
42
43    const RenderObjectChildList* children() const { return &m_children; }
44    RenderObjectChildList* children() { return &m_children; }
45
46    void clearPreferredLogicalWidthsDirtyBits();
47
48    unsigned span() const { return m_span; }
49    void setSpan(unsigned span) { m_span = span; }
50
51    bool isTableColumnGroupWithColumnChildren() { return firstChild(); }
52    bool isTableColumn() const { return style()->display() == TABLE_COLUMN; }
53    bool isTableColumnGroup() const { return style()->display() == TABLE_COLUMN_GROUP; }
54
55    RenderTableCol* enclosingColumnGroup() const;
56    RenderTableCol* enclosingColumnGroupIfAdjacentBefore() const
57    {
58        if (previousSibling())
59            return 0;
60        return enclosingColumnGroup();
61    }
62
63    RenderTableCol* enclosingColumnGroupIfAdjacentAfter() const
64    {
65        if (nextSibling())
66            return 0;
67        return enclosingColumnGroup();
68    }
69
70
71    // Returns the next column or column-group.
72    RenderTableCol* nextColumn() const;
73
74    const BorderValue& borderAdjoiningCellStartBorder(const RenderTableCell*) const;
75    const BorderValue& borderAdjoiningCellEndBorder(const RenderTableCell*) const;
76    const BorderValue& borderAdjoiningCellBefore(const RenderTableCell*) const;
77    const BorderValue& borderAdjoiningCellAfter(const RenderTableCell*) const;
78
79private:
80    virtual RenderObjectChildList* virtualChildren() { return children(); }
81    virtual const RenderObjectChildList* virtualChildren() const { return children(); }
82
83    virtual const char* renderName() const { return "RenderTableCol"; }
84    virtual bool isRenderTableCol() const OVERRIDE { return true; }
85    virtual void updateFromElement();
86    virtual void computePreferredLogicalWidths() OVERRIDE { ASSERT_NOT_REACHED(); }
87
88    virtual void insertedIntoTree() OVERRIDE;
89    virtual void willBeRemovedFromTree() OVERRIDE;
90
91    virtual bool isChildAllowed(RenderObject*, RenderStyle*) const;
92    virtual bool canHaveChildren() const;
93    virtual bool requiresLayer() const { return false; }
94
95    virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE;
96    virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
97
98    virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
99
100    RenderTable* table() const;
101
102    RenderObjectChildList m_children;
103    unsigned m_span;
104};
105
106inline RenderTableCol* toRenderTableCol(RenderObject* object)
107{
108    ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderTableCol());
109    return static_cast<RenderTableCol*>(object);
110}
111
112inline const RenderTableCol* toRenderTableCol(const RenderObject* object)
113{
114    ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderTableCol());
115    return static_cast<const RenderTableCol*>(object);
116}
117
118// This will catch anyone doing an unnecessary cast.
119void toRenderTableCol(const RenderTableCol*);
120
121}
122
123#endif
124