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, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved.
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.
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.
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.
26 #include "core/rendering/RenderTableRow.h"
28 #include "core/HTMLNames.h"
29 #include "core/fetch/ImageResource.h"
30 #include "core/paint/TableRowPainter.h"
31 #include "core/rendering/GraphicsContextAnnotator.h"
32 #include "core/rendering/HitTestResult.h"
33 #include "core/rendering/PaintInfo.h"
34 #include "core/rendering/RenderTableCell.h"
35 #include "core/rendering/RenderView.h"
36 #include "core/rendering/SubtreeLayoutScope.h"
37 #include "core/rendering/style/StyleInheritedData.h"
41 using namespace HTMLNames;
43 RenderTableRow::RenderTableRow(Element* element)
45 , m_rowIndex(unsetRowIndex)
47 // init RenderObject attributes
48 setInline(false); // our object is not Inline
51 void RenderTableRow::trace(Visitor* visitor)
53 visitor->trace(m_children);
54 RenderBox::trace(visitor);
57 void RenderTableRow::willBeRemovedFromTree()
59 RenderBox::willBeRemovedFromTree();
61 section()->setNeedsCellRecalc();
64 static bool borderWidthChanged(const RenderStyle* oldStyle, const RenderStyle* newStyle)
66 return oldStyle->borderLeftWidth() != newStyle->borderLeftWidth()
67 || oldStyle->borderTopWidth() != newStyle->borderTopWidth()
68 || oldStyle->borderRightWidth() != newStyle->borderRightWidth()
69 || oldStyle->borderBottomWidth() != newStyle->borderBottomWidth();
72 void RenderTableRow::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
74 ASSERT(style()->display() == TABLE_ROW);
76 RenderBox::styleDidChange(diff, oldStyle);
77 propagateStyleToAnonymousChildren();
79 if (section() && oldStyle && style()->logicalHeight() != oldStyle->logicalHeight())
80 section()->rowLogicalHeightChanged(this);
82 // If border was changed, notify table.
84 RenderTable* table = this->table();
85 if (table && !table->selfNeedsLayout() && !table->normalChildNeedsLayout() && oldStyle && oldStyle->border() != style()->border())
86 table->invalidateCollapsedBorders();
88 if (table && oldStyle && diff.needsFullLayout() && needsLayout() && table->collapseBorders() && borderWidthChanged(oldStyle, style())) {
89 // If the border width changes on a row, we need to make sure the cells in the row know to lay out again.
90 // This only happens when borders are collapsed, since they end up affecting the border sides of the cell
92 for (RenderBox* childBox = firstChildBox(); childBox; childBox = childBox->nextSiblingBox()) {
93 if (!childBox->isTableCell())
95 childBox->setChildNeedsLayout();
101 const BorderValue& RenderTableRow::borderAdjoiningStartCell(const RenderTableCell* cell) const
103 ASSERT_UNUSED(cell, cell->isFirstOrLastCellInRow());
104 // FIXME: https://webkit.org/b/79272 - Add support for mixed directionality at the cell level.
105 return style()->borderStart();
108 const BorderValue& RenderTableRow::borderAdjoiningEndCell(const RenderTableCell* cell) const
110 ASSERT_UNUSED(cell, cell->isFirstOrLastCellInRow());
111 // FIXME: https://webkit.org/b/79272 - Add support for mixed directionality at the cell level.
112 return style()->borderEnd();
115 void RenderTableRow::addChild(RenderObject* child, RenderObject* beforeChild)
117 if (!child->isTableCell()) {
118 RenderObject* last = beforeChild;
121 if (last && last->isAnonymous() && last->isTableCell() && !last->isBeforeOrAfterContent()) {
122 RenderTableCell* lastCell = toRenderTableCell(last);
123 if (beforeChild == lastCell)
124 beforeChild = lastCell->firstChild();
125 lastCell->addChild(child, beforeChild);
129 if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == this) {
130 RenderObject* cell = beforeChild->previousSibling();
131 if (cell && cell->isTableCell() && cell->isAnonymous()) {
132 cell->addChild(child);
137 // If beforeChild is inside an anonymous cell, insert into the cell.
138 if (last && !last->isTableCell() && last->parent() && last->parent()->isAnonymous() && !last->parent()->isBeforeOrAfterContent()) {
139 last->parent()->addChild(child, beforeChild);
143 RenderTableCell* cell = RenderTableCell::createAnonymousWithParentRenderer(this);
144 addChild(cell, beforeChild);
145 cell->addChild(child);
149 if (beforeChild && beforeChild->parent() != this)
150 beforeChild = splitAnonymousBoxesAroundChild(beforeChild);
152 RenderTableCell* cell = toRenderTableCell(child);
154 // Generated content can result in us having a null section so make sure to null check our parent.
156 section()->addCell(cell, this);
158 ASSERT(!beforeChild || beforeChild->isTableCell());
159 RenderBox::addChild(cell, beforeChild);
161 if (beforeChild || nextRow())
162 section()->setNeedsCellRecalc();
165 void RenderTableRow::layout()
167 ASSERT(needsLayout());
169 // Table rows do not add translation.
170 LayoutState state(*this, LayoutSize());
172 for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) {
173 SubtreeLayoutScope layouter(*cell);
174 if (!cell->needsLayout())
175 cell->markForPaginationRelayoutIfNeeded(layouter);
176 if (cell->needsLayout()) {
177 cell->computeAndSetBlockDirectionMargins(table());
183 addVisualEffectOverflow();
184 // We do not call addOverflowFromCell here. The cell are laid out to be
185 // measured above and will be sized correctly in a follow-up phase.
187 // We only ever need to issue paint invalidations if our cells didn't, which means that they didn't need
188 // layout, so we know that our bounds didn't change. This code is just making up for
189 // the fact that we did not invalidate paints in setStyle() because we had a layout hint.
190 if (selfNeedsLayout()) {
191 for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) {
192 // FIXME: Is this needed when issuing paint invalidations after layout?
193 cell->setShouldDoFullPaintInvalidation();
197 // RenderTableSection::layoutRows will set our logical height and width later, so it calls updateLayerTransform().
202 bool RenderTableRow::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action)
204 // Table rows cannot ever be hit tested. Effectively they do not exist.
205 // Just forward to our children always.
206 for (RenderTableCell* cell = lastCell(); cell; cell = cell->previousCell()) {
207 // FIXME: We have to skip over inline flows, since they can show up inside table rows
208 // at the moment (a demoted inline <form> for example). If we ever implement a
209 // table-specific hit-test method (which we should do for performance reasons anyway),
210 // then we can remove this check.
211 if (!cell->hasSelfPaintingLayer()) {
212 LayoutPoint cellPoint = flipForWritingModeForChild(cell, accumulatedOffset);
213 if (cell->nodeAtPoint(request, result, locationInContainer, cellPoint, action)) {
214 updateHitTestResult(result, locationInContainer.point() - toLayoutSize(cellPoint));
223 void RenderTableRow::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
225 TableRowPainter(*this).paint(paintInfo, paintOffset);
228 void RenderTableRow::imageChanged(WrappedImagePtr, const IntRect*)
230 // FIXME: Examine cells and issue paint invalidations of only the rect the image paints in.
231 setShouldDoFullPaintInvalidation();
234 RenderTableRow* RenderTableRow::createAnonymous(Document* document)
236 RenderTableRow* renderer = new RenderTableRow(0);
237 renderer->setDocumentForAnonymous(document);
241 RenderTableRow* RenderTableRow::createAnonymousWithParentRenderer(const RenderObject* parent)
243 RenderTableRow* newRow = RenderTableRow::createAnonymous(&parent->document());
244 RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisplay(parent->style(), TABLE_ROW);
245 newRow->setStyle(newStyle.release());
249 void RenderTableRow::addOverflowFromCell(const RenderTableCell* cell)
251 // Non-row-spanning-cells don't create overflow (they are fully contained within this row).
252 if (cell->rowSpan() == 1)
255 // Cells only generates visual overflow.
256 LayoutRect cellVisualOverflowRect = cell->visualOverflowRectForPropagation(style());
258 // The cell and the row share the section's coordinate system. However
259 // the visual overflow should be determined in the coordinate system of
260 // the row, that's why we shift it below.
261 LayoutUnit cellOffsetLogicalTopDifference = cell->location().y() - location().y();
262 cellVisualOverflowRect.move(0, cellOffsetLogicalTopDifference);
264 addVisualOverflow(cellVisualOverflowRect);