RenderTableRow.cpp [plain text]
#include "config.h"
#include "RenderTableRow.h"
#include "CachedImage.h"
#include "Document.h"
#include "HTMLNames.h"
#include "PaintInfo.h"
#include "RenderTableCell.h"
#include "RenderView.h"
namespace WebCore {
using namespace HTMLNames;
RenderTableRow::RenderTableRow(Node* node)
: RenderBox(node)
, m_rowIndex(unsetRowIndex)
{
setInline(false); }
void RenderTableRow::willBeDestroyed()
{
RenderTableSection* recalcSection = section();
RenderBox::willBeDestroyed();
if (recalcSection)
recalcSection->setNeedsCellRecalc();
}
void RenderTableRow::updateBeforeAndAfterContent()
{
if (!isAnonymous() && document()->usesBeforeAfterRules()) {
children()->updateBeforeAfterContent(this, BEFORE);
children()->updateBeforeAfterContent(this, AFTER);
}
}
void RenderTableRow::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
ASSERT(style()->display() == TABLE_ROW);
RenderBox::styleDidChange(diff, oldStyle);
propagateStyleToAnonymousChildren();
if (parent())
updateBeforeAndAfterContent();
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();
}
}
void RenderTableRow::addChild(RenderObject* child, RenderObject* beforeChild)
{
if (!beforeChild)
beforeChild = afterPseudoElementRenderer();
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()
{
ASSERT(needsLayout());
LayoutStateMaintainer statePusher(view(), this, LayoutSize(), 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->computeBlockDirectionMargins(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(RenderBoxModelObject* 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 LayoutPoint& pointInContainer, 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, pointInContainer, cellPoint, action)) {
updateHitTestResult(result, pointInContainer - toLayoutSize(cellPoint));
return true;
}
}
}
return false;
}
void RenderTableRow::paintOutlineForRowIfNeeded(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
PaintPhase paintPhase = paintInfo.phase;
if ((paintPhase == PaintPhaseOutline || paintPhase == PaintPhaseSelfOutline) && style()->visibility() == VISIBLE)
paintOutline(paintInfo.context, LayoutRect(paintOffset, 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::createAnonymousWithParentRenderer(const RenderObject* parent)
{
RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisplay(parent->style(), TABLE_ROW);
RenderTableRow* newRow = new (parent->renderArena()) RenderTableRow(parent->document() );
newRow->setStyle(newStyle.release());
return newRow;
}
}