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)
: RenderBox(element)
, 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();
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 (RenderBox* childBox = firstChildBox(); childBox; childBox = childBox->nextSiblingBox()) {
if (!childBox->isTableCell())
continue;
childBox->setChildNeedsLayout(true, 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 = lastChild();
if (last && last->isAnonymous() && last->isTableCell() && !last->isBeforeOrAfterContent()) {
if (beforeChild == last)
beforeChild = last->firstChild();
last->addChild(child, beforeChild);
return;
}
if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == this) {
RenderObject* cell = beforeChild->previousSibling();
if (cell && cell->isTableCell() && cell->isAnonymous()) {
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 || nextSibling())
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 (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
if (child->isTableCell()) {
RenderTableCell* cell = toRenderTableCell(child);
if (!cell->needsLayout() && paginated && view()->layoutState()->pageLogicalHeight() && view()->layoutState()->pageLogicalOffset(cell, cell->logicalTop()) != cell->pageLogicalOffset())
cell->setChildNeedsLayout(true, MarkOnlyThis);
if (child->needsLayout()) {
cell->computeAndSetBlockDirectionMargins(table());
cell->layout();
}
}
}
if (selfNeedsLayout() && checkForRepaintDuringLayout()) {
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
if (child->isTableCell())
child->repaint();
}
}
statePusher.pop();
setNeedsLayout(false);
}
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 (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
if (child->isTableCell() && !toRenderBox(child)->hasSelfPaintingLayer()) {
LayoutPoint cellPoint = flipForWritingModeForChild(toRenderTableCell(child), accumulatedOffset);
if (child->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.context, LayoutRect(adjustedPaintOffset, size()));
}
void RenderTableRow::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
ASSERT(hasSelfPaintingLayer());
paintOutlineForRowIfNeeded(paintInfo, paintOffset);
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
if (child->isTableCell()) {
if (paintInfo.phase == PaintPhaseBlockBackground || paintInfo.phase == PaintPhaseChildBlockBackground) {
RenderTableCell* cell = toRenderTableCell(child);
cell->paintBackgroundsBehindCell(paintInfo, paintOffset, this);
}
if (!toRenderBox(child)->hasSelfPaintingLayer())
child->paint(paintInfo, paintOffset);
}
}
}
void RenderTableRow::imageChanged(WrappedImagePtr, const IntRect*)
{
repaint();
}
RenderTableRow* RenderTableRow::createAnonymous(Document* document)
{
RenderTableRow* renderer = new (document->renderArena()) RenderTableRow(0);
renderer->setDocumentForAnonymous(document);
return renderer;
}
RenderTableRow* RenderTableRow::createAnonymousWithParentRenderer(const RenderObject* parent)
{
RenderTableRow* newRow = RenderTableRow::createAnonymous(parent->document());
RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisplay(parent->style(), TABLE_ROW);
newRow->setStyle(newStyle.release());
return newRow;
}
}