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, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
8 | * |
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. |
13 | * |
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. |
18 | * |
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. |
23 | */ |
24 | |
25 | #include "config.h" |
26 | #include "RenderTableRow.h" |
27 | |
28 | #include "Document.h" |
29 | #include "HTMLNames.h" |
30 | #include "HitTestResult.h" |
31 | #include "PaintInfo.h" |
32 | #include "RenderLayoutState.h" |
33 | #include "RenderTableCell.h" |
34 | #include "RenderTreeBuilder.h" |
35 | #include "RenderView.h" |
36 | #include "StyleInheritedData.h" |
37 | #include <wtf/IsoMallocInlines.h> |
38 | #include <wtf/StackStats.h> |
39 | |
40 | namespace WebCore { |
41 | |
42 | using namespace HTMLNames; |
43 | |
44 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderTableRow); |
45 | |
46 | RenderTableRow::RenderTableRow(Element& element, RenderStyle&& style) |
47 | : RenderBox(element, WTFMove(style), 0) |
48 | , m_rowIndex(unsetRowIndex) |
49 | { |
50 | setInline(false); |
51 | } |
52 | |
53 | RenderTableRow::RenderTableRow(Document& document, RenderStyle&& style) |
54 | : RenderBox(document, WTFMove(style), 0) |
55 | , m_rowIndex(unsetRowIndex) |
56 | { |
57 | setInline(false); |
58 | } |
59 | |
60 | void RenderTableRow::willBeRemovedFromTree() |
61 | { |
62 | RenderBox::willBeRemovedFromTree(); |
63 | |
64 | section()->setNeedsCellRecalc(); |
65 | } |
66 | |
67 | static bool borderWidthChanged(const RenderStyle* oldStyle, const RenderStyle* newStyle) |
68 | { |
69 | return oldStyle->borderLeftWidth() != newStyle->borderLeftWidth() |
70 | || oldStyle->borderTopWidth() != newStyle->borderTopWidth() |
71 | || oldStyle->borderRightWidth() != newStyle->borderRightWidth() |
72 | || oldStyle->borderBottomWidth() != newStyle->borderBottomWidth(); |
73 | } |
74 | |
75 | void RenderTableRow::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
76 | { |
77 | ASSERT(style().display() == DisplayType::TableRow); |
78 | |
79 | RenderBox::styleDidChange(diff, oldStyle); |
80 | propagateStyleToAnonymousChildren(PropagateToAllChildren); |
81 | |
82 | if (section() && oldStyle && style().logicalHeight() != oldStyle->logicalHeight()) |
83 | section()->rowLogicalHeightChanged(rowIndex()); |
84 | |
85 | // If border was changed, notify table. |
86 | if (RenderTable* table = this->table()) { |
87 | if (oldStyle && oldStyle->border() != style().border()) |
88 | table->invalidateCollapsedBorders(); |
89 | |
90 | if (oldStyle && diff == StyleDifference::Layout && needsLayout() && table->collapseBorders() && borderWidthChanged(oldStyle, &style())) { |
91 | // If the border width changes on a row, we need to make sure the cells in the row know to lay out again. |
92 | // This only happens when borders are collapsed, since they end up affecting the border sides of the cell |
93 | // itself. |
94 | for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) |
95 | cell->setChildNeedsLayout(MarkOnlyThis); |
96 | } |
97 | } |
98 | } |
99 | |
100 | const BorderValue& RenderTableRow::borderAdjoiningStartCell(const RenderTableCell& cell) const |
101 | { |
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(); |
105 | } |
106 | |
107 | const BorderValue& RenderTableRow::borderAdjoiningEndCell(const RenderTableCell& cell) const |
108 | { |
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(); |
112 | } |
113 | |
114 | void RenderTableRow::didInsertTableCell(RenderTableCell& child, RenderObject* beforeChild) |
115 | { |
116 | // Generated content can result in us having a null section so make sure to null check our parent. |
117 | if (auto* section = this->section()) { |
118 | section->addCell(&child, this); |
119 | if (beforeChild || nextRow()) |
120 | section->setNeedsCellRecalc(); |
121 | } |
122 | if (auto* table = this->table()) |
123 | table->invalidateCollapsedBorders(); |
124 | } |
125 | |
126 | void RenderTableRow::layout() |
127 | { |
128 | StackStats::LayoutCheckPoint layoutCheckPoint; |
129 | ASSERT(needsLayout()); |
130 | |
131 | // Table rows do not add translation. |
132 | LayoutStateMaintainer statePusher(*this, LayoutSize(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode()); |
133 | |
134 | auto* layoutState = view().frameView().layoutContext().layoutState(); |
135 | bool paginated = layoutState->isPaginated(); |
136 | |
137 | for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) { |
138 | if (!cell->needsLayout() && paginated && (layoutState->pageLogicalHeightChanged() || (layoutState->pageLogicalHeight() && layoutState->pageLogicalOffset(cell, cell->logicalTop()) != cell->pageLogicalOffset()))) |
139 | cell->setChildNeedsLayout(MarkOnlyThis); |
140 | |
141 | if (cell->needsLayout()) { |
142 | cell->computeAndSetBlockDirectionMargins(*table()); |
143 | cell->layout(); |
144 | } |
145 | } |
146 | |
147 | clearOverflow(); |
148 | addVisualEffectOverflow(); |
149 | // We only ever need to repaint if our cells didn't, which menas that they didn't need |
150 | // layout, so we know that our bounds didn't change. This code is just making up for |
151 | // the fact that we did not repaint in setStyle() because we had a layout hint. |
152 | // We cannot call repaint() because our clippedOverflowRectForRepaint() is taken from the |
153 | // parent table, and being mid-layout, that is invalid. Instead, we repaint our cells. |
154 | if (selfNeedsLayout() && checkForRepaintDuringLayout()) { |
155 | for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) |
156 | cell->repaint(); |
157 | } |
158 | |
159 | // RenderTableSection::layoutRows will set our logical height and width later, so it calls updateLayerTransform(). |
160 | clearNeedsLayout(); |
161 | } |
162 | |
163 | LayoutRect RenderTableRow::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const |
164 | { |
165 | ASSERT(parent()); |
166 | // Rows and cells are in the same coordinate space. We need to both compute our overflow rect (which |
167 | // will accommodate a row outline and any visual effects on the row itself), but we also need to add in |
168 | // the repaint rects of cells. |
169 | LayoutRect result = RenderBox::clippedOverflowRectForRepaint(repaintContainer); |
170 | for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) { |
171 | // Even if a cell is a repaint container, it's the row that paints the background behind it. |
172 | // So we don't care if a cell is a repaintContainer here. |
173 | result.uniteIfNonZero(cell->clippedOverflowRectForRepaint(repaintContainer)); |
174 | } |
175 | return result; |
176 | } |
177 | |
178 | // Hit Testing |
179 | bool RenderTableRow::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action) |
180 | { |
181 | // Table rows cannot ever be hit tested. Effectively they do not exist. |
182 | // Just forward to our children always. |
183 | for (RenderTableCell* cell = lastCell(); cell; cell = cell->previousCell()) { |
184 | // FIXME: We have to skip over inline flows, since they can show up inside table rows |
185 | // at the moment (a demoted inline <form> for example). If we ever implement a |
186 | // table-specific hit-test method (which we should do for performance reasons anyway), |
187 | // then we can remove this check. |
188 | if (!cell->hasSelfPaintingLayer()) { |
189 | LayoutPoint cellPoint = flipForWritingModeForChild(cell, accumulatedOffset); |
190 | if (cell->nodeAtPoint(request, result, locationInContainer, cellPoint, action)) { |
191 | updateHitTestResult(result, locationInContainer.point() - toLayoutSize(cellPoint)); |
192 | return true; |
193 | } |
194 | } |
195 | } |
196 | |
197 | return false; |
198 | } |
199 | |
200 | void RenderTableRow::paintOutlineForRowIfNeeded(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
201 | { |
202 | LayoutPoint adjustedPaintOffset = paintOffset + location(); |
203 | PaintPhase paintPhase = paintInfo.phase; |
204 | if ((paintPhase == PaintPhase::Outline || paintPhase == PaintPhase::SelfOutline) && style().visibility() == Visibility::Visible) |
205 | paintOutline(paintInfo, LayoutRect(adjustedPaintOffset, size())); |
206 | } |
207 | |
208 | void RenderTableRow::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
209 | { |
210 | ASSERT(hasSelfPaintingLayer()); |
211 | |
212 | paintOutlineForRowIfNeeded(paintInfo, paintOffset); |
213 | for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) { |
214 | // Paint the row background behind the cell. |
215 | if (paintInfo.phase == PaintPhase::BlockBackground || paintInfo.phase == PaintPhase::ChildBlockBackground) |
216 | cell->paintBackgroundsBehindCell(paintInfo, paintOffset, this); |
217 | if (!cell->hasSelfPaintingLayer()) |
218 | cell->paint(paintInfo, paintOffset); |
219 | } |
220 | } |
221 | |
222 | void RenderTableRow::imageChanged(WrappedImagePtr, const IntRect*) |
223 | { |
224 | // FIXME: Examine cells and repaint only the rect the image paints in. |
225 | repaint(); |
226 | } |
227 | |
228 | RenderPtr<RenderTableRow> RenderTableRow::createTableRowWithStyle(Document& document, const RenderStyle& style) |
229 | { |
230 | auto row = createRenderer<RenderTableRow>(document, RenderStyle::createAnonymousStyleWithDisplay(style, DisplayType::TableRow)); |
231 | row->initializeStyle(); |
232 | return row; |
233 | } |
234 | |
235 | RenderPtr<RenderTableRow> RenderTableRow::createAnonymousWithParentRenderer(const RenderTableSection& parent) |
236 | { |
237 | return RenderTableRow::createTableRowWithStyle(parent.document(), parent.style()); |
238 | } |
239 | |
240 | } // namespace WebCore |
241 | |