eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1 | /** |
| 2 | * This file is part of the DOM implementation for KDE. |
| 3 | * |
| 4 | * Copyright (C) 1997 Martin Jones (mjones@kde.org) |
| 5 | * (C) 1997 Torben Weis (weis@kde.org) |
| 6 | * (C) 1998 Waldo Bastian (bastian@kde.org) |
| 7 | * (C) 1999 Lars Knoll (knoll@kde.org) |
| 8 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 9 | * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 10 | * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 11 | * |
| 12 | * This library is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU Library General Public |
| 14 | * License as published by the Free Software Foundation; either |
| 15 | * version 2 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This library is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * Library General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Library General Public License |
| 23 | * along with this library; see the file COPYING.LIB. If not, write to |
| 24 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 25 | * Boston, MA 02111-1307, USA. |
| 26 | */ |
| 27 | |
| 28 | #include "config.h" |
| 29 | #include "RenderTableSection.h" |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 30 | |
bdash | b07ae8d | 2007-02-08 04:56:20 +0000 | [diff] [blame] | 31 | #include "CachedImage.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 32 | #include "Document.h" |
darin | 98fa8b8 | 2006-03-20 08:03:57 +0000 | [diff] [blame] | 33 | #include "HTMLNames.h" |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 34 | #include "RenderTableCell.h" |
| 35 | #include "RenderTableCol.h" |
| 36 | #include "RenderTableRow.h" |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 37 | #include "RenderView.h" |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 38 | #include "TextStream.h" |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 39 | #include <limits> |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 40 | #include <wtf/Vector.h> |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 41 | |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 42 | using namespace std; |
| 43 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 44 | namespace WebCore { |
| 45 | |
| 46 | using namespace HTMLNames; |
| 47 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 48 | RenderTableSection::RenderTableSection(Node* node) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 49 | : RenderContainer(node) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 50 | , m_gridRows(0) |
| 51 | , m_cCol(0) |
| 52 | , m_cRow(-1) |
| 53 | , m_needsCellRecalc(false) |
| 54 | , m_outerBorderLeft(0) |
| 55 | , m_outerBorderRight(0) |
| 56 | , m_outerBorderTop(0) |
| 57 | , m_outerBorderBottom(0) |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 58 | , m_overflowLeft(0) |
| 59 | , m_overflowWidth(0) |
ap | 292f4df | 2007-02-18 16:15:07 +0000 | [diff] [blame] | 60 | , m_overflowTop(0) |
| 61 | , m_overflowHeight(0) |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 62 | , m_hasOverflowingCell(false) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 63 | { |
| 64 | // init RenderObject attributes |
| 65 | setInline(false); // our object is not Inline |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | RenderTableSection::~RenderTableSection() |
| 69 | { |
| 70 | clearGrid(); |
| 71 | } |
| 72 | |
| 73 | void RenderTableSection::destroy() |
| 74 | { |
antti | 078e87f | 2007-08-16 16:13:28 +0000 | [diff] [blame] | 75 | RenderTable* recalcTable = table(); |
| 76 | |
| 77 | RenderContainer::destroy(); |
| 78 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 79 | // recalc cell info because RenderTable has unguarded pointers |
| 80 | // stored that point to this RenderTableSection. |
antti | 078e87f | 2007-08-16 16:13:28 +0000 | [diff] [blame] | 81 | if (recalcTable) |
| 82 | recalcTable->setNeedsSectionRecalc(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 83 | } |
| 84 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 85 | void RenderTableSection::setStyle(RenderStyle* newStyle) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 86 | { |
| 87 | // we don't allow changing this one |
| 88 | if (style()) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 89 | newStyle->setDisplay(style()->display()); |
| 90 | else if (newStyle->display() != TABLE_FOOTER_GROUP && newStyle->display() != TABLE_HEADER_GROUP) |
| 91 | newStyle->setDisplay(TABLE_ROW_GROUP); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 92 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 93 | RenderContainer::setStyle(newStyle); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 94 | } |
| 95 | |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 96 | void RenderTableSection::addChild(RenderObject* child, RenderObject* beforeChild) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 97 | { |
hyatt | 58028f5 | 2007-05-01 04:57:01 +0000 | [diff] [blame] | 98 | // Make sure we don't append things after :after-generated content if we have it. |
| 99 | if (!beforeChild && isAfterContent(lastChild())) |
| 100 | beforeChild = lastChild(); |
| 101 | |
bdakin | 8a0dd6b | 2006-02-11 02:08:57 +0000 | [diff] [blame] | 102 | bool isTableSection = element() && (element()->hasTagName(theadTag) || element()->hasTagName(tbodyTag) || element()->hasTagName(tfootTag)); |
| 103 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 104 | if (!child->isTableRow()) { |
mjs | 6666eee7 | 2006-07-14 07:45:13 +0000 | [diff] [blame] | 105 | if (isTableSection && child->element() && child->element()->hasTagName(formTag) && document()->isHTMLDocument()) { |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 106 | RenderContainer::addChild(child, beforeChild); |
| 107 | return; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 108 | } |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 109 | |
| 110 | RenderObject* last = beforeChild; |
| 111 | if (!last) |
| 112 | last = lastChild(); |
| 113 | if (last && last->isAnonymous()) { |
| 114 | last->addChild(child); |
| 115 | return; |
| 116 | } |
| 117 | |
darin | 10ab135 | 2006-01-29 01:29:33 +0000 | [diff] [blame] | 118 | // If beforeChild is inside an anonymous cell/row, insert into the cell or into |
| 119 | // the anonymous row containing it, if there is one. |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 120 | RenderObject* lastBox = last; |
| 121 | while (lastBox && lastBox->parent()->isAnonymous() && !lastBox->isTableRow()) |
| 122 | lastBox = lastBox->parent(); |
| 123 | if (lastBox && lastBox->isAnonymous()) { |
| 124 | lastBox->addChild(child, beforeChild); |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | RenderObject* row = new (renderArena()) RenderTableRow(document() /* anonymous table */); |
| 129 | RenderStyle* newStyle = new (renderArena()) RenderStyle(); |
| 130 | newStyle->inheritFrom(style()); |
| 131 | newStyle->setDisplay(TABLE_ROW); |
| 132 | row->setStyle(newStyle); |
| 133 | addChild(row, beforeChild); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 134 | row->addChild(child); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 135 | return; |
| 136 | } |
| 137 | |
| 138 | if (beforeChild) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 139 | setNeedsCellRecalc(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 140 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 141 | ++m_cRow; |
| 142 | m_cCol = 0; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 143 | |
lars | b5288ad | 2007-01-13 18:48:29 +0000 | [diff] [blame] | 144 | // make sure we have enough rows |
| 145 | if (!ensureRows(m_cRow + 1)) |
| 146 | return; |
| 147 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 148 | m_grid[m_cRow].rowRenderer = child; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 149 | |
| 150 | if (!beforeChild) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 151 | m_grid[m_cRow].height = child->style()->height(); |
| 152 | if (m_grid[m_cRow].height.isRelative()) |
| 153 | m_grid[m_cRow].height = Length(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 154 | } |
| 155 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 156 | // If the next renderer is actually wrapped in an anonymous table row, we need to go up and find that. |
mjs | 6666eee7 | 2006-07-14 07:45:13 +0000 | [diff] [blame] | 157 | while (beforeChild && !beforeChild->isTableRow()) |
| 158 | beforeChild = beforeChild->parent(); |
| 159 | |
darin | 316ed06 | 2006-01-23 05:29:14 +0000 | [diff] [blame] | 160 | RenderContainer::addChild(child, beforeChild); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | bool RenderTableSection::ensureRows(int numRows) |
| 164 | { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 165 | int nRows = m_gridRows; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 166 | if (numRows > nRows) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 167 | if (numRows > static_cast<int>(m_grid.size())) { |
lars | b5288ad | 2007-01-13 18:48:29 +0000 | [diff] [blame] | 168 | size_t maxSize = numeric_limits<size_t>::max() / sizeof(RowStruct); |
| 169 | if (static_cast<size_t>(numRows) > maxSize) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 170 | return false; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 171 | m_grid.resize(numRows); |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 172 | } |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 173 | m_gridRows = numRows; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 174 | int nCols = table()->numEffCols(); |
| 175 | CellStruct emptyCellStruct; |
| 176 | emptyCellStruct.cell = 0; |
| 177 | emptyCellStruct.inColSpan = false; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 178 | for (int r = nRows; r < numRows; r++) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 179 | m_grid[r].row = new Row(nCols); |
| 180 | m_grid[r].row->fill(emptyCellStruct); |
| 181 | m_grid[r].rowRenderer = 0; |
hyatt | 851433b | 2007-05-12 06:40:14 +0000 | [diff] [blame] | 182 | m_grid[r].baseline = 0; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 183 | m_grid[r].height = Length(); |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 184 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | return true; |
| 188 | } |
| 189 | |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 190 | void RenderTableSection::addCell(RenderTableCell* cell, RenderObject* row) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 191 | { |
| 192 | int rSpan = cell->rowSpan(); |
| 193 | int cSpan = cell->colSpan(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 194 | Vector<RenderTable::ColumnStruct>& columns = table()->columns(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 195 | int nCols = columns.size(); |
| 196 | |
| 197 | // ### mozilla still seems to do the old HTML way, even for strict DTD |
| 198 | // (see the annotation on table cell layouting in the CSS specs and the testcase below: |
| 199 | // <TABLE border> |
| 200 | // <TR><TD>1 <TD rowspan="2">2 <TD>3 <TD>4 |
| 201 | // <TR><TD colspan="2">5 |
| 202 | // </TABLE> |
| 203 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 204 | while (m_cCol < nCols && (cellAt(m_cRow, m_cCol).cell || cellAt(m_cRow, m_cCol).inColSpan)) |
| 205 | m_cCol++; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 206 | |
| 207 | if (rSpan == 1) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 208 | // we ignore height settings on rowspan cells |
| 209 | Length height = cell->style()->height(); |
ddkilzer | d1687ca | 2007-01-04 05:28:35 +0000 | [diff] [blame] | 210 | if (height.isPositive() || (height.isRelative() && height.value() >= 0)) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 211 | Length cRowHeight = m_grid[m_cRow].height; |
darin | 947a31b | 2006-02-24 03:08:41 +0000 | [diff] [blame] | 212 | switch (height.type()) { |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 213 | case Percent: |
darin | 947a31b | 2006-02-24 03:08:41 +0000 | [diff] [blame] | 214 | if (!(cRowHeight.isPercent()) || |
ddkilzer | d1687ca | 2007-01-04 05:28:35 +0000 | [diff] [blame] | 215 | (cRowHeight.isPercent() && cRowHeight.rawValue() < height.rawValue())) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 216 | m_grid[m_cRow].height = height; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 217 | break; |
| 218 | case Fixed: |
darin | 947a31b | 2006-02-24 03:08:41 +0000 | [diff] [blame] | 219 | if (cRowHeight.type() < Percent || |
| 220 | (cRowHeight.isFixed() && cRowHeight.value() < height.value())) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 221 | m_grid[m_cRow].height = height; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 222 | break; |
| 223 | case Relative: |
| 224 | default: |
| 225 | break; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 226 | } |
| 227 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | // make sure we have enough rows |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 231 | if (!ensureRows(m_cRow + rSpan)) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 232 | return; |
| 233 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 234 | m_grid[m_cRow].rowRenderer = row; |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 235 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 236 | int col = m_cCol; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 237 | // tell the cell where it is |
| 238 | CellStruct currentCell; |
| 239 | currentCell.cell = cell; |
| 240 | currentCell.inColSpan = false; |
| 241 | while (cSpan) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 242 | int currentSpan; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 243 | if (m_cCol >= nCols) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 244 | table()->appendColumn(cSpan); |
| 245 | currentSpan = cSpan; |
| 246 | } else { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 247 | if (cSpan < columns[m_cCol].span) |
| 248 | table()->splitColumn(m_cCol, cSpan); |
| 249 | currentSpan = columns[m_cCol].span; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 250 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 251 | |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 252 | for (int r = 0; r < rSpan; r++) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 253 | CellStruct& c = cellAt(m_cRow + r, m_cCol); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 254 | if (currentCell.cell && !c.cell) |
| 255 | c.cell = currentCell.cell; |
| 256 | if (currentCell.inColSpan) |
| 257 | c.inColSpan = true; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 258 | } |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 259 | m_cCol++; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 260 | cSpan -= currentSpan; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 261 | currentCell.cell = 0; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 262 | currentCell.inColSpan = true; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 263 | } |
| 264 | if (cell) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 265 | cell->setRow(m_cRow); |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 266 | cell->setCol(table()->effColToCol(col)); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 270 | void RenderTableSection::setCellWidths() |
| 271 | { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 272 | Vector<int>& columnPos = table()->columnPositions(); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 273 | bool pushedLayoutState = false; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 274 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 275 | for (int i = 0; i < m_gridRows; i++) { |
| 276 | Row& row = *m_grid[i].row; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 277 | int cols = row.size(); |
| 278 | for (int j = 0; j < cols; j++) { |
| 279 | CellStruct current = row[j]; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 280 | RenderTableCell* cell = current.cell; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 281 | |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 282 | if (!cell) |
| 283 | continue; |
| 284 | int endCol = j; |
| 285 | int cspan = cell->colSpan(); |
| 286 | while (cspan && endCol < cols) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 287 | cspan -= table()->columns()[endCol].span; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 288 | endCol++; |
| 289 | } |
| 290 | int w = columnPos[endCol] - columnPos[j] - table()->hBorderSpacing(); |
| 291 | int oldWidth = cell->width(); |
| 292 | if (w != oldWidth) { |
| 293 | cell->setNeedsLayout(true); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 294 | if (!table()->selfNeedsLayout() && cell->checkForRepaintDuringLayout()) { |
| 295 | if (!pushedLayoutState) { |
| 296 | // Technically, we should also push state for the row, but since |
| 297 | // rows don't push a coordinate transform, that's not necessary. |
| 298 | view()->pushLayoutState(this, IntSize(m_x, m_y)); |
| 299 | pushedLayoutState = true; |
| 300 | } |
hyatt | d72625b | 2007-04-26 19:51:11 +0000 | [diff] [blame] | 301 | cell->repaint(); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 302 | } |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 303 | cell->setWidth(w); |
| 304 | } |
| 305 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 306 | } |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 307 | |
| 308 | if (pushedLayoutState) |
| 309 | view()->popLayoutState(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 310 | } |
| 311 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 312 | void RenderTableSection::calcRowHeight() |
| 313 | { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 314 | RenderTableCell* cell; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 315 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 316 | int spacing = table()->vBorderSpacing(); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 317 | bool pushedLayoutState = false; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 318 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 319 | m_rowPos.resize(m_gridRows + 1); |
| 320 | m_rowPos[0] = spacing; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 321 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 322 | for (int r = 0; r < m_gridRows; r++) { |
| 323 | m_rowPos[r + 1] = 0; |
hyatt | 777b31c | 2007-07-19 20:01:26 +0000 | [diff] [blame] | 324 | m_grid[r].baseline = 0; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 325 | int baseline = 0; |
| 326 | int bdesc = 0; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 327 | int ch = m_grid[r].height.calcMinValue(0); |
| 328 | int pos = m_rowPos[r] + ch + (m_grid[r].rowRenderer ? spacing : 0); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 329 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 330 | m_rowPos[r + 1] = max(m_rowPos[r + 1], pos); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 331 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 332 | Row* row = m_grid[r].row; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 333 | int totalCols = row->size(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 334 | |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 335 | for (int c = 0; c < totalCols; c++) { |
| 336 | CellStruct current = cellAt(r, c); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 337 | cell = current.cell; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 338 | if (!cell || current.inColSpan) |
| 339 | continue; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 340 | if (r < m_gridRows - 1 && cellAt(r + 1, c).cell == cell) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 341 | continue; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 342 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 343 | int indx = max(r - cell->rowSpan() + 1, 0); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 344 | |
| 345 | if (cell->overrideSize() != -1) { |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 346 | if (!pushedLayoutState) { |
| 347 | // Technically, we should also push state for the row, but since |
| 348 | // rows don't push a coordinate transform, that's not necessary. |
| 349 | view()->pushLayoutState(this, IntSize(m_x, m_y)); |
| 350 | pushedLayoutState = true; |
| 351 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 352 | cell->setOverrideSize(-1); |
| 353 | cell->setChildNeedsLayout(true, false); |
| 354 | cell->layoutIfNeeded(); |
| 355 | } |
| 356 | |
| 357 | // Explicit heights use the border box in quirks mode. In strict mode do the right |
| 358 | // thing and actually add in the border and padding. |
darin | 947a31b | 2006-02-24 03:08:41 +0000 | [diff] [blame] | 359 | ch = cell->style()->height().calcValue(0) + |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 360 | (cell->style()->htmlHacks() ? 0 : (cell->paddingTop() + cell->paddingBottom() + |
| 361 | cell->borderTop() + cell->borderBottom())); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 362 | ch = max(ch, cell->height()); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 363 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 364 | pos = m_rowPos[indx] + ch + (m_grid[r].rowRenderer ? spacing : 0); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 365 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 366 | m_rowPos[r + 1] = max(m_rowPos[r + 1], pos); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 367 | |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 368 | // find out the baseline |
| 369 | EVerticalAlign va = cell->style()->verticalAlign(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 370 | if (va == BASELINE || va == TEXT_BOTTOM || va == TEXT_TOP || va == SUPER || va == SUB) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 371 | int b = cell->baselinePosition(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 372 | if (b > cell->borderTop() + cell->paddingTop()) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 373 | baseline = max(baseline, b); |
| 374 | bdesc = max(bdesc, m_rowPos[indx] + ch - b); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 375 | } |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 376 | } |
| 377 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 378 | |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 379 | //do we have baseline aligned elements? |
| 380 | if (baseline) { |
| 381 | // increase rowheight if baseline requires |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 382 | 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] | 383 | m_grid[r].baseline = baseline; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 384 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 385 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 386 | m_rowPos[r + 1] = max(m_rowPos[r + 1], m_rowPos[r]); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 387 | } |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 388 | |
| 389 | if (pushedLayoutState) |
| 390 | view()->popLayoutState(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | int RenderTableSection::layoutRows(int toAdd) |
| 394 | { |
| 395 | int rHeight; |
| 396 | int rindx; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 397 | int totalRows = m_gridRows; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 398 | |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 399 | // Set the width of our section now. The rows will also be this width. |
| 400 | m_width = table()->contentWidth(); |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 401 | m_overflowLeft = 0; |
| 402 | m_overflowWidth = m_width; |
ap | 292f4df | 2007-02-18 16:15:07 +0000 | [diff] [blame] | 403 | m_overflowTop = 0; |
| 404 | m_overflowHeight = 0; |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 405 | m_hasOverflowingCell = false; |
| 406 | |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 407 | if (table()->collapseBorders()) |
| 408 | recalcOuterBorder(); |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 409 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 410 | if (toAdd && totalRows && (m_rowPos[totalRows] || !nextSibling())) { |
| 411 | int totalHeight = m_rowPos[totalRows] + toAdd; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 412 | |
| 413 | int dh = toAdd; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 414 | int totalPercent = 0; |
| 415 | int numAuto = 0; |
| 416 | for (int r = 0; r < totalRows; r++) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 417 | if (m_grid[r].height.isAuto()) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 418 | numAuto++; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 419 | else if (m_grid[r].height.isPercent()) |
| 420 | totalPercent += m_grid[r].height.rawValue(); |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 421 | } |
| 422 | if (totalPercent) { |
| 423 | // try to satisfy percent |
| 424 | int add = 0; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 425 | totalPercent = min(totalPercent, 100 * percentScaleFactor); |
| 426 | int rh = m_rowPos[1] - m_rowPos[0]; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 427 | for (int r = 0; r < totalRows; r++) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 428 | if (totalPercent > 0 && m_grid[r].height.isPercent()) { |
| 429 | int toAdd = min(dh, (totalHeight * m_grid[r].height.rawValue() / (100 * percentScaleFactor)) - rh); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 430 | // If toAdd is negative, then we don't want to shrink the row (this bug |
| 431 | // affected Outlook Web Access). |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 432 | toAdd = max(0, toAdd); |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 433 | add += toAdd; |
| 434 | dh -= toAdd; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 435 | totalPercent -= m_grid[r].height.rawValue(); |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 436 | } |
| 437 | if (r < totalRows - 1) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 438 | rh = m_rowPos[r + 2] - m_rowPos[r + 1]; |
| 439 | m_rowPos[r + 1] += add; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | if (numAuto) { |
| 443 | // distribute over variable cols |
| 444 | int add = 0; |
| 445 | for (int r = 0; r < totalRows; r++) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 446 | if (numAuto > 0 && m_grid[r].height.isAuto()) { |
| 447 | int toAdd = dh / numAuto; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 448 | add += toAdd; |
| 449 | dh -= toAdd; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 450 | numAuto--; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 451 | } |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 452 | m_rowPos[r + 1] += add; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 453 | } |
| 454 | } |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 455 | if (dh > 0 && m_rowPos[totalRows]) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 456 | // if some left overs, distribute equally. |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 457 | int tot = m_rowPos[totalRows]; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 458 | int add = 0; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 459 | int prev = m_rowPos[0]; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 460 | for (int r = 0; r < totalRows; r++) { |
| 461 | //weight with the original height |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 462 | add += dh * (m_rowPos[r + 1] - prev) / tot; |
| 463 | prev = m_rowPos[r + 1]; |
| 464 | m_rowPos[r + 1] += add; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | } |
| 468 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 469 | int hspacing = table()->hBorderSpacing(); |
| 470 | int vspacing = table()->vBorderSpacing(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 471 | int nEffCols = table()->numEffCols(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 472 | |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 473 | view()->pushLayoutState(this, IntSize(m_x, m_y)); |
| 474 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 475 | for (int r = 0; r < totalRows; r++) { |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 476 | // Set the row's x/y position and width/height. |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 477 | if (RenderObject* rowRenderer = m_grid[r].rowRenderer) { |
| 478 | rowRenderer->setPos(0, m_rowPos[r]); |
| 479 | rowRenderer->setWidth(m_width); |
| 480 | rowRenderer->setHeight(m_rowPos[r + 1] - m_rowPos[r] - vspacing); |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 481 | } |
| 482 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 483 | for (int c = 0; c < nEffCols; c++) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 484 | RenderTableCell* cell = cellAt(r, c).cell; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 485 | |
| 486 | if (!cell) |
| 487 | continue; |
| 488 | if (r < totalRows - 1 && cell == cellAt(r + 1, c).cell) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 489 | continue; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 490 | |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 491 | rindx = max(0, r - cell->rowSpan() + 1); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 492 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 493 | rHeight = m_rowPos[r + 1] - m_rowPos[rindx] - vspacing; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 494 | |
| 495 | // Force percent height children to lay themselves out again. |
| 496 | // This will cause these children to grow to fill the cell. |
| 497 | // FIXME: There is still more work to do here to fully match WinIE (should |
| 498 | // it become necessary to do so). In quirks mode, WinIE behaves like we |
| 499 | // do, but it will clip the cells that spill out of the table section. In |
| 500 | // strict mode, Mozilla and WinIE both regrow the table to accommodate the |
| 501 | // new height of the cell (thus letting the percentages cause growth one |
| 502 | // time only). We may also not be handling row-spanning cells correctly. |
| 503 | // |
| 504 | // Note also the oddity where replaced elements always flex, and yet blocks/tables do |
| 505 | // not necessarily flex. WinIE is crazy and inconsistent, and we can't hope to |
| 506 | // match the behavior perfectly, but we'll continue to refine it as we discover new |
| 507 | // bugs. :) |
| 508 | bool cellChildrenFlex = false; |
| 509 | bool flexAllChildren = cell->style()->height().isFixed() || |
| 510 | (!table()->style()->height().isAuto() && rHeight != cell->height()); |
| 511 | |
| 512 | for (RenderObject* o = cell->firstChild(); o; o = o->nextSibling()) { |
| 513 | if (!o->isText() && o->style()->height().isPercent() && (o->isReplaced() || o->scrollsOverflow() || flexAllChildren)) { |
| 514 | // Tables with no sections do not flex. |
| 515 | if (!o->isTable() || static_cast<RenderTable*>(o)->hasSections()) { |
| 516 | o->setNeedsLayout(true, false); |
| 517 | cell->setChildNeedsLayout(true, false); |
| 518 | cellChildrenFlex = true; |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | if (cellChildrenFlex) { |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 523 | // Alignment within a cell is based off the calculated |
| 524 | // height, which becomes irrelevant once the cell has |
| 525 | // been resized based off its percentage. -dwh |
ap | 7332aaa | 2006-04-28 16:02:45 +0000 | [diff] [blame] | 526 | cell->setOverrideSize(max(0, |
| 527 | rHeight - cell->borderTop() - cell->paddingTop() - |
| 528 | cell->borderBottom() - cell->paddingBottom())); |
| 529 | cell->layoutIfNeeded(); |
hyatt | 851433b | 2007-05-12 06:40:14 +0000 | [diff] [blame] | 530 | |
| 531 | // If the baseline moved, we may have to update the data for our row. Find out the new baseline. |
| 532 | EVerticalAlign va = cell->style()->verticalAlign(); |
| 533 | if (va == BASELINE || va == TEXT_BOTTOM || va == TEXT_TOP || va == SUPER || va == SUB) { |
| 534 | int b = cell->baselinePosition(); |
| 535 | if (b > cell->borderTop() + cell->paddingTop()) |
| 536 | m_grid[r].baseline = max(m_grid[r].baseline, b); |
| 537 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 538 | } |
| 539 | |
bdakin | f993635 | 2007-04-19 19:58:20 +0000 | [diff] [blame] | 540 | int te = 0; |
| 541 | switch (cell->style()->verticalAlign()) { |
| 542 | case SUB: |
| 543 | case SUPER: |
| 544 | case TEXT_TOP: |
| 545 | case TEXT_BOTTOM: |
| 546 | case BASELINE: |
hyatt | 851433b | 2007-05-12 06:40:14 +0000 | [diff] [blame] | 547 | te = getBaseline(r) - cell->baselinePosition(); |
bdakin | f993635 | 2007-04-19 19:58:20 +0000 | [diff] [blame] | 548 | break; |
| 549 | case TOP: |
| 550 | te = 0; |
| 551 | break; |
| 552 | case MIDDLE: |
| 553 | te = (rHeight - cell->height()) / 2; |
| 554 | break; |
| 555 | case BOTTOM: |
| 556 | te = rHeight - cell->height(); |
| 557 | break; |
| 558 | default: |
| 559 | break; |
| 560 | } |
| 561 | |
| 562 | int oldTe = cell->borderTopExtra(); |
| 563 | int oldBe = cell->borderBottomExtra(); |
| 564 | |
| 565 | int be = rHeight - cell->height() - te; |
| 566 | cell->setCellTopExtra(te); |
| 567 | cell->setCellBottomExtra(be); |
| 568 | if ((te != oldTe || be > oldBe) && !table()->selfNeedsLayout() && cell->checkForRepaintDuringLayout()) |
| 569 | cell->repaint(); |
| 570 | |
harrison | b100b8e | 2006-11-17 01:06:58 +0000 | [diff] [blame] | 571 | IntRect oldCellRect(cell->xPos(), cell->yPos() - cell->borderTopExtra() , cell->width(), cell->height()); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 572 | |
| 573 | if (style()->direction() == RTL) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 574 | cell->setPos(table()->columnPositions()[nEffCols] - table()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + hspacing, m_rowPos[rindx]); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 575 | } else |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 576 | cell->setPos(table()->columnPositions()[c] + hspacing, m_rowPos[rindx]); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 577 | |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 578 | m_overflowLeft = min(m_overflowLeft, cell->xPos() + cell->overflowLeft(false)); |
| 579 | m_overflowWidth = max(m_overflowWidth, cell->xPos() + cell->overflowWidth(false)); |
ap | 292f4df | 2007-02-18 16:15:07 +0000 | [diff] [blame] | 580 | m_overflowTop = min(m_overflowTop, cell->yPos() + cell->overflowTop(false)); |
| 581 | m_overflowHeight = max(m_overflowHeight, cell->yPos() + cell->overflowHeight(false)); |
| 582 | m_hasOverflowingCell |= cell->overflowLeft(false) || cell->overflowWidth(false) > cell->width() || cell->overflowTop(false) || cell->overflowHeight(false) > cell->height(); |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 583 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 584 | // If the cell moved, we have to repaint it as well as any floating/positioned |
| 585 | // descendants. An exception is if we need a layout. In this case, we know we're going to |
| 586 | // repaint ourselves (and the cell) anyway. |
| 587 | if (!table()->selfNeedsLayout() && cell->checkForRepaintDuringLayout()) |
harrison | b100b8e | 2006-11-17 01:06:58 +0000 | [diff] [blame] | 588 | cell->repaintDuringLayoutIfMoved(oldCellRect); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 592 | view()->popLayoutState(); |
| 593 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 594 | m_height = m_rowPos[totalRows]; |
ap | 292f4df | 2007-02-18 16:15:07 +0000 | [diff] [blame] | 595 | m_overflowHeight = max(m_overflowHeight, m_height); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 596 | return m_height; |
| 597 | } |
| 598 | |
adele | 04d4ce1 | 2006-02-11 20:11:05 +0000 | [diff] [blame] | 599 | int RenderTableSection::lowestPosition(bool includeOverflowInterior, bool includeSelf) const |
| 600 | { |
| 601 | int bottom = RenderContainer::lowestPosition(includeOverflowInterior, includeSelf); |
| 602 | if (!includeOverflowInterior && hasOverflowClip()) |
| 603 | return bottom; |
| 604 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 605 | for (RenderObject* row = firstChild(); row; row = row->nextSibling()) { |
| 606 | for (RenderObject* cell = row->firstChild(); cell; cell = cell->nextSibling()) { |
| 607 | if (cell->isTableCell()) |
| 608 | bottom = max(bottom, cell->yPos() + cell->lowestPosition(false)); |
adele | 04d4ce1 | 2006-02-11 20:11:05 +0000 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
| 612 | return bottom; |
| 613 | } |
| 614 | |
| 615 | int RenderTableSection::rightmostPosition(bool includeOverflowInterior, bool includeSelf) const |
| 616 | { |
| 617 | int right = RenderContainer::rightmostPosition(includeOverflowInterior, includeSelf); |
| 618 | if (!includeOverflowInterior && hasOverflowClip()) |
| 619 | return right; |
| 620 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 621 | for (RenderObject* row = firstChild(); row; row = row->nextSibling()) { |
| 622 | for (RenderObject* cell = row->firstChild(); cell; cell = cell->nextSibling()) { |
| 623 | if (cell->isTableCell()) |
| 624 | right = max(right, cell->xPos() + cell->rightmostPosition(false)); |
adele | 04d4ce1 | 2006-02-11 20:11:05 +0000 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
| 628 | return right; |
| 629 | } |
| 630 | |
| 631 | int RenderTableSection::leftmostPosition(bool includeOverflowInterior, bool includeSelf) const |
| 632 | { |
| 633 | int left = RenderContainer::leftmostPosition(includeOverflowInterior, includeSelf); |
| 634 | if (!includeOverflowInterior && hasOverflowClip()) |
| 635 | return left; |
| 636 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 637 | for (RenderObject* row = firstChild(); row; row = row->nextSibling()) { |
| 638 | for (RenderObject* cell = row->firstChild(); cell; cell = cell->nextSibling()) { |
| 639 | if (cell->isTableCell()) |
| 640 | left = min(left, cell->xPos() + cell->leftmostPosition(false)); |
adele | 04d4ce1 | 2006-02-11 20:11:05 +0000 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
| 644 | return left; |
| 645 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 646 | |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 647 | int RenderTableSection::calcOuterBorderTop() const |
| 648 | { |
| 649 | int totalCols = table()->numEffCols(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 650 | if (!m_gridRows || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 651 | return 0; |
| 652 | |
| 653 | unsigned borderWidth = 0; |
| 654 | |
| 655 | const BorderValue& sb = style()->borderTop(); |
| 656 | if (sb.style() == BHIDDEN) |
| 657 | return -1; |
| 658 | if (sb.style() > BHIDDEN) |
| 659 | borderWidth = sb.width; |
| 660 | |
| 661 | const BorderValue& rb = firstChild()->style()->borderTop(); |
| 662 | if (rb.style() == BHIDDEN) |
| 663 | return -1; |
| 664 | if (rb.style() > BHIDDEN && rb.width > borderWidth) |
| 665 | borderWidth = rb.width; |
| 666 | |
| 667 | bool allHidden = true; |
| 668 | for (int c = 0; c < totalCols; c++) { |
| 669 | const CellStruct& current = cellAt(0, c); |
| 670 | if (current.inColSpan || !current.cell) |
| 671 | continue; |
| 672 | const BorderValue& cb = current.cell->style()->borderTop(); |
| 673 | // FIXME: Don't repeat for the same col group |
| 674 | RenderTableCol* colGroup = table()->colElement(c); |
| 675 | if (colGroup) { |
| 676 | const BorderValue& gb = colGroup->style()->borderTop(); |
| 677 | if (gb.style() == BHIDDEN || cb.style() == BHIDDEN) |
| 678 | continue; |
| 679 | else |
| 680 | allHidden = false; |
| 681 | if (gb.style() > BHIDDEN && gb.width > borderWidth) |
| 682 | borderWidth = gb.width; |
| 683 | if (cb.style() > BHIDDEN && cb.width > borderWidth) |
| 684 | borderWidth = cb.width; |
| 685 | } else { |
| 686 | if (cb.style() == BHIDDEN) |
| 687 | continue; |
| 688 | else |
| 689 | allHidden = false; |
| 690 | if (cb.style() > BHIDDEN && cb.width > borderWidth) |
| 691 | borderWidth = cb.width; |
| 692 | } |
| 693 | } |
| 694 | if (allHidden) |
| 695 | return -1; |
| 696 | |
| 697 | return borderWidth / 2; |
| 698 | } |
| 699 | |
| 700 | int RenderTableSection::calcOuterBorderBottom() const |
| 701 | { |
| 702 | int totalCols = table()->numEffCols(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 703 | if (!m_gridRows || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 704 | return 0; |
| 705 | |
| 706 | unsigned borderWidth = 0; |
| 707 | |
| 708 | const BorderValue& sb = style()->borderBottom(); |
| 709 | if (sb.style() == BHIDDEN) |
| 710 | return -1; |
| 711 | if (sb.style() > BHIDDEN) |
| 712 | borderWidth = sb.width; |
| 713 | |
| 714 | const BorderValue& rb = lastChild()->style()->borderBottom(); |
| 715 | if (rb.style() == BHIDDEN) |
| 716 | return -1; |
| 717 | if (rb.style() > BHIDDEN && rb.width > borderWidth) |
| 718 | borderWidth = rb.width; |
| 719 | |
| 720 | bool allHidden = true; |
| 721 | for (int c = 0; c < totalCols; c++) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 722 | const CellStruct& current = cellAt(m_gridRows - 1, c); |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 723 | if (current.inColSpan || !current.cell) |
| 724 | continue; |
| 725 | const BorderValue& cb = current.cell->style()->borderBottom(); |
| 726 | // FIXME: Don't repeat for the same col group |
| 727 | RenderTableCol* colGroup = table()->colElement(c); |
| 728 | if (colGroup) { |
| 729 | const BorderValue& gb = colGroup->style()->borderBottom(); |
| 730 | if (gb.style() == BHIDDEN || cb.style() == BHIDDEN) |
| 731 | continue; |
| 732 | else |
| 733 | allHidden = false; |
| 734 | if (gb.style() > BHIDDEN && gb.width > borderWidth) |
| 735 | borderWidth = gb.width; |
| 736 | if (cb.style() > BHIDDEN && cb.width > borderWidth) |
| 737 | borderWidth = cb.width; |
| 738 | } else { |
| 739 | if (cb.style() == BHIDDEN) |
| 740 | continue; |
| 741 | else |
| 742 | allHidden = false; |
| 743 | if (cb.style() > BHIDDEN && cb.width > borderWidth) |
| 744 | borderWidth = cb.width; |
| 745 | } |
| 746 | } |
| 747 | if (allHidden) |
| 748 | return -1; |
| 749 | |
| 750 | return (borderWidth + 1) / 2; |
| 751 | } |
| 752 | |
| 753 | int RenderTableSection::calcOuterBorderLeft(bool rtl) const |
| 754 | { |
| 755 | int totalCols = table()->numEffCols(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 756 | if (!m_gridRows || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 757 | return 0; |
| 758 | |
| 759 | unsigned borderWidth = 0; |
| 760 | |
| 761 | const BorderValue& sb = style()->borderLeft(); |
| 762 | if (sb.style() == BHIDDEN) |
| 763 | return -1; |
| 764 | if (sb.style() > BHIDDEN) |
| 765 | borderWidth = sb.width; |
| 766 | |
| 767 | int leftmostColumn = rtl ? totalCols - 1 : 0; |
| 768 | RenderTableCol* colGroup = table()->colElement(leftmostColumn); |
| 769 | if (colGroup) { |
| 770 | const BorderValue& gb = colGroup->style()->borderLeft(); |
| 771 | if (gb.style() == BHIDDEN) |
| 772 | return -1; |
| 773 | if (gb.style() > BHIDDEN && gb.width > borderWidth) |
| 774 | borderWidth = gb.width; |
| 775 | } |
| 776 | |
| 777 | bool allHidden = true; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 778 | for (int r = 0; r < m_gridRows; r++) { |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 779 | const CellStruct& current = cellAt(r, leftmostColumn); |
| 780 | if (!current.cell) |
| 781 | continue; |
| 782 | // FIXME: Don't repeat for the same cell |
| 783 | const BorderValue& cb = current.cell->style()->borderLeft(); |
| 784 | const BorderValue& rb = current.cell->parent()->style()->borderLeft(); |
| 785 | if (cb.style() == BHIDDEN || rb.style() == BHIDDEN) |
| 786 | continue; |
| 787 | else |
| 788 | allHidden = false; |
| 789 | if (cb.style() > BHIDDEN && cb.width > borderWidth) |
| 790 | borderWidth = cb.width; |
| 791 | if (rb.style() > BHIDDEN && rb.width > borderWidth) |
| 792 | borderWidth = rb.width; |
| 793 | } |
| 794 | if (allHidden) |
| 795 | return -1; |
| 796 | |
| 797 | return borderWidth / 2; |
| 798 | } |
| 799 | |
| 800 | int RenderTableSection::calcOuterBorderRight(bool rtl) const |
| 801 | { |
| 802 | int totalCols = table()->numEffCols(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 803 | if (!m_gridRows || !totalCols) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 804 | return 0; |
| 805 | |
| 806 | unsigned borderWidth = 0; |
| 807 | |
| 808 | const BorderValue& sb = style()->borderRight(); |
| 809 | if (sb.style() == BHIDDEN) |
| 810 | return -1; |
| 811 | if (sb.style() > BHIDDEN) |
| 812 | borderWidth = sb.width; |
| 813 | |
| 814 | int rightmostColumn = rtl ? 0 : totalCols - 1; |
| 815 | RenderTableCol* colGroup = table()->colElement(rightmostColumn); |
| 816 | if (colGroup) { |
| 817 | const BorderValue& gb = colGroup->style()->borderRight(); |
| 818 | if (gb.style() == BHIDDEN) |
| 819 | return -1; |
| 820 | if (gb.style() > BHIDDEN && gb.width > borderWidth) |
| 821 | borderWidth = gb.width; |
| 822 | } |
| 823 | |
| 824 | bool allHidden = true; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 825 | for (int r = 0; r < m_gridRows; r++) { |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 826 | const CellStruct& current = cellAt(r, rightmostColumn); |
| 827 | if (!current.cell) |
| 828 | continue; |
| 829 | // FIXME: Don't repeat for the same cell |
| 830 | const BorderValue& cb = current.cell->style()->borderRight(); |
| 831 | const BorderValue& rb = current.cell->parent()->style()->borderRight(); |
| 832 | if (cb.style() == BHIDDEN || rb.style() == BHIDDEN) |
| 833 | continue; |
| 834 | else |
| 835 | allHidden = false; |
| 836 | if (cb.style() > BHIDDEN && cb.width > borderWidth) |
| 837 | borderWidth = cb.width; |
| 838 | if (rb.style() > BHIDDEN && rb.width > borderWidth) |
| 839 | borderWidth = rb.width; |
| 840 | } |
| 841 | if (allHidden) |
| 842 | return -1; |
| 843 | |
| 844 | return (borderWidth + 1) / 2; |
| 845 | } |
| 846 | |
| 847 | void RenderTableSection::recalcOuterBorder() |
| 848 | { |
| 849 | bool rtl = table()->style()->direction() == RTL; |
| 850 | m_outerBorderTop = calcOuterBorderTop(); |
| 851 | m_outerBorderBottom = calcOuterBorderBottom(); |
| 852 | m_outerBorderLeft = calcOuterBorderLeft(rtl); |
| 853 | m_outerBorderRight = calcOuterBorderRight(rtl); |
| 854 | } |
| 855 | |
| 856 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 857 | void RenderTableSection::paint(PaintInfo& paintInfo, int tx, int ty) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 858 | { |
antti | b366607 | 2007-08-17 23:29:50 +0000 | [diff] [blame] | 859 | // put this back in when all layout tests can handle it |
| 860 | // ASSERT(!needsLayout()); |
| 861 | // avoid crashing on bugs that cause us to paint with dirty layout |
| 862 | if (needsLayout()) |
| 863 | return; |
| 864 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 865 | unsigned totalRows = m_gridRows; |
| 866 | unsigned totalCols = table()->columns().size(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 867 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 868 | if (!totalRows || !totalCols) |
ap | 0e708ba | 2006-05-20 08:47:37 +0000 | [diff] [blame] | 869 | return; |
| 870 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 871 | tx += m_x; |
| 872 | ty += m_y; |
| 873 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 874 | // Check which rows and cols are visible and only paint these. |
| 875 | // FIXME: Could use a binary search here. |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 876 | PaintPhase paintPhase = paintInfo.phase; |
| 877 | int x = paintInfo.rect.x(); |
| 878 | int y = paintInfo.rect.y(); |
| 879 | int w = paintInfo.rect.width(); |
| 880 | int h = paintInfo.rect.height(); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 881 | |
bdakin | f061af7 | 2006-03-31 01:19:41 +0000 | [diff] [blame] | 882 | int os = 2 * maximalOutlineSize(paintPhase); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 883 | unsigned startrow = 0; |
| 884 | unsigned endrow = totalRows; |
ap | 292f4df | 2007-02-18 16:15:07 +0000 | [diff] [blame] | 885 | |
| 886 | // If some cell overflows, just paint all of them. |
| 887 | if (!m_hasOverflowingCell) { |
| 888 | for (; startrow < totalRows; startrow++) { |
| 889 | if (ty + m_rowPos[startrow + 1] >= y - os) |
| 890 | break; |
| 891 | } |
| 892 | if (startrow == totalRows && ty + m_rowPos[totalRows] + table()->outerBorderBottom() >= y - os) |
| 893 | startrow--; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 894 | |
ap | 292f4df | 2007-02-18 16:15:07 +0000 | [diff] [blame] | 895 | for (; endrow > 0; endrow--) { |
| 896 | if (ty + m_rowPos[endrow - 1] <= y + h + os) |
| 897 | break; |
| 898 | } |
| 899 | if (!endrow && ty + m_rowPos[0] - table()->outerBorderTop() <= y + h + os) |
| 900 | endrow++; |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 901 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 902 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 903 | unsigned startcol = 0; |
| 904 | unsigned endcol = totalCols; |
adele | ddfe27f | 2007-01-05 23:03:50 +0000 | [diff] [blame] | 905 | // FIXME: Implement RTL. |
| 906 | if (!m_hasOverflowingCell && style()->direction() == LTR) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 907 | for (; startcol < totalCols; startcol++) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 908 | if (tx + table()->columnPositions()[startcol + 1] >= x - os) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 909 | break; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 910 | } |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 911 | if (startcol == totalCols && tx + table()->columnPositions()[totalCols] + table()->outerBorderRight() >= x - os) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 912 | startcol--; |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 913 | |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 914 | for (; endcol > 0; endcol--) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 915 | if (tx + table()->columnPositions()[endcol - 1] <= x + w + os) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 916 | break; |
| 917 | } |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 918 | if (!endcol && tx + table()->columnPositions()[0] - table()->outerBorderLeft() <= y + w + os) |
darin | 3201110 | 2006-05-15 04:42:09 +0000 | [diff] [blame] | 919 | endcol++; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | if (startcol < endcol) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 923 | // draw the cells |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 924 | for (unsigned r = startrow; r < endrow; r++) { |
| 925 | unsigned c = startcol; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 926 | // since a cell can be -1 (indicating a colspan) we might have to search backwards to include it |
| 927 | while (c && cellAt(r, c).inColSpan) |
| 928 | c--; |
| 929 | for (; c < endcol; c++) { |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 930 | CellStruct current = cellAt(r, c); |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 931 | RenderTableCell* cell = current.cell; |
hyatt | e031dd0 | 2006-03-18 01:01:06 +0000 | [diff] [blame] | 932 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 933 | // Cells must always paint in the order in which they appear taking into account |
| 934 | // their upper left originating row/column. For cells with rowspans, avoid repainting |
| 935 | // if we've already seen the cell. |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 936 | if (!cell || (r > startrow && (cellAt(r - 1, c).cell == cell))) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 937 | continue; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 938 | |
darin | 7e7c8e4 | 2007-04-25 01:14:03 +0000 | [diff] [blame] | 939 | RenderTableRow* row = static_cast<RenderTableRow*>(cell->parent()); |
| 940 | |
bdakin | f061af7 | 2006-03-31 01:19:41 +0000 | [diff] [blame] | 941 | if (paintPhase == PaintPhaseBlockBackground || paintPhase == PaintPhaseChildBlockBackground) { |
hyatt | e031dd0 | 2006-03-18 01:01:06 +0000 | [diff] [blame] | 942 | // We need to handle painting a stack of backgrounds. This stack (from bottom to top) consists of |
| 943 | // the column group, column, row group, row, and then the cell. |
| 944 | RenderObject* col = table()->colElement(c); |
| 945 | RenderObject* colGroup = 0; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 946 | if (col && col->parent()->style()->display() == TABLE_COLUMN_GROUP) |
| 947 | colGroup = col->parent(); |
| 948 | |
hyatt | e031dd0 | 2006-03-18 01:01:06 +0000 | [diff] [blame] | 949 | // Column groups and columns first. |
| 950 | // FIXME: Columns and column groups do not currently support opacity, and they are being painted "too late" in |
| 951 | // the stack, since we have already opened a transparency layer (potentially) for the table row group. |
| 952 | // Note that we deliberately ignore whether or not the cell has a layer, since these backgrounds paint "behind" the |
| 953 | // cell. |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 954 | cell->paintBackgroundsBehindCell(paintInfo, tx, ty, colGroup); |
| 955 | cell->paintBackgroundsBehindCell(paintInfo, tx, ty, col); |
| 956 | |
hyatt | e031dd0 | 2006-03-18 01:01:06 +0000 | [diff] [blame] | 957 | // Paint the row group next. |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 958 | cell->paintBackgroundsBehindCell(paintInfo, tx, ty, this); |
| 959 | |
hyatt | e031dd0 | 2006-03-18 01:01:06 +0000 | [diff] [blame] | 960 | // Paint the row next, but only if it doesn't have a layer. If a row has a layer, it will be responsible for |
| 961 | // painting the row background for the cell. |
darin | 7e7c8e4 | 2007-04-25 01:14:03 +0000 | [diff] [blame] | 962 | if (!row->hasLayer()) |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 963 | cell->paintBackgroundsBehindCell(paintInfo, tx, ty, row); |
hyatt | e031dd0 | 2006-03-18 01:01:06 +0000 | [diff] [blame] | 964 | } |
| 965 | |
darin | 7e7c8e4 | 2007-04-25 01:14:03 +0000 | [diff] [blame] | 966 | if ((!cell->hasLayer() && !row->hasLayer()) || paintInfo.phase == PaintPhaseCollapsedTableBorders) |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 967 | cell->paint(paintInfo, tx, ty); |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 968 | } |
| 969 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | |
bdash | b07ae8d | 2007-02-08 04:56:20 +0000 | [diff] [blame] | 973 | void RenderTableSection::imageChanged(CachedImage* image) |
| 974 | { |
| 975 | if (!image || !image->canRender() || !parent()) |
| 976 | return; |
| 977 | |
| 978 | // FIXME: Examine cells and repaint only the rect the image paints in. |
| 979 | repaint(); |
| 980 | } |
| 981 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 982 | void RenderTableSection::recalcCells() |
| 983 | { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 984 | m_cCol = 0; |
| 985 | m_cRow = -1; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 986 | clearGrid(); |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 987 | m_gridRows = 0; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 988 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 989 | for (RenderObject* row = firstChild(); row; row = row->nextSibling()) { |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 990 | if (row->isTableRow()) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 991 | m_cRow++; |
| 992 | m_cCol = 0; |
lars | b5288ad | 2007-01-13 18:48:29 +0000 | [diff] [blame] | 993 | if (!ensureRows(m_cRow + 1)) |
| 994 | break; |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 995 | m_grid[m_cRow].rowRenderer = row; |
eseidel | 05ef043 | 2006-05-25 22:11:36 +0000 | [diff] [blame] | 996 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 997 | for (RenderObject* cell = row->firstChild(); cell; cell = cell->nextSibling()) { |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 998 | if (cell->isTableCell()) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 999 | addCell(static_cast<RenderTableCell*>(cell), row); |
| 1000 | } |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1001 | } |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1002 | } |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1003 | m_needsCellRecalc = false; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1004 | setNeedsLayout(true); |
| 1005 | } |
| 1006 | |
| 1007 | void RenderTableSection::clearGrid() |
| 1008 | { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1009 | int rows = m_gridRows; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1010 | while (rows--) |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1011 | delete m_grid[rows].row; |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | int RenderTableSection::numColumns() const |
| 1015 | { |
| 1016 | int result = 0; |
| 1017 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1018 | for (int r = 0; r < m_gridRows; ++r) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1019 | for (int c = result; c < table()->numEffCols(); ++c) { |
| 1020 | const CellStruct& cell = cellAt(r, c); |
| 1021 | if (cell.cell || cell.inColSpan) |
| 1022 | result = c; |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | return result + 1; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1029 | void RenderTableSection::appendColumn(int pos) |
| 1030 | { |
| 1031 | for (int row = 0; row < m_gridRows; ++row) { |
| 1032 | m_grid[row].row->resize(pos + 1); |
| 1033 | CellStruct& c = cellAt(row, pos); |
| 1034 | c.cell = 0; |
| 1035 | c.inColSpan = false; |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | void RenderTableSection::splitColumn(int pos, int newSize) |
| 1040 | { |
| 1041 | if (m_cCol > pos) |
| 1042 | m_cCol++; |
| 1043 | for (int row = 0; row < m_gridRows; ++row) { |
| 1044 | m_grid[row].row->resize(newSize); |
| 1045 | Row& r = *m_grid[row].row; |
| 1046 | memmove(r.data() + pos + 1, r.data() + pos, (newSize - 1 - pos) * sizeof(CellStruct)); |
| 1047 | r[pos + 1].cell = 0; |
| 1048 | r[pos + 1].inColSpan = r[pos].inColSpan || r[pos].cell; |
| 1049 | } |
| 1050 | } |
| 1051 | |
hyatt | 818bb12 | 2007-04-25 19:10:24 +0000 | [diff] [blame] | 1052 | RenderObject* RenderTableSection::removeChildNode(RenderObject* child, bool fullRemove) |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1053 | { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1054 | setNeedsCellRecalc(); |
hyatt | 818bb12 | 2007-04-25 19:10:24 +0000 | [diff] [blame] | 1055 | return RenderContainer::removeChildNode(child, fullRemove); |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1058 | // Hit Testing |
bdakin | c4d8acc | 2006-10-31 21:48:20 +0000 | [diff] [blame] | 1059 | bool RenderTableSection::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int x, int y, int tx, int ty, HitTestAction action) |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1060 | { |
| 1061 | // Table sections cannot ever be hit tested. Effectively they do not exist. |
| 1062 | // Just forward to our children always. |
| 1063 | tx += m_x; |
| 1064 | ty += m_y; |
| 1065 | |
| 1066 | for (RenderObject* child = lastChild(); child; child = child->previousSibling()) { |
| 1067 | // FIXME: We have to skip over inline flows, since they can show up inside table rows |
| 1068 | // at the moment (a demoted inline <form> for example). If we ever implement a |
| 1069 | // table-specific hit-test method (which we should do for performance reasons anyway), |
| 1070 | // then we can remove this check. |
darin | 4ef3f99 | 2007-04-25 06:49:08 +0000 | [diff] [blame] | 1071 | if (!child->hasLayer() && !child->isInlineFlow() && child->nodeAtPoint(request, result, x, y, tx, ty, action)) { |
hyatt | 6a2ac52 | 2007-01-11 07:26:44 +0000 | [diff] [blame] | 1072 | updateHitTestResult(result, IntPoint(x - tx, y - ty)); |
hyatt | d866e59 | 2006-03-17 09:50:35 +0000 | [diff] [blame] | 1073 | return true; |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | return false; |
| 1078 | } |
| 1079 | |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1080 | #ifndef NDEBUG |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1081 | void RenderTableSection::dump(TextStream* stream, DeprecatedString ind) const |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1082 | { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1083 | *stream << endl << ind << "grid=(" << m_gridRows << "," << table()->numEffCols() << ")" << endl << ind; |
| 1084 | for (int r = 0; r < m_gridRows; r++) { |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1085 | for (int c = 0; c < table()->numEffCols(); c++) { |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1086 | if (cellAt(r, c).cell && !cellAt(r, c).inColSpan) |
ap | 50b5835 | 2006-01-22 20:32:36 +0000 | [diff] [blame] | 1087 | *stream << "(" << cellAt(r, c).cell->row() << "," << cellAt(r, c).cell->col() << "," |
| 1088 | << cellAt(r, c).cell->rowSpan() << "," << cellAt(r, c).cell->colSpan() << ") "; |
| 1089 | else |
| 1090 | *stream << cellAt(r, c).cell << "null cell "; |
| 1091 | } |
| 1092 | *stream << endl << ind; |
eseidel | a043f3d | 2006-01-20 19:24:53 +0000 | [diff] [blame] | 1093 | } |
| 1094 | RenderContainer::dump(stream,ind); |
| 1095 | } |
| 1096 | #endif |
| 1097 | |
ddkilzer | 260f3d2 | 2007-01-05 05:56:31 +0000 | [diff] [blame] | 1098 | } // namespace WebCore |