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"
#if ENABLE(WML)
#include "WMLNames.h"
#endif
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::styleWillChange(StyleDifference diff, const RenderStyle* newStyle)
{
if (section() && style() && style()->height() != newStyle->height())
section()->setNeedsCellRecalc();
ASSERT(newStyle->display() == TABLE_ROW);
RenderContainer::styleWillChange(diff, newStyle);
}
void RenderTableRow::addChild(RenderObject* child, RenderObject* beforeChild)
{
if (!beforeChild && isAfterContent(lastChild()))
beforeChild = lastChild();
bool isTableRow = element() && element()->hasTagName(trTag);
#if ENABLE(WML)
if (!isTableRow && element() && element()->isWMLElement())
isTableRow = element()->hasTagName(WMLNames::trTag);
#endif
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() );
RefPtr<RenderStyle> newStyle = RenderStyle::create();
newStyle->inheritFrom(style());
newStyle->setDisplay(TABLE_CELL);
cell->setStyle(newStyle.release());
addChild(cell, beforeChild);
cell->addChild(child);
return;
}
while (beforeChild && beforeChild->parent() != this)
beforeChild = beforeChild->parent();
RenderTableCell* cell = static_cast<RenderTableCell*>(child);
if (parent())
section()->addCell(cell, this);
ASSERT(!beforeChild || beforeChild->isTableCell() || isTableRow && beforeChild->element() && beforeChild->element()->hasTagName(formTag) && document()->isHTMLDocument());
RenderContainer::addChild(cell, beforeChild);
if (beforeChild || nextSibling())
section()->setNeedsCellRecalc();
}
void RenderTableRow::layout()
{
ASSERT(needsLayout());
LayoutStateMaintainer statePusher(view(), 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();
}
}
statePusher.pop();
setNeedsLayout(false);
}
IntRect RenderTableRow::clippedOverflowRectForRepaint(RenderBox* repaintContainer)
{
if (RenderTable* parentTable = table())
return parentTable->clippedOverflowRectForRepaint(repaintContainer);
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->isTableCell() && !toRenderBox(child)->hasSelfPaintingLayer() && 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(hasSelfPaintingLayer());
if (!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 (!toRenderBox(child)->hasSelfPaintingLayer())
child->paint(paintInfo, tx, ty);
}
}
}
void RenderTableRow::imageChanged(WrappedImagePtr, const IntRect*)
{
repaint();
}
}