RenderTableRow.cpp [plain text]
#include "config.h"
#include "RenderTableRow.h"
#include "Document.h"
#include "HTMLNames.h"
#include "HitTestResult.h"
#include "PaintInfo.h"
#include "RenderTableCell.h"
#include "RenderView.h"
#include "StyleInheritedData.h"
#include <wtf/StackStats.h>
namespace WebCore {
using namespace HTMLNames;
RenderTableRow::RenderTableRow(Element& element, PassRef<RenderStyle> style)
: RenderBox(element, WTF::move(style), 0)
, m_rowIndex(unsetRowIndex)
{
setInline(false);
}
RenderTableRow::RenderTableRow(Document& document, PassRef<RenderStyle> style)
: RenderBox(document, WTF::move(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() == TABLE_ROW);
RenderBox::styleDidChange(diff, oldStyle);
propagateStyleToAnonymousChildren(PropagateToAllChildren);
if (section() && oldStyle && style().logicalHeight() != oldStyle->logicalHeight())
section()->rowLogicalHeightChanged(rowIndex());
if (parent()) {
RenderTable* table = this->table();
if (table && !table->selfNeedsLayout() && !table->normalChildNeedsLayout() && oldStyle && oldStyle->border() != style().border())
table->invalidateCollapsedBorders();
if (table && oldStyle && diff == StyleDifferenceLayout && 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::addChild(RenderObject* child, RenderObject* beforeChild)
{
if (!child->isTableCell()) {
RenderObject* last = beforeChild;
if (!last)
last = lastCell();
if (last && last->isAnonymous() && last->isTableCell() && !last->isBeforeOrAfterContent()) {
RenderTableCell* cell = toRenderTableCell(last);
if (beforeChild == cell)
beforeChild = cell->firstChild();
cell->addChild(child, beforeChild);
return;
}
if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == this) {
RenderObject* cell = beforeChild->previousSibling();
if (cell && cell->isTableCell() && cell->isAnonymous()) {
toRenderTableCell(cell)->addChild(child);
return;
}
}
if (last && !last->isTableCell() && last->parent() && last->parent()->isAnonymous() && !last->parent()->isBeforeOrAfterContent()) {
last->parent()->addChild(child, beforeChild);
return;
}
RenderTableCell* cell = RenderTableCell::createAnonymousWithParentRenderer(this);
addChild(cell, beforeChild);
cell->addChild(child);
return;
}
if (beforeChild && beforeChild->parent() != this)
beforeChild = splitAnonymousBoxesAroundChild(beforeChild);
RenderTableCell* cell = toRenderTableCell(child);
if (parent())
section()->addCell(cell, this);
ASSERT(!beforeChild || beforeChild->isTableCell());
RenderBox::addChild(cell, beforeChild);
if (beforeChild || nextRow())
section()->setNeedsCellRecalc();
}
void RenderTableRow::layout()
{
StackStats::LayoutCheckPoint layoutCheckPoint;
ASSERT(needsLayout());
LayoutStateMaintainer statePusher(view(), *this, LayoutSize(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
bool paginated = view().layoutState()->isPaginated();
for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) {
if (!cell->needsLayout() && paginated && view().layoutState()->pageLogicalHeight() && view().layoutState()->pageLogicalOffset(cell, cell->logicalTop()) != cell->pageLogicalOffset())
cell->setChildNeedsLayout(MarkOnlyThis);
if (cell->needsLayout()) {
cell->computeAndSetBlockDirectionMargins(table());
cell->layout();
}
}
if (selfNeedsLayout() && checkForRepaintDuringLayout()) {
for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell())
cell->repaint();
}
statePusher.pop();
clearNeedsLayout();
}
LayoutRect RenderTableRow::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const
{
ASSERT(parent());
if (repaintContainer == this)
return RenderBox::clippedOverflowRectForRepaint(repaintContainer);
if (RenderTable* parentTable = table())
return parentTable->clippedOverflowRectForRepaint(repaintContainer);
return LayoutRect();
}
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 == PaintPhaseOutline || paintPhase == PaintPhaseSelfOutline) && style().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 == PaintPhaseBlockBackground || paintInfo.phase == PaintPhaseChildBlockBackground)
cell->paintBackgroundsBehindCell(paintInfo, paintOffset, this);
if (!cell->hasSelfPaintingLayer())
cell->paint(paintInfo, paintOffset);
}
}
void RenderTableRow::imageChanged(WrappedImagePtr, const IntRect*)
{
repaint();
}
RenderTableRow* RenderTableRow::createAnonymousWithParentRenderer(const RenderObject* parent)
{
auto newRow = new RenderTableRow(parent->document(), RenderStyle::createAnonymousStyleWithDisplay(&parent->style(), TABLE_ROW));
newRow->initializeStyle();
return newRow;
}
}