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/rendering/GraphicsContextAnnotator.h"
31 #include "core/rendering/HitTestResult.h"
32 #include "core/rendering/PaintInfo.h"
33 #include "core/rendering/RenderTableCell.h"
34 #include "core/rendering/RenderView.h"
35 #include "core/rendering/SubtreeLayoutScope.h"
36 #include "core/rendering/style/StyleInheritedData.h"
40 using namespace HTMLNames;
42 RenderTableRow::RenderTableRow(Element* element)
44 , m_rowIndex(unsetRowIndex)
46 // init RenderObject attributes
47 setInline(false); // our object is not Inline
50 void RenderTableRow::trace(Visitor* visitor)
52 visitor->trace(m_children);
53 RenderBox::trace(visitor);
56 void RenderTableRow::willBeRemovedFromTree()
58 RenderBox::willBeRemovedFromTree();
60 section()->setNeedsCellRecalc();
63 static bool borderWidthChanged(const RenderStyle* oldStyle, const RenderStyle* newStyle)
65 return oldStyle->borderLeftWidth() != newStyle->borderLeftWidth()
66 || oldStyle->borderTopWidth() != newStyle->borderTopWidth()
67 || oldStyle->borderRightWidth() != newStyle->borderRightWidth()
68 || oldStyle->borderBottomWidth() != newStyle->borderBottomWidth();
71 void RenderTableRow::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
73 ASSERT(style()->display() == TABLE_ROW);
75 RenderBox::styleDidChange(diff, oldStyle);
76 propagateStyleToAnonymousChildren();
78 if (section() && oldStyle && style()->logicalHeight() != oldStyle->logicalHeight())
79 section()->rowLogicalHeightChanged(rowIndex());
81 // If border was changed, notify table.
83 RenderTable* table = this->table();
84 if (table && !table->selfNeedsLayout() && !table->normalChildNeedsLayout() && oldStyle && oldStyle->border() != style()->border())
85 table->invalidateCollapsedBorders();
87 if (table && oldStyle && diff.needsFullLayout() && needsLayout() && table->collapseBorders() && borderWidthChanged(oldStyle, style())) {
88 // If the border width changes on a row, we need to make sure the cells in the row know to lay out again.
89 // This only happens when borders are collapsed, since they end up affecting the border sides of the cell
91 for (RenderBox* childBox = firstChildBox(); childBox; childBox = childBox->nextSiblingBox()) {
92 if (!childBox->isTableCell())
94 childBox->setChildNeedsLayout();
100 const BorderValue& RenderTableRow::borderAdjoiningStartCell(const RenderTableCell* cell) const
102 ASSERT_UNUSED(cell, cell->isFirstOrLastCellInRow());
103 // FIXME: https://webkit.org/b/79272 - Add support for mixed directionality at the cell level.
104 return style()->borderStart();
107 const BorderValue& RenderTableRow::borderAdjoiningEndCell(const RenderTableCell* cell) const
109 ASSERT_UNUSED(cell, cell->isFirstOrLastCellInRow());
110 // FIXME: https://webkit.org/b/79272 - Add support for mixed directionality at the cell level.
111 return style()->borderEnd();
114 void RenderTableRow::addChild(RenderObject* child, RenderObject* beforeChild)
116 if (!child->isTableCell()) {
117 RenderObject* last = beforeChild;
120 if (last && last->isAnonymous() && last->isTableCell() && !last->isBeforeOrAfterContent()) {
121 RenderTableCell* lastCell = toRenderTableCell(last);
122 if (beforeChild == lastCell)
123 beforeChild = lastCell->firstChild();
124 lastCell->addChild(child, beforeChild);
128 if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == this) {
129 RenderObject* cell = beforeChild->previousSibling();
130 if (cell && cell->isTableCell() && cell->isAnonymous()) {
131 cell->addChild(child);
136 // If beforeChild is inside an anonymous cell, insert into the cell.
137 if (last && !last->isTableCell() && last->parent() && last->parent()->isAnonymous() && !last->parent()->isBeforeOrAfterContent()) {
138 last->parent()->addChild(child, beforeChild);
142 RenderTableCell* cell = RenderTableCell::createAnonymousWithParentRenderer(this);
143 addChild(cell, beforeChild);
144 cell->addChild(child);
148 if (beforeChild && beforeChild->parent() != this)
149 beforeChild = splitAnonymousBoxesAroundChild(beforeChild);
151 RenderTableCell* cell = toRenderTableCell(child);
153 // Generated content can result in us having a null section so make sure to null check our parent.
155 section()->addCell(cell, this);
157 ASSERT(!beforeChild || beforeChild->isTableCell());
158 RenderBox::addChild(cell, beforeChild);
160 if (beforeChild || nextRow())
161 section()->setNeedsCellRecalc();
164 void RenderTableRow::layout()
166 ASSERT(needsLayout());
168 // Table rows do not add translation.
169 LayoutState state(*this, LayoutSize());
171 for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) {
172 SubtreeLayoutScope layouter(*cell);
173 if (!cell->needsLayout())
174 cell->markForPaginationRelayoutIfNeeded(layouter);
175 if (cell->needsLayout()) {
176 cell->computeAndSetBlockDirectionMargins(table());
182 addVisualEffectOverflow();
184 // We only ever need to issue paint invalidations if our cells didn't, which means that they didn't need
185 // layout, so we know that our bounds didn't change. This code is just making up for
186 // the fact that we did not invalidate paints in setStyle() because we had a layout hint.
187 // We cannot call repaint() because our clippedOverflowRectForPaintInvalidation() is taken from the
188 // parent table, and being mid-layout, that is invalid. Instead, we issue paint invalidations for our cells.
189 if (selfNeedsLayout() && checkForPaintInvalidation()) {
190 for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) {
191 // FIXME: Is this needed with Repaint After Layout?
192 cell->setShouldDoFullPaintInvalidation(true);
196 // RenderTableSection::layoutRows will set our logical height and width later, so it calls updateLayerTransform().
201 bool RenderTableRow::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action)
203 // Table rows cannot ever be hit tested. Effectively they do not exist.
204 // Just forward to our children always.
205 for (RenderTableCell* cell = lastCell(); cell; cell = cell->previousCell()) {
206 // FIXME: We have to skip over inline flows, since they can show up inside table rows
207 // at the moment (a demoted inline <form> for example). If we ever implement a
208 // table-specific hit-test method (which we should do for performance reasons anyway),
209 // then we can remove this check.
210 if (!cell->hasSelfPaintingLayer()) {
211 LayoutPoint cellPoint = flipForWritingModeForChild(cell, accumulatedOffset);
212 if (cell->nodeAtPoint(request, result, locationInContainer, cellPoint, action)) {
213 updateHitTestResult(result, locationInContainer.point() - toLayoutSize(cellPoint));
222 void RenderTableRow::paintOutlineForRowIfNeeded(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
224 LayoutPoint adjustedPaintOffset = paintOffset + location();
225 PaintPhase paintPhase = paintInfo.phase;
226 if ((paintPhase == PaintPhaseOutline || paintPhase == PaintPhaseSelfOutline) && style()->visibility() == VISIBLE)
227 paintOutline(paintInfo, LayoutRect(adjustedPaintOffset, size()));
230 void RenderTableRow::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
232 ASSERT(hasSelfPaintingLayer());
233 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, this);
235 paintOutlineForRowIfNeeded(paintInfo, paintOffset);
236 for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) {
237 // Paint the row background behind the cell.
238 if (paintInfo.phase == PaintPhaseBlockBackground || paintInfo.phase == PaintPhaseChildBlockBackground)
239 cell->paintBackgroundsBehindCell(paintInfo, paintOffset, this);
240 if (!cell->hasSelfPaintingLayer())
241 cell->paint(paintInfo, paintOffset);
245 void RenderTableRow::imageChanged(WrappedImagePtr, const IntRect*)
247 // FIXME: Examine cells and repaint only the rect the image paints in.
248 paintInvalidationForWholeRenderer();
251 RenderTableRow* RenderTableRow::createAnonymous(Document* document)
253 RenderTableRow* renderer = new RenderTableRow(0);
254 renderer->setDocumentForAnonymous(document);
258 RenderTableRow* RenderTableRow::createAnonymousWithParentRenderer(const RenderObject* parent)
260 RenderTableRow* newRow = RenderTableRow::createAnonymous(&parent->document());
261 RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisplay(parent->style(), TABLE_ROW);
262 newRow->setStyle(newStyle.release());