blob: 39f594c84b248d25a10a69899f452648ead29b59 [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"
darinb9481ed2006-03-20 02:57:59 +000028#include "Document.h"
tonikitoo@webkit.org81c027d2010-07-29 13:19:43 +000029#include "HitTestResult.h"
darin98fa8b82006-03-20 08:03:57 +000030#include "HTMLNames.h"
tonyg@chromium.orgb138b1e2011-01-15 00:27:07 +000031#include "PaintInfo.h"
darin91298e52006-06-12 01:10:17 +000032#include "RenderTableCell.h"
33#include "RenderTableCol.h"
34#include "RenderTableRow.h"
weinigfef13632007-04-29 20:09:08 +000035#include "RenderView.h"
commit-queue@webkit.orgd0c076d2012-08-22 22:25:59 +000036#include "StyleInheritedData.h"
darin91298e52006-06-12 01:10:17 +000037#include <limits>
jamesr@google.com36623a32010-07-23 20:22:29 +000038#include <wtf/HashSet.h>
andersca@apple.coma5fb7da2013-04-16 19:57:36 +000039#include <wtf/StackStats.h>
eseidela043f3d2006-01-20 19:24:53 +000040
41namespace WebCore {
42
43using namespace HTMLNames;
44
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +000045// Those 2 variables are used to balance the memory consumption vs the repaint time on big tables.
46static unsigned gMinTableSizeToUseFastPaintPathWithOverflowingCell = 75 * 75;
47static float gMaxAllowedOverflowingCellRatioForFastPaintPath = 0.1f;
48
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +000049static inline void setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(RenderTableSection::RowStruct& row)
dbates@webkit.orge1131832009-11-19 00:05:57 +000050{
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +000051 ASSERT(row.rowRenderer);
akling@apple.com827be9c2013-10-29 02:58:43 +000052 row.logicalHeight = row.rowRenderer->style().logicalHeight();
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +000053 if (row.logicalHeight.isRelative())
54 row.logicalHeight = Length();
dbates@webkit.orge1131832009-11-19 00:05:57 +000055}
56
jchaffraix@webkit.org74857b42011-12-20 14:08:52 +000057static inline void updateLogicalHeightForCell(RenderTableSection::RowStruct& row, const RenderTableCell* cell)
58{
59 // We ignore height settings on rowspan cells.
60 if (cell->rowSpan() != 1)
61 return;
62
akling@apple.com827be9c2013-10-29 02:58:43 +000063 Length logicalHeight = cell->style().logicalHeight();
jchaffraix@webkit.org74857b42011-12-20 14:08:52 +000064 if (logicalHeight.isPositive() || (logicalHeight.isRelative() && logicalHeight.value() >= 0)) {
65 Length cRowLogicalHeight = row.logicalHeight;
66 switch (logicalHeight.type()) {
67 case Percent:
68 if (!(cRowLogicalHeight.isPercent())
69 || (cRowLogicalHeight.isPercent() && cRowLogicalHeight.percent() < logicalHeight.percent()))
70 row.logicalHeight = logicalHeight;
71 break;
72 case Fixed:
73 if (cRowLogicalHeight.type() < Percent
74 || (cRowLogicalHeight.isFixed() && cRowLogicalHeight.value() < logicalHeight.value()))
75 row.logicalHeight = logicalHeight;
76 break;
77 case Relative:
78 default:
79 break;
80 }
81 }
82}
83
akling@apple.com8f40c5b2013-10-27 22:54:07 +000084RenderTableSection::RenderTableSection(Element& element, PassRef<RenderStyle> style)
85 : RenderBox(element, std::move(style), 0)
ddkilzer260f3d22007-01-05 05:56:31 +000086 , m_cCol(0)
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +000087 , m_cRow(0)
mitz@apple.com8010bba2010-11-05 02:43:17 +000088 , m_outerBorderStart(0)
89 , m_outerBorderEnd(0)
90 , m_outerBorderBefore(0)
91 , m_outerBorderAfter(0)
simon.fraser@apple.com85362502009-05-08 01:23:32 +000092 , m_needsCellRecalc(false)
jamesr@google.com36623a32010-07-23 20:22:29 +000093 , m_hasMultipleCellLevels(false)
eseidela043f3d2006-01-20 19:24:53 +000094{
akling@apple.com42e10632013-10-14 17:55:52 +000095 setInline(false);
96}
97
akling@apple.com8f40c5b2013-10-27 22:54:07 +000098RenderTableSection::RenderTableSection(Document& document, PassRef<RenderStyle> style)
99 : RenderBox(document, std::move(style), 0)
akling@apple.com42e10632013-10-14 17:55:52 +0000100 , m_cCol(0)
101 , m_cRow(0)
102 , m_outerBorderStart(0)
103 , m_outerBorderEnd(0)
104 , m_outerBorderBefore(0)
105 , m_outerBorderAfter(0)
106 , m_needsCellRecalc(false)
107 , m_hasMultipleCellLevels(false)
108{
109 setInline(false);
eseidela043f3d2006-01-20 19:24:53 +0000110}
111
112RenderTableSection::~RenderTableSection()
113{
eseidela043f3d2006-01-20 19:24:53 +0000114}
115
inferno@chromium.orga7f719f2011-09-06 01:45:39 +0000116void RenderTableSection::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
117{
118 RenderBox::styleDidChange(diff, oldStyle);
antti@apple.comcf4adae2013-09-24 00:55:44 +0000119 propagateStyleToAnonymousChildren(PropagateToAllChildren);
jchaffraix@webkit.org38e74af2011-09-23 19:56:21 +0000120
121 // If border was changed, notify table.
122 RenderTable* table = this->table();
akling@apple.com827be9c2013-10-29 02:58:43 +0000123 if (table && !table->selfNeedsLayout() && !table->normalChildNeedsLayout() && oldStyle && oldStyle->border() != style().border())
jchaffraix@webkit.org38e74af2011-09-23 19:56:21 +0000124 table->invalidateCollapsedBorders();
inferno@chromium.orga7f719f2011-09-06 01:45:39 +0000125}
126
jchaffraix@webkit.org54b0e092012-08-22 02:16:02 +0000127void RenderTableSection::willBeRemovedFromTree()
eseidela043f3d2006-01-20 19:24:53 +0000128{
jchaffraix@webkit.org54b0e092012-08-22 02:16:02 +0000129 RenderBox::willBeRemovedFromTree();
130
131 // Preventively invalidate our cells as we may be re-inserted into
132 // a new table which would require us to rebuild our structure.
133 setNeedsCellRecalc();
eseidela043f3d2006-01-20 19:24:53 +0000134}
135
darin316ed062006-01-23 05:29:14 +0000136void RenderTableSection::addChild(RenderObject* child, RenderObject* beforeChild)
eseidela043f3d2006-01-20 19:24:53 +0000137{
eseidela043f3d2006-01-20 19:24:53 +0000138 if (!child->isTableRow()) {
darin316ed062006-01-23 05:29:14 +0000139 RenderObject* last = beforeChild;
140 if (!last)
antti@apple.com7f9196b2013-09-24 20:47:01 +0000141 last = lastRow();
inferno@chromium.orga7f719f2011-09-06 01:45:39 +0000142 if (last && last->isAnonymous() && !last->isBeforeOrAfterContent()) {
antti@apple.comdc54c7e2013-09-23 19:32:15 +0000143 RenderTableRow* row = toRenderTableRow(last);
144 if (beforeChild == row)
antti@apple.com7f9196b2013-09-24 20:47:01 +0000145 beforeChild = row->firstCell();
antti@apple.comdc54c7e2013-09-23 19:32:15 +0000146 row->addChild(child, beforeChild);
darin316ed062006-01-23 05:29:14 +0000147 return;
148 }
149
inferno@chromium.orgb1ffad72011-10-10 18:58:12 +0000150 if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == this) {
151 RenderObject* row = beforeChild->previousSibling();
fsamuel@chromium.orgfc34e992011-10-25 19:10:58 +0000152 if (row && row->isTableRow() && row->isAnonymous()) {
antti@apple.com43afcf72013-09-20 11:44:17 +0000153 toRenderTableRow(row)->addChild(child);
inferno@chromium.orgb1ffad72011-10-10 18:58:12 +0000154 return;
155 }
156 }
157
darin10ab1352006-01-29 01:29:33 +0000158 // If beforeChild is inside an anonymous cell/row, insert into the cell or into
159 // the anonymous row containing it, if there is one.
darin316ed062006-01-23 05:29:14 +0000160 RenderObject* lastBox = last;
161 while (lastBox && lastBox->parent()->isAnonymous() && !lastBox->isTableRow())
162 lastBox = lastBox->parent();
inferno@chromium.orga7f719f2011-09-06 01:45:39 +0000163 if (lastBox && lastBox->isAnonymous() && !lastBox->isBeforeOrAfterContent()) {
antti@apple.com43afcf72013-09-20 11:44:17 +0000164 toRenderTableRow(lastBox)->addChild(child, beforeChild);
darin316ed062006-01-23 05:29:14 +0000165 return;
166 }
167
antti@apple.com43afcf72013-09-20 11:44:17 +0000168 RenderTableRow* row = RenderTableRow::createAnonymousWithParentRenderer(this);
darin316ed062006-01-23 05:29:14 +0000169 addChild(row, beforeChild);
eseidela043f3d2006-01-20 19:24:53 +0000170 row->addChild(child);
eseidela043f3d2006-01-20 19:24:53 +0000171 return;
172 }
173
174 if (beforeChild)
ddkilzer260f3d22007-01-05 05:56:31 +0000175 setNeedsCellRecalc();
eseidela043f3d2006-01-20 19:24:53 +0000176
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000177 unsigned insertionRow = m_cRow;
ddkilzer260f3d22007-01-05 05:56:31 +0000178 ++m_cRow;
179 m_cCol = 0;
eseidela043f3d2006-01-20 19:24:53 +0000180
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +0000181 ensureRows(m_cRow);
larsb5288ad2007-01-13 18:48:29 +0000182
jchaffraix@webkit.orga0177fd2012-05-01 03:13:06 +0000183 RenderTableRow* row = toRenderTableRow(child);
184 m_grid[insertionRow].rowRenderer = row;
185 row->setRowIndex(insertionRow);
eseidela043f3d2006-01-20 19:24:53 +0000186
dbates@webkit.orge1131832009-11-19 00:05:57 +0000187 if (!beforeChild)
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +0000188 setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[insertionRow]);
eseidela043f3d2006-01-20 19:24:53 +0000189
inferno@chromium.orga8d71922012-04-09 16:03:46 +0000190 if (beforeChild && beforeChild->parent() != this)
191 beforeChild = splitAnonymousBoxesAroundChild(beforeChild);
mjs6666eee72006-07-14 07:45:13 +0000192
bdakin@apple.com40ae9be2009-04-16 20:48:19 +0000193 ASSERT(!beforeChild || beforeChild->isTableRow());
hyatt@apple.comf073d9b2009-02-05 00:53:38 +0000194 RenderBox::addChild(child, beforeChild);
eseidela043f3d2006-01-20 19:24:53 +0000195}
196
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +0000197void RenderTableSection::ensureRows(unsigned numRows)
eseidela043f3d2006-01-20 19:24:53 +0000198{
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +0000199 if (numRows <= m_grid.size())
200 return;
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000201
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +0000202 unsigned oldSize = m_grid.size();
203 m_grid.grow(numRows);
eseidela043f3d2006-01-20 19:24:53 +0000204
andersca@apple.com86298632013-11-10 19:32:33 +0000205 unsigned effectiveColumnCount = std::max(1u, table()->numEffCols());
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +0000206 for (unsigned row = oldSize; row < m_grid.size(); ++row)
akling@apple.com194ce1d2013-11-13 11:46:51 +0000207 m_grid[row].row.resizeToFit(effectiveColumnCount);
eseidela043f3d2006-01-20 19:24:53 +0000208}
209
hyatt@apple.comd885df72009-01-22 02:31:52 +0000210void RenderTableSection::addCell(RenderTableCell* cell, RenderTableRow* row)
eseidela043f3d2006-01-20 19:24:53 +0000211{
jchaffraix@webkit.orgb86b64e2011-11-14 21:21:43 +0000212 // We don't insert the cell if we need cell recalc as our internal columns' representation
213 // will have drifted from the table's representation. Also recalcCells will call addCell
214 // at a later time after sync'ing our columns' with the table's.
215 if (needsCellRecalc())
216 return;
217
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000218 unsigned rSpan = cell->rowSpan();
219 unsigned cSpan = cell->colSpan();
jchaffraix@webkit.orgb87ce752012-10-15 21:52:22 +0000220 const Vector<RenderTable::ColumnStruct>& columns = table()->columns();
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000221 unsigned nCols = columns.size();
jchaffraix@webkit.orga0177fd2012-05-01 03:13:06 +0000222 unsigned insertionRow = row->rowIndex();
eseidela043f3d2006-01-20 19:24:53 +0000223
224 // ### mozilla still seems to do the old HTML way, even for strict DTD
225 // (see the annotation on table cell layouting in the CSS specs and the testcase below:
226 // <TABLE border>
227 // <TR><TD>1 <TD rowspan="2">2 <TD>3 <TD>4
228 // <TR><TD colspan="2">5
229 // </TABLE>
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000230 while (m_cCol < nCols && (cellAt(insertionRow, m_cCol).hasCells() || cellAt(insertionRow, m_cCol).inColSpan))
ddkilzer260f3d22007-01-05 05:56:31 +0000231 m_cCol++;
jamesr@google.comb4266232010-07-28 20:07:19 +0000232
jchaffraix@webkit.org74857b42011-12-20 14:08:52 +0000233 updateLogicalHeightForCell(m_grid[insertionRow], cell);
eseidela043f3d2006-01-20 19:24:53 +0000234
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +0000235 ensureRows(insertionRow + rSpan);
eseidela043f3d2006-01-20 19:24:53 +0000236
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000237 m_grid[insertionRow].rowRenderer = row;
hyattd866e592006-03-17 09:50:35 +0000238
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000239 unsigned col = m_cCol;
eseidela043f3d2006-01-20 19:24:53 +0000240 // tell the cell where it is
jamesr@google.com36623a32010-07-23 20:22:29 +0000241 bool inColSpan = false;
eseidela043f3d2006-01-20 19:24:53 +0000242 while (cSpan) {
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000243 unsigned currentSpan;
jamesr@google.comb4266232010-07-28 20:07:19 +0000244 if (m_cCol >= nCols) {
245 table()->appendColumn(cSpan);
246 currentSpan = cSpan;
247 } else {
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000248 if (cSpan < columns[m_cCol].span)
jamesr@google.comb4266232010-07-28 20:07:19 +0000249 table()->splitColumn(m_cCol, cSpan);
250 currentSpan = columns[m_cCol].span;
251 }
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000252 for (unsigned r = 0; r < rSpan; r++) {
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000253 CellStruct& c = cellAt(insertionRow + r, m_cCol);
jamesr@google.comb4266232010-07-28 20:07:19 +0000254 ASSERT(cell);
255 c.cells.append(cell);
256 // If cells overlap then we take the slow path for painting.
257 if (c.cells.size() > 1)
258 m_hasMultipleCellLevels = true;
259 if (inColSpan)
260 c.inColSpan = true;
261 }
262 m_cCol++;
263 cSpan -= currentSpan;
264 inColSpan = true;
eseidela043f3d2006-01-20 19:24:53 +0000265 }
eric@webkit.org5832ab72009-03-25 22:15:03 +0000266 cell->setCol(table()->effColToCol(col));
eseidela043f3d2006-01-20 19:24:53 +0000267}
268
eae@chromium.org351bc642012-02-08 05:37:54 +0000269int RenderTableSection::calcRowLogicalHeight()
eseidela043f3d2006-01-20 19:24:53 +0000270{
hyatt@apple.comc93db9b2009-02-04 22:29:04 +0000271#ifndef NDEBUG
ojan@chromium.orgccdc4292013-02-07 00:55:10 +0000272 SetLayoutNeededForbiddenScope layoutForbiddenScope(this);
hyatt@apple.comc93db9b2009-02-04 22:29:04 +0000273#endif
274
275 ASSERT(!needsLayout());
276
ddkilzer260f3d22007-01-05 05:56:31 +0000277 RenderTableCell* cell;
eseidela043f3d2006-01-20 19:24:53 +0000278
ossy@webkit.orgcf6bebb2013-11-25 14:57:38 +0000279 // We ignore the border-spacing on any non-top section as it is already included in the previous section's last row position.
280 int spacing = 0;
281 if (this == table()->topSection())
282 spacing = table()->vBorderSpacing();
akling@apple.com691cf5c2013-08-24 16:33:15 +0000283
weinig@apple.comf8d77f32013-11-18 01:12:17 +0000284 LayoutStateMaintainer statePusher(view());
eseidela043f3d2006-01-20 19:24:53 +0000285
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000286 m_rowPos.resize(m_grid.size() + 1);
ddkilzer260f3d22007-01-05 05:56:31 +0000287 m_rowPos[0] = spacing;
eseidela043f3d2006-01-20 19:24:53 +0000288
commit-queue@webkit.org1fdc04c2013-04-23 06:36:45 +0000289 unsigned totalRows = m_grid.size();
290
291 for (unsigned r = 0; r < totalRows; r++) {
zimmermann@webkit.org14b310a2012-02-25 09:27:25 +0000292 m_grid[r].baseline = 0;
leviw@chromium.org2650e382012-04-04 10:37:36 +0000293 LayoutUnit baselineDescent = 0;
eseidela043f3d2006-01-20 19:24:53 +0000294
jchaffraix@webkit.orgaddd65e2012-02-26 00:19:22 +0000295 // Our base size is the biggest logical height from our cells' styles (excluding row spanning cells).
andersca@apple.com86298632013-11-10 19:32:33 +0000296 m_rowPos[r + 1] = std::max(m_rowPos[r] + minimumValueForLength(m_grid[r].logicalHeight, 0).round(), 0);
eseidela043f3d2006-01-20 19:24:53 +0000297
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +0000298 Row& row = m_grid[r].row;
299 unsigned totalCols = row.size();
eseidela043f3d2006-01-20 19:24:53 +0000300
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000301 for (unsigned c = 0; c < totalCols; c++) {
jamesr@google.com36623a32010-07-23 20:22:29 +0000302 CellStruct& current = cellAt(r, c);
commit-queue@webkit.org5ec57ca2012-07-12 22:33:36 +0000303 for (unsigned i = 0; i < current.cells.size(); i++) {
304 cell = current.cells[i];
305 if (current.inColSpan && cell->rowSpan() == 1)
306 continue;
jamesr@google.comb4266232010-07-28 20:07:19 +0000307
commit-queue@webkit.orgbb454812013-05-14 19:57:51 +0000308 // FIXME: We are always adding the height of a rowspan to the last rows which doesn't match
309 // other browsers. See webkit.org/b/52185 for example.
310 if ((cell->rowIndex() + cell->rowSpan() - 1) != r) {
311 // We will apply the height of the rowspan to the current row if next row is not valid.
312 if ((r + 1) < totalRows) {
313 unsigned col = 0;
314 CellStruct nextRowCell = cellAt(r + 1, col);
commit-queue@webkit.org1fdc04c2013-04-23 06:36:45 +0000315
commit-queue@webkit.orgbb454812013-05-14 19:57:51 +0000316 // We are trying to find that next row is valid or not.
317 while (nextRowCell.cells.size() && nextRowCell.cells[0]->rowSpan() > 1 && nextRowCell.cells[0]->rowIndex() < (r + 1)) {
318 col++;
319 if (col < totalCols)
320 nextRowCell = cellAt(r + 1, col);
321 else
322 break;
commit-queue@webkit.org1fdc04c2013-04-23 06:36:45 +0000323 }
commit-queue@webkit.orgbb454812013-05-14 19:57:51 +0000324
325 // We are adding the height of the rowspan to the current row if next row is not valid.
326 if (col < totalCols && nextRowCell.cells.size())
327 continue;
commit-queue@webkit.org1fdc04c2013-04-23 06:36:45 +0000328 }
329 }
jamesr@google.com36623a32010-07-23 20:22:29 +0000330
commit-queue@webkit.orgbb454812013-05-14 19:57:51 +0000331 // For row spanning cells, |r| is the last row in the span.
332 unsigned cellStartRow = cell->rowIndex();
333
commit-queue@webkit.org5ec57ca2012-07-12 22:33:36 +0000334 if (cell->hasOverrideHeight()) {
335 if (!statePusher.didPush()) {
336 // Technically, we should also push state for the row, but since
337 // rows don't push a coordinate transform, that's not necessary.
weinig@apple.comf8d77f32013-11-18 01:12:17 +0000338 statePusher.push(*this, locationOffset());
commit-queue@webkit.org5ec57ca2012-07-12 22:33:36 +0000339 }
340 cell->clearIntrinsicPadding();
341 cell->clearOverrideSize();
antti@apple.comca2a8ff2013-10-04 04:04:35 +0000342 cell->setChildNeedsLayout(MarkOnlyThis);
commit-queue@webkit.org5ec57ca2012-07-12 22:33:36 +0000343 cell->layoutIfNeeded();
weinigfef13632007-04-29 20:09:08 +0000344 }
mitz@apple.com8010bba2010-11-05 02:43:17 +0000345
commit-queue@webkit.org5ec57ca2012-07-12 22:33:36 +0000346 int cellLogicalHeight = cell->logicalHeightForRowSizing();
andersca@apple.com86298632013-11-10 19:32:33 +0000347 m_rowPos[r + 1] = std::max(m_rowPos[r + 1], m_rowPos[cellStartRow] + cellLogicalHeight);
eseidela043f3d2006-01-20 19:24:53 +0000348
commit-queue@webkit.orgbb454812013-05-14 19:57:51 +0000349 // Find out the baseline. The baseline is set on the first row in a rowspan.
robert@webkit.org292be542013-03-09 06:40:13 +0000350 if (cell->isBaselineAligned()) {
commit-queue@webkit.org5ec57ca2012-07-12 22:33:36 +0000351 LayoutUnit baselinePosition = cell->cellBaselinePosition();
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +0000352 if (baselinePosition > cell->borderAndPaddingBefore()) {
andersca@apple.com86298632013-11-10 19:32:33 +0000353 m_grid[cellStartRow].baseline = std::max(m_grid[cellStartRow].baseline, baselinePosition);
commit-queue@webkit.orgbb454812013-05-14 19:57:51 +0000354 // The descent of a cell that spans multiple rows does not affect the height of the first row it spans, so don't let it
355 // become the baseline descent applied to the rest of the row. Also we don't account for the baseline descent of
356 // non-spanning cells when computing a spanning cell's extent.
357 int cellStartRowBaselineDescent = 0;
358 if (cell->rowSpan() == 1) {
andersca@apple.com86298632013-11-10 19:32:33 +0000359 baselineDescent = std::max(baselineDescent, cellLogicalHeight - (baselinePosition - cell->intrinsicPaddingBefore()));
commit-queue@webkit.orgbb454812013-05-14 19:57:51 +0000360 cellStartRowBaselineDescent = baselineDescent;
361 }
andersca@apple.com86298632013-11-10 19:32:33 +0000362 m_rowPos[cellStartRow + 1] = std::max<int>(m_rowPos[cellStartRow + 1], m_rowPos[cellStartRow] + m_grid[cellStartRow].baseline + cellStartRowBaselineDescent);
commit-queue@webkit.org5ec57ca2012-07-12 22:33:36 +0000363 }
eseidela043f3d2006-01-20 19:24:53 +0000364 }
ap50b58352006-01-22 20:32:36 +0000365 }
366 }
eseidela043f3d2006-01-20 19:24:53 +0000367
jchaffraix@webkit.orgaddd65e2012-02-26 00:19:22 +0000368 // Add the border-spacing to our final position.
ossy@webkit.org6d30aa72013-11-28 17:40:59 +0000369 // Use table border-spacing even in non-top sections
370 spacing = table()->vBorderSpacing();
jchaffraix@webkit.orgaddd65e2012-02-26 00:19:22 +0000371 m_rowPos[r + 1] += m_grid[r].rowRenderer ? spacing : 0;
andersca@apple.com86298632013-11-10 19:32:33 +0000372 m_rowPos[r + 1] = std::max(m_rowPos[r + 1], m_rowPos[r]);
eseidela043f3d2006-01-20 19:24:53 +0000373 }
weinigfef13632007-04-29 20:09:08 +0000374
hyatt@apple.comc93db9b2009-02-04 22:29:04 +0000375 ASSERT(!needsLayout());
376
simon.fraser@apple.comfeaef2e2008-11-07 19:17:08 +0000377 statePusher.pop();
mitz@apple.com440ac8c2008-04-05 16:05:08 +0000378
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000379 return m_rowPos[m_grid.size()];
eseidela043f3d2006-01-20 19:24:53 +0000380}
381
hyatt@apple.combfda0e32009-01-31 21:20:17 +0000382void RenderTableSection::layout()
383{
mark.lam@apple.com6df1a802012-10-19 20:09:36 +0000384 StackStats::LayoutCheckPoint layoutCheckPoint;
hyatt@apple.combfda0e32009-01-31 21:20:17 +0000385 ASSERT(needsLayout());
inferno@chromium.org7081f502012-05-26 00:28:23 +0000386 ASSERT(!needsCellRecalc());
387 ASSERT(!table()->needsSectionRecalc());
hyatt@apple.combfda0e32009-01-31 21:20:17 +0000388
jchaffraix@webkit.orga9ddfc12012-06-18 17:11:12 +0000389 // addChild may over-grow m_grid but we don't want to throw away the memory too early as addChild
390 // can be called in a loop (e.g during parsing). Doing it now ensures we have a stable-enough structure.
391 m_grid.shrinkToFit();
392
weinig@apple.comf8d77f32013-11-18 01:12:17 +0000393 LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
jchaffraix@webkit.orga66f1082012-10-16 16:42:02 +0000394
395 const Vector<int>& columnPos = table()->columnPositions();
396
397 for (unsigned r = 0; r < m_grid.size(); ++r) {
398 Row& row = m_grid[r].row;
399 unsigned cols = row.size();
400 // First, propagate our table layout's information to the cells. This will mark the row as needing layout
401 // if there was a column logical width change.
402 for (unsigned startColumn = 0; startColumn < cols; ++startColumn) {
403 CellStruct& current = row[startColumn];
404 RenderTableCell* cell = current.primaryCell();
405 if (!cell || current.inColSpan)
406 continue;
407
408 unsigned endCol = startColumn;
409 unsigned cspan = cell->colSpan();
410 while (cspan && endCol < cols) {
411 ASSERT(endCol < table()->columns().size());
412 cspan -= table()->columns()[endCol].span;
413 endCol++;
414 }
415 int tableLayoutLogicalWidth = columnPos[endCol] - columnPos[startColumn] - table()->hBorderSpacing();
416 cell->setCellLogicalWidth(tableLayoutLogicalWidth);
hyatt@apple.combfda0e32009-01-31 21:20:17 +0000417 }
jchaffraix@webkit.orga66f1082012-10-16 16:42:02 +0000418
419 if (RenderTableRow* rowRenderer = m_grid[r].rowRenderer)
420 rowRenderer->layoutIfNeeded();
hyatt@apple.combfda0e32009-01-31 21:20:17 +0000421 }
jchaffraix@webkit.orga66f1082012-10-16 16:42:02 +0000422
hyatt@apple.combfda0e32009-01-31 21:20:17 +0000423 statePusher.pop();
antti@apple.comca2a8ff2013-10-04 04:04:35 +0000424 clearNeedsLayout();
hyatt@apple.combfda0e32009-01-31 21:20:17 +0000425}
426
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000427void RenderTableSection::distributeExtraLogicalHeightToPercentRows(int& extraLogicalHeight, int totalPercent)
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000428{
429 if (!totalPercent)
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000430 return;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000431
432 unsigned totalRows = m_grid.size();
433 int totalHeight = m_rowPos[totalRows] + extraLogicalHeight;
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000434 int totalLogicalHeightAdded = 0;
andersca@apple.com86298632013-11-10 19:32:33 +0000435 totalPercent = std::min(totalPercent, 100);
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000436 int rowHeight = m_rowPos[1] - m_rowPos[0];
437 for (unsigned r = 0; r < totalRows; ++r) {
438 if (totalPercent > 0 && m_grid[r].logicalHeight.isPercent()) {
andersca@apple.com86298632013-11-10 19:32:33 +0000439 int toAdd = std::min<int>(extraLogicalHeight, (totalHeight * m_grid[r].logicalHeight.percent() / 100) - rowHeight);
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000440 // If toAdd is negative, then we don't want to shrink the row (this bug
441 // affected Outlook Web Access).
andersca@apple.com86298632013-11-10 19:32:33 +0000442 toAdd = std::max(0, toAdd);
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000443 totalLogicalHeightAdded += toAdd;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000444 extraLogicalHeight -= toAdd;
445 totalPercent -= m_grid[r].logicalHeight.percent();
446 }
447 ASSERT(totalRows >= 1);
448 if (r < totalRows - 1)
449 rowHeight = m_rowPos[r + 2] - m_rowPos[r + 1];
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000450 m_rowPos[r + 1] += totalLogicalHeightAdded;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000451 }
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000452}
453
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000454void RenderTableSection::distributeExtraLogicalHeightToAutoRows(int& extraLogicalHeight, unsigned autoRowsCount)
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000455{
456 if (!autoRowsCount)
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000457 return;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000458
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000459 int totalLogicalHeightAdded = 0;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000460 for (unsigned r = 0; r < m_grid.size(); ++r) {
461 if (autoRowsCount > 0 && m_grid[r].logicalHeight.isAuto()) {
462 // Recomputing |extraLogicalHeightForRow| guarantees that we properly ditribute round |extraLogicalHeight|.
463 int extraLogicalHeightForRow = extraLogicalHeight / autoRowsCount;
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000464 totalLogicalHeightAdded += extraLogicalHeightForRow;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000465 extraLogicalHeight -= extraLogicalHeightForRow;
466 --autoRowsCount;
467 }
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000468 m_rowPos[r + 1] += totalLogicalHeightAdded;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000469 }
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000470}
471
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000472void RenderTableSection::distributeRemainingExtraLogicalHeight(int& extraLogicalHeight)
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000473{
474 unsigned totalRows = m_grid.size();
475
476 if (extraLogicalHeight <= 0 || !m_rowPos[totalRows])
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000477 return;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000478
479 // FIXME: m_rowPos[totalRows] - m_rowPos[0] is the total rows' size.
480 int totalRowSize = m_rowPos[totalRows];
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000481 int totalLogicalHeightAdded = 0;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000482 int previousRowPosition = m_rowPos[0];
483 for (unsigned r = 0; r < totalRows; r++) {
484 // weight with the original height
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000485 totalLogicalHeightAdded += extraLogicalHeight * (m_rowPos[r + 1] - previousRowPosition) / totalRowSize;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000486 previousRowPosition = m_rowPos[r + 1];
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000487 m_rowPos[r + 1] += totalLogicalHeightAdded;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000488 }
489
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000490 extraLogicalHeight -= totalLogicalHeightAdded;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000491}
492
493int RenderTableSection::distributeExtraLogicalHeightToRows(int extraLogicalHeight)
494{
495 if (!extraLogicalHeight)
496 return extraLogicalHeight;
497
498 unsigned totalRows = m_grid.size();
499 if (!totalRows)
500 return extraLogicalHeight;
501
502 if (!m_rowPos[totalRows] && nextSibling())
503 return extraLogicalHeight;
504
505 unsigned autoRowsCount = 0;
506 int totalPercent = 0;
507 for (unsigned r = 0; r < totalRows; r++) {
508 if (m_grid[r].logicalHeight.isAuto())
509 ++autoRowsCount;
510 else if (m_grid[r].logicalHeight.isPercent())
511 totalPercent += m_grid[r].logicalHeight.percent();
512 }
513
514 int remainingExtraLogicalHeight = extraLogicalHeight;
jchaffraix@webkit.orgc2788982012-03-20 21:02:34 +0000515 distributeExtraLogicalHeightToPercentRows(remainingExtraLogicalHeight, totalPercent);
516 distributeExtraLogicalHeightToAutoRows(remainingExtraLogicalHeight, autoRowsCount);
517 distributeRemainingExtraLogicalHeight(remainingExtraLogicalHeight);
518 return extraLogicalHeight - remainingExtraLogicalHeight;
jchaffraix@webkit.org3395b972012-03-09 22:58:05 +0000519}
520
jchaffraix@webkit.org94f150f2012-03-20 04:53:14 +0000521void RenderTableSection::layoutRows()
eseidela043f3d2006-01-20 19:24:53 +0000522{
hyatt@apple.comc93db9b2009-02-04 22:29:04 +0000523#ifndef NDEBUG
ojan@chromium.orgccdc4292013-02-07 00:55:10 +0000524 SetLayoutNeededForbiddenScope layoutForbiddenScope(this);
hyatt@apple.comc93db9b2009-02-04 22:29:04 +0000525#endif
526
527 ASSERT(!needsLayout());
528
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000529 unsigned totalRows = m_grid.size();
530
hyattd866e592006-03-17 09:50:35 +0000531 // Set the width of our section now. The rows will also be this width.
mitz@apple.com8010bba2010-11-05 02:43:17 +0000532 setLogicalWidth(table()->contentLogicalWidth());
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +0000533 m_forceSlowPaintPathWithOverflowingCell = false;
adeleddfe27f2007-01-05 23:03:50 +0000534
eae@chromium.org351bc642012-02-08 05:37:54 +0000535 int vspacing = table()->vBorderSpacing();
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000536 unsigned nEffCols = table()->numEffCols();
ddkilzer260f3d22007-01-05 05:56:31 +0000537
weinig@apple.comf8d77f32013-11-18 01:12:17 +0000538 LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || style().isFlippedBlocksWritingMode());
weinigfef13632007-04-29 20:09:08 +0000539
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000540 for (unsigned r = 0; r < totalRows; r++) {
hyattd866e592006-03-17 09:50:35 +0000541 // Set the row's x/y position and width/height.
hyatt@apple.comd885df72009-01-22 02:31:52 +0000542 if (RenderTableRow* rowRenderer = m_grid[r].rowRenderer) {
robert@webkit.orgf9766b12013-08-27 19:21:00 +0000543 // FIXME: the x() position of the row should be table()->hBorderSpacing() so that it can
544 // report the correct offsetLeft. However, that will require a lot of rebaselining of test results.
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000545 rowRenderer->setLocation(LayoutPoint(0, m_rowPos[r]));
mitz@apple.com8010bba2010-11-05 02:43:17 +0000546 rowRenderer->setLogicalWidth(logicalWidth());
547 rowRenderer->setLogicalHeight(m_rowPos[r + 1] - m_rowPos[r] - vspacing);
simon.fraser@apple.com78e3bdb2010-11-30 00:53:05 +0000548 rowRenderer->updateLayerTransform();
hyattd866e592006-03-17 09:50:35 +0000549 }
550
mitz@apple.com48b3ee82012-07-12 02:38:38 +0000551 int rowHeightIncreaseForPagination = 0;
552
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000553 for (unsigned c = 0; c < nEffCols; c++) {
jamesr@google.com36623a32010-07-23 20:22:29 +0000554 CellStruct& cs = cellAt(r, c);
555 RenderTableCell* cell = cs.primaryCell();
556
jamesr@google.comb4266232010-07-28 20:07:19 +0000557 if (!cell || cs.inColSpan)
ap50b58352006-01-22 20:32:36 +0000558 continue;
eseidela043f3d2006-01-20 19:24:53 +0000559
jchaffraix@webkit.org83cb3912012-10-05 03:56:17 +0000560 int rowIndex = cell->rowIndex();
561 int rHeight = m_rowPos[rowIndex + cell->rowSpan()] - m_rowPos[rowIndex] - vspacing;
562
eseidela043f3d2006-01-20 19:24:53 +0000563 // Force percent height children to lay themselves out again.
564 // This will cause these children to grow to fill the cell.
565 // FIXME: There is still more work to do here to fully match WinIE (should
566 // it become necessary to do so). In quirks mode, WinIE behaves like we
567 // do, but it will clip the cells that spill out of the table section. In
568 // strict mode, Mozilla and WinIE both regrow the table to accommodate the
569 // new height of the cell (thus letting the percentages cause growth one
570 // time only). We may also not be handling row-spanning cells correctly.
571 //
572 // Note also the oddity where replaced elements always flex, and yet blocks/tables do
573 // not necessarily flex. WinIE is crazy and inconsistent, and we can't hope to
574 // match the behavior perfectly, but we'll continue to refine it as we discover new
575 // bugs. :)
576 bool cellChildrenFlex = false;
akling@apple.com827be9c2013-10-29 02:58:43 +0000577 bool flexAllChildren = cell->style().logicalHeight().isFixed()
578 || (!table()->style().logicalHeight().isAuto() && rHeight != cell->logicalHeight());
eseidela043f3d2006-01-20 19:24:53 +0000579
580 for (RenderObject* o = cell->firstChild(); o; o = o->nextSibling()) {
akling@apple.com827be9c2013-10-29 02:58:43 +0000581 if (!o->isText() && o->style().logicalHeight().isPercent() && (flexAllChildren || ((o->isReplaced() || (o->isBox() && toRenderBox(o)->scrollsOverflow())) && !o->isTextControl()))) {
eseidela043f3d2006-01-20 19:24:53 +0000582 // Tables with no sections do not flex.
darin@apple.com445c34f2009-08-01 00:40:58 +0000583 if (!o->isTable() || toRenderTable(o)->hasSections()) {
antti@apple.comca2a8ff2013-10-04 04:04:35 +0000584 o->setNeedsLayout(MarkOnlyThis);
eseidela043f3d2006-01-20 19:24:53 +0000585 cellChildrenFlex = true;
586 }
587 }
588 }
mitz@apple.com1547c6d2009-03-20 23:41:54 +0000589
tony@chromium.org05b9d2c2012-09-05 01:31:38 +0000590 if (TrackedRendererListHashSet* percentHeightDescendants = cell->percentHeightDescendants()) {
591 TrackedRendererListHashSet::iterator end = percentHeightDescendants->end();
592 for (TrackedRendererListHashSet::iterator it = percentHeightDescendants->begin(); it != end; ++it) {
mitz@apple.com1547c6d2009-03-20 23:41:54 +0000593 RenderBox* box = *it;
594 if (!box->isReplaced() && !box->scrollsOverflow() && !flexAllChildren)
595 continue;
596
597 while (box != cell) {
598 if (box->normalChildNeedsLayout())
599 break;
antti@apple.comca2a8ff2013-10-04 04:04:35 +0000600 box->setChildNeedsLayout(MarkOnlyThis);
mitz@apple.com1547c6d2009-03-20 23:41:54 +0000601 box = box->containingBlock();
602 ASSERT(box);
603 if (!box)
604 break;
605 }
606 cellChildrenFlex = true;
607 }
608 }
609
eseidela043f3d2006-01-20 19:24:53 +0000610 if (cellChildrenFlex) {
antti@apple.comca2a8ff2013-10-04 04:04:35 +0000611 cell->setChildNeedsLayout(MarkOnlyThis);
eseidela043f3d2006-01-20 19:24:53 +0000612 // Alignment within a cell is based off the calculated
613 // height, which becomes irrelevant once the cell has
hyatt@apple.com0bf6c842009-01-23 03:42:12 +0000614 // been resized based off its percentage.
ojan@chromium.org7a1ce8b2012-06-05 18:32:10 +0000615 cell->setOverrideLogicalContentHeightFromRowHeight(rHeight);
ap7332aaa2006-04-28 16:02:45 +0000616 cell->layoutIfNeeded();
mitz@apple.com8010bba2010-11-05 02:43:17 +0000617
hyatt851433b2007-05-12 06:40:14 +0000618 // If the baseline moved, we may have to update the data for our row. Find out the new baseline.
robert@webkit.org292be542013-03-09 06:40:13 +0000619 if (cell->isBaselineAligned()) {
leviw@chromium.org2650e382012-04-04 10:37:36 +0000620 LayoutUnit baseline = cell->cellBaselinePosition();
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +0000621 if (baseline > cell->borderAndPaddingBefore())
andersca@apple.com86298632013-11-10 19:32:33 +0000622 m_grid[r].baseline = std::max(m_grid[r].baseline, baseline);
hyatt851433b2007-05-12 06:40:14 +0000623 }
eseidela043f3d2006-01-20 19:24:53 +0000624 }
mitz@apple.com8010bba2010-11-05 02:43:17 +0000625
jchaffraix@webkit.org83cb3912012-10-05 03:56:17 +0000626 cell->computeIntrinsicPadding(rHeight);
mitz@apple.com8010bba2010-11-05 02:43:17 +0000627
eae@chromium.org1146f212012-07-18 22:06:34 +0000628 LayoutRect oldCellRect = cell->frameRect();
mitz@apple.com8010bba2010-11-05 02:43:17 +0000629
jchaffraix@webkit.org4b5292a2012-06-06 16:07:16 +0000630 setLogicalPositionForCell(cell, c);
eseidela043f3d2006-01-20 19:24:53 +0000631
akling@apple.com691cf5c2013-08-24 16:33:15 +0000632 if (!cell->needsLayout() && view().layoutState()->pageLogicalHeight() && view().layoutState()->pageLogicalOffset(cell, cell->logicalTop()) != cell->pageLogicalOffset())
antti@apple.comca2a8ff2013-10-04 04:04:35 +0000633 cell->setChildNeedsLayout(MarkOnlyThis);
mitz@apple.com8010bba2010-11-05 02:43:17 +0000634
hyatt@apple.com1259d732010-09-20 16:12:58 +0000635 cell->layoutIfNeeded();
mitz@apple.com8010bba2010-11-05 02:43:17 +0000636
637 // FIXME: Make pagination work with vertical tables.
akling@apple.com691cf5c2013-08-24 16:33:15 +0000638 if (view().layoutState()->pageLogicalHeight() && cell->logicalHeight() != rHeight) {
hyatt@apple.com8403ad22012-04-10 18:14:20 +0000639 // FIXME: Pagination might have made us change size. For now just shrink or grow the cell to fit without doing a relayout.
640 // We'll also do a basic increase of the row height to accommodate the cell if it's bigger, but this isn't quite right
641 // either. It's at least stable though and won't result in an infinite # of relayouts that may never stabilize.
mitz@apple.com48b3ee82012-07-12 02:38:38 +0000642 if (cell->logicalHeight() > rHeight)
andersca@apple.com86298632013-11-10 19:32:33 +0000643 rowHeightIncreaseForPagination = std::max<int>(rowHeightIncreaseForPagination, cell->logicalHeight() - rHeight);
mitz@apple.com48b3ee82012-07-12 02:38:38 +0000644 cell->setLogicalHeight(rHeight);
hyatt@apple.com8403ad22012-04-10 18:14:20 +0000645 }
mitz@apple.com8010bba2010-11-05 02:43:17 +0000646
leviw@chromium.org7353dfd2011-08-12 21:01:45 +0000647 LayoutSize childOffset(cell->location() - oldCellRect.location());
hyatt@apple.comb297b492010-09-20 20:21:34 +0000648 if (childOffset.width() || childOffset.height()) {
akling@apple.com691cf5c2013-08-24 16:33:15 +0000649 view().addLayoutDelta(childOffset);
hyatt@apple.com1259d732010-09-20 16:12:58 +0000650
hyatt@apple.comb297b492010-09-20 20:21:34 +0000651 // If the child moved, we have to repaint it as well as any floating/positioned
652 // descendants. An exception is if we need a layout. In this case, we know we're going to
653 // repaint ourselves (and the child) anyway.
654 if (!table()->selfNeedsLayout() && cell->checkForRepaintDuringLayout())
655 cell->repaintDuringLayoutIfMoved(oldCellRect);
656 }
eseidela043f3d2006-01-20 19:24:53 +0000657 }
mitz@apple.com48b3ee82012-07-12 02:38:38 +0000658 if (rowHeightIncreaseForPagination) {
659 for (unsigned rowIndex = r + 1; rowIndex <= totalRows; rowIndex++)
660 m_rowPos[rowIndex] += rowHeightIncreaseForPagination;
661 for (unsigned c = 0; c < nEffCols; ++c) {
662 Vector<RenderTableCell*, 1>& cells = cellAt(r, c).cells;
663 for (size_t i = 0; i < cells.size(); ++i)
664 cells[i]->setLogicalHeight(cells[i]->logicalHeight() + rowHeightIncreaseForPagination);
665 }
666 }
eseidela043f3d2006-01-20 19:24:53 +0000667 }
668
hyatt@apple.com8b2cd1f2009-01-26 03:38:55 +0000669 ASSERT(!needsLayout());
670
mitz@apple.com8010bba2010-11-05 02:43:17 +0000671 setLogicalHeight(m_rowPos[totalRows]);
hyatt@apple.com7214c6a2009-08-19 16:28:51 +0000672
robert@webkit.org4c91cc92013-03-27 23:49:48 +0000673 computeOverflowFromCells(totalRows, nEffCols);
674
675 statePusher.pop();
676}
677
678void RenderTableSection::computeOverflowFromCells()
679{
680 unsigned totalRows = m_grid.size();
681 unsigned nEffCols = table()->numEffCols();
682 computeOverflowFromCells(totalRows, nEffCols);
683}
684
685void RenderTableSection::computeOverflowFromCells(unsigned totalRows, unsigned nEffCols)
686{
abucur@adobe.com6585d012013-09-04 08:26:41 +0000687 clearOverflow();
robert@webkit.orge4314c42013-08-08 18:13:22 +0000688 m_overflowingCells.clear();
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +0000689 unsigned totalCellsCount = nEffCols * totalRows;
690 int maxAllowedOverflowingCellsCount = totalCellsCount < gMinTableSizeToUseFastPaintPathWithOverflowingCell ? 0 : gMaxAllowedOverflowingCellRatioForFastPaintPath * totalCellsCount;
691
692#ifndef NDEBUG
693 bool hasOverflowingCell = false;
694#endif
hyatt@apple.com7214c6a2009-08-19 16:28:51 +0000695 // Now that our height has been determined, add in overflow from cells.
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +0000696 for (unsigned r = 0; r < totalRows; r++) {
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000697 for (unsigned c = 0; c < nEffCols; c++) {
jamesr@google.com36623a32010-07-23 20:22:29 +0000698 CellStruct& cs = cellAt(r, c);
699 RenderTableCell* cell = cs.primaryCell();
jamesr@google.comb4266232010-07-28 20:07:19 +0000700 if (!cell || cs.inColSpan)
hyatt@apple.com7214c6a2009-08-19 16:28:51 +0000701 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000702 if (r < totalRows - 1 && cell == primaryCellAt(r + 1, c))
hyatt@apple.com7214c6a2009-08-19 16:28:51 +0000703 continue;
704 addOverflowFromChild(cell);
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +0000705#ifndef NDEBUG
706 hasOverflowingCell |= cell->hasVisualOverflow();
707#endif
708 if (cell->hasVisualOverflow() && !m_forceSlowPaintPathWithOverflowingCell) {
709 m_overflowingCells.add(cell);
710 if (m_overflowingCells.size() > maxAllowedOverflowingCellsCount) {
711 // We need to set m_forcesSlowPaintPath only if there is a least one overflowing cells as the hit testing code rely on this information.
712 m_forceSlowPaintPathWithOverflowingCell = true;
713 // The slow path does not make any use of the overflowing cells info, don't hold on to the memory.
714 m_overflowingCells.clear();
715 }
716 }
hyatt@apple.com7214c6a2009-08-19 16:28:51 +0000717 }
718 }
weinigfef13632007-04-29 20:09:08 +0000719
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +0000720 ASSERT(hasOverflowingCell == this->hasOverflowingCell());
eseidela043f3d2006-01-20 19:24:53 +0000721}
722
eae@chromium.org351bc642012-02-08 05:37:54 +0000723int RenderTableSection::calcOuterBorderBefore() const
darin32011102006-05-15 04:42:09 +0000724{
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000725 unsigned totalCols = table()->numEffCols();
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000726 if (!m_grid.size() || !totalCols)
darin32011102006-05-15 04:42:09 +0000727 return 0;
728
729 unsigned borderWidth = 0;
730
akling@apple.com827be9c2013-10-29 02:58:43 +0000731 const BorderValue& sb = style().borderBefore();
darin32011102006-05-15 04:42:09 +0000732 if (sb.style() == BHIDDEN)
733 return -1;
734 if (sb.style() > BHIDDEN)
hyatt@apple.come607db72010-04-09 20:21:55 +0000735 borderWidth = sb.width();
darin32011102006-05-15 04:42:09 +0000736
akling@apple.com827be9c2013-10-29 02:58:43 +0000737 const BorderValue& rb = firstRow()->style().borderBefore();
darin32011102006-05-15 04:42:09 +0000738 if (rb.style() == BHIDDEN)
739 return -1;
hyatt@apple.come607db72010-04-09 20:21:55 +0000740 if (rb.style() > BHIDDEN && rb.width() > borderWidth)
741 borderWidth = rb.width();
darin32011102006-05-15 04:42:09 +0000742
743 bool allHidden = true;
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000744 for (unsigned c = 0; c < totalCols; c++) {
darin32011102006-05-15 04:42:09 +0000745 const CellStruct& current = cellAt(0, c);
jamesr@google.com36623a32010-07-23 20:22:29 +0000746 if (current.inColSpan || !current.hasCells())
darin32011102006-05-15 04:42:09 +0000747 continue;
akling@apple.com827be9c2013-10-29 02:58:43 +0000748 const BorderValue& cb = current.primaryCell()->style().borderBefore(); // FIXME: Make this work with perpendicular and flipped cells.
darin32011102006-05-15 04:42:09 +0000749 // FIXME: Don't repeat for the same col group
750 RenderTableCol* colGroup = table()->colElement(c);
751 if (colGroup) {
akling@apple.com827be9c2013-10-29 02:58:43 +0000752 const BorderValue& gb = colGroup->style().borderBefore();
darin32011102006-05-15 04:42:09 +0000753 if (gb.style() == BHIDDEN || cb.style() == BHIDDEN)
754 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000755 allHidden = false;
hyatt@apple.come607db72010-04-09 20:21:55 +0000756 if (gb.style() > BHIDDEN && gb.width() > borderWidth)
757 borderWidth = gb.width();
758 if (cb.style() > BHIDDEN && cb.width() > borderWidth)
759 borderWidth = cb.width();
darin32011102006-05-15 04:42:09 +0000760 } else {
761 if (cb.style() == BHIDDEN)
762 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000763 allHidden = false;
hyatt@apple.come607db72010-04-09 20:21:55 +0000764 if (cb.style() > BHIDDEN && cb.width() > borderWidth)
765 borderWidth = cb.width();
darin32011102006-05-15 04:42:09 +0000766 }
767 }
768 if (allHidden)
769 return -1;
770
771 return borderWidth / 2;
772}
773
eae@chromium.org351bc642012-02-08 05:37:54 +0000774int RenderTableSection::calcOuterBorderAfter() const
darin32011102006-05-15 04:42:09 +0000775{
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000776 unsigned totalCols = table()->numEffCols();
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000777 if (!m_grid.size() || !totalCols)
darin32011102006-05-15 04:42:09 +0000778 return 0;
779
780 unsigned borderWidth = 0;
781
akling@apple.com827be9c2013-10-29 02:58:43 +0000782 const BorderValue& sb = style().borderAfter();
darin32011102006-05-15 04:42:09 +0000783 if (sb.style() == BHIDDEN)
784 return -1;
785 if (sb.style() > BHIDDEN)
hyatt@apple.come607db72010-04-09 20:21:55 +0000786 borderWidth = sb.width();
darin32011102006-05-15 04:42:09 +0000787
akling@apple.com827be9c2013-10-29 02:58:43 +0000788 const BorderValue& rb = lastRow()->style().borderAfter();
darin32011102006-05-15 04:42:09 +0000789 if (rb.style() == BHIDDEN)
790 return -1;
hyatt@apple.come607db72010-04-09 20:21:55 +0000791 if (rb.style() > BHIDDEN && rb.width() > borderWidth)
792 borderWidth = rb.width();
darin32011102006-05-15 04:42:09 +0000793
794 bool allHidden = true;
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000795 for (unsigned c = 0; c < totalCols; c++) {
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000796 const CellStruct& current = cellAt(m_grid.size() - 1, c);
jamesr@google.com36623a32010-07-23 20:22:29 +0000797 if (current.inColSpan || !current.hasCells())
darin32011102006-05-15 04:42:09 +0000798 continue;
akling@apple.com827be9c2013-10-29 02:58:43 +0000799 const BorderValue& cb = current.primaryCell()->style().borderAfter(); // FIXME: Make this work with perpendicular and flipped cells.
darin32011102006-05-15 04:42:09 +0000800 // FIXME: Don't repeat for the same col group
801 RenderTableCol* colGroup = table()->colElement(c);
802 if (colGroup) {
akling@apple.com827be9c2013-10-29 02:58:43 +0000803 const BorderValue& gb = colGroup->style().borderAfter();
darin32011102006-05-15 04:42:09 +0000804 if (gb.style() == BHIDDEN || cb.style() == BHIDDEN)
805 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000806 allHidden = false;
hyatt@apple.come607db72010-04-09 20:21:55 +0000807 if (gb.style() > BHIDDEN && gb.width() > borderWidth)
808 borderWidth = gb.width();
809 if (cb.style() > BHIDDEN && cb.width() > borderWidth)
810 borderWidth = cb.width();
darin32011102006-05-15 04:42:09 +0000811 } else {
812 if (cb.style() == BHIDDEN)
813 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000814 allHidden = false;
hyatt@apple.come607db72010-04-09 20:21:55 +0000815 if (cb.style() > BHIDDEN && cb.width() > borderWidth)
816 borderWidth = cb.width();
darin32011102006-05-15 04:42:09 +0000817 }
818 }
819 if (allHidden)
820 return -1;
821
822 return (borderWidth + 1) / 2;
823}
824
eae@chromium.org351bc642012-02-08 05:37:54 +0000825int RenderTableSection::calcOuterBorderStart() const
darin32011102006-05-15 04:42:09 +0000826{
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000827 unsigned totalCols = table()->numEffCols();
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000828 if (!m_grid.size() || !totalCols)
darin32011102006-05-15 04:42:09 +0000829 return 0;
830
831 unsigned borderWidth = 0;
832
akling@apple.com827be9c2013-10-29 02:58:43 +0000833 const BorderValue& sb = style().borderStart();
darin32011102006-05-15 04:42:09 +0000834 if (sb.style() == BHIDDEN)
835 return -1;
836 if (sb.style() > BHIDDEN)
hyatt@apple.come607db72010-04-09 20:21:55 +0000837 borderWidth = sb.width();
darin32011102006-05-15 04:42:09 +0000838
mitz@apple.com8010bba2010-11-05 02:43:17 +0000839 if (RenderTableCol* colGroup = table()->colElement(0)) {
akling@apple.com827be9c2013-10-29 02:58:43 +0000840 const BorderValue& gb = colGroup->style().borderStart();
darin32011102006-05-15 04:42:09 +0000841 if (gb.style() == BHIDDEN)
842 return -1;
hyatt@apple.come607db72010-04-09 20:21:55 +0000843 if (gb.style() > BHIDDEN && gb.width() > borderWidth)
844 borderWidth = gb.width();
darin32011102006-05-15 04:42:09 +0000845 }
846
847 bool allHidden = true;
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000848 for (unsigned r = 0; r < m_grid.size(); r++) {
mitz@apple.com8010bba2010-11-05 02:43:17 +0000849 const CellStruct& current = cellAt(r, 0);
jamesr@google.com36623a32010-07-23 20:22:29 +0000850 if (!current.hasCells())
darin32011102006-05-15 04:42:09 +0000851 continue;
852 // FIXME: Don't repeat for the same cell
akling@apple.com827be9c2013-10-29 02:58:43 +0000853 const BorderValue& cb = current.primaryCell()->style().borderStart(); // FIXME: Make this work with perpendicular and flipped cells.
854 const BorderValue& rb = current.primaryCell()->parent()->style().borderStart();
darin32011102006-05-15 04:42:09 +0000855 if (cb.style() == BHIDDEN || rb.style() == BHIDDEN)
856 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000857 allHidden = false;
hyatt@apple.come607db72010-04-09 20:21:55 +0000858 if (cb.style() > BHIDDEN && cb.width() > borderWidth)
859 borderWidth = cb.width();
860 if (rb.style() > BHIDDEN && rb.width() > borderWidth)
861 borderWidth = rb.width();
darin32011102006-05-15 04:42:09 +0000862 }
863 if (allHidden)
864 return -1;
865
akling@apple.com827be9c2013-10-29 02:58:43 +0000866 return (borderWidth + (table()->style().isLeftToRightDirection() ? 0 : 1)) / 2;
darin32011102006-05-15 04:42:09 +0000867}
868
eae@chromium.org351bc642012-02-08 05:37:54 +0000869int RenderTableSection::calcOuterBorderEnd() const
darin32011102006-05-15 04:42:09 +0000870{
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +0000871 unsigned totalCols = table()->numEffCols();
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000872 if (!m_grid.size() || !totalCols)
darin32011102006-05-15 04:42:09 +0000873 return 0;
874
875 unsigned borderWidth = 0;
876
akling@apple.com827be9c2013-10-29 02:58:43 +0000877 const BorderValue& sb = style().borderEnd();
darin32011102006-05-15 04:42:09 +0000878 if (sb.style() == BHIDDEN)
879 return -1;
880 if (sb.style() > BHIDDEN)
hyatt@apple.come607db72010-04-09 20:21:55 +0000881 borderWidth = sb.width();
darin32011102006-05-15 04:42:09 +0000882
mitz@apple.com8010bba2010-11-05 02:43:17 +0000883 if (RenderTableCol* colGroup = table()->colElement(totalCols - 1)) {
akling@apple.com827be9c2013-10-29 02:58:43 +0000884 const BorderValue& gb = colGroup->style().borderEnd();
darin32011102006-05-15 04:42:09 +0000885 if (gb.style() == BHIDDEN)
886 return -1;
hyatt@apple.come607db72010-04-09 20:21:55 +0000887 if (gb.style() > BHIDDEN && gb.width() > borderWidth)
888 borderWidth = gb.width();
darin32011102006-05-15 04:42:09 +0000889 }
890
891 bool allHidden = true;
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000892 for (unsigned r = 0; r < m_grid.size(); r++) {
mitz@apple.com8010bba2010-11-05 02:43:17 +0000893 const CellStruct& current = cellAt(r, totalCols - 1);
jamesr@google.com36623a32010-07-23 20:22:29 +0000894 if (!current.hasCells())
darin32011102006-05-15 04:42:09 +0000895 continue;
896 // FIXME: Don't repeat for the same cell
akling@apple.com827be9c2013-10-29 02:58:43 +0000897 const BorderValue& cb = current.primaryCell()->style().borderEnd(); // FIXME: Make this work with perpendicular and flipped cells.
898 const BorderValue& rb = current.primaryCell()->parent()->style().borderEnd();
darin32011102006-05-15 04:42:09 +0000899 if (cb.style() == BHIDDEN || rb.style() == BHIDDEN)
900 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +0000901 allHidden = false;
hyatt@apple.come607db72010-04-09 20:21:55 +0000902 if (cb.style() > BHIDDEN && cb.width() > borderWidth)
903 borderWidth = cb.width();
904 if (rb.style() > BHIDDEN && rb.width() > borderWidth)
905 borderWidth = rb.width();
darin32011102006-05-15 04:42:09 +0000906 }
907 if (allHidden)
908 return -1;
909
akling@apple.com827be9c2013-10-29 02:58:43 +0000910 return (borderWidth + (table()->style().isLeftToRightDirection() ? 1 : 0)) / 2;
darin32011102006-05-15 04:42:09 +0000911}
912
913void RenderTableSection::recalcOuterBorder()
914{
mitz@apple.com8010bba2010-11-05 02:43:17 +0000915 m_outerBorderBefore = calcOuterBorderBefore();
916 m_outerBorderAfter = calcOuterBorderAfter();
917 m_outerBorderStart = calcOuterBorderStart();
918 m_outerBorderEnd = calcOuterBorderEnd();
darin32011102006-05-15 04:42:09 +0000919}
920
antti@apple.com0e632aa2013-10-22 21:03:38 +0000921int RenderTableSection::firstLineBaseline() const
mitz@apple.com57a2f482008-08-23 07:16:41 +0000922{
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000923 if (!m_grid.size())
mitz@apple.com57a2f482008-08-23 07:16:41 +0000924 return -1;
925
eae@chromium.org82b94982012-10-22 18:38:29 +0000926 int firstLineBaseline = m_grid[0].baseline;
mitz@apple.com57a2f482008-08-23 07:16:41 +0000927 if (firstLineBaseline)
928 return firstLineBaseline + m_rowPos[0];
929
930 firstLineBaseline = -1;
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +0000931 const Row& firstRow = m_grid[0].row;
932 for (size_t i = 0; i < firstRow.size(); ++i) {
933 const CellStruct& cs = firstRow.at(i);
934 const RenderTableCell* cell = cs.primaryCell();
robert@webkit.org3b67b1f2012-05-16 21:06:10 +0000935 // Only cells with content have a baseline
936 if (cell && cell->contentLogicalHeight())
andersca@apple.com86298632013-11-10 19:32:33 +0000937 firstLineBaseline = std::max<int>(firstLineBaseline, cell->logicalTop() + cell->borderAndPaddingBefore() + cell->contentLogicalHeight());
mitz@apple.com57a2f482008-08-23 07:16:41 +0000938 }
939
940 return firstLineBaseline;
941}
darin32011102006-05-15 04:42:09 +0000942
leviw@chromium.orgb3757502011-06-29 21:33:11 +0000943void RenderTableSection::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
eseidela043f3d2006-01-20 19:24:53 +0000944{
inferno@chromium.org64a831b2012-08-03 19:47:08 +0000945 // put this back in when all layout tests can handle it
946 // ASSERT(!needsLayout());
947 // avoid crashing on bugs that cause us to paint with dirty layout
eric@webkit.org5d226dc2012-08-02 21:06:06 +0000948 if (needsLayout())
949 return;
inferno@chromium.org64a831b2012-08-03 19:47:08 +0000950
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +0000951 unsigned totalRows = m_grid.size();
ddkilzer260f3d22007-01-05 05:56:31 +0000952 unsigned totalCols = table()->columns().size();
eseidela043f3d2006-01-20 19:24:53 +0000953
ddkilzer260f3d22007-01-05 05:56:31 +0000954 if (!totalRows || !totalCols)
ap0e708ba2006-05-20 08:47:37 +0000955 return;
956
leviw@chromium.orgb3757502011-06-29 21:33:11 +0000957 LayoutPoint adjustedPaintOffset = paintOffset + location();
eseidela043f3d2006-01-20 19:24:53 +0000958
hyatt@apple.comfe52f5b2009-02-25 01:21:03 +0000959 PaintPhase phase = paintInfo.phase;
leviw@chromium.org61ca1372011-06-07 18:56:41 +0000960 bool pushedClip = pushContentsClip(paintInfo, adjustedPaintOffset);
961 paintObject(paintInfo, adjustedPaintOffset);
hyatt@apple.comfe52f5b2009-02-25 01:21:03 +0000962 if (pushedClip)
leviw@chromium.org61ca1372011-06-07 18:56:41 +0000963 popContentsClip(paintInfo, phase, adjustedPaintOffset);
robert@webkit.org87e8d0c2012-01-14 19:13:35 +0000964
akling@apple.com827be9c2013-10-29 02:58:43 +0000965 if ((phase == PaintPhaseOutline || phase == PaintPhaseSelfOutline) && style().visibility() == VISIBLE)
wangxianzhu@chromium.org64f38292013-02-28 20:38:23 +0000966 paintOutline(paintInfo, LayoutRect(adjustedPaintOffset, size()));
hyatt@apple.comfe52f5b2009-02-25 01:21:03 +0000967}
968
jamesr@google.com36623a32010-07-23 20:22:29 +0000969static inline bool compareCellPositions(RenderTableCell* elem1, RenderTableCell* elem2)
970{
jchaffraix@webkit.orga0177fd2012-05-01 03:13:06 +0000971 return elem1->rowIndex() < elem2->rowIndex();
jamesr@google.com36623a32010-07-23 20:22:29 +0000972}
973
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +0000974// This comparison is used only when we have overflowing cells as we have an unsorted array to sort. We thus need
975// to sort both on rows and columns to properly repaint.
976static inline bool compareCellPositionsWithOverflowingCells(RenderTableCell* elem1, RenderTableCell* elem2)
977{
jchaffraix@webkit.orga0177fd2012-05-01 03:13:06 +0000978 if (elem1->rowIndex() != elem2->rowIndex())
979 return elem1->rowIndex() < elem2->rowIndex();
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +0000980
981 return elem1->col() < elem2->col();
982}
983
leviw@chromium.org890e9b02011-07-07 23:17:55 +0000984void RenderTableSection::paintCell(RenderTableCell* cell, PaintInfo& paintInfo, const LayoutPoint& paintOffset)
jamesr@google.com36623a32010-07-23 20:22:29 +0000985{
ojan@chromium.org035c88ca2011-10-03 22:00:25 +0000986 LayoutPoint cellPoint = flipForWritingModeForChild(cell, paintOffset);
jamesr@google.com36623a32010-07-23 20:22:29 +0000987 PaintPhase paintPhase = paintInfo.phase;
988 RenderTableRow* row = toRenderTableRow(cell->parent());
989
990 if (paintPhase == PaintPhaseBlockBackground || paintPhase == PaintPhaseChildBlockBackground) {
991 // We need to handle painting a stack of backgrounds. This stack (from bottom to top) consists of
992 // the column group, column, row group, row, and then the cell.
jchaffraix@webkit.org1ddd9fa2012-05-31 16:00:20 +0000993 RenderTableCol* column = table()->colElement(cell->col());
994 RenderTableCol* columnGroup = column ? column->enclosingColumnGroup() : 0;
jamesr@google.com36623a32010-07-23 20:22:29 +0000995
996 // Column groups and columns first.
997 // FIXME: Columns and column groups do not currently support opacity, and they are being painted "too late" in
998 // the stack, since we have already opened a transparency layer (potentially) for the table row group.
999 // Note that we deliberately ignore whether or not the cell has a layer, since these backgrounds paint "behind" the
1000 // cell.
jchaffraix@webkit.org1ddd9fa2012-05-31 16:00:20 +00001001 cell->paintBackgroundsBehindCell(paintInfo, cellPoint, columnGroup);
1002 cell->paintBackgroundsBehindCell(paintInfo, cellPoint, column);
jamesr@google.com36623a32010-07-23 20:22:29 +00001003
1004 // Paint the row group next.
leviw@chromium.org719a45b2011-06-03 20:59:40 +00001005 cell->paintBackgroundsBehindCell(paintInfo, cellPoint, this);
jamesr@google.com36623a32010-07-23 20:22:29 +00001006
1007 // Paint the row next, but only if it doesn't have a layer. If a row has a layer, it will be responsible for
1008 // painting the row background for the cell.
1009 if (!row->hasSelfPaintingLayer())
leviw@chromium.org719a45b2011-06-03 20:59:40 +00001010 cell->paintBackgroundsBehindCell(paintInfo, cellPoint, row);
jamesr@google.com36623a32010-07-23 20:22:29 +00001011 }
robert@webkit.org2d408272011-12-19 19:49:27 +00001012 if ((!cell->hasSelfPaintingLayer() && !row->hasSelfPaintingLayer()))
leviw@chromium.org61ca1372011-06-07 18:56:41 +00001013 cell->paint(paintInfo, cellPoint);
jamesr@google.com36623a32010-07-23 20:22:29 +00001014}
1015
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001016LayoutRect RenderTableSection::logicalRectForWritingModeAndDirection(const LayoutRect& rect) const
1017{
1018 LayoutRect tableAlignedRect(rect);
1019
1020 flipForWritingMode(tableAlignedRect);
1021
akling@apple.com827be9c2013-10-29 02:58:43 +00001022 if (!style().isHorizontalWritingMode())
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001023 tableAlignedRect = tableAlignedRect.transposedRect();
1024
1025 const Vector<int>& columnPos = table()->columnPositions();
jchaffraix@webkit.org6d6c3052012-11-05 07:55:28 +00001026 // FIXME: The table's direction should determine our row's direction, not the section's (see bug 96691).
akling@apple.com827be9c2013-10-29 02:58:43 +00001027 if (!style().isLeftToRightDirection())
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001028 tableAlignedRect.setX(columnPos[columnPos.size() - 1] - tableAlignedRect.maxX());
1029
1030 return tableAlignedRect;
1031}
1032
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001033CellSpan RenderTableSection::dirtiedRows(const LayoutRect& damageRect) const
1034{
1035 if (m_forceSlowPaintPathWithOverflowingCell)
1036 return fullTableRowSpan();
1037
commit-queue@webkit.org9fa1a352012-06-19 16:07:00 +00001038 CellSpan coveredRows = spannedRows(damageRect);
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001039
commit-queue@webkit.org9fa1a352012-06-19 16:07:00 +00001040 // To repaint the border we might need to repaint first or last row even if they are not spanned themselves.
1041 if (coveredRows.start() >= m_rowPos.size() - 1 && m_rowPos[m_rowPos.size() - 1] + table()->outerBorderAfter() >= damageRect.y())
1042 --coveredRows.start();
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001043
commit-queue@webkit.org9fa1a352012-06-19 16:07:00 +00001044 if (!coveredRows.end() && m_rowPos[0] - table()->outerBorderBefore() <= damageRect.maxY())
1045 ++coveredRows.end();
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001046
commit-queue@webkit.org9fa1a352012-06-19 16:07:00 +00001047 return coveredRows;
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001048}
1049
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001050CellSpan RenderTableSection::dirtiedColumns(const LayoutRect& damageRect) const
1051{
1052 if (m_forceSlowPaintPathWithOverflowingCell)
1053 return fullTableColumnSpan();
1054
commit-queue@webkit.org9fa1a352012-06-19 16:07:00 +00001055 CellSpan coveredColumns = spannedColumns(damageRect);
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001056
jchaffraix@webkit.orgb87ce752012-10-15 21:52:22 +00001057 const Vector<int>& columnPos = table()->columnPositions();
commit-queue@webkit.org9fa1a352012-06-19 16:07:00 +00001058 // To repaint the border we might need to repaint first or last column even if they are not spanned themselves.
1059 if (coveredColumns.start() >= columnPos.size() - 1 && columnPos[columnPos.size() - 1] + table()->outerBorderEnd() >= damageRect.x())
1060 --coveredColumns.start();
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001061
commit-queue@webkit.org9fa1a352012-06-19 16:07:00 +00001062 if (!coveredColumns.end() && columnPos[0] - table()->outerBorderStart() <= damageRect.maxX())
1063 ++coveredColumns.end();
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001064
commit-queue@webkit.org9fa1a352012-06-19 16:07:00 +00001065 return coveredColumns;
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001066}
1067
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001068CellSpan RenderTableSection::spannedRows(const LayoutRect& flippedRect) const
1069{
1070 // Find the first row that starts after rect top.
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001071 unsigned nextRow = std::upper_bound(m_rowPos.begin(), m_rowPos.end(), flippedRect.y()) - m_rowPos.begin();
1072
1073 if (nextRow == m_rowPos.size())
1074 return CellSpan(m_rowPos.size() - 1, m_rowPos.size() - 1); // After all rows.
1075
1076 unsigned startRow = nextRow > 0 ? nextRow - 1 : 0;
1077
1078 // Find the first row that starts after rect bottom.
1079 unsigned endRow;
1080 if (m_rowPos[nextRow] >= flippedRect.maxY())
1081 endRow = nextRow;
1082 else {
1083 endRow = std::upper_bound(m_rowPos.begin() + nextRow, m_rowPos.end(), flippedRect.maxY()) - m_rowPos.begin();
1084 if (endRow == m_rowPos.size())
1085 endRow = m_rowPos.size() - 1;
1086 }
1087
1088 return CellSpan(startRow, endRow);
1089}
1090
1091CellSpan RenderTableSection::spannedColumns(const LayoutRect& flippedRect) const
1092{
1093 const Vector<int>& columnPos = table()->columnPositions();
1094
commit-queue@webkit.org01f61412012-08-15 18:01:05 +00001095 // Find the first column that starts after rect left.
1096 // lower_bound doesn't handle the edge between two cells properly as it would wrongly return the
1097 // cell on the logical top/left.
1098 // upper_bound on the other hand properly returns the cell on the logical bottom/right, which also
1099 // matches the behavior of other browsers.
1100 unsigned nextColumn = std::upper_bound(columnPos.begin(), columnPos.end(), flippedRect.x()) - columnPos.begin();
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001101
1102 if (nextColumn == columnPos.size())
1103 return CellSpan(columnPos.size() - 1, columnPos.size() - 1); // After all columns.
1104
1105 unsigned startColumn = nextColumn > 0 ? nextColumn - 1 : 0;
1106
commit-queue@webkit.org01f61412012-08-15 18:01:05 +00001107 // Find the first column that starts after rect right.
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001108 unsigned endColumn;
1109 if (columnPos[nextColumn] >= flippedRect.maxX())
1110 endColumn = nextColumn;
1111 else {
commit-queue@webkit.org01f61412012-08-15 18:01:05 +00001112 endColumn = std::upper_bound(columnPos.begin() + nextColumn, columnPos.end(), flippedRect.maxX()) - columnPos.begin();
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001113 if (endColumn == columnPos.size())
1114 endColumn = columnPos.size() - 1;
1115 }
1116
1117 return CellSpan(startColumn, endColumn);
1118}
1119
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001120void RenderTableSection::paintRowGroupBorder(const PaintInfo& paintInfo, bool antialias, LayoutRect rect, BoxSide side, CSSPropertyID borderColor, EBorderStyle borderStyle, EBorderStyle tableBorderStyle)
1121{
1122 if (tableBorderStyle == BHIDDEN)
1123 return;
1124 rect.intersect(paintInfo.rect);
1125 if (rect.isEmpty())
1126 return;
akling@apple.com827be9c2013-10-29 02:58:43 +00001127 drawLineForBoxSide(paintInfo.context, rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height(), side, style().visitedDependentColor(borderColor), borderStyle, 0, 0, antialias);
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001128}
1129
1130int RenderTableSection::offsetLeftForRowGroupBorder(RenderTableCell* cell, const LayoutRect& rowGroupRect, unsigned row)
1131{
akling@apple.com827be9c2013-10-29 02:58:43 +00001132 if (style().isHorizontalWritingMode()) {
1133 if (style().isLeftToRightDirection())
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001134 return cell ? cell->x().toInt() + cell->width().toInt() : 0;
akling@apple.com827be9c2013-10-29 02:58:43 +00001135 return -outerBorderLeft(&style());
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001136 }
1137 bool isLastRow = row + 1 == m_grid.size();
akling@apple.com827be9c2013-10-29 02:58:43 +00001138 return rowGroupRect.width().toInt() - m_rowPos[row + 1] + (isLastRow ? -outerBorderLeft(&style()) : 0);
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001139}
1140
1141int RenderTableSection::offsetTopForRowGroupBorder(RenderTableCell* cell, BoxSide borderSide, unsigned row)
1142{
1143 bool isLastRow = row + 1 == m_grid.size();
akling@apple.com827be9c2013-10-29 02:58:43 +00001144 if (style().isHorizontalWritingMode())
1145 return m_rowPos[row] + (!row && borderSide == BSRight ? -outerBorderTop(&style()) : isLastRow && borderSide == BSLeft ? outerBorderTop(&style()) : 0);
1146 if (style().isLeftToRightDirection())
1147 return (cell ? cell->y().toInt() + cell->height().toInt() : 0) + (borderSide == BSLeft ? outerBorderTop(&style()) : 0);
1148 return borderSide == BSRight ? -outerBorderTop(&style()) : 0;
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001149}
1150
1151int RenderTableSection::verticalRowGroupBorderHeight(RenderTableCell* cell, const LayoutRect& rowGroupRect, unsigned row)
1152{
1153 bool isLastRow = row + 1 == m_grid.size();
akling@apple.com827be9c2013-10-29 02:58:43 +00001154 if (style().isHorizontalWritingMode())
1155 return m_rowPos[row + 1] - m_rowPos[row] + (!row ? outerBorderTop(&style()) : isLastRow ? outerBorderBottom(&style()) : 0);
1156 if (style().isLeftToRightDirection())
1157 return rowGroupRect.height().toInt() - (cell ? cell->y().toInt() + cell->height().toInt() : 0) + outerBorderBottom(&style());
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001158 return cell ? rowGroupRect.height().toInt() - (cell->y().toInt() - cell->height().toInt()) : 0;
1159}
1160
1161int RenderTableSection::horizontalRowGroupBorderWidth(RenderTableCell* cell, const LayoutRect& rowGroupRect, unsigned row, unsigned column)
1162{
akling@apple.com827be9c2013-10-29 02:58:43 +00001163 if (style().isHorizontalWritingMode()) {
1164 if (style().isLeftToRightDirection())
1165 return rowGroupRect.width().toInt() - (cell ? cell->x().toInt() + cell->width().toInt() : 0) + (!column ? outerBorderLeft(&style()) : column == table()->numEffCols() ? outerBorderRight(&style()) : 0);
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001166 return cell ? rowGroupRect.width().toInt() - (cell->x().toInt() - cell->width().toInt()) : 0;
1167 }
1168 bool isLastRow = row + 1 == m_grid.size();
akling@apple.com827be9c2013-10-29 02:58:43 +00001169 return m_rowPos[row + 1] - m_rowPos[row] + (isLastRow ? outerBorderLeft(&style()) : !row ? outerBorderRight(&style()) : 0);
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001170}
1171
1172void RenderTableSection::paintRowGroupBorderIfRequired(const PaintInfo& paintInfo, const LayoutPoint& paintOffset, unsigned row, unsigned column, BoxSide borderSide, RenderTableCell* cell)
1173{
1174 if (table()->currentBorderValue()->precedence() > BROWGROUP)
1175 return;
1176 if (paintInfo.context->paintingDisabled())
1177 return;
1178
akling@apple.com827be9c2013-10-29 02:58:43 +00001179 const RenderStyle& style = this->style();
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001180 bool antialias = shouldAntialiasLines(paintInfo.context);
1181 LayoutRect rowGroupRect = LayoutRect(paintOffset, size());
akling@apple.com827be9c2013-10-29 02:58:43 +00001182 rowGroupRect.moveBy(-LayoutPoint(outerBorderLeft(&style), (borderSide == BSRight) ? 0 : outerBorderTop(&style)));
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001183
1184 switch (borderSide) {
1185 case BSTop:
1186 paintRowGroupBorder(paintInfo, antialias, LayoutRect(paintOffset.x() + offsetLeftForRowGroupBorder(cell, rowGroupRect, row), rowGroupRect.y(),
akling@apple.com827be9c2013-10-29 02:58:43 +00001187 horizontalRowGroupBorderWidth(cell, rowGroupRect, row, column), style.borderTop().width()), BSTop, CSSPropertyBorderTopColor, style.borderTopStyle(), table()->style().borderTopStyle());
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001188 break;
1189 case BSBottom:
1190 paintRowGroupBorder(paintInfo, antialias, LayoutRect(paintOffset.x() + offsetLeftForRowGroupBorder(cell, rowGroupRect, row), rowGroupRect.y() + rowGroupRect.height(),
akling@apple.com827be9c2013-10-29 02:58:43 +00001191 horizontalRowGroupBorderWidth(cell, rowGroupRect, row, column), style.borderBottom().width()), BSBottom, CSSPropertyBorderBottomColor, style.borderBottomStyle(), table()->style().borderBottomStyle());
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001192 break;
1193 case BSLeft:
akling@apple.com827be9c2013-10-29 02:58:43 +00001194 paintRowGroupBorder(paintInfo, antialias, LayoutRect(rowGroupRect.x(), rowGroupRect.y() + offsetTopForRowGroupBorder(cell, borderSide, row), style.borderLeft().width(),
1195 verticalRowGroupBorderHeight(cell, rowGroupRect, row)), BSLeft, CSSPropertyBorderLeftColor, style.borderLeftStyle(), table()->style().borderLeftStyle());
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001196 break;
1197 case BSRight:
akling@apple.com827be9c2013-10-29 02:58:43 +00001198 paintRowGroupBorder(paintInfo, antialias, LayoutRect(rowGroupRect.x() + rowGroupRect.width(), rowGroupRect.y() + offsetTopForRowGroupBorder(cell, borderSide, row), style.borderRight().width(),
1199 verticalRowGroupBorderHeight(cell, rowGroupRect, row)), BSRight, CSSPropertyBorderRightColor, style.borderRightStyle(), table()->style().borderRightStyle());
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001200 break;
1201 default:
1202 break;
1203 }
1204
1205}
1206
1207static BoxSide physicalBorderForDirection(RenderStyle* styleForCellFlow, CollapsedBorderSide side)
1208{
1209
1210 switch (side) {
1211 case CBSStart:
1212 if (styleForCellFlow->isHorizontalWritingMode())
1213 return styleForCellFlow->isLeftToRightDirection() ? BSLeft : BSRight;
1214 return styleForCellFlow->isLeftToRightDirection() ? BSTop : BSBottom;
1215 case CBSEnd:
1216 if (styleForCellFlow->isHorizontalWritingMode())
1217 return styleForCellFlow->isLeftToRightDirection() ? BSRight : BSLeft;
1218 return styleForCellFlow->isLeftToRightDirection() ? BSBottom : BSTop;
1219 case CBSBefore:
1220 if (styleForCellFlow->isHorizontalWritingMode())
1221 return BSTop;
1222 return styleForCellFlow->isLeftToRightDirection() ? BSRight : BSLeft;
1223 case CBSAfter:
1224 if (styleForCellFlow->isHorizontalWritingMode())
1225 return BSBottom;
1226 return styleForCellFlow->isLeftToRightDirection() ? BSLeft : BSRight;
1227 default:
1228 ASSERT_NOT_REACHED();
1229 return BSLeft;
1230 }
1231}
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001232
leviw@chromium.orgc4918082011-06-29 01:06:00 +00001233void RenderTableSection::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
hyatt@apple.comfe52f5b2009-02-25 01:21:03 +00001234{
weinig0a635f02006-11-01 21:49:13 +00001235 PaintPhase paintPhase = paintInfo.phase;
eseidela043f3d2006-01-20 19:24:53 +00001236
leviw@chromium.orgc4918082011-06-29 01:06:00 +00001237 LayoutRect localRepaintRect = paintInfo.rect;
leviw@chromium.org43d0c4d2011-06-04 02:25:54 +00001238 localRepaintRect.moveBy(-paintOffset);
jchaffraix@webkit.org21764312012-02-29 20:49:49 +00001239 localRepaintRect.inflate(maximalOutlineSize(paintPhase));
eseidela043f3d2006-01-20 19:24:53 +00001240
commit-queue@webkit.org9fa1a352012-06-19 16:07:00 +00001241 LayoutRect tableAlignedRect = logicalRectForWritingModeAndDirection(localRepaintRect);
1242
1243 CellSpan dirtiedRows = this->dirtiedRows(tableAlignedRect);
1244 CellSpan dirtiedColumns = this->dirtiedColumns(tableAlignedRect);
jamesr@google.comf88b2582010-08-17 20:57:15 +00001245
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001246 if (dirtiedColumns.start() < dirtiedColumns.end()) {
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001247 if (!m_hasMultipleCellLevels && !m_overflowingCells.size()) {
robert@webkit.org2d408272011-12-19 19:49:27 +00001248 if (paintInfo.phase == PaintPhaseCollapsedTableBorders) {
1249 // Collapsed borders are painted from the bottom right to the top left so that precedence
robert@webkit.orgc75e7672013-06-11 18:11:31 +00001250 // due to cell position is respected. We need to paint one row beyond the topmost dirtied
1251 // row to calculate its collapsed border value.
1252 unsigned startRow = dirtiedRows.start() ? dirtiedRows.start() - 1 : 0;
1253 for (unsigned r = dirtiedRows.end(); r > startRow; r--) {
robert@webkit.org2d408272011-12-19 19:49:27 +00001254 unsigned row = r - 1;
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001255 bool shouldPaintRowGroupBorder = false;
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001256 for (unsigned c = dirtiedColumns.end(); c > dirtiedColumns.start(); c--) {
robert@webkit.org2d408272011-12-19 19:49:27 +00001257 unsigned col = c - 1;
1258 CellStruct& current = cellAt(row, col);
1259 RenderTableCell* cell = current.primaryCell();
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001260 if (!cell) {
1261 if (!c)
akling@apple.com827be9c2013-10-29 02:58:43 +00001262 paintRowGroupBorderIfRequired(paintInfo, paintOffset, row, col, physicalBorderForDirection(&style(), CBSStart));
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001263 else if (c == table()->numEffCols())
akling@apple.com827be9c2013-10-29 02:58:43 +00001264 paintRowGroupBorderIfRequired(paintInfo, paintOffset, row, col, physicalBorderForDirection(&style(), CBSEnd));
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001265 shouldPaintRowGroupBorder = true;
robert@webkit.org2d408272011-12-19 19:49:27 +00001266 continue;
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001267 }
1268 if ((row > dirtiedRows.start() && primaryCellAt(row - 1, col) == cell) || (col > dirtiedColumns.start() && primaryCellAt(row, col - 1) == cell))
1269 continue;
1270
1271 // If we had a run of null cells paint their corresponding section of the row group's border if necessary. Note that
1272 // this will only happen once within a row as the null cells will always be clustered together on one end of the row.
1273 if (shouldPaintRowGroupBorder) {
1274 if (r == m_grid.size())
akling@apple.com827be9c2013-10-29 02:58:43 +00001275 paintRowGroupBorderIfRequired(paintInfo, paintOffset, row, col, physicalBorderForDirection(&style(), CBSAfter), cell);
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001276 else if (!row && !table()->sectionAbove(this))
akling@apple.com827be9c2013-10-29 02:58:43 +00001277 paintRowGroupBorderIfRequired(paintInfo, paintOffset, row, col, physicalBorderForDirection(&style(), CBSBefore), cell);
robert@webkit.org2d9d64b2013-10-17 17:44:20 +00001278 shouldPaintRowGroupBorder = false;
1279 }
1280
robert@webkit.org2d408272011-12-19 19:49:27 +00001281 LayoutPoint cellPoint = flipForWritingModeForChild(cell, paintOffset);
1282 cell->paintCollapsedBorders(paintInfo, cellPoint);
1283 }
1284 }
1285 } else {
1286 // Draw the dirty cells in the order that they appear.
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001287 for (unsigned r = dirtiedRows.start(); r < dirtiedRows.end(); r++) {
robert@webkit.org87e8d0c2012-01-14 19:13:35 +00001288 RenderTableRow* row = m_grid[r].rowRenderer;
1289 if (row && !row->hasSelfPaintingLayer())
1290 row->paintOutlineForRowIfNeeded(paintInfo, paintOffset);
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001291 for (unsigned c = dirtiedColumns.start(); c < dirtiedColumns.end(); c++) {
robert@webkit.org2d408272011-12-19 19:49:27 +00001292 CellStruct& current = cellAt(r, c);
1293 RenderTableCell* cell = current.primaryCell();
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001294 if (!cell || (r > dirtiedRows.start() && primaryCellAt(r - 1, c) == cell) || (c > dirtiedColumns.start() && primaryCellAt(r, c - 1) == cell))
robert@webkit.org2d408272011-12-19 19:49:27 +00001295 continue;
1296 paintCell(cell, paintInfo, paintOffset);
1297 }
hyatte031dd02006-03-18 01:01:06 +00001298 }
ap50b58352006-01-22 20:32:36 +00001299 }
jamesr@google.com36623a32010-07-23 20:22:29 +00001300 } else {
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001301 // The overflowing cells should be scarce to avoid adding a lot of cells to the HashSet.
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001302#ifndef NDEBUG
1303 unsigned totalRows = m_grid.size();
1304 unsigned totalCols = table()->columns().size();
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001305 ASSERT(m_overflowingCells.size() < totalRows * totalCols * gMaxAllowedOverflowingCellRatioForFastPaintPath);
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001306#endif
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001307
1308 // 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 +00001309 Vector<RenderTableCell*> cells;
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001310 copyToVector(m_overflowingCells, cells);
1311
jamesr@google.com36623a32010-07-23 20:22:29 +00001312 HashSet<RenderTableCell*> spanningCells;
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001313
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001314 for (unsigned r = dirtiedRows.start(); r < dirtiedRows.end(); r++) {
robert@webkit.org87e8d0c2012-01-14 19:13:35 +00001315 RenderTableRow* row = m_grid[r].rowRenderer;
1316 if (row && !row->hasSelfPaintingLayer())
1317 row->paintOutlineForRowIfNeeded(paintInfo, paintOffset);
jchaffraix@webkit.org7e3f5d42012-02-28 01:05:10 +00001318 for (unsigned c = dirtiedColumns.start(); c < dirtiedColumns.end(); c++) {
jamesr@google.com36623a32010-07-23 20:22:29 +00001319 CellStruct& current = cellAt(r, c);
jamesr@google.comb4266232010-07-28 20:07:19 +00001320 if (!current.hasCells())
jamesr@google.com36623a32010-07-23 20:22:29 +00001321 continue;
1322 for (unsigned i = 0; i < current.cells.size(); ++i) {
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001323 if (m_overflowingCells.contains(current.cells[i]))
1324 continue;
1325
jamesr@google.com36623a32010-07-23 20:22:29 +00001326 if (current.cells[i]->rowSpan() > 1 || current.cells[i]->colSpan() > 1) {
rafael.lobo@openbossa.org61c47ed2013-05-31 00:53:31 +00001327 if (!spanningCells.add(current.cells[i]).isNewEntry)
jamesr@google.com36623a32010-07-23 20:22:29 +00001328 continue;
jamesr@google.com36623a32010-07-23 20:22:29 +00001329 }
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001330
jamesr@google.com36623a32010-07-23 20:22:29 +00001331 cells.append(current.cells[i]);
1332 }
1333 }
1334 }
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001335
jamesr@google.com36623a32010-07-23 20:22:29 +00001336 // Sort the dirty cells by paint order.
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001337 if (!m_overflowingCells.size())
1338 std::stable_sort(cells.begin(), cells.end(), compareCellPositions);
1339 else
1340 std::sort(cells.begin(), cells.end(), compareCellPositionsWithOverflowingCells);
1341
robert@webkit.org2d408272011-12-19 19:49:27 +00001342 if (paintInfo.phase == PaintPhaseCollapsedTableBorders) {
1343 for (unsigned i = cells.size(); i > 0; --i) {
1344 LayoutPoint cellPoint = flipForWritingModeForChild(cells[i - 1], paintOffset);
1345 cells[i - 1]->paintCollapsedBorders(paintInfo, cellPoint);
1346 }
1347 } else {
1348 for (unsigned i = 0; i < cells.size(); ++i)
1349 paintCell(cells[i], paintInfo, paintOffset);
1350 }
ap50b58352006-01-22 20:32:36 +00001351 }
eseidela043f3d2006-01-20 19:24:53 +00001352 }
1353}
1354
darin@apple.com98a7ac62009-01-05 17:26:53 +00001355void RenderTableSection::imageChanged(WrappedImagePtr, const IntRect*)
bdashb07ae8d2007-02-08 04:56:20 +00001356{
bdashb07ae8d2007-02-08 04:56:20 +00001357 // FIXME: Examine cells and repaint only the rect the image paints in.
1358 repaint();
1359}
1360
eseidela043f3d2006-01-20 19:24:53 +00001361void RenderTableSection::recalcCells()
1362{
jchaffraix@webkit.orgb86b64e2011-11-14 21:21:43 +00001363 ASSERT(m_needsCellRecalc);
1364 // We reset the flag here to ensure that |addCell| works. This is safe to do as
1365 // fillRowsWithDefaultStartingAtPosition makes sure we match the table's columns
1366 // representation.
1367 m_needsCellRecalc = false;
1368
ddkilzer260f3d22007-01-05 05:56:31 +00001369 m_cCol = 0;
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +00001370 m_cRow = 0;
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +00001371 m_grid.clear();
eseidela043f3d2006-01-20 19:24:53 +00001372
antti@apple.com7f9196b2013-09-24 20:47:01 +00001373 for (RenderTableRow* row = firstRow(); row; row = row->nextRow()) {
1374 unsigned insertionRow = m_cRow;
1375 m_cRow++;
1376 m_cCol = 0;
1377 ensureRows(m_cRow);
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +00001378
antti@apple.com7f9196b2013-09-24 20:47:01 +00001379 m_grid[insertionRow].rowRenderer = row;
1380 row->setRowIndex(insertionRow);
1381 setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[insertionRow]);
eseidel05ef0432006-05-25 22:11:36 +00001382
antti@apple.com7f9196b2013-09-24 20:47:01 +00001383 for (RenderTableCell* cell = row->firstCell(); cell; cell = cell->nextCell())
1384 addCell(cell, row);
eseidela043f3d2006-01-20 19:24:53 +00001385 }
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +00001386
jchaffraix@webkit.orge98e3e52011-11-11 01:41:26 +00001387 m_grid.shrinkToFit();
antti@apple.comca2a8ff2013-10-04 04:04:35 +00001388 setNeedsLayout();
eseidela043f3d2006-01-20 19:24:53 +00001389}
1390
jchaffraix@webkit.org74857b42011-12-20 14:08:52 +00001391// FIXME: This function could be made O(1) in certain cases (like for the non-most-constrainive cells' case).
jchaffraix@webkit.org19bbb722011-11-03 17:20:01 +00001392void RenderTableSection::rowLogicalHeightChanged(unsigned rowIndex)
1393{
jchaffraix@webkit.orgdd34df42012-01-24 04:15:06 +00001394 if (needsCellRecalc())
1395 return;
1396
jchaffraix@webkit.org19bbb722011-11-03 17:20:01 +00001397 setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[rowIndex]);
jchaffraix@webkit.org74857b42011-12-20 14:08:52 +00001398
antti@apple.com7f9196b2013-09-24 20:47:01 +00001399 for (RenderTableCell* cell = m_grid[rowIndex].rowRenderer->firstCell(); cell; cell = cell->nextCell())
1400 updateLogicalHeightForCell(m_grid[rowIndex], cell);
jchaffraix@webkit.org19bbb722011-11-03 17:20:01 +00001401}
1402
jamesr@google.com5ddfb042011-01-20 21:34:34 +00001403void RenderTableSection::setNeedsCellRecalc()
1404{
1405 m_needsCellRecalc = true;
1406 if (RenderTable* t = table())
1407 t->setNeedsSectionRecalc();
1408}
1409
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +00001410unsigned RenderTableSection::numColumns() const
ap50b58352006-01-22 20:32:36 +00001411{
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +00001412 unsigned result = 0;
ap50b58352006-01-22 20:32:36 +00001413
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +00001414 for (unsigned r = 0; r < m_grid.size(); ++r) {
jchaffraix@webkit.org369c5d32011-10-28 01:28:58 +00001415 for (unsigned c = result; c < table()->numEffCols(); ++c) {
ap50b58352006-01-22 20:32:36 +00001416 const CellStruct& cell = cellAt(r, c);
jamesr@google.com36623a32010-07-23 20:22:29 +00001417 if (cell.hasCells() || cell.inColSpan)
ap50b58352006-01-22 20:32:36 +00001418 result = c;
1419 }
1420 }
1421
1422 return result + 1;
eseidela043f3d2006-01-20 19:24:53 +00001423}
1424
jchaffraix@webkit.orgec614042012-09-20 00:58:58 +00001425const BorderValue& RenderTableSection::borderAdjoiningStartCell(const RenderTableCell* cell) const
1426{
jchaffraix@webkit.org6d6c3052012-11-05 07:55:28 +00001427 ASSERT(cell->isFirstOrLastCellInRow());
akling@apple.com827be9c2013-10-29 02:58:43 +00001428 return hasSameDirectionAs(cell) ? style().borderStart() : style().borderEnd();
jchaffraix@webkit.orgec614042012-09-20 00:58:58 +00001429}
1430
1431const BorderValue& RenderTableSection::borderAdjoiningEndCell(const RenderTableCell* cell) const
1432{
jchaffraix@webkit.org6d6c3052012-11-05 07:55:28 +00001433 ASSERT(cell->isFirstOrLastCellInRow());
akling@apple.com827be9c2013-10-29 02:58:43 +00001434 return hasSameDirectionAs(cell) ? style().borderEnd() : style().borderStart();
jchaffraix@webkit.orgec614042012-09-20 00:58:58 +00001435}
1436
jchaffraix@webkit.orgceaacec2012-06-01 20:15:01 +00001437const RenderTableCell* RenderTableSection::firstRowCellAdjoiningTableStart() const
1438{
jchaffraix@webkit.orgec614042012-09-20 00:58:58 +00001439 unsigned adjoiningStartCellColumnIndex = hasSameDirectionAs(table()) ? 0 : table()->lastColumnIndex();
jchaffraix@webkit.org4b5292a2012-06-06 16:07:16 +00001440 return cellAt(0, adjoiningStartCellColumnIndex).primaryCell();
jchaffraix@webkit.orgceaacec2012-06-01 20:15:01 +00001441}
1442
1443const RenderTableCell* RenderTableSection::firstRowCellAdjoiningTableEnd() const
1444{
jchaffraix@webkit.orgec614042012-09-20 00:58:58 +00001445 unsigned adjoiningEndCellColumnIndex = hasSameDirectionAs(table()) ? table()->lastColumnIndex() : 0;
jchaffraix@webkit.org4b5292a2012-06-06 16:07:16 +00001446 return cellAt(0, adjoiningEndCellColumnIndex).primaryCell();
jchaffraix@webkit.orgceaacec2012-06-01 20:15:01 +00001447}
1448
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +00001449void RenderTableSection::appendColumn(unsigned pos)
ddkilzer260f3d22007-01-05 05:56:31 +00001450{
jchaffraix@webkit.orgb86b64e2011-11-14 21:21:43 +00001451 ASSERT(!m_needsCellRecalc);
1452
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +00001453 for (unsigned row = 0; row < m_grid.size(); ++row)
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +00001454 m_grid[row].row.resize(pos + 1);
ddkilzer260f3d22007-01-05 05:56:31 +00001455}
1456
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +00001457void RenderTableSection::splitColumn(unsigned pos, unsigned first)
ddkilzer260f3d22007-01-05 05:56:31 +00001458{
inferno@chromium.orgb1ffad72011-10-10 18:58:12 +00001459 ASSERT(!m_needsCellRecalc);
1460
ddkilzer260f3d22007-01-05 05:56:31 +00001461 if (m_cCol > pos)
1462 m_cCol++;
jchaffraix@webkit.org68d3b572011-10-27 19:12:39 +00001463 for (unsigned row = 0; row < m_grid.size(); ++row) {
jchaffraix@webkit.org9fb80752011-10-28 18:04:14 +00001464 Row& r = m_grid[row].row;
jamesr@google.com36623a32010-07-23 20:22:29 +00001465 r.insert(pos + 1, CellStruct());
1466 if (r[pos].hasCells()) {
andersca@apple.com92012992013-05-05 19:03:49 +00001467 r[pos + 1].cells.appendVector(r[pos].cells);
jamesr@google.com36623a32010-07-23 20:22:29 +00001468 RenderTableCell* cell = r[pos].primaryCell();
1469 ASSERT(cell);
commit-queue@webkit.org1ee5b342012-05-08 05:14:07 +00001470 ASSERT(cell->colSpan() >= (r[pos].inColSpan ? 1u : 0));
jchaffraix@webkit.orgfb2a8602011-11-16 02:03:54 +00001471 unsigned colleft = cell->colSpan() - r[pos].inColSpan;
jamesr@google.com36623a32010-07-23 20:22:29 +00001472 if (first > colleft)
1473 r[pos + 1].inColSpan = 0;
1474 else
1475 r[pos + 1].inColSpan = first + r[pos].inColSpan;
1476 } else {
1477 r[pos + 1].inColSpan = 0;
1478 }
ddkilzer260f3d22007-01-05 05:56:31 +00001479 }
1480}
1481
hyattd866e592006-03-17 09:50:35 +00001482// Hit Testing
allan.jensen@nokia.com9a9045b2012-08-28 09:41:54 +00001483bool RenderTableSection::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action)
hyattd866e592006-03-17 09:50:35 +00001484{
jamesr@google.comf88b2582010-08-17 20:57:15 +00001485 // If we have no children then we have nothing to do.
antti@apple.com7f9196b2013-09-24 20:47:01 +00001486 if (!firstRow())
jamesr@google.comf88b2582010-08-17 20:57:15 +00001487 return false;
1488
hyattd866e592006-03-17 09:50:35 +00001489 // Table sections cannot ever be hit tested. Effectively they do not exist.
1490 // Just forward to our children always.
eae@chromium.orge14cd1a2011-07-06 23:38:32 +00001491 LayoutPoint adjustedLocation = accumulatedOffset + location();
hyattd866e592006-03-17 09:50:35 +00001492
allan.jensen@nokia.com9a9045b2012-08-28 09:41:54 +00001493 if (hasOverflowClip() && !locationInContainer.intersects(overflowClipRect(adjustedLocation, locationInContainer.region())))
hyatt@apple.comfe52f5b2009-02-25 01:21:03 +00001494 return false;
1495
jchaffraix@webkit.orgf4ce0502011-08-18 20:20:57 +00001496 if (hasOverflowingCell()) {
antti@apple.com7f9196b2013-09-24 20:47:01 +00001497 for (RenderTableRow* row = lastRow(); row; row = row->previousRow()) {
jamesr@google.comf88b2582010-08-17 20:57:15 +00001498 // FIXME: We have to skip over inline flows, since they can show up inside table rows
1499 // at the moment (a demoted inline <form> for example). If we ever implement a
1500 // table-specific hit-test method (which we should do for performance reasons anyway),
1501 // then we can remove this check.
antti@apple.comd04c0812013-09-25 17:45:59 +00001502 if (!row->hasSelfPaintingLayer()) {
antti@apple.com7f9196b2013-09-24 20:47:01 +00001503 LayoutPoint childPoint = flipForWritingModeForChild(row, adjustedLocation);
1504 if (row->nodeAtPoint(request, result, locationInContainer, childPoint, action)) {
allan.jensen@nokia.com9a9045b2012-08-28 09:41:54 +00001505 updateHitTestResult(result, toLayoutPoint(locationInContainer.point() - childPoint));
mitz@apple.com39fb3ae2010-11-09 20:46:15 +00001506 return true;
1507 }
jamesr@google.comf88b2582010-08-17 20:57:15 +00001508 }
1509 }
1510 return false;
1511 }
1512
inferno@chromium.org9c8b2302012-02-21 19:10:05 +00001513 recalcCellsIfNeeded();
1514
allan.jensen@nokia.com9a9045b2012-08-28 09:41:54 +00001515 LayoutRect hitTestRect = locationInContainer.boundingBox();
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001516 hitTestRect.moveBy(-adjustedLocation);
jamesr@google.comf88b2582010-08-17 20:57:15 +00001517
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001518 LayoutRect tableAlignedRect = logicalRectForWritingModeAndDirection(hitTestRect);
1519 CellSpan rowSpan = spannedRows(tableAlignedRect);
1520 CellSpan columnSpan = spannedColumns(tableAlignedRect);
jamesr@google.comf88b2582010-08-17 20:57:15 +00001521
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001522 // Now iterate over the spanned rows and columns.
1523 for (unsigned hitRow = rowSpan.start(); hitRow < rowSpan.end(); ++hitRow) {
1524 for (unsigned hitColumn = columnSpan.start(); hitColumn < columnSpan.end(); ++hitColumn) {
1525 CellStruct& current = cellAt(hitRow, hitColumn);
jamesr@google.comf88b2582010-08-17 20:57:15 +00001526
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001527 // If the cell is empty, there's nothing to do
1528 if (!current.hasCells())
1529 continue;
jamesr@google.comf88b2582010-08-17 20:57:15 +00001530
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001531 for (unsigned i = current.cells.size() ; i; ) {
1532 --i;
1533 RenderTableCell* cell = current.cells[i];
1534 LayoutPoint cellPoint = flipForWritingModeForChild(cell, adjustedLocation);
allan.jensen@nokia.com9a9045b2012-08-28 09:41:54 +00001535 if (static_cast<RenderObject*>(cell)->nodeAtPoint(request, result, locationInContainer, cellPoint, action)) {
1536 updateHitTestResult(result, locationInContainer.point() - toLayoutSize(cellPoint));
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001537 return true;
1538 }
1539 }
1540 if (!result.isRectBasedTest())
1541 break;
hyattd866e592006-03-17 09:50:35 +00001542 }
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001543 if (!result.isRectBasedTest())
1544 break;
hyattd866e592006-03-17 09:50:35 +00001545 }
jamesr@google.comf88b2582010-08-17 20:57:15 +00001546
commit-queue@webkit.orgbe3795c2012-06-11 09:38:48 +00001547 return false;
hyattd866e592006-03-17 09:50:35 +00001548}
1549
robert@webkit.org76a76102012-01-15 13:48:45 +00001550void RenderTableSection::removeCachedCollapsedBorders(const RenderTableCell* cell)
1551{
1552 if (!table()->collapseBorders())
1553 return;
1554
1555 for (int side = CBSBefore; side <= CBSEnd; ++side)
andersca@apple.com86298632013-11-10 19:32:33 +00001556 m_cellsCollapsedBorders.remove(std::make_pair(cell, side));
robert@webkit.org76a76102012-01-15 13:48:45 +00001557}
1558
1559void RenderTableSection::setCachedCollapsedBorder(const RenderTableCell* cell, CollapsedBorderSide side, CollapsedBorderValue border)
1560{
1561 ASSERT(table()->collapseBorders());
andersca@apple.com86298632013-11-10 19:32:33 +00001562 m_cellsCollapsedBorders.set(std::make_pair(cell, side), border);
robert@webkit.org76a76102012-01-15 13:48:45 +00001563}
1564
1565CollapsedBorderValue& RenderTableSection::cachedCollapsedBorder(const RenderTableCell* cell, CollapsedBorderSide side)
1566{
1567 ASSERT(table()->collapseBorders());
zandobersek@gmail.com83a31192014-01-04 17:26:52 +00001568 HashMap<std::pair<const RenderTableCell*, int>, CollapsedBorderValue>::iterator it = m_cellsCollapsedBorders.find(std::make_pair(cell, side));
robert@webkit.org76a76102012-01-15 13:48:45 +00001569 ASSERT(it != m_cellsCollapsedBorders.end());
benjamin@webkit.orgee554052012-10-07 23:12:07 +00001570 return it->value;
robert@webkit.org76a76102012-01-15 13:48:45 +00001571}
1572
inferno@chromium.org2164c612012-04-04 22:41:56 +00001573RenderTableSection* RenderTableSection::createAnonymousWithParentRenderer(const RenderObject* parent)
1574{
akling@apple.com827be9c2013-10-29 02:58:43 +00001575 auto section = new RenderTableSection(parent->document(), RenderStyle::createAnonymousStyleWithDisplay(&parent->style(), TABLE_ROW_GROUP));
akling@apple.com8f40c5b2013-10-27 22:54:07 +00001576 section->initializeStyle();
1577 return section;
inferno@chromium.org2164c612012-04-04 22:41:56 +00001578}
1579
jchaffraix@webkit.org4b5292a2012-06-06 16:07:16 +00001580void RenderTableSection::setLogicalPositionForCell(RenderTableCell* cell, unsigned effectiveColumn) const
1581{
eae@chromium.org1146f212012-07-18 22:06:34 +00001582 LayoutPoint oldCellLocation = cell->location();
jchaffraix@webkit.org4b5292a2012-06-06 16:07:16 +00001583
1584 LayoutPoint cellLocation(0, m_rowPos[cell->rowIndex()]);
1585 int horizontalBorderSpacing = table()->hBorderSpacing();
1586
jchaffraix@webkit.org6d6c3052012-11-05 07:55:28 +00001587 // FIXME: The table's direction should determine our row's direction, not the section's (see bug 96691).
akling@apple.com827be9c2013-10-29 02:58:43 +00001588 if (!style().isLeftToRightDirection())
jchaffraix@webkit.org4b5292a2012-06-06 16:07:16 +00001589 cellLocation.setX(table()->columnPositions()[table()->numEffCols()] - table()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + horizontalBorderSpacing);
1590 else
1591 cellLocation.setX(table()->columnPositions()[effectiveColumn] + horizontalBorderSpacing);
1592
1593 cell->setLogicalLocation(cellLocation);
akling@apple.com691cf5c2013-08-24 16:33:15 +00001594 view().addLayoutDelta(oldCellLocation - cell->location());
jchaffraix@webkit.org4b5292a2012-06-06 16:07:16 +00001595}
1596
ddkilzer260f3d22007-01-05 05:56:31 +00001597} // namespace WebCore