source: webkit/trunk/Source/WebCore/rendering/RenderTableRow.cpp

Last change on this file was 290225, checked in by Alan Bujtas, 3 years ago

RenderBox::flipForWritingModeForChild should take const RenderBox& as the child renderer
https://bugs.webkit.org/show_bug.cgi?id=236895

Reviewed by Antti Koivisto.

  • rendering/LegacyInlineElementBox.cpp:

(WebCore::LegacyInlineElementBox::paint):
(WebCore::LegacyInlineElementBox::nodeAtPoint):

  • rendering/RenderBlock.cpp:

(WebCore::RenderBlock::paintChild):
(WebCore::RenderBlock::hitTestContents):
(WebCore::RenderBlock::paintExcludedChildrenInBorder):
(WebCore::RenderBlock::hitTestExcludedChildrenInBorder):

  • rendering/RenderBlockFlow.cpp:

(WebCore::RenderBlockFlow::paintColumnRules):

  • rendering/RenderBox.cpp:

(WebCore::RenderBox::flipForWritingModeForChild const):
(WebCore::RenderBox::topLeftLocation const):

  • rendering/RenderBox.h:
  • rendering/RenderFlexibleBox.cpp:

(WebCore::RenderFlexibleBox::hitTestChildren):

  • rendering/RenderTable.cpp:

(WebCore::RenderTable::paintObject):
(WebCore::RenderTable::nodeAtPoint):

  • rendering/RenderTableRow.cpp:

(WebCore::RenderTableRow::nodeAtPoint):

  • rendering/RenderTableSection.cpp:

(WebCore::RenderTableSection::paintCell):
(WebCore::RenderTableSection::paintObject):
(WebCore::RenderTableSection::nodeAtPoint):

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