Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / layout / LayoutTableCol.cpp
blobefb55a11e40a7e413b5a4dc0fe2a1285d578431b
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)
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.
26 #include "config.h"
27 #include "core/layout/LayoutTableCol.h"
29 #include "core/HTMLNames.h"
30 #include "core/html/HTMLTableColElement.h"
31 #include "core/layout/LayoutTable.h"
32 #include "core/layout/LayoutTableCell.h"
34 namespace blink {
36 using namespace HTMLNames;
38 LayoutTableCol::LayoutTableCol(Element* element)
39 : LayoutBox(element)
40 , m_span(1)
42 // init LayoutObject attributes
43 setInline(true); // our object is not Inline
44 updateFromElement();
47 void LayoutTableCol::styleDidChange(StyleDifference diff, const ComputedStyle* oldStyle)
49 LayoutBox::styleDidChange(diff, oldStyle);
51 // If border was changed, notify table.
52 if (parent()) {
53 LayoutTable* table = this->table();
54 if (table && !table->selfNeedsLayout() && !table->normalChildNeedsLayout() && oldStyle && oldStyle->border() != style()->border()) {
55 table->invalidateCollapsedBorders();
56 } else if (oldStyle && oldStyle->logicalWidth() != style()->logicalWidth()) {
57 // FIXME : setPreferredLogicalWidthsDirty is done for all cells as of now.
58 // Need to find a better way so that only the cells which are changed by
59 // the col width should have preferred logical widths recomputed.
60 for (LayoutObject* child = table->children()->firstChild(); child; child = child->nextSibling()) {
61 if (!child->isTableSection())
62 continue;
63 LayoutTableSection* section = toLayoutTableSection(child);
64 for (LayoutTableRow* row = section->firstRow(); row; row = row->nextRow()) {
65 for (LayoutTableCell* cell = row->firstCell(); cell; cell = cell->nextCell())
66 cell->setPreferredLogicalWidthsDirty();
73 void LayoutTableCol::updateFromElement()
75 unsigned oldSpan = m_span;
76 Node* n = node();
77 if (isHTMLTableColElement(n)) {
78 HTMLTableColElement& tc = toHTMLTableColElement(*n);
79 m_span = tc.span();
80 } else {
81 m_span = 1;
83 if (m_span != oldSpan && style() && parent())
84 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalidationReason::AttributeChanged);
87 void LayoutTableCol::insertedIntoTree()
89 LayoutBox::insertedIntoTree();
90 table()->addColumn(this);
93 void LayoutTableCol::willBeRemovedFromTree()
95 LayoutBox::willBeRemovedFromTree();
96 table()->removeColumn(this);
99 bool LayoutTableCol::isChildAllowed(LayoutObject* child, const ComputedStyle& style) const
101 // We cannot use isTableColumn here as style() may return 0.
102 return child->isLayoutTableCol() && style.display() == TABLE_COLUMN;
105 bool LayoutTableCol::canHaveChildren() const
107 // Cols cannot have children. This is actually necessary to fix a bug
108 // with libraries.uc.edu, which makes a <p> be a table-column.
109 return isTableColumnGroup();
112 LayoutRect LayoutTableCol::clippedOverflowRectForPaintInvalidation(const LayoutBoxModelObject* paintInvalidationContainer, const PaintInvalidationState* paintInvalidationState) const
114 // For now, just paint invalidate the whole table.
115 // FIXME: Find a better way to do this, e.g., need to paint invalidate all the cells that we
116 // might have propagated a background color or borders into.
117 // FIXME: check for paintInvalidationContainer each time here?
119 LayoutTable* parentTable = table();
120 if (!parentTable)
121 return LayoutRect();
122 return parentTable->clippedOverflowRectForPaintInvalidation(paintInvalidationContainer, paintInvalidationState);
125 void LayoutTableCol::imageChanged(WrappedImagePtr, const IntRect*)
127 // FIXME: Issue paint invalidation of only the rect the image paints in.
128 setShouldDoFullPaintInvalidation();
131 void LayoutTableCol::clearPreferredLogicalWidthsDirtyBits()
133 clearPreferredLogicalWidthsDirty();
135 for (LayoutObject* child = firstChild(); child; child = child->nextSibling())
136 child->clearPreferredLogicalWidthsDirty();
139 LayoutTable* LayoutTableCol::table() const
141 LayoutObject* table = parent();
142 if (table && !table->isTable())
143 table = table->parent();
144 return table && table->isTable() ? toLayoutTable(table) : nullptr;
147 LayoutTableCol* LayoutTableCol::enclosingColumnGroup() const
149 if (!parent()->isLayoutTableCol())
150 return nullptr;
152 LayoutTableCol* parentColumnGroup = toLayoutTableCol(parent());
153 ASSERT(parentColumnGroup->isTableColumnGroup());
154 ASSERT(isTableColumn());
155 return parentColumnGroup;
158 LayoutTableCol* LayoutTableCol::nextColumn() const
160 // If |this| is a column-group, the next column is the colgroup's first child column.
161 if (LayoutObject* firstChild = this->firstChild())
162 return toLayoutTableCol(firstChild);
164 // Otherwise it's the next column along.
165 LayoutObject* next = nextSibling();
167 // 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.
168 if (!next && parent()->isLayoutTableCol())
169 next = parent()->nextSibling();
171 for (; next && !next->isLayoutTableCol(); next = next->nextSibling()) { }
173 return toLayoutTableCol(next);
176 const BorderValue& LayoutTableCol::borderAdjoiningCellStartBorder(const LayoutTableCell*) const
178 return style()->borderStart();
181 const BorderValue& LayoutTableCol::borderAdjoiningCellEndBorder(const LayoutTableCell*) const
183 return style()->borderEnd();
186 const BorderValue& LayoutTableCol::borderAdjoiningCellBefore(const LayoutTableCell* cell) const
188 ASSERT_UNUSED(cell, table()->colElement(cell->col() + cell->colSpan()) == this);
189 return style()->borderStart();
192 const BorderValue& LayoutTableCol::borderAdjoiningCellAfter(const LayoutTableCell* cell) const
194 ASSERT_UNUSED(cell, table()->colElement(cell->col() - 1) == this);
195 return style()->borderEnd();