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 RenderTableRow_h
26#define RenderTableRow_h
27
28#include "RenderTableSection.h"
29
30namespace WebCore {
31
32static const unsigned unsetRowIndex = 0x7FFFFFFF;
33static const unsigned maxRowIndex = 0x7FFFFFFE; // 2,147,483,646
34
35class RenderTableRow : public RenderBox {
36public:
37    explicit RenderTableRow(Element*);
38
39    RenderObject* firstChild() const { ASSERT(children() == virtualChildren()); return children()->firstChild(); }
40    RenderObject* lastChild() const { ASSERT(children() == virtualChildren()); return children()->lastChild(); }
41
42    const RenderObjectChildList* children() const { return &m_children; }
43    RenderObjectChildList* children() { return &m_children; }
44
45    RenderTableSection* section() const { return toRenderTableSection(parent()); }
46    RenderTable* table() const { return toRenderTable(parent()->parent()); }
47
48    void paintOutlineForRowIfNeeded(PaintInfo&, const LayoutPoint&);
49
50    static RenderTableRow* createAnonymous(Document*);
51    static RenderTableRow* createAnonymousWithParentRenderer(const RenderObject*);
52    virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject* parent) const OVERRIDE
53    {
54        return createAnonymousWithParentRenderer(parent);
55    }
56
57    void setRowIndex(unsigned rowIndex)
58    {
59        if (UNLIKELY(rowIndex > maxRowIndex))
60            CRASH();
61
62        m_rowIndex = rowIndex;
63    }
64
65    bool rowIndexWasSet() const { return m_rowIndex != unsetRowIndex; }
66    unsigned rowIndex() const
67    {
68        ASSERT(rowIndexWasSet());
69        return m_rowIndex;
70    }
71
72    const BorderValue& borderAdjoiningTableStart() const
73    {
74        if (section()->hasSameDirectionAs(table()))
75            return style()->borderStart();
76
77        return style()->borderEnd();
78    }
79
80    const BorderValue& borderAdjoiningTableEnd() const
81    {
82        if (section()->hasSameDirectionAs(table()))
83            return style()->borderEnd();
84
85        return style()->borderStart();
86    }
87
88    const BorderValue& borderAdjoiningStartCell(const RenderTableCell*) const;
89    const BorderValue& borderAdjoiningEndCell(const RenderTableCell*) const;
90
91private:
92    virtual RenderObjectChildList* virtualChildren() { return children(); }
93    virtual const RenderObjectChildList* virtualChildren() const { return children(); }
94
95    virtual const char* renderName() const { return (isAnonymous() || isPseudoElement()) ? "RenderTableRow (anonymous)" : "RenderTableRow"; }
96
97    virtual bool isTableRow() const { return true; }
98
99    virtual void willBeRemovedFromTree() OVERRIDE;
100
101    virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0);
102    virtual void layout();
103    virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const;
104    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
105
106    virtual bool requiresLayer() const OVERRIDE { return hasOverflowClip() || hasTransform() || hasHiddenBackface() || hasClipPath() || createsGroup(); }
107
108    virtual void paint(PaintInfo&, const LayoutPoint&);
109
110    virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
111
112    virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
113
114    RenderObjectChildList m_children;
115    unsigned m_rowIndex : 31;
116};
117
118inline RenderTableRow* toRenderTableRow(RenderObject* object)
119{
120    ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isTableRow());
121    return static_cast<RenderTableRow*>(object);
122}
123
124inline const RenderTableRow* toRenderTableRow(const RenderObject* object)
125{
126    ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isTableRow());
127    return static_cast<const RenderTableRow*>(object);
128}
129
130// This will catch anyone doing an unnecessary cast.
131void toRenderTableRow(const RenderTableRow*);
132
133} // namespace WebCore
134
135#endif // RenderTableRow_h
136