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" |
bdash | b07ae8d | 2007-02-08 04:56:20 +0000 | [diff] [blame] | 28 | #include "CachedImage.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 29 | #include "Document.h" |
tonikitoo@webkit.org | 81c027d | 2010-07-29 13:19:43 +0000 | [diff] [blame] | 30 | #include "HitTestResult.h" |
darin | 98fa8b8 | 2006-03-20 08:03:57 +0000 | [diff] [blame] | 31 | #include "HTMLNames.h" |
tonyg@chromium.org | b138b1e | 2011-01-15 00:27:07 +0000 | [diff] [blame] | 32 | #include "PaintInfo.h" |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 33 | #include "RenderTableCell.h" |
| 34 | #include "RenderTableCol.h" |
| 35 | #include "RenderTableRow.h" |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 36 | #include "RenderView.h" |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 37 | #include <limits> |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 38 | #include <wtf/HashSet.h> |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 39 | #include <wtf/Vector.h> |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 40 | |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 41 | using namespace std; |
| 42 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 43 | namespace WebCore { |
| 44 | |
| 45 | using namespace HTMLNames; |
| 46 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 47 | // Those 2 variables are used to balance the memory consumption vs the repaint time on big tables. |
| 48 | static unsigned gMinTableSizeToUseFastPaintPathWithOverflowingCell = 75 * 75; |
| 49 | static float gMaxAllowedOverflowingCellRatioForFastPaintPath = 0.1f; |
| 50 | |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 51 | static inline void setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(RenderTableSection::RowStruct& row) |
dbates@webkit.org | e113183 | 2009-11-19 00:05:57 +0000 | [diff] [blame] | 52 | { |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 53 | ASSERT(row.rowRenderer); |
| 54 | row.logicalHeight = row.rowRenderer->style()->logicalHeight(); |
| 55 | if (row.logicalHeight.isRelative()) |
| 56 | row.logicalHeight = Length(); |
dbates@webkit.org | e113183 | 2009-11-19 00:05:57 +0000 | [diff] [blame] | 57 | } |
| 58 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 59 | RenderTableSection::RenderTableSection(Node* node) |
hyatt@apple.com | f073d9b | 2009-02-05 00:53:38 +0000 | [diff] [blame] | 60 | : RenderBox(node) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 61 | , m_cCol(0) |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 62 | , m_cRow(0) |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 63 | , m_outerBorderStart(0) |
| 64 | , m_outerBorderEnd(0) |
| 65 | , m_outerBorderBefore(0) |
| 66 | , m_outerBorderAfter(0) |
simon.fraser@apple.com | 8536250 | 2009-05-08 01:23:32 +0000 | [diff] [blame] | 67 | , m_needsCellRecalc(false) |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 68 | , m_hasMultipleCellLevels(false) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 69 | { |
| 70 | // init RenderObject attributes |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 71 | setInline(false); // our object is not Inline |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | RenderTableSection::~RenderTableSection() |
| 75 | { |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 76 | } |
| 77 | |
inferno@chromium.org | a7f719f | 2011-09-06 01:45:39 +0000 | [diff] [blame] | 78 | void RenderTableSection::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
| 79 | { |
| 80 | RenderBox::styleDidChange(diff, oldStyle); |
| 81 | propagateStyleToAnonymousChildren(); |
jchaffraix@webkit.org | 38e74af | 2011-09-23 19:56:21 +0000 | [diff] [blame] | 82 | |
| 83 | // If border was changed, notify table. |
| 84 | RenderTable* table = this->table(); |
| 85 | if (table && !table->selfNeedsLayout() && !table->normalChildNeedsLayout() && oldStyle && oldStyle->border() != style()->border()) |
| 86 | table->invalidateCollapsedBorders(); |
inferno@chromium.org | a7f719f | 2011-09-06 01:45:39 +0000 | [diff] [blame] | 87 | } |
| 88 | |
simon.fraser@apple.com | 73cb0b3 | 2011-07-09 00:43:14 +0000 | [diff] [blame] | 89 | void RenderTableSection::willBeDestroyed() |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 90 | { |
antti | 078e87f | 2007-08-16 16:13:28 +0000 | [diff] [blame] | 91 | RenderTable* recalcTable = table(); |
| 92 | |
simon.fraser@apple.com | 73cb0b3 | 2011-07-09 00:43:14 +0000 | [diff] [blame] | 93 | RenderBox::willBeDestroyed(); |
antti | 078e87f | 2007-08-16 16:13:28 +0000 | [diff] [blame] | 94 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 95 | // recalc cell info because RenderTable has unguarded pointers |
| 96 | // stored that point to this RenderTableSection. |
antti | 078e87f | 2007-08-16 16:13:28 +0000 | [diff] [blame] | 97 | if (recalcTable) |
| 98 | recalcTable->setNeedsSectionRecalc(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 99 | } |
| 100 | |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 101 | void RenderTableSection::addChild(RenderObject* child, RenderObject* beforeChild) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 102 | { |
hyatt | 58028f5 | 2007-05-01 04:57:01 +0000 | [diff] [blame] | 103 | // Make sure we don't append things after :after-generated content if we have it. |
inferno@chromium.org | cff5887 | 2011-09-21 22:05:07 +0000 | [diff] [blame] | 104 | if (!beforeChild) |
| 105 | beforeChild = findAfterContentRenderer(); |
hyatt | 58028f5 | 2007-05-01 04:57:01 +0000 | [diff] [blame] | 106 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 107 | if (!child->isTableRow()) { |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 108 | RenderObject* last = beforeChild; |
| 109 | if (!last) |
| 110 | last = lastChild(); |
inferno@chromium.org | a7f719f | 2011-09-06 01:45:39 +0000 | [diff] [blame] | 111 | if (last && last->isAnonymous() && !last->isBeforeOrAfterContent()) { |
inferno@chromium.org | 947af30 | 2011-01-04 02:27:50 +0000 | [diff] [blame] | 112 | if (beforeChild == last) |
| 113 | beforeChild = last->firstChild(); |
| 114 | last->addChild(child, beforeChild); |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 115 | return; |
| 116 | } |
| 117 | |
inferno@chromium.org | b1ffad7 | 2011-10-10 18:58:12 +0000 | [diff] [blame] | 118 | if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == this) { |
| 119 | RenderObject* row = beforeChild->previousSibling(); |
fsamuel@chromium.org | fc34e99 | 2011-10-25 19:10:58 +0000 | [diff] [blame] | 120 | if (row && row->isTableRow() && row->isAnonymous()) { |
inferno@chromium.org | b1ffad7 | 2011-10-10 18:58:12 +0000 | [diff] [blame] | 121 | row->addChild(child); |
| 122 | return; |
| 123 | } |
| 124 | } |
| 125 | |
darin | 10ab135 | 2006-01-29 01:29:33 +0000 | [diff] [blame] | 126 | // If beforeChild is inside an anonymous cell/row, insert into the cell or into |
| 127 | // the anonymous row containing it, if there is one. |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 128 | RenderObject* lastBox = last; |
| 129 | while (lastBox && lastBox->parent()->isAnonymous() && !lastBox->isTableRow()) |
| 130 | lastBox = lastBox->parent(); |
inferno@chromium.org | a7f719f | 2011-09-06 01:45:39 +0000 | [diff] [blame] | 131 | if (lastBox && lastBox->isAnonymous() && !lastBox->isBeforeOrAfterContent()) { |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 132 | lastBox->addChild(child, beforeChild); |
| 133 | return; |
| 134 | } |
| 135 | |
eric@webkit.org | 32963e3 | 2009-06-05 03:25:12 +0000 | [diff] [blame] | 136 | RenderObject* row = new (renderArena()) RenderTableRow(document() /* anonymous table row */); |
hyatt@apple.com | dec0cbf2 | 2008-10-17 00:25:33 +0000 | [diff] [blame] | 137 | RefPtr<RenderStyle> newStyle = RenderStyle::create(); |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 138 | newStyle->inheritFrom(style()); |
| 139 | newStyle->setDisplay(TABLE_ROW); |
hyatt@apple.com | dec0cbf2 | 2008-10-17 00:25:33 +0000 | [diff] [blame] | 140 | row->setStyle(newStyle.release()); |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 141 | addChild(row, beforeChild); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 142 | row->addChild(child); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 143 | return; |
| 144 | } |
| 145 | |
| 146 | if (beforeChild) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 147 | setNeedsCellRecalc(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 148 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 149 | unsigned insertionRow = m_cRow; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 150 | ++m_cRow; |
| 151 | m_cCol = 0; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 152 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame^] | 153 | ensureRows(m_cRow); |
lars | b5288ad | 2007-01-13 18:48:29 +0000 | [diff] [blame] | 154 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 155 | m_grid[insertionRow].rowRenderer = toRenderTableRow(child); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 156 | |
dbates@webkit.org | e113183 | 2009-11-19 00:05:57 +0000 | [diff] [blame] | 157 | if (!beforeChild) |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 158 | setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[insertionRow]); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 159 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 160 | // If the next renderer is actually wrapped in an anonymous table row, we need to go up and find that. |
mitz@apple.com | fdbd51e | 2008-01-18 21:52:57 +0000 | [diff] [blame] | 161 | while (beforeChild && beforeChild->parent() != this) |
mjs | 6666eee7 | 2006-07-14 07:45:13 +0000 | [diff] [blame] | 162 | beforeChild = beforeChild->parent(); |
| 163 | |
bdakin@apple.com | 40ae9be | 2009-04-16 20:48:19 +0000 | [diff] [blame] | 164 | ASSERT(!beforeChild || beforeChild->isTableRow()); |
hyatt@apple.com | f073d9b | 2009-02-05 00:53:38 +0000 | [diff] [blame] | 165 | RenderBox::addChild(child, beforeChild); |
mjs@apple.com | 2fcfc48 | 2011-04-08 06:01:59 +0000 | [diff] [blame] | 166 | toRenderTableRow(child)->updateBeforeAndAfterContent(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 167 | } |
| 168 | |
weinig@apple.com | 8497411 | 2009-02-03 06:45:48 +0000 | [diff] [blame] | 169 | void RenderTableSection::removeChild(RenderObject* oldChild) |
| 170 | { |
| 171 | setNeedsCellRecalc(); |
hyatt@apple.com | f073d9b | 2009-02-05 00:53:38 +0000 | [diff] [blame] | 172 | RenderBox::removeChild(oldChild); |
weinig@apple.com | 8497411 | 2009-02-03 06:45:48 +0000 | [diff] [blame] | 173 | } |
| 174 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame^] | 175 | void RenderTableSection::ensureRows(unsigned numRows) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 176 | { |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame^] | 177 | if (numRows <= m_grid.size()) |
| 178 | return; |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 179 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame^] | 180 | unsigned oldSize = m_grid.size(); |
| 181 | m_grid.grow(numRows); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 182 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame^] | 183 | unsigned effectiveColumnCount = max(1u, table()->numEffCols()); |
| 184 | for (unsigned row = oldSize; row < m_grid.size(); ++row) |
| 185 | m_grid[row].row.grow(effectiveColumnCount); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 186 | } |
| 187 | |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 188 | void RenderTableSection::addCell(RenderTableCell* cell, RenderTableRow* row) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 189 | { |
jchaffraix@webkit.org | d01277d | 2011-11-09 19:57:16 +0000 | [diff] [blame] | 190 | // We don't insert the cell if we need cell recalc as our internal columns' representation |
| 191 | // will have drifted from the table's representation. Also recalcCells will call addCell |
| 192 | // at a later time after sync'ing our columns' with the table's. |
| 193 | if (needsCellRecalc()) |
| 194 | return; |
| 195 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 196 | int rSpan = cell->rowSpan(); |
| 197 | int cSpan = cell->colSpan(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 198 | Vector<RenderTable::ColumnStruct>& columns = table()->columns(); |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 199 | unsigned nCols = columns.size(); |
| 200 | // addCell should be called only after m_cRow has been incremented. |
| 201 | ASSERT(m_cRow); |
| 202 | unsigned insertionRow = m_cRow - 1; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 203 | |
| 204 | // ### mozilla still seems to do the old HTML way, even for strict DTD |
| 205 | // (see the annotation on table cell layouting in the CSS specs and the testcase below: |
| 206 | // <TABLE border> |
| 207 | // <TR><TD>1 <TD rowspan="2">2 <TD>3 <TD>4 |
| 208 | // <TR><TD colspan="2">5 |
| 209 | // </TABLE> |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 210 | 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] | 211 | m_cCol++; |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 212 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 213 | if (rSpan == 1) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 214 | // we ignore height settings on rowspan cells |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 215 | Length logicalHeight = cell->style()->logicalHeight(); |
| 216 | if (logicalHeight.isPositive() || (logicalHeight.isRelative() && logicalHeight.value() >= 0)) { |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 217 | Length cRowLogicalHeight = m_grid[insertionRow].logicalHeight; |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 218 | switch (logicalHeight.type()) { |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 219 | case Percent: |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 220 | if (!(cRowLogicalHeight.isPercent()) || |
commit-queue@webkit.org | 0740d9e | 2011-03-22 00:24:01 +0000 | [diff] [blame] | 221 | (cRowLogicalHeight.isPercent() && cRowLogicalHeight.percent() < logicalHeight.percent())) |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 222 | m_grid[insertionRow].logicalHeight = logicalHeight; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 223 | break; |
| 224 | case Fixed: |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 225 | if (cRowLogicalHeight.type() < Percent || |
| 226 | (cRowLogicalHeight.isFixed() && cRowLogicalHeight.value() < logicalHeight.value())) |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 227 | m_grid[insertionRow].logicalHeight = logicalHeight; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 228 | break; |
| 229 | case Relative: |
| 230 | default: |
| 231 | break; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 232 | } |
| 233 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 234 | } |
| 235 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame^] | 236 | ensureRows(insertionRow + rSpan); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 237 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 238 | m_grid[insertionRow].rowRenderer = row; |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 239 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 240 | unsigned col = m_cCol; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 241 | // tell the cell where it is |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 242 | bool inColSpan = false; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 243 | while (cSpan) { |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 244 | int currentSpan; |
| 245 | if (m_cCol >= nCols) { |
| 246 | table()->appendColumn(cSpan); |
| 247 | currentSpan = cSpan; |
| 248 | } else { |
| 249 | if (cSpan < (int)columns[m_cCol].span) |
| 250 | table()->splitColumn(m_cCol, cSpan); |
| 251 | currentSpan = columns[m_cCol].span; |
| 252 | } |
| 253 | for (int r = 0; r < rSpan; r++) { |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 254 | CellStruct& c = cellAt(insertionRow + r, m_cCol); |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 255 | ASSERT(cell); |
| 256 | c.cells.append(cell); |
| 257 | // If cells overlap then we take the slow path for painting. |
| 258 | if (c.cells.size() > 1) |
| 259 | m_hasMultipleCellLevels = true; |
| 260 | if (inColSpan) |
| 261 | c.inColSpan = true; |
| 262 | } |
| 263 | m_cCol++; |
| 264 | cSpan -= currentSpan; |
| 265 | inColSpan = true; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 266 | } |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 267 | cell->setRow(insertionRow); |
eric@webkit.org | 5832ab7 | 2009-03-25 22:15:03 +0000 | [diff] [blame] | 268 | cell->setCol(table()->effColToCol(col)); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 269 | } |
| 270 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 271 | void RenderTableSection::setCellLogicalWidths() |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 272 | { |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 273 | Vector<LayoutUnit>& columnPos = table()->columnPositions(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 274 | |
simon.fraser@apple.com | feaef2e | 2008-11-07 19:17:08 +0000 | [diff] [blame] | 275 | LayoutStateMaintainer statePusher(view()); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 276 | |
| 277 | for (unsigned i = 0; i < m_grid.size(); i++) { |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 278 | Row& row = m_grid[i].row; |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 279 | unsigned cols = row.size(); |
| 280 | for (unsigned j = 0; j < cols; j++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 281 | CellStruct& current = row[j]; |
| 282 | RenderTableCell* cell = current.primaryCell(); |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 283 | if (!cell || current.inColSpan) |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 284 | continue; |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 285 | unsigned endCol = j; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 286 | int cspan = cell->colSpan(); |
| 287 | while (cspan && endCol < cols) { |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 288 | ASSERT(endCol < table()->columns().size()); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 289 | cspan -= table()->columns()[endCol].span; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 290 | endCol++; |
| 291 | } |
leviw@chromium.org | f6fccf5 | 2011-11-04 00:56:59 +0000 | [diff] [blame] | 292 | LayoutUnit w = columnPos[endCol] - columnPos[j] - table()->hBorderSpacing(); |
| 293 | LayoutUnit oldLogicalWidth = cell->logicalWidth(); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 294 | if (w != oldLogicalWidth) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 295 | cell->setNeedsLayout(true); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 296 | if (!table()->selfNeedsLayout() && cell->checkForRepaintDuringLayout()) { |
simon.fraser@apple.com | feaef2e | 2008-11-07 19:17:08 +0000 | [diff] [blame] | 297 | if (!statePusher.didPush()) { |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 298 | // Technically, we should also push state for the row, but since |
| 299 | // rows don't push a coordinate transform, that's not necessary. |
leviw@chromium.org | f6fccf5 | 2011-11-04 00:56:59 +0000 | [diff] [blame] | 300 | statePusher.push(this, LayoutSize(x(), y())); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 301 | } |
hyatt | d72625b | 2007-04-26 19:51:11 +0000 | [diff] [blame] | 302 | cell->repaint(); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 303 | } |
mitz@apple.com | 2722b37 | 2010-11-03 18:03:55 +0000 | [diff] [blame] | 304 | cell->updateLogicalWidth(w); |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 307 | } |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 308 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 309 | statePusher.pop(); // only pops if we pushed |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 310 | } |
| 311 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 312 | LayoutUnit RenderTableSection::calcRowLogicalHeight() |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 313 | { |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 314 | #ifndef NDEBUG |
| 315 | setNeedsLayoutIsForbidden(true); |
| 316 | #endif |
| 317 | |
| 318 | ASSERT(!needsLayout()); |
| 319 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 320 | RenderTableCell* cell; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 321 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 322 | LayoutUnit spacing = table()->vBorderSpacing(); |
simon.fraser@apple.com | feaef2e | 2008-11-07 19:17:08 +0000 | [diff] [blame] | 323 | |
| 324 | LayoutStateMaintainer statePusher(view()); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 325 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 326 | m_rowPos.resize(m_grid.size() + 1); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 327 | m_rowPos[0] = spacing; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 328 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 329 | for (unsigned r = 0; r < m_grid.size(); r++) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 330 | m_rowPos[r + 1] = 0; |
hyatt | 777b31c | 2007-07-19 20:01:26 +0000 | [diff] [blame] | 331 | m_grid[r].baseline = 0; |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 332 | LayoutUnit baseline = 0; |
| 333 | LayoutUnit bdesc = 0; |
| 334 | LayoutUnit ch = m_grid[r].logicalHeight.calcMinValue(0); |
| 335 | LayoutUnit pos = m_rowPos[r] + ch + (m_grid[r].rowRenderer ? spacing : 0); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 336 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 337 | m_rowPos[r + 1] = max(m_rowPos[r + 1], pos); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 338 | |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 339 | Row& row = m_grid[r].row; |
| 340 | unsigned totalCols = row.size(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 341 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 342 | for (unsigned c = 0; c < totalCols; c++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 343 | CellStruct& current = cellAt(r, c); |
| 344 | cell = current.primaryCell(); |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 345 | |
| 346 | if (!cell || current.inColSpan) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 347 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 348 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 349 | if ((cell->row() + cell->rowSpan() - 1) > r) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 350 | continue; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 351 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 352 | unsigned indx = max(r - cell->rowSpan() + 1, 0u); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 353 | |
ojan@chromium.org | f734c92 | 2011-09-07 20:18:14 +0000 | [diff] [blame] | 354 | if (cell->hasOverrideHeight()) { |
simon.fraser@apple.com | feaef2e | 2008-11-07 19:17:08 +0000 | [diff] [blame] | 355 | if (!statePusher.didPush()) { |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 356 | // Technically, we should also push state for the row, but since |
| 357 | // rows don't push a coordinate transform, that's not necessary. |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 358 | statePusher.push(this, locationOffset()); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 359 | } |
tony@chromium.org | aefe0ea | 2011-07-08 22:15:14 +0000 | [diff] [blame] | 360 | cell->clearIntrinsicPadding(); |
| 361 | cell->clearOverrideSize(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 362 | cell->setChildNeedsLayout(true, false); |
| 363 | cell->layoutIfNeeded(); |
| 364 | } |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 365 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 366 | LayoutUnit adjustedLogicalHeight = cell->logicalHeight() - (cell->intrinsicPaddingBefore() + cell->intrinsicPaddingAfter()); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 367 | |
dominicc@chromium.org | 2b740ac | 2011-11-01 20:55:57 +0000 | [diff] [blame] | 368 | ch = cell->style()->logicalHeight().calcValue(0); |
| 369 | if (document()->inQuirksMode() || cell->style()->boxSizing() == BORDER_BOX) { |
| 370 | // Explicit heights use the border box in quirks mode. |
| 371 | // Don't adjust height. |
| 372 | } else { |
| 373 | // In strict mode, box-sizing: content-box do the right |
| 374 | // thing and actually add in the border and padding. |
| 375 | LayoutUnit adjustedPaddingBefore = cell->paddingBefore() - cell->intrinsicPaddingBefore(); |
| 376 | LayoutUnit adjustedPaddingAfter = cell->paddingAfter() - cell->intrinsicPaddingAfter(); |
| 377 | ch += adjustedPaddingBefore + adjustedPaddingAfter + cell->borderBefore() + cell->borderAfter(); |
| 378 | } |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 379 | ch = max(ch, adjustedLogicalHeight); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 380 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 381 | pos = m_rowPos[indx] + ch + (m_grid[r].rowRenderer ? spacing : 0); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 382 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 383 | m_rowPos[r + 1] = max(m_rowPos[r + 1], pos); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 384 | |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 385 | // find out the baseline |
| 386 | EVerticalAlign va = cell->style()->verticalAlign(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 387 | if (va == BASELINE || va == TEXT_BOTTOM || va == TEXT_TOP || va == SUPER || va == SUB) { |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 388 | LayoutUnit b = cell->cellBaselinePosition(); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 389 | if (b > cell->borderBefore() + cell->paddingBefore()) { |
hyatt@apple.com | d76152f | 2010-09-21 07:45:08 +0000 | [diff] [blame] | 390 | baseline = max(baseline, b - cell->intrinsicPaddingBefore()); |
| 391 | bdesc = max(bdesc, m_rowPos[indx] + ch - (b - cell->intrinsicPaddingBefore())); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 392 | } |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 393 | } |
| 394 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 395 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 396 | // do we have baseline aligned elements? |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 397 | if (baseline) { |
| 398 | // increase rowheight if baseline requires |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 399 | m_rowPos[r + 1] = max(m_rowPos[r + 1], baseline + bdesc + (m_grid[r].rowRenderer ? spacing : 0)); |
hyatt | 851433b | 2007-05-12 06:40:14 +0000 | [diff] [blame] | 400 | m_grid[r].baseline = baseline; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 401 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 402 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 403 | m_rowPos[r + 1] = max(m_rowPos[r + 1], m_rowPos[r]); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 404 | } |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 405 | |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 406 | #ifndef NDEBUG |
| 407 | setNeedsLayoutIsForbidden(false); |
| 408 | #endif |
| 409 | |
| 410 | ASSERT(!needsLayout()); |
| 411 | |
simon.fraser@apple.com | feaef2e | 2008-11-07 19:17:08 +0000 | [diff] [blame] | 412 | statePusher.pop(); |
mitz@apple.com | 440ac8c | 2008-04-05 16:05:08 +0000 | [diff] [blame] | 413 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 414 | return m_rowPos[m_grid.size()]; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 415 | } |
| 416 | |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 417 | void RenderTableSection::layout() |
| 418 | { |
| 419 | ASSERT(needsLayout()); |
| 420 | |
leviw@chromium.org | 5b6a6ce | 2011-07-02 00:16:52 +0000 | [diff] [blame] | 421 | LayoutStateMaintainer statePusher(view(), this, locationOffset(), style()->isFlippedBlocksWritingMode()); |
hyatt@apple.com | bfda0e3 | 2009-01-31 21:20:17 +0000 | [diff] [blame] | 422 | for (RenderObject* child = children()->firstChild(); child; child = child->nextSibling()) { |
| 423 | if (child->isTableRow()) { |
| 424 | child->layoutIfNeeded(); |
| 425 | ASSERT(!child->needsLayout()); |
| 426 | } |
| 427 | } |
| 428 | statePusher.pop(); |
| 429 | setNeedsLayout(false); |
| 430 | } |
| 431 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 432 | LayoutUnit RenderTableSection::layoutRows(LayoutUnit toAdd) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 433 | { |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 434 | #ifndef NDEBUG |
| 435 | setNeedsLayoutIsForbidden(true); |
| 436 | #endif |
| 437 | |
| 438 | ASSERT(!needsLayout()); |
| 439 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 440 | LayoutUnit rHeight; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 441 | int rindx; |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 442 | unsigned totalRows = m_grid.size(); |
| 443 | |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 444 | // 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] | 445 | setLogicalWidth(table()->contentLogicalWidth()); |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 446 | m_overflow.clear(); |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 447 | m_overflowingCells.clear(); |
| 448 | m_forceSlowPaintPathWithOverflowingCell = false; |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 449 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 450 | if (toAdd && totalRows && (m_rowPos[totalRows] || !nextSibling())) { |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 451 | LayoutUnit totalHeight = m_rowPos[totalRows] + toAdd; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 452 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 453 | LayoutUnit dh = toAdd; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 454 | int totalPercent = 0; |
| 455 | int numAuto = 0; |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 456 | for (unsigned r = 0; r < totalRows; r++) { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 457 | if (m_grid[r].logicalHeight.isAuto()) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 458 | numAuto++; |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 459 | else if (m_grid[r].logicalHeight.isPercent()) |
commit-queue@webkit.org | 0740d9e | 2011-03-22 00:24:01 +0000 | [diff] [blame] | 460 | totalPercent += m_grid[r].logicalHeight.percent(); |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 461 | } |
| 462 | if (totalPercent) { |
| 463 | // try to satisfy percent |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 464 | LayoutUnit add = 0; |
commit-queue@webkit.org | 0740d9e | 2011-03-22 00:24:01 +0000 | [diff] [blame] | 465 | totalPercent = min(totalPercent, 100); |
leviw@chromium.org | f6fccf5 | 2011-11-04 00:56:59 +0000 | [diff] [blame] | 466 | LayoutUnit rh = m_rowPos[1] - m_rowPos[0]; |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 467 | for (unsigned r = 0; r < totalRows; r++) { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 468 | if (totalPercent > 0 && m_grid[r].logicalHeight.isPercent()) { |
leviw@chromium.org | f6fccf5 | 2011-11-04 00:56:59 +0000 | [diff] [blame] | 469 | LayoutUnit toAdd = min<LayoutUnit>(dh, (totalHeight * m_grid[r].logicalHeight.percent() / 100) - rh); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 470 | // If toAdd is negative, then we don't want to shrink the row (this bug |
| 471 | // affected Outlook Web Access). |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 472 | toAdd = max<LayoutUnit>(0, toAdd); |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 473 | add += toAdd; |
| 474 | dh -= toAdd; |
commit-queue@webkit.org | 0740d9e | 2011-03-22 00:24:01 +0000 | [diff] [blame] | 475 | totalPercent -= m_grid[r].logicalHeight.percent(); |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 476 | } |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 477 | ASSERT(totalRows >= 1); |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 478 | if (r < totalRows - 1) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 479 | rh = m_rowPos[r + 2] - m_rowPos[r + 1]; |
| 480 | m_rowPos[r + 1] += add; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | if (numAuto) { |
| 484 | // distribute over variable cols |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 485 | LayoutUnit add = 0; |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 486 | for (unsigned r = 0; r < totalRows; r++) { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 487 | if (numAuto > 0 && m_grid[r].logicalHeight.isAuto()) { |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 488 | LayoutUnit toAdd = dh / numAuto; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 489 | add += toAdd; |
| 490 | dh -= toAdd; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 491 | numAuto--; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 492 | } |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 493 | m_rowPos[r + 1] += add; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 494 | } |
| 495 | } |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 496 | if (dh > 0 && m_rowPos[totalRows]) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 497 | // if some left overs, distribute equally. |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 498 | LayoutUnit tot = m_rowPos[totalRows]; |
| 499 | LayoutUnit add = 0; |
| 500 | LayoutUnit prev = m_rowPos[0]; |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 501 | for (unsigned r = 0; r < totalRows; r++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 502 | // weight with the original height |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 503 | add += dh * (m_rowPos[r + 1] - prev) / tot; |
| 504 | prev = m_rowPos[r + 1]; |
| 505 | m_rowPos[r + 1] += add; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 510 | LayoutUnit hspacing = table()->hBorderSpacing(); |
| 511 | LayoutUnit vspacing = table()->vBorderSpacing(); |
| 512 | LayoutUnit nEffCols = table()->numEffCols(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 513 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 514 | LayoutStateMaintainer statePusher(view(), this, LayoutSize(x(), y()), style()->isFlippedBlocksWritingMode()); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 515 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 516 | for (unsigned r = 0; r < totalRows; r++) { |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 517 | // Set the row's x/y position and width/height. |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 518 | if (RenderTableRow* rowRenderer = m_grid[r].rowRenderer) { |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 519 | rowRenderer->setLocation(LayoutPoint(0, m_rowPos[r])); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 520 | rowRenderer->setLogicalWidth(logicalWidth()); |
| 521 | rowRenderer->setLogicalHeight(m_rowPos[r + 1] - m_rowPos[r] - vspacing); |
simon.fraser@apple.com | 78e3bdb | 2010-11-30 00:53:05 +0000 | [diff] [blame] | 522 | rowRenderer->updateLayerTransform(); |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 523 | } |
| 524 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 525 | for (int c = 0; c < nEffCols; c++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 526 | CellStruct& cs = cellAt(r, c); |
| 527 | RenderTableCell* cell = cs.primaryCell(); |
| 528 | |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 529 | if (!cell || cs.inColSpan) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 530 | continue; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 531 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 532 | rindx = cell->row(); |
| 533 | rHeight = m_rowPos[rindx + cell->rowSpan()] - m_rowPos[rindx] - vspacing; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 534 | |
| 535 | // Force percent height children to lay themselves out again. |
| 536 | // This will cause these children to grow to fill the cell. |
| 537 | // FIXME: There is still more work to do here to fully match WinIE (should |
| 538 | // it become necessary to do so). In quirks mode, WinIE behaves like we |
| 539 | // do, but it will clip the cells that spill out of the table section. In |
| 540 | // strict mode, Mozilla and WinIE both regrow the table to accommodate the |
| 541 | // new height of the cell (thus letting the percentages cause growth one |
| 542 | // time only). We may also not be handling row-spanning cells correctly. |
| 543 | // |
| 544 | // Note also the oddity where replaced elements always flex, and yet blocks/tables do |
| 545 | // not necessarily flex. WinIE is crazy and inconsistent, and we can't hope to |
| 546 | // match the behavior perfectly, but we'll continue to refine it as we discover new |
| 547 | // bugs. :) |
| 548 | bool cellChildrenFlex = false; |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 549 | bool flexAllChildren = cell->style()->logicalHeight().isFixed() |
| 550 | || (!table()->style()->logicalHeight().isAuto() && rHeight != cell->logicalHeight()); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 551 | |
| 552 | for (RenderObject* o = cell->firstChild(); o; o = o->nextSibling()) { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 553 | if (!o->isText() && o->style()->logicalHeight().isPercent() && (flexAllChildren || o->isReplaced() || (o->isBox() && toRenderBox(o)->scrollsOverflow()))) { |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 554 | // Tables with no sections do not flex. |
darin@apple.com | 445c34f | 2009-08-01 00:40:58 +0000 | [diff] [blame] | 555 | if (!o->isTable() || toRenderTable(o)->hasSections()) { |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 556 | o->setNeedsLayout(true, false); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 557 | cellChildrenFlex = true; |
| 558 | } |
| 559 | } |
| 560 | } |
mitz@apple.com | 1547c6d | 2009-03-20 23:41:54 +0000 | [diff] [blame] | 561 | |
| 562 | if (HashSet<RenderBox*>* percentHeightDescendants = cell->percentHeightDescendants()) { |
| 563 | HashSet<RenderBox*>::iterator end = percentHeightDescendants->end(); |
| 564 | for (HashSet<RenderBox*>::iterator it = percentHeightDescendants->begin(); it != end; ++it) { |
| 565 | RenderBox* box = *it; |
| 566 | if (!box->isReplaced() && !box->scrollsOverflow() && !flexAllChildren) |
| 567 | continue; |
| 568 | |
| 569 | while (box != cell) { |
| 570 | if (box->normalChildNeedsLayout()) |
| 571 | break; |
| 572 | box->setChildNeedsLayout(true, false); |
| 573 | box = box->containingBlock(); |
| 574 | ASSERT(box); |
| 575 | if (!box) |
| 576 | break; |
| 577 | } |
| 578 | cellChildrenFlex = true; |
| 579 | } |
| 580 | } |
| 581 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 582 | if (cellChildrenFlex) { |
mitz@apple.com | 1547c6d | 2009-03-20 23:41:54 +0000 | [diff] [blame] | 583 | cell->setChildNeedsLayout(true, false); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 584 | // Alignment within a cell is based off the calculated |
| 585 | // height, which becomes irrelevant once the cell has |
hyatt@apple.com | 0bf6c84 | 2009-01-23 03:42:12 +0000 | [diff] [blame] | 586 | // been resized based off its percentage. |
ojan@chromium.org | f734c92 | 2011-09-07 20:18:14 +0000 | [diff] [blame] | 587 | cell->setOverrideHeightFromRowHeight(rHeight); |
ap | 7332aaa | 2006-04-28 16:02:45 +0000 | [diff] [blame] | 588 | cell->layoutIfNeeded(); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 589 | |
hyatt | 851433b | 2007-05-12 06:40:14 +0000 | [diff] [blame] | 590 | // If the baseline moved, we may have to update the data for our row. Find out the new baseline. |
| 591 | EVerticalAlign va = cell->style()->verticalAlign(); |
| 592 | if (va == BASELINE || va == TEXT_BOTTOM || va == TEXT_TOP || va == SUPER || va == SUB) { |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 593 | LayoutUnit baseline = cell->cellBaselinePosition(); |
| 594 | if (baseline > cell->borderBefore() + cell->paddingBefore()) |
| 595 | m_grid[r].baseline = max(m_grid[r].baseline, baseline); |
hyatt | 851433b | 2007-05-12 06:40:14 +0000 | [diff] [blame] | 596 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 597 | } |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 598 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 599 | LayoutUnit oldIntrinsicPaddingBefore = cell->intrinsicPaddingBefore(); |
| 600 | LayoutUnit oldIntrinsicPaddingAfter = cell->intrinsicPaddingAfter(); |
| 601 | LayoutUnit logicalHeightWithoutIntrinsicPadding = cell->logicalHeight() - oldIntrinsicPaddingBefore - oldIntrinsicPaddingAfter; |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 602 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 603 | LayoutUnit intrinsicPaddingBefore = 0; |
bdakin | f993635 | 2007-04-19 19:58:20 +0000 | [diff] [blame] | 604 | switch (cell->style()->verticalAlign()) { |
| 605 | case SUB: |
| 606 | case SUPER: |
| 607 | case TEXT_TOP: |
| 608 | case TEXT_BOTTOM: |
hyatt@apple.com | 5defbad | 2009-01-23 04:30:47 +0000 | [diff] [blame] | 609 | case BASELINE: { |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 610 | LayoutUnit b = cell->cellBaselinePosition(); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 611 | if (b > cell->borderBefore() + cell->paddingBefore()) |
| 612 | intrinsicPaddingBefore = getBaseline(r) - (b - oldIntrinsicPaddingBefore); |
bdakin | f993635 | 2007-04-19 19:58:20 +0000 | [diff] [blame] | 613 | break; |
hyatt@apple.com | 5defbad | 2009-01-23 04:30:47 +0000 | [diff] [blame] | 614 | } |
bdakin | f993635 | 2007-04-19 19:58:20 +0000 | [diff] [blame] | 615 | case TOP: |
bdakin | f993635 | 2007-04-19 19:58:20 +0000 | [diff] [blame] | 616 | break; |
| 617 | case MIDDLE: |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 618 | intrinsicPaddingBefore = (rHeight - logicalHeightWithoutIntrinsicPadding) / 2; |
bdakin | f993635 | 2007-04-19 19:58:20 +0000 | [diff] [blame] | 619 | break; |
| 620 | case BOTTOM: |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 621 | intrinsicPaddingBefore = rHeight - logicalHeightWithoutIntrinsicPadding; |
bdakin | f993635 | 2007-04-19 19:58:20 +0000 | [diff] [blame] | 622 | break; |
| 623 | default: |
| 624 | break; |
| 625 | } |
hyatt@apple.com | 0bf6c84 | 2009-01-23 03:42:12 +0000 | [diff] [blame] | 626 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 627 | LayoutUnit intrinsicPaddingAfter = rHeight - logicalHeightWithoutIntrinsicPadding - intrinsicPaddingBefore; |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 628 | cell->setIntrinsicPaddingBefore(intrinsicPaddingBefore); |
| 629 | cell->setIntrinsicPaddingAfter(intrinsicPaddingAfter); |
| 630 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 631 | LayoutRect oldCellRect(cell->x(), cell->y() , cell->width(), cell->height()); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 632 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 633 | LayoutPoint cellLocation(0, m_rowPos[rindx]); |
hyatt@apple.com | c0fa163 | 2010-09-30 20:01:33 +0000 | [diff] [blame] | 634 | if (!style()->isLeftToRightDirection()) |
eae@chromium.org | be9be86 | 2011-05-12 23:30:09 +0000 | [diff] [blame] | 635 | cellLocation.setX(table()->columnPositions()[nEffCols] - table()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + hspacing); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 636 | else |
eae@chromium.org | be9be86 | 2011-05-12 23:30:09 +0000 | [diff] [blame] | 637 | cellLocation.setX(table()->columnPositions()[c] + hspacing); |
| 638 | cell->setLogicalLocation(cellLocation); |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 639 | view()->addLayoutDelta(oldCellRect.location() - cell->location()); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 640 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 641 | if (intrinsicPaddingBefore != oldIntrinsicPaddingBefore || intrinsicPaddingAfter != oldIntrinsicPaddingAfter) |
hyatt@apple.com | 1259d73 | 2010-09-20 16:12:58 +0000 | [diff] [blame] | 642 | cell->setNeedsLayout(true, false); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 643 | |
hyatt@apple.com | 61bbedf | 2011-01-26 23:10:57 +0000 | [diff] [blame] | 644 | if (!cell->needsLayout() && view()->layoutState()->pageLogicalHeight() && view()->layoutState()->pageLogicalOffset(cell->logicalTop()) != cell->pageLogicalOffset()) |
hyatt@apple.com | 1259d73 | 2010-09-20 16:12:58 +0000 | [diff] [blame] | 645 | cell->setChildNeedsLayout(true, false); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 646 | |
hyatt@apple.com | 1259d73 | 2010-09-20 16:12:58 +0000 | [diff] [blame] | 647 | cell->layoutIfNeeded(); |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 648 | |
| 649 | // FIXME: Make pagination work with vertical tables. |
hyatt@apple.com | 9285815d | 2010-12-14 19:58:38 +0000 | [diff] [blame] | 650 | if (style()->isHorizontalWritingMode() && view()->layoutState()->pageLogicalHeight() && cell->height() != rHeight) |
hyatt@apple.com | 1259d73 | 2010-09-20 16:12:58 +0000 | [diff] [blame] | 651 | cell->setHeight(rHeight); // FIXME: Pagination might have made us change size. For now just shrink or grow the cell to fit without doing a relayout. |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 652 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 653 | LayoutSize childOffset(cell->location() - oldCellRect.location()); |
hyatt@apple.com | b297b49 | 2010-09-20 20:21:34 +0000 | [diff] [blame] | 654 | if (childOffset.width() || childOffset.height()) { |
| 655 | view()->addLayoutDelta(childOffset); |
hyatt@apple.com | 1259d73 | 2010-09-20 16:12:58 +0000 | [diff] [blame] | 656 | |
hyatt@apple.com | b297b49 | 2010-09-20 20:21:34 +0000 | [diff] [blame] | 657 | // If the child moved, we have to repaint it as well as any floating/positioned |
| 658 | // descendants. An exception is if we need a layout. In this case, we know we're going to |
| 659 | // repaint ourselves (and the child) anyway. |
| 660 | if (!table()->selfNeedsLayout() && cell->checkForRepaintDuringLayout()) |
| 661 | cell->repaintDuringLayoutIfMoved(oldCellRect); |
| 662 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
hyatt@apple.com | c93db9b | 2009-02-04 22:29:04 +0000 | [diff] [blame] | 666 | #ifndef NDEBUG |
| 667 | setNeedsLayoutIsForbidden(false); |
| 668 | #endif |
| 669 | |
hyatt@apple.com | 8b2cd1f | 2009-01-26 03:38:55 +0000 | [diff] [blame] | 670 | ASSERT(!needsLayout()); |
| 671 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 672 | setLogicalHeight(m_rowPos[totalRows]); |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 673 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 674 | unsigned totalCellsCount = nEffCols * totalRows; |
| 675 | int maxAllowedOverflowingCellsCount = totalCellsCount < gMinTableSizeToUseFastPaintPathWithOverflowingCell ? 0 : gMaxAllowedOverflowingCellRatioForFastPaintPath * totalCellsCount; |
| 676 | |
| 677 | #ifndef NDEBUG |
| 678 | bool hasOverflowingCell = false; |
| 679 | #endif |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 680 | // 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] | 681 | for (unsigned r = 0; r < totalRows; r++) { |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 682 | for (int c = 0; c < nEffCols; c++) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 683 | CellStruct& cs = cellAt(r, c); |
| 684 | RenderTableCell* cell = cs.primaryCell(); |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 685 | if (!cell || cs.inColSpan) |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 686 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 687 | if (r < totalRows - 1 && cell == primaryCellAt(r + 1, c)) |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 688 | continue; |
| 689 | addOverflowFromChild(cell); |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 690 | #ifndef NDEBUG |
| 691 | hasOverflowingCell |= cell->hasVisualOverflow(); |
| 692 | #endif |
| 693 | if (cell->hasVisualOverflow() && !m_forceSlowPaintPathWithOverflowingCell) { |
| 694 | m_overflowingCells.add(cell); |
| 695 | if (m_overflowingCells.size() > maxAllowedOverflowingCellsCount) { |
| 696 | // We need to set m_forcesSlowPaintPath only if there is a least one overflowing cells as the hit testing code rely on this information. |
| 697 | m_forceSlowPaintPathWithOverflowingCell = true; |
| 698 | // The slow path does not make any use of the overflowing cells info, don't hold on to the memory. |
| 699 | m_overflowingCells.clear(); |
| 700 | } |
| 701 | } |
hyatt@apple.com | 7214c6a | 2009-08-19 16:28:51 +0000 | [diff] [blame] | 702 | } |
| 703 | } |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 704 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 705 | ASSERT(hasOverflowingCell == this->hasOverflowingCell()); |
| 706 | |
mitz@apple.com | eea5285 | 2009-12-31 18:41:23 +0000 | [diff] [blame] | 707 | statePusher.pop(); |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 708 | return height(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 709 | } |
| 710 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 711 | LayoutUnit RenderTableSection::calcOuterBorderBefore() const |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 712 | { |
| 713 | int totalCols = table()->numEffCols(); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 714 | if (!m_grid.size() || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 715 | return 0; |
| 716 | |
| 717 | unsigned borderWidth = 0; |
| 718 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 719 | const BorderValue& sb = style()->borderBefore(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 720 | if (sb.style() == BHIDDEN) |
| 721 | return -1; |
| 722 | if (sb.style() > BHIDDEN) |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 723 | borderWidth = sb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 724 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 725 | const BorderValue& rb = firstChild()->style()->borderBefore(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 726 | if (rb.style() == BHIDDEN) |
| 727 | return -1; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 728 | if (rb.style() > BHIDDEN && rb.width() > borderWidth) |
| 729 | borderWidth = rb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 730 | |
| 731 | bool allHidden = true; |
| 732 | for (int c = 0; c < totalCols; c++) { |
| 733 | const CellStruct& current = cellAt(0, c); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 734 | if (current.inColSpan || !current.hasCells()) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 735 | continue; |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 736 | 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] | 737 | // FIXME: Don't repeat for the same col group |
| 738 | RenderTableCol* colGroup = table()->colElement(c); |
| 739 | if (colGroup) { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 740 | const BorderValue& gb = colGroup->style()->borderBefore(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 741 | if (gb.style() == BHIDDEN || cb.style() == BHIDDEN) |
| 742 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 743 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 744 | if (gb.style() > BHIDDEN && gb.width() > borderWidth) |
| 745 | borderWidth = gb.width(); |
| 746 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 747 | borderWidth = cb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 748 | } else { |
| 749 | if (cb.style() == BHIDDEN) |
| 750 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 751 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 752 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 753 | borderWidth = cb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | if (allHidden) |
| 757 | return -1; |
| 758 | |
| 759 | return borderWidth / 2; |
| 760 | } |
| 761 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 762 | LayoutUnit RenderTableSection::calcOuterBorderAfter() const |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 763 | { |
| 764 | int totalCols = table()->numEffCols(); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 765 | if (!m_grid.size() || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 766 | return 0; |
| 767 | |
| 768 | unsigned borderWidth = 0; |
| 769 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 770 | const BorderValue& sb = style()->borderAfter(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 771 | if (sb.style() == BHIDDEN) |
| 772 | return -1; |
| 773 | if (sb.style() > BHIDDEN) |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 774 | borderWidth = sb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 775 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 776 | const BorderValue& rb = lastChild()->style()->borderAfter(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 777 | if (rb.style() == BHIDDEN) |
| 778 | return -1; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 779 | if (rb.style() > BHIDDEN && rb.width() > borderWidth) |
| 780 | borderWidth = rb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 781 | |
| 782 | bool allHidden = true; |
| 783 | for (int c = 0; c < totalCols; c++) { |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 784 | const CellStruct& current = cellAt(m_grid.size() - 1, c); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 785 | if (current.inColSpan || !current.hasCells()) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 786 | continue; |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 787 | 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] | 788 | // FIXME: Don't repeat for the same col group |
| 789 | RenderTableCol* colGroup = table()->colElement(c); |
| 790 | if (colGroup) { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 791 | const BorderValue& gb = colGroup->style()->borderAfter(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 792 | if (gb.style() == BHIDDEN || cb.style() == BHIDDEN) |
| 793 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 794 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 795 | if (gb.style() > BHIDDEN && gb.width() > borderWidth) |
| 796 | borderWidth = gb.width(); |
| 797 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 798 | borderWidth = cb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 799 | } else { |
| 800 | if (cb.style() == BHIDDEN) |
| 801 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 802 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 803 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 804 | borderWidth = cb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | if (allHidden) |
| 808 | return -1; |
| 809 | |
| 810 | return (borderWidth + 1) / 2; |
| 811 | } |
| 812 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 813 | LayoutUnit RenderTableSection::calcOuterBorderStart() const |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 814 | { |
| 815 | int totalCols = table()->numEffCols(); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 816 | if (!m_grid.size() || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 817 | return 0; |
| 818 | |
| 819 | unsigned borderWidth = 0; |
| 820 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 821 | const BorderValue& sb = style()->borderStart(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 822 | if (sb.style() == BHIDDEN) |
| 823 | return -1; |
| 824 | if (sb.style() > BHIDDEN) |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 825 | borderWidth = sb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 826 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 827 | if (RenderTableCol* colGroup = table()->colElement(0)) { |
| 828 | const BorderValue& gb = colGroup->style()->borderStart(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 829 | if (gb.style() == BHIDDEN) |
| 830 | return -1; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 831 | if (gb.style() > BHIDDEN && gb.width() > borderWidth) |
| 832 | borderWidth = gb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | bool allHidden = true; |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 836 | for (unsigned r = 0; r < m_grid.size(); r++) { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 837 | const CellStruct& current = cellAt(r, 0); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 838 | if (!current.hasCells()) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 839 | continue; |
| 840 | // FIXME: Don't repeat for the same cell |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 841 | const BorderValue& cb = current.primaryCell()->style()->borderStart(); // FIXME: Make this work with perpendicular and flipped cells. |
| 842 | const BorderValue& rb = current.primaryCell()->parent()->style()->borderStart(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 843 | if (cb.style() == BHIDDEN || rb.style() == BHIDDEN) |
| 844 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 845 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 846 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 847 | borderWidth = cb.width(); |
| 848 | if (rb.style() > BHIDDEN && rb.width() > borderWidth) |
| 849 | borderWidth = rb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 850 | } |
| 851 | if (allHidden) |
| 852 | return -1; |
| 853 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 854 | return (borderWidth + (table()->style()->isLeftToRightDirection() ? 0 : 1)) / 2; |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 855 | } |
| 856 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 857 | LayoutUnit RenderTableSection::calcOuterBorderEnd() const |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 858 | { |
| 859 | int totalCols = table()->numEffCols(); |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 860 | if (!m_grid.size() || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 861 | return 0; |
| 862 | |
| 863 | unsigned borderWidth = 0; |
| 864 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 865 | const BorderValue& sb = style()->borderEnd(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 866 | if (sb.style() == BHIDDEN) |
| 867 | return -1; |
| 868 | if (sb.style() > BHIDDEN) |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 869 | borderWidth = sb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 870 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 871 | if (RenderTableCol* colGroup = table()->colElement(totalCols - 1)) { |
| 872 | const BorderValue& gb = colGroup->style()->borderEnd(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 873 | if (gb.style() == BHIDDEN) |
| 874 | return -1; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 875 | if (gb.style() > BHIDDEN && gb.width() > borderWidth) |
| 876 | borderWidth = gb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | bool allHidden = true; |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 880 | for (unsigned r = 0; r < m_grid.size(); r++) { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 881 | const CellStruct& current = cellAt(r, totalCols - 1); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 882 | if (!current.hasCells()) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 883 | continue; |
| 884 | // FIXME: Don't repeat for the same cell |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 885 | const BorderValue& cb = current.primaryCell()->style()->borderEnd(); // FIXME: Make this work with perpendicular and flipped cells. |
| 886 | const BorderValue& rb = current.primaryCell()->parent()->style()->borderEnd(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 887 | if (cb.style() == BHIDDEN || rb.style() == BHIDDEN) |
| 888 | continue; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 889 | allHidden = false; |
hyatt@apple.com | e607db7 | 2010-04-09 20:21:55 +0000 | [diff] [blame] | 890 | if (cb.style() > BHIDDEN && cb.width() > borderWidth) |
| 891 | borderWidth = cb.width(); |
| 892 | if (rb.style() > BHIDDEN && rb.width() > borderWidth) |
| 893 | borderWidth = rb.width(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 894 | } |
| 895 | if (allHidden) |
| 896 | return -1; |
| 897 | |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 898 | return (borderWidth + (table()->style()->isLeftToRightDirection() ? 1 : 0)) / 2; |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | void RenderTableSection::recalcOuterBorder() |
| 902 | { |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 903 | m_outerBorderBefore = calcOuterBorderBefore(); |
| 904 | m_outerBorderAfter = calcOuterBorderAfter(); |
| 905 | m_outerBorderStart = calcOuterBorderStart(); |
| 906 | m_outerBorderEnd = calcOuterBorderEnd(); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 907 | } |
| 908 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 909 | LayoutUnit RenderTableSection::firstLineBoxBaseline() const |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 910 | { |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 911 | if (!m_grid.size()) |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 912 | return -1; |
| 913 | |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 914 | LayoutUnit firstLineBaseline = m_grid[0].baseline; |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 915 | if (firstLineBaseline) |
| 916 | return firstLineBaseline + m_rowPos[0]; |
| 917 | |
| 918 | firstLineBaseline = -1; |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 919 | const Row& firstRow = m_grid[0].row; |
| 920 | for (size_t i = 0; i < firstRow.size(); ++i) { |
| 921 | const CellStruct& cs = firstRow.at(i); |
| 922 | const RenderTableCell* cell = cs.primaryCell(); |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 923 | if (cell) |
mitz@apple.com | 8010bba | 2010-11-05 02:43:17 +0000 | [diff] [blame] | 924 | firstLineBaseline = max(firstLineBaseline, cell->logicalTop() + cell->paddingBefore() + cell->borderBefore() + cell->contentLogicalHeight()); |
mitz@apple.com | 57a2f48 | 2008-08-23 07:16:41 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | return firstLineBaseline; |
| 928 | } |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 929 | |
leviw@chromium.org | b375750 | 2011-06-29 21:33:11 +0000 | [diff] [blame] | 930 | void RenderTableSection::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 931 | { |
antti | b366607 | 2007-08-17 23:29:50 +0000 | [diff] [blame] | 932 | // put this back in when all layout tests can handle it |
| 933 | // ASSERT(!needsLayout()); |
| 934 | // avoid crashing on bugs that cause us to paint with dirty layout |
| 935 | if (needsLayout()) |
| 936 | return; |
| 937 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 938 | unsigned totalRows = m_grid.size(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 939 | unsigned totalCols = table()->columns().size(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 940 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 941 | if (!totalRows || !totalCols) |
ap | 0e708ba | 2006-05-20 08:47:37 +0000 | [diff] [blame] | 942 | return; |
| 943 | |
leviw@chromium.org | b375750 | 2011-06-29 21:33:11 +0000 | [diff] [blame] | 944 | LayoutPoint adjustedPaintOffset = paintOffset + location(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 945 | |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 946 | PaintPhase phase = paintInfo.phase; |
leviw@chromium.org | 61ca137 | 2011-06-07 18:56:41 +0000 | [diff] [blame] | 947 | bool pushedClip = pushContentsClip(paintInfo, adjustedPaintOffset); |
| 948 | paintObject(paintInfo, adjustedPaintOffset); |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 949 | if (pushedClip) |
leviw@chromium.org | 61ca137 | 2011-06-07 18:56:41 +0000 | [diff] [blame] | 950 | popContentsClip(paintInfo, phase, adjustedPaintOffset); |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 951 | } |
| 952 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 953 | static inline bool compareCellPositions(RenderTableCell* elem1, RenderTableCell* elem2) |
| 954 | { |
| 955 | return elem1->row() < elem2->row(); |
| 956 | } |
| 957 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 958 | // This comparison is used only when we have overflowing cells as we have an unsorted array to sort. We thus need |
| 959 | // to sort both on rows and columns to properly repaint. |
| 960 | static inline bool compareCellPositionsWithOverflowingCells(RenderTableCell* elem1, RenderTableCell* elem2) |
| 961 | { |
| 962 | if (elem1->row() != elem2->row()) |
| 963 | return elem1->row() < elem2->row(); |
| 964 | |
| 965 | return elem1->col() < elem2->col(); |
| 966 | } |
| 967 | |
leviw@chromium.org | 890e9b0 | 2011-07-07 23:17:55 +0000 | [diff] [blame] | 968 | void RenderTableSection::paintCell(RenderTableCell* cell, PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 969 | { |
ojan@chromium.org | 035c88ca | 2011-10-03 22:00:25 +0000 | [diff] [blame] | 970 | LayoutPoint cellPoint = flipForWritingModeForChild(cell, paintOffset); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 971 | PaintPhase paintPhase = paintInfo.phase; |
| 972 | RenderTableRow* row = toRenderTableRow(cell->parent()); |
| 973 | |
| 974 | if (paintPhase == PaintPhaseBlockBackground || paintPhase == PaintPhaseChildBlockBackground) { |
| 975 | // We need to handle painting a stack of backgrounds. This stack (from bottom to top) consists of |
| 976 | // the column group, column, row group, row, and then the cell. |
| 977 | RenderObject* col = table()->colElement(cell->col()); |
| 978 | RenderObject* colGroup = 0; |
| 979 | if (col && col->parent()->style()->display() == TABLE_COLUMN_GROUP) |
| 980 | colGroup = col->parent(); |
| 981 | |
| 982 | // Column groups and columns first. |
| 983 | // FIXME: Columns and column groups do not currently support opacity, and they are being painted "too late" in |
| 984 | // the stack, since we have already opened a transparency layer (potentially) for the table row group. |
| 985 | // Note that we deliberately ignore whether or not the cell has a layer, since these backgrounds paint "behind" the |
| 986 | // cell. |
leviw@chromium.org | 719a45b | 2011-06-03 20:59:40 +0000 | [diff] [blame] | 987 | cell->paintBackgroundsBehindCell(paintInfo, cellPoint, colGroup); |
| 988 | cell->paintBackgroundsBehindCell(paintInfo, cellPoint, col); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 989 | |
| 990 | // Paint the row group next. |
leviw@chromium.org | 719a45b | 2011-06-03 20:59:40 +0000 | [diff] [blame] | 991 | cell->paintBackgroundsBehindCell(paintInfo, cellPoint, this); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 992 | |
| 993 | // Paint the row next, but only if it doesn't have a layer. If a row has a layer, it will be responsible for |
| 994 | // painting the row background for the cell. |
| 995 | if (!row->hasSelfPaintingLayer()) |
leviw@chromium.org | 719a45b | 2011-06-03 20:59:40 +0000 | [diff] [blame] | 996 | cell->paintBackgroundsBehindCell(paintInfo, cellPoint, row); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 997 | } |
| 998 | if ((!cell->hasSelfPaintingLayer() && !row->hasSelfPaintingLayer()) || paintInfo.phase == PaintPhaseCollapsedTableBorders) |
leviw@chromium.org | 61ca137 | 2011-06-07 18:56:41 +0000 | [diff] [blame] | 999 | cell->paint(paintInfo, cellPoint); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
leviw@chromium.org | c491808 | 2011-06-29 01:06:00 +0000 | [diff] [blame] | 1002 | void RenderTableSection::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 1003 | { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1004 | // Check which rows and cols are visible and only paint these. |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 1005 | unsigned totalRows = m_grid.size(); |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 1006 | unsigned totalCols = table()->columns().size(); |
| 1007 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 1008 | PaintPhase paintPhase = paintInfo.phase; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1009 | |
leviw@chromium.org | c491808 | 2011-06-29 01:06:00 +0000 | [diff] [blame] | 1010 | LayoutUnit os = 2 * maximalOutlineSize(paintPhase); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1011 | unsigned startrow = 0; |
| 1012 | unsigned endrow = totalRows; |
mitz@apple.com | 20e5bec | 2010-12-08 01:37:57 +0000 | [diff] [blame] | 1013 | |
leviw@chromium.org | c491808 | 2011-06-29 01:06:00 +0000 | [diff] [blame] | 1014 | LayoutRect localRepaintRect = paintInfo.rect; |
leviw@chromium.org | 43d0c4d | 2011-06-04 02:25:54 +0000 | [diff] [blame] | 1015 | localRepaintRect.moveBy(-paintOffset); |
mitz@apple.com | 20e5bec | 2010-12-08 01:37:57 +0000 | [diff] [blame] | 1016 | if (style()->isFlippedBlocksWritingMode()) { |
| 1017 | if (style()->isHorizontalWritingMode()) |
hyatt@apple.com | aa0cba0 | 2011-02-01 21:39:47 +0000 | [diff] [blame] | 1018 | localRepaintRect.setY(height() - localRepaintRect.maxY()); |
mitz@apple.com | 20e5bec | 2010-12-08 01:37:57 +0000 | [diff] [blame] | 1019 | else |
hyatt@apple.com | aa0cba0 | 2011-02-01 21:39:47 +0000 | [diff] [blame] | 1020 | localRepaintRect.setX(width() - localRepaintRect.maxX()); |
mitz@apple.com | 20e5bec | 2010-12-08 01:37:57 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1023 | if (!m_forceSlowPaintPathWithOverflowingCell) { |
leviw@chromium.org | c491808 | 2011-06-29 01:06:00 +0000 | [diff] [blame] | 1024 | LayoutUnit before = (style()->isHorizontalWritingMode() ? localRepaintRect.y() : localRepaintRect.x()) - os; |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1025 | // binary search to find a row |
mitz@apple.com | 20e5bec | 2010-12-08 01:37:57 +0000 | [diff] [blame] | 1026 | startrow = std::lower_bound(m_rowPos.begin(), m_rowPos.end(), before) - m_rowPos.begin(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1027 | |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1028 | // The binary search above gives us the first row with |
| 1029 | // a y position >= the top of the paint rect. Thus, the previous |
| 1030 | // may need to be repainted as well. |
mitz@apple.com | 20e5bec | 2010-12-08 01:37:57 +0000 | [diff] [blame] | 1031 | if (startrow == m_rowPos.size() || (startrow > 0 && (m_rowPos[startrow] > before))) |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1032 | --startrow; |
| 1033 | |
leviw@chromium.org | c491808 | 2011-06-29 01:06:00 +0000 | [diff] [blame] | 1034 | LayoutUnit after = (style()->isHorizontalWritingMode() ? localRepaintRect.maxY() : localRepaintRect.maxX()) + os; |
mitz@apple.com | 20e5bec | 2010-12-08 01:37:57 +0000 | [diff] [blame] | 1035 | endrow = std::lower_bound(m_rowPos.begin(), m_rowPos.end(), after) - m_rowPos.begin(); |
fsamuel@chromium.org | 179df3b | 2010-10-05 23:55:13 +0000 | [diff] [blame] | 1036 | if (endrow == m_rowPos.size()) |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1037 | --endrow; |
| 1038 | |
mitz@apple.com | 20e5bec | 2010-12-08 01:37:57 +0000 | [diff] [blame] | 1039 | if (!endrow && m_rowPos[0] - table()->outerBorderBefore() <= after) |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1040 | ++endrow; |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 1041 | } |
mitz@apple.com | 20e5bec | 2010-12-08 01:37:57 +0000 | [diff] [blame] | 1042 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1043 | unsigned startcol = 0; |
| 1044 | unsigned endcol = totalCols; |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 1045 | // FIXME: Implement RTL. |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1046 | if (!m_forceSlowPaintPathWithOverflowingCell && style()->isLeftToRightDirection()) { |
leviw@chromium.org | c491808 | 2011-06-29 01:06:00 +0000 | [diff] [blame] | 1047 | LayoutUnit start = (style()->isHorizontalWritingMode() ? localRepaintRect.x() : localRepaintRect.y()) - os; |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 1048 | Vector<LayoutUnit>& columnPos = table()->columnPositions(); |
mitz@apple.com | 20e5bec | 2010-12-08 01:37:57 +0000 | [diff] [blame] | 1049 | startcol = std::lower_bound(columnPos.begin(), columnPos.end(), start) - columnPos.begin(); |
| 1050 | if ((startcol == columnPos.size()) || (startcol > 0 && (columnPos[startcol] > start))) |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1051 | --startcol; |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 1052 | |
leviw@chromium.org | c491808 | 2011-06-29 01:06:00 +0000 | [diff] [blame] | 1053 | LayoutUnit end = (style()->isHorizontalWritingMode() ? localRepaintRect.maxX() : localRepaintRect.maxY()) + os; |
mitz@apple.com | 20e5bec | 2010-12-08 01:37:57 +0000 | [diff] [blame] | 1054 | endcol = std::lower_bound(columnPos.begin(), columnPos.end(), end) - columnPos.begin(); |
fsamuel@chromium.org | 179df3b | 2010-10-05 23:55:13 +0000 | [diff] [blame] | 1055 | if (endcol == columnPos.size()) |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1056 | --endcol; |
| 1057 | |
mitz@apple.com | 20e5bec | 2010-12-08 01:37:57 +0000 | [diff] [blame] | 1058 | if (!endcol && columnPos[0] - table()->outerBorderStart() <= end) |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1059 | ++endcol; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1060 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1061 | if (startcol < endcol) { |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1062 | if (!m_hasMultipleCellLevels && !m_overflowingCells.size()) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1063 | // Draw the dirty cells in the order that they appear. |
| 1064 | for (unsigned r = startrow; r < endrow; r++) { |
| 1065 | for (unsigned c = startcol; c < endcol; c++) { |
| 1066 | CellStruct& current = cellAt(r, c); |
| 1067 | RenderTableCell* cell = current.primaryCell(); |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 1068 | if (!cell || (r > startrow && primaryCellAt(r - 1, c) == cell) || (c > startcol && primaryCellAt(r, c - 1) == cell)) |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1069 | continue; |
leviw@chromium.org | 43d0c4d | 2011-06-04 02:25:54 +0000 | [diff] [blame] | 1070 | paintCell(cell, paintInfo, paintOffset); |
hyatt | e031dd0 | 2006-03-18 01:01:06 +0000 | [diff] [blame] | 1071 | } |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1072 | } |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1073 | } else { |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1074 | // The overflowing cells should be scarce to avoid adding a lot of cells to the HashSet. |
| 1075 | ASSERT(m_overflowingCells.size() < totalRows * totalCols * gMaxAllowedOverflowingCellRatioForFastPaintPath); |
| 1076 | |
| 1077 | // To make sure we properly repaint the section, we repaint all the overflowing cells that we collected. |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1078 | Vector<RenderTableCell*> cells; |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1079 | copyToVector(m_overflowingCells, cells); |
| 1080 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1081 | HashSet<RenderTableCell*> spanningCells; |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1082 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1083 | for (unsigned r = startrow; r < endrow; r++) { |
| 1084 | for (unsigned c = startcol; c < endcol; c++) { |
| 1085 | CellStruct& current = cellAt(r, c); |
jamesr@google.com | b426623 | 2010-07-28 20:07:19 +0000 | [diff] [blame] | 1086 | if (!current.hasCells()) |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1087 | continue; |
| 1088 | for (unsigned i = 0; i < current.cells.size(); ++i) { |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1089 | if (m_overflowingCells.contains(current.cells[i])) |
| 1090 | continue; |
| 1091 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1092 | if (current.cells[i]->rowSpan() > 1 || current.cells[i]->colSpan() > 1) { |
| 1093 | if (spanningCells.contains(current.cells[i])) |
| 1094 | continue; |
| 1095 | spanningCells.add(current.cells[i]); |
| 1096 | } |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1097 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1098 | cells.append(current.cells[i]); |
| 1099 | } |
| 1100 | } |
| 1101 | } |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1102 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1103 | // Sort the dirty cells by paint order. |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1104 | if (!m_overflowingCells.size()) |
| 1105 | std::stable_sort(cells.begin(), cells.end(), compareCellPositions); |
| 1106 | else |
| 1107 | std::sort(cells.begin(), cells.end(), compareCellPositionsWithOverflowingCells); |
| 1108 | |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1109 | int size = cells.size(); |
| 1110 | // Paint the cells. |
| 1111 | for (int i = 0; i < size; ++i) |
leviw@chromium.org | 43d0c4d | 2011-06-04 02:25:54 +0000 | [diff] [blame] | 1112 | paintCell(cells[i], paintInfo, paintOffset); |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1113 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
darin@apple.com | 98a7ac6 | 2009-01-05 17:26:53 +0000 | [diff] [blame] | 1117 | void RenderTableSection::imageChanged(WrappedImagePtr, const IntRect*) |
bdash | b07ae8d | 2007-02-08 04:56:20 +0000 | [diff] [blame] | 1118 | { |
bdash | b07ae8d | 2007-02-08 04:56:20 +0000 | [diff] [blame] | 1119 | // FIXME: Examine cells and repaint only the rect the image paints in. |
| 1120 | repaint(); |
| 1121 | } |
| 1122 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1123 | void RenderTableSection::recalcCells() |
| 1124 | { |
jchaffraix@webkit.org | d01277d | 2011-11-09 19:57:16 +0000 | [diff] [blame] | 1125 | ASSERT(m_needsCellRecalc); |
| 1126 | // We reset the flag here to ensure that |addCell| works. This is safe to do as |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame^] | 1127 | // we clear the grid and properly rebuild it during |addCell|. |
jchaffraix@webkit.org | d01277d | 2011-11-09 19:57:16 +0000 | [diff] [blame] | 1128 | m_needsCellRecalc = false; |
| 1129 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1130 | m_cCol = 0; |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1131 | m_cRow = 0; |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame^] | 1132 | m_grid.clear(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1133 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1134 | for (RenderObject* row = firstChild(); row; row = row->nextSibling()) { |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1135 | if (row->isTableRow()) { |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1136 | unsigned insertionRow = m_cRow; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1137 | m_cRow++; |
| 1138 | m_cCol = 0; |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame^] | 1139 | ensureRows(m_cRow); |
| 1140 | |
darin@apple.com | 445c34f | 2009-08-01 00:40:58 +0000 | [diff] [blame] | 1141 | RenderTableRow* tableRow = toRenderTableRow(row); |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1142 | m_grid[insertionRow].rowRenderer = tableRow; |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 1143 | setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[insertionRow]); |
eseidel | 05ef043 | 2006-05-25 22:11:36 +0000 | [diff] [blame] | 1144 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1145 | for (RenderObject* cell = row->firstChild(); cell; cell = cell->nextSibling()) { |
jchaffraix@webkit.org | ddeb7db | 2011-11-01 18:02:42 +0000 | [diff] [blame] | 1146 | if (!cell->isTableCell()) |
| 1147 | continue; |
| 1148 | |
| 1149 | RenderTableCell* tableCell = toRenderTableCell(cell); |
jchaffraix@webkit.org | ddeb7db | 2011-11-01 18:02:42 +0000 | [diff] [blame] | 1150 | addCell(tableCell, tableRow); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1151 | } |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1152 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1153 | } |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 1154 | |
jchaffraix@webkit.org | e98e3e5 | 2011-11-11 01:41:26 +0000 | [diff] [blame^] | 1155 | m_grid.shrinkToFit(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1156 | setNeedsLayout(true); |
| 1157 | } |
| 1158 | |
jchaffraix@webkit.org | 19bbb72 | 2011-11-03 17:20:01 +0000 | [diff] [blame] | 1159 | void RenderTableSection::rowLogicalHeightChanged(unsigned rowIndex) |
| 1160 | { |
| 1161 | setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[rowIndex]); |
| 1162 | } |
| 1163 | |
jamesr@google.com | 5ddfb04 | 2011-01-20 21:34:34 +0000 | [diff] [blame] | 1164 | void RenderTableSection::setNeedsCellRecalc() |
| 1165 | { |
| 1166 | m_needsCellRecalc = true; |
| 1167 | if (RenderTable* t = table()) |
| 1168 | t->setNeedsSectionRecalc(); |
| 1169 | } |
| 1170 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1171 | unsigned RenderTableSection::numColumns() const |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1172 | { |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1173 | unsigned result = 0; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1174 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 1175 | for (unsigned r = 0; r < m_grid.size(); ++r) { |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1176 | for (unsigned c = result; c < table()->numEffCols(); ++c) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1177 | const CellStruct& cell = cellAt(r, c); |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1178 | if (cell.hasCells() || cell.inColSpan) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1179 | result = c; |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | return result + 1; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1186 | void RenderTableSection::appendColumn(int pos) |
| 1187 | { |
jchaffraix@webkit.org | d01277d | 2011-11-09 19:57:16 +0000 | [diff] [blame] | 1188 | ASSERT(!m_needsCellRecalc); |
| 1189 | |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 1190 | for (unsigned row = 0; row < m_grid.size(); ++row) |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 1191 | m_grid[row].row.resize(pos + 1); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
jchaffraix@webkit.org | 369c5d3 | 2011-10-28 01:28:58 +0000 | [diff] [blame] | 1194 | void RenderTableSection::splitColumn(unsigned pos, int first) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1195 | { |
inferno@chromium.org | b1ffad7 | 2011-10-10 18:58:12 +0000 | [diff] [blame] | 1196 | ASSERT(!m_needsCellRecalc); |
| 1197 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1198 | if (m_cCol > pos) |
| 1199 | m_cCol++; |
jchaffraix@webkit.org | 68d3b57 | 2011-10-27 19:12:39 +0000 | [diff] [blame] | 1200 | for (unsigned row = 0; row < m_grid.size(); ++row) { |
jchaffraix@webkit.org | 9fb8075 | 2011-10-28 18:04:14 +0000 | [diff] [blame] | 1201 | Row& r = m_grid[row].row; |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 1202 | r.insert(pos + 1, CellStruct()); |
| 1203 | if (r[pos].hasCells()) { |
| 1204 | r[pos + 1].cells.append(r[pos].cells); |
| 1205 | RenderTableCell* cell = r[pos].primaryCell(); |
| 1206 | ASSERT(cell); |
| 1207 | int colleft = cell->colSpan() - r[pos].inColSpan; |
| 1208 | if (first > colleft) |
| 1209 | r[pos + 1].inColSpan = 0; |
| 1210 | else |
| 1211 | r[pos + 1].inColSpan = first + r[pos].inColSpan; |
| 1212 | } else { |
| 1213 | r[pos + 1].inColSpan = 0; |
| 1214 | } |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1218 | // Hit Testing |
eae@chromium.org | e14cd1a | 2011-07-06 23:38:32 +0000 | [diff] [blame] | 1219 | bool RenderTableSection::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action) |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1220 | { |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1221 | // If we have no children then we have nothing to do. |
| 1222 | if (!firstChild()) |
| 1223 | return false; |
| 1224 | |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1225 | // Table sections cannot ever be hit tested. Effectively they do not exist. |
| 1226 | // Just forward to our children always. |
eae@chromium.org | e14cd1a | 2011-07-06 23:38:32 +0000 | [diff] [blame] | 1227 | LayoutPoint adjustedLocation = accumulatedOffset + location(); |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1228 | |
hyatt@apple.com | d4d3bcf | 2011-10-04 18:17:04 +0000 | [diff] [blame] | 1229 | if (hasOverflowClip() && !overflowClipRect(adjustedLocation, result.region()).intersects(result.rectForPoint(pointInContainer))) |
hyatt@apple.com | fe52f5b | 2009-02-25 01:21:03 +0000 | [diff] [blame] | 1230 | return false; |
| 1231 | |
jchaffraix@webkit.org | f4ce050 | 2011-08-18 20:20:57 +0000 | [diff] [blame] | 1232 | if (hasOverflowingCell()) { |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1233 | for (RenderObject* child = lastChild(); child; child = child->previousSibling()) { |
| 1234 | // FIXME: We have to skip over inline flows, since they can show up inside table rows |
| 1235 | // at the moment (a demoted inline <form> for example). If we ever implement a |
| 1236 | // table-specific hit-test method (which we should do for performance reasons anyway), |
| 1237 | // then we can remove this check. |
mitz@apple.com | 39fb3ae | 2010-11-09 20:46:15 +0000 | [diff] [blame] | 1238 | if (child->isBox() && !toRenderBox(child)->hasSelfPaintingLayer()) { |
ojan@chromium.org | 035c88ca | 2011-10-03 22:00:25 +0000 | [diff] [blame] | 1239 | LayoutPoint childPoint = flipForWritingModeForChild(toRenderBox(child), adjustedLocation); |
eae@chromium.org | f9ce267 | 2011-06-08 03:12:08 +0000 | [diff] [blame] | 1240 | if (child->nodeAtPoint(request, result, pointInContainer, childPoint, action)) { |
eae@chromium.org | e14cd1a | 2011-07-06 23:38:32 +0000 | [diff] [blame] | 1241 | updateHitTestResult(result, toLayoutPoint(pointInContainer - childPoint)); |
mitz@apple.com | 39fb3ae | 2010-11-09 20:46:15 +0000 | [diff] [blame] | 1242 | return true; |
| 1243 | } |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1244 | } |
| 1245 | } |
| 1246 | return false; |
| 1247 | } |
| 1248 | |
eae@chromium.org | e14cd1a | 2011-07-06 23:38:32 +0000 | [diff] [blame] | 1249 | LayoutPoint location = pointInContainer - toLayoutSize(adjustedLocation); |
mitz@apple.com | 39fb3ae | 2010-11-09 20:46:15 +0000 | [diff] [blame] | 1250 | if (style()->isFlippedBlocksWritingMode()) { |
| 1251 | if (style()->isHorizontalWritingMode()) |
| 1252 | location.setY(height() - location.y()); |
| 1253 | else |
| 1254 | location.setX(width() - location.x()); |
| 1255 | } |
| 1256 | |
eae@chromium.org | e14cd1a | 2011-07-06 23:38:32 +0000 | [diff] [blame] | 1257 | LayoutUnit offsetInColumnDirection = style()->isHorizontalWritingMode() ? location.y() : location.x(); |
mitz@apple.com | 39fb3ae | 2010-11-09 20:46:15 +0000 | [diff] [blame] | 1258 | // Find the first row that starts after offsetInColumnDirection. |
| 1259 | unsigned nextRow = std::upper_bound(m_rowPos.begin(), m_rowPos.end(), offsetInColumnDirection) - m_rowPos.begin(); |
| 1260 | if (nextRow == m_rowPos.size()) |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1261 | return false; |
mitz@apple.com | 39fb3ae | 2010-11-09 20:46:15 +0000 | [diff] [blame] | 1262 | // Now set hitRow to the index of the hit row, or 0. |
| 1263 | unsigned hitRow = nextRow > 0 ? nextRow - 1 : 0; |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1264 | |
eae@chromium.org | e14cd1a | 2011-07-06 23:38:32 +0000 | [diff] [blame] | 1265 | Vector<LayoutUnit>& columnPos = table()->columnPositions(); |
leviw@chromium.org | 7353dfd | 2011-08-12 21:01:45 +0000 | [diff] [blame] | 1266 | LayoutUnit offsetInRowDirection = style()->isHorizontalWritingMode() ? location.x() : location.y(); |
mitz@apple.com | 39fb3ae | 2010-11-09 20:46:15 +0000 | [diff] [blame] | 1267 | if (!style()->isLeftToRightDirection()) |
| 1268 | offsetInRowDirection = columnPos[columnPos.size() - 1] - offsetInRowDirection; |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1269 | |
mitz@apple.com | 39fb3ae | 2010-11-09 20:46:15 +0000 | [diff] [blame] | 1270 | unsigned nextColumn = std::lower_bound(columnPos.begin(), columnPos.end(), offsetInRowDirection) - columnPos.begin(); |
| 1271 | if (nextColumn == columnPos.size()) |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1272 | return false; |
mitz@apple.com | 39fb3ae | 2010-11-09 20:46:15 +0000 | [diff] [blame] | 1273 | unsigned hitColumn = nextColumn > 0 ? nextColumn - 1 : 0; |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1274 | |
mitz@apple.com | 39fb3ae | 2010-11-09 20:46:15 +0000 | [diff] [blame] | 1275 | CellStruct& current = cellAt(hitRow, hitColumn); |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1276 | |
| 1277 | // If the cell is empty, there's nothing to do |
| 1278 | if (!current.hasCells()) |
| 1279 | return false; |
| 1280 | |
| 1281 | for (int i = current.cells.size() - 1; i >= 0; --i) { |
| 1282 | RenderTableCell* cell = current.cells[i]; |
ojan@chromium.org | 035c88ca | 2011-10-03 22:00:25 +0000 | [diff] [blame] | 1283 | LayoutPoint cellPoint = flipForWritingModeForChild(cell, adjustedLocation); |
eae@chromium.org | f9ce267 | 2011-06-08 03:12:08 +0000 | [diff] [blame] | 1284 | if (static_cast<RenderObject*>(cell)->nodeAtPoint(request, result, pointInContainer, cellPoint, action)) { |
eae@chromium.org | e14cd1a | 2011-07-06 23:38:32 +0000 | [diff] [blame] | 1285 | updateHitTestResult(result, toLayoutPoint(pointInContainer - cellPoint)); |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1286 | return true; |
| 1287 | } |
| 1288 | } |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1289 | return false; |
jamesr@google.com | f88b258 | 2010-08-17 20:57:15 +0000 | [diff] [blame] | 1290 | |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
jchaffraix@webkit.org | 19bbb72 | 2011-11-03 17:20:01 +0000 | [diff] [blame] | 1293 | unsigned RenderTableSection::rowIndexForRenderer(const RenderTableRow* row) const |
| 1294 | { |
| 1295 | for (size_t i = 0; i < m_grid.size(); ++i) { |
| 1296 | if (m_grid[i].rowRenderer == row) |
| 1297 | return i; |
| 1298 | } |
| 1299 | ASSERT_NOT_REACHED(); |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1303 | } // namespace WebCore |