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