RenderTableRow.cpp [plain text]
#include "config.h"
#include "RenderTableRow.h"
#include "Document.h"
#include "HTMLNames.h"
#include "HitTestResult.h"
#include "PaintInfo.h"
#include "RenderLayoutState.h"
#include "RenderTableCell.h"
#include "RenderTreeBuilder.h"
#include "RenderView.h"
#include "StyleInheritedData.h"
#include <wtf/IsoMallocInlines.h>
#include <wtf/StackStats.h>
namespace WebCore {
using namespace HTMLNames;
WTF_MAKE_ISO_ALLOCATED_IMPL(RenderTableRow);
RenderTableRow::RenderTableRow(Element& element, RenderStyle&& style)
: RenderBox(element, WTFMove(style), 0)
, m_rowIndex(unsetRowIndex)
{
setInline(false);
}
RenderTableRow::RenderTableRow(Document& document, RenderStyle&& style)
: RenderBox(document, WTFMove(style), 0)
, m_rowIndex(unsetRowIndex)
{
setInline(false);
}
void RenderTableRow::willBeRemovedFromTree()
{
RenderBox::willBeRemovedFromTree();
section()->setNeedsCellRecalc();
}
static bool borderWidthChanged(const RenderStyle* oldStyle, const RenderStyle* newStyle)
{
return oldStyle->borderLeftWidth() != newStyle->borderLeftWidth()
|| oldStyle->borderTopWidth() != newStyle->borderTopWidth()
|| oldStyle->borderRightWidth() != newStyle->borderRightWidth()
|| oldStyle->borderBottomWidth() != newStyle->borderBottomWidth();
}
void RenderTableRow::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
ASSERT(style().display() == DisplayType::TableRow);
RenderBox::styleDidChange(diff, oldStyle);
propagateStyleToAnonymousChildren(PropagateToAllChildren);
if (section() && oldStyle && style().logicalHeight() != oldStyle->logicalHeight())
section()->rowLogicalHeightChanged(rowIndex());
if (RenderTable* table = this->table()) {
if (oldStyle && oldStyle->border() != style().border())
table->invalidateCollapsedBorders();
if (oldStyle && diff == StyleDifference::Layout && needsLayout() && table->collapseBorders() && borderWidthChanged(oldStyle, &style())) {
for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell())
cell->setChildNeedsLayout(MarkOnlyThis);
}
}
}
const BorderValue& RenderTableRow::borderAdjoiningStartCell(const RenderTableCell& cell) const
{
ASSERT_UNUSED(cell, cell.isFirstOrLastCellInRow());
return style().borderStart();
}
const BorderValue& RenderTableRow::borderAdjoiningEndCell(const RenderTableCell& cell) const
{
ASSERT_UNUSED(cell, cell.isFirstOrLastCellInRow());
return style().borderEnd();
}
void RenderTableRow::didInsertTableCell(RenderTableCell& child, RenderObject* beforeChild)
{
if (auto* section = this->section()) {
section->addCell(&child, this);
if (beforeChild || nextRow())
section->setNeedsCellRecalc();
}
if (auto* table = this->table())
table->invalidateCollapsedBorders();
}
void RenderTableRow::layout()
{
StackStats::LayoutCheckPoint layoutCheckPoint;
ASSERT(needsLayout());
LayoutStateMaintainer statePusher(*this, LayoutSize(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
auto* layoutState = view().frameView().layoutContext().layoutState();
bool paginated = layoutState->isPaginated();
for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) {
if (!cell->needsLayout() && paginated && (layoutState->pageLogicalHeightChanged() || (layoutState->pageLogicalHeight() && layoutState->pageLogicalOffset(cell, cell->logicalTop()) != cell->pageLogicalOffset())))
cell->setChildNeedsLayout(MarkOnlyThis);
if (cell->needsLayout()) {
cell->computeAndSetBlockDirectionMargins(*table());
cell->layout();
}
}
clearOverflow();
addVisualEffectOverflow();
if (selfNeedsLayout() && checkForRepaintDuringLayout()) {
for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell())
cell->repaint();
}
clearNeedsLayout();
}
LayoutRect RenderTableRow::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const
{
ASSERT(parent());
LayoutRect result = RenderBox::clippedOverflowRectForRepaint(repaintContainer);
for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) {
result.uniteIfNonZero(cell->clippedOverflowRectForRepaint(repaintContainer));
}
return result;
}
bool RenderTableRow::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action)
{
for (RenderTableCell* cell = lastCell(); cell; cell = cell->previousCell()) {
if (!cell->hasSelfPaintingLayer()) {
LayoutPoint cellPoint = flipForWritingModeForChild(cell, accumulatedOffset);
if (cell->nodeAtPoint(request, result, locationInContainer, cellPoint, action)) {
updateHitTestResult(result, locationInContainer.point() - toLayoutSize(cellPoint));
return true;
}
}
}
return false;
}
void RenderTableRow::paintOutlineForRowIfNeeded(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
LayoutPoint adjustedPaintOffset = paintOffset + location();
PaintPhase paintPhase = paintInfo.phase;
if ((paintPhase == PaintPhase::Outline || paintPhase == PaintPhase::SelfOutline) && style().visibility() == Visibility::Visible)
paintOutline(paintInfo, LayoutRect(adjustedPaintOffset, size()));
}
void RenderTableRow::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
ASSERT(hasSelfPaintingLayer());
paintOutlineForRowIfNeeded(paintInfo, paintOffset);
for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) {
if (paintInfo.phase == PaintPhase::BlockBackground || paintInfo.phase == PaintPhase::ChildBlockBackground)
cell->paintBackgroundsBehindCell(paintInfo, paintOffset, this);
if (!cell->hasSelfPaintingLayer())
cell->paint(paintInfo, paintOffset);
}
}
void RenderTableRow::imageChanged(WrappedImagePtr, const IntRect*)
{
repaint();
}
RenderPtr<RenderTableRow> RenderTableRow::createTableRowWithStyle(Document& document, const RenderStyle& style)
{
auto row = createRenderer<RenderTableRow>(document, RenderStyle::createAnonymousStyleWithDisplay(style, DisplayType::TableRow));
row->initializeStyle();
return row;
}
RenderPtr<RenderTableRow> RenderTableRow::createAnonymousWithParentRenderer(const RenderTableSection& parent)
{
return RenderTableRow::createTableRowWithStyle(parent.document(), parent.style());
}
}