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