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/layout/LayoutTableRow.h"
28 #include "core/HTMLNames.h"
29 #include "core/fetch/ImageResource.h"
30 #include "core/layout/HitTestResult.h"
31 #include "core/layout/LayoutAnalyzer.h"
32 #include "core/layout/LayoutTableCell.h"
33 #include "core/layout/LayoutView.h"
34 #include "core/layout/SubtreeLayoutScope.h"
35 #include "core/paint/TableRowPainter.h"
36 #include "core/style/StyleInheritedData.h"
40 using namespace HTMLNames
;
42 LayoutTableRow::LayoutTableRow(Element
* element
)
44 , m_rowIndex(unsetRowIndex
)
46 // init LayoutObject attributes
47 setInline(false); // our object is not Inline
50 void LayoutTableRow::willBeRemovedFromTree()
52 LayoutBox::willBeRemovedFromTree();
54 section()->setNeedsCellRecalc();
57 static bool borderWidthChanged(const ComputedStyle
* oldStyle
, const ComputedStyle
* newStyle
)
59 return oldStyle
->borderLeftWidth() != newStyle
->borderLeftWidth()
60 || oldStyle
->borderTopWidth() != newStyle
->borderTopWidth()
61 || oldStyle
->borderRightWidth() != newStyle
->borderRightWidth()
62 || oldStyle
->borderBottomWidth() != newStyle
->borderBottomWidth();
65 void LayoutTableRow::styleDidChange(StyleDifference diff
, const ComputedStyle
* oldStyle
)
67 ASSERT(style()->display() == TABLE_ROW
);
69 LayoutBox::styleDidChange(diff
, oldStyle
);
70 propagateStyleToAnonymousChildren();
72 if (section() && oldStyle
&& style()->logicalHeight() != oldStyle
->logicalHeight())
73 section()->rowLogicalHeightChanged(this);
75 // If border was changed, notify table.
77 LayoutTable
* table
= this->table();
78 if (table
&& !table
->selfNeedsLayout() && !table
->normalChildNeedsLayout() && oldStyle
&& oldStyle
->border() != style()->border())
79 table
->invalidateCollapsedBorders();
81 if (table
&& oldStyle
&& diff
.needsFullLayout() && needsLayout() && table
->collapseBorders() && borderWidthChanged(oldStyle
, style())) {
82 // If the border width changes on a row, we need to make sure the cells in the row know to lay out again.
83 // This only happens when borders are collapsed, since they end up affecting the border sides of the cell
85 for (LayoutBox
* childBox
= firstChildBox(); childBox
; childBox
= childBox
->nextSiblingBox()) {
86 if (!childBox
->isTableCell())
88 childBox
->setChildNeedsLayout();
94 const BorderValue
& LayoutTableRow::borderAdjoiningStartCell(const LayoutTableCell
* cell
) const
96 ASSERT_UNUSED(cell
, cell
->isFirstOrLastCellInRow());
97 // FIXME: https://webkit.org/b/79272 - Add support for mixed directionality at the cell level.
98 return style()->borderStart();
101 const BorderValue
& LayoutTableRow::borderAdjoiningEndCell(const LayoutTableCell
* 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()->borderEnd();
108 void LayoutTableRow::addChild(LayoutObject
* child
, LayoutObject
* beforeChild
)
110 if (!child
->isTableCell()) {
111 LayoutObject
* last
= beforeChild
;
114 if (last
&& last
->isAnonymous() && last
->isTableCell() && !last
->isBeforeOrAfterContent()) {
115 LayoutTableCell
* lastCell
= toLayoutTableCell(last
);
116 if (beforeChild
== lastCell
)
117 beforeChild
= lastCell
->firstChild();
118 lastCell
->addChild(child
, beforeChild
);
122 if (beforeChild
&& !beforeChild
->isAnonymous() && beforeChild
->parent() == this) {
123 LayoutObject
* cell
= beforeChild
->previousSibling();
124 if (cell
&& cell
->isTableCell() && cell
->isAnonymous()) {
125 cell
->addChild(child
);
130 // If beforeChild is inside an anonymous cell, insert into the cell.
131 if (last
&& !last
->isTableCell() && last
->parent() && last
->parent()->isAnonymous() && !last
->parent()->isBeforeOrAfterContent()) {
132 last
->parent()->addChild(child
, beforeChild
);
136 LayoutTableCell
* cell
= LayoutTableCell::createAnonymousWithParent(this);
137 addChild(cell
, beforeChild
);
138 cell
->addChild(child
);
142 if (beforeChild
&& beforeChild
->parent() != this)
143 beforeChild
= splitAnonymousBoxesAroundChild(beforeChild
);
145 LayoutTableCell
* cell
= toLayoutTableCell(child
);
147 // Generated content can result in us having a null section so make sure to null check our parent.
149 section()->addCell(cell
, this);
151 ASSERT(!beforeChild
|| beforeChild
->isTableCell());
152 LayoutBox::addChild(cell
, beforeChild
);
154 if (beforeChild
|| nextRow())
155 section()->setNeedsCellRecalc();
158 void LayoutTableRow::layout()
160 ASSERT(needsLayout());
161 LayoutAnalyzer::Scope
analyzer(*this);
163 // Table rows do not add translation.
164 LayoutState
state(*this, LayoutSize());
166 for (LayoutTableCell
* cell
= firstCell(); cell
; cell
= cell
->nextCell()) {
167 SubtreeLayoutScope
layouter(*cell
);
168 if (!cell
->needsLayout())
169 cell
->markForPaginationRelayoutIfNeeded(layouter
);
170 if (cell
->needsLayout())
175 addVisualEffectOverflow();
176 // We do not call addOverflowFromCell here. The cell are laid out to be
177 // measured above and will be sized correctly in a follow-up phase.
179 // We only ever need to issue paint invalidations if our cells didn't, which means that they didn't need
180 // layout, so we know that our bounds didn't change. This code is just making up for
181 // the fact that we did not invalidate paints in setStyle() because we had a layout hint.
182 if (selfNeedsLayout()) {
183 for (LayoutTableCell
* cell
= firstCell(); cell
; cell
= cell
->nextCell()) {
184 // FIXME: Is this needed when issuing paint invalidations after layout?
185 cell
->setShouldDoFullPaintInvalidation();
189 // LayoutTableSection::layoutRows will set our logical height and width later, so it calls updateLayerTransform().
194 bool LayoutTableRow::nodeAtPoint(HitTestResult
& result
, const HitTestLocation
& locationInContainer
, const LayoutPoint
& accumulatedOffset
, HitTestAction action
)
196 // Table rows cannot ever be hit tested. Effectively they do not exist.
197 // Just forward to our children always.
198 for (LayoutTableCell
* cell
= lastCell(); cell
; cell
= cell
->previousCell()) {
199 // FIXME: We have to skip over inline flows, since they can show up inside table rows
200 // at the moment (a demoted inline <form> for example). If we ever implement a
201 // table-specific hit-test method (which we should do for performance reasons anyway),
202 // then we can remove this check.
203 if (!cell
->hasSelfPaintingLayer()) {
204 LayoutPoint cellPoint
= flipForWritingModeForChild(cell
, accumulatedOffset
);
205 if (cell
->nodeAtPoint(result
, locationInContainer
, cellPoint
, action
)) {
206 updateHitTestResult(result
, locationInContainer
.point() - toLayoutSize(cellPoint
));
215 void LayoutTableRow::paint(const PaintInfo
& paintInfo
, const LayoutPoint
& paintOffset
)
217 TableRowPainter(*this).paint(paintInfo
, paintOffset
);
220 void LayoutTableRow::imageChanged(WrappedImagePtr
, const IntRect
*)
222 // FIXME: Examine cells and issue paint invalidations of only the rect the image paints in.
223 setShouldDoFullPaintInvalidation();
226 LayoutTableRow
* LayoutTableRow::createAnonymous(Document
* document
)
228 LayoutTableRow
* layoutObject
= new LayoutTableRow(nullptr);
229 layoutObject
->setDocumentForAnonymous(document
);
233 LayoutTableRow
* LayoutTableRow::createAnonymousWithParent(const LayoutObject
* parent
)
235 LayoutTableRow
* newRow
= LayoutTableRow::createAnonymous(&parent
->document());
236 RefPtr
<ComputedStyle
> newStyle
= ComputedStyle::createAnonymousStyleWithDisplay(parent
->styleRef(), TABLE_ROW
);
237 newRow
->setStyle(newStyle
.release());
241 void LayoutTableRow::addOverflowFromCell(const LayoutTableCell
* cell
)
243 // Non-row-spanning-cells don't create overflow (they are fully contained within this row).
244 if (cell
->rowSpan() == 1)
247 // Cells only generates visual overflow.
248 LayoutRect cellVisualOverflowRect
= cell
->visualOverflowRectForPropagation(styleRef());
250 // The cell and the row share the section's coordinate system. However
251 // the visual overflow should be determined in the coordinate system of
252 // the row, that's why we shift it below.
253 LayoutUnit cellOffsetLogicalTopDifference
= cell
->location().y() - location().y();
254 cellVisualOverflowRect
.move(0, cellOffsetLogicalTopDifference
);
256 addVisualOverflow(cellVisualOverflowRect
);