darin@apple.com | 8383315 | 2008-01-14 17:51:10 +0000 | [diff] [blame] | 1 | /* |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 2 | * Copyright (C) 1997 Martin Jones (mjones@kde.org) |
| 3 | * (C) 1997 Torben Weis (weis@kde.org) |
| 4 | * (C) 1998 Waldo Bastian (bastian@kde.org) |
| 5 | * (C) 1999 Lars Knoll (knoll@kde.org) |
| 6 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 7 | * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved. |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 8 | * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 9 | * |
| 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 |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 22 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 23 | * Boston, MA 02110-1301, USA. |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "RenderTableSection.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 28 | #include "Document.h" |
tonikitoo@webkit.org | 81c027d | 2010-07-29 13:19:43 +0000 | [diff] [blame] | 29 | #include "HitTestResult.h" |
darin | 98fa8b8 | 2006-03-20 08:03:57 +0000 | [diff] [blame] | 30 | #include "HTMLNames.h" |
tonyg@chromium.org | b138b1e | 2011-01-15 00:27:07 +0000 | [diff] [blame] | 31 | #include "PaintInfo.h" |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 32 | #include "RenderTableCell.h" |
| 33 | #include "RenderTableCol.h" |
| 34 | #include "RenderTableRow.h" |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 35 | #include "RenderView.h" |
commit-queue@webkit.org | d0c076d | 2012-08-22 22:25:59 +0000 | [diff] [blame] | 36 | #include "StyleInheritedData.h" |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 37 | #include <limits> |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 38 | #include <wtf/HashSet.h> |
andersca@apple.com | a5fb7da | 2013-04-16 19:57:36 +0000 | [diff] [blame] | 39 | #include <wtf/StackStats.h> |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 40 | |
| 41 | namespace WebCore { |
| 42 | |
| 43 | using namespace HTMLNames; |
| 44 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 45 | // Those 2 variables are used to balance the memory consumption vs the repaint time on big tables. |
| 46 | static unsigned gMinTableSizeToUseFastPaintPathWithOverflowingCell = 75 * 75; |
| 47 | static float gMaxAllowedOverflowingCellRatioForFastPaintPath = 0.1f; |
| 48 | |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 49 | static inline void setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(RenderTableSection::RowStruct& row) |
dbates@webkit.org | e113183 | 2009-11-19 00:05:57 +0000 | [diff] [blame] | 50 | { |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 51 | ASSERT(row.rowRenderer); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 52 | row.logicalHeight = row.rowRenderer->style().logicalHeight(); |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 53 | if (row.logicalHeight.isRelative()) |
| 54 | row.logicalHeight = Length(); |
dbates@webkit.org | e113183 | 2009-11-19 00:05:57 +0000 | [diff] [blame] | 55 | } |
| 56 | |
jchaffraix@webkit.org | 74857b4 | 2011-12-20 14:08:52 +0000 | [diff] [blame] | 57 | static 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.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 63 | Length logicalHeight = cell->style().logicalHeight(); |
jchaffraix@webkit.org | 74857b4 | 2011-12-20 14:08:52 +0000 | [diff] [blame] | 64 | 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.com | 8f40c5b | 2013-10-27 22:54:07 +0000 | [diff] [blame] | 84 | RenderTableSection::RenderTableSection(Element& element, PassRef<RenderStyle> style) |
| 85 | : RenderBox(element, std::move(style), 0) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 86 | , m_cCol(0) |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 87 | , m_cRow(0) |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 88 | , m_outerBorderStart(0) |
| 89 | , m_outerBorderEnd(0) |
| 90 | , m_outerBorderBefore(0) |
| 91 | , m_outerBorderAfter(0) |
simon.fraser@apple.com | 8536250 | 2009-05-08 01:23:32 +0000 | [diff] [blame] | 92 | , m_needsCellRecalc(false) |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 93 | , m_hasMultipleCellLevels(false) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 94 | { |
akling@apple.com | 42e1063 | 2013-10-14 17:55:52 +0000 | [diff] [blame] | 95 | setInline(false); |
| 96 | } |
| 97 | |
akling@apple.com | 8f40c5b | 2013-10-27 22:54:07 +0000 | [diff] [blame] | 98 | RenderTableSection::RenderTableSection(Document& document, PassRef<RenderStyle> style) |
| 99 | : RenderBox(document, std::move(style), 0) |
akling@apple.com | 42e1063 | 2013-10-14 17:55:52 +0000 | [diff] [blame] | 100 | , 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); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | RenderTableSection::~RenderTableSection() |
| 113 | { |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 114 | } |
| 115 | |
inferno@chromium.org | a7f719f | 2011-09-06 01:45:39 +0000 | [diff] [blame] | 116 | void RenderTableSection::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
| 117 | { |
| 118 | RenderBox::styleDidChange(diff, oldStyle); |
antti@apple.com | cf4adae | 2013-09-24 00:55:44 +0000 | [diff] [blame] | 119 | propagateStyleToAnonymousChildren(PropagateToAllChildren); |
jchaffraix@webkit.org | 38e74af | 2011-09-23 19:56:21 +0000 | [diff] [blame] | 120 | |
| 121 | // If border was changed, notify table. |
| 122 | RenderTable* table = this->table(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 123 | if (table && !table->selfNeedsLayout() && !table->normalChildNeedsLayout() && oldStyle && oldStyle->border() != style().border()) |
jchaffraix@webkit.org | 38e74af | 2011-09-23 19:56:21 +0000 | [diff] [blame] | 124 | table->invalidateCollapsedBorders(); |
inferno@chromium.org | a7f719f | 2011-09-06 01:45:39 +0000 | [diff] [blame] | 125 | } |
| 126 | |
jchaffraix@webkit.org | 54b0e09 | 2012-08-22 02:16:02 +0000 | [diff] [blame] | 127 | void RenderTableSection::willBeRemovedFromTree() |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 128 | { |
jchaffraix@webkit.org | 54b0e09 | 2012-08-22 02:16:02 +0000 | [diff] [blame] | 129 | 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(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 134 | } |
| 135 | |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 136 | void RenderTableSection::addChild(RenderObject* child, RenderObject* beforeChild) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 137 | { |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 138 | if (!child->isTableRow()) { |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 139 | RenderObject* last = beforeChild; |
| 140 | if (!last) |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 141 | last = lastRow(); |
inferno@chromium.org | a7f719f | 2011-09-06 01:45:39 +0000 | [diff] [blame] | 142 | if (last && last->isAnonymous() && !last->isBeforeOrAfterContent()) { |
antti@apple.com | dc54c7e | 2013-09-23 19:32:15 +0000 | [diff] [blame] | 143 | RenderTableRow* row = toRenderTableRow(last); |
| 144 | if (beforeChild == row) |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 145 | beforeChild = row->firstCell(); |
antti@apple.com | dc54c7e | 2013-09-23 19:32:15 +0000 | [diff] [blame] | 146 | row->addChild(child, beforeChild); |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 147 | return; |
| 148 | } |
| 149 | |
inferno@chromium.org | b1ffad7 | 2011-10-10 18:58:12 +0000 | [diff] [blame] | 150 | if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == this) { |
| 151 | RenderObject* row = beforeChild->previousSibling(); |
fsamuel@chromium.org | fc34e99 | 2011-10-25 19:10:58 +0000 | [diff] [blame] | 152 | if (row && row->isTableRow() && row->isAnonymous()) { |
antti@apple.com | 43afcf7 | 2013-09-20 11:44:17 +0000 | [diff] [blame] | 153 | toRenderTableRow(row)->addChild(child); |
inferno@chromium.org | b1ffad7 | 2011-10-10 18:58:12 +0000 | [diff] [blame] | 154 | return; |
| 155 | } |
| 156 | } |
| 157 | |
darin | 10ab135 | 2006-01-29 01:29:33 +0000 | [diff] [blame] | 158 | // If beforeChild is inside an anonymous cell/row, insert into the cell or into |
| 159 | // the anonymous row containing it, if there is one. |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 160 | RenderObject* lastBox = last; |
| 161 | while (lastBox && lastBox->parent()->isAnonymous() && !lastBox->isTableRow()) |
| 162 | lastBox = lastBox->parent(); |
inferno@chromium.org | a7f719f | 2011-09-06 01:45:39 +0000 | [diff] [blame] | 163 | if (lastBox && lastBox->isAnonymous() && !lastBox->isBeforeOrAfterContent()) { |
antti@apple.com | 43afcf7 | 2013-09-20 11:44:17 +0000 | [diff] [blame] | 164 | toRenderTableRow(lastBox)->addChild(child, beforeChild); |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 165 | return; |
| 166 | } |
| 167 | |
antti@apple.com | 43afcf7 | 2013-09-20 11:44:17 +0000 | [diff] [blame] | 168 | RenderTableRow* row = RenderTableRow::createAnonymousWithParentRenderer(this); |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 169 | addChild(row, beforeChild); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 170 | row->addChild(child); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 171 | return; |
| 172 | } |
| 173 | |
| 174 | if (beforeChild) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 175 | setNeedsCellRecalc(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 176 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 177 | unsigned insertionRow = m_cRow; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 178 | ++m_cRow; |
| 179 | m_cCol = 0; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 180 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 181 | ensureRows(m_cRow); |
lars | b5288ad | 2007-01-13 18:48:29 +0000 | [diff] [blame] | 182 | |
jchaffraix@webkit.org | a0177fd | 2012-05-01 03:13:06 +0000 | [diff] [blame] | 183 | RenderTableRow* row = toRenderTableRow(child); |
| 184 | m_grid[insertionRow].rowRenderer = row; |
| 185 | row->setRowIndex(insertionRow); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 186 | |
dbates@webkit.org | e113183 | 2009-11-19 00:05:57 +0000 | [diff] [blame] | 187 | if (!beforeChild) |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 188 | setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[insertionRow]); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 189 | |
inferno@chromium.org | a8d7192 | 2012-04-09 16:03:46 +0000 | [diff] [blame] | 190 | if (beforeChild && beforeChild->parent() != this) |
| 191 | beforeChild = splitAnonymousBoxesAroundChild(beforeChild); |
mjs | 6666eee7 | 2006-07-14 07:45:13 +0000 | [diff] [blame] | 192 | |
bdakin@apple.com | 40ae9be | 2009-04-16 20:48:19 +0000 | [diff] [blame] | 193 | ASSERT(!beforeChild || beforeChild->isTableRow()); |
hyatt@apple.com | f073d9b | 2009-02-05 00:53:38 +0000 | [diff] [blame] | 194 | RenderBox::addChild(child, beforeChild); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 195 | } |
| 196 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 197 | void RenderTableSection::ensureRows(unsigned numRows) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 198 | { |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 199 | if (numRows <= m_grid.size()) |
| 200 | return; |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 201 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 202 | unsigned oldSize = m_grid.size(); |
| 203 | m_grid.grow(numRows); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 204 | |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 205 | unsigned effectiveColumnCount = std::max(1u, table()->numEffCols()); |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 206 | for (unsigned row = oldSize; row < m_grid.size(); ++row) |
akling@apple.com | 194ce1d | 2013-11-13 11:46:51 +0000 | [diff] [blame] | 207 | m_grid[row].row.resizeToFit(effectiveColumnCount); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 208 | } |
| 209 | |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 210 | void RenderTableSection::addCell(RenderTableCell* cell, RenderTableRow* row) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 211 | { |
jchaffraix@webkit.org | b86b64e | 2011-11-14 21:21:43 +0000 | [diff] [blame] | 212 | // 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.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 218 | unsigned rSpan = cell->rowSpan(); |
| 219 | unsigned cSpan = cell->colSpan(); |
jchaffraix@webkit.org | b87ce75 | 2012-10-15 21:52:22 +0000 | [diff] [blame] | 220 | const Vector<RenderTable::ColumnStruct>& columns = table()->columns(); |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 221 | unsigned nCols = columns.size(); |
jchaffraix@webkit.org | a0177fd | 2012-05-01 03:13:06 +0000 | [diff] [blame] | 222 | unsigned insertionRow = row->rowIndex(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 223 | |
| 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.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 230 | while (m_cCol < nCols && (cellAt(insertionRow, m_cCol).hasCells() || cellAt(insertionRow, m_cCol).inColSpan)) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 231 | m_cCol++; |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 232 | |
jchaffraix@webkit.org | 74857b4 | 2011-12-20 14:08:52 +0000 | [diff] [blame] | 233 | updateLogicalHeightForCell(m_grid[insertionRow], cell); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 234 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 235 | ensureRows(insertionRow + rSpan); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 236 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 237 | m_grid[insertionRow].rowRenderer = row; |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 238 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 239 | unsigned col = m_cCol; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 240 | // tell the cell where it is |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 241 | bool inColSpan = false; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 242 | while (cSpan) { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 243 | unsigned currentSpan; |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 244 | if (m_cCol >= nCols) { |
| 245 | table()->appendColumn(cSpan); |
| 246 | currentSpan = cSpan; |
| 247 | } else { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 248 | if (cSpan < columns[m_cCol].span) |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 249 | table()->splitColumn(m_cCol, cSpan); |
| 250 | currentSpan = columns[m_cCol].span; |
| 251 | } |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 252 | for (unsigned r = 0; r < rSpan; r++) { |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 253 | CellStruct& c = cellAt(insertionRow + r, m_cCol); |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 254 | 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; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 265 | } |
eric@webkit.org | 5832ab7 | 2009-03-25 22:15:03 +0000 | [diff] [blame] | 266 | cell->setCol(table()->effColToCol(col)); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 267 | } |
| 268 | |
eae@chromium.org | 351bc64 | 2012-02-08 05:37:54 +0000 | [diff] [blame] | 269 | int RenderTableSection::calcRowLogicalHeight() |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 270 | { |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 271 | #ifndef NDEBUG |
ojan@chromium.org | ccdc429 | 2013-02-07 00:55:10 +0000 | [diff] [blame] | 272 | SetLayoutNeededForbiddenScope layoutForbiddenScope(this); |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 273 | #endif |
| 274 | |
| 275 | ASSERT(!needsLayout()); |
| 276 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 277 | RenderTableCell* cell; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 278 | |
ossy@webkit.org | cf6bebb | 2013-11-25 14:57:38 +0000 | [diff] [blame] | 279 | // 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.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 283 | |
weinig@apple.com | f8d77f3 | 2013-11-18 01:12:17 +0000 | [diff] [blame] | 284 | LayoutStateMaintainer statePusher(view()); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 285 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 286 | m_rowPos.resize(m_grid.size() + 1); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 287 | m_rowPos[0] = spacing; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 288 | |
commit-queue@webkit.org | 1fdc04c | 2013-04-23 06:36:45 +0000 | [diff] [blame] | 289 | unsigned totalRows = m_grid.size(); |
| 290 | |
| 291 | for (unsigned r = 0; r < totalRows; r++) { |
zimmermann@webkit.org | 14b310a | 2012-02-25 09:27:25 +0000 | [diff] [blame] | 292 | m_grid[r].baseline = 0; |
leviw@chromium.org | 2650e38 | 2012-04-04 10:37:36 +0000 | [diff] [blame] | 293 | LayoutUnit baselineDescent = 0; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 294 | |
jchaffraix@webkit.org | addd65e | 2012-02-26 00:19:22 +0000 | [diff] [blame] | 295 | // Our base size is the biggest logical height from our cells' styles (excluding row spanning cells). |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 296 | m_rowPos[r + 1] = std::max(m_rowPos[r] + minimumValueForLength(m_grid[r].logicalHeight, 0).round(), 0); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 297 | |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 298 | Row& row = m_grid[r].row; |
| 299 | unsigned totalCols = row.size(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 300 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 301 | for (unsigned c = 0; c < totalCols; c++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 302 | CellStruct& current = cellAt(r, c); |
commit-queue@webkit.org | 5ec57ca | 2012-07-12 22:33:36 +0000 | [diff] [blame] | 303 | 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.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 307 | |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 308 | // 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.org | 1fdc04c | 2013-04-23 06:36:45 +0000 | [diff] [blame] | 315 | |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 316 | // 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.org | 1fdc04c | 2013-04-23 06:36:45 +0000 | [diff] [blame] | 323 | } |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 324 | |
| 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.org | 1fdc04c | 2013-04-23 06:36:45 +0000 | [diff] [blame] | 328 | } |
| 329 | } |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 330 | |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 331 | // For row spanning cells, |r| is the last row in the span. |
| 332 | unsigned cellStartRow = cell->rowIndex(); |
| 333 | |
commit-queue@webkit.org | 5ec57ca | 2012-07-12 22:33:36 +0000 | [diff] [blame] | 334 | 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.com | f8d77f3 | 2013-11-18 01:12:17 +0000 | [diff] [blame] | 338 | statePusher.push(*this, locationOffset()); |
commit-queue@webkit.org | 5ec57ca | 2012-07-12 22:33:36 +0000 | [diff] [blame] | 339 | } |
| 340 | cell->clearIntrinsicPadding(); |
| 341 | cell->clearOverrideSize(); |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 342 | cell->setChildNeedsLayout(MarkOnlyThis); |
commit-queue@webkit.org | 5ec57ca | 2012-07-12 22:33:36 +0000 | [diff] [blame] | 343 | cell->layoutIfNeeded(); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 344 | } |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 345 | |
commit-queue@webkit.org | 5ec57ca | 2012-07-12 22:33:36 +0000 | [diff] [blame] | 346 | int cellLogicalHeight = cell->logicalHeightForRowSizing(); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 347 | m_rowPos[r + 1] = std::max(m_rowPos[r + 1], m_rowPos[cellStartRow] + cellLogicalHeight); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 348 | |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 349 | // Find out the baseline. The baseline is set on the first row in a rowspan. |
robert@webkit.org | 292be54 | 2013-03-09 06:40:13 +0000 | [diff] [blame] | 350 | if (cell->isBaselineAligned()) { |
commit-queue@webkit.org | 5ec57ca | 2012-07-12 22:33:36 +0000 | [diff] [blame] | 351 | LayoutUnit baselinePosition = cell->cellBaselinePosition(); |
zoltan@webkit.org | 8e79cc2 | 2013-06-14 00:39:36 +0000 | [diff] [blame] | 352 | if (baselinePosition > cell->borderAndPaddingBefore()) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 353 | m_grid[cellStartRow].baseline = std::max(m_grid[cellStartRow].baseline, baselinePosition); |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 354 | // 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.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 359 | baselineDescent = std::max(baselineDescent, cellLogicalHeight - (baselinePosition - cell->intrinsicPaddingBefore())); |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 360 | cellStartRowBaselineDescent = baselineDescent; |
| 361 | } |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 362 | m_rowPos[cellStartRow + 1] = std::max<int>(m_rowPos[cellStartRow + 1], m_rowPos[cellStartRow] + m_grid[cellStartRow].baseline + cellStartRowBaselineDescent); |
commit-queue@webkit.org | 5ec57ca | 2012-07-12 22:33:36 +0000 | [diff] [blame] | 363 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 364 | } |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 365 | } |
| 366 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 367 | |
jchaffraix@webkit.org | addd65e | 2012-02-26 00:19:22 +0000 | [diff] [blame] | 368 | // Add the border-spacing to our final position. |
ossy@webkit.org | 6d30aa7 | 2013-11-28 17:40:59 +0000 | [diff] [blame] | 369 | // Use table border-spacing even in non-top sections |
| 370 | spacing = table()->vBorderSpacing(); |
jchaffraix@webkit.org | addd65e | 2012-02-26 00:19:22 +0000 | [diff] [blame] | 371 | m_rowPos[r + 1] += m_grid[r].rowRenderer ? spacing : 0; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 372 | m_rowPos[r + 1] = std::max(m_rowPos[r + 1], m_rowPos[r]); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 373 | } |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 374 | |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 375 | ASSERT(!needsLayout()); |
| 376 | |
simon.fraser@apple.com | feaef2e | 2008-11-07 19:17:08 +0000 | [diff] [blame] | 377 | statePusher.pop(); |
mitz@apple.com | 440ac8c | 2008-04-05 16:05:08 +0000 | [diff] [blame] | 378 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 379 | return m_rowPos[m_grid.size()]; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 380 | } |
| 381 | |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 382 | void RenderTableSection::layout() |
| 383 | { |
mark.lam@apple.com | 6df1a80 | 2012-10-19 20:09:36 +0000 | [diff] [blame] | 384 | StackStats::LayoutCheckPoint layoutCheckPoint; |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 385 | ASSERT(needsLayout()); |
inferno@chromium.org | 7081f50 | 2012-05-26 00:28:23 +0000 | [diff] [blame] | 386 | ASSERT(!needsCellRecalc()); |
| 387 | ASSERT(!table()->needsSectionRecalc()); |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 388 | |
jchaffraix@webkit.org | a9ddfc1 | 2012-06-18 17:11:12 +0000 | [diff] [blame] | 389 | // 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.com | f8d77f3 | 2013-11-18 01:12:17 +0000 | [diff] [blame] | 393 | LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode()); |
jchaffraix@webkit.org | a66f108 | 2012-10-16 16:42:02 +0000 | [diff] [blame] | 394 | |
| 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.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 417 | } |
jchaffraix@webkit.org | a66f108 | 2012-10-16 16:42:02 +0000 | [diff] [blame] | 418 | |
| 419 | if (RenderTableRow* rowRenderer = m_grid[r].rowRenderer) |
| 420 | rowRenderer->layoutIfNeeded(); |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 421 | } |
jchaffraix@webkit.org | a66f108 | 2012-10-16 16:42:02 +0000 | [diff] [blame] | 422 | |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 423 | statePusher.pop(); |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 424 | clearNeedsLayout(); |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 425 | } |
| 426 | |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 427 | void RenderTableSection::distributeExtraLogicalHeightToPercentRows(int& extraLogicalHeight, int totalPercent) |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 428 | { |
| 429 | if (!totalPercent) |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 430 | return; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 431 | |
| 432 | unsigned totalRows = m_grid.size(); |
| 433 | int totalHeight = m_rowPos[totalRows] + extraLogicalHeight; |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 434 | int totalLogicalHeightAdded = 0; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 435 | totalPercent = std::min(totalPercent, 100); |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 436 | 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.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 439 | int toAdd = std::min<int>(extraLogicalHeight, (totalHeight * m_grid[r].logicalHeight.percent() / 100) - rowHeight); |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 440 | // If toAdd is negative, then we don't want to shrink the row (this bug |
| 441 | // affected Outlook Web Access). |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 442 | toAdd = std::max(0, toAdd); |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 443 | totalLogicalHeightAdded += toAdd; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 444 | 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.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 450 | m_rowPos[r + 1] += totalLogicalHeightAdded; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 451 | } |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 452 | } |
| 453 | |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 454 | void RenderTableSection::distributeExtraLogicalHeightToAutoRows(int& extraLogicalHeight, unsigned autoRowsCount) |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 455 | { |
| 456 | if (!autoRowsCount) |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 457 | return; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 458 | |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 459 | int totalLogicalHeightAdded = 0; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 460 | 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.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 464 | totalLogicalHeightAdded += extraLogicalHeightForRow; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 465 | extraLogicalHeight -= extraLogicalHeightForRow; |
| 466 | --autoRowsCount; |
| 467 | } |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 468 | m_rowPos[r + 1] += totalLogicalHeightAdded; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 469 | } |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 470 | } |
| 471 | |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 472 | void RenderTableSection::distributeRemainingExtraLogicalHeight(int& extraLogicalHeight) |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 473 | { |
| 474 | unsigned totalRows = m_grid.size(); |
| 475 | |
| 476 | if (extraLogicalHeight <= 0 || !m_rowPos[totalRows]) |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 477 | return; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 478 | |
| 479 | // FIXME: m_rowPos[totalRows] - m_rowPos[0] is the total rows' size. |
| 480 | int totalRowSize = m_rowPos[totalRows]; |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 481 | int totalLogicalHeightAdded = 0; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 482 | int previousRowPosition = m_rowPos[0]; |
| 483 | for (unsigned r = 0; r < totalRows; r++) { |
| 484 | // weight with the original height |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 485 | totalLogicalHeightAdded += extraLogicalHeight * (m_rowPos[r + 1] - previousRowPosition) / totalRowSize; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 486 | previousRowPosition = m_rowPos[r + 1]; |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 487 | m_rowPos[r + 1] += totalLogicalHeightAdded; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 488 | } |
| 489 | |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 490 | extraLogicalHeight -= totalLogicalHeightAdded; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | int 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.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 515 | distributeExtraLogicalHeightToPercentRows(remainingExtraLogicalHeight, totalPercent); |
| 516 | distributeExtraLogicalHeightToAutoRows(remainingExtraLogicalHeight, autoRowsCount); |
| 517 | distributeRemainingExtraLogicalHeight(remainingExtraLogicalHeight); |
| 518 | return extraLogicalHeight - remainingExtraLogicalHeight; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 519 | } |
| 520 | |
jchaffraix@webkit.org | 94f150f | 2012-03-20 04:53:14 +0000 | [diff] [blame] | 521 | void RenderTableSection::layoutRows() |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 522 | { |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 523 | #ifndef NDEBUG |
ojan@chromium.org | ccdc429 | 2013-02-07 00:55:10 +0000 | [diff] [blame] | 524 | SetLayoutNeededForbiddenScope layoutForbiddenScope(this); |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 525 | #endif |
| 526 | |
| 527 | ASSERT(!needsLayout()); |
| 528 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 529 | unsigned totalRows = m_grid.size(); |
| 530 | |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 531 | // Set the width of our section now. The rows will also be this width. |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 532 | setLogicalWidth(table()->contentLogicalWidth()); |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 533 | m_forceSlowPaintPathWithOverflowingCell = false; |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 534 | |
eae@chromium.org | 351bc64 | 2012-02-08 05:37:54 +0000 | [diff] [blame] | 535 | int vspacing = table()->vBorderSpacing(); |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 536 | unsigned nEffCols = table()->numEffCols(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 537 | |
weinig@apple.com | f8d77f3 | 2013-11-18 01:12:17 +0000 | [diff] [blame] | 538 | LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || style().isFlippedBlocksWritingMode()); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 539 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 540 | for (unsigned r = 0; r < totalRows; r++) { |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 541 | // Set the row's x/y position and width/height. |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 542 | if (RenderTableRow* rowRenderer = m_grid[r].rowRenderer) { |
robert@webkit.org | f9766b1 | 2013-08-27 19:21:00 +0000 | [diff] [blame] | 543 | // 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.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 545 | rowRenderer->setLocation(LayoutPoint(0, m_rowPos[r])); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 546 | rowRenderer->setLogicalWidth(logicalWidth()); |
| 547 | rowRenderer->setLogicalHeight(m_rowPos[r + 1] - m_rowPos[r] - vspacing); |
simon.fraser@apple.com | 78e3bdb | 2010-11-30 00:53:05 +0000 | [diff] [blame] | 548 | rowRenderer->updateLayerTransform(); |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 549 | } |
| 550 | |
mitz@apple.com | 48b3ee8 | 2012-07-12 02:38:38 +0000 | [diff] [blame] | 551 | int rowHeightIncreaseForPagination = 0; |
| 552 | |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 553 | for (unsigned c = 0; c < nEffCols; c++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 554 | CellStruct& cs = cellAt(r, c); |
| 555 | RenderTableCell* cell = cs.primaryCell(); |
| 556 | |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 557 | if (!cell || cs.inColSpan) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 558 | continue; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 559 | |
jchaffraix@webkit.org | 83cb391 | 2012-10-05 03:56:17 +0000 | [diff] [blame] | 560 | int rowIndex = cell->rowIndex(); |
| 561 | int rHeight = m_rowPos[rowIndex + cell->rowSpan()] - m_rowPos[rowIndex] - vspacing; |
| 562 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 563 | // 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.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 577 | bool flexAllChildren = cell->style().logicalHeight().isFixed() |
| 578 | || (!table()->style().logicalHeight().isAuto() && rHeight != cell->logicalHeight()); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 579 | |
| 580 | for (RenderObject* o = cell->firstChild(); o; o = o->nextSibling()) { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 581 | if (!o->isText() && o->style().logicalHeight().isPercent() && (flexAllChildren || ((o->isReplaced() || (o->isBox() && toRenderBox(o)->scrollsOverflow())) && !o->isTextControl()))) { |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 582 | // Tables with no sections do not flex. |
darin@apple.com | 445c34f | 2009-08-01 00:40:58 +0000 | [diff] [blame] | 583 | if (!o->isTable() || toRenderTable(o)->hasSections()) { |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 584 | o->setNeedsLayout(MarkOnlyThis); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 585 | cellChildrenFlex = true; |
| 586 | } |
| 587 | } |
| 588 | } |
mitz@apple.com | 1547c6d | 2009-03-20 23:41:54 +0000 | [diff] [blame] | 589 | |
tony@chromium.org | 05b9d2c | 2012-09-05 01:31:38 +0000 | [diff] [blame] | 590 | if (TrackedRendererListHashSet* percentHeightDescendants = cell->percentHeightDescendants()) { |
| 591 | TrackedRendererListHashSet::iterator end = percentHeightDescendants->end(); |
| 592 | for (TrackedRendererListHashSet::iterator it = percentHeightDescendants->begin(); it != end; ++it) { |
mitz@apple.com | 1547c6d | 2009-03-20 23:41:54 +0000 | [diff] [blame] | 593 | 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.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 600 | box->setChildNeedsLayout(MarkOnlyThis); |
mitz@apple.com | 1547c6d | 2009-03-20 23:41:54 +0000 | [diff] [blame] | 601 | box = box->containingBlock(); |
| 602 | ASSERT(box); |
| 603 | if (!box) |
| 604 | break; |
| 605 | } |
| 606 | cellChildrenFlex = true; |
| 607 | } |
| 608 | } |
| 609 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 610 | if (cellChildrenFlex) { |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 611 | cell->setChildNeedsLayout(MarkOnlyThis); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 612 | // Alignment within a cell is based off the calculated |
| 613 | // height, which becomes irrelevant once the cell has |
hyatt@apple.com | 0bf6c84 | 2009-01-23 03:42:12 +0000 | [diff] [blame] | 614 | // been resized based off its percentage. |
ojan@chromium.org | 7a1ce8b | 2012-06-05 18:32:10 +0000 | [diff] [blame] | 615 | cell->setOverrideLogicalContentHeightFromRowHeight(rHeight); |
ap | 7332aaa | 2006-04-28 16:02:45 +0000 | [diff] [blame] | 616 | cell->layoutIfNeeded(); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 617 | |
hyatt | 851433b | 2007-05-12 06:40:14 +0000 | [diff] [blame] | 618 | // If the baseline moved, we may have to update the data for our row. Find out the new baseline. |
robert@webkit.org | 292be54 | 2013-03-09 06:40:13 +0000 | [diff] [blame] | 619 | if (cell->isBaselineAligned()) { |
leviw@chromium.org | 2650e38 | 2012-04-04 10:37:36 +0000 | [diff] [blame] | 620 | LayoutUnit baseline = cell->cellBaselinePosition(); |
zoltan@webkit.org | 8e79cc2 | 2013-06-14 00:39:36 +0000 | [diff] [blame] | 621 | if (baseline > cell->borderAndPaddingBefore()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 622 | m_grid[r].baseline = std::max(m_grid[r].baseline, baseline); |
hyatt | 851433b | 2007-05-12 06:40:14 +0000 | [diff] [blame] | 623 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 624 | } |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 625 | |
jchaffraix@webkit.org | 83cb391 | 2012-10-05 03:56:17 +0000 | [diff] [blame] | 626 | cell->computeIntrinsicPadding(rHeight); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 627 | |
eae@chromium.org | 1146f21 | 2012-07-18 22:06:34 +0000 | [diff] [blame] | 628 | LayoutRect oldCellRect = cell->frameRect(); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 629 | |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 630 | setLogicalPositionForCell(cell, c); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 631 | |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 632 | if (!cell->needsLayout() && view().layoutState()->pageLogicalHeight() && view().layoutState()->pageLogicalOffset(cell, cell->logicalTop()) != cell->pageLogicalOffset()) |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 633 | cell->setChildNeedsLayout(MarkOnlyThis); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 634 | |
hyatt@apple.com | 1259d73 | 2010-09-20 16:12:58 +0000 | [diff] [blame] | 635 | cell->layoutIfNeeded(); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 636 | |
| 637 | // FIXME: Make pagination work with vertical tables. |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 638 | if (view().layoutState()->pageLogicalHeight() && cell->logicalHeight() != rHeight) { |
hyatt@apple.com | 8403ad2 | 2012-04-10 18:14:20 +0000 | [diff] [blame] | 639 | // 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.com | 48b3ee8 | 2012-07-12 02:38:38 +0000 | [diff] [blame] | 642 | if (cell->logicalHeight() > rHeight) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 643 | rowHeightIncreaseForPagination = std::max<int>(rowHeightIncreaseForPagination, cell->logicalHeight() - rHeight); |
mitz@apple.com | 48b3ee8 | 2012-07-12 02:38:38 +0000 | [diff] [blame] | 644 | cell->setLogicalHeight(rHeight); |
hyatt@apple.com | 8403ad2 | 2012-04-10 18:14:20 +0000 | [diff] [blame] | 645 | } |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 646 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 647 | LayoutSize childOffset(cell->location() - oldCellRect.location()); |
hyatt@apple.com | b297b49 | 2010-09-20 20:21:34 +0000 | [diff] [blame] | 648 | if (childOffset.width() || childOffset.height()) { |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 649 | view().addLayoutDelta(childOffset); |
hyatt@apple.com | 1259d73 | 2010-09-20 16:12:58 +0000 | [diff] [blame] | 650 | |
hyatt@apple.com | b297b49 | 2010-09-20 20:21:34 +0000 | [diff] [blame] | 651 | // 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 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 657 | } |
mitz@apple.com | 48b3ee8 | 2012-07-12 02:38:38 +0000 | [diff] [blame] | 658 | 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 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 667 | } |
| 668 | |
hyatt@apple.com | 8b2cd1f | 2009-01-26 03:38:55 +0000 | [diff] [blame] | 669 | ASSERT(!needsLayout()); |
| 670 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 671 | setLogicalHeight(m_rowPos[totalRows]); |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 672 | |
robert@webkit.org | 4c91cc9 | 2013-03-27 23:49:48 +0000 | [diff] [blame] | 673 | computeOverflowFromCells(totalRows, nEffCols); |
| 674 | |
| 675 | statePusher.pop(); |
| 676 | } |
| 677 | |
| 678 | void RenderTableSection::computeOverflowFromCells() |
| 679 | { |
| 680 | unsigned totalRows = m_grid.size(); |
| 681 | unsigned nEffCols = table()->numEffCols(); |
| 682 | computeOverflowFromCells(totalRows, nEffCols); |
| 683 | } |
| 684 | |
| 685 | void RenderTableSection::computeOverflowFromCells(unsigned totalRows, unsigned nEffCols) |
| 686 | { |
abucur@adobe.com | 6585d01 | 2013-09-04 08:26:41 +0000 | [diff] [blame] | 687 | clearOverflow(); |
robert@webkit.org | e4314c4 | 2013-08-08 18:13:22 +0000 | [diff] [blame] | 688 | m_overflowingCells.clear(); |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 689 | unsigned totalCellsCount = nEffCols * totalRows; |
| 690 | int maxAllowedOverflowingCellsCount = totalCellsCount < gMinTableSizeToUseFastPaintPathWithOverflowingCell ? 0 : gMaxAllowedOverflowingCellRatioForFastPaintPath * totalCellsCount; |
| 691 | |
| 692 | #ifndef NDEBUG |
| 693 | bool hasOverflowingCell = false; |
| 694 | #endif |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 695 | // Now that our height has been determined, add in overflow from cells. |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 696 | for (unsigned r = 0; r < totalRows; r++) { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 697 | for (unsigned c = 0; c < nEffCols; c++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 698 | CellStruct& cs = cellAt(r, c); |
| 699 | RenderTableCell* cell = cs.primaryCell(); |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 700 | if (!cell || cs.inColSpan) |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 701 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 702 | if (r < totalRows - 1 && cell == primaryCellAt(r + 1, c)) |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 703 | continue; |
| 704 | addOverflowFromChild(cell); |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 705 | #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.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 717 | } |
| 718 | } |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 719 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 720 | ASSERT(hasOverflowingCell == this->hasOverflowingCell()); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 721 | } |
| 722 | |
eae@chromium.org | 351bc64 | 2012-02-08 05:37:54 +0000 | [diff] [blame] | 723 | int RenderTableSection::calcOuterBorderBefore() const |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 724 | { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 725 | unsigned totalCols = table()->numEffCols(); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 726 | if (!m_grid.size() || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 727 | return 0; |
| 728 | |
| 729 | unsigned borderWidth = 0; |
| 730 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 731 | const BorderValue& sb = style().borderBefore(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 732 | if (sb.style() == BHIDDEN) |
| 733 | return -1; |
| 734 | if (sb.style() > BHIDDEN) |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 735 | borderWidth = sb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 736 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 737 | const BorderValue& rb = firstRow()->style().borderBefore(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 738 | if (rb.style() == BHIDDEN) |
| 739 | return -1; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 740 | if (rb.style() > BHIDDEN && rb.width() > borderWidth) |
| 741 | borderWidth = rb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 742 | |
| 743 | bool allHidden = true; |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 744 | for (unsigned c = 0; c < totalCols; c++) { |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 745 | const CellStruct& current = cellAt(0, c); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 746 | if (current.inColSpan || !current.hasCells()) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 747 | continue; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 748 | const BorderValue& cb = current.primaryCell()->style().borderBefore(); // FIXME: Make this work with perpendicular and flipped cells. |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 749 | // FIXME: Don't repeat for the same col group |
| 750 | RenderTableCol* colGroup = table()->colElement(c); |
| 751 | if (colGroup) { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 752 | const BorderValue& gb = colGroup->style().borderBefore(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 753 | if (gb.style() == BHIDDEN || cb.style() == BHIDDEN) |
| 754 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 755 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 756 | if (gb.style() > BHIDDEN && gb.width() > borderWidth) |
| 757 | borderWidth = gb.width(); |
| 758 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 759 | borderWidth = cb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 760 | } else { |
| 761 | if (cb.style() == BHIDDEN) |
| 762 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 763 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 764 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 765 | borderWidth = cb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | if (allHidden) |
| 769 | return -1; |
| 770 | |
| 771 | return borderWidth / 2; |
| 772 | } |
| 773 | |
eae@chromium.org | 351bc64 | 2012-02-08 05:37:54 +0000 | [diff] [blame] | 774 | int RenderTableSection::calcOuterBorderAfter() const |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 775 | { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 776 | unsigned totalCols = table()->numEffCols(); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 777 | if (!m_grid.size() || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 778 | return 0; |
| 779 | |
| 780 | unsigned borderWidth = 0; |
| 781 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 782 | const BorderValue& sb = style().borderAfter(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 783 | if (sb.style() == BHIDDEN) |
| 784 | return -1; |
| 785 | if (sb.style() > BHIDDEN) |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 786 | borderWidth = sb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 787 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 788 | const BorderValue& rb = lastRow()->style().borderAfter(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 789 | if (rb.style() == BHIDDEN) |
| 790 | return -1; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 791 | if (rb.style() > BHIDDEN && rb.width() > borderWidth) |
| 792 | borderWidth = rb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 793 | |
| 794 | bool allHidden = true; |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 795 | for (unsigned c = 0; c < totalCols; c++) { |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 796 | const CellStruct& current = cellAt(m_grid.size() - 1, c); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 797 | if (current.inColSpan || !current.hasCells()) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 798 | continue; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 799 | const BorderValue& cb = current.primaryCell()->style().borderAfter(); // FIXME: Make this work with perpendicular and flipped cells. |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 800 | // FIXME: Don't repeat for the same col group |
| 801 | RenderTableCol* colGroup = table()->colElement(c); |
| 802 | if (colGroup) { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 803 | const BorderValue& gb = colGroup->style().borderAfter(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 804 | if (gb.style() == BHIDDEN || cb.style() == BHIDDEN) |
| 805 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 806 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 807 | if (gb.style() > BHIDDEN && gb.width() > borderWidth) |
| 808 | borderWidth = gb.width(); |
| 809 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 810 | borderWidth = cb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 811 | } else { |
| 812 | if (cb.style() == BHIDDEN) |
| 813 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 814 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 815 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 816 | borderWidth = cb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 817 | } |
| 818 | } |
| 819 | if (allHidden) |
| 820 | return -1; |
| 821 | |
| 822 | return (borderWidth + 1) / 2; |
| 823 | } |
| 824 | |
eae@chromium.org | 351bc64 | 2012-02-08 05:37:54 +0000 | [diff] [blame] | 825 | int RenderTableSection::calcOuterBorderStart() const |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 826 | { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 827 | unsigned totalCols = table()->numEffCols(); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 828 | if (!m_grid.size() || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 829 | return 0; |
| 830 | |
| 831 | unsigned borderWidth = 0; |
| 832 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 833 | const BorderValue& sb = style().borderStart(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 834 | if (sb.style() == BHIDDEN) |
| 835 | return -1; |
| 836 | if (sb.style() > BHIDDEN) |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 837 | borderWidth = sb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 838 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 839 | if (RenderTableCol* colGroup = table()->colElement(0)) { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 840 | const BorderValue& gb = colGroup->style().borderStart(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 841 | if (gb.style() == BHIDDEN) |
| 842 | return -1; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 843 | if (gb.style() > BHIDDEN && gb.width() > borderWidth) |
| 844 | borderWidth = gb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | bool allHidden = true; |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 848 | for (unsigned r = 0; r < m_grid.size(); r++) { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 849 | const CellStruct& current = cellAt(r, 0); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 850 | if (!current.hasCells()) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 851 | continue; |
| 852 | // FIXME: Don't repeat for the same cell |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 853 | 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(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 855 | if (cb.style() == BHIDDEN || rb.style() == BHIDDEN) |
| 856 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 857 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 858 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 859 | borderWidth = cb.width(); |
| 860 | if (rb.style() > BHIDDEN && rb.width() > borderWidth) |
| 861 | borderWidth = rb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 862 | } |
| 863 | if (allHidden) |
| 864 | return -1; |
| 865 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 866 | return (borderWidth + (table()->style().isLeftToRightDirection() ? 0 : 1)) / 2; |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 867 | } |
| 868 | |
eae@chromium.org | 351bc64 | 2012-02-08 05:37:54 +0000 | [diff] [blame] | 869 | int RenderTableSection::calcOuterBorderEnd() const |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 870 | { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 871 | unsigned totalCols = table()->numEffCols(); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 872 | if (!m_grid.size() || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 873 | return 0; |
| 874 | |
| 875 | unsigned borderWidth = 0; |
| 876 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 877 | const BorderValue& sb = style().borderEnd(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 878 | if (sb.style() == BHIDDEN) |
| 879 | return -1; |
| 880 | if (sb.style() > BHIDDEN) |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 881 | borderWidth = sb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 882 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 883 | if (RenderTableCol* colGroup = table()->colElement(totalCols - 1)) { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 884 | const BorderValue& gb = colGroup->style().borderEnd(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 885 | if (gb.style() == BHIDDEN) |
| 886 | return -1; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 887 | if (gb.style() > BHIDDEN && gb.width() > borderWidth) |
| 888 | borderWidth = gb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | bool allHidden = true; |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 892 | for (unsigned r = 0; r < m_grid.size(); r++) { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 893 | const CellStruct& current = cellAt(r, totalCols - 1); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 894 | if (!current.hasCells()) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 895 | continue; |
| 896 | // FIXME: Don't repeat for the same cell |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 897 | 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(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 899 | if (cb.style() == BHIDDEN || rb.style() == BHIDDEN) |
| 900 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 901 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 902 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 903 | borderWidth = cb.width(); |
| 904 | if (rb.style() > BHIDDEN && rb.width() > borderWidth) |
| 905 | borderWidth = rb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 906 | } |
| 907 | if (allHidden) |
| 908 | return -1; |
| 909 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 910 | return (borderWidth + (table()->style().isLeftToRightDirection() ? 1 : 0)) / 2; |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | void RenderTableSection::recalcOuterBorder() |
| 914 | { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 915 | m_outerBorderBefore = calcOuterBorderBefore(); |
| 916 | m_outerBorderAfter = calcOuterBorderAfter(); |
| 917 | m_outerBorderStart = calcOuterBorderStart(); |
| 918 | m_outerBorderEnd = calcOuterBorderEnd(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 919 | } |
| 920 | |
antti@apple.com | 0e632aa | 2013-10-22 21:03:38 +0000 | [diff] [blame] | 921 | int RenderTableSection::firstLineBaseline() const |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 922 | { |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 923 | if (!m_grid.size()) |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 924 | return -1; |
| 925 | |
eae@chromium.org | 82b9498 | 2012-10-22 18:38:29 +0000 | [diff] [blame] | 926 | int firstLineBaseline = m_grid[0].baseline; |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 927 | if (firstLineBaseline) |
| 928 | return firstLineBaseline + m_rowPos[0]; |
| 929 | |
| 930 | firstLineBaseline = -1; |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 931 | 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.org | 3b67b1f | 2012-05-16 21:06:10 +0000 | [diff] [blame] | 935 | // Only cells with content have a baseline |
| 936 | if (cell && cell->contentLogicalHeight()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 937 | firstLineBaseline = std::max<int>(firstLineBaseline, cell->logicalTop() + cell->borderAndPaddingBefore() + cell->contentLogicalHeight()); |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | return firstLineBaseline; |
| 941 | } |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 942 | |
leviw@chromium.org | b375750 | 2011-06-29 21:33:11 +0000 | [diff] [blame] | 943 | void RenderTableSection::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 944 | { |
inferno@chromium.org | 64a831b | 2012-08-03 19:47:08 +0000 | [diff] [blame] | 945 | // 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.org | 5d226dc | 2012-08-02 21:06:06 +0000 | [diff] [blame] | 948 | if (needsLayout()) |
| 949 | return; |
inferno@chromium.org | 64a831b | 2012-08-03 19:47:08 +0000 | [diff] [blame] | 950 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 951 | unsigned totalRows = m_grid.size(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 952 | unsigned totalCols = table()->columns().size(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 953 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 954 | if (!totalRows || !totalCols) |
ap | 0e708ba | 2006-05-20 08:47:37 +0000 | [diff] [blame] | 955 | return; |
| 956 | |
leviw@chromium.org | b375750 | 2011-06-29 21:33:11 +0000 | [diff] [blame] | 957 | LayoutPoint adjustedPaintOffset = paintOffset + location(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 958 | |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 959 | PaintPhase phase = paintInfo.phase; |
leviw@chromium.org | 61ca137 | 2011-06-07 18:56:41 +0000 | [diff] [blame] | 960 | bool pushedClip = pushContentsClip(paintInfo, adjustedPaintOffset); |
| 961 | paintObject(paintInfo, adjustedPaintOffset); |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 962 | if (pushedClip) |
leviw@chromium.org | 61ca137 | 2011-06-07 18:56:41 +0000 | [diff] [blame] | 963 | popContentsClip(paintInfo, phase, adjustedPaintOffset); |
robert@webkit.org | 87e8d0c | 2012-01-14 19:13:35 +0000 | [diff] [blame] | 964 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 965 | if ((phase == PaintPhaseOutline || phase == PaintPhaseSelfOutline) && style().visibility() == VISIBLE) |
wangxianzhu@chromium.org | 64f3829 | 2013-02-28 20:38:23 +0000 | [diff] [blame] | 966 | paintOutline(paintInfo, LayoutRect(adjustedPaintOffset, size())); |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 967 | } |
| 968 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 969 | static inline bool compareCellPositions(RenderTableCell* elem1, RenderTableCell* elem2) |
| 970 | { |
jchaffraix@webkit.org | a0177fd | 2012-05-01 03:13:06 +0000 | [diff] [blame] | 971 | return elem1->rowIndex() < elem2->rowIndex(); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 972 | } |
| 973 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 974 | // 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. |
| 976 | static inline bool compareCellPositionsWithOverflowingCells(RenderTableCell* elem1, RenderTableCell* elem2) |
| 977 | { |
jchaffraix@webkit.org | a0177fd | 2012-05-01 03:13:06 +0000 | [diff] [blame] | 978 | if (elem1->rowIndex() != elem2->rowIndex()) |
| 979 | return elem1->rowIndex() < elem2->rowIndex(); |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 980 | |
| 981 | return elem1->col() < elem2->col(); |
| 982 | } |
| 983 | |
leviw@chromium.org | 890e9b0 | 2011-07-07 23:17:55 +0000 | [diff] [blame] | 984 | void RenderTableSection::paintCell(RenderTableCell* cell, PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 985 | { |
ojan@chromium.org | 035c88ca | 2011-10-03 22:00:25 +0000 | [diff] [blame] | 986 | LayoutPoint cellPoint = flipForWritingModeForChild(cell, paintOffset); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 987 | 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.org | 1ddd9fa | 2012-05-31 16:00:20 +0000 | [diff] [blame] | 993 | RenderTableCol* column = table()->colElement(cell->col()); |
| 994 | RenderTableCol* columnGroup = column ? column->enclosingColumnGroup() : 0; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 995 | |
| 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.org | 1ddd9fa | 2012-05-31 16:00:20 +0000 | [diff] [blame] | 1001 | cell->paintBackgroundsBehindCell(paintInfo, cellPoint, columnGroup); |
| 1002 | cell->paintBackgroundsBehindCell(paintInfo, cellPoint, column); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1003 | |
| 1004 | // Paint the row group next. |
leviw@chromium.org | 719a45b | 2011-06-03 20:59:40 +0000 | [diff] [blame] | 1005 | cell->paintBackgroundsBehindCell(paintInfo, cellPoint, this); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1006 | |
| 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.org | 719a45b | 2011-06-03 20:59:40 +0000 | [diff] [blame] | 1010 | cell->paintBackgroundsBehindCell(paintInfo, cellPoint, row); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1011 | } |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1012 | if ((!cell->hasSelfPaintingLayer() && !row->hasSelfPaintingLayer())) |
leviw@chromium.org | 61ca137 | 2011-06-07 18:56:41 +0000 | [diff] [blame] | 1013 | cell->paint(paintInfo, cellPoint); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1016 | LayoutRect RenderTableSection::logicalRectForWritingModeAndDirection(const LayoutRect& rect) const |
| 1017 | { |
| 1018 | LayoutRect tableAlignedRect(rect); |
| 1019 | |
| 1020 | flipForWritingMode(tableAlignedRect); |
| 1021 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1022 | if (!style().isHorizontalWritingMode()) |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1023 | tableAlignedRect = tableAlignedRect.transposedRect(); |
| 1024 | |
| 1025 | const Vector<int>& columnPos = table()->columnPositions(); |
jchaffraix@webkit.org | 6d6c305 | 2012-11-05 07:55:28 +0000 | [diff] [blame] | 1026 | // FIXME: The table's direction should determine our row's direction, not the section's (see bug 96691). |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1027 | if (!style().isLeftToRightDirection()) |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1028 | tableAlignedRect.setX(columnPos[columnPos.size() - 1] - tableAlignedRect.maxX()); |
| 1029 | |
| 1030 | return tableAlignedRect; |
| 1031 | } |
| 1032 | |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1033 | CellSpan RenderTableSection::dirtiedRows(const LayoutRect& damageRect) const |
| 1034 | { |
| 1035 | if (m_forceSlowPaintPathWithOverflowingCell) |
| 1036 | return fullTableRowSpan(); |
| 1037 | |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1038 | CellSpan coveredRows = spannedRows(damageRect); |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1039 | |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1040 | // 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.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1043 | |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1044 | if (!coveredRows.end() && m_rowPos[0] - table()->outerBorderBefore() <= damageRect.maxY()) |
| 1045 | ++coveredRows.end(); |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1046 | |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1047 | return coveredRows; |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1050 | CellSpan RenderTableSection::dirtiedColumns(const LayoutRect& damageRect) const |
| 1051 | { |
| 1052 | if (m_forceSlowPaintPathWithOverflowingCell) |
| 1053 | return fullTableColumnSpan(); |
| 1054 | |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1055 | CellSpan coveredColumns = spannedColumns(damageRect); |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1056 | |
jchaffraix@webkit.org | b87ce75 | 2012-10-15 21:52:22 +0000 | [diff] [blame] | 1057 | const Vector<int>& columnPos = table()->columnPositions(); |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1058 | // 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.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1061 | |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1062 | if (!coveredColumns.end() && columnPos[0] - table()->outerBorderStart() <= damageRect.maxX()) |
| 1063 | ++coveredColumns.end(); |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1064 | |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1065 | return coveredColumns; |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1068 | CellSpan RenderTableSection::spannedRows(const LayoutRect& flippedRect) const |
| 1069 | { |
| 1070 | // Find the first row that starts after rect top. |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1071 | 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 | |
| 1091 | CellSpan RenderTableSection::spannedColumns(const LayoutRect& flippedRect) const |
| 1092 | { |
| 1093 | const Vector<int>& columnPos = table()->columnPositions(); |
| 1094 | |
commit-queue@webkit.org | 01f6141 | 2012-08-15 18:01:05 +0000 | [diff] [blame] | 1095 | // 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.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1101 | |
| 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.org | 01f6141 | 2012-08-15 18:01:05 +0000 | [diff] [blame] | 1107 | // Find the first column that starts after rect right. |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1108 | unsigned endColumn; |
| 1109 | if (columnPos[nextColumn] >= flippedRect.maxX()) |
| 1110 | endColumn = nextColumn; |
| 1111 | else { |
commit-queue@webkit.org | 01f6141 | 2012-08-15 18:01:05 +0000 | [diff] [blame] | 1112 | endColumn = std::upper_bound(columnPos.begin() + nextColumn, columnPos.end(), flippedRect.maxX()) - columnPos.begin(); |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1113 | if (endColumn == columnPos.size()) |
| 1114 | endColumn = columnPos.size() - 1; |
| 1115 | } |
| 1116 | |
| 1117 | return CellSpan(startColumn, endColumn); |
| 1118 | } |
| 1119 | |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1120 | void 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.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1127 | 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.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | int RenderTableSection::offsetLeftForRowGroupBorder(RenderTableCell* cell, const LayoutRect& rowGroupRect, unsigned row) |
| 1131 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1132 | if (style().isHorizontalWritingMode()) { |
| 1133 | if (style().isLeftToRightDirection()) |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1134 | return cell ? cell->x().toInt() + cell->width().toInt() : 0; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1135 | return -outerBorderLeft(&style()); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1136 | } |
| 1137 | bool isLastRow = row + 1 == m_grid.size(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1138 | return rowGroupRect.width().toInt() - m_rowPos[row + 1] + (isLastRow ? -outerBorderLeft(&style()) : 0); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | int RenderTableSection::offsetTopForRowGroupBorder(RenderTableCell* cell, BoxSide borderSide, unsigned row) |
| 1142 | { |
| 1143 | bool isLastRow = row + 1 == m_grid.size(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1144 | 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.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | int RenderTableSection::verticalRowGroupBorderHeight(RenderTableCell* cell, const LayoutRect& rowGroupRect, unsigned row) |
| 1152 | { |
| 1153 | bool isLastRow = row + 1 == m_grid.size(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1154 | 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.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1158 | return cell ? rowGroupRect.height().toInt() - (cell->y().toInt() - cell->height().toInt()) : 0; |
| 1159 | } |
| 1160 | |
| 1161 | int RenderTableSection::horizontalRowGroupBorderWidth(RenderTableCell* cell, const LayoutRect& rowGroupRect, unsigned row, unsigned column) |
| 1162 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1163 | 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.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1166 | return cell ? rowGroupRect.width().toInt() - (cell->x().toInt() - cell->width().toInt()) : 0; |
| 1167 | } |
| 1168 | bool isLastRow = row + 1 == m_grid.size(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1169 | return m_rowPos[row + 1] - m_rowPos[row] + (isLastRow ? outerBorderLeft(&style()) : !row ? outerBorderRight(&style()) : 0); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | void 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.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1179 | const RenderStyle& style = this->style(); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1180 | bool antialias = shouldAntialiasLines(paintInfo.context); |
| 1181 | LayoutRect rowGroupRect = LayoutRect(paintOffset, size()); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1182 | rowGroupRect.moveBy(-LayoutPoint(outerBorderLeft(&style), (borderSide == BSRight) ? 0 : outerBorderTop(&style))); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1183 | |
| 1184 | switch (borderSide) { |
| 1185 | case BSTop: |
| 1186 | paintRowGroupBorder(paintInfo, antialias, LayoutRect(paintOffset.x() + offsetLeftForRowGroupBorder(cell, rowGroupRect, row), rowGroupRect.y(), |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1187 | horizontalRowGroupBorderWidth(cell, rowGroupRect, row, column), style.borderTop().width()), BSTop, CSSPropertyBorderTopColor, style.borderTopStyle(), table()->style().borderTopStyle()); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1188 | break; |
| 1189 | case BSBottom: |
| 1190 | paintRowGroupBorder(paintInfo, antialias, LayoutRect(paintOffset.x() + offsetLeftForRowGroupBorder(cell, rowGroupRect, row), rowGroupRect.y() + rowGroupRect.height(), |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1191 | horizontalRowGroupBorderWidth(cell, rowGroupRect, row, column), style.borderBottom().width()), BSBottom, CSSPropertyBorderBottomColor, style.borderBottomStyle(), table()->style().borderBottomStyle()); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1192 | break; |
| 1193 | case BSLeft: |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1194 | 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.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1196 | break; |
| 1197 | case BSRight: |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1198 | 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.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1200 | break; |
| 1201 | default: |
| 1202 | break; |
| 1203 | } |
| 1204 | |
| 1205 | } |
| 1206 | |
| 1207 | static 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.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1232 | |
leviw@chromium.org | c491808 | 2011-06-29 01:06:00 +0000 | [diff] [blame] | 1233 | void RenderTableSection::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 1234 | { |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 1235 | PaintPhase paintPhase = paintInfo.phase; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1236 | |
leviw@chromium.org | c491808 | 2011-06-29 01:06:00 +0000 | [diff] [blame] | 1237 | LayoutRect localRepaintRect = paintInfo.rect; |
leviw@chromium.org | 43d0c4d | 2011-06-04 02:25:54 +0000 | [diff] [blame] | 1238 | localRepaintRect.moveBy(-paintOffset); |
jchaffraix@webkit.org | 2176431 | 2012-02-29 20:49:49 +0000 | [diff] [blame] | 1239 | localRepaintRect.inflate(maximalOutlineSize(paintPhase)); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1240 | |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1241 | LayoutRect tableAlignedRect = logicalRectForWritingModeAndDirection(localRepaintRect); |
| 1242 | |
| 1243 | CellSpan dirtiedRows = this->dirtiedRows(tableAlignedRect); |
| 1244 | CellSpan dirtiedColumns = this->dirtiedColumns(tableAlignedRect); |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1245 | |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1246 | if (dirtiedColumns.start() < dirtiedColumns.end()) { |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1247 | if (!m_hasMultipleCellLevels && !m_overflowingCells.size()) { |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1248 | if (paintInfo.phase == PaintPhaseCollapsedTableBorders) { |
| 1249 | // Collapsed borders are painted from the bottom right to the top left so that precedence |
robert@webkit.org | c75e767 | 2013-06-11 18:11:31 +0000 | [diff] [blame] | 1250 | // 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.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1254 | unsigned row = r - 1; |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1255 | bool shouldPaintRowGroupBorder = false; |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1256 | for (unsigned c = dirtiedColumns.end(); c > dirtiedColumns.start(); c--) { |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1257 | unsigned col = c - 1; |
| 1258 | CellStruct& current = cellAt(row, col); |
| 1259 | RenderTableCell* cell = current.primaryCell(); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1260 | if (!cell) { |
| 1261 | if (!c) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1262 | paintRowGroupBorderIfRequired(paintInfo, paintOffset, row, col, physicalBorderForDirection(&style(), CBSStart)); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1263 | else if (c == table()->numEffCols()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1264 | paintRowGroupBorderIfRequired(paintInfo, paintOffset, row, col, physicalBorderForDirection(&style(), CBSEnd)); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1265 | shouldPaintRowGroupBorder = true; |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1266 | continue; |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1267 | } |
| 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.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1275 | paintRowGroupBorderIfRequired(paintInfo, paintOffset, row, col, physicalBorderForDirection(&style(), CBSAfter), cell); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1276 | else if (!row && !table()->sectionAbove(this)) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1277 | paintRowGroupBorderIfRequired(paintInfo, paintOffset, row, col, physicalBorderForDirection(&style(), CBSBefore), cell); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1278 | shouldPaintRowGroupBorder = false; |
| 1279 | } |
| 1280 | |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1281 | 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.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1287 | for (unsigned r = dirtiedRows.start(); r < dirtiedRows.end(); r++) { |
robert@webkit.org | 87e8d0c | 2012-01-14 19:13:35 +0000 | [diff] [blame] | 1288 | RenderTableRow* row = m_grid[r].rowRenderer; |
| 1289 | if (row && !row->hasSelfPaintingLayer()) |
| 1290 | row->paintOutlineForRowIfNeeded(paintInfo, paintOffset); |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1291 | for (unsigned c = dirtiedColumns.start(); c < dirtiedColumns.end(); c++) { |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1292 | CellStruct& current = cellAt(r, c); |
| 1293 | RenderTableCell* cell = current.primaryCell(); |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1294 | if (!cell || (r > dirtiedRows.start() && primaryCellAt(r - 1, c) == cell) || (c > dirtiedColumns.start() && primaryCellAt(r, c - 1) == cell)) |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1295 | continue; |
| 1296 | paintCell(cell, paintInfo, paintOffset); |
| 1297 | } |
hyatt | e031dd0 | 2006-03-18 01:01:06 +0000 | [diff] [blame] | 1298 | } |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1299 | } |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1300 | } else { |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1301 | // The overflowing cells should be scarce to avoid adding a lot of cells to the HashSet. |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1302 | #ifndef NDEBUG |
| 1303 | unsigned totalRows = m_grid.size(); |
| 1304 | unsigned totalCols = table()->columns().size(); |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1305 | ASSERT(m_overflowingCells.size() < totalRows * totalCols * gMaxAllowedOverflowingCellRatioForFastPaintPath); |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1306 | #endif |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1307 | |
| 1308 | // To make sure we properly repaint the section, we repaint all the overflowing cells that we collected. |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1309 | Vector<RenderTableCell*> cells; |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1310 | copyToVector(m_overflowingCells, cells); |
| 1311 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1312 | HashSet<RenderTableCell*> spanningCells; |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1313 | |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1314 | for (unsigned r = dirtiedRows.start(); r < dirtiedRows.end(); r++) { |
robert@webkit.org | 87e8d0c | 2012-01-14 19:13:35 +0000 | [diff] [blame] | 1315 | RenderTableRow* row = m_grid[r].rowRenderer; |
| 1316 | if (row && !row->hasSelfPaintingLayer()) |
| 1317 | row->paintOutlineForRowIfNeeded(paintInfo, paintOffset); |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1318 | for (unsigned c = dirtiedColumns.start(); c < dirtiedColumns.end(); c++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1319 | CellStruct& current = cellAt(r, c); |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 1320 | if (!current.hasCells()) |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1321 | continue; |
| 1322 | for (unsigned i = 0; i < current.cells.size(); ++i) { |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1323 | if (m_overflowingCells.contains(current.cells[i])) |
| 1324 | continue; |
| 1325 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1326 | if (current.cells[i]->rowSpan() > 1 || current.cells[i]->colSpan() > 1) { |
rafael.lobo@openbossa.org | 61c47ed | 2013-05-31 00:53:31 +0000 | [diff] [blame] | 1327 | if (!spanningCells.add(current.cells[i]).isNewEntry) |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1328 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1329 | } |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1330 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1331 | cells.append(current.cells[i]); |
| 1332 | } |
| 1333 | } |
| 1334 | } |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1335 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1336 | // Sort the dirty cells by paint order. |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1337 | 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.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1342 | 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 | } |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1351 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | |
darin@apple.com | 98a7ac6 | 2009-01-05 17:26:53 +0000 | [diff] [blame] | 1355 | void RenderTableSection::imageChanged(WrappedImagePtr, const IntRect*) |
bdash | b07ae8d | 2007-02-08 04:56:20 +0000 | [diff] [blame] | 1356 | { |
bdash | b07ae8d | 2007-02-08 04:56:20 +0000 | [diff] [blame] | 1357 | // FIXME: Examine cells and repaint only the rect the image paints in. |
| 1358 | repaint(); |
| 1359 | } |
| 1360 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1361 | void RenderTableSection::recalcCells() |
| 1362 | { |
jchaffraix@webkit.org | b86b64e | 2011-11-14 21:21:43 +0000 | [diff] [blame] | 1363 | 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 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1369 | m_cCol = 0; |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1370 | m_cRow = 0; |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 1371 | m_grid.clear(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1372 | |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1373 | 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.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 1378 | |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1379 | m_grid[insertionRow].rowRenderer = row; |
| 1380 | row->setRowIndex(insertionRow); |
| 1381 | setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[insertionRow]); |
eseidel | 05ef043 | 2006-05-25 22:11:36 +0000 | [diff] [blame] | 1382 | |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1383 | for (RenderTableCell* cell = row->firstCell(); cell; cell = cell->nextCell()) |
| 1384 | addCell(cell, row); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1385 | } |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 1386 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 1387 | m_grid.shrinkToFit(); |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 1388 | setNeedsLayout(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
jchaffraix@webkit.org | 74857b4 | 2011-12-20 14:08:52 +0000 | [diff] [blame] | 1391 | // FIXME: This function could be made O(1) in certain cases (like for the non-most-constrainive cells' case). |
jchaffraix@webkit.org | 19bbb72 | 2011-11-03 17:20:01 +0000 | [diff] [blame] | 1392 | void RenderTableSection::rowLogicalHeightChanged(unsigned rowIndex) |
| 1393 | { |
jchaffraix@webkit.org | dd34df4 | 2012-01-24 04:15:06 +0000 | [diff] [blame] | 1394 | if (needsCellRecalc()) |
| 1395 | return; |
| 1396 | |
jchaffraix@webkit.org | 19bbb72 | 2011-11-03 17:20:01 +0000 | [diff] [blame] | 1397 | setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[rowIndex]); |
jchaffraix@webkit.org | 74857b4 | 2011-12-20 14:08:52 +0000 | [diff] [blame] | 1398 | |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1399 | for (RenderTableCell* cell = m_grid[rowIndex].rowRenderer->firstCell(); cell; cell = cell->nextCell()) |
| 1400 | updateLogicalHeightForCell(m_grid[rowIndex], cell); |
jchaffraix@webkit.org | 19bbb72 | 2011-11-03 17:20:01 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
jamesr@google.com | 5ddfb04 | 2011-01-20 21:34:34 +0000 | [diff] [blame] | 1403 | void RenderTableSection::setNeedsCellRecalc() |
| 1404 | { |
| 1405 | m_needsCellRecalc = true; |
| 1406 | if (RenderTable* t = table()) |
| 1407 | t->setNeedsSectionRecalc(); |
| 1408 | } |
| 1409 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1410 | unsigned RenderTableSection::numColumns() const |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1411 | { |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1412 | unsigned result = 0; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1413 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 1414 | for (unsigned r = 0; r < m_grid.size(); ++r) { |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1415 | for (unsigned c = result; c < table()->numEffCols(); ++c) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1416 | const CellStruct& cell = cellAt(r, c); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1417 | if (cell.hasCells() || cell.inColSpan) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1418 | result = c; |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | return result + 1; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
jchaffraix@webkit.org | ec61404 | 2012-09-20 00:58:58 +0000 | [diff] [blame] | 1425 | const BorderValue& RenderTableSection::borderAdjoiningStartCell(const RenderTableCell* cell) const |
| 1426 | { |
jchaffraix@webkit.org | 6d6c305 | 2012-11-05 07:55:28 +0000 | [diff] [blame] | 1427 | ASSERT(cell->isFirstOrLastCellInRow()); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1428 | return hasSameDirectionAs(cell) ? style().borderStart() : style().borderEnd(); |
jchaffraix@webkit.org | ec61404 | 2012-09-20 00:58:58 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | const BorderValue& RenderTableSection::borderAdjoiningEndCell(const RenderTableCell* cell) const |
| 1432 | { |
jchaffraix@webkit.org | 6d6c305 | 2012-11-05 07:55:28 +0000 | [diff] [blame] | 1433 | ASSERT(cell->isFirstOrLastCellInRow()); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1434 | return hasSameDirectionAs(cell) ? style().borderEnd() : style().borderStart(); |
jchaffraix@webkit.org | ec61404 | 2012-09-20 00:58:58 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
jchaffraix@webkit.org | ceaacec | 2012-06-01 20:15:01 +0000 | [diff] [blame] | 1437 | const RenderTableCell* RenderTableSection::firstRowCellAdjoiningTableStart() const |
| 1438 | { |
jchaffraix@webkit.org | ec61404 | 2012-09-20 00:58:58 +0000 | [diff] [blame] | 1439 | unsigned adjoiningStartCellColumnIndex = hasSameDirectionAs(table()) ? 0 : table()->lastColumnIndex(); |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1440 | return cellAt(0, adjoiningStartCellColumnIndex).primaryCell(); |
jchaffraix@webkit.org | ceaacec | 2012-06-01 20:15:01 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | const RenderTableCell* RenderTableSection::firstRowCellAdjoiningTableEnd() const |
| 1444 | { |
jchaffraix@webkit.org | ec61404 | 2012-09-20 00:58:58 +0000 | [diff] [blame] | 1445 | unsigned adjoiningEndCellColumnIndex = hasSameDirectionAs(table()) ? table()->lastColumnIndex() : 0; |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1446 | return cellAt(0, adjoiningEndCellColumnIndex).primaryCell(); |
jchaffraix@webkit.org | ceaacec | 2012-06-01 20:15:01 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 1449 | void RenderTableSection::appendColumn(unsigned pos) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1450 | { |
jchaffraix@webkit.org | b86b64e | 2011-11-14 21:21:43 +0000 | [diff] [blame] | 1451 | ASSERT(!m_needsCellRecalc); |
| 1452 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 1453 | for (unsigned row = 0; row < m_grid.size(); ++row) |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 1454 | m_grid[row].row.resize(pos + 1); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 1457 | void RenderTableSection::splitColumn(unsigned pos, unsigned first) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1458 | { |
inferno@chromium.org | b1ffad7 | 2011-10-10 18:58:12 +0000 | [diff] [blame] | 1459 | ASSERT(!m_needsCellRecalc); |
| 1460 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1461 | if (m_cCol > pos) |
| 1462 | m_cCol++; |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 1463 | for (unsigned row = 0; row < m_grid.size(); ++row) { |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 1464 | Row& r = m_grid[row].row; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1465 | r.insert(pos + 1, CellStruct()); |
| 1466 | if (r[pos].hasCells()) { |
andersca@apple.com | 9201299 | 2013-05-05 19:03:49 +0000 | [diff] [blame] | 1467 | r[pos + 1].cells.appendVector(r[pos].cells); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1468 | RenderTableCell* cell = r[pos].primaryCell(); |
| 1469 | ASSERT(cell); |
commit-queue@webkit.org | 1ee5b34 | 2012-05-08 05:14:07 +0000 | [diff] [blame] | 1470 | ASSERT(cell->colSpan() >= (r[pos].inColSpan ? 1u : 0)); |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 1471 | unsigned colleft = cell->colSpan() - r[pos].inColSpan; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1472 | 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 | } |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1479 | } |
| 1480 | } |
| 1481 | |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1482 | // Hit Testing |
allan.jensen@nokia.com | 9a9045b | 2012-08-28 09:41:54 +0000 | [diff] [blame] | 1483 | bool RenderTableSection::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action) |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1484 | { |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1485 | // If we have no children then we have nothing to do. |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1486 | if (!firstRow()) |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1487 | return false; |
| 1488 | |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1489 | // Table sections cannot ever be hit tested. Effectively they do not exist. |
| 1490 | // Just forward to our children always. |
eae@chromium.org | e14cd1a | 2011-07-06 23:38:32 +0000 | [diff] [blame] | 1491 | LayoutPoint adjustedLocation = accumulatedOffset + location(); |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1492 | |
allan.jensen@nokia.com | 9a9045b | 2012-08-28 09:41:54 +0000 | [diff] [blame] | 1493 | if (hasOverflowClip() && !locationInContainer.intersects(overflowClipRect(adjustedLocation, locationInContainer.region()))) |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 1494 | return false; |
| 1495 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1496 | if (hasOverflowingCell()) { |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1497 | for (RenderTableRow* row = lastRow(); row; row = row->previousRow()) { |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1498 | // 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.com | d04c081 | 2013-09-25 17:45:59 +0000 | [diff] [blame] | 1502 | if (!row->hasSelfPaintingLayer()) { |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1503 | LayoutPoint childPoint = flipForWritingModeForChild(row, adjustedLocation); |
| 1504 | if (row->nodeAtPoint(request, result, locationInContainer, childPoint, action)) { |
allan.jensen@nokia.com | 9a9045b | 2012-08-28 09:41:54 +0000 | [diff] [blame] | 1505 | updateHitTestResult(result, toLayoutPoint(locationInContainer.point() - childPoint)); |
mitz@apple.com | 39fb3ae | 2010-11-09 20:46:15 +0000 | [diff] [blame] | 1506 | return true; |
| 1507 | } |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1508 | } |
| 1509 | } |
| 1510 | return false; |
| 1511 | } |
| 1512 | |
inferno@chromium.org | 9c8b230 | 2012-02-21 19:10:05 +0000 | [diff] [blame] | 1513 | recalcCellsIfNeeded(); |
| 1514 | |
allan.jensen@nokia.com | 9a9045b | 2012-08-28 09:41:54 +0000 | [diff] [blame] | 1515 | LayoutRect hitTestRect = locationInContainer.boundingBox(); |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1516 | hitTestRect.moveBy(-adjustedLocation); |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1517 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1518 | LayoutRect tableAlignedRect = logicalRectForWritingModeAndDirection(hitTestRect); |
| 1519 | CellSpan rowSpan = spannedRows(tableAlignedRect); |
| 1520 | CellSpan columnSpan = spannedColumns(tableAlignedRect); |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1521 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1522 | // 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.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1526 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1527 | // If the cell is empty, there's nothing to do |
| 1528 | if (!current.hasCells()) |
| 1529 | continue; |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1530 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1531 | for (unsigned i = current.cells.size() ; i; ) { |
| 1532 | --i; |
| 1533 | RenderTableCell* cell = current.cells[i]; |
| 1534 | LayoutPoint cellPoint = flipForWritingModeForChild(cell, adjustedLocation); |
allan.jensen@nokia.com | 9a9045b | 2012-08-28 09:41:54 +0000 | [diff] [blame] | 1535 | if (static_cast<RenderObject*>(cell)->nodeAtPoint(request, result, locationInContainer, cellPoint, action)) { |
| 1536 | updateHitTestResult(result, locationInContainer.point() - toLayoutSize(cellPoint)); |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1537 | return true; |
| 1538 | } |
| 1539 | } |
| 1540 | if (!result.isRectBasedTest()) |
| 1541 | break; |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1542 | } |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1543 | if (!result.isRectBasedTest()) |
| 1544 | break; |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1545 | } |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1546 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1547 | return false; |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
robert@webkit.org | 76a7610 | 2012-01-15 13:48:45 +0000 | [diff] [blame] | 1550 | void RenderTableSection::removeCachedCollapsedBorders(const RenderTableCell* cell) |
| 1551 | { |
| 1552 | if (!table()->collapseBorders()) |
| 1553 | return; |
| 1554 | |
| 1555 | for (int side = CBSBefore; side <= CBSEnd; ++side) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1556 | m_cellsCollapsedBorders.remove(std::make_pair(cell, side)); |
robert@webkit.org | 76a7610 | 2012-01-15 13:48:45 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | void RenderTableSection::setCachedCollapsedBorder(const RenderTableCell* cell, CollapsedBorderSide side, CollapsedBorderValue border) |
| 1560 | { |
| 1561 | ASSERT(table()->collapseBorders()); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1562 | m_cellsCollapsedBorders.set(std::make_pair(cell, side), border); |
robert@webkit.org | 76a7610 | 2012-01-15 13:48:45 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | CollapsedBorderValue& RenderTableSection::cachedCollapsedBorder(const RenderTableCell* cell, CollapsedBorderSide side) |
| 1566 | { |
| 1567 | ASSERT(table()->collapseBorders()); |
zandobersek@gmail.com | 83a3119 | 2014-01-04 17:26:52 +0000 | [diff] [blame] | 1568 | HashMap<std::pair<const RenderTableCell*, int>, CollapsedBorderValue>::iterator it = m_cellsCollapsedBorders.find(std::make_pair(cell, side)); |
robert@webkit.org | 76a7610 | 2012-01-15 13:48:45 +0000 | [diff] [blame] | 1569 | ASSERT(it != m_cellsCollapsedBorders.end()); |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 1570 | return it->value; |
robert@webkit.org | 76a7610 | 2012-01-15 13:48:45 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
inferno@chromium.org | 2164c61 | 2012-04-04 22:41:56 +0000 | [diff] [blame] | 1573 | RenderTableSection* RenderTableSection::createAnonymousWithParentRenderer(const RenderObject* parent) |
| 1574 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1575 | auto section = new RenderTableSection(parent->document(), RenderStyle::createAnonymousStyleWithDisplay(&parent->style(), TABLE_ROW_GROUP)); |
akling@apple.com | 8f40c5b | 2013-10-27 22:54:07 +0000 | [diff] [blame] | 1576 | section->initializeStyle(); |
| 1577 | return section; |
inferno@chromium.org | 2164c61 | 2012-04-04 22:41:56 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1580 | void RenderTableSection::setLogicalPositionForCell(RenderTableCell* cell, unsigned effectiveColumn) const |
| 1581 | { |
eae@chromium.org | 1146f21 | 2012-07-18 22:06:34 +0000 | [diff] [blame] | 1582 | LayoutPoint oldCellLocation = cell->location(); |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1583 | |
| 1584 | LayoutPoint cellLocation(0, m_rowPos[cell->rowIndex()]); |
| 1585 | int horizontalBorderSpacing = table()->hBorderSpacing(); |
| 1586 | |
jchaffraix@webkit.org | 6d6c305 | 2012-11-05 07:55:28 +0000 | [diff] [blame] | 1587 | // FIXME: The table's direction should determine our row's direction, not the section's (see bug 96691). |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1588 | if (!style().isLeftToRightDirection()) |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1589 | 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.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1594 | view().addLayoutDelta(oldCellLocation - cell->location()); |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1595 | } |
| 1596 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1597 | } // namespace WebCore |