2 * Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 * (C) 1997 Torben Weis (weis@kde.org)
4 * (C) 1998 Waldo Bastian (bastian@kde.org)
5 * (C) 1999 Lars Knoll (knoll@kde.org)
6 * (C) 1999 Antti Koivisto (koivisto@kde.org)
7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 #include "RenderTableRow.h"
28 #include "CachedImage.h"
30 #include "HTMLNames.h"
31 #include "PaintInfo.h"
32 #include "RenderTableCell.h"
33 #include "RenderView.h"
37 using namespace HTMLNames;
39 RenderTableRow::RenderTableRow(Node* node)
42 // init RenderObject attributes
43 setInline(false); // our object is not Inline
46 void RenderTableRow::willBeDestroyed()
48 RenderTableSection* recalcSection = section();
50 RenderBox::willBeDestroyed();
53 recalcSection->setNeedsCellRecalc();
56 void RenderTableRow::styleWillChange(StyleDifference diff, const RenderStyle* newStyle)
58 if (section() && style() && style()->logicalHeight() != newStyle->logicalHeight())
59 section()->setNeedsCellRecalc();
61 ASSERT(newStyle->display() == TABLE_ROW);
63 RenderBox::styleWillChange(diff, newStyle);
66 void RenderTableRow::updateBeforeAndAfterContent()
68 if (!isAnonymous() && document()->usesBeforeAfterRules()) {
69 children()->updateBeforeAfterContent(this, BEFORE);
70 children()->updateBeforeAfterContent(this, AFTER);
74 void RenderTableRow::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
76 RenderBox::styleDidChange(diff, oldStyle);
77 propagateStyleToAnonymousChildren();
80 updateBeforeAndAfterContent();
83 void RenderTableRow::addChild(RenderObject* child, RenderObject* beforeChild)
85 // Make sure we don't append things after :after-generated content if we have it.
86 if (!beforeChild && isAfterContent(lastChild()))
87 beforeChild = lastChild();
89 if (!child->isTableCell()) {
90 RenderObject* last = beforeChild;
93 if (last && last->isAnonymous() && last->isTableCell() && !last->isBeforeOrAfterContent()) {
94 if (beforeChild == last)
95 beforeChild = last->firstChild();
96 last->addChild(child, beforeChild);
100 // If beforeChild is inside an anonymous cell, insert into the cell.
101 if (last && !last->isTableCell() && last->parent() && last->parent()->isAnonymous() && !last->parent()->isBeforeOrAfterContent()) {
102 last->parent()->addChild(child, beforeChild);
106 RenderTableCell* cell = new (renderArena()) RenderTableCell(document() /* anonymous object */);
107 RefPtr<RenderStyle> newStyle = RenderStyle::create();
108 newStyle->inheritFrom(style());
109 newStyle->setDisplay(TABLE_CELL);
110 cell->setStyle(newStyle.release());
111 addChild(cell, beforeChild);
112 cell->addChild(child);
116 // If the next renderer is actually wrapped in an anonymous table cell, we need to go up and find that.
117 while (beforeChild && beforeChild->parent() != this)
118 beforeChild = beforeChild->parent();
120 RenderTableCell* cell = toRenderTableCell(child);
122 // Generated content can result in us having a null section so make sure to null check our parent.
124 section()->addCell(cell, this);
126 ASSERT(!beforeChild || beforeChild->isTableCell());
127 RenderBox::addChild(cell, beforeChild);
129 if (beforeChild || nextSibling())
130 section()->setNeedsCellRecalc();
133 void RenderTableRow::layout()
135 ASSERT(needsLayout());
137 // Table rows do not add translation.
138 LayoutStateMaintainer statePusher(view(), this, LayoutSize(), style()->isFlippedBlocksWritingMode());
140 bool paginated = view()->layoutState()->isPaginated();
142 for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
143 if (child->isTableCell()) {
144 RenderTableCell* cell = toRenderTableCell(child);
145 if (!cell->needsLayout() && paginated && view()->layoutState()->pageLogicalHeight() && view()->layoutState()->pageLogicalOffset(cell->logicalTop()) != cell->pageLogicalOffset())
146 cell->setChildNeedsLayout(true, false);
148 if (child->needsLayout()) {
149 cell->computeBlockDirectionMargins(table());
155 // We only ever need to repaint if our cells didn't, which menas that they didn't need
156 // layout, so we know that our bounds didn't change. This code is just making up for
157 // the fact that we did not repaint in setStyle() because we had a layout hint.
158 // We cannot call repaint() because our clippedOverflowRectForRepaint() is taken from the
159 // parent table, and being mid-layout, that is invalid. Instead, we repaint our cells.
160 if (selfNeedsLayout() && checkForRepaintDuringLayout()) {
161 for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
162 if (child->isTableCell())
168 // RenderTableSection::layoutRows will set our logical height and width later, so it calls updateLayerTransform().
169 setNeedsLayout(false);
172 IntRect RenderTableRow::clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer) const
176 if (repaintContainer == this)
177 return RenderBox::clippedOverflowRectForRepaint(repaintContainer);
179 // For now, just repaint the whole table.
180 // FIXME: Find a better way to do this, e.g., need to repaint all the cells that we
181 // might have propagated a background color into.
182 // FIXME: do repaintContainer checks here
183 if (RenderTable* parentTable = table())
184 return parentTable->clippedOverflowRectForRepaint(repaintContainer);
190 bool RenderTableRow::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action)
192 // Table rows cannot ever be hit tested. Effectively they do not exist.
193 // Just forward to our children always.
194 for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
195 // FIXME: We have to skip over inline flows, since they can show up inside table rows
196 // at the moment (a demoted inline <form> for example). If we ever implement a
197 // table-specific hit-test method (which we should do for performance reasons anyway),
198 // then we can remove this check.
199 if (child->isTableCell() && !toRenderBox(child)->hasSelfPaintingLayer()) {
200 LayoutPoint cellPoint = flipForWritingMode(toRenderTableCell(child), accumulatedOffset, ParentToChildFlippingAdjustment);
201 if (child->nodeAtPoint(request, result, pointInContainer, cellPoint, action)) {
202 updateHitTestResult(result, pointInContainer - toLayoutSize(cellPoint));
211 void RenderTableRow::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
213 ASSERT(hasSelfPaintingLayer());
216 for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
217 if (child->isTableCell()) {
218 // Paint the row background behind the cell.
219 if (paintInfo.phase == PaintPhaseBlockBackground || paintInfo.phase == PaintPhaseChildBlockBackground) {
220 RenderTableCell* cell = toRenderTableCell(child);
221 cell->paintBackgroundsBehindCell(paintInfo, paintOffset, this);
223 if (!toRenderBox(child)->hasSelfPaintingLayer())
224 child->paint(paintInfo, paintOffset);
229 void RenderTableRow::imageChanged(WrappedImagePtr, const IntRect*)
231 // FIXME: Examine cells and repaint only the rect the image paints in.
235 } // namespace WebCore