RenderTableRow.cpp [plain text]
#include "config.h"
#include "RenderTableRow.h"
#include "CachedImage.h"
#include "Document.h"
#include "HTMLNames.h"
#include "RenderTableCell.h"
#include "RenderView.h"
namespace WebCore {
using namespace HTMLNames;
RenderTableRow::RenderTableRow(Node* node)
: RenderContainer(node)
{
setInline(false); }
void RenderTableRow::destroy()
{
RenderTableSection* recalcSection = section();
RenderContainer::destroy();
if (recalcSection)
recalcSection->setNeedsCellRecalc();
}
void RenderTableRow::setStyle(RenderStyle* newStyle)
{
if (section() && style() && style()->height() != newStyle->height())
section()->setNeedsCellRecalc();
newStyle->setDisplay(TABLE_ROW);
RenderContainer::setStyle(newStyle);
}
void RenderTableRow::addChild(RenderObject* child, RenderObject* beforeChild)
{
if (!beforeChild && isAfterContent(lastChild()))
beforeChild = lastChild();
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);
if (parent())
section()->addCell(cell, this);
RenderContainer::addChild(cell, beforeChild);
if (beforeChild || nextSibling())
section()->setNeedsCellRecalc();
}
void RenderTableRow::layout()
{
ASSERT(needsLayout());
view()->pushLayoutState(this, IntSize());
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
if (child->isTableCell()) {
RenderTableCell* cell = static_cast<RenderTableCell*>(child);
if (child->needsLayout()) {
cell->calcVerticalMargins();
cell->layout();
}
}
}
if (selfNeedsLayout() && checkForRepaintDuringLayout()) {
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
if (child->isTableCell())
child->repaint();
}
}
view()->popLayoutState();
setNeedsLayout(false);
}
IntRect RenderTableRow::absoluteClippedOverflowRect()
{
if (RenderTable* parentTable = table())
return parentTable->absoluteClippedOverflowRect();
return IntRect();
}
bool RenderTableRow::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int x, int y, int tx, int ty, HitTestAction action)
{
for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
if (!child->hasLayer() && !child->isInlineFlow() && child->nodeAtPoint(request, result, x, y, tx, ty, action)) {
updateHitTestResult(result, IntPoint(x - tx, y - ty));
return true;
}
}
return false;
}
void RenderTableRow::paint(PaintInfo& paintInfo, int tx, int ty)
{
ASSERT(m_layer);
if (!m_layer)
return;
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
if (child->isTableCell()) {
if (paintInfo.phase == PaintPhaseBlockBackground || paintInfo.phase == PaintPhaseChildBlockBackground) {
RenderTableCell* cell = static_cast<RenderTableCell*>(child);
cell->paintBackgroundsBehindCell(paintInfo, tx, ty, this);
}
if (!child->hasLayer())
child->paint(paintInfo, tx, ty);
}
}
}
void RenderTableRow::imageChanged(CachedImage* image)
{
if (!image || !image->canRender() || !parent())
return;
repaint();
}
}