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)
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.
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.
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.
27 #include "RenderTableCol.h"
29 #include "CachedImage.h"
30 #include "HTMLNames.h"
31 #include "HTMLTableColElement.h"
32 #include "RenderTable.h"
36 using namespace HTMLNames;
38 RenderTableCol::RenderTableCol(Node* node)
42 // init RenderObject attributes
43 setInline(true); // our object is not Inline
47 void RenderTableCol::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
49 RenderBox::styleDidChange(diff, oldStyle);
51 // If border was changed, notify table.
53 RenderTable* table = this->table();
54 if (table && !table->selfNeedsLayout() && !table->normalChildNeedsLayout() && oldStyle && oldStyle->border() != style()->border())
55 table->invalidateCollapsedBorders();
59 void RenderTableCol::updateFromElement()
61 unsigned oldSpan = m_span;
63 if (n && (n->hasTagName(colTag) || n->hasTagName(colgroupTag))) {
64 HTMLTableColElement* tc = static_cast<HTMLTableColElement*>(n);
67 m_span = !(style() && style()->display() == TABLE_COLUMN_GROUP);
68 if (m_span != oldSpan && style() && parent())
69 setNeedsLayoutAndPrefWidthsRecalc();
72 bool RenderTableCol::isChildAllowed(RenderObject* child, RenderStyle* style) const
74 // We cannot use isTableColumn here as style() may return 0.
75 return child->isRenderTableCol() && style->display() == TABLE_COLUMN;
78 bool RenderTableCol::canHaveChildren() const
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();
85 LayoutRect RenderTableCol::clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer) const
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?
92 RenderTable* parentTable = table();
95 return parentTable->clippedOverflowRectForRepaint(repaintContainer);
98 void RenderTableCol::imageChanged(WrappedImagePtr, const IntRect*)
100 // FIXME: Repaint only the rect the image paints in.
104 void RenderTableCol::computePreferredLogicalWidths()
106 setPreferredLogicalWidthsDirty(false);
108 for (RenderObject* child = firstChild(); child; child = child->nextSibling())
109 child->setPreferredLogicalWidthsDirty(false);
112 RenderTable* RenderTableCol::table() const
114 RenderObject* table = parent();
115 if (table && !table->isTable())
116 table = table->parent();
117 return table && table->isTable() ? toRenderTable(table) : 0;
120 RenderTableCol* RenderTableCol::enclosingColumnGroup() const
122 if (!parent()->isRenderTableCol())
125 RenderTableCol* parentColumnGroup = toRenderTableCol(parent());
126 ASSERT(parentColumnGroup->isTableColumnGroup());
127 ASSERT(isTableColumn());
128 return parentColumnGroup;
131 RenderTableCol* RenderTableCol::nextColumn() const
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);
137 // Otherwise it's the next column along.
138 RenderObject* next = nextSibling();
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();
144 for (; next && !next->isRenderTableCol(); next = next->nextSibling()) {
145 // We allow captions mixed with columns and column-groups.
146 if (next->isTableCaption())
152 return toRenderTableCol(next);