Fix the issue that Web Audio test case fails on PR3.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / RenderTableCol.cpp
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 #include "config.h"
27 #include "RenderTableCol.h"
28
29 #include "CachedImage.h"
30 #include "HTMLNames.h"
31 #include "HTMLTableColElement.h"
32 #include "RenderTable.h"
33
34 namespace WebCore {
35
36 using namespace HTMLNames;
37
38 RenderTableCol::RenderTableCol(Node* node)
39     : RenderBox(node)
40     , m_span(1)
41 {
42     // init RenderObject attributes
43     setInline(true); // our object is not Inline
44     updateFromElement();
45 }
46
47 void RenderTableCol::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
48 {
49     RenderBox::styleDidChange(diff, oldStyle);
50
51     // If border was changed, notify table.
52     if (parent()) {
53         RenderTable* table = this->table();
54         if (table && !table->selfNeedsLayout() && !table->normalChildNeedsLayout() && oldStyle && oldStyle->border() != style()->border())
55             table->invalidateCollapsedBorders();
56     }
57 }
58
59 void RenderTableCol::updateFromElement()
60 {
61     unsigned oldSpan = m_span;
62     Node* n = node();
63     if (n && (n->hasTagName(colTag) || n->hasTagName(colgroupTag))) {
64         HTMLTableColElement* tc = static_cast<HTMLTableColElement*>(n);
65         m_span = tc->span();
66     } else
67         m_span = !(style() && style()->display() == TABLE_COLUMN_GROUP);
68     if (m_span != oldSpan && style() && parent())
69         setNeedsLayoutAndPrefWidthsRecalc();
70 }
71
72 bool RenderTableCol::isChildAllowed(RenderObject* child, RenderStyle* style) const
73 {
74     // We cannot use isTableColumn here as style() may return 0.
75     return child->isRenderTableCol() && style->display() == TABLE_COLUMN;
76 }
77
78 bool RenderTableCol::canHaveChildren() const
79 {
80     // Cols cannot have children. This is actually necessary to fix a bug
81     // with libraries.uc.edu, which makes a <p> be a table-column.
82     return isTableColumnGroup();
83 }
84
85 LayoutRect RenderTableCol::clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer) const
86 {
87     // For now, just repaint the whole table.
88     // FIXME: Find a better way to do this, e.g., need to repaint all the cells that we
89     // might have propagated a background color or borders into.
90     // FIXME: check for repaintContainer each time here?
91
92     RenderTable* parentTable = table();
93     if (!parentTable)
94         return LayoutRect();
95     return parentTable->clippedOverflowRectForRepaint(repaintContainer);
96 }
97
98 void RenderTableCol::imageChanged(WrappedImagePtr, const IntRect*)
99 {
100     // FIXME: Repaint only the rect the image paints in.
101     repaint();
102 }
103
104 void RenderTableCol::computePreferredLogicalWidths()
105 {
106     setPreferredLogicalWidthsDirty(false);
107
108     for (RenderObject* child = firstChild(); child; child = child->nextSibling())
109         child->setPreferredLogicalWidthsDirty(false);
110 }
111
112 RenderTable* RenderTableCol::table() const
113 {
114     RenderObject* table = parent();
115     if (table && !table->isTable())
116         table = table->parent();
117     return table && table->isTable() ? toRenderTable(table) : 0;
118 }
119
120 RenderTableCol* RenderTableCol::enclosingColumnGroup() const
121 {
122     if (!parent()->isRenderTableCol())
123         return 0;
124
125     RenderTableCol* parentColumnGroup = toRenderTableCol(parent());
126     ASSERT(parentColumnGroup->isTableColumnGroup());
127     ASSERT(isTableColumn());
128     return parentColumnGroup;
129 }
130
131 RenderTableCol* RenderTableCol::nextColumn() const
132 {
133     // If |this| is a column-group, the next column is the colgroup's first child column.
134     if (RenderObject* firstChild = this->firstChild())
135         return toRenderTableCol(firstChild);
136
137     // Otherwise it's the next column along.
138     RenderObject* next = nextSibling();
139
140     // Failing that, the child is the last column in a column-group, so the next column is the next column/column-group after its column-group.
141     if (!next && parent()->isRenderTableCol())
142         next = parent()->nextSibling();
143
144     for (; next && !next->isRenderTableCol(); next = next->nextSibling()) {
145         // We allow captions mixed with columns and column-groups.
146         if (next->isTableCaption())
147             continue;
148
149         return 0;
150     }
151
152     return toRenderTableCol(next);
153 }
154
155 }