blob: e2747cfada4d4cd8e89a584d01ff7917e053ee5f [file] [log] [blame]
darin@apple.com83833152008-01-14 17:51:10 +00001/*
eseidela043f3d2006-01-20 19:24:53 +00002 * 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)
mitz@apple.com8010bba2010-11-05 02:43:17 +00007 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
ap50b58352006-01-22 20:32:36 +00008 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
eseidela043f3d2006-01-20 19:24:53 +00009 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public License
21 * along with this library; see the file COPYING.LIB. If not, write to
ddkilzerc8eccec2007-09-26 02:29:57 +000022 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
eseidela043f3d2006-01-20 19:24:53 +000024 */
25
26#include "config.h"
27#include "RenderTableSection.h"
bdashb07ae8d2007-02-08 04:56:20 +000028#include "CachedImage.h"
darinb9481ed2006-03-20 02:57:59 +000029#include "Document.h"
tonikitoo@webkit.org81c027d2010-07-29 13:19:43 +000030#include "HitTestResult.h"
darin98fa8b82006-03-20 08:03:57 +000031#include "HTMLNames.h"
tonyg@chromium.orgb138b1e2011-01-15 00:27:07 +000032#include "PaintInfo.h"
darin91298e52006-06-12 01:10:17 +000033#include "RenderTableCell.h"
34#include "RenderTableCol.h"
35#include "RenderTableRow.h"
weinigfef13632007-04-29 20:09:08 +000036#include "RenderView.h"
darin91298e52006-06-12 01:10:17 +000037#include <limits>
jamesr@google.com36623a32010-07-23 20:22:29 +000038#include <wtf/HashSet.h>
ddkilzer260f3d22007-01-05 05:56:31 +000039#include <wtf/Vector.h>
eseidela043f3d2006-01-20 19:24:53 +000040
darin7bd70952006-04-13 07:07:34 +000041using namespace std;
42
eseidela043f3d2006-01-20 19:24:53 +000043namespace WebCore {
44
45using namespace HTMLNames;
46
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +000047// Those 2 variables are used to balance the memory consumption vs the repaint time on big tables.
48static unsigned gMinTableSizeToUseFastPaintPathWithOverflowingCell = 75 * 75;
49static float gMaxAllowedOverflowingCellRatioForFastPaintPath = 0.1f;
50
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +000051static inline void setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(RenderTableSection::RowStruct& row)
dbates@webkit.orge1131832009-11-19 00:05:57 +000052{
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +000053 ASSERT(row.rowRenderer);
54 row.logicalHeight = row.rowRenderer->style()->logicalHeight();
55 if (row.logicalHeight.isRelative())
56 row.logicalHeight = Length();
dbates@webkit.orge1131832009-11-19 00:05:57 +000057}
58
darinb9481ed2006-03-20 02:57:59 +000059RenderTableSection::RenderTableSection(Node* node)
hyatt@apple.comf073d9b2009-02-05 00:53:38 +000060 : RenderBox(node)
ddkilzer260f3d22007-01-05 05:56:31 +000061 , m_cCol(0)
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +000062 , m_cRow(0)
mitz@apple.com8010bba2010-11-05 02:43:17 +000063 , m_outerBorderStart(0)
64 , m_outerBorderEnd(0)
65 , m_outerBorderBefore(0)
66 , m_outerBorderAfter(0)
simon.fraser@apple.com85362502009-05-08 01:23:32 +000067 , m_needsCellRecalc(false)
jamesr@google.com36623a32010-07-23 20:22:29 +000068 , m_hasMultipleCellLevels(false)
eseidela043f3d2006-01-20 19:24:53 +000069{
70 // init RenderObject attributes
jamesr@google.com36623a32010-07-23 20:22:29 +000071 setInline(false); // our object is not Inline
eseidela043f3d2006-01-20 19:24:53 +000072}
73
74RenderTableSection::~RenderTableSection()
75{
eseidela043f3d2006-01-20 19:24:53 +000076}
77
inferno@chromium.orga7f719f2011-09-06 01:45:39 +000078void RenderTableSection::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
79{
80 RenderBox::styleDidChange(diff, oldStyle);
81 propagateStyleToAnonymousChildren();
jchaffraix@webkit.org38e74af2011-09-23 19:56:21 +000082
83 // If border was changed, notify table.
84 RenderTable* table = this->table();
85 if (table && !table->selfNeedsLayout() && !table->normalChildNeedsLayout() && oldStyle && oldStyle->border() != style()->border())
86 table->invalidateCollapsedBorders();
inferno@chromium.orga7f719f2011-09-06 01:45:39 +000087}
88
simon.fraser@apple.com73cb0b32011-07-09 00:43:14 +000089void RenderTableSection::willBeDestroyed()
eseidela043f3d2006-01-20 19:24:53 +000090{
antti078e87f2007-08-16 16:13:28 +000091 RenderTable* recalcTable = table();
92
simon.fraser@apple.com73cb0b32011-07-09 00:43:14 +000093 RenderBox::willBeDestroyed();
antti078e87f2007-08-16 16:13:28 +000094
eseidela043f3d2006-01-20 19:24:53 +000095 // recalc cell info because RenderTable has unguarded pointers
96 // stored that point to this RenderTableSection.
antti078e87f2007-08-16 16:13:28 +000097 if (recalcTable)
98 recalcTable->setNeedsSectionRecalc();
eseidela043f3d2006-01-20 19:24:53 +000099}
100
darin316ed062006-01-23 05:29:14 +0000101void RenderTableSection::addChild(RenderObject* child, RenderObject* beforeChild)
eseidela043f3d2006-01-20 19:24:53 +0000102{
hyatt58028f52007-05-01 04:57:01 +0000103 // Make sure we don't append things after :after-generated content if we have it.
inferno@chromium.orgcff58872011-09-21 22:05:07 +0000104 if (!beforeChild)
105 beforeChild = findAfterContentRenderer();
hyatt58028f52007-05-01 04:57:01 +0000106
eseidela043f3d2006-01-20 19:24:53 +0000107 if (!child->isTableRow()) {
darin316ed062006-01-23 05:29:14 +0000108 RenderObject* last = beforeChild;
109 if (!last)
110 last = lastChild();
inferno@chromium.orga7f719f2011-09-06 01:45:39 +0000111 if (last && last->isAnonymous() && !last->isBeforeOrAfterContent()) {
inferno@chromium.org947af302011-01-04 02:27:50 +0000112 if (beforeChild == last)
113 beforeChild = last->firstChild();
114 last->addChild(child, beforeChild);
darin316ed062006-01-23 05:29:14 +0000115 return;
116 }
117
inferno@chromium.orgb1ffad72011-10-10 18:58:12 +0000118 if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == this) {
119 RenderObject* row = beforeChild->previousSibling();
fsamuel@chromium.orgfc34e992011-10-25 19:10:58 +0000120 if (row && row->isTableRow() && row->isAnonymous()) {
inferno@chromium.orgb1ffad72011-10-10 18:58:12 +0000121 row->addChild(child);
122 return;
123 }
124 }
125
darin10ab1352006-01-29 01:29:33 +0000126 // If beforeChild is inside an anonymous cell/row, insert into the cell or into
127 // the anonymous row containing it, if there is one.
darin316ed062006-01-23 05:29:14 +0000128 RenderObject* lastBox = last;
129 while (lastBox && lastBox->parent()->isAnonymous() && !lastBox->isTableRow())
130 lastBox = lastBox->parent();
inferno@chromium.orga7f719f2011-09-06 01:45:39 +0000131 if (lastBox && lastBox->isAnonymous() && !lastBox->isBeforeOrAfterContent()) {
darin316ed062006-01-23 05:29:14 +0000132 lastBox->addChild(child, beforeChild);
133 return;
134 }
135
eric@webkit.org32963e32009-06-05 03:25:12 +0000136 RenderObject* row = new (renderArena()) RenderTableRow(document() /* anonymous table row */);
hyatt@apple.comdec0cbf22008-10-17 00:25:33 +0000137 RefPtr<RenderStyle> newStyle = RenderStyle::create();
darin316ed062006-01-23 05:29:14 +0000138 newStyle->inheritFrom(style());
139 newStyle->setDisplay(TABLE_ROW);
hyatt@apple.comdec0cbf22008-10-17 00:25:33 +0000140 row->setStyle(newStyle.release());
darin316ed062006-01-23 05:29:14 +0000141 addChild(row, beforeChild);
eseidela043f3d2006-01-20 19:24:53 +0000142 row->addChild(child);
eseidela043f3d2006-01-20 19:24:53 +0000143 return;
144 }
145
146 if (beforeChild)
ddkilzer260f3d22007-01-05 05:56:31 +0000147 setNeedsCellRecalc();
eseidela043f3d2006-01-20 19:24:53 +0000148
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000149 unsigned insertionRow = m_cRow;
ddkilzer260f3d22007-01-05 05:56:31 +0000150 ++m_cRow;
151 m_cCol = 0;
eseidela043f3d2006-01-20 19:24:53 +0000152
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +0000153 ensureRows(m_cRow);
larsb5288ad2007-01-13 18:48:29 +0000154
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000155 m_grid[insertionRow].rowRenderer = toRenderTableRow(child);
eseidela043f3d2006-01-20 19:24:53 +0000156
dbates@webkit.orge1131832009-11-19 00:05:57 +0000157 if (!beforeChild)
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +0000158 setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[insertionRow]);
eseidela043f3d2006-01-20 19:24:53 +0000159
ddkilzer260f3d22007-01-05 05:56:31 +0000160 // If the next renderer is actually wrapped in an anonymous table row, we need to go up and find that.
mitz@apple.comfdbd51e2008-01-18 21:52:57 +0000161 while (beforeChild && beforeChild->parent() != this)
mjs6666eee72006-07-14 07:45:13 +0000162 beforeChild = beforeChild->parent();
163
bdakin@apple.com40ae9be2009-04-16 20:48:19 +0000164 ASSERT(!beforeChild || beforeChild->isTableRow());
hyatt@apple.comf073d9b2009-02-05 00:53:38 +0000165 RenderBox::addChild(child, beforeChild);
mjs@apple.com2fcfc482011-04-08 06:01:59 +0000166 toRenderTableRow(child)->updateBeforeAndAfterContent();
eseidela043f3d2006-01-20 19:24:53 +0000167}
168
weinig@apple.com84974112009-02-03 06:45:48 +0000169void RenderTableSection::removeChild(RenderObject* oldChild)
170{
171 setNeedsCellRecalc();
hyatt@apple.comf073d9b2009-02-05 00:53:38 +0000172 RenderBox::removeChild(oldChild);
weinig@apple.com84974112009-02-03 06:45:48 +0000173}
174
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +0000175void RenderTableSection::ensureRows(unsigned numRows)
eseidela043f3d2006-01-20 19:24:53 +0000176{
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +0000177 if (numRows <= m_grid.size())
178 return;
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000179
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +0000180 unsigned oldSize = m_grid.size();
181 m_grid.grow(numRows);
eseidela043f3d2006-01-20 19:24:53 +0000182
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +0000183 unsigned effectiveColumnCount = max(1u, table()->numEffCols());
184 for (unsigned row = oldSize; row < m_grid.size(); ++row)
185 m_grid[row].row.grow(effectiveColumnCount);
eseidela043f3d2006-01-20 19:24:53 +0000186}
187
hyatt@apple.comd885df72009-01-22 02:31:52 +0000188void RenderTableSection::addCell(RenderTableCell* cell, RenderTableRow* row)
eseidela043f3d2006-01-20 19:24:53 +0000189{
jchaffraix@webkit.orgd01277d2011-11-09 19:57:16 +0000190 // We don't insert the cell if we need cell recalc as our internal columns' representation
191 // will have drifted from the table's representation. Also recalcCells will call addCell
192 // at a later time after sync'ing our columns' with the table's.
193 if (needsCellRecalc())
194 return;
195
eseidela043f3d2006-01-20 19:24:53 +0000196 int rSpan = cell->rowSpan();
197 int cSpan = cell->colSpan();
ddkilzer260f3d22007-01-05 05:56:31 +0000198 Vector<RenderTable::ColumnStruct>& columns = table()->columns();
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000199 unsigned nCols = columns.size();
200 // addCell should be called only after m_cRow has been incremented.
201 ASSERT(m_cRow);
202 unsigned insertionRow = m_cRow - 1;
eseidela043f3d2006-01-20 19:24:53 +0000203
204 // ### mozilla still seems to do the old HTML way, even for strict DTD
205 // (see the annotation on table cell layouting in the CSS specs and the testcase below:
206 // <TABLE border>
207 // <TR><TD>1 <TD rowspan="2">2 <TD>3 <TD>4
208 // <TR><TD colspan="2">5
209 // </TABLE>
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000210 while (m_cCol < nCols && (cellAt(insertionRow, m_cCol).hasCells() || cellAt(insertionRow, m_cCol).inColSpan))
ddkilzer260f3d22007-01-05 05:56:31 +0000211 m_cCol++;
jamesr@google.comb4266232010-07-28 20:07:19 +0000212
eseidela043f3d2006-01-20 19:24:53 +0000213 if (rSpan == 1) {
ap50b58352006-01-22 20:32:36 +0000214 // we ignore height settings on rowspan cells
mitz@apple.com8010bba2010-11-05 02:43:17 +0000215 Length logicalHeight = cell->style()->logicalHeight();
216 if (logicalHeight.isPositive() || (logicalHeight.isRelative() && logicalHeight.value() >= 0)) {
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000217 Length cRowLogicalHeight = m_grid[insertionRow].logicalHeight;
mitz@apple.com8010bba2010-11-05 02:43:17 +0000218 switch (logicalHeight.type()) {
eseidela043f3d2006-01-20 19:24:53 +0000219 case Percent:
mitz@apple.com8010bba2010-11-05 02:43:17 +0000220 if (!(cRowLogicalHeight.isPercent()) ||
commit-queue@webkit.org0740d9e2011-03-22 00:24:01 +0000221 (cRowLogicalHeight.isPercent() && cRowLogicalHeight.percent() < logicalHeight.percent()))
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000222 m_grid[insertionRow].logicalHeight = logicalHeight;
eseidela043f3d2006-01-20 19:24:53 +0000223 break;
224 case Fixed:
mitz@apple.com8010bba2010-11-05 02:43:17 +0000225 if (cRowLogicalHeight.type() < Percent ||
226 (cRowLogicalHeight.isFixed() && cRowLogicalHeight.value() < logicalHeight.value()))
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000227 m_grid[insertionRow].logicalHeight = logicalHeight;
eseidela043f3d2006-01-20 19:24:53 +0000228 break;
229 case Relative:
230 default:
231 break;
ap50b58352006-01-22 20:32:36 +0000232 }
233 }
eseidela043f3d2006-01-20 19:24:53 +0000234 }
235
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +0000236 ensureRows(insertionRow + rSpan);
eseidela043f3d2006-01-20 19:24:53 +0000237
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000238 m_grid[insertionRow].rowRenderer = row;
hyattd866e592006-03-17 09:50:35 +0000239
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000240 unsigned col = m_cCol;
eseidela043f3d2006-01-20 19:24:53 +0000241 // tell the cell where it is
jamesr@google.com36623a32010-07-23 20:22:29 +0000242 bool inColSpan = false;
eseidela043f3d2006-01-20 19:24:53 +0000243 while (cSpan) {
jamesr@google.comb4266232010-07-28 20:07:19 +0000244 int currentSpan;
245 if (m_cCol >= nCols) {
246 table()->appendColumn(cSpan);
247 currentSpan = cSpan;
248 } else {
249 if (cSpan < (int)columns[m_cCol].span)
250 table()->splitColumn(m_cCol, cSpan);
251 currentSpan = columns[m_cCol].span;
252 }
253 for (int r = 0; r < rSpan; r++) {
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000254 CellStruct& c = cellAt(insertionRow + r, m_cCol);
jamesr@google.comb4266232010-07-28 20:07:19 +0000255 ASSERT(cell);
256 c.cells.append(cell);
257 // If cells overlap then we take the slow path for painting.
258 if (c.cells.size() > 1)
259 m_hasMultipleCellLevels = true;
260 if (inColSpan)
261 c.inColSpan = true;
262 }
263 m_cCol++;
264 cSpan -= currentSpan;
265 inColSpan = true;
eseidela043f3d2006-01-20 19:24:53 +0000266 }
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000267 cell->setRow(insertionRow);
eric@webkit.org5832ab72009-03-25 22:15:03 +0000268 cell->setCol(table()->effColToCol(col));
eseidela043f3d2006-01-20 19:24:53 +0000269}
270
mitz@apple.com8010bba2010-11-05 02:43:17 +0000271void RenderTableSection::setCellLogicalWidths()
eseidela043f3d2006-01-20 19:24:53 +0000272{
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000273 Vector<LayoutUnit>& columnPos = table()->columnPositions();
eseidela043f3d2006-01-20 19:24:53 +0000274
simon.fraser@apple.comfeaef2e2008-11-07 19:17:08 +0000275 LayoutStateMaintainer statePusher(view());
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000276
277 for (unsigned i = 0; i < m_grid.size(); i++) {
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +0000278 Row& row = m_grid[i].row;
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000279 unsigned cols = row.size();
280 for (unsigned j = 0; j < cols; j++) {
jamesr@google.com36623a32010-07-23 20:22:29 +0000281 CellStruct& current = row[j];
282 RenderTableCell* cell = current.primaryCell();
jamesr@google.comb4266232010-07-28 20:07:19 +0000283 if (!cell || current.inColSpan)
jamesr@google.com36623a32010-07-23 20:22:29 +0000284 continue;
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000285 unsigned endCol = j;
ap50b58352006-01-22 20:32:36 +0000286 int cspan = cell->colSpan();
287 while (cspan && endCol < cols) {
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000288 ASSERT(endCol < table()->columns().size());
ddkilzer260f3d22007-01-05 05:56:31 +0000289 cspan -= table()->columns()[endCol].span;
ap50b58352006-01-22 20:32:36 +0000290 endCol++;
291 }
leviw@chromium.orgf6fccf52011-11-04 00:56:59 +0000292 LayoutUnit w = columnPos[endCol] - columnPos[j] - table()->hBorderSpacing();
293 LayoutUnit oldLogicalWidth = cell->logicalWidth();
mitz@apple.com8010bba2010-11-05 02:43:17 +0000294 if (w != oldLogicalWidth) {
ap50b58352006-01-22 20:32:36 +0000295 cell->setNeedsLayout(true);
weinigfef13632007-04-29 20:09:08 +0000296 if (!table()->selfNeedsLayout() && cell->checkForRepaintDuringLayout()) {
simon.fraser@apple.comfeaef2e2008-11-07 19:17:08 +0000297 if (!statePusher.didPush()) {
weinigfef13632007-04-29 20:09:08 +0000298 // Technically, we should also push state for the row, but since
299 // rows don't push a coordinate transform, that's not necessary.
leviw@chromium.orgf6fccf52011-11-04 00:56:59 +0000300 statePusher.push(this, LayoutSize(x(), y()));
weinigfef13632007-04-29 20:09:08 +0000301 }
hyattd72625b2007-04-26 19:51:11 +0000302 cell->repaint();
weinigfef13632007-04-29 20:09:08 +0000303 }
mitz@apple.com2722b372010-11-03 18:03:55 +0000304 cell->updateLogicalWidth(w);
ap50b58352006-01-22 20:32:36 +0000305 }
306 }
eseidela043f3d2006-01-20 19:24:53 +0000307 }
weinigfef13632007-04-29 20:09:08 +0000308
jamesr@google.com36623a32010-07-23 20:22:29 +0000309 statePusher.pop(); // only pops if we pushed
eseidela043f3d2006-01-20 19:24:53 +0000310}
311
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000312LayoutUnit RenderTableSection::calcRowLogicalHeight()
eseidela043f3d2006-01-20 19:24:53 +0000313{
hyatt@apple.comc93db9b2009-02-04 22:29:04 +0000314#ifndef NDEBUG
315 setNeedsLayoutIsForbidden(true);
316#endif
317
318 ASSERT(!needsLayout());
319
ddkilzer260f3d22007-01-05 05:56:31 +0000320 RenderTableCell* cell;
eseidela043f3d2006-01-20 19:24:53 +0000321
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000322 LayoutUnit spacing = table()->vBorderSpacing();
simon.fraser@apple.comfeaef2e2008-11-07 19:17:08 +0000323
324 LayoutStateMaintainer statePusher(view());
eseidela043f3d2006-01-20 19:24:53 +0000325
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000326 m_rowPos.resize(m_grid.size() + 1);
ddkilzer260f3d22007-01-05 05:56:31 +0000327 m_rowPos[0] = spacing;
eseidela043f3d2006-01-20 19:24:53 +0000328
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000329 for (unsigned r = 0; r < m_grid.size(); r++) {
ddkilzer260f3d22007-01-05 05:56:31 +0000330 m_rowPos[r + 1] = 0;
hyatt777b31c2007-07-19 20:01:26 +0000331 m_grid[r].baseline = 0;
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000332 LayoutUnit baseline = 0;
333 LayoutUnit bdesc = 0;
334 LayoutUnit ch = m_grid[r].logicalHeight.calcMinValue(0);
335 LayoutUnit pos = m_rowPos[r] + ch + (m_grid[r].rowRenderer ? spacing : 0);
eseidela043f3d2006-01-20 19:24:53 +0000336
ddkilzer260f3d22007-01-05 05:56:31 +0000337 m_rowPos[r + 1] = max(m_rowPos[r + 1], pos);
eseidela043f3d2006-01-20 19:24:53 +0000338
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +0000339 Row& row = m_grid[r].row;
340 unsigned totalCols = row.size();
eseidela043f3d2006-01-20 19:24:53 +0000341
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000342 for (unsigned c = 0; c < totalCols; c++) {
jamesr@google.com36623a32010-07-23 20:22:29 +0000343 CellStruct& current = cellAt(r, c);
344 cell = current.primaryCell();
jamesr@google.comb4266232010-07-28 20:07:19 +0000345
346 if (!cell || current.inColSpan)
ap50b58352006-01-22 20:32:36 +0000347 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000348
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000349 if ((cell->row() + cell->rowSpan() - 1) > r)
ap50b58352006-01-22 20:32:36 +0000350 continue;
eseidela043f3d2006-01-20 19:24:53 +0000351
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000352 unsigned indx = max(r - cell->rowSpan() + 1, 0u);
eseidela043f3d2006-01-20 19:24:53 +0000353
ojan@chromium.orgf734c922011-09-07 20:18:14 +0000354 if (cell->hasOverrideHeight()) {
simon.fraser@apple.comfeaef2e2008-11-07 19:17:08 +0000355 if (!statePusher.didPush()) {
weinigfef13632007-04-29 20:09:08 +0000356 // Technically, we should also push state for the row, but since
357 // rows don't push a coordinate transform, that's not necessary.
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000358 statePusher.push(this, locationOffset());
weinigfef13632007-04-29 20:09:08 +0000359 }
tony@chromium.orgaefe0ea2011-07-08 22:15:14 +0000360 cell->clearIntrinsicPadding();
361 cell->clearOverrideSize();
eseidela043f3d2006-01-20 19:24:53 +0000362 cell->setChildNeedsLayout(true, false);
363 cell->layoutIfNeeded();
364 }
mitz@apple.com8010bba2010-11-05 02:43:17 +0000365
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000366 LayoutUnit adjustedLogicalHeight = cell->logicalHeight() - (cell->intrinsicPaddingBefore() + cell->intrinsicPaddingAfter());
mitz@apple.com8010bba2010-11-05 02:43:17 +0000367
dominicc@chromium.org2b740ac2011-11-01 20:55:57 +0000368 ch = cell->style()->logicalHeight().calcValue(0);
369 if (document()->inQuirksMode() || cell->style()->boxSizing() == BORDER_BOX) {
370 // Explicit heights use the border box in quirks mode.
371 // Don't adjust height.
372 } else {
373 // In strict mode, box-sizing: content-box do the right
374 // thing and actually add in the border and padding.
375 LayoutUnit adjustedPaddingBefore = cell->paddingBefore() - cell->intrinsicPaddingBefore();
376 LayoutUnit adjustedPaddingAfter = cell->paddingAfter() - cell->intrinsicPaddingAfter();
377 ch += adjustedPaddingBefore + adjustedPaddingAfter + cell->borderBefore() + cell->borderAfter();
378 }
mitz@apple.com8010bba2010-11-05 02:43:17 +0000379 ch = max(ch, adjustedLogicalHeight);
eseidela043f3d2006-01-20 19:24:53 +0000380
ddkilzer260f3d22007-01-05 05:56:31 +0000381 pos = m_rowPos[indx] + ch + (m_grid[r].rowRenderer ? spacing : 0);
eseidela043f3d2006-01-20 19:24:53 +0000382
ddkilzer260f3d22007-01-05 05:56:31 +0000383 m_rowPos[r + 1] = max(m_rowPos[r + 1], pos);
eseidela043f3d2006-01-20 19:24:53 +0000384
ap50b58352006-01-22 20:32:36 +0000385 // find out the baseline
386 EVerticalAlign va = cell->style()->verticalAlign();
ddkilzer260f3d22007-01-05 05:56:31 +0000387 if (va == BASELINE || va == TEXT_BOTTOM || va == TEXT_TOP || va == SUPER || va == SUB) {
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000388 LayoutUnit b = cell->cellBaselinePosition();
mitz@apple.com8010bba2010-11-05 02:43:17 +0000389 if (b > cell->borderBefore() + cell->paddingBefore()) {
hyatt@apple.comd76152f2010-09-21 07:45:08 +0000390 baseline = max(baseline, b - cell->intrinsicPaddingBefore());
391 bdesc = max(bdesc, m_rowPos[indx] + ch - (b - cell->intrinsicPaddingBefore()));
eseidela043f3d2006-01-20 19:24:53 +0000392 }
ap50b58352006-01-22 20:32:36 +0000393 }
394 }
eseidela043f3d2006-01-20 19:24:53 +0000395
jamesr@google.com36623a32010-07-23 20:22:29 +0000396 // do we have baseline aligned elements?
ap50b58352006-01-22 20:32:36 +0000397 if (baseline) {
398 // increase rowheight if baseline requires
ddkilzer260f3d22007-01-05 05:56:31 +0000399 m_rowPos[r + 1] = max(m_rowPos[r + 1], baseline + bdesc + (m_grid[r].rowRenderer ? spacing : 0));
hyatt851433b2007-05-12 06:40:14 +0000400 m_grid[r].baseline = baseline;
ap50b58352006-01-22 20:32:36 +0000401 }
eseidela043f3d2006-01-20 19:24:53 +0000402
ddkilzer260f3d22007-01-05 05:56:31 +0000403 m_rowPos[r + 1] = max(m_rowPos[r + 1], m_rowPos[r]);
eseidela043f3d2006-01-20 19:24:53 +0000404 }
weinigfef13632007-04-29 20:09:08 +0000405
hyatt@apple.comc93db9b2009-02-04 22:29:04 +0000406#ifndef NDEBUG
407 setNeedsLayoutIsForbidden(false);
408#endif
409
410 ASSERT(!needsLayout());
411
simon.fraser@apple.comfeaef2e2008-11-07 19:17:08 +0000412 statePusher.pop();
mitz@apple.com440ac8c2008-04-05 16:05:08 +0000413
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000414 return m_rowPos[m_grid.size()];
eseidela043f3d2006-01-20 19:24:53 +0000415}
416
hyatt@apple.combfda0e32009-01-31 21:20:17 +0000417void RenderTableSection::layout()
418{
419 ASSERT(needsLayout());
420
leviw@chromium.org5b6a6ce2011-07-02 00:16:52 +0000421 LayoutStateMaintainer statePusher(view(), this, locationOffset(), style()->isFlippedBlocksWritingMode());
hyatt@apple.combfda0e32009-01-31 21:20:17 +0000422 for (RenderObject* child = children()->firstChild(); child; child = child->nextSibling()) {
423 if (child->isTableRow()) {
424 child->layoutIfNeeded();
425 ASSERT(!child->needsLayout());
426 }
427 }
428 statePusher.pop();
429 setNeedsLayout(false);
430}
431
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000432LayoutUnit RenderTableSection::layoutRows(LayoutUnit toAdd)
eseidela043f3d2006-01-20 19:24:53 +0000433{
hyatt@apple.comc93db9b2009-02-04 22:29:04 +0000434#ifndef NDEBUG
435 setNeedsLayoutIsForbidden(true);
436#endif
437
438 ASSERT(!needsLayout());
439
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000440 LayoutUnit rHeight;
eseidela043f3d2006-01-20 19:24:53 +0000441 int rindx;
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000442 unsigned totalRows = m_grid.size();
443
hyattd866e592006-03-17 09:50:35 +0000444 // Set the width of our section now. The rows will also be this width.
mitz@apple.com8010bba2010-11-05 02:43:17 +0000445 setLogicalWidth(table()->contentLogicalWidth());
hyatt@apple.com5dc5a312009-08-18 19:15:19 +0000446 m_overflow.clear();
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +0000447 m_overflowingCells.clear();
448 m_forceSlowPaintPathWithOverflowingCell = false;
adeleddfe27f2007-01-05 23:03:50 +0000449
ddkilzer260f3d22007-01-05 05:56:31 +0000450 if (toAdd && totalRows && (m_rowPos[totalRows] || !nextSibling())) {
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000451 LayoutUnit totalHeight = m_rowPos[totalRows] + toAdd;
eseidela043f3d2006-01-20 19:24:53 +0000452
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000453 LayoutUnit dh = toAdd;
ap50b58352006-01-22 20:32:36 +0000454 int totalPercent = 0;
455 int numAuto = 0;
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000456 for (unsigned r = 0; r < totalRows; r++) {
mitz@apple.com8010bba2010-11-05 02:43:17 +0000457 if (m_grid[r].logicalHeight.isAuto())
ap50b58352006-01-22 20:32:36 +0000458 numAuto++;
mitz@apple.com8010bba2010-11-05 02:43:17 +0000459 else if (m_grid[r].logicalHeight.isPercent())
commit-queue@webkit.org0740d9e2011-03-22 00:24:01 +0000460 totalPercent += m_grid[r].logicalHeight.percent();
ap50b58352006-01-22 20:32:36 +0000461 }
462 if (totalPercent) {
463 // try to satisfy percent
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000464 LayoutUnit add = 0;
commit-queue@webkit.org0740d9e2011-03-22 00:24:01 +0000465 totalPercent = min(totalPercent, 100);
leviw@chromium.orgf6fccf52011-11-04 00:56:59 +0000466 LayoutUnit rh = m_rowPos[1] - m_rowPos[0];
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000467 for (unsigned r = 0; r < totalRows; r++) {
mitz@apple.com8010bba2010-11-05 02:43:17 +0000468 if (totalPercent > 0 && m_grid[r].logicalHeight.isPercent()) {
leviw@chromium.orgf6fccf52011-11-04 00:56:59 +0000469 LayoutUnit toAdd = min<LayoutUnit>(dh, (totalHeight * m_grid[r].logicalHeight.percent() / 100) - rh);
eseidela043f3d2006-01-20 19:24:53 +0000470 // If toAdd is negative, then we don't want to shrink the row (this bug
471 // affected Outlook Web Access).
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000472 toAdd = max<LayoutUnit>(0, toAdd);
ap50b58352006-01-22 20:32:36 +0000473 add += toAdd;
474 dh -= toAdd;
commit-queue@webkit.org0740d9e2011-03-22 00:24:01 +0000475 totalPercent -= m_grid[r].logicalHeight.percent();
ap50b58352006-01-22 20:32:36 +0000476 }
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000477 ASSERT(totalRows >= 1);
ap50b58352006-01-22 20:32:36 +0000478 if (r < totalRows - 1)
ddkilzer260f3d22007-01-05 05:56:31 +0000479 rh = m_rowPos[r + 2] - m_rowPos[r + 1];
480 m_rowPos[r + 1] += add;
ap50b58352006-01-22 20:32:36 +0000481 }
482 }
483 if (numAuto) {
484 // distribute over variable cols
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000485 LayoutUnit add = 0;
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000486 for (unsigned r = 0; r < totalRows; r++) {
mitz@apple.com8010bba2010-11-05 02:43:17 +0000487 if (numAuto > 0 && m_grid[r].logicalHeight.isAuto()) {
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000488 LayoutUnit toAdd = dh / numAuto;
ap50b58352006-01-22 20:32:36 +0000489 add += toAdd;
490 dh -= toAdd;
eseidela043f3d2006-01-20 19:24:53 +0000491 numAuto--;
ap50b58352006-01-22 20:32:36 +0000492 }
ddkilzer260f3d22007-01-05 05:56:31 +0000493 m_rowPos[r + 1] += add;
ap50b58352006-01-22 20:32:36 +0000494 }
495 }
ddkilzer260f3d22007-01-05 05:56:31 +0000496 if (dh > 0 && m_rowPos[totalRows]) {
ap50b58352006-01-22 20:32:36 +0000497 // if some left overs, distribute equally.
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000498 LayoutUnit tot = m_rowPos[totalRows];
499 LayoutUnit add = 0;
500 LayoutUnit prev = m_rowPos[0];
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000501 for (unsigned r = 0; r < totalRows; r++) {
jamesr@google.com36623a32010-07-23 20:22:29 +0000502 // weight with the original height
ddkilzer260f3d22007-01-05 05:56:31 +0000503 add += dh * (m_rowPos[r + 1] - prev) / tot;
504 prev = m_rowPos[r + 1];
505 m_rowPos[r + 1] += add;
eseidela043f3d2006-01-20 19:24:53 +0000506 }
507 }
508 }
509
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000510 LayoutUnit hspacing = table()->hBorderSpacing();
511 LayoutUnit vspacing = table()->vBorderSpacing();
512 LayoutUnit nEffCols = table()->numEffCols();
ddkilzer260f3d22007-01-05 05:56:31 +0000513
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000514 LayoutStateMaintainer statePusher(view(), this, LayoutSize(x(), y()), style()->isFlippedBlocksWritingMode());
weinigfef13632007-04-29 20:09:08 +0000515
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000516 for (unsigned r = 0; r < totalRows; r++) {
hyattd866e592006-03-17 09:50:35 +0000517 // Set the row's x/y position and width/height.
hyatt@apple.comd885df72009-01-22 02:31:52 +0000518 if (RenderTableRow* rowRenderer = m_grid[r].rowRenderer) {
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000519 rowRenderer->setLocation(LayoutPoint(0, m_rowPos[r]));
mitz@apple.com8010bba2010-11-05 02:43:17 +0000520 rowRenderer->setLogicalWidth(logicalWidth());
521 rowRenderer->setLogicalHeight(m_rowPos[r + 1] - m_rowPos[r] - vspacing);
simon.fraser@apple.com78e3bdb2010-11-30 00:53:05 +0000522 rowRenderer->updateLayerTransform();
hyattd866e592006-03-17 09:50:35 +0000523 }
524
eseidela043f3d2006-01-20 19:24:53 +0000525 for (int c = 0; c < nEffCols; c++) {
jamesr@google.com36623a32010-07-23 20:22:29 +0000526 CellStruct& cs = cellAt(r, c);
527 RenderTableCell* cell = cs.primaryCell();
528
jamesr@google.comb4266232010-07-28 20:07:19 +0000529 if (!cell || cs.inColSpan)
ap50b58352006-01-22 20:32:36 +0000530 continue;
eseidela043f3d2006-01-20 19:24:53 +0000531
jamesr@google.com36623a32010-07-23 20:22:29 +0000532 rindx = cell->row();
533 rHeight = m_rowPos[rindx + cell->rowSpan()] - m_rowPos[rindx] - vspacing;
eseidela043f3d2006-01-20 19:24:53 +0000534
535 // Force percent height children to lay themselves out again.
536 // This will cause these children to grow to fill the cell.
537 // FIXME: There is still more work to do here to fully match WinIE (should
538 // it become necessary to do so). In quirks mode, WinIE behaves like we
539 // do, but it will clip the cells that spill out of the table section. In
540 // strict mode, Mozilla and WinIE both regrow the table to accommodate the
541 // new height of the cell (thus letting the percentages cause growth one
542 // time only). We may also not be handling row-spanning cells correctly.
543 //
544 // Note also the oddity where replaced elements always flex, and yet blocks/tables do
545 // not necessarily flex. WinIE is crazy and inconsistent, and we can't hope to
546 // match the behavior perfectly, but we'll continue to refine it as we discover new
547 // bugs. :)
548 bool cellChildrenFlex = false;
mitz@apple.com8010bba2010-11-05 02:43:17 +0000549 bool flexAllChildren = cell->style()->logicalHeight().isFixed()
550 || (!table()->style()->logicalHeight().isAuto() && rHeight != cell->logicalHeight());
eseidela043f3d2006-01-20 19:24:53 +0000551
552 for (RenderObject* o = cell->firstChild(); o; o = o->nextSibling()) {
mitz@apple.com8010bba2010-11-05 02:43:17 +0000553 if (!o->isText() && o->style()->logicalHeight().isPercent() && (flexAllChildren || o->isReplaced() || (o->isBox() && toRenderBox(o)->scrollsOverflow()))) {
eseidela043f3d2006-01-20 19:24:53 +0000554 // Tables with no sections do not flex.
darin@apple.com445c34f2009-08-01 00:40:58 +0000555 if (!o->isTable() || toRenderTable(o)->hasSections()) {
eseidela043f3d2006-01-20 19:24:53 +0000556 o->setNeedsLayout(true, false);
eseidela043f3d2006-01-20 19:24:53 +0000557 cellChildrenFlex = true;
558 }
559 }
560 }
mitz@apple.com1547c6d2009-03-20 23:41:54 +0000561
562 if (HashSet<RenderBox*>* percentHeightDescendants = cell->percentHeightDescendants()) {
563 HashSet<RenderBox*>::iterator end = percentHeightDescendants->end();
564 for (HashSet<RenderBox*>::iterator it = percentHeightDescendants->begin(); it != end; ++it) {
565 RenderBox* box = *it;
566 if (!box->isReplaced() && !box->scrollsOverflow() && !flexAllChildren)
567 continue;
568
569 while (box != cell) {
570 if (box->normalChildNeedsLayout())
571 break;
572 box->setChildNeedsLayout(true, false);
573 box = box->containingBlock();
574 ASSERT(box);
575 if (!box)
576 break;
577 }
578 cellChildrenFlex = true;
579 }
580 }
581
eseidela043f3d2006-01-20 19:24:53 +0000582 if (cellChildrenFlex) {
mitz@apple.com1547c6d2009-03-20 23:41:54 +0000583 cell->setChildNeedsLayout(true, false);
eseidela043f3d2006-01-20 19:24:53 +0000584 // Alignment within a cell is based off the calculated
585 // height, which becomes irrelevant once the cell has
hyatt@apple.com0bf6c842009-01-23 03:42:12 +0000586 // been resized based off its percentage.
ojan@chromium.orgf734c922011-09-07 20:18:14 +0000587 cell->setOverrideHeightFromRowHeight(rHeight);
ap7332aaa2006-04-28 16:02:45 +0000588 cell->layoutIfNeeded();
mitz@apple.com8010bba2010-11-05 02:43:17 +0000589
hyatt851433b2007-05-12 06:40:14 +0000590 // If the baseline moved, we may have to update the data for our row. Find out the new baseline.
591 EVerticalAlign va = cell->style()->verticalAlign();
592 if (va == BASELINE || va == TEXT_BOTTOM || va == TEXT_TOP || va == SUPER || va == SUB) {
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000593 LayoutUnit baseline = cell->cellBaselinePosition();
594 if (baseline > cell->borderBefore() + cell->paddingBefore())
595 m_grid[r].baseline = max(m_grid[r].baseline, baseline);
hyatt851433b2007-05-12 06:40:14 +0000596 }
eseidela043f3d2006-01-20 19:24:53 +0000597 }
mitz@apple.com8010bba2010-11-05 02:43:17 +0000598
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000599 LayoutUnit oldIntrinsicPaddingBefore = cell->intrinsicPaddingBefore();
600 LayoutUnit oldIntrinsicPaddingAfter = cell->intrinsicPaddingAfter();
601 LayoutUnit logicalHeightWithoutIntrinsicPadding = cell->logicalHeight() - oldIntrinsicPaddingBefore - oldIntrinsicPaddingAfter;
mitz@apple.com8010bba2010-11-05 02:43:17 +0000602
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000603 LayoutUnit intrinsicPaddingBefore = 0;
bdakinf9936352007-04-19 19:58:20 +0000604 switch (cell->style()->verticalAlign()) {
605 case SUB:
606 case SUPER:
607 case TEXT_TOP:
608 case TEXT_BOTTOM:
hyatt@apple.com5defbad2009-01-23 04:30:47 +0000609 case BASELINE: {
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000610 LayoutUnit b = cell->cellBaselinePosition();
mitz@apple.com8010bba2010-11-05 02:43:17 +0000611 if (b > cell->borderBefore() + cell->paddingBefore())
612 intrinsicPaddingBefore = getBaseline(r) - (b - oldIntrinsicPaddingBefore);
bdakinf9936352007-04-19 19:58:20 +0000613 break;
hyatt@apple.com5defbad2009-01-23 04:30:47 +0000614 }
bdakinf9936352007-04-19 19:58:20 +0000615 case TOP:
bdakinf9936352007-04-19 19:58:20 +0000616 break;
617 case MIDDLE:
mitz@apple.com8010bba2010-11-05 02:43:17 +0000618 intrinsicPaddingBefore = (rHeight - logicalHeightWithoutIntrinsicPadding) / 2;
bdakinf9936352007-04-19 19:58:20 +0000619 break;
620 case BOTTOM:
mitz@apple.com8010bba2010-11-05 02:43:17 +0000621 intrinsicPaddingBefore = rHeight - logicalHeightWithoutIntrinsicPadding;
bdakinf9936352007-04-19 19:58:20 +0000622 break;
623 default:
624 break;
625 }
hyatt@apple.com0bf6c842009-01-23 03:42:12 +0000626
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000627 LayoutUnit intrinsicPaddingAfter = rHeight - logicalHeightWithoutIntrinsicPadding - intrinsicPaddingBefore;
mitz@apple.com8010bba2010-11-05 02:43:17 +0000628 cell->setIntrinsicPaddingBefore(intrinsicPaddingBefore);
629 cell->setIntrinsicPaddingAfter(intrinsicPaddingAfter);
630
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000631 LayoutRect oldCellRect(cell->x(), cell->y() , cell->width(), cell->height());
mitz@apple.com8010bba2010-11-05 02:43:17 +0000632
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000633 LayoutPoint cellLocation(0, m_rowPos[rindx]);
hyatt@apple.comc0fa1632010-09-30 20:01:33 +0000634 if (!style()->isLeftToRightDirection())
eae@chromium.orgbe9be862011-05-12 23:30:09 +0000635 cellLocation.setX(table()->columnPositions()[nEffCols] - table()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + hspacing);
jamesr@google.com36623a32010-07-23 20:22:29 +0000636 else
eae@chromium.orgbe9be862011-05-12 23:30:09 +0000637 cellLocation.setX(table()->columnPositions()[c] + hspacing);
638 cell->setLogicalLocation(cellLocation);
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000639 view()->addLayoutDelta(oldCellRect.location() - cell->location());
eseidela043f3d2006-01-20 19:24:53 +0000640
mitz@apple.com8010bba2010-11-05 02:43:17 +0000641 if (intrinsicPaddingBefore != oldIntrinsicPaddingBefore || intrinsicPaddingAfter != oldIntrinsicPaddingAfter)
hyatt@apple.com1259d732010-09-20 16:12:58 +0000642 cell->setNeedsLayout(true, false);
mitz@apple.com8010bba2010-11-05 02:43:17 +0000643
hyatt@apple.com61bbedf2011-01-26 23:10:57 +0000644 if (!cell->needsLayout() && view()->layoutState()->pageLogicalHeight() && view()->layoutState()->pageLogicalOffset(cell->logicalTop()) != cell->pageLogicalOffset())
hyatt@apple.com1259d732010-09-20 16:12:58 +0000645 cell->setChildNeedsLayout(true, false);
mitz@apple.com8010bba2010-11-05 02:43:17 +0000646
hyatt@apple.com1259d732010-09-20 16:12:58 +0000647 cell->layoutIfNeeded();
mitz@apple.com8010bba2010-11-05 02:43:17 +0000648
649 // FIXME: Make pagination work with vertical tables.
hyatt@apple.com9285815d2010-12-14 19:58:38 +0000650 if (style()->isHorizontalWritingMode() && view()->layoutState()->pageLogicalHeight() && cell->height() != rHeight)
hyatt@apple.com1259d732010-09-20 16:12:58 +0000651 cell->setHeight(rHeight); // FIXME: Pagination might have made us change size. For now just shrink or grow the cell to fit without doing a relayout.
mitz@apple.com8010bba2010-11-05 02:43:17 +0000652
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000653 LayoutSize childOffset(cell->location() - oldCellRect.location());
hyatt@apple.comb297b492010-09-20 20:21:34 +0000654 if (childOffset.width() || childOffset.height()) {
655 view()->addLayoutDelta(childOffset);
hyatt@apple.com1259d732010-09-20 16:12:58 +0000656
hyatt@apple.comb297b492010-09-20 20:21:34 +0000657 // If the child moved, we have to repaint it as well as any floating/positioned
658 // descendants. An exception is if we need a layout. In this case, we know we're going to
659 // repaint ourselves (and the child) anyway.
660 if (!table()->selfNeedsLayout() && cell->checkForRepaintDuringLayout())
661 cell->repaintDuringLayoutIfMoved(oldCellRect);
662 }
eseidela043f3d2006-01-20 19:24:53 +0000663 }
664 }
665
hyatt@apple.comc93db9b2009-02-04 22:29:04 +0000666#ifndef NDEBUG
667 setNeedsLayoutIsForbidden(false);
668#endif
669
hyatt@apple.com8b2cd1f2009-01-26 03:38:55 +0000670 ASSERT(!needsLayout());
671
mitz@apple.com8010bba2010-11-05 02:43:17 +0000672 setLogicalHeight(m_rowPos[totalRows]);
hyatt@apple.com7214c6a2009-08-19 16:28:51 +0000673
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +0000674 unsigned totalCellsCount = nEffCols * totalRows;
675 int maxAllowedOverflowingCellsCount = totalCellsCount < gMinTableSizeToUseFastPaintPathWithOverflowingCell ? 0 : gMaxAllowedOverflowingCellRatioForFastPaintPath * totalCellsCount;
676
677#ifndef NDEBUG
678 bool hasOverflowingCell = false;
679#endif
hyatt@apple.com7214c6a2009-08-19 16:28:51 +0000680 // Now that our height has been determined, add in overflow from cells.
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000681 for (unsigned r = 0; r < totalRows; r++) {
hyatt@apple.com7214c6a2009-08-19 16:28:51 +0000682 for (int c = 0; c < nEffCols; c++) {
jamesr@google.com36623a32010-07-23 20:22:29 +0000683 CellStruct& cs = cellAt(r, c);
684 RenderTableCell* cell = cs.primaryCell();
jamesr@google.comb4266232010-07-28 20:07:19 +0000685 if (!cell || cs.inColSpan)
hyatt@apple.com7214c6a2009-08-19 16:28:51 +0000686 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000687 if (r < totalRows - 1 && cell == primaryCellAt(r + 1, c))
hyatt@apple.com7214c6a2009-08-19 16:28:51 +0000688 continue;
689 addOverflowFromChild(cell);
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +0000690#ifndef NDEBUG
691 hasOverflowingCell |= cell->hasVisualOverflow();
692#endif
693 if (cell->hasVisualOverflow() && !m_forceSlowPaintPathWithOverflowingCell) {
694 m_overflowingCells.add(cell);
695 if (m_overflowingCells.size() > maxAllowedOverflowingCellsCount) {
696 // We need to set m_forcesSlowPaintPath only if there is a least one overflowing cells as the hit testing code rely on this information.
697 m_forceSlowPaintPathWithOverflowingCell = true;
698 // The slow path does not make any use of the overflowing cells info, don't hold on to the memory.
699 m_overflowingCells.clear();
700 }
701 }
hyatt@apple.com7214c6a2009-08-19 16:28:51 +0000702 }
703 }
weinigfef13632007-04-29 20:09:08 +0000704
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +0000705 ASSERT(hasOverflowingCell == this->hasOverflowingCell());
706
mitz@apple.comeea52852009-12-31 18:41:23 +0000707 statePusher.pop();
hyatt@apple.comd885df72009-01-22 02:31:52 +0000708 return height();
eseidela043f3d2006-01-20 19:24:53 +0000709}
710
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000711LayoutUnit RenderTableSection::calcOuterBorderBefore() const
darin32011102006-05-15 04:42:09 +0000712{
713 int totalCols = table()->numEffCols();
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000714 if (!m_grid.size() || !totalCols)
darin32011102006-05-15 04:42:09 +0000715 return 0;
716
717 unsigned borderWidth = 0;
718
mitz@apple.com8010bba2010-11-05 02:43:17 +0000719 const BorderValue& sb = style()->borderBefore();
darin32011102006-05-15 04:42:09 +0000720 if (sb.style() == BHIDDEN)
721 return -1;
722 if (sb.style() > BHIDDEN)
hyatt@apple.come607db72010-04-09 20:21:55 +0000723 borderWidth = sb.width();
darin32011102006-05-15 04:42:09 +0000724
mitz@apple.com8010bba2010-11-05 02:43:17 +0000725 const BorderValue& rb = firstChild()->style()->borderBefore();
darin32011102006-05-15 04:42:09 +0000726 if (rb.style() == BHIDDEN)
727 return -1;
hyatt@apple.come607db72010-04-09 20:21:55 +0000728 if (rb.style() > BHIDDEN && rb.width() > borderWidth)
729 borderWidth = rb.width();
darin32011102006-05-15 04:42:09 +0000730
731 bool allHidden = true;
732 for (int c = 0; c < totalCols; c++) {
733 const CellStruct& current = cellAt(0, c);
jamesr@google.com36623a32010-07-23 20:22:29 +0000734 if (current.inColSpan || !current.hasCells())
darin32011102006-05-15 04:42:09 +0000735 continue;
mitz@apple.com8010bba2010-11-05 02:43:17 +0000736 const BorderValue& cb = current.primaryCell()->style()->borderBefore(); // FIXME: Make this work with perpendicular and flipped cells.
darin32011102006-05-15 04:42:09 +0000737 // FIXME: Don't repeat for the same col group
738 RenderTableCol* colGroup = table()->colElement(c);
739 if (colGroup) {
mitz@apple.com8010bba2010-11-05 02:43:17 +0000740 const BorderValue& gb = colGroup->style()->borderBefore();
darin32011102006-05-15 04:42:09 +0000741 if (gb.style() == BHIDDEN || cb.style() == BHIDDEN)
742 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000743 allHidden = false;
hyatt@apple.come607db72010-04-09 20:21:55 +0000744 if (gb.style() > BHIDDEN && gb.width() > borderWidth)
745 borderWidth = gb.width();
746 if (cb.style() > BHIDDEN && cb.width() > borderWidth)
747 borderWidth = cb.width();
darin32011102006-05-15 04:42:09 +0000748 } else {
749 if (cb.style() == BHIDDEN)
750 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000751 allHidden = false;
hyatt@apple.come607db72010-04-09 20:21:55 +0000752 if (cb.style() > BHIDDEN && cb.width() > borderWidth)
753 borderWidth = cb.width();
darin32011102006-05-15 04:42:09 +0000754 }
755 }
756 if (allHidden)
757 return -1;
758
759 return borderWidth / 2;
760}
761
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000762LayoutUnit RenderTableSection::calcOuterBorderAfter() const
darin32011102006-05-15 04:42:09 +0000763{
764 int totalCols = table()->numEffCols();
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000765 if (!m_grid.size() || !totalCols)
darin32011102006-05-15 04:42:09 +0000766 return 0;
767
768 unsigned borderWidth = 0;
769
mitz@apple.com8010bba2010-11-05 02:43:17 +0000770 const BorderValue& sb = style()->borderAfter();
darin32011102006-05-15 04:42:09 +0000771 if (sb.style() == BHIDDEN)
772 return -1;
773 if (sb.style() > BHIDDEN)
hyatt@apple.come607db72010-04-09 20:21:55 +0000774 borderWidth = sb.width();
darin32011102006-05-15 04:42:09 +0000775
mitz@apple.com8010bba2010-11-05 02:43:17 +0000776 const BorderValue& rb = lastChild()->style()->borderAfter();
darin32011102006-05-15 04:42:09 +0000777 if (rb.style() == BHIDDEN)
778 return -1;
hyatt@apple.come607db72010-04-09 20:21:55 +0000779 if (rb.style() > BHIDDEN && rb.width() > borderWidth)
780 borderWidth = rb.width();
darin32011102006-05-15 04:42:09 +0000781
782 bool allHidden = true;
783 for (int c = 0; c < totalCols; c++) {
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000784 const CellStruct& current = cellAt(m_grid.size() - 1, c);
jamesr@google.com36623a32010-07-23 20:22:29 +0000785 if (current.inColSpan || !current.hasCells())
darin32011102006-05-15 04:42:09 +0000786 continue;
mitz@apple.com8010bba2010-11-05 02:43:17 +0000787 const BorderValue& cb = current.primaryCell()->style()->borderAfter(); // FIXME: Make this work with perpendicular and flipped cells.
darin32011102006-05-15 04:42:09 +0000788 // FIXME: Don't repeat for the same col group
789 RenderTableCol* colGroup = table()->colElement(c);
790 if (colGroup) {
mitz@apple.com8010bba2010-11-05 02:43:17 +0000791 const BorderValue& gb = colGroup->style()->borderAfter();
darin32011102006-05-15 04:42:09 +0000792 if (gb.style() == BHIDDEN || cb.style() == BHIDDEN)
793 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000794 allHidden = false;
hyatt@apple.come607db72010-04-09 20:21:55 +0000795 if (gb.style() > BHIDDEN && gb.width() > borderWidth)
796 borderWidth = gb.width();
797 if (cb.style() > BHIDDEN && cb.width() > borderWidth)
798 borderWidth = cb.width();
darin32011102006-05-15 04:42:09 +0000799 } else {
800 if (cb.style() == BHIDDEN)
801 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000802 allHidden = false;
hyatt@apple.come607db72010-04-09 20:21:55 +0000803 if (cb.style() > BHIDDEN && cb.width() > borderWidth)
804 borderWidth = cb.width();
darin32011102006-05-15 04:42:09 +0000805 }
806 }
807 if (allHidden)
808 return -1;
809
810 return (borderWidth + 1) / 2;
811}
812
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000813LayoutUnit RenderTableSection::calcOuterBorderStart() const
darin32011102006-05-15 04:42:09 +0000814{
815 int totalCols = table()->numEffCols();
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000816 if (!m_grid.size() || !totalCols)
darin32011102006-05-15 04:42:09 +0000817 return 0;
818
819 unsigned borderWidth = 0;
820
mitz@apple.com8010bba2010-11-05 02:43:17 +0000821 const BorderValue& sb = style()->borderStart();
darin32011102006-05-15 04:42:09 +0000822 if (sb.style() == BHIDDEN)
823 return -1;
824 if (sb.style() > BHIDDEN)
hyatt@apple.come607db72010-04-09 20:21:55 +0000825 borderWidth = sb.width();
darin32011102006-05-15 04:42:09 +0000826
mitz@apple.com8010bba2010-11-05 02:43:17 +0000827 if (RenderTableCol* colGroup = table()->colElement(0)) {
828 const BorderValue& gb = colGroup->style()->borderStart();
darin32011102006-05-15 04:42:09 +0000829 if (gb.style() == BHIDDEN)
830 return -1;
hyatt@apple.come607db72010-04-09 20:21:55 +0000831 if (gb.style() > BHIDDEN && gb.width() > borderWidth)
832 borderWidth = gb.width();
darin32011102006-05-15 04:42:09 +0000833 }
834
835 bool allHidden = true;
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000836 for (unsigned r = 0; r < m_grid.size(); r++) {
mitz@apple.com8010bba2010-11-05 02:43:17 +0000837 const CellStruct& current = cellAt(r, 0);
jamesr@google.com36623a32010-07-23 20:22:29 +0000838 if (!current.hasCells())
darin32011102006-05-15 04:42:09 +0000839 continue;
840 // FIXME: Don't repeat for the same cell
mitz@apple.com8010bba2010-11-05 02:43:17 +0000841 const BorderValue& cb = current.primaryCell()->style()->borderStart(); // FIXME: Make this work with perpendicular and flipped cells.
842 const BorderValue& rb = current.primaryCell()->parent()->style()->borderStart();
darin32011102006-05-15 04:42:09 +0000843 if (cb.style() == BHIDDEN || rb.style() == BHIDDEN)
844 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000845 allHidden = false;
hyatt@apple.come607db72010-04-09 20:21:55 +0000846 if (cb.style() > BHIDDEN && cb.width() > borderWidth)
847 borderWidth = cb.width();
848 if (rb.style() > BHIDDEN && rb.width() > borderWidth)
849 borderWidth = rb.width();
darin32011102006-05-15 04:42:09 +0000850 }
851 if (allHidden)
852 return -1;
853
mitz@apple.com8010bba2010-11-05 02:43:17 +0000854 return (borderWidth + (table()->style()->isLeftToRightDirection() ? 0 : 1)) / 2;
darin32011102006-05-15 04:42:09 +0000855}
856
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000857LayoutUnit RenderTableSection::calcOuterBorderEnd() const
darin32011102006-05-15 04:42:09 +0000858{
859 int totalCols = table()->numEffCols();
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000860 if (!m_grid.size() || !totalCols)
darin32011102006-05-15 04:42:09 +0000861 return 0;
862
863 unsigned borderWidth = 0;
864
mitz@apple.com8010bba2010-11-05 02:43:17 +0000865 const BorderValue& sb = style()->borderEnd();
darin32011102006-05-15 04:42:09 +0000866 if (sb.style() == BHIDDEN)
867 return -1;
868 if (sb.style() > BHIDDEN)
hyatt@apple.come607db72010-04-09 20:21:55 +0000869 borderWidth = sb.width();
darin32011102006-05-15 04:42:09 +0000870
mitz@apple.com8010bba2010-11-05 02:43:17 +0000871 if (RenderTableCol* colGroup = table()->colElement(totalCols - 1)) {
872 const BorderValue& gb = colGroup->style()->borderEnd();
darin32011102006-05-15 04:42:09 +0000873 if (gb.style() == BHIDDEN)
874 return -1;
hyatt@apple.come607db72010-04-09 20:21:55 +0000875 if (gb.style() > BHIDDEN && gb.width() > borderWidth)
876 borderWidth = gb.width();
darin32011102006-05-15 04:42:09 +0000877 }
878
879 bool allHidden = true;
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000880 for (unsigned r = 0; r < m_grid.size(); r++) {
mitz@apple.com8010bba2010-11-05 02:43:17 +0000881 const CellStruct& current = cellAt(r, totalCols - 1);
jamesr@google.com36623a32010-07-23 20:22:29 +0000882 if (!current.hasCells())
darin32011102006-05-15 04:42:09 +0000883 continue;
884 // FIXME: Don't repeat for the same cell
mitz@apple.com8010bba2010-11-05 02:43:17 +0000885 const BorderValue& cb = current.primaryCell()->style()->borderEnd(); // FIXME: Make this work with perpendicular and flipped cells.
886 const BorderValue& rb = current.primaryCell()->parent()->style()->borderEnd();
darin32011102006-05-15 04:42:09 +0000887 if (cb.style() == BHIDDEN || rb.style() == BHIDDEN)
888 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000889 allHidden = false;
hyatt@apple.come607db72010-04-09 20:21:55 +0000890 if (cb.style() > BHIDDEN && cb.width() > borderWidth)
891 borderWidth = cb.width();
892 if (rb.style() > BHIDDEN && rb.width() > borderWidth)
893 borderWidth = rb.width();
darin32011102006-05-15 04:42:09 +0000894 }
895 if (allHidden)
896 return -1;
897
mitz@apple.com8010bba2010-11-05 02:43:17 +0000898 return (borderWidth + (table()->style()->isLeftToRightDirection() ? 1 : 0)) / 2;
darin32011102006-05-15 04:42:09 +0000899}
900
901void RenderTableSection::recalcOuterBorder()
902{
mitz@apple.com8010bba2010-11-05 02:43:17 +0000903 m_outerBorderBefore = calcOuterBorderBefore();
904 m_outerBorderAfter = calcOuterBorderAfter();
905 m_outerBorderStart = calcOuterBorderStart();
906 m_outerBorderEnd = calcOuterBorderEnd();
darin32011102006-05-15 04:42:09 +0000907}
908
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000909LayoutUnit RenderTableSection::firstLineBoxBaseline() const
mitz@apple.com57a2f482008-08-23 07:16:41 +0000910{
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000911 if (!m_grid.size())
mitz@apple.com57a2f482008-08-23 07:16:41 +0000912 return -1;
913
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000914 LayoutUnit firstLineBaseline = m_grid[0].baseline;
mitz@apple.com57a2f482008-08-23 07:16:41 +0000915 if (firstLineBaseline)
916 return firstLineBaseline + m_rowPos[0];
917
918 firstLineBaseline = -1;
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +0000919 const Row& firstRow = m_grid[0].row;
920 for (size_t i = 0; i < firstRow.size(); ++i) {
921 const CellStruct& cs = firstRow.at(i);
922 const RenderTableCell* cell = cs.primaryCell();
mitz@apple.com57a2f482008-08-23 07:16:41 +0000923 if (cell)
mitz@apple.com8010bba2010-11-05 02:43:17 +0000924 firstLineBaseline = max(firstLineBaseline, cell->logicalTop() + cell->paddingBefore() + cell->borderBefore() + cell->contentLogicalHeight());
mitz@apple.com57a2f482008-08-23 07:16:41 +0000925 }
926
927 return firstLineBaseline;
928}
darin32011102006-05-15 04:42:09 +0000929
leviw@chromium.orgb3757502011-06-29 21:33:11 +0000930void RenderTableSection::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
eseidela043f3d2006-01-20 19:24:53 +0000931{
anttib3666072007-08-17 23:29:50 +0000932 // put this back in when all layout tests can handle it
933 // ASSERT(!needsLayout());
934 // avoid crashing on bugs that cause us to paint with dirty layout
935 if (needsLayout())
936 return;
937
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000938 unsigned totalRows = m_grid.size();
ddkilzer260f3d22007-01-05 05:56:31 +0000939 unsigned totalCols = table()->columns().size();
eseidela043f3d2006-01-20 19:24:53 +0000940
ddkilzer260f3d22007-01-05 05:56:31 +0000941 if (!totalRows || !totalCols)
ap0e708ba2006-05-20 08:47:37 +0000942 return;
943
leviw@chromium.orgb3757502011-06-29 21:33:11 +0000944 LayoutPoint adjustedPaintOffset = paintOffset + location();
eseidela043f3d2006-01-20 19:24:53 +0000945
hyatt@apple.comfe52f5b2009-02-25 01:21:03 +0000946 PaintPhase phase = paintInfo.phase;
leviw@chromium.org61ca1372011-06-07 18:56:41 +0000947 bool pushedClip = pushContentsClip(paintInfo, adjustedPaintOffset);
948 paintObject(paintInfo, adjustedPaintOffset);
hyatt@apple.comfe52f5b2009-02-25 01:21:03 +0000949 if (pushedClip)
leviw@chromium.org61ca1372011-06-07 18:56:41 +0000950 popContentsClip(paintInfo, phase, adjustedPaintOffset);
hyatt@apple.comfe52f5b2009-02-25 01:21:03 +0000951}
952
jamesr@google.com36623a32010-07-23 20:22:29 +0000953static inline bool compareCellPositions(RenderTableCell* elem1, RenderTableCell* elem2)
954{
955 return elem1->row() < elem2->row();
956}
957
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +0000958// This comparison is used only when we have overflowing cells as we have an unsorted array to sort. We thus need
959// to sort both on rows and columns to properly repaint.
960static inline bool compareCellPositionsWithOverflowingCells(RenderTableCell* elem1, RenderTableCell* elem2)
961{
962 if (elem1->row() != elem2->row())
963 return elem1->row() < elem2->row();
964
965 return elem1->col() < elem2->col();
966}
967
leviw@chromium.org890e9b02011-07-07 23:17:55 +0000968void RenderTableSection::paintCell(RenderTableCell* cell, PaintInfo& paintInfo, const LayoutPoint& paintOffset)
jamesr@google.com36623a32010-07-23 20:22:29 +0000969{
ojan@chromium.org035c88ca2011-10-03 22:00:25 +0000970 LayoutPoint cellPoint = flipForWritingModeForChild(cell, paintOffset);
jamesr@google.com36623a32010-07-23 20:22:29 +0000971 PaintPhase paintPhase = paintInfo.phase;
972 RenderTableRow* row = toRenderTableRow(cell->parent());
973
974 if (paintPhase == PaintPhaseBlockBackground || paintPhase == PaintPhaseChildBlockBackground) {
975 // We need to handle painting a stack of backgrounds. This stack (from bottom to top) consists of
976 // the column group, column, row group, row, and then the cell.
977 RenderObject* col = table()->colElement(cell->col());
978 RenderObject* colGroup = 0;
979 if (col && col->parent()->style()->display() == TABLE_COLUMN_GROUP)
980 colGroup = col->parent();
981
982 // Column groups and columns first.
983 // FIXME: Columns and column groups do not currently support opacity, and they are being painted "too late" in
984 // the stack, since we have already opened a transparency layer (potentially) for the table row group.
985 // Note that we deliberately ignore whether or not the cell has a layer, since these backgrounds paint "behind" the
986 // cell.
leviw@chromium.org719a45b2011-06-03 20:59:40 +0000987 cell->paintBackgroundsBehindCell(paintInfo, cellPoint, colGroup);
988 cell->paintBackgroundsBehindCell(paintInfo, cellPoint, col);
jamesr@google.com36623a32010-07-23 20:22:29 +0000989
990 // Paint the row group next.
leviw@chromium.org719a45b2011-06-03 20:59:40 +0000991 cell->paintBackgroundsBehindCell(paintInfo, cellPoint, this);
jamesr@google.com36623a32010-07-23 20:22:29 +0000992
993 // Paint the row next, but only if it doesn't have a layer. If a row has a layer, it will be responsible for
994 // painting the row background for the cell.
995 if (!row->hasSelfPaintingLayer())
leviw@chromium.org719a45b2011-06-03 20:59:40 +0000996 cell->paintBackgroundsBehindCell(paintInfo, cellPoint, row);
jamesr@google.com36623a32010-07-23 20:22:29 +0000997 }
998 if ((!cell->hasSelfPaintingLayer() && !row->hasSelfPaintingLayer()) || paintInfo.phase == PaintPhaseCollapsedTableBorders)
leviw@chromium.org61ca1372011-06-07 18:56:41 +0000999 cell->paint(paintInfo, cellPoint);
jamesr@google.com36623a32010-07-23 20:22:29 +00001000}
1001
leviw@chromium.orgc4918082011-06-29 01:06:00 +00001002void RenderTableSection::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
hyatt@apple.comfe52f5b2009-02-25 01:21:03 +00001003{
ddkilzer260f3d22007-01-05 05:56:31 +00001004 // Check which rows and cols are visible and only paint these.
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +00001005 unsigned totalRows = m_grid.size();
hyatt@apple.comfe52f5b2009-02-25 01:21:03 +00001006 unsigned totalCols = table()->columns().size();
1007
weinig0a635f02006-11-01 21:49:13 +00001008 PaintPhase paintPhase = paintInfo.phase;
eseidela043f3d2006-01-20 19:24:53 +00001009
leviw@chromium.orgc4918082011-06-29 01:06:00 +00001010 LayoutUnit os = 2 * maximalOutlineSize(paintPhase);
ddkilzer260f3d22007-01-05 05:56:31 +00001011 unsigned startrow = 0;
1012 unsigned endrow = totalRows;
mitz@apple.com20e5bec2010-12-08 01:37:57 +00001013
leviw@chromium.orgc4918082011-06-29 01:06:00 +00001014 LayoutRect localRepaintRect = paintInfo.rect;
leviw@chromium.org43d0c4d2011-06-04 02:25:54 +00001015 localRepaintRect.moveBy(-paintOffset);
mitz@apple.com20e5bec2010-12-08 01:37:57 +00001016 if (style()->isFlippedBlocksWritingMode()) {
1017 if (style()->isHorizontalWritingMode())
hyatt@apple.comaa0cba02011-02-01 21:39:47 +00001018 localRepaintRect.setY(height() - localRepaintRect.maxY());
mitz@apple.com20e5bec2010-12-08 01:37:57 +00001019 else
hyatt@apple.comaa0cba02011-02-01 21:39:47 +00001020 localRepaintRect.setX(width() - localRepaintRect.maxX());
mitz@apple.com20e5bec2010-12-08 01:37:57 +00001021 }
1022
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001023 if (!m_forceSlowPaintPathWithOverflowingCell) {
leviw@chromium.orgc4918082011-06-29 01:06:00 +00001024 LayoutUnit before = (style()->isHorizontalWritingMode() ? localRepaintRect.y() : localRepaintRect.x()) - os;
jamesr@google.comf88b2582010-08-17 20:57:15 +00001025 // binary search to find a row
mitz@apple.com20e5bec2010-12-08 01:37:57 +00001026 startrow = std::lower_bound(m_rowPos.begin(), m_rowPos.end(), before) - m_rowPos.begin();
eseidela043f3d2006-01-20 19:24:53 +00001027
jamesr@google.comf88b2582010-08-17 20:57:15 +00001028 // The binary search above gives us the first row with
1029 // a y position >= the top of the paint rect. Thus, the previous
1030 // may need to be repainted as well.
mitz@apple.com20e5bec2010-12-08 01:37:57 +00001031 if (startrow == m_rowPos.size() || (startrow > 0 && (m_rowPos[startrow] > before)))
jamesr@google.comf88b2582010-08-17 20:57:15 +00001032 --startrow;
1033
leviw@chromium.orgc4918082011-06-29 01:06:00 +00001034 LayoutUnit after = (style()->isHorizontalWritingMode() ? localRepaintRect.maxY() : localRepaintRect.maxX()) + os;
mitz@apple.com20e5bec2010-12-08 01:37:57 +00001035 endrow = std::lower_bound(m_rowPos.begin(), m_rowPos.end(), after) - m_rowPos.begin();
fsamuel@chromium.org179df3b2010-10-05 23:55:13 +00001036 if (endrow == m_rowPos.size())
jamesr@google.comf88b2582010-08-17 20:57:15 +00001037 --endrow;
1038
mitz@apple.com20e5bec2010-12-08 01:37:57 +00001039 if (!endrow && m_rowPos[0] - table()->outerBorderBefore() <= after)
jamesr@google.comf88b2582010-08-17 20:57:15 +00001040 ++endrow;
weinig0a635f02006-11-01 21:49:13 +00001041 }
mitz@apple.com20e5bec2010-12-08 01:37:57 +00001042
ddkilzer260f3d22007-01-05 05:56:31 +00001043 unsigned startcol = 0;
1044 unsigned endcol = totalCols;
adeleddfe27f2007-01-05 23:03:50 +00001045 // FIXME: Implement RTL.
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001046 if (!m_forceSlowPaintPathWithOverflowingCell && style()->isLeftToRightDirection()) {
leviw@chromium.orgc4918082011-06-29 01:06:00 +00001047 LayoutUnit start = (style()->isHorizontalWritingMode() ? localRepaintRect.x() : localRepaintRect.y()) - os;
leviw@chromium.org7353dfd2011-08-12 21:01:45 +00001048 Vector<LayoutUnit>& columnPos = table()->columnPositions();
mitz@apple.com20e5bec2010-12-08 01:37:57 +00001049 startcol = std::lower_bound(columnPos.begin(), columnPos.end(), start) - columnPos.begin();
1050 if ((startcol == columnPos.size()) || (startcol > 0 && (columnPos[startcol] > start)))
jamesr@google.comf88b2582010-08-17 20:57:15 +00001051 --startcol;
weinig0a635f02006-11-01 21:49:13 +00001052
leviw@chromium.orgc4918082011-06-29 01:06:00 +00001053 LayoutUnit end = (style()->isHorizontalWritingMode() ? localRepaintRect.maxX() : localRepaintRect.maxY()) + os;
mitz@apple.com20e5bec2010-12-08 01:37:57 +00001054 endcol = std::lower_bound(columnPos.begin(), columnPos.end(), end) - columnPos.begin();
fsamuel@chromium.org179df3b2010-10-05 23:55:13 +00001055 if (endcol == columnPos.size())
jamesr@google.comf88b2582010-08-17 20:57:15 +00001056 --endcol;
1057
mitz@apple.com20e5bec2010-12-08 01:37:57 +00001058 if (!endcol && columnPos[0] - table()->outerBorderStart() <= end)
jamesr@google.comf88b2582010-08-17 20:57:15 +00001059 ++endcol;
eseidela043f3d2006-01-20 19:24:53 +00001060 }
eseidela043f3d2006-01-20 19:24:53 +00001061 if (startcol < endcol) {
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001062 if (!m_hasMultipleCellLevels && !m_overflowingCells.size()) {
jamesr@google.com36623a32010-07-23 20:22:29 +00001063 // Draw the dirty cells in the order that they appear.
1064 for (unsigned r = startrow; r < endrow; r++) {
1065 for (unsigned c = startcol; c < endcol; c++) {
1066 CellStruct& current = cellAt(r, c);
1067 RenderTableCell* cell = current.primaryCell();
jamesr@google.comb4266232010-07-28 20:07:19 +00001068 if (!cell || (r > startrow && primaryCellAt(r - 1, c) == cell) || (c > startcol && primaryCellAt(r, c - 1) == cell))
jamesr@google.com36623a32010-07-23 20:22:29 +00001069 continue;
leviw@chromium.org43d0c4d2011-06-04 02:25:54 +00001070 paintCell(cell, paintInfo, paintOffset);
hyatte031dd02006-03-18 01:01:06 +00001071 }
ap50b58352006-01-22 20:32:36 +00001072 }
jamesr@google.com36623a32010-07-23 20:22:29 +00001073 } else {
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001074 // The overflowing cells should be scarce to avoid adding a lot of cells to the HashSet.
1075 ASSERT(m_overflowingCells.size() < totalRows * totalCols * gMaxAllowedOverflowingCellRatioForFastPaintPath);
1076
1077 // To make sure we properly repaint the section, we repaint all the overflowing cells that we collected.
jamesr@google.com36623a32010-07-23 20:22:29 +00001078 Vector<RenderTableCell*> cells;
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001079 copyToVector(m_overflowingCells, cells);
1080
jamesr@google.com36623a32010-07-23 20:22:29 +00001081 HashSet<RenderTableCell*> spanningCells;
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001082
jamesr@google.com36623a32010-07-23 20:22:29 +00001083 for (unsigned r = startrow; r < endrow; r++) {
1084 for (unsigned c = startcol; c < endcol; c++) {
1085 CellStruct& current = cellAt(r, c);
jamesr@google.comb4266232010-07-28 20:07:19 +00001086 if (!current.hasCells())
jamesr@google.com36623a32010-07-23 20:22:29 +00001087 continue;
1088 for (unsigned i = 0; i < current.cells.size(); ++i) {
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001089 if (m_overflowingCells.contains(current.cells[i]))
1090 continue;
1091
jamesr@google.com36623a32010-07-23 20:22:29 +00001092 if (current.cells[i]->rowSpan() > 1 || current.cells[i]->colSpan() > 1) {
1093 if (spanningCells.contains(current.cells[i]))
1094 continue;
1095 spanningCells.add(current.cells[i]);
1096 }
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001097
jamesr@google.com36623a32010-07-23 20:22:29 +00001098 cells.append(current.cells[i]);
1099 }
1100 }
1101 }
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001102
jamesr@google.com36623a32010-07-23 20:22:29 +00001103 // Sort the dirty cells by paint order.
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001104 if (!m_overflowingCells.size())
1105 std::stable_sort(cells.begin(), cells.end(), compareCellPositions);
1106 else
1107 std::sort(cells.begin(), cells.end(), compareCellPositionsWithOverflowingCells);
1108
jamesr@google.com36623a32010-07-23 20:22:29 +00001109 int size = cells.size();
1110 // Paint the cells.
1111 for (int i = 0; i < size; ++i)
leviw@chromium.org43d0c4d2011-06-04 02:25:54 +00001112 paintCell(cells[i], paintInfo, paintOffset);
ap50b58352006-01-22 20:32:36 +00001113 }
eseidela043f3d2006-01-20 19:24:53 +00001114 }
1115}
1116
darin@apple.com98a7ac62009-01-05 17:26:53 +00001117void RenderTableSection::imageChanged(WrappedImagePtr, const IntRect*)
bdashb07ae8d2007-02-08 04:56:20 +00001118{
bdashb07ae8d2007-02-08 04:56:20 +00001119 // FIXME: Examine cells and repaint only the rect the image paints in.
1120 repaint();
1121}
1122
eseidela043f3d2006-01-20 19:24:53 +00001123void RenderTableSection::recalcCells()
1124{
jchaffraix@webkit.orgd01277d2011-11-09 19:57:16 +00001125 ASSERT(m_needsCellRecalc);
1126 // We reset the flag here to ensure that |addCell| works. This is safe to do as
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +00001127 // we clear the grid and properly rebuild it during |addCell|.
jchaffraix@webkit.orgd01277d2011-11-09 19:57:16 +00001128 m_needsCellRecalc = false;
1129
ddkilzer260f3d22007-01-05 05:56:31 +00001130 m_cCol = 0;
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +00001131 m_cRow = 0;
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +00001132 m_grid.clear();
eseidela043f3d2006-01-20 19:24:53 +00001133
ddkilzer260f3d22007-01-05 05:56:31 +00001134 for (RenderObject* row = firstChild(); row; row = row->nextSibling()) {
hyattd866e592006-03-17 09:50:35 +00001135 if (row->isTableRow()) {
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +00001136 unsigned insertionRow = m_cRow;
ddkilzer260f3d22007-01-05 05:56:31 +00001137 m_cRow++;
1138 m_cCol = 0;
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +00001139 ensureRows(m_cRow);
1140
darin@apple.com445c34f2009-08-01 00:40:58 +00001141 RenderTableRow* tableRow = toRenderTableRow(row);
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +00001142 m_grid[insertionRow].rowRenderer = tableRow;
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +00001143 setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[insertionRow]);
eseidel05ef0432006-05-25 22:11:36 +00001144
ddkilzer260f3d22007-01-05 05:56:31 +00001145 for (RenderObject* cell = row->firstChild(); cell; cell = cell->nextSibling()) {
jchaffraix@webkit.orgddeb7db2011-11-01 18:02:42 +00001146 if (!cell->isTableCell())
1147 continue;
1148
1149 RenderTableCell* tableCell = toRenderTableCell(cell);
jchaffraix@webkit.orgddeb7db2011-11-01 18:02:42 +00001150 addCell(tableCell, tableRow);
ddkilzer260f3d22007-01-05 05:56:31 +00001151 }
hyattd866e592006-03-17 09:50:35 +00001152 }
eseidela043f3d2006-01-20 19:24:53 +00001153 }
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +00001154
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +00001155 m_grid.shrinkToFit();
eseidela043f3d2006-01-20 19:24:53 +00001156 setNeedsLayout(true);
1157}
1158
jchaffraix@webkit.org19bbb722011-11-03 17:20:01 +00001159void RenderTableSection::rowLogicalHeightChanged(unsigned rowIndex)
1160{
1161 setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[rowIndex]);
1162}
1163
jamesr@google.com5ddfb042011-01-20 21:34:34 +00001164void RenderTableSection::setNeedsCellRecalc()
1165{
1166 m_needsCellRecalc = true;
1167 if (RenderTable* t = table())
1168 t->setNeedsSectionRecalc();
1169}
1170
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +00001171unsigned RenderTableSection::numColumns() const
ap50b58352006-01-22 20:32:36 +00001172{
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +00001173 unsigned result = 0;
ap50b58352006-01-22 20:32:36 +00001174
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +00001175 for (unsigned r = 0; r < m_grid.size(); ++r) {
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +00001176 for (unsigned c = result; c < table()->numEffCols(); ++c) {
ap50b58352006-01-22 20:32:36 +00001177 const CellStruct& cell = cellAt(r, c);
jamesr@google.com36623a32010-07-23 20:22:29 +00001178 if (cell.hasCells() || cell.inColSpan)
ap50b58352006-01-22 20:32:36 +00001179 result = c;
1180 }
1181 }
1182
1183 return result + 1;
eseidela043f3d2006-01-20 19:24:53 +00001184}
1185
ddkilzer260f3d22007-01-05 05:56:31 +00001186void RenderTableSection::appendColumn(int pos)
1187{
jchaffraix@webkit.orgd01277d2011-11-09 19:57:16 +00001188 ASSERT(!m_needsCellRecalc);
1189
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +00001190 for (unsigned row = 0; row < m_grid.size(); ++row)
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +00001191 m_grid[row].row.resize(pos + 1);
ddkilzer260f3d22007-01-05 05:56:31 +00001192}
1193
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +00001194void RenderTableSection::splitColumn(unsigned pos, int first)
ddkilzer260f3d22007-01-05 05:56:31 +00001195{
inferno@chromium.orgb1ffad72011-10-10 18:58:12 +00001196 ASSERT(!m_needsCellRecalc);
1197
ddkilzer260f3d22007-01-05 05:56:31 +00001198 if (m_cCol > pos)
1199 m_cCol++;
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +00001200 for (unsigned row = 0; row < m_grid.size(); ++row) {
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +00001201 Row& r = m_grid[row].row;
jamesr@google.com36623a32010-07-23 20:22:29 +00001202 r.insert(pos + 1, CellStruct());
1203 if (r[pos].hasCells()) {
1204 r[pos + 1].cells.append(r[pos].cells);
1205 RenderTableCell* cell = r[pos].primaryCell();
1206 ASSERT(cell);
1207 int colleft = cell->colSpan() - r[pos].inColSpan;
1208 if (first > colleft)
1209 r[pos + 1].inColSpan = 0;
1210 else
1211 r[pos + 1].inColSpan = first + r[pos].inColSpan;
1212 } else {
1213 r[pos + 1].inColSpan = 0;
1214 }
ddkilzer260f3d22007-01-05 05:56:31 +00001215 }
1216}
1217
hyattd866e592006-03-17 09:50:35 +00001218// Hit Testing
eae@chromium.orge14cd1a2011-07-06 23:38:32 +00001219bool RenderTableSection::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action)
hyattd866e592006-03-17 09:50:35 +00001220{
jamesr@google.comf88b2582010-08-17 20:57:15 +00001221 // If we have no children then we have nothing to do.
1222 if (!firstChild())
1223 return false;
1224
hyattd866e592006-03-17 09:50:35 +00001225 // Table sections cannot ever be hit tested. Effectively they do not exist.
1226 // Just forward to our children always.
eae@chromium.orge14cd1a2011-07-06 23:38:32 +00001227 LayoutPoint adjustedLocation = accumulatedOffset + location();
hyattd866e592006-03-17 09:50:35 +00001228
hyatt@apple.comd4d3bcf2011-10-04 18:17:04 +00001229 if (hasOverflowClip() && !overflowClipRect(adjustedLocation, result.region()).intersects(result.rectForPoint(pointInContainer)))
hyatt@apple.comfe52f5b2009-02-25 01:21:03 +00001230 return false;
1231
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001232 if (hasOverflowingCell()) {
jamesr@google.comf88b2582010-08-17 20:57:15 +00001233 for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
1234 // FIXME: We have to skip over inline flows, since they can show up inside table rows
1235 // at the moment (a demoted inline <form> for example). If we ever implement a
1236 // table-specific hit-test method (which we should do for performance reasons anyway),
1237 // then we can remove this check.
mitz@apple.com39fb3ae2010-11-09 20:46:15 +00001238 if (child->isBox() && !toRenderBox(child)->hasSelfPaintingLayer()) {
ojan@chromium.org035c88ca2011-10-03 22:00:25 +00001239 LayoutPoint childPoint = flipForWritingModeForChild(toRenderBox(child), adjustedLocation);
eae@chromium.orgf9ce2672011-06-08 03:12:08 +00001240 if (child->nodeAtPoint(request, result, pointInContainer, childPoint, action)) {
eae@chromium.orge14cd1a2011-07-06 23:38:32 +00001241 updateHitTestResult(result, toLayoutPoint(pointInContainer - childPoint));
mitz@apple.com39fb3ae2010-11-09 20:46:15 +00001242 return true;
1243 }
jamesr@google.comf88b2582010-08-17 20:57:15 +00001244 }
1245 }
1246 return false;
1247 }
1248
eae@chromium.orge14cd1a2011-07-06 23:38:32 +00001249 LayoutPoint location = pointInContainer - toLayoutSize(adjustedLocation);
mitz@apple.com39fb3ae2010-11-09 20:46:15 +00001250 if (style()->isFlippedBlocksWritingMode()) {
1251 if (style()->isHorizontalWritingMode())
1252 location.setY(height() - location.y());
1253 else
1254 location.setX(width() - location.x());
1255 }
1256
eae@chromium.orge14cd1a2011-07-06 23:38:32 +00001257 LayoutUnit offsetInColumnDirection = style()->isHorizontalWritingMode() ? location.y() : location.x();
mitz@apple.com39fb3ae2010-11-09 20:46:15 +00001258 // Find the first row that starts after offsetInColumnDirection.
1259 unsigned nextRow = std::upper_bound(m_rowPos.begin(), m_rowPos.end(), offsetInColumnDirection) - m_rowPos.begin();
1260 if (nextRow == m_rowPos.size())
jamesr@google.comf88b2582010-08-17 20:57:15 +00001261 return false;
mitz@apple.com39fb3ae2010-11-09 20:46:15 +00001262 // Now set hitRow to the index of the hit row, or 0.
1263 unsigned hitRow = nextRow > 0 ? nextRow - 1 : 0;
jamesr@google.comf88b2582010-08-17 20:57:15 +00001264
eae@chromium.orge14cd1a2011-07-06 23:38:32 +00001265 Vector<LayoutUnit>& columnPos = table()->columnPositions();
leviw@chromium.org7353dfd2011-08-12 21:01:45 +00001266 LayoutUnit offsetInRowDirection = style()->isHorizontalWritingMode() ? location.x() : location.y();
mitz@apple.com39fb3ae2010-11-09 20:46:15 +00001267 if (!style()->isLeftToRightDirection())
1268 offsetInRowDirection = columnPos[columnPos.size() - 1] - offsetInRowDirection;
jamesr@google.comf88b2582010-08-17 20:57:15 +00001269
mitz@apple.com39fb3ae2010-11-09 20:46:15 +00001270 unsigned nextColumn = std::lower_bound(columnPos.begin(), columnPos.end(), offsetInRowDirection) - columnPos.begin();
1271 if (nextColumn == columnPos.size())
jamesr@google.comf88b2582010-08-17 20:57:15 +00001272 return false;
mitz@apple.com39fb3ae2010-11-09 20:46:15 +00001273 unsigned hitColumn = nextColumn > 0 ? nextColumn - 1 : 0;
jamesr@google.comf88b2582010-08-17 20:57:15 +00001274
mitz@apple.com39fb3ae2010-11-09 20:46:15 +00001275 CellStruct& current = cellAt(hitRow, hitColumn);
jamesr@google.comf88b2582010-08-17 20:57:15 +00001276
1277 // If the cell is empty, there's nothing to do
1278 if (!current.hasCells())
1279 return false;
1280
1281 for (int i = current.cells.size() - 1; i >= 0; --i) {
1282 RenderTableCell* cell = current.cells[i];
ojan@chromium.org035c88ca2011-10-03 22:00:25 +00001283 LayoutPoint cellPoint = flipForWritingModeForChild(cell, adjustedLocation);
eae@chromium.orgf9ce2672011-06-08 03:12:08 +00001284 if (static_cast<RenderObject*>(cell)->nodeAtPoint(request, result, pointInContainer, cellPoint, action)) {
eae@chromium.orge14cd1a2011-07-06 23:38:32 +00001285 updateHitTestResult(result, toLayoutPoint(pointInContainer - cellPoint));
hyattd866e592006-03-17 09:50:35 +00001286 return true;
1287 }
1288 }
hyattd866e592006-03-17 09:50:35 +00001289 return false;
jamesr@google.comf88b2582010-08-17 20:57:15 +00001290
hyattd866e592006-03-17 09:50:35 +00001291}
1292
jchaffraix@webkit.org19bbb722011-11-03 17:20:01 +00001293unsigned RenderTableSection::rowIndexForRenderer(const RenderTableRow* row) const
1294{
1295 for (size_t i = 0; i < m_grid.size(); ++i) {
1296 if (m_grid[i].rowRenderer == row)
1297 return i;
1298 }
1299 ASSERT_NOT_REACHED();
1300 return 0;
1301}
1302
ddkilzer260f3d22007-01-05 05:56:31 +00001303} // namespace WebCore