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" |
cdumez@apple.com | 6962695 | 2016-05-17 22:39:00 +0000 | [diff] [blame] | 32 | #include "RenderChildIterator.h" |
abucur@adobe.com | 7f9668a | 2014-05-16 13:22:00 +0000 | [diff] [blame] | 33 | #include "RenderNamedFlowFragment.h" |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 34 | #include "RenderTableCell.h" |
| 35 | #include "RenderTableCol.h" |
| 36 | #include "RenderTableRow.h" |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 37 | #include "RenderTextControl.h" |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 38 | #include "RenderView.h" |
commit-queue@webkit.org | d0c076d | 2012-08-22 22:25:59 +0000 | [diff] [blame] | 39 | #include "StyleInheritedData.h" |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 40 | #include <limits> |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 41 | #include <wtf/HashSet.h> |
andersca@apple.com | a5fb7da | 2013-04-16 19:57:36 +0000 | [diff] [blame] | 42 | #include <wtf/StackStats.h> |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 43 | |
| 44 | namespace WebCore { |
| 45 | |
| 46 | using namespace HTMLNames; |
| 47 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 48 | // Those 2 variables are used to balance the memory consumption vs the repaint time on big tables. |
cdumez@apple.com | 4bf983a | 2015-05-19 07:22:36 +0000 | [diff] [blame] | 49 | static const unsigned gMinTableSizeToUseFastPaintPathWithOverflowingCell = 75 * 75; |
| 50 | static const float gMaxAllowedOverflowingCellRatioForFastPaintPath = 0.1f; |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 51 | |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 52 | static inline void setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(RenderTableSection::RowStruct& row) |
dbates@webkit.org | e113183 | 2009-11-19 00:05:57 +0000 | [diff] [blame] | 53 | { |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 54 | ASSERT(row.rowRenderer); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 55 | row.logicalHeight = row.rowRenderer->style().logicalHeight(); |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 56 | if (row.logicalHeight.isRelative()) |
| 57 | row.logicalHeight = Length(); |
dbates@webkit.org | e113183 | 2009-11-19 00:05:57 +0000 | [diff] [blame] | 58 | } |
| 59 | |
jchaffraix@webkit.org | 74857b4 | 2011-12-20 14:08:52 +0000 | [diff] [blame] | 60 | static inline void updateLogicalHeightForCell(RenderTableSection::RowStruct& row, const RenderTableCell* cell) |
| 61 | { |
| 62 | // We ignore height settings on rowspan cells. |
| 63 | if (cell->rowSpan() != 1) |
| 64 | return; |
| 65 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 66 | Length logicalHeight = cell->style().logicalHeight(); |
jchaffraix@webkit.org | 74857b4 | 2011-12-20 14:08:52 +0000 | [diff] [blame] | 67 | if (logicalHeight.isPositive() || (logicalHeight.isRelative() && logicalHeight.value() >= 0)) { |
| 68 | Length cRowLogicalHeight = row.logicalHeight; |
| 69 | switch (logicalHeight.type()) { |
| 70 | case Percent: |
commit-queue@webkit.org | 2a67f68 | 2015-05-10 21:43:26 +0000 | [diff] [blame] | 71 | if (!cRowLogicalHeight.isPercent() || cRowLogicalHeight.percent() < logicalHeight.percent()) |
jchaffraix@webkit.org | 74857b4 | 2011-12-20 14:08:52 +0000 | [diff] [blame] | 72 | row.logicalHeight = logicalHeight; |
| 73 | break; |
| 74 | case Fixed: |
darin@apple.com | b432608 | 2014-04-08 08:58:43 +0000 | [diff] [blame] | 75 | if (cRowLogicalHeight.isAuto() || cRowLogicalHeight.isRelative() |
jchaffraix@webkit.org | 74857b4 | 2011-12-20 14:08:52 +0000 | [diff] [blame] | 76 | || (cRowLogicalHeight.isFixed() && cRowLogicalHeight.value() < logicalHeight.value())) |
| 77 | row.logicalHeight = logicalHeight; |
| 78 | break; |
| 79 | case Relative: |
| 80 | default: |
| 81 | break; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
antti@apple.com | 454418f | 2016-04-25 19:49:23 +0000 | [diff] [blame] | 86 | RenderTableSection::RenderTableSection(Element& element, RenderStyle&& style) |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 87 | : RenderBox(element, WTFMove(style), 0) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 88 | { |
akling@apple.com | 42e1063 | 2013-10-14 17:55:52 +0000 | [diff] [blame] | 89 | setInline(false); |
| 90 | } |
| 91 | |
antti@apple.com | 454418f | 2016-04-25 19:49:23 +0000 | [diff] [blame] | 92 | RenderTableSection::RenderTableSection(Document& document, RenderStyle&& style) |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 93 | : RenderBox(document, WTFMove(style), 0) |
akling@apple.com | 42e1063 | 2013-10-14 17:55:52 +0000 | [diff] [blame] | 94 | { |
| 95 | setInline(false); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | RenderTableSection::~RenderTableSection() |
| 99 | { |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 100 | } |
| 101 | |
inferno@chromium.org | a7f719f | 2011-09-06 01:45:39 +0000 | [diff] [blame] | 102 | void RenderTableSection::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
| 103 | { |
| 104 | RenderBox::styleDidChange(diff, oldStyle); |
antti@apple.com | cf4adae | 2013-09-24 00:55:44 +0000 | [diff] [blame] | 105 | propagateStyleToAnonymousChildren(PropagateToAllChildren); |
jchaffraix@webkit.org | 38e74af | 2011-09-23 19:56:21 +0000 | [diff] [blame] | 106 | |
| 107 | // If border was changed, notify table. |
| 108 | RenderTable* table = this->table(); |
zalan@apple.com | 4214662 | 2015-04-01 15:56:34 +0000 | [diff] [blame] | 109 | if (table && oldStyle && oldStyle->border() != style().border()) |
jchaffraix@webkit.org | 38e74af | 2011-09-23 19:56:21 +0000 | [diff] [blame] | 110 | table->invalidateCollapsedBorders(); |
inferno@chromium.org | a7f719f | 2011-09-06 01:45:39 +0000 | [diff] [blame] | 111 | } |
| 112 | |
jchaffraix@webkit.org | 54b0e09 | 2012-08-22 02:16:02 +0000 | [diff] [blame] | 113 | void RenderTableSection::willBeRemovedFromTree() |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 114 | { |
jchaffraix@webkit.org | 54b0e09 | 2012-08-22 02:16:02 +0000 | [diff] [blame] | 115 | RenderBox::willBeRemovedFromTree(); |
| 116 | |
| 117 | // Preventively invalidate our cells as we may be re-inserted into |
| 118 | // a new table which would require us to rebuild our structure. |
| 119 | setNeedsCellRecalc(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 120 | } |
| 121 | |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 122 | void RenderTableSection::addChild(RenderObject* child, RenderObject* beforeChild) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 123 | { |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 124 | if (!is<RenderTableRow>(*child)) { |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 125 | RenderObject* last = beforeChild; |
| 126 | if (!last) |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 127 | last = lastRow(); |
inferno@chromium.org | a7f719f | 2011-09-06 01:45:39 +0000 | [diff] [blame] | 128 | if (last && last->isAnonymous() && !last->isBeforeOrAfterContent()) { |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 129 | RenderTableRow& row = downcast<RenderTableRow>(*last); |
| 130 | if (beforeChild == &row) |
| 131 | beforeChild = row.firstCell(); |
| 132 | row.addChild(child, beforeChild); |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 133 | return; |
| 134 | } |
| 135 | |
inferno@chromium.org | b1ffad7 | 2011-10-10 18:58:12 +0000 | [diff] [blame] | 136 | if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == this) { |
| 137 | RenderObject* row = beforeChild->previousSibling(); |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 138 | if (is<RenderTableRow>(row) && row->isAnonymous()) { |
| 139 | downcast<RenderTableRow>(*row).addChild(child); |
inferno@chromium.org | b1ffad7 | 2011-10-10 18:58:12 +0000 | [diff] [blame] | 140 | return; |
| 141 | } |
| 142 | } |
| 143 | |
darin | 10ab135 | 2006-01-29 01:29:33 +0000 | [diff] [blame] | 144 | // If beforeChild is inside an anonymous cell/row, insert into the cell or into |
| 145 | // the anonymous row containing it, if there is one. |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 146 | RenderObject* lastBox = last; |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 147 | while (lastBox && lastBox->parent()->isAnonymous() && !is<RenderTableRow>(*lastBox)) |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 148 | lastBox = lastBox->parent(); |
inferno@chromium.org | a7f719f | 2011-09-06 01:45:39 +0000 | [diff] [blame] | 149 | if (lastBox && lastBox->isAnonymous() && !lastBox->isBeforeOrAfterContent()) { |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 150 | downcast<RenderTableRow>(*lastBox).addChild(child, beforeChild); |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 151 | return; |
| 152 | } |
| 153 | |
zalan@apple.com | cda46e4 | 2016-07-26 02:40:04 +0000 | [diff] [blame^] | 154 | auto* row = RenderTableRow::createAnonymousWithParentRenderer(*this).release(); |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 155 | addChild(row, beforeChild); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 156 | row->addChild(child); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | |
| 160 | if (beforeChild) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 161 | setNeedsCellRecalc(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 162 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 163 | unsigned insertionRow = m_cRow; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 164 | ++m_cRow; |
| 165 | m_cCol = 0; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 166 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 167 | ensureRows(m_cRow); |
lars | b5288ad | 2007-01-13 18:48:29 +0000 | [diff] [blame] | 168 | |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 169 | RenderTableRow& row = downcast<RenderTableRow>(*child); |
| 170 | m_grid[insertionRow].rowRenderer = &row; |
| 171 | row.setRowIndex(insertionRow); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 172 | |
dbates@webkit.org | e113183 | 2009-11-19 00:05:57 +0000 | [diff] [blame] | 173 | if (!beforeChild) |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 174 | setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[insertionRow]); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 175 | |
inferno@chromium.org | a8d7192 | 2012-04-09 16:03:46 +0000 | [diff] [blame] | 176 | if (beforeChild && beforeChild->parent() != this) |
| 177 | beforeChild = splitAnonymousBoxesAroundChild(beforeChild); |
mjs | 6666eee7 | 2006-07-14 07:45:13 +0000 | [diff] [blame] | 178 | |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 179 | ASSERT(!beforeChild || is<RenderTableRow>(*beforeChild)); |
hyatt@apple.com | f073d9b | 2009-02-05 00:53:38 +0000 | [diff] [blame] | 180 | RenderBox::addChild(child, beforeChild); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 181 | } |
| 182 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 183 | void RenderTableSection::ensureRows(unsigned numRows) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 184 | { |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 185 | if (numRows <= m_grid.size()) |
| 186 | return; |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 187 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 188 | unsigned oldSize = m_grid.size(); |
| 189 | m_grid.grow(numRows); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 190 | |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 191 | unsigned effectiveColumnCount = std::max(1u, table()->numEffCols()); |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 192 | for (unsigned row = oldSize; row < m_grid.size(); ++row) |
akling@apple.com | 194ce1d | 2013-11-13 11:46:51 +0000 | [diff] [blame] | 193 | m_grid[row].row.resizeToFit(effectiveColumnCount); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 194 | } |
| 195 | |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 196 | void RenderTableSection::addCell(RenderTableCell* cell, RenderTableRow* row) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 197 | { |
jchaffraix@webkit.org | b86b64e | 2011-11-14 21:21:43 +0000 | [diff] [blame] | 198 | // We don't insert the cell if we need cell recalc as our internal columns' representation |
| 199 | // will have drifted from the table's representation. Also recalcCells will call addCell |
| 200 | // at a later time after sync'ing our columns' with the table's. |
| 201 | if (needsCellRecalc()) |
| 202 | return; |
| 203 | |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 204 | unsigned rSpan = cell->rowSpan(); |
| 205 | unsigned cSpan = cell->colSpan(); |
jchaffraix@webkit.org | b87ce75 | 2012-10-15 21:52:22 +0000 | [diff] [blame] | 206 | const Vector<RenderTable::ColumnStruct>& columns = table()->columns(); |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 207 | unsigned nCols = columns.size(); |
jchaffraix@webkit.org | a0177fd | 2012-05-01 03:13:06 +0000 | [diff] [blame] | 208 | unsigned insertionRow = row->rowIndex(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 209 | |
| 210 | // ### mozilla still seems to do the old HTML way, even for strict DTD |
| 211 | // (see the annotation on table cell layouting in the CSS specs and the testcase below: |
| 212 | // <TABLE border> |
| 213 | // <TR><TD>1 <TD rowspan="2">2 <TD>3 <TD>4 |
| 214 | // <TR><TD colspan="2">5 |
| 215 | // </TABLE> |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 216 | 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] | 217 | m_cCol++; |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 218 | |
jchaffraix@webkit.org | 74857b4 | 2011-12-20 14:08:52 +0000 | [diff] [blame] | 219 | updateLogicalHeightForCell(m_grid[insertionRow], cell); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 220 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 221 | ensureRows(insertionRow + rSpan); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 222 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 223 | m_grid[insertionRow].rowRenderer = row; |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 224 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 225 | unsigned col = m_cCol; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 226 | // tell the cell where it is |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 227 | bool inColSpan = false; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 228 | while (cSpan) { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 229 | unsigned currentSpan; |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 230 | if (m_cCol >= nCols) { |
| 231 | table()->appendColumn(cSpan); |
| 232 | currentSpan = cSpan; |
| 233 | } else { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 234 | if (cSpan < columns[m_cCol].span) |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 235 | table()->splitColumn(m_cCol, cSpan); |
| 236 | currentSpan = columns[m_cCol].span; |
| 237 | } |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 238 | for (unsigned r = 0; r < rSpan; r++) { |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 239 | CellStruct& c = cellAt(insertionRow + r, m_cCol); |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 240 | ASSERT(cell); |
| 241 | c.cells.append(cell); |
| 242 | // If cells overlap then we take the slow path for painting. |
| 243 | if (c.cells.size() > 1) |
| 244 | m_hasMultipleCellLevels = true; |
| 245 | if (inColSpan) |
| 246 | c.inColSpan = true; |
| 247 | } |
| 248 | m_cCol++; |
| 249 | cSpan -= currentSpan; |
| 250 | inColSpan = true; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 251 | } |
eric@webkit.org | 5832ab7 | 2009-03-25 22:15:03 +0000 | [diff] [blame] | 252 | cell->setCol(table()->effColToCol(col)); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 253 | } |
| 254 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 255 | LayoutUnit RenderTableSection::calcRowLogicalHeight() |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 256 | { |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 257 | #ifndef NDEBUG |
ojan@chromium.org | ccdc429 | 2013-02-07 00:55:10 +0000 | [diff] [blame] | 258 | SetLayoutNeededForbiddenScope layoutForbiddenScope(this); |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 259 | #endif |
| 260 | |
| 261 | ASSERT(!needsLayout()); |
| 262 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 263 | RenderTableCell* cell; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 264 | |
ossy@webkit.org | cf6bebb | 2013-11-25 14:57:38 +0000 | [diff] [blame] | 265 | // We ignore the border-spacing on any non-top section as it is already included in the previous section's last row position. |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 266 | LayoutUnit spacing = 0; |
ossy@webkit.org | cf6bebb | 2013-11-25 14:57:38 +0000 | [diff] [blame] | 267 | if (this == table()->topSection()) |
| 268 | spacing = table()->vBorderSpacing(); |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 269 | |
weinig@apple.com | f8d77f3 | 2013-11-18 01:12:17 +0000 | [diff] [blame] | 270 | LayoutStateMaintainer statePusher(view()); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 271 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 272 | m_rowPos.resize(m_grid.size() + 1); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 273 | m_rowPos[0] = spacing; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 274 | |
commit-queue@webkit.org | 1fdc04c | 2013-04-23 06:36:45 +0000 | [diff] [blame] | 275 | unsigned totalRows = m_grid.size(); |
| 276 | |
| 277 | for (unsigned r = 0; r < totalRows; r++) { |
zimmermann@webkit.org | 14b310a | 2012-02-25 09:27:25 +0000 | [diff] [blame] | 278 | m_grid[r].baseline = 0; |
leviw@chromium.org | 2650e38 | 2012-04-04 10:37:36 +0000 | [diff] [blame] | 279 | LayoutUnit baselineDescent = 0; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 280 | |
jchaffraix@webkit.org | addd65e | 2012-02-26 00:19:22 +0000 | [diff] [blame] | 281 | // Our base size is the biggest logical height from our cells' styles (excluding row spanning cells). |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 282 | m_rowPos[r + 1] = std::max(m_rowPos[r] + minimumValueForLength(m_grid[r].logicalHeight, 0), LayoutUnit::fromPixel(0)); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 283 | |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 284 | Row& row = m_grid[r].row; |
| 285 | unsigned totalCols = row.size(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 286 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 287 | for (unsigned c = 0; c < totalCols; c++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 288 | CellStruct& current = cellAt(r, c); |
commit-queue@webkit.org | 5ec57ca | 2012-07-12 22:33:36 +0000 | [diff] [blame] | 289 | for (unsigned i = 0; i < current.cells.size(); i++) { |
| 290 | cell = current.cells[i]; |
| 291 | if (current.inColSpan && cell->rowSpan() == 1) |
| 292 | continue; |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 293 | |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 294 | // FIXME: We are always adding the height of a rowspan to the last rows which doesn't match |
| 295 | // other browsers. See webkit.org/b/52185 for example. |
| 296 | if ((cell->rowIndex() + cell->rowSpan() - 1) != r) { |
| 297 | // We will apply the height of the rowspan to the current row if next row is not valid. |
| 298 | if ((r + 1) < totalRows) { |
| 299 | unsigned col = 0; |
| 300 | CellStruct nextRowCell = cellAt(r + 1, col); |
commit-queue@webkit.org | 1fdc04c | 2013-04-23 06:36:45 +0000 | [diff] [blame] | 301 | |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 302 | // We are trying to find that next row is valid or not. |
| 303 | while (nextRowCell.cells.size() && nextRowCell.cells[0]->rowSpan() > 1 && nextRowCell.cells[0]->rowIndex() < (r + 1)) { |
| 304 | col++; |
| 305 | if (col < totalCols) |
| 306 | nextRowCell = cellAt(r + 1, col); |
| 307 | else |
| 308 | break; |
commit-queue@webkit.org | 1fdc04c | 2013-04-23 06:36:45 +0000 | [diff] [blame] | 309 | } |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 310 | |
| 311 | // We are adding the height of the rowspan to the current row if next row is not valid. |
| 312 | if (col < totalCols && nextRowCell.cells.size()) |
| 313 | continue; |
commit-queue@webkit.org | 1fdc04c | 2013-04-23 06:36:45 +0000 | [diff] [blame] | 314 | } |
| 315 | } |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 316 | |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 317 | // For row spanning cells, |r| is the last row in the span. |
| 318 | unsigned cellStartRow = cell->rowIndex(); |
| 319 | |
rego@igalia.com | f7d624c | 2015-04-22 10:31:24 +0000 | [diff] [blame] | 320 | if (cell->hasOverrideLogicalContentHeight()) { |
commit-queue@webkit.org | 5ec57ca | 2012-07-12 22:33:36 +0000 | [diff] [blame] | 321 | if (!statePusher.didPush()) { |
| 322 | // Technically, we should also push state for the row, but since |
| 323 | // rows don't push a coordinate transform, that's not necessary. |
weinig@apple.com | f8d77f3 | 2013-11-18 01:12:17 +0000 | [diff] [blame] | 324 | statePusher.push(*this, locationOffset()); |
commit-queue@webkit.org | 5ec57ca | 2012-07-12 22:33:36 +0000 | [diff] [blame] | 325 | } |
| 326 | cell->clearIntrinsicPadding(); |
| 327 | cell->clearOverrideSize(); |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 328 | cell->setChildNeedsLayout(MarkOnlyThis); |
commit-queue@webkit.org | 5ec57ca | 2012-07-12 22:33:36 +0000 | [diff] [blame] | 329 | cell->layoutIfNeeded(); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 330 | } |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 331 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 332 | LayoutUnit cellLogicalHeight = cell->logicalHeightForRowSizing(); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 333 | 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] | 334 | |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 335 | // 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] | 336 | if (cell->isBaselineAligned()) { |
zalan@apple.com | df6351f | 2016-01-11 22:03:03 +0000 | [diff] [blame] | 337 | LayoutUnit baselinePosition = cell->cellBaselinePosition() - cell->intrinsicPaddingBefore(); |
| 338 | LayoutUnit borderAndComputedPaddingBefore = cell->borderAndPaddingBefore() - cell->intrinsicPaddingBefore(); |
| 339 | if (baselinePosition > borderAndComputedPaddingBefore) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 340 | 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] | 341 | // 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 |
| 342 | // become the baseline descent applied to the rest of the row. Also we don't account for the baseline descent of |
| 343 | // non-spanning cells when computing a spanning cell's extent. |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 344 | LayoutUnit cellStartRowBaselineDescent = 0; |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 345 | if (cell->rowSpan() == 1) { |
zalan@apple.com | df6351f | 2016-01-11 22:03:03 +0000 | [diff] [blame] | 346 | baselineDescent = std::max(baselineDescent, cellLogicalHeight - baselinePosition); |
commit-queue@webkit.org | bb45481 | 2013-05-14 19:57:51 +0000 | [diff] [blame] | 347 | cellStartRowBaselineDescent = baselineDescent; |
| 348 | } |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 349 | m_rowPos[cellStartRow + 1] = std::max(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] | 350 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 351 | } |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 354 | |
jchaffraix@webkit.org | addd65e | 2012-02-26 00:19:22 +0000 | [diff] [blame] | 355 | // Add the border-spacing to our final position. |
ossy@webkit.org | 6d30aa7 | 2013-11-28 17:40:59 +0000 | [diff] [blame] | 356 | // Use table border-spacing even in non-top sections |
| 357 | spacing = table()->vBorderSpacing(); |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 358 | m_rowPos[r + 1] += m_grid[r].rowRenderer ? spacing : LayoutUnit::fromPixel(0); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 359 | m_rowPos[r + 1] = std::max(m_rowPos[r + 1], m_rowPos[r]); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 360 | } |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 361 | |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 362 | ASSERT(!needsLayout()); |
| 363 | |
simon.fraser@apple.com | feaef2e | 2008-11-07 19:17:08 +0000 | [diff] [blame] | 364 | statePusher.pop(); |
mitz@apple.com | 440ac8c | 2008-04-05 16:05:08 +0000 | [diff] [blame] | 365 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 366 | return m_rowPos[m_grid.size()]; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 367 | } |
| 368 | |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 369 | void RenderTableSection::layout() |
| 370 | { |
mark.lam@apple.com | 6df1a80 | 2012-10-19 20:09:36 +0000 | [diff] [blame] | 371 | StackStats::LayoutCheckPoint layoutCheckPoint; |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 372 | ASSERT(needsLayout()); |
inferno@chromium.org | 7081f50 | 2012-05-26 00:28:23 +0000 | [diff] [blame] | 373 | ASSERT(!needsCellRecalc()); |
| 374 | ASSERT(!table()->needsSectionRecalc()); |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 375 | |
jchaffraix@webkit.org | a9ddfc1 | 2012-06-18 17:11:12 +0000 | [diff] [blame] | 376 | // addChild may over-grow m_grid but we don't want to throw away the memory too early as addChild |
| 377 | // can be called in a loop (e.g during parsing). Doing it now ensures we have a stable-enough structure. |
| 378 | m_grid.shrinkToFit(); |
| 379 | |
weinig@apple.com | f8d77f3 | 2013-11-18 01:12:17 +0000 | [diff] [blame] | 380 | LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode()); |
hyatt@apple.com | ccad374 | 2015-02-04 21:39:00 +0000 | [diff] [blame] | 381 | bool paginated = view().layoutState()->isPaginated(); |
| 382 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 383 | const Vector<LayoutUnit>& columnPos = table()->columnPositions(); |
hyatt@apple.com | ccad374 | 2015-02-04 21:39:00 +0000 | [diff] [blame] | 384 | |
jchaffraix@webkit.org | a66f108 | 2012-10-16 16:42:02 +0000 | [diff] [blame] | 385 | for (unsigned r = 0; r < m_grid.size(); ++r) { |
| 386 | Row& row = m_grid[r].row; |
| 387 | unsigned cols = row.size(); |
| 388 | // First, propagate our table layout's information to the cells. This will mark the row as needing layout |
| 389 | // if there was a column logical width change. |
| 390 | for (unsigned startColumn = 0; startColumn < cols; ++startColumn) { |
| 391 | CellStruct& current = row[startColumn]; |
| 392 | RenderTableCell* cell = current.primaryCell(); |
| 393 | if (!cell || current.inColSpan) |
| 394 | continue; |
| 395 | |
| 396 | unsigned endCol = startColumn; |
| 397 | unsigned cspan = cell->colSpan(); |
| 398 | while (cspan && endCol < cols) { |
| 399 | ASSERT(endCol < table()->columns().size()); |
| 400 | cspan -= table()->columns()[endCol].span; |
| 401 | endCol++; |
| 402 | } |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 403 | LayoutUnit tableLayoutLogicalWidth = columnPos[endCol] - columnPos[startColumn] - table()->hBorderSpacing(); |
jchaffraix@webkit.org | a66f108 | 2012-10-16 16:42:02 +0000 | [diff] [blame] | 404 | cell->setCellLogicalWidth(tableLayoutLogicalWidth); |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 405 | } |
jchaffraix@webkit.org | a66f108 | 2012-10-16 16:42:02 +0000 | [diff] [blame] | 406 | |
hyatt@apple.com | ccad374 | 2015-02-04 21:39:00 +0000 | [diff] [blame] | 407 | if (RenderTableRow* rowRenderer = m_grid[r].rowRenderer) { |
| 408 | if (!rowRenderer->needsLayout() && paginated && view().layoutState()->pageLogicalHeightChanged()) |
| 409 | rowRenderer->setChildNeedsLayout(MarkOnlyThis); |
| 410 | |
jchaffraix@webkit.org | a66f108 | 2012-10-16 16:42:02 +0000 | [diff] [blame] | 411 | rowRenderer->layoutIfNeeded(); |
hyatt@apple.com | ccad374 | 2015-02-04 21:39:00 +0000 | [diff] [blame] | 412 | } |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 413 | } |
jchaffraix@webkit.org | a66f108 | 2012-10-16 16:42:02 +0000 | [diff] [blame] | 414 | |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 415 | statePusher.pop(); |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 416 | clearNeedsLayout(); |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 417 | } |
| 418 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 419 | void RenderTableSection::distributeExtraLogicalHeightToPercentRows(LayoutUnit& extraLogicalHeight, int totalPercent) |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 420 | { |
| 421 | if (!totalPercent) |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 422 | return; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 423 | |
| 424 | unsigned totalRows = m_grid.size(); |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 425 | LayoutUnit totalHeight = m_rowPos[totalRows] + extraLogicalHeight; |
| 426 | LayoutUnit totalLogicalHeightAdded = 0; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 427 | totalPercent = std::min(totalPercent, 100); |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 428 | LayoutUnit rowHeight = m_rowPos[1] - m_rowPos[0]; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 429 | for (unsigned r = 0; r < totalRows; ++r) { |
commit-queue@webkit.org | 2a67f68 | 2015-05-10 21:43:26 +0000 | [diff] [blame] | 430 | if (totalPercent > 0 && m_grid[r].logicalHeight.isPercent()) { |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 431 | LayoutUnit toAdd = std::min<LayoutUnit>(extraLogicalHeight, (totalHeight * m_grid[r].logicalHeight.percent() / 100) - rowHeight); |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 432 | // If toAdd is negative, then we don't want to shrink the row (this bug |
| 433 | // affected Outlook Web Access). |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 434 | toAdd = std::max(LayoutUnit::fromPixel(0), toAdd); |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 435 | totalLogicalHeightAdded += toAdd; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 436 | extraLogicalHeight -= toAdd; |
| 437 | totalPercent -= m_grid[r].logicalHeight.percent(); |
| 438 | } |
| 439 | ASSERT(totalRows >= 1); |
| 440 | if (r < totalRows - 1) |
| 441 | rowHeight = m_rowPos[r + 2] - m_rowPos[r + 1]; |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 442 | m_rowPos[r + 1] += totalLogicalHeightAdded; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 443 | } |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 444 | } |
| 445 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 446 | void RenderTableSection::distributeExtraLogicalHeightToAutoRows(LayoutUnit& extraLogicalHeight, unsigned autoRowsCount) |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 447 | { |
| 448 | if (!autoRowsCount) |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 449 | return; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 450 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 451 | LayoutUnit totalLogicalHeightAdded = 0; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 452 | for (unsigned r = 0; r < m_grid.size(); ++r) { |
| 453 | if (autoRowsCount > 0 && m_grid[r].logicalHeight.isAuto()) { |
| 454 | // Recomputing |extraLogicalHeightForRow| guarantees that we properly ditribute round |extraLogicalHeight|. |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 455 | LayoutUnit extraLogicalHeightForRow = extraLogicalHeight / autoRowsCount; |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 456 | totalLogicalHeightAdded += extraLogicalHeightForRow; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 457 | extraLogicalHeight -= extraLogicalHeightForRow; |
| 458 | --autoRowsCount; |
| 459 | } |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 460 | m_rowPos[r + 1] += totalLogicalHeightAdded; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 461 | } |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 462 | } |
| 463 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 464 | void RenderTableSection::distributeRemainingExtraLogicalHeight(LayoutUnit& extraLogicalHeight) |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 465 | { |
| 466 | unsigned totalRows = m_grid.size(); |
| 467 | |
| 468 | if (extraLogicalHeight <= 0 || !m_rowPos[totalRows]) |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 469 | return; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 470 | |
| 471 | // FIXME: m_rowPos[totalRows] - m_rowPos[0] is the total rows' size. |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 472 | LayoutUnit totalRowSize = m_rowPos[totalRows]; |
| 473 | LayoutUnit totalLogicalHeightAdded = 0; |
| 474 | LayoutUnit previousRowPosition = m_rowPos[0]; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 475 | for (unsigned r = 0; r < totalRows; r++) { |
| 476 | // weight with the original height |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 477 | totalLogicalHeightAdded += extraLogicalHeight * (m_rowPos[r + 1] - previousRowPosition) / totalRowSize; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 478 | previousRowPosition = m_rowPos[r + 1]; |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 479 | m_rowPos[r + 1] += totalLogicalHeightAdded; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 480 | } |
| 481 | |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 482 | extraLogicalHeight -= totalLogicalHeightAdded; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 483 | } |
| 484 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 485 | LayoutUnit RenderTableSection::distributeExtraLogicalHeightToRows(LayoutUnit extraLogicalHeight) |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 486 | { |
| 487 | if (!extraLogicalHeight) |
| 488 | return extraLogicalHeight; |
| 489 | |
| 490 | unsigned totalRows = m_grid.size(); |
| 491 | if (!totalRows) |
| 492 | return extraLogicalHeight; |
| 493 | |
| 494 | if (!m_rowPos[totalRows] && nextSibling()) |
| 495 | return extraLogicalHeight; |
| 496 | |
| 497 | unsigned autoRowsCount = 0; |
| 498 | int totalPercent = 0; |
| 499 | for (unsigned r = 0; r < totalRows; r++) { |
| 500 | if (m_grid[r].logicalHeight.isAuto()) |
| 501 | ++autoRowsCount; |
commit-queue@webkit.org | 2a67f68 | 2015-05-10 21:43:26 +0000 | [diff] [blame] | 502 | else if (m_grid[r].logicalHeight.isPercent()) |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 503 | totalPercent += m_grid[r].logicalHeight.percent(); |
| 504 | } |
| 505 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 506 | LayoutUnit remainingExtraLogicalHeight = extraLogicalHeight; |
jchaffraix@webkit.org | c278898 | 2012-03-20 21:02:34 +0000 | [diff] [blame] | 507 | distributeExtraLogicalHeightToPercentRows(remainingExtraLogicalHeight, totalPercent); |
| 508 | distributeExtraLogicalHeightToAutoRows(remainingExtraLogicalHeight, autoRowsCount); |
| 509 | distributeRemainingExtraLogicalHeight(remainingExtraLogicalHeight); |
| 510 | return extraLogicalHeight - remainingExtraLogicalHeight; |
jchaffraix@webkit.org | 3395b97 | 2012-03-09 22:58:05 +0000 | [diff] [blame] | 511 | } |
| 512 | |
jchaffraix@webkit.org | 94f150f | 2012-03-20 04:53:14 +0000 | [diff] [blame] | 513 | void RenderTableSection::layoutRows() |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 514 | { |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 515 | #ifndef NDEBUG |
ojan@chromium.org | ccdc429 | 2013-02-07 00:55:10 +0000 | [diff] [blame] | 516 | SetLayoutNeededForbiddenScope layoutForbiddenScope(this); |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 517 | #endif |
| 518 | |
| 519 | ASSERT(!needsLayout()); |
| 520 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 521 | unsigned totalRows = m_grid.size(); |
| 522 | |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 523 | // 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] | 524 | setLogicalWidth(table()->contentLogicalWidth()); |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 525 | m_forceSlowPaintPathWithOverflowingCell = false; |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 526 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 527 | LayoutUnit vspacing = table()->vBorderSpacing(); |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 528 | unsigned nEffCols = table()->numEffCols(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 529 | |
weinig@apple.com | f8d77f3 | 2013-11-18 01:12:17 +0000 | [diff] [blame] | 530 | LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || style().isFlippedBlocksWritingMode()); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 531 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 532 | for (unsigned r = 0; r < totalRows; r++) { |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 533 | // Set the row's x/y position and width/height. |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 534 | if (RenderTableRow* rowRenderer = m_grid[r].rowRenderer) { |
robert@webkit.org | f9766b1 | 2013-08-27 19:21:00 +0000 | [diff] [blame] | 535 | // FIXME: the x() position of the row should be table()->hBorderSpacing() so that it can |
| 536 | // 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] | 537 | rowRenderer->setLocation(LayoutPoint(0, m_rowPos[r])); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 538 | rowRenderer->setLogicalWidth(logicalWidth()); |
| 539 | rowRenderer->setLogicalHeight(m_rowPos[r + 1] - m_rowPos[r] - vspacing); |
simon.fraser@apple.com | 78e3bdb | 2010-11-30 00:53:05 +0000 | [diff] [blame] | 540 | rowRenderer->updateLayerTransform(); |
zalan@apple.com | d423bcc | 2016-02-06 23:07:54 +0000 | [diff] [blame] | 541 | rowRenderer->clearOverflow(); |
| 542 | rowRenderer->addVisualEffectOverflow(); |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 543 | } |
| 544 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 545 | LayoutUnit rowHeightIncreaseForPagination = 0; |
mitz@apple.com | 48b3ee8 | 2012-07-12 02:38:38 +0000 | [diff] [blame] | 546 | |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 547 | for (unsigned c = 0; c < nEffCols; c++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 548 | CellStruct& cs = cellAt(r, c); |
| 549 | RenderTableCell* cell = cs.primaryCell(); |
| 550 | |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 551 | if (!cell || cs.inColSpan) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 552 | continue; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 553 | |
jchaffraix@webkit.org | 83cb391 | 2012-10-05 03:56:17 +0000 | [diff] [blame] | 554 | int rowIndex = cell->rowIndex(); |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 555 | LayoutUnit rHeight = m_rowPos[rowIndex + cell->rowSpan()] - m_rowPos[rowIndex] - vspacing; |
jchaffraix@webkit.org | 83cb391 | 2012-10-05 03:56:17 +0000 | [diff] [blame] | 556 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 557 | // Force percent height children to lay themselves out again. |
| 558 | // This will cause these children to grow to fill the cell. |
| 559 | // FIXME: There is still more work to do here to fully match WinIE (should |
| 560 | // it become necessary to do so). In quirks mode, WinIE behaves like we |
| 561 | // do, but it will clip the cells that spill out of the table section. In |
| 562 | // strict mode, Mozilla and WinIE both regrow the table to accommodate the |
| 563 | // new height of the cell (thus letting the percentages cause growth one |
| 564 | // time only). We may also not be handling row-spanning cells correctly. |
| 565 | // |
| 566 | // Note also the oddity where replaced elements always flex, and yet blocks/tables do |
| 567 | // not necessarily flex. WinIE is crazy and inconsistent, and we can't hope to |
| 568 | // match the behavior perfectly, but we'll continue to refine it as we discover new |
| 569 | // bugs. :) |
| 570 | bool cellChildrenFlex = false; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 571 | bool flexAllChildren = cell->style().logicalHeight().isFixed() |
| 572 | || (!table()->style().logicalHeight().isAuto() && rHeight != cell->logicalHeight()); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 573 | |
cdumez@apple.com | 6962695 | 2016-05-17 22:39:00 +0000 | [diff] [blame] | 574 | for (auto& renderer : childrenOfType<RenderObject>(*cell)) { |
| 575 | if (!is<RenderText>(renderer) && renderer.style().logicalHeight().isPercentOrCalculated() && (flexAllChildren || ((renderer.isReplaced() || (is<RenderBox>(renderer) && downcast<RenderBox>(renderer).scrollsOverflow())) && !is<RenderTextControl>(renderer)))) { |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 576 | // Tables with no sections do not flex. |
cdumez@apple.com | 6962695 | 2016-05-17 22:39:00 +0000 | [diff] [blame] | 577 | if (!is<RenderTable>(renderer) || downcast<RenderTable>(renderer).hasSections()) { |
| 578 | renderer.setNeedsLayout(MarkOnlyThis); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 579 | cellChildrenFlex = true; |
| 580 | } |
| 581 | } |
| 582 | } |
mitz@apple.com | 1547c6d | 2009-03-20 23:41:54 +0000 | [diff] [blame] | 583 | |
tony@chromium.org | 05b9d2c | 2012-09-05 01:31:38 +0000 | [diff] [blame] | 584 | if (TrackedRendererListHashSet* percentHeightDescendants = cell->percentHeightDescendants()) { |
| 585 | TrackedRendererListHashSet::iterator end = percentHeightDescendants->end(); |
| 586 | for (TrackedRendererListHashSet::iterator it = percentHeightDescendants->begin(); it != end; ++it) { |
mitz@apple.com | 1547c6d | 2009-03-20 23:41:54 +0000 | [diff] [blame] | 587 | RenderBox* box = *it; |
| 588 | if (!box->isReplaced() && !box->scrollsOverflow() && !flexAllChildren) |
| 589 | continue; |
| 590 | |
| 591 | while (box != cell) { |
| 592 | if (box->normalChildNeedsLayout()) |
| 593 | break; |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 594 | box->setChildNeedsLayout(MarkOnlyThis); |
mitz@apple.com | 1547c6d | 2009-03-20 23:41:54 +0000 | [diff] [blame] | 595 | box = box->containingBlock(); |
| 596 | ASSERT(box); |
| 597 | if (!box) |
| 598 | break; |
| 599 | } |
| 600 | cellChildrenFlex = true; |
| 601 | } |
| 602 | } |
| 603 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 604 | if (cellChildrenFlex) { |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 605 | cell->setChildNeedsLayout(MarkOnlyThis); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 606 | // Alignment within a cell is based off the calculated |
| 607 | // height, which becomes irrelevant once the cell has |
hyatt@apple.com | 0bf6c84 | 2009-01-23 03:42:12 +0000 | [diff] [blame] | 608 | // been resized based off its percentage. |
ojan@chromium.org | 7a1ce8b | 2012-06-05 18:32:10 +0000 | [diff] [blame] | 609 | cell->setOverrideLogicalContentHeightFromRowHeight(rHeight); |
ap | 7332aaa | 2006-04-28 16:02:45 +0000 | [diff] [blame] | 610 | cell->layoutIfNeeded(); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 611 | |
hyatt | 851433b | 2007-05-12 06:40:14 +0000 | [diff] [blame] | 612 | // 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] | 613 | if (cell->isBaselineAligned()) { |
leviw@chromium.org | 2650e38 | 2012-04-04 10:37:36 +0000 | [diff] [blame] | 614 | LayoutUnit baseline = cell->cellBaselinePosition(); |
zoltan@webkit.org | 8e79cc2 | 2013-06-14 00:39:36 +0000 | [diff] [blame] | 615 | if (baseline > cell->borderAndPaddingBefore()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 616 | m_grid[r].baseline = std::max(m_grid[r].baseline, baseline); |
hyatt | 851433b | 2007-05-12 06:40:14 +0000 | [diff] [blame] | 617 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 618 | } |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 619 | |
jchaffraix@webkit.org | 83cb391 | 2012-10-05 03:56:17 +0000 | [diff] [blame] | 620 | cell->computeIntrinsicPadding(rHeight); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 621 | |
eae@chromium.org | 1146f21 | 2012-07-18 22:06:34 +0000 | [diff] [blame] | 622 | LayoutRect oldCellRect = cell->frameRect(); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 623 | |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 624 | setLogicalPositionForCell(cell, c); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 625 | |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 626 | 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] | 627 | cell->setChildNeedsLayout(MarkOnlyThis); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 628 | |
hyatt@apple.com | 1259d73 | 2010-09-20 16:12:58 +0000 | [diff] [blame] | 629 | cell->layoutIfNeeded(); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 630 | |
| 631 | // FIXME: Make pagination work with vertical tables. |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 632 | if (view().layoutState()->pageLogicalHeight() && cell->logicalHeight() != rHeight) { |
hyatt@apple.com | 8403ad2 | 2012-04-10 18:14:20 +0000 | [diff] [blame] | 633 | // FIXME: Pagination might have made us change size. For now just shrink or grow the cell to fit without doing a relayout. |
| 634 | // 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 |
| 635 | // 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] | 636 | if (cell->logicalHeight() > rHeight) |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 637 | rowHeightIncreaseForPagination = std::max(rowHeightIncreaseForPagination, cell->logicalHeight() - rHeight); |
mitz@apple.com | 48b3ee8 | 2012-07-12 02:38:38 +0000 | [diff] [blame] | 638 | cell->setLogicalHeight(rHeight); |
hyatt@apple.com | 8403ad2 | 2012-04-10 18:14:20 +0000 | [diff] [blame] | 639 | } |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 640 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 641 | LayoutSize childOffset(cell->location() - oldCellRect.location()); |
hyatt@apple.com | b297b49 | 2010-09-20 20:21:34 +0000 | [diff] [blame] | 642 | if (childOffset.width() || childOffset.height()) { |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 643 | view().addLayoutDelta(childOffset); |
hyatt@apple.com | 1259d73 | 2010-09-20 16:12:58 +0000 | [diff] [blame] | 644 | |
hyatt@apple.com | b297b49 | 2010-09-20 20:21:34 +0000 | [diff] [blame] | 645 | // If the child moved, we have to repaint it as well as any floating/positioned |
| 646 | // descendants. An exception is if we need a layout. In this case, we know we're going to |
| 647 | // repaint ourselves (and the child) anyway. |
| 648 | if (!table()->selfNeedsLayout() && cell->checkForRepaintDuringLayout()) |
| 649 | cell->repaintDuringLayoutIfMoved(oldCellRect); |
| 650 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 651 | } |
mitz@apple.com | 48b3ee8 | 2012-07-12 02:38:38 +0000 | [diff] [blame] | 652 | if (rowHeightIncreaseForPagination) { |
| 653 | for (unsigned rowIndex = r + 1; rowIndex <= totalRows; rowIndex++) |
| 654 | m_rowPos[rowIndex] += rowHeightIncreaseForPagination; |
| 655 | for (unsigned c = 0; c < nEffCols; ++c) { |
| 656 | Vector<RenderTableCell*, 1>& cells = cellAt(r, c).cells; |
| 657 | for (size_t i = 0; i < cells.size(); ++i) |
| 658 | cells[i]->setLogicalHeight(cells[i]->logicalHeight() + rowHeightIncreaseForPagination); |
| 659 | } |
| 660 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 661 | } |
| 662 | |
hyatt@apple.com | 8b2cd1f | 2009-01-26 03:38:55 +0000 | [diff] [blame] | 663 | ASSERT(!needsLayout()); |
| 664 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 665 | setLogicalHeight(m_rowPos[totalRows]); |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 666 | |
robert@webkit.org | 4c91cc9 | 2013-03-27 23:49:48 +0000 | [diff] [blame] | 667 | computeOverflowFromCells(totalRows, nEffCols); |
| 668 | |
| 669 | statePusher.pop(); |
| 670 | } |
| 671 | |
| 672 | void RenderTableSection::computeOverflowFromCells() |
| 673 | { |
| 674 | unsigned totalRows = m_grid.size(); |
| 675 | unsigned nEffCols = table()->numEffCols(); |
| 676 | computeOverflowFromCells(totalRows, nEffCols); |
| 677 | } |
| 678 | |
| 679 | void RenderTableSection::computeOverflowFromCells(unsigned totalRows, unsigned nEffCols) |
| 680 | { |
abucur@adobe.com | 6585d01 | 2013-09-04 08:26:41 +0000 | [diff] [blame] | 681 | clearOverflow(); |
robert@webkit.org | e4314c4 | 2013-08-08 18:13:22 +0000 | [diff] [blame] | 682 | m_overflowingCells.clear(); |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 683 | unsigned totalCellsCount = nEffCols * totalRows; |
commit-queue@webkit.org | 877bfc3 | 2015-03-10 21:54:21 +0000 | [diff] [blame] | 684 | unsigned maxAllowedOverflowingCellsCount = totalCellsCount < gMinTableSizeToUseFastPaintPathWithOverflowingCell ? 0 : gMaxAllowedOverflowingCellRatioForFastPaintPath * totalCellsCount; |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 685 | |
| 686 | #ifndef NDEBUG |
| 687 | bool hasOverflowingCell = false; |
| 688 | #endif |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 689 | // 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] | 690 | for (unsigned r = 0; r < totalRows; r++) { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 691 | for (unsigned c = 0; c < nEffCols; c++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 692 | CellStruct& cs = cellAt(r, c); |
| 693 | RenderTableCell* cell = cs.primaryCell(); |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 694 | if (!cell || cs.inColSpan) |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 695 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 696 | if (r < totalRows - 1 && cell == primaryCellAt(r + 1, c)) |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 697 | continue; |
| 698 | addOverflowFromChild(cell); |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 699 | #ifndef NDEBUG |
| 700 | hasOverflowingCell |= cell->hasVisualOverflow(); |
| 701 | #endif |
| 702 | if (cell->hasVisualOverflow() && !m_forceSlowPaintPathWithOverflowingCell) { |
| 703 | m_overflowingCells.add(cell); |
| 704 | if (m_overflowingCells.size() > maxAllowedOverflowingCellsCount) { |
| 705 | // We need to set m_forcesSlowPaintPath only if there is a least one overflowing cells as the hit testing code rely on this information. |
| 706 | m_forceSlowPaintPathWithOverflowingCell = true; |
| 707 | // The slow path does not make any use of the overflowing cells info, don't hold on to the memory. |
| 708 | m_overflowingCells.clear(); |
| 709 | } |
| 710 | } |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 711 | } |
| 712 | } |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 713 | ASSERT(hasOverflowingCell == this->hasOverflowingCell()); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 714 | } |
| 715 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 716 | LayoutUnit RenderTableSection::calcOuterBorderBefore() const |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 717 | { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 718 | unsigned totalCols = table()->numEffCols(); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 719 | if (!m_grid.size() || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 720 | return 0; |
| 721 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 722 | LayoutUnit borderWidth = 0; |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 723 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 724 | const BorderValue& sb = style().borderBefore(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 725 | if (sb.style() == BHIDDEN) |
| 726 | return -1; |
| 727 | if (sb.style() > BHIDDEN) |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 728 | borderWidth = sb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 729 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 730 | const BorderValue& rb = firstRow()->style().borderBefore(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 731 | if (rb.style() == BHIDDEN) |
| 732 | return -1; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 733 | if (rb.style() > BHIDDEN && rb.width() > borderWidth) |
| 734 | borderWidth = rb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 735 | |
| 736 | bool allHidden = true; |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 737 | for (unsigned c = 0; c < totalCols; c++) { |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 738 | const CellStruct& current = cellAt(0, c); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 739 | if (current.inColSpan || !current.hasCells()) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 740 | continue; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 741 | 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] | 742 | // FIXME: Don't repeat for the same col group |
| 743 | RenderTableCol* colGroup = table()->colElement(c); |
| 744 | if (colGroup) { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 745 | const BorderValue& gb = colGroup->style().borderBefore(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 746 | if (gb.style() == BHIDDEN || cb.style() == BHIDDEN) |
| 747 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 748 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 749 | if (gb.style() > BHIDDEN && gb.width() > borderWidth) |
| 750 | borderWidth = gb.width(); |
| 751 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 752 | borderWidth = cb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 753 | } else { |
| 754 | if (cb.style() == BHIDDEN) |
| 755 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 756 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 757 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 758 | borderWidth = cb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 759 | } |
| 760 | } |
| 761 | if (allHidden) |
| 762 | return -1; |
zalan@apple.com | 6a1fae4a | 2016-03-06 03:10:21 +0000 | [diff] [blame] | 763 | return CollapsedBorderValue::adjustedCollapsedBorderWidth(borderWidth, document().deviceScaleFactor(), false); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 764 | } |
| 765 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 766 | LayoutUnit RenderTableSection::calcOuterBorderAfter() const |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 767 | { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 768 | unsigned totalCols = table()->numEffCols(); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 769 | if (!m_grid.size() || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 770 | return 0; |
| 771 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 772 | LayoutUnit borderWidth = 0; |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 773 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 774 | const BorderValue& sb = style().borderAfter(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 775 | if (sb.style() == BHIDDEN) |
| 776 | return -1; |
| 777 | if (sb.style() > BHIDDEN) |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 778 | borderWidth = sb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 779 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 780 | const BorderValue& rb = lastRow()->style().borderAfter(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 781 | if (rb.style() == BHIDDEN) |
| 782 | return -1; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 783 | if (rb.style() > BHIDDEN && rb.width() > borderWidth) |
| 784 | borderWidth = rb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 785 | |
| 786 | bool allHidden = true; |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 787 | for (unsigned c = 0; c < totalCols; c++) { |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 788 | const CellStruct& current = cellAt(m_grid.size() - 1, c); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 789 | if (current.inColSpan || !current.hasCells()) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 790 | continue; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 791 | 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] | 792 | // FIXME: Don't repeat for the same col group |
| 793 | RenderTableCol* colGroup = table()->colElement(c); |
| 794 | if (colGroup) { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 795 | const BorderValue& gb = colGroup->style().borderAfter(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 796 | if (gb.style() == BHIDDEN || cb.style() == BHIDDEN) |
| 797 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 798 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 799 | if (gb.style() > BHIDDEN && gb.width() > borderWidth) |
| 800 | borderWidth = gb.width(); |
| 801 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 802 | borderWidth = cb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 803 | } else { |
| 804 | if (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 (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 808 | borderWidth = cb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 809 | } |
| 810 | } |
| 811 | if (allHidden) |
| 812 | return -1; |
zalan@apple.com | 6a1fae4a | 2016-03-06 03:10:21 +0000 | [diff] [blame] | 813 | return CollapsedBorderValue::adjustedCollapsedBorderWidth(borderWidth, document().deviceScaleFactor(), true); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 814 | } |
| 815 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 816 | LayoutUnit RenderTableSection::calcOuterBorderStart() const |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 817 | { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 818 | unsigned totalCols = table()->numEffCols(); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 819 | if (!m_grid.size() || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 820 | return 0; |
| 821 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 822 | LayoutUnit borderWidth = 0; |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 823 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 824 | const BorderValue& sb = style().borderStart(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 825 | if (sb.style() == BHIDDEN) |
| 826 | return -1; |
| 827 | if (sb.style() > BHIDDEN) |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 828 | borderWidth = sb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 829 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 830 | if (RenderTableCol* colGroup = table()->colElement(0)) { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 831 | const BorderValue& gb = colGroup->style().borderStart(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 832 | if (gb.style() == BHIDDEN) |
| 833 | return -1; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 834 | if (gb.style() > BHIDDEN && gb.width() > borderWidth) |
| 835 | borderWidth = gb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | bool allHidden = true; |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 839 | for (unsigned r = 0; r < m_grid.size(); r++) { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 840 | const CellStruct& current = cellAt(r, 0); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 841 | if (!current.hasCells()) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 842 | continue; |
| 843 | // FIXME: Don't repeat for the same cell |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 844 | const BorderValue& cb = current.primaryCell()->style().borderStart(); // FIXME: Make this work with perpendicular and flipped cells. |
| 845 | const BorderValue& rb = current.primaryCell()->parent()->style().borderStart(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 846 | if (cb.style() == BHIDDEN || rb.style() == BHIDDEN) |
| 847 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 848 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 849 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 850 | borderWidth = cb.width(); |
| 851 | if (rb.style() > BHIDDEN && rb.width() > borderWidth) |
| 852 | borderWidth = rb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 853 | } |
| 854 | if (allHidden) |
| 855 | return -1; |
zalan@apple.com | 6a1fae4a | 2016-03-06 03:10:21 +0000 | [diff] [blame] | 856 | return CollapsedBorderValue::adjustedCollapsedBorderWidth(borderWidth, document().deviceScaleFactor(), !table()->style().isLeftToRightDirection()); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 857 | } |
| 858 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 859 | LayoutUnit RenderTableSection::calcOuterBorderEnd() const |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 860 | { |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 861 | unsigned totalCols = table()->numEffCols(); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 862 | if (!m_grid.size() || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 863 | return 0; |
| 864 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 865 | LayoutUnit borderWidth = 0; |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 866 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 867 | const BorderValue& sb = style().borderEnd(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 868 | if (sb.style() == BHIDDEN) |
| 869 | return -1; |
| 870 | if (sb.style() > BHIDDEN) |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 871 | borderWidth = sb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 872 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 873 | if (RenderTableCol* colGroup = table()->colElement(totalCols - 1)) { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 874 | const BorderValue& gb = colGroup->style().borderEnd(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 875 | if (gb.style() == BHIDDEN) |
| 876 | return -1; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 877 | if (gb.style() > BHIDDEN && gb.width() > borderWidth) |
| 878 | borderWidth = gb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | bool allHidden = true; |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 882 | for (unsigned r = 0; r < m_grid.size(); r++) { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 883 | const CellStruct& current = cellAt(r, totalCols - 1); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 884 | if (!current.hasCells()) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 885 | continue; |
| 886 | // FIXME: Don't repeat for the same cell |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 887 | const BorderValue& cb = current.primaryCell()->style().borderEnd(); // FIXME: Make this work with perpendicular and flipped cells. |
| 888 | const BorderValue& rb = current.primaryCell()->parent()->style().borderEnd(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 889 | if (cb.style() == BHIDDEN || rb.style() == BHIDDEN) |
| 890 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 891 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 892 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 893 | borderWidth = cb.width(); |
| 894 | if (rb.style() > BHIDDEN && rb.width() > borderWidth) |
| 895 | borderWidth = rb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 896 | } |
| 897 | if (allHidden) |
| 898 | return -1; |
zalan@apple.com | 6a1fae4a | 2016-03-06 03:10:21 +0000 | [diff] [blame] | 899 | return CollapsedBorderValue::adjustedCollapsedBorderWidth(borderWidth, document().deviceScaleFactor(), table()->style().isLeftToRightDirection()); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | void RenderTableSection::recalcOuterBorder() |
| 903 | { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 904 | m_outerBorderBefore = calcOuterBorderBefore(); |
| 905 | m_outerBorderAfter = calcOuterBorderAfter(); |
| 906 | m_outerBorderStart = calcOuterBorderStart(); |
| 907 | m_outerBorderEnd = calcOuterBorderEnd(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 908 | } |
| 909 | |
mmaxfield@apple.com | 5f90774 | 2015-03-11 18:22:06 +0000 | [diff] [blame] | 910 | Optional<int> RenderTableSection::firstLineBaseline() const |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 911 | { |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 912 | if (!m_grid.size()) |
mmaxfield@apple.com | 5f90774 | 2015-03-11 18:22:06 +0000 | [diff] [blame] | 913 | return Optional<int>(); |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 914 | |
eae@chromium.org | 82b9498 | 2012-10-22 18:38:29 +0000 | [diff] [blame] | 915 | int firstLineBaseline = m_grid[0].baseline; |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 916 | if (firstLineBaseline) |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 917 | return firstLineBaseline + roundToInt(m_rowPos[0]); |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 918 | |
mmaxfield@apple.com | 5f90774 | 2015-03-11 18:22:06 +0000 | [diff] [blame] | 919 | Optional<int> result; |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 920 | const Row& firstRow = m_grid[0].row; |
| 921 | for (size_t i = 0; i < firstRow.size(); ++i) { |
| 922 | const CellStruct& cs = firstRow.at(i); |
| 923 | const RenderTableCell* cell = cs.primaryCell(); |
robert@webkit.org | 3b67b1f | 2012-05-16 21:06:10 +0000 | [diff] [blame] | 924 | // Only cells with content have a baseline |
mmaxfield@apple.com | 5f90774 | 2015-03-11 18:22:06 +0000 | [diff] [blame] | 925 | if (cell && cell->contentLogicalHeight()) { |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 926 | int candidate = roundToInt(cell->logicalTop() + cell->borderAndPaddingBefore() + cell->contentLogicalHeight()); |
mmaxfield@apple.com | 5f90774 | 2015-03-11 18:22:06 +0000 | [diff] [blame] | 927 | result = std::max(result.valueOr(candidate), candidate); |
| 928 | } |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 929 | } |
| 930 | |
mmaxfield@apple.com | 5f90774 | 2015-03-11 18:22:06 +0000 | [diff] [blame] | 931 | return result; |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 932 | } |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 933 | |
leviw@chromium.org | b375750 | 2011-06-29 21:33:11 +0000 | [diff] [blame] | 934 | void RenderTableSection::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 935 | { |
inferno@chromium.org | 64a831b | 2012-08-03 19:47:08 +0000 | [diff] [blame] | 936 | // put this back in when all layout tests can handle it |
| 937 | // ASSERT(!needsLayout()); |
| 938 | // 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] | 939 | if (needsLayout()) |
| 940 | return; |
inferno@chromium.org | 64a831b | 2012-08-03 19:47:08 +0000 | [diff] [blame] | 941 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 942 | unsigned totalRows = m_grid.size(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 943 | unsigned totalCols = table()->columns().size(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 944 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 945 | if (!totalRows || !totalCols) |
ap | 0e708ba | 2006-05-20 08:47:37 +0000 | [diff] [blame] | 946 | return; |
| 947 | |
leviw@chromium.org | b375750 | 2011-06-29 21:33:11 +0000 | [diff] [blame] | 948 | LayoutPoint adjustedPaintOffset = paintOffset + location(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 949 | |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 950 | PaintPhase phase = paintInfo.phase; |
leviw@chromium.org | 61ca137 | 2011-06-07 18:56:41 +0000 | [diff] [blame] | 951 | bool pushedClip = pushContentsClip(paintInfo, adjustedPaintOffset); |
| 952 | paintObject(paintInfo, adjustedPaintOffset); |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 953 | if (pushedClip) |
leviw@chromium.org | 61ca137 | 2011-06-07 18:56:41 +0000 | [diff] [blame] | 954 | popContentsClip(paintInfo, phase, adjustedPaintOffset); |
robert@webkit.org | 87e8d0c | 2012-01-14 19:13:35 +0000 | [diff] [blame] | 955 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 956 | if ((phase == PaintPhaseOutline || phase == PaintPhaseSelfOutline) && style().visibility() == VISIBLE) |
wangxianzhu@chromium.org | 64f3829 | 2013-02-28 20:38:23 +0000 | [diff] [blame] | 957 | paintOutline(paintInfo, LayoutRect(adjustedPaintOffset, size())); |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 958 | } |
| 959 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 960 | static inline bool compareCellPositions(RenderTableCell* elem1, RenderTableCell* elem2) |
| 961 | { |
jchaffraix@webkit.org | a0177fd | 2012-05-01 03:13:06 +0000 | [diff] [blame] | 962 | return elem1->rowIndex() < elem2->rowIndex(); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 963 | } |
| 964 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 965 | // This comparison is used only when we have overflowing cells as we have an unsorted array to sort. We thus need |
| 966 | // to sort both on rows and columns to properly repaint. |
| 967 | static inline bool compareCellPositionsWithOverflowingCells(RenderTableCell* elem1, RenderTableCell* elem2) |
| 968 | { |
jchaffraix@webkit.org | a0177fd | 2012-05-01 03:13:06 +0000 | [diff] [blame] | 969 | if (elem1->rowIndex() != elem2->rowIndex()) |
| 970 | return elem1->rowIndex() < elem2->rowIndex(); |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 971 | |
| 972 | return elem1->col() < elem2->col(); |
| 973 | } |
| 974 | |
leviw@chromium.org | 890e9b0 | 2011-07-07 23:17:55 +0000 | [diff] [blame] | 975 | void RenderTableSection::paintCell(RenderTableCell* cell, PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 976 | { |
ojan@chromium.org | 035c88ca | 2011-10-03 22:00:25 +0000 | [diff] [blame] | 977 | LayoutPoint cellPoint = flipForWritingModeForChild(cell, paintOffset); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 978 | PaintPhase paintPhase = paintInfo.phase; |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 979 | RenderTableRow& row = downcast<RenderTableRow>(*cell->parent()); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 980 | |
| 981 | if (paintPhase == PaintPhaseBlockBackground || paintPhase == PaintPhaseChildBlockBackground) { |
| 982 | // We need to handle painting a stack of backgrounds. This stack (from bottom to top) consists of |
| 983 | // the column group, column, row group, row, and then the cell. |
jchaffraix@webkit.org | 1ddd9fa | 2012-05-31 16:00:20 +0000 | [diff] [blame] | 984 | RenderTableCol* column = table()->colElement(cell->col()); |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 985 | RenderTableCol* columnGroup = column ? column->enclosingColumnGroup() : nullptr; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 986 | |
| 987 | // Column groups and columns first. |
| 988 | // FIXME: Columns and column groups do not currently support opacity, and they are being painted "too late" in |
| 989 | // the stack, since we have already opened a transparency layer (potentially) for the table row group. |
| 990 | // Note that we deliberately ignore whether or not the cell has a layer, since these backgrounds paint "behind" the |
| 991 | // cell. |
jchaffraix@webkit.org | 1ddd9fa | 2012-05-31 16:00:20 +0000 | [diff] [blame] | 992 | cell->paintBackgroundsBehindCell(paintInfo, cellPoint, columnGroup); |
| 993 | cell->paintBackgroundsBehindCell(paintInfo, cellPoint, column); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 994 | |
| 995 | // Paint the row group next. |
leviw@chromium.org | 719a45b | 2011-06-03 20:59:40 +0000 | [diff] [blame] | 996 | cell->paintBackgroundsBehindCell(paintInfo, cellPoint, this); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 997 | |
| 998 | // Paint the row next, but only if it doesn't have a layer. If a row has a layer, it will be responsible for |
| 999 | // painting the row background for the cell. |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 1000 | if (!row.hasSelfPaintingLayer()) |
| 1001 | cell->paintBackgroundsBehindCell(paintInfo, cellPoint, &row); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1002 | } |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 1003 | if ((!cell->hasSelfPaintingLayer() && !row.hasSelfPaintingLayer())) |
leviw@chromium.org | 61ca137 | 2011-06-07 18:56:41 +0000 | [diff] [blame] | 1004 | cell->paint(paintInfo, cellPoint); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1007 | LayoutRect RenderTableSection::logicalRectForWritingModeAndDirection(const LayoutRect& rect) const |
| 1008 | { |
| 1009 | LayoutRect tableAlignedRect(rect); |
| 1010 | |
| 1011 | flipForWritingMode(tableAlignedRect); |
| 1012 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1013 | if (!style().isHorizontalWritingMode()) |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1014 | tableAlignedRect = tableAlignedRect.transposedRect(); |
| 1015 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1016 | const Vector<LayoutUnit>& columnPos = table()->columnPositions(); |
jchaffraix@webkit.org | 6d6c305 | 2012-11-05 07:55:28 +0000 | [diff] [blame] | 1017 | // 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] | 1018 | if (!style().isLeftToRightDirection()) |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1019 | tableAlignedRect.setX(columnPos[columnPos.size() - 1] - tableAlignedRect.maxX()); |
| 1020 | |
| 1021 | return tableAlignedRect; |
| 1022 | } |
| 1023 | |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1024 | CellSpan RenderTableSection::dirtiedRows(const LayoutRect& damageRect) const |
| 1025 | { |
| 1026 | if (m_forceSlowPaintPathWithOverflowingCell) |
| 1027 | return fullTableRowSpan(); |
| 1028 | |
mmaxfield@apple.com | f28245e | 2014-05-20 00:45:52 +0000 | [diff] [blame] | 1029 | CellSpan coveredRows = spannedRows(damageRect, IncludeAllIntersectingCells); |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1030 | |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1031 | // To repaint the border we might need to repaint first or last row even if they are not spanned themselves. |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1032 | if (coveredRows.start >= m_rowPos.size() - 1 && m_rowPos[m_rowPos.size() - 1] + table()->outerBorderAfter() >= damageRect.y()) |
| 1033 | --coveredRows.start; |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1034 | |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1035 | if (!coveredRows.end && m_rowPos[0] - table()->outerBorderBefore() <= damageRect.maxY()) |
| 1036 | ++coveredRows.end; |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1037 | |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1038 | return coveredRows; |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1041 | CellSpan RenderTableSection::dirtiedColumns(const LayoutRect& damageRect) const |
| 1042 | { |
| 1043 | if (m_forceSlowPaintPathWithOverflowingCell) |
| 1044 | return fullTableColumnSpan(); |
| 1045 | |
mmaxfield@apple.com | f28245e | 2014-05-20 00:45:52 +0000 | [diff] [blame] | 1046 | CellSpan coveredColumns = spannedColumns(damageRect, IncludeAllIntersectingCells); |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1047 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1048 | const Vector<LayoutUnit>& columnPos = table()->columnPositions(); |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1049 | // To repaint the border we might need to repaint first or last column even if they are not spanned themselves. |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1050 | if (coveredColumns.start >= columnPos.size() - 1 && columnPos[columnPos.size() - 1] + table()->outerBorderEnd() >= damageRect.x()) |
| 1051 | --coveredColumns.start; |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1052 | |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1053 | if (!coveredColumns.end && columnPos[0] - table()->outerBorderStart() <= damageRect.maxX()) |
| 1054 | ++coveredColumns.end; |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1055 | |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1056 | return coveredColumns; |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
mmaxfield@apple.com | f28245e | 2014-05-20 00:45:52 +0000 | [diff] [blame] | 1059 | CellSpan RenderTableSection::spannedRows(const LayoutRect& flippedRect, ShouldIncludeAllIntersectingCells shouldIncludeAllIntersectionCells) const |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1060 | { |
| 1061 | // Find the first row that starts after rect top. |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1062 | unsigned nextRow = std::upper_bound(m_rowPos.begin(), m_rowPos.end(), flippedRect.y()) - m_rowPos.begin(); |
mmaxfield@apple.com | f28245e | 2014-05-20 00:45:52 +0000 | [diff] [blame] | 1063 | if (shouldIncludeAllIntersectionCells == IncludeAllIntersectingCells && nextRow && m_rowPos[nextRow - 1] == flippedRect.y()) |
| 1064 | --nextRow; |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1065 | |
| 1066 | if (nextRow == m_rowPos.size()) |
| 1067 | return CellSpan(m_rowPos.size() - 1, m_rowPos.size() - 1); // After all rows. |
| 1068 | |
| 1069 | unsigned startRow = nextRow > 0 ? nextRow - 1 : 0; |
| 1070 | |
| 1071 | // Find the first row that starts after rect bottom. |
| 1072 | unsigned endRow; |
| 1073 | if (m_rowPos[nextRow] >= flippedRect.maxY()) |
| 1074 | endRow = nextRow; |
| 1075 | else { |
andersca@apple.com | 1612395 | 2014-12-06 21:04:35 +0000 | [diff] [blame] | 1076 | endRow = std::upper_bound(m_rowPos.begin() + static_cast<int32_t>(nextRow), m_rowPos.end(), flippedRect.maxY()) - m_rowPos.begin(); |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1077 | if (endRow == m_rowPos.size()) |
| 1078 | endRow = m_rowPos.size() - 1; |
| 1079 | } |
| 1080 | |
| 1081 | return CellSpan(startRow, endRow); |
| 1082 | } |
| 1083 | |
mmaxfield@apple.com | f28245e | 2014-05-20 00:45:52 +0000 | [diff] [blame] | 1084 | CellSpan RenderTableSection::spannedColumns(const LayoutRect& flippedRect, ShouldIncludeAllIntersectingCells shouldIncludeAllIntersectionCells) const |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1085 | { |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1086 | const Vector<LayoutUnit>& columnPos = table()->columnPositions(); |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1087 | |
commit-queue@webkit.org | 01f6141 | 2012-08-15 18:01:05 +0000 | [diff] [blame] | 1088 | // Find the first column that starts after rect left. |
| 1089 | // lower_bound doesn't handle the edge between two cells properly as it would wrongly return the |
| 1090 | // cell on the logical top/left. |
| 1091 | // upper_bound on the other hand properly returns the cell on the logical bottom/right, which also |
| 1092 | // matches the behavior of other browsers. |
| 1093 | unsigned nextColumn = std::upper_bound(columnPos.begin(), columnPos.end(), flippedRect.x()) - columnPos.begin(); |
mmaxfield@apple.com | f28245e | 2014-05-20 00:45:52 +0000 | [diff] [blame] | 1094 | if (shouldIncludeAllIntersectionCells == IncludeAllIntersectingCells && nextColumn && columnPos[nextColumn - 1] == flippedRect.x()) |
| 1095 | --nextColumn; |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1096 | |
| 1097 | if (nextColumn == columnPos.size()) |
| 1098 | return CellSpan(columnPos.size() - 1, columnPos.size() - 1); // After all columns. |
| 1099 | |
| 1100 | unsigned startColumn = nextColumn > 0 ? nextColumn - 1 : 0; |
| 1101 | |
commit-queue@webkit.org | 01f6141 | 2012-08-15 18:01:05 +0000 | [diff] [blame] | 1102 | // Find the first column that starts after rect right. |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1103 | unsigned endColumn; |
| 1104 | if (columnPos[nextColumn] >= flippedRect.maxX()) |
| 1105 | endColumn = nextColumn; |
| 1106 | else { |
andersca@apple.com | 1612395 | 2014-12-06 21:04:35 +0000 | [diff] [blame] | 1107 | endColumn = std::upper_bound(columnPos.begin() + static_cast<int32_t>(nextColumn), columnPos.end(), flippedRect.maxX()) - columnPos.begin(); |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1108 | if (endColumn == columnPos.size()) |
| 1109 | endColumn = columnPos.size() - 1; |
| 1110 | } |
| 1111 | |
| 1112 | return CellSpan(startColumn, endColumn); |
| 1113 | } |
| 1114 | |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1115 | void RenderTableSection::paintRowGroupBorder(const PaintInfo& paintInfo, bool antialias, LayoutRect rect, BoxSide side, CSSPropertyID borderColor, EBorderStyle borderStyle, EBorderStyle tableBorderStyle) |
| 1116 | { |
| 1117 | if (tableBorderStyle == BHIDDEN) |
| 1118 | return; |
| 1119 | rect.intersect(paintInfo.rect); |
| 1120 | if (rect.isEmpty()) |
| 1121 | return; |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1122 | drawLineForBoxSide(paintInfo.context(), rect, side, style().visitedDependentColor(borderColor), borderStyle, 0, 0, antialias); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1125 | LayoutUnit RenderTableSection::offsetLeftForRowGroupBorder(RenderTableCell* cell, const LayoutRect& rowGroupRect, unsigned row) |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1126 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1127 | if (style().isHorizontalWritingMode()) { |
| 1128 | if (style().isLeftToRightDirection()) |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1129 | return cell ? cell->x() + cell->width() : LayoutUnit::fromPixel(0); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1130 | return -outerBorderLeft(&style()); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1131 | } |
| 1132 | bool isLastRow = row + 1 == m_grid.size(); |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1133 | return rowGroupRect.width() - m_rowPos[row + 1] + (isLastRow ? -outerBorderLeft(&style()) : LayoutUnit::fromPixel(0)); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1136 | LayoutUnit RenderTableSection::offsetTopForRowGroupBorder(RenderTableCell* cell, BoxSide borderSide, unsigned row) |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1137 | { |
| 1138 | bool isLastRow = row + 1 == m_grid.size(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1139 | if (style().isHorizontalWritingMode()) |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1140 | return m_rowPos[row] + (!row && borderSide == BSRight ? -outerBorderTop(&style()) : isLastRow && borderSide == BSLeft ? outerBorderTop(&style()) : LayoutUnit::fromPixel(0)); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1141 | if (style().isLeftToRightDirection()) |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1142 | return (cell ? cell->y() + cell->height() : LayoutUnit::fromPixel(0)) + (borderSide == BSLeft ? outerBorderTop(&style()) : LayoutUnit::fromPixel(0)); |
| 1143 | return borderSide == BSRight ? -outerBorderTop(&style()) : LayoutUnit::fromPixel(0); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1146 | LayoutUnit RenderTableSection::verticalRowGroupBorderHeight(RenderTableCell* cell, const LayoutRect& rowGroupRect, unsigned row) |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1147 | { |
| 1148 | bool isLastRow = row + 1 == m_grid.size(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1149 | if (style().isHorizontalWritingMode()) |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1150 | return m_rowPos[row + 1] - m_rowPos[row] + (!row ? outerBorderTop(&style()) : isLastRow ? outerBorderBottom(&style()) : LayoutUnit::fromPixel(0)); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1151 | if (style().isLeftToRightDirection()) |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1152 | return rowGroupRect.height() - (cell ? cell->y() + cell->height() : LayoutUnit::fromPixel(0)) + outerBorderBottom(&style()); |
| 1153 | return cell ? rowGroupRect.height() - (cell->y() - cell->height()) : LayoutUnit::fromPixel(0); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1156 | LayoutUnit RenderTableSection::horizontalRowGroupBorderWidth(RenderTableCell* cell, const LayoutRect& rowGroupRect, unsigned row, unsigned column) |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1157 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1158 | if (style().isHorizontalWritingMode()) { |
| 1159 | if (style().isLeftToRightDirection()) |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1160 | return rowGroupRect.width() - (cell ? cell->x() + cell->width() : LayoutUnit::fromPixel(0)) + (!column ? outerBorderLeft(&style()) : column == table()->numEffCols() ? outerBorderRight(&style()) : LayoutUnit::fromPixel(0)); |
| 1161 | return cell ? rowGroupRect.width() - (cell->x() - cell->width()) : LayoutUnit::fromPixel(0); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1162 | } |
| 1163 | bool isLastRow = row + 1 == m_grid.size(); |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1164 | return m_rowPos[row + 1] - m_rowPos[row] + (isLastRow ? outerBorderLeft(&style()) : !row ? outerBorderRight(&style()) : LayoutUnit::fromPixel(0)); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | void RenderTableSection::paintRowGroupBorderIfRequired(const PaintInfo& paintInfo, const LayoutPoint& paintOffset, unsigned row, unsigned column, BoxSide borderSide, RenderTableCell* cell) |
| 1168 | { |
| 1169 | if (table()->currentBorderValue()->precedence() > BROWGROUP) |
| 1170 | return; |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1171 | if (paintInfo.context().paintingDisabled()) |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1172 | return; |
| 1173 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1174 | const RenderStyle& style = this->style(); |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1175 | bool antialias = shouldAntialiasLines(paintInfo.context()); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1176 | LayoutRect rowGroupRect = LayoutRect(paintOffset, size()); |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1177 | rowGroupRect.moveBy(-LayoutPoint(outerBorderLeft(&style), (borderSide == BSRight) ? LayoutUnit::fromPixel(0) : outerBorderTop(&style))); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1178 | |
| 1179 | switch (borderSide) { |
| 1180 | case BSTop: |
| 1181 | 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] | 1182 | 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] | 1183 | break; |
| 1184 | case BSBottom: |
| 1185 | 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] | 1186 | 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] | 1187 | break; |
| 1188 | case BSLeft: |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1189 | paintRowGroupBorder(paintInfo, antialias, LayoutRect(rowGroupRect.x(), rowGroupRect.y() + offsetTopForRowGroupBorder(cell, borderSide, row), style.borderLeft().width(), |
| 1190 | verticalRowGroupBorderHeight(cell, rowGroupRect, row)), BSLeft, CSSPropertyBorderLeftColor, style.borderLeftStyle(), table()->style().borderLeftStyle()); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1191 | break; |
| 1192 | case BSRight: |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1193 | paintRowGroupBorder(paintInfo, antialias, LayoutRect(rowGroupRect.x() + rowGroupRect.width(), rowGroupRect.y() + offsetTopForRowGroupBorder(cell, borderSide, row), style.borderRight().width(), |
| 1194 | verticalRowGroupBorderHeight(cell, rowGroupRect, row)), BSRight, CSSPropertyBorderRightColor, style.borderRightStyle(), table()->style().borderRightStyle()); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1195 | break; |
| 1196 | default: |
| 1197 | break; |
| 1198 | } |
| 1199 | |
| 1200 | } |
| 1201 | |
antti@apple.com | 5c4302b | 2016-04-26 18:20:09 +0000 | [diff] [blame] | 1202 | static BoxSide physicalBorderForDirection(const RenderStyle* styleForCellFlow, CollapsedBorderSide side) |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1203 | { |
| 1204 | |
| 1205 | switch (side) { |
| 1206 | case CBSStart: |
| 1207 | if (styleForCellFlow->isHorizontalWritingMode()) |
| 1208 | return styleForCellFlow->isLeftToRightDirection() ? BSLeft : BSRight; |
| 1209 | return styleForCellFlow->isLeftToRightDirection() ? BSTop : BSBottom; |
| 1210 | case CBSEnd: |
| 1211 | if (styleForCellFlow->isHorizontalWritingMode()) |
| 1212 | return styleForCellFlow->isLeftToRightDirection() ? BSRight : BSLeft; |
| 1213 | return styleForCellFlow->isLeftToRightDirection() ? BSBottom : BSTop; |
| 1214 | case CBSBefore: |
| 1215 | if (styleForCellFlow->isHorizontalWritingMode()) |
| 1216 | return BSTop; |
| 1217 | return styleForCellFlow->isLeftToRightDirection() ? BSRight : BSLeft; |
| 1218 | case CBSAfter: |
| 1219 | if (styleForCellFlow->isHorizontalWritingMode()) |
| 1220 | return BSBottom; |
| 1221 | return styleForCellFlow->isLeftToRightDirection() ? BSLeft : BSRight; |
| 1222 | default: |
| 1223 | ASSERT_NOT_REACHED(); |
| 1224 | return BSLeft; |
| 1225 | } |
| 1226 | } |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1227 | |
leviw@chromium.org | c491808 | 2011-06-29 01:06:00 +0000 | [diff] [blame] | 1228 | void RenderTableSection::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 1229 | { |
leviw@chromium.org | c491808 | 2011-06-29 01:06:00 +0000 | [diff] [blame] | 1230 | LayoutRect localRepaintRect = paintInfo.rect; |
leviw@chromium.org | 43d0c4d | 2011-06-04 02:25:54 +0000 | [diff] [blame] | 1231 | localRepaintRect.moveBy(-paintOffset); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1232 | |
commit-queue@webkit.org | 9fa1a35 | 2012-06-19 16:07:00 +0000 | [diff] [blame] | 1233 | LayoutRect tableAlignedRect = logicalRectForWritingModeAndDirection(localRepaintRect); |
| 1234 | |
| 1235 | CellSpan dirtiedRows = this->dirtiedRows(tableAlignedRect); |
| 1236 | CellSpan dirtiedColumns = this->dirtiedColumns(tableAlignedRect); |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1237 | |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1238 | if (dirtiedColumns.start < dirtiedColumns.end) { |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1239 | if (!m_hasMultipleCellLevels && !m_overflowingCells.size()) { |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1240 | if (paintInfo.phase == PaintPhaseCollapsedTableBorders) { |
| 1241 | // 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] | 1242 | // due to cell position is respected. We need to paint one row beyond the topmost dirtied |
| 1243 | // row to calculate its collapsed border value. |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1244 | unsigned startRow = dirtiedRows.start ? dirtiedRows.start - 1 : 0; |
| 1245 | for (unsigned r = dirtiedRows.end; r > startRow; r--) { |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1246 | unsigned row = r - 1; |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1247 | bool shouldPaintRowGroupBorder = false; |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1248 | for (unsigned c = dirtiedColumns.end; c > dirtiedColumns.start; c--) { |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1249 | unsigned col = c - 1; |
| 1250 | CellStruct& current = cellAt(row, col); |
| 1251 | RenderTableCell* cell = current.primaryCell(); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1252 | if (!cell) { |
| 1253 | if (!c) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1254 | paintRowGroupBorderIfRequired(paintInfo, paintOffset, row, col, physicalBorderForDirection(&style(), CBSStart)); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1255 | else if (c == table()->numEffCols()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1256 | paintRowGroupBorderIfRequired(paintInfo, paintOffset, row, col, physicalBorderForDirection(&style(), CBSEnd)); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1257 | shouldPaintRowGroupBorder = true; |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1258 | continue; |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1259 | } |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1260 | if ((row > dirtiedRows.start && primaryCellAt(row - 1, col) == cell) || (col > dirtiedColumns.start && primaryCellAt(row, col - 1) == cell)) |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1261 | continue; |
| 1262 | |
| 1263 | // If we had a run of null cells paint their corresponding section of the row group's border if necessary. Note that |
| 1264 | // this will only happen once within a row as the null cells will always be clustered together on one end of the row. |
| 1265 | if (shouldPaintRowGroupBorder) { |
| 1266 | if (r == m_grid.size()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1267 | paintRowGroupBorderIfRequired(paintInfo, paintOffset, row, col, physicalBorderForDirection(&style(), CBSAfter), cell); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1268 | else if (!row && !table()->sectionAbove(this)) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1269 | paintRowGroupBorderIfRequired(paintInfo, paintOffset, row, col, physicalBorderForDirection(&style(), CBSBefore), cell); |
robert@webkit.org | 2d9d64b | 2013-10-17 17:44:20 +0000 | [diff] [blame] | 1270 | shouldPaintRowGroupBorder = false; |
| 1271 | } |
| 1272 | |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1273 | LayoutPoint cellPoint = flipForWritingModeForChild(cell, paintOffset); |
| 1274 | cell->paintCollapsedBorders(paintInfo, cellPoint); |
| 1275 | } |
| 1276 | } |
| 1277 | } else { |
| 1278 | // Draw the dirty cells in the order that they appear. |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1279 | for (unsigned r = dirtiedRows.start; r < dirtiedRows.end; r++) { |
robert@webkit.org | 87e8d0c | 2012-01-14 19:13:35 +0000 | [diff] [blame] | 1280 | RenderTableRow* row = m_grid[r].rowRenderer; |
| 1281 | if (row && !row->hasSelfPaintingLayer()) |
| 1282 | row->paintOutlineForRowIfNeeded(paintInfo, paintOffset); |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1283 | for (unsigned c = dirtiedColumns.start; c < dirtiedColumns.end; c++) { |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1284 | CellStruct& current = cellAt(r, c); |
| 1285 | RenderTableCell* cell = current.primaryCell(); |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1286 | 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] | 1287 | continue; |
| 1288 | paintCell(cell, paintInfo, paintOffset); |
| 1289 | } |
hyatt | e031dd0 | 2006-03-18 01:01:06 +0000 | [diff] [blame] | 1290 | } |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1291 | } |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1292 | } else { |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1293 | // 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] | 1294 | #ifndef NDEBUG |
| 1295 | unsigned totalRows = m_grid.size(); |
| 1296 | unsigned totalCols = table()->columns().size(); |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1297 | ASSERT(m_overflowingCells.size() < totalRows * totalCols * gMaxAllowedOverflowingCellRatioForFastPaintPath); |
jchaffraix@webkit.org | 7e3f5d4 | 2012-02-28 01:05:10 +0000 | [diff] [blame] | 1298 | #endif |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1299 | |
| 1300 | // 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] | 1301 | Vector<RenderTableCell*> cells; |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1302 | copyToVector(m_overflowingCells, cells); |
| 1303 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1304 | HashSet<RenderTableCell*> spanningCells; |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1305 | |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1306 | for (unsigned r = dirtiedRows.start; r < dirtiedRows.end; r++) { |
robert@webkit.org | 87e8d0c | 2012-01-14 19:13:35 +0000 | [diff] [blame] | 1307 | RenderTableRow* row = m_grid[r].rowRenderer; |
| 1308 | if (row && !row->hasSelfPaintingLayer()) |
| 1309 | row->paintOutlineForRowIfNeeded(paintInfo, paintOffset); |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1310 | for (unsigned c = dirtiedColumns.start; c < dirtiedColumns.end; c++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1311 | CellStruct& current = cellAt(r, c); |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 1312 | if (!current.hasCells()) |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1313 | continue; |
| 1314 | for (unsigned i = 0; i < current.cells.size(); ++i) { |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1315 | if (m_overflowingCells.contains(current.cells[i])) |
| 1316 | continue; |
| 1317 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1318 | 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] | 1319 | if (!spanningCells.add(current.cells[i]).isNewEntry) |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1320 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1321 | } |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1322 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1323 | cells.append(current.cells[i]); |
| 1324 | } |
| 1325 | } |
| 1326 | } |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1327 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1328 | // Sort the dirty cells by paint order. |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1329 | if (!m_overflowingCells.size()) |
| 1330 | std::stable_sort(cells.begin(), cells.end(), compareCellPositions); |
| 1331 | else |
| 1332 | std::sort(cells.begin(), cells.end(), compareCellPositionsWithOverflowingCells); |
| 1333 | |
robert@webkit.org | 2d40827 | 2011-12-19 19:49:27 +0000 | [diff] [blame] | 1334 | if (paintInfo.phase == PaintPhaseCollapsedTableBorders) { |
| 1335 | for (unsigned i = cells.size(); i > 0; --i) { |
| 1336 | LayoutPoint cellPoint = flipForWritingModeForChild(cells[i - 1], paintOffset); |
| 1337 | cells[i - 1]->paintCollapsedBorders(paintInfo, cellPoint); |
| 1338 | } |
| 1339 | } else { |
| 1340 | for (unsigned i = 0; i < cells.size(); ++i) |
| 1341 | paintCell(cells[i], paintInfo, paintOffset); |
| 1342 | } |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1343 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1344 | } |
| 1345 | } |
| 1346 | |
darin@apple.com | 98a7ac6 | 2009-01-05 17:26:53 +0000 | [diff] [blame] | 1347 | void RenderTableSection::imageChanged(WrappedImagePtr, const IntRect*) |
bdash | b07ae8d | 2007-02-08 04:56:20 +0000 | [diff] [blame] | 1348 | { |
bdash | b07ae8d | 2007-02-08 04:56:20 +0000 | [diff] [blame] | 1349 | // FIXME: Examine cells and repaint only the rect the image paints in. |
| 1350 | repaint(); |
| 1351 | } |
| 1352 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1353 | void RenderTableSection::recalcCells() |
| 1354 | { |
jchaffraix@webkit.org | b86b64e | 2011-11-14 21:21:43 +0000 | [diff] [blame] | 1355 | ASSERT(m_needsCellRecalc); |
dbates@webkit.org | f04ec0f | 2014-03-18 20:00:47 +0000 | [diff] [blame] | 1356 | // We reset the flag here to ensure that addCell() works. This is safe to do because we clear the grid |
| 1357 | // and update its dimensions to be consistent with the table's column representation before we rebuild |
| 1358 | // the grid using addCell(). |
jchaffraix@webkit.org | b86b64e | 2011-11-14 21:21:43 +0000 | [diff] [blame] | 1359 | m_needsCellRecalc = false; |
| 1360 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1361 | m_cCol = 0; |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1362 | m_cRow = 0; |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 1363 | m_grid.clear(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1364 | |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1365 | for (RenderTableRow* row = firstRow(); row; row = row->nextRow()) { |
| 1366 | unsigned insertionRow = m_cRow; |
| 1367 | m_cRow++; |
| 1368 | m_cCol = 0; |
| 1369 | ensureRows(m_cRow); |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 1370 | |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1371 | m_grid[insertionRow].rowRenderer = row; |
| 1372 | row->setRowIndex(insertionRow); |
| 1373 | setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[insertionRow]); |
eseidel | 05ef043 | 2006-05-25 22:11:36 +0000 | [diff] [blame] | 1374 | |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1375 | for (RenderTableCell* cell = row->firstCell(); cell; cell = cell->nextCell()) |
| 1376 | addCell(cell, row); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1377 | } |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 1378 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame] | 1379 | m_grid.shrinkToFit(); |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 1380 | setNeedsLayout(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
jchaffraix@webkit.org | 74857b4 | 2011-12-20 14:08:52 +0000 | [diff] [blame] | 1383 | // 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] | 1384 | void RenderTableSection::rowLogicalHeightChanged(unsigned rowIndex) |
| 1385 | { |
jchaffraix@webkit.org | dd34df4 | 2012-01-24 04:15:06 +0000 | [diff] [blame] | 1386 | if (needsCellRecalc()) |
| 1387 | return; |
| 1388 | |
jchaffraix@webkit.org | 19bbb72 | 2011-11-03 17:20:01 +0000 | [diff] [blame] | 1389 | setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[rowIndex]); |
jchaffraix@webkit.org | 74857b4 | 2011-12-20 14:08:52 +0000 | [diff] [blame] | 1390 | |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1391 | for (RenderTableCell* cell = m_grid[rowIndex].rowRenderer->firstCell(); cell; cell = cell->nextCell()) |
| 1392 | updateLogicalHeightForCell(m_grid[rowIndex], cell); |
jchaffraix@webkit.org | 19bbb72 | 2011-11-03 17:20:01 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
jamesr@google.com | 5ddfb04 | 2011-01-20 21:34:34 +0000 | [diff] [blame] | 1395 | void RenderTableSection::setNeedsCellRecalc() |
| 1396 | { |
| 1397 | m_needsCellRecalc = true; |
dbates@webkit.org | f04ec0f | 2014-03-18 20:00:47 +0000 | [diff] [blame] | 1398 | |
| 1399 | // Clear the grid now to ensure that we don't hold onto any stale pointers (e.g. a cell renderer that is being removed). |
| 1400 | m_grid.clear(); |
| 1401 | |
jamesr@google.com | 5ddfb04 | 2011-01-20 21:34:34 +0000 | [diff] [blame] | 1402 | if (RenderTable* t = table()) |
| 1403 | t->setNeedsSectionRecalc(); |
| 1404 | } |
| 1405 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1406 | unsigned RenderTableSection::numColumns() const |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1407 | { |
dbates@webkit.org | f04ec0f | 2014-03-18 20:00:47 +0000 | [diff] [blame] | 1408 | ASSERT(!m_needsCellRecalc); |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1409 | unsigned result = 0; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1410 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 1411 | for (unsigned r = 0; r < m_grid.size(); ++r) { |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1412 | for (unsigned c = result; c < table()->numEffCols(); ++c) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1413 | const CellStruct& cell = cellAt(r, c); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1414 | if (cell.hasCells() || cell.inColSpan) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1415 | result = c; |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | return result + 1; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1420 | } |
| 1421 | |
zalan@apple.com | 1731e36 | 2016-07-24 01:39:13 +0000 | [diff] [blame] | 1422 | const BorderValue& RenderTableSection::borderAdjoiningStartCell(const RenderTableCell& cell) const |
jchaffraix@webkit.org | ec61404 | 2012-09-20 00:58:58 +0000 | [diff] [blame] | 1423 | { |
zalan@apple.com | 1731e36 | 2016-07-24 01:39:13 +0000 | [diff] [blame] | 1424 | ASSERT(cell.isFirstOrLastCellInRow()); |
zalan@apple.com | b2e5272 | 2016-07-26 02:15:56 +0000 | [diff] [blame] | 1425 | return isDirectionSame(this, &cell) ? style().borderStart() : style().borderEnd(); |
jchaffraix@webkit.org | ec61404 | 2012-09-20 00:58:58 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
zalan@apple.com | 1731e36 | 2016-07-24 01:39:13 +0000 | [diff] [blame] | 1428 | const BorderValue& RenderTableSection::borderAdjoiningEndCell(const RenderTableCell& cell) const |
jchaffraix@webkit.org | ec61404 | 2012-09-20 00:58:58 +0000 | [diff] [blame] | 1429 | { |
zalan@apple.com | 1731e36 | 2016-07-24 01:39:13 +0000 | [diff] [blame] | 1430 | ASSERT(cell.isFirstOrLastCellInRow()); |
zalan@apple.com | b2e5272 | 2016-07-26 02:15:56 +0000 | [diff] [blame] | 1431 | return isDirectionSame(this, &cell) ? style().borderEnd() : style().borderStart(); |
jchaffraix@webkit.org | ec61404 | 2012-09-20 00:58:58 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
jchaffraix@webkit.org | ceaacec | 2012-06-01 20:15:01 +0000 | [diff] [blame] | 1434 | const RenderTableCell* RenderTableSection::firstRowCellAdjoiningTableStart() const |
| 1435 | { |
zalan@apple.com | b2e5272 | 2016-07-26 02:15:56 +0000 | [diff] [blame] | 1436 | unsigned adjoiningStartCellColumnIndex = isDirectionSame(this, table()) ? 0 : table()->lastColumnIndex(); |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1437 | return cellAt(0, adjoiningStartCellColumnIndex).primaryCell(); |
jchaffraix@webkit.org | ceaacec | 2012-06-01 20:15:01 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | const RenderTableCell* RenderTableSection::firstRowCellAdjoiningTableEnd() const |
| 1441 | { |
zalan@apple.com | b2e5272 | 2016-07-26 02:15:56 +0000 | [diff] [blame] | 1442 | unsigned adjoiningEndCellColumnIndex = isDirectionSame(this, table()) ? table()->lastColumnIndex() : 0; |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1443 | return cellAt(0, adjoiningEndCellColumnIndex).primaryCell(); |
jchaffraix@webkit.org | ceaacec | 2012-06-01 20:15:01 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 1446 | void RenderTableSection::appendColumn(unsigned pos) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1447 | { |
jchaffraix@webkit.org | b86b64e | 2011-11-14 21:21:43 +0000 | [diff] [blame] | 1448 | ASSERT(!m_needsCellRecalc); |
| 1449 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 1450 | for (unsigned row = 0; row < m_grid.size(); ++row) |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 1451 | m_grid[row].row.resize(pos + 1); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1452 | } |
| 1453 | |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 1454 | void RenderTableSection::splitColumn(unsigned pos, unsigned first) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1455 | { |
inferno@chromium.org | b1ffad7 | 2011-10-10 18:58:12 +0000 | [diff] [blame] | 1456 | ASSERT(!m_needsCellRecalc); |
| 1457 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1458 | if (m_cCol > pos) |
| 1459 | m_cCol++; |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 1460 | for (unsigned row = 0; row < m_grid.size(); ++row) { |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 1461 | Row& r = m_grid[row].row; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1462 | r.insert(pos + 1, CellStruct()); |
| 1463 | if (r[pos].hasCells()) { |
andersca@apple.com | 9201299 | 2013-05-05 19:03:49 +0000 | [diff] [blame] | 1464 | r[pos + 1].cells.appendVector(r[pos].cells); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1465 | RenderTableCell* cell = r[pos].primaryCell(); |
| 1466 | ASSERT(cell); |
commit-queue@webkit.org | 1ee5b34 | 2012-05-08 05:14:07 +0000 | [diff] [blame] | 1467 | ASSERT(cell->colSpan() >= (r[pos].inColSpan ? 1u : 0)); |
jchaffraix@webkit.org | fb2a860 | 2011-11-16 02:03:54 +0000 | [diff] [blame] | 1468 | unsigned colleft = cell->colSpan() - r[pos].inColSpan; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1469 | if (first > colleft) |
| 1470 | r[pos + 1].inColSpan = 0; |
| 1471 | else |
| 1472 | r[pos + 1].inColSpan = first + r[pos].inColSpan; |
| 1473 | } else { |
| 1474 | r[pos + 1].inColSpan = 0; |
| 1475 | } |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1476 | } |
| 1477 | } |
| 1478 | |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1479 | // Hit Testing |
allan.jensen@nokia.com | 9a9045b | 2012-08-28 09:41:54 +0000 | [diff] [blame] | 1480 | 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] | 1481 | { |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1482 | // If we have no children then we have nothing to do. |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1483 | if (!firstRow()) |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1484 | return false; |
| 1485 | |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1486 | // Table sections cannot ever be hit tested. Effectively they do not exist. |
| 1487 | // Just forward to our children always. |
eae@chromium.org | e14cd1a | 2011-07-06 23:38:32 +0000 | [diff] [blame] | 1488 | LayoutPoint adjustedLocation = accumulatedOffset + location(); |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1489 | |
abucur@adobe.com | 7f9668a | 2014-05-16 13:22:00 +0000 | [diff] [blame] | 1490 | if (hasOverflowClip() && !locationInContainer.intersects(overflowClipRect(adjustedLocation, currentRenderNamedFlowFragment()))) |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 1491 | return false; |
| 1492 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1493 | if (hasOverflowingCell()) { |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1494 | for (RenderTableRow* row = lastRow(); row; row = row->previousRow()) { |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1495 | // FIXME: We have to skip over inline flows, since they can show up inside table rows |
| 1496 | // at the moment (a demoted inline <form> for example). If we ever implement a |
| 1497 | // table-specific hit-test method (which we should do for performance reasons anyway), |
| 1498 | // then we can remove this check. |
antti@apple.com | d04c081 | 2013-09-25 17:45:59 +0000 | [diff] [blame] | 1499 | if (!row->hasSelfPaintingLayer()) { |
antti@apple.com | 7f9196b | 2013-09-24 20:47:01 +0000 | [diff] [blame] | 1500 | LayoutPoint childPoint = flipForWritingModeForChild(row, adjustedLocation); |
| 1501 | if (row->nodeAtPoint(request, result, locationInContainer, childPoint, action)) { |
allan.jensen@nokia.com | 9a9045b | 2012-08-28 09:41:54 +0000 | [diff] [blame] | 1502 | updateHitTestResult(result, toLayoutPoint(locationInContainer.point() - childPoint)); |
mitz@apple.com | 39fb3ae | 2010-11-09 20:46:15 +0000 | [diff] [blame] | 1503 | return true; |
| 1504 | } |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1505 | } |
| 1506 | } |
| 1507 | return false; |
| 1508 | } |
| 1509 | |
inferno@chromium.org | 9c8b230 | 2012-02-21 19:10:05 +0000 | [diff] [blame] | 1510 | recalcCellsIfNeeded(); |
| 1511 | |
allan.jensen@nokia.com | 9a9045b | 2012-08-28 09:41:54 +0000 | [diff] [blame] | 1512 | LayoutRect hitTestRect = locationInContainer.boundingBox(); |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1513 | hitTestRect.moveBy(-adjustedLocation); |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1514 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1515 | LayoutRect tableAlignedRect = logicalRectForWritingModeAndDirection(hitTestRect); |
mmaxfield@apple.com | f28245e | 2014-05-20 00:45:52 +0000 | [diff] [blame] | 1516 | CellSpan rowSpan = spannedRows(tableAlignedRect, DoNotIncludeAllIntersectingCells); |
| 1517 | CellSpan columnSpan = spannedColumns(tableAlignedRect, DoNotIncludeAllIntersectingCells); |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1518 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1519 | // Now iterate over the spanned rows and columns. |
zalan@apple.com | ec6c110a | 2015-02-17 22:41:25 +0000 | [diff] [blame] | 1520 | for (unsigned hitRow = rowSpan.start; hitRow < rowSpan.end; ++hitRow) { |
| 1521 | for (unsigned hitColumn = columnSpan.start; hitColumn < columnSpan.end; ++hitColumn) { |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1522 | CellStruct& current = cellAt(hitRow, hitColumn); |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1523 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1524 | // If the cell is empty, there's nothing to do |
| 1525 | if (!current.hasCells()) |
| 1526 | continue; |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1527 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1528 | for (unsigned i = current.cells.size() ; i; ) { |
| 1529 | --i; |
| 1530 | RenderTableCell* cell = current.cells[i]; |
| 1531 | LayoutPoint cellPoint = flipForWritingModeForChild(cell, adjustedLocation); |
allan.jensen@nokia.com | 9a9045b | 2012-08-28 09:41:54 +0000 | [diff] [blame] | 1532 | if (static_cast<RenderObject*>(cell)->nodeAtPoint(request, result, locationInContainer, cellPoint, action)) { |
| 1533 | updateHitTestResult(result, locationInContainer.point() - toLayoutSize(cellPoint)); |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1534 | return true; |
| 1535 | } |
| 1536 | } |
| 1537 | if (!result.isRectBasedTest()) |
| 1538 | break; |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1539 | } |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1540 | if (!result.isRectBasedTest()) |
| 1541 | break; |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1542 | } |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1543 | |
commit-queue@webkit.org | be3795c | 2012-06-11 09:38:48 +0000 | [diff] [blame] | 1544 | return false; |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
zalan@apple.com | 4214662 | 2015-04-01 15:56:34 +0000 | [diff] [blame] | 1547 | void RenderTableSection::clearCachedCollapsedBorders() |
| 1548 | { |
| 1549 | if (!table()->collapseBorders()) |
| 1550 | return; |
| 1551 | m_cellsCollapsedBorders.clear(); |
| 1552 | } |
| 1553 | |
| 1554 | void RenderTableSection::removeCachedCollapsedBorders(const RenderTableCell& cell) |
robert@webkit.org | 76a7610 | 2012-01-15 13:48:45 +0000 | [diff] [blame] | 1555 | { |
| 1556 | if (!table()->collapseBorders()) |
| 1557 | return; |
| 1558 | |
| 1559 | for (int side = CBSBefore; side <= CBSEnd; ++side) |
zalan@apple.com | 4214662 | 2015-04-01 15:56:34 +0000 | [diff] [blame] | 1560 | m_cellsCollapsedBorders.remove(std::make_pair(&cell, side)); |
robert@webkit.org | 76a7610 | 2012-01-15 13:48:45 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
zalan@apple.com | 4214662 | 2015-04-01 15:56:34 +0000 | [diff] [blame] | 1563 | void RenderTableSection::setCachedCollapsedBorder(const RenderTableCell& cell, CollapsedBorderSide side, CollapsedBorderValue border) |
robert@webkit.org | 76a7610 | 2012-01-15 13:48:45 +0000 | [diff] [blame] | 1564 | { |
| 1565 | ASSERT(table()->collapseBorders()); |
zalan@apple.com | 4214662 | 2015-04-01 15:56:34 +0000 | [diff] [blame] | 1566 | ASSERT(border.width()); |
| 1567 | m_cellsCollapsedBorders.set(std::make_pair(&cell, side), border); |
robert@webkit.org | 76a7610 | 2012-01-15 13:48:45 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
zalan@apple.com | 4214662 | 2015-04-01 15:56:34 +0000 | [diff] [blame] | 1570 | CollapsedBorderValue RenderTableSection::cachedCollapsedBorder(const RenderTableCell& cell, CollapsedBorderSide side) |
robert@webkit.org | 76a7610 | 2012-01-15 13:48:45 +0000 | [diff] [blame] | 1571 | { |
zalan@apple.com | 4214662 | 2015-04-01 15:56:34 +0000 | [diff] [blame] | 1572 | ASSERT(table()->collapseBorders() && table()->collapsedBordersAreValid()); |
| 1573 | auto it = m_cellsCollapsedBorders.find(std::make_pair(&cell, side)); |
| 1574 | // Only non-empty collapsed borders are in the hashmap. |
| 1575 | if (it == m_cellsCollapsedBorders.end()) |
| 1576 | return CollapsedBorderValue(BorderValue(), Color(), BCELL); |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 1577 | return it->value; |
robert@webkit.org | 76a7610 | 2012-01-15 13:48:45 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
zalan@apple.com | cda46e4 | 2016-07-26 02:40:04 +0000 | [diff] [blame^] | 1580 | std::unique_ptr<RenderTableSection> RenderTableSection::createTableSectionWithStyle(Document& document, const RenderStyle& style) |
inferno@chromium.org | 2164c61 | 2012-04-04 22:41:56 +0000 | [diff] [blame] | 1581 | { |
zalan@apple.com | cda46e4 | 2016-07-26 02:40:04 +0000 | [diff] [blame^] | 1582 | auto section = std::make_unique<RenderTableSection>(document, RenderStyle::createAnonymousStyleWithDisplay(style, TABLE_ROW_GROUP)); |
akling@apple.com | 8f40c5b | 2013-10-27 22:54:07 +0000 | [diff] [blame] | 1583 | section->initializeStyle(); |
| 1584 | return section; |
inferno@chromium.org | 2164c61 | 2012-04-04 22:41:56 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
zalan@apple.com | cda46e4 | 2016-07-26 02:40:04 +0000 | [diff] [blame^] | 1587 | std::unique_ptr<RenderTableSection> RenderTableSection::createAnonymousWithParentRenderer(const RenderTable& parent) |
| 1588 | { |
| 1589 | return RenderTableSection::createTableSectionWithStyle(parent.document(), parent.style()); |
| 1590 | } |
| 1591 | |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1592 | void RenderTableSection::setLogicalPositionForCell(RenderTableCell* cell, unsigned effectiveColumn) const |
| 1593 | { |
eae@chromium.org | 1146f21 | 2012-07-18 22:06:34 +0000 | [diff] [blame] | 1594 | LayoutPoint oldCellLocation = cell->location(); |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1595 | |
| 1596 | LayoutPoint cellLocation(0, m_rowPos[cell->rowIndex()]); |
zalan@apple.com | 5471a8d | 2015-10-27 16:38:10 +0000 | [diff] [blame] | 1597 | LayoutUnit horizontalBorderSpacing = table()->hBorderSpacing(); |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1598 | |
jchaffraix@webkit.org | 6d6c305 | 2012-11-05 07:55:28 +0000 | [diff] [blame] | 1599 | // 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] | 1600 | if (!style().isLeftToRightDirection()) |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1601 | cellLocation.setX(table()->columnPositions()[table()->numEffCols()] - table()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + horizontalBorderSpacing); |
| 1602 | else |
| 1603 | cellLocation.setX(table()->columnPositions()[effectiveColumn] + horizontalBorderSpacing); |
| 1604 | |
| 1605 | cell->setLogicalLocation(cellLocation); |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1606 | view().addLayoutDelta(oldCellLocation - cell->location()); |
jchaffraix@webkit.org | 4b5292a | 2012-06-06 16:07:16 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1609 | } // namespace WebCore |