RenderTableRow.cpp [plain text]
#include "config.h"
#include "RenderTableRow.h"
#include "RenderTableCell.h"
#include "Document.h"
#include "HTMLNames.h"
namespace WebCore {
using namespace HTMLNames;
RenderTableRow::RenderTableRow(Node* node)
: RenderContainer(node)
{
setInline(false); }
void RenderTableRow::destroy()
{
RenderTableSection *s = section();
if (s)
s->setNeedCellRecalc();
RenderContainer::destroy();
}
void RenderTableRow::setStyle(RenderStyle* newStyle)
{
if (section() && style() && style()->height() != newStyle->height())
section()->setNeedCellRecalc();
newStyle->setDisplay(TABLE_ROW);
RenderContainer::setStyle(newStyle);
}
void RenderTableRow::addChild(RenderObject* child, RenderObject* beforeChild)
{
bool isTableRow = element() && element()->hasTagName(trTag);
if (!child->isTableCell()) {
if (isTableRow && child->element() && child->element()->hasTagName(formTag) && document()->isHTMLDocument()) {
RenderContainer::addChild(child, beforeChild);
return;
}
RenderObject* last = beforeChild;
if (!last)
last = lastChild();
if (last && last->isAnonymous() && last->isTableCell()) {
last->addChild(child);
return;
}
if (last && !last->isTableCell() && last->parent() && last->parent()->isAnonymous()) {
last->parent()->addChild(child, beforeChild);
return;
}
RenderTableCell* cell = new (renderArena()) RenderTableCell(document() );
RenderStyle* newStyle = new (renderArena()) RenderStyle();
newStyle->inheritFrom(style());
newStyle->setDisplay(TABLE_CELL);
cell->setStyle(newStyle);
addChild(cell, beforeChild);
cell->addChild(child);
return;
}
while (beforeChild && !beforeChild->isTableCell())
beforeChild = beforeChild->parent();
RenderTableCell* cell = static_cast<RenderTableCell*>(child);
section()->addCell(cell, this);
RenderContainer::addChild(cell, beforeChild);
if (beforeChild || nextSibling())
section()->setNeedCellRecalc();
}
void RenderTableRow::layout()
{
ASSERT(needsLayout());
ASSERT(minMaxKnown());
for (RenderObject *child = firstChild(); child; child = child->nextSibling()) {
if (child->isTableCell()) {
RenderTableCell *cell = static_cast<RenderTableCell *>(child);
if (child->needsLayout()) {
cell->calcVerticalMargins();
cell->layout();
}
}
}
setNeedsLayout(false);
}
IntRect RenderTableRow::getAbsoluteRepaintRect()
{
RenderTable* parentTable = table();
if (parentTable)
return parentTable->getAbsoluteRepaintRect();
else
return IntRect();
}
bool RenderTableRow::nodeAtPoint(NodeInfo& info, int x, int y, int tx, int ty, HitTestAction action)
{
for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
if (!child->layer() && !child->isInlineFlow() && child->nodeAtPoint(info, x, y, tx, ty, action)) {
setInnerNode(info);
return true;
}
}
return false;
}
void RenderTableRow::paint(PaintInfo& i, int tx, int ty)
{
assert(m_layer);
if (!m_layer)
return;
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
if (child->isTableCell()) {
if (i.phase == PaintPhaseBlockBackground || i.phase == PaintPhaseChildBlockBackground) {
RenderTableCell* cell = static_cast<RenderTableCell*>(child);
cell->paintBackgroundsBehindCell(i, tx, ty, this);
}
if (!child->layer())
child->paint(i, tx, ty);
}
}
}
}