WebCore:
Reviewed by Sam Weinig.
- http://bugs.webkit.org/show_bug.cgi?id=12078
Clean up RenderTable*
- Coding style cleanup.
- Canceled AutoTableLayout and FixedTableLayout being friend classes of
RenderTable. Instead, added public accessors to RenderTable for what
the table layout classes need and changed TableLayout::calcMinMaxWidth()
to take references to the caller's min and max widths.
- Made RenderTableSection's grid protected and moved code that accessed it
from RenderTable into RenderTableSection.
No test possible (no change to functionality).
* rendering/AutoTableLayout.cpp:
(WebCore::AutoTableLayout::calcMinMaxWidth):
(WebCore::AutoTableLayout::layout):
* rendering/AutoTableLayout.h:
* rendering/FixedTableLayout.cpp:
(WebCore::FixedTableLayout::calcWidthArray):
(WebCore::FixedTableLayout::calcMinMaxWidth):
(WebCore::FixedTableLayout::layout):
* rendering/FixedTableLayout.h:
* rendering/RenderTable.cpp:
(WebCore::RenderTable::RenderTable):
(WebCore::RenderTable::~RenderTable):
(WebCore::RenderTable::setStyle):
(WebCore::RenderTable::addChild):
(WebCore::RenderTable::calcWidth):
(WebCore::RenderTable::layout):
(WebCore::RenderTable::setCellWidths):
(WebCore::RenderTable::paint):
(WebCore::RenderTable::paintBoxDecorations):
(WebCore::RenderTable::calcMinMaxWidth):
(WebCore::RenderTable::splitColumn): Factored out the section work
to RenderTableSection::splitColumn().
(WebCore::RenderTable::appendColumn): Factored out the section work
to RenderTableSection::appendColumn().
(WebCore::RenderTable::colElement):
(WebCore::RenderTable::recalcSections):
(WebCore::RenderTable::removeChildNode):
(WebCore::RenderTable::calcBorderLeft):
(WebCore::RenderTable::calcBorderRight):
(WebCore::RenderTable::outerBorderTop):
(WebCore::RenderTable::outerBorderBottom):
(WebCore::RenderTable::outerBorderLeft):
(WebCore::RenderTable::outerBorderRight):
(WebCore::RenderTable::sectionAbove):
(WebCore::RenderTable::sectionBelow):
(WebCore::RenderTable::cellAbove):
(WebCore::RenderTable::cellBelow):
(WebCore::RenderTable::cellBefore):
(WebCore::RenderTable::getOverflowClipRect):
(WebCore::RenderTable::dump):
* rendering/RenderTable.h:
(WebCore::RenderTable::getColumnPos):
(WebCore::RenderTable::hBorderSpacing):
(WebCore::RenderTable::vBorderSpacing):
(WebCore::RenderTable::getRules):
(WebCore::RenderTable::cellPadding):
(WebCore::RenderTable::setCellPadding):
(WebCore::RenderTable::ColumnStruct::ColumnStruct):
(WebCore::RenderTable::columns): Added this accessor.
(WebCore::RenderTable::columnPositions): Added this accessor.
(WebCore::RenderTable::header):
(WebCore::RenderTable::footer):
(WebCore::RenderTable::firstBody):
(WebCore::RenderTable::numEffCols):
(WebCore::RenderTable::spanOfEffCol):
(WebCore::RenderTable::colToEffCol):
(WebCore::RenderTable::effColToCol):
(WebCore::RenderTable::bordersPaddingAndSpacing):
(WebCore::RenderTable::needsSectionRecalc):
(WebCore::RenderTable::setNeedsSectionRecalc): Renamed setNeedSectionRecalc()
to this.
(WebCore::RenderTable::hasSections):
(WebCore::RenderTable::recalcSectionsIfNeeded):
* rendering/RenderTableCell.cpp:
(WebCore::RenderTableCell::RenderTableCell):
(WebCore::RenderTableCell::destroy):
(WebCore::RenderTableCell::updateFromElement):
(WebCore::RenderTableCell::styleOrColWidth):
(WebCore::RenderTableCell::computeAbsoluteRepaintRect):
(WebCore::RenderTableCell::absolutePosition):
(WebCore::RenderTableCell::baselinePosition):
(WebCore::RenderTableCell::setStyle):
(WebCore::compareBorders):
(WebCore::RenderTableCell::collapsedTopBorder):
(WebCore::RenderTableCell::paint):
(WebCore::collapsedBorderStyle):
(WebCore::CollapsedBorder::CollapsedBorder):
(WebCore::CollapsedBorders::CollapsedBorders):
(WebCore::CollapsedBorders::addBorder):
(WebCore::CollapsedBorders::nextBorder):
(WebCore::RenderTableCell::paintCollapsedBorder):
(WebCore::RenderTableCell::paintBackgroundsBehindCell):
(WebCore::RenderTableCell::paintBoxDecorations):
(WebCore::RenderTableCell::dump):
* rendering/RenderTableCell.h:
(WebCore::RenderTableCell::colSpan):
(WebCore::RenderTableCell::setColSpan):
(WebCore::RenderTableCell::rowSpan):
(WebCore::RenderTableCell::setRowSpan):
(WebCore::RenderTableCell::col):
(WebCore::RenderTableCell::setCol):
(WebCore::RenderTableCell::row):
(WebCore::RenderTableCell::setRow):
(WebCore::RenderTableCell::section):
(WebCore::RenderTableCell::table):
(WebCore::RenderTableCell::yPos):
(WebCore::RenderTableCell::setCellTopExtra):
(WebCore::RenderTableCell::setCellBottomExtra):
(WebCore::RenderTableCell::borderTopExtra):
(WebCore::RenderTableCell::borderBottomExtra):
* rendering/RenderTableRow.cpp:
(WebCore::RenderTableRow::destroy):
(WebCore::RenderTableRow::setStyle):
(WebCore::RenderTableRow::addChild):
(WebCore::RenderTableRow::layout):
(WebCore::RenderTableRow::getAbsoluteRepaintRect):
(WebCore::RenderTableRow::paint):
* rendering/RenderTableRow.h:
(WebCore::RenderTableRow::section):
(WebCore::RenderTableRow::table):
(WebCore::RenderTableRow::lineHeight):
* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::RenderTableSection):
(WebCore::RenderTableSection::destroy):
(WebCore::RenderTableSection::setStyle):
(WebCore::RenderTableSection::addChild):
(WebCore::RenderTableSection::ensureRows):
(WebCore::RenderTableSection::addCell):
(WebCore::RenderTableSection::setCellWidths):
(WebCore::RenderTableSection::calcRowHeight):
(WebCore::RenderTableSection::layoutRows):
(WebCore::RenderTableSection::lowestPosition):
(WebCore::RenderTableSection::rightmostPosition):
(WebCore::RenderTableSection::leftmostPosition):
(WebCore::RenderTableSection::calcOuterBorderTop):
(WebCore::RenderTableSection::calcOuterBorderBottom):
(WebCore::RenderTableSection::calcOuterBorderLeft):
(WebCore::RenderTableSection::calcOuterBorderRight):
(WebCore::RenderTableSection::paint):
(WebCore::RenderTableSection::recalcCells):
(WebCore::RenderTableSection::clearGrid):
(WebCore::RenderTableSection::numColumns):
(WebCore::RenderTableSection::appendColumn): Added. Moved code from
RenderTable::appendColumn() into here.
(WebCore::RenderTableSection::splitColumn): Added. Moved code from
RenderTable::splitColumn() into here.
(WebCore::RenderTableSection::removeChildNode):
(WebCore::RenderTableSection::dump):
* rendering/RenderTableSection.h:
(WebCore::RenderTableSection::renderName):
(WebCore::RenderTableSection::isTableSection):
(WebCore::RenderTableSection::lineHeight):
(WebCore::RenderTableSection::table):
(WebCore::RenderTableSection::cellAt):
(WebCore::RenderTableSection::numRows):
(WebCore::RenderTableSection::recalcCellsIfNeeded):
(WebCore::RenderTableSection::needsCellRecalc):
(WebCore::RenderTableSection::setNeedsCellRecalc):
(WebCore::RenderTableSection::getBaseline):
* rendering/TableLayout.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@18608 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/rendering/RenderTableSection.cpp b/WebCore/rendering/RenderTableSection.cpp
index 6455a7b..e79bf18 100644
--- a/WebCore/rendering/RenderTableSection.cpp
+++ b/WebCore/rendering/RenderTableSection.cpp
@@ -30,12 +30,12 @@
#include "Document.h"
#include "HTMLNames.h"
-#include "TextStream.h"
#include "RenderTableCell.h"
#include "RenderTableCol.h"
#include "RenderTableRow.h"
-#include <wtf/Vector.h>
+#include "TextStream.h"
#include <limits>
+#include <wtf/Vector.h>
using namespace std;
@@ -45,17 +45,17 @@
RenderTableSection::RenderTableSection(Node* node)
: RenderContainer(node)
+ , m_gridRows(0)
+ , m_cCol(0)
+ , m_cRow(-1)
+ , m_needsCellRecalc(false)
+ , m_outerBorderLeft(0)
+ , m_outerBorderRight(0)
+ , m_outerBorderTop(0)
+ , m_outerBorderBottom(0)
{
// init RenderObject attributes
setInline(false); // our object is not Inline
- gridRows = 0;
- cCol = 0;
- cRow = -1;
- needCellRecalc = false;
- m_outerBorderLeft = 0;
- m_outerBorderRight = 0;
- m_outerBorderTop = 0;
- m_outerBorderBottom = 0;
}
RenderTableSection::~RenderTableSection()
@@ -68,20 +68,20 @@
// recalc cell info because RenderTable has unguarded pointers
// stored that point to this RenderTableSection.
if (table())
- table()->setNeedSectionRecalc();
+ table()->setNeedsSectionRecalc();
RenderContainer::destroy();
}
-void RenderTableSection::setStyle(RenderStyle* _style)
+void RenderTableSection::setStyle(RenderStyle* newStyle)
{
// we don't allow changing this one
if (style())
- _style->setDisplay(style()->display());
- else if (_style->display() != TABLE_FOOTER_GROUP && _style->display() != TABLE_HEADER_GROUP)
- _style->setDisplay(TABLE_ROW_GROUP);
+ newStyle->setDisplay(style()->display());
+ else if (newStyle->display() != TABLE_FOOTER_GROUP && newStyle->display() != TABLE_HEADER_GROUP)
+ newStyle->setDisplay(TABLE_ROW_GROUP);
- RenderContainer::setStyle(_style);
+ RenderContainer::setStyle(newStyle);
}
void RenderTableSection::addChild(RenderObject* child, RenderObject* beforeChild)
@@ -123,21 +123,21 @@
}
if (beforeChild)
- setNeedCellRecalc();
+ setNeedsCellRecalc();
- ++cRow;
- cCol = 0;
+ ++m_cRow;
+ m_cCol = 0;
- ensureRows(cRow + 1);
- grid[cRow].rowRenderer = child;
+ ensureRows(m_cRow + 1);
+ m_grid[m_cRow].rowRenderer = child;
if (!beforeChild) {
- grid[cRow].height = child->style()->height();
- if (grid[cRow].height.isRelative())
- grid[cRow].height = Length();
+ m_grid[m_cRow].height = child->style()->height();
+ if (m_grid[m_cRow].height.isRelative())
+ m_grid[m_cRow].height = Length();
}
- // If the next renderer is actually wrapped in an anonymous table row, we need to go up and find that
+ // If the next renderer is actually wrapped in an anonymous table row, we need to go up and find that.
while (beforeChild && !beforeChild->isTableRow())
beforeChild = beforeChild->parent();
@@ -146,24 +146,24 @@
bool RenderTableSection::ensureRows(int numRows)
{
- int nRows = gridRows;
+ int nRows = m_gridRows;
if (numRows > nRows) {
- if (numRows > static_cast<int>(grid.size())) {
+ if (numRows > static_cast<int>(m_grid.size())) {
if (numRows > static_cast<int>(numeric_limits<size_t>::max() / sizeof(RowStruct)))
return false;
- grid.resize(numRows);
+ m_grid.resize(numRows);
}
- gridRows = numRows;
+ m_gridRows = numRows;
int nCols = table()->numEffCols();
CellStruct emptyCellStruct;
emptyCellStruct.cell = 0;
emptyCellStruct.inColSpan = false;
for (int r = nRows; r < numRows; r++) {
- grid[r].row = new Row(nCols);
- grid[r].row->fill(emptyCellStruct);
- grid[r].rowRenderer = 0;
- grid[r].baseLine = 0;
- grid[r].height = Length();
+ m_grid[r].row = new Row(nCols);
+ m_grid[r].row->fill(emptyCellStruct);
+ m_grid[r].rowRenderer = 0;
+ m_grid[r].baseLine = 0;
+ m_grid[r].height = Length();
}
}
@@ -174,7 +174,7 @@
{
int rSpan = cell->rowSpan();
int cSpan = cell->colSpan();
- Vector<RenderTable::ColumnStruct>& columns = table()->columns;
+ Vector<RenderTable::ColumnStruct>& columns = table()->columns();
int nCols = columns.size();
// ### mozilla still seems to do the old HTML way, even for strict DTD
@@ -184,24 +184,24 @@
// <TR><TD colspan="2">5
// </TABLE>
- while (cCol < nCols && (cellAt(cRow, cCol).cell || cellAt(cRow, cCol).inColSpan))
- cCol++;
+ while (m_cCol < nCols && (cellAt(m_cRow, m_cCol).cell || cellAt(m_cRow, m_cCol).inColSpan))
+ m_cCol++;
if (rSpan == 1) {
// we ignore height settings on rowspan cells
Length height = cell->style()->height();
if (height.isPositive() || (height.isRelative() && height.value() >= 0)) {
- Length cRowHeight = grid[cRow].height;
+ Length cRowHeight = m_grid[m_cRow].height;
switch (height.type()) {
case Percent:
if (!(cRowHeight.isPercent()) ||
(cRowHeight.isPercent() && cRowHeight.rawValue() < height.rawValue()))
- grid[cRow].height = height;
+ m_grid[m_cRow].height = height;
break;
case Fixed:
if (cRowHeight.type() < Percent ||
(cRowHeight.isFixed() && cRowHeight.value() < height.value()))
- grid[cRow].height = height;
+ m_grid[m_cRow].height = height;
break;
case Relative:
default:
@@ -211,65 +211,62 @@
}
// make sure we have enough rows
- if (!ensureRows(cRow + rSpan))
+ if (!ensureRows(m_cRow + rSpan))
return;
- grid[cRow].rowRenderer = row;
+ m_grid[m_cRow].rowRenderer = row;
- int col = cCol;
+ int col = m_cCol;
// tell the cell where it is
CellStruct currentCell;
currentCell.cell = cell;
currentCell.inColSpan = false;
while (cSpan) {
int currentSpan;
- if (cCol >= nCols) {
+ if (m_cCol >= nCols) {
table()->appendColumn(cSpan);
currentSpan = cSpan;
} else {
- if (cSpan < columns[cCol].span)
- table()->splitColumn(cCol, cSpan);
- currentSpan = columns[cCol].span;
+ if (cSpan < columns[m_cCol].span)
+ table()->splitColumn(m_cCol, cSpan);
+ currentSpan = columns[m_cCol].span;
}
for (int r = 0; r < rSpan; r++) {
- CellStruct& c = cellAt(cRow + r, cCol);
+ CellStruct& c = cellAt(m_cRow + r, m_cCol);
if (currentCell.cell && !c.cell)
c.cell = currentCell.cell;
if (currentCell.inColSpan)
c.inColSpan = true;
}
- cCol++;
+ m_cCol++;
cSpan -= currentSpan;
currentCell.cell = 0;
currentCell.inColSpan = true;
}
if (cell) {
- cell->setRow(cRow);
+ cell->setRow(m_cRow);
cell->setCol(table()->effColToCol(col));
}
}
-
-
void RenderTableSection::setCellWidths()
{
- Vector<int>& columnPos = table()->columnPos;
+ Vector<int>& columnPos = table()->columnPositions();
- int rows = gridRows;
- for (int i = 0; i < rows; i++) {
- Row &row = *grid[i].row;
+ for (int i = 0; i < m_gridRows; i++) {
+ Row& row = *m_grid[i].row;
int cols = row.size();
for (int j = 0; j < cols; j++) {
CellStruct current = row[j];
- RenderTableCell *cell = current.cell;
+ RenderTableCell* cell = current.cell;
if (!cell)
continue;
int endCol = j;
int cspan = cell->colSpan();
while (cspan && endCol < cols) {
- cspan -= table()->columns[endCol].span;
+ cspan -= table()->columns()[endCol].span;
endCol++;
}
int w = columnPos[endCol] - columnPos[j] - table()->hBorderSpacing();
@@ -285,43 +282,37 @@
}
}
-
void RenderTableSection::calcRowHeight()
{
- int indx;
- RenderTableCell *cell;
+ RenderTableCell* cell;
- int totalRows = gridRows;
int spacing = table()->vBorderSpacing();
- rowPos.resize(totalRows + 1);
- rowPos[0] = spacing;
+ m_rowPos.resize(m_gridRows + 1);
+ m_rowPos[0] = spacing;
- for (int r = 0; r < totalRows; r++) {
- rowPos[r + 1] = 0;
+ for (int r = 0; r < m_gridRows; r++) {
+ m_rowPos[r + 1] = 0;
int baseline = 0;
int bdesc = 0;
- int ch = grid[r].height.calcMinValue(0);
- int pos = rowPos[r] + ch + (grid[r].rowRenderer ? spacing : 0);
+ int ch = m_grid[r].height.calcMinValue(0);
+ int pos = m_rowPos[r] + ch + (m_grid[r].rowRenderer ? spacing : 0);
- if (pos > rowPos[r + 1])
- rowPos[r + 1] = pos;
+ m_rowPos[r + 1] = max(m_rowPos[r + 1], pos);
- Row *row = grid[r].row;
+ Row* row = m_grid[r].row;
int totalCols = row->size();
- int totalRows = gridRows;
for (int c = 0; c < totalCols; c++) {
CellStruct current = cellAt(r, c);
cell = current.cell;
if (!cell || current.inColSpan)
continue;
- if (r < totalRows - 1 && cellAt(r + 1, c).cell == cell)
+ if (r < m_gridRows - 1 && cellAt(r + 1, c).cell == cell)
continue;
- if ((indx = r - cell->rowSpan() + 1) < 0)
- indx = 0;
+ int indx = max(r - cell->rowSpan() + 1, 0);
if (cell->overrideSize() != -1) {
cell->setOverrideSize(-1);
@@ -334,26 +325,19 @@
ch = cell->style()->height().calcValue(0) +
(cell->style()->htmlHacks() ? 0 : (cell->paddingTop() + cell->paddingBottom() +
cell->borderTop() + cell->borderBottom()));
- if (cell->height() > ch)
- ch = cell->height();
+ ch = max(ch, cell->height());
- pos = rowPos[indx] + ch + (grid[r].rowRenderer ? spacing : 0);
+ pos = m_rowPos[indx] + ch + (m_grid[r].rowRenderer ? spacing : 0);
- if (pos > rowPos[r + 1])
- rowPos[r + 1] = pos;
+ m_rowPos[r + 1] = max(m_rowPos[r + 1], pos);
// find out the baseline
EVerticalAlign va = cell->style()->verticalAlign();
- if (va == BASELINE || va == TEXT_BOTTOM || va == TEXT_TOP
- || va == SUPER || va == SUB) {
+ if (va == BASELINE || va == TEXT_BOTTOM || va == TEXT_TOP || va == SUPER || va == SUB) {
int b = cell->baselinePosition();
if (b > cell->borderTop() + cell->paddingTop()) {
- if (b > baseline)
- baseline = b;
-
- int td = rowPos[indx] + ch - b;
- if (td > bdesc)
- bdesc = td;
+ baseline = max(baseline, b);
+ bdesc = max(bdesc, m_rowPos[indx] + ch - b);
}
}
}
@@ -361,15 +345,11 @@
//do we have baseline aligned elements?
if (baseline) {
// increase rowheight if baseline requires
- int bRowPos = baseline + bdesc + (grid[r].rowRenderer ? spacing : 0);
- if (rowPos[r + 1] < bRowPos)
- rowPos[r + 1] = bRowPos;
-
- grid[r].baseLine = baseline;
+ m_rowPos[r + 1] = max(m_rowPos[r + 1], baseline + bdesc + (m_grid[r].rowRenderer ? spacing : 0));
+ m_grid[r].baseLine = baseline;
}
- if (rowPos[r + 1] < rowPos[r])
- rowPos[r + 1] = rowPos[r];
+ m_rowPos[r + 1] = max(m_rowPos[r + 1], m_rowPos[r]);
}
}
@@ -377,100 +357,96 @@
{
int rHeight;
int rindx;
- int totalRows = gridRows;
- int hspacing = table()->hBorderSpacing();
- int vspacing = table()->vBorderSpacing();
+ int totalRows = m_gridRows;
// Set the width of our section now. The rows will also be this width.
m_width = table()->contentWidth();
if (table()->collapseBorders())
recalcOuterBorder();
- if (toAdd && totalRows && (rowPos[totalRows] || !nextSibling())) {
-
- int totalHeight = rowPos[totalRows] + toAdd;
+ if (toAdd && totalRows && (m_rowPos[totalRows] || !nextSibling())) {
+ int totalHeight = m_rowPos[totalRows] + toAdd;
int dh = toAdd;
int totalPercent = 0;
int numAuto = 0;
for (int r = 0; r < totalRows; r++) {
- if (grid[r].height.isAuto())
+ if (m_grid[r].height.isAuto())
numAuto++;
- else if (grid[r].height.isPercent())
- totalPercent += grid[r].height.rawValue();
+ else if (m_grid[r].height.isPercent())
+ totalPercent += m_grid[r].height.rawValue();
}
if (totalPercent) {
// try to satisfy percent
int add = 0;
- if (totalPercent > 100 * percentScaleFactor)
- totalPercent = 100 * percentScaleFactor;
- int rh = rowPos[1] - rowPos[0];
+ totalPercent = min(totalPercent, 100 * percentScaleFactor);
+ int rh = m_rowPos[1] - m_rowPos[0];
for (int r = 0; r < totalRows; r++) {
- if (totalPercent > 0 && grid[r].height.isPercent()) {
- int toAdd = min(dh, (totalHeight * grid[r].height.rawValue() / (100 * percentScaleFactor)) - rh);
+ if (totalPercent > 0 && m_grid[r].height.isPercent()) {
+ int toAdd = min(dh, (totalHeight * m_grid[r].height.rawValue() / (100 * percentScaleFactor)) - rh);
// If toAdd is negative, then we don't want to shrink the row (this bug
// affected Outlook Web Access).
toAdd = max(0, toAdd);
add += toAdd;
dh -= toAdd;
- totalPercent -= grid[r].height.rawValue();
+ totalPercent -= m_grid[r].height.rawValue();
}
if (r < totalRows - 1)
- rh = rowPos[r + 2] - rowPos[r + 1];
- rowPos[r + 1] += add;
+ rh = m_rowPos[r + 2] - m_rowPos[r + 1];
+ m_rowPos[r + 1] += add;
}
}
if (numAuto) {
// distribute over variable cols
int add = 0;
for (int r = 0; r < totalRows; r++) {
- if (numAuto > 0 && grid[r].height.isAuto()) {
- int toAdd = dh/numAuto;
+ if (numAuto > 0 && m_grid[r].height.isAuto()) {
+ int toAdd = dh / numAuto;
add += toAdd;
dh -= toAdd;
numAuto--;
}
- rowPos[r + 1] += add;
+ m_rowPos[r + 1] += add;
}
}
- if (dh > 0 && rowPos[totalRows]) {
+ if (dh > 0 && m_rowPos[totalRows]) {
// if some left overs, distribute equally.
- int tot = rowPos[totalRows];
+ int tot = m_rowPos[totalRows];
int add = 0;
- int prev = rowPos[0];
+ int prev = m_rowPos[0];
for (int r = 0; r < totalRows; r++) {
//weight with the original height
- add += dh * (rowPos[r + 1] - prev) / tot;
- prev = rowPos[r + 1];
- rowPos[r + 1] += add;
+ add += dh * (m_rowPos[r + 1] - prev) / tot;
+ prev = m_rowPos[r + 1];
+ m_rowPos[r + 1] += add;
}
}
}
- int leftOffset = hspacing;
-
+ int hspacing = table()->hBorderSpacing();
+ int vspacing = table()->vBorderSpacing();
int nEffCols = table()->numEffCols();
+
for (int r = 0; r < totalRows; r++) {
// Set the row's x/y position and width/height.
- if (grid[r].rowRenderer) {
- grid[r].rowRenderer->setPos(0, rowPos[r]);
- grid[r].rowRenderer->setWidth(m_width);
- grid[r].rowRenderer->setHeight(rowPos[r+1] - rowPos[r] - vspacing);
+ if (m_grid[r].rowRenderer) {
+ m_grid[r].rowRenderer->setPos(0, m_rowPos[r]);
+ m_grid[r].rowRenderer->setWidth(m_width);
+ m_grid[r].rowRenderer->setHeight(m_rowPos[r + 1] - m_rowPos[r] - vspacing);
}
for (int c = 0; c < nEffCols; c++) {
- CellStruct current = cellAt(r, c);
- RenderTableCell* cell = current.cell;
+ RenderTableCell* cell = cellAt(r, c).cell;
if (!cell)
continue;
if (r < totalRows - 1 && cell == cellAt(r + 1, c).cell)
continue;
- if ((rindx = r-cell->rowSpan() + 1) < 0)
+ if ((rindx = r - cell->rowSpan() + 1) < 0)
rindx = 0;
- rHeight = rowPos[r + 1] - rowPos[rindx] - vspacing;
+ rHeight = m_rowPos[r + 1] - m_rowPos[rindx] - vspacing;
// Force percent height children to lay themselves out again.
// This will cause these children to grow to fill the cell.
@@ -511,9 +487,8 @@
cell->borderBottom() - cell->paddingBottom()));
cell->layoutIfNeeded();
} else {
- EVerticalAlign va = cell->style()->verticalAlign();
int te = 0;
- switch (va) {
+ switch (cell->style()->verticalAlign()) {
case SUB:
case SUPER:
case TEXT_TOP:
@@ -525,7 +500,7 @@
te = 0;
break;
case MIDDLE:
- te = (rHeight - cell->height())/2;
+ te = (rHeight - cell->height()) / 2;
break;
case BOTTOM:
te = rHeight - cell->height();
@@ -547,13 +522,9 @@
IntRect oldCellRect(cell->xPos(), cell->yPos() - cell->borderTopExtra() , cell->width(), cell->height());
if (style()->direction() == RTL) {
- cell->setPos(
- table()->columnPos[nEffCols] -
- table()->columnPos[table()->colToEffCol(cell->col()+cell->colSpan())] +
- leftOffset,
- rowPos[rindx]);
+ cell->setPos(table()->columnPositions()[nEffCols] - table()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + hspacing, m_rowPos[rindx]);
} else
- cell->setPos(table()->columnPos[c] + leftOffset, rowPos[rindx]);
+ cell->setPos(table()->columnPositions()[c] + hspacing, m_rowPos[rindx]);
// If the cell moved, we have to repaint it as well as any floating/positioned
// descendants. An exception is if we need a layout. In this case, we know we're going to
@@ -563,7 +534,7 @@
}
}
- m_height = rowPos[totalRows];
+ m_height = m_rowPos[totalRows];
return m_height;
}
@@ -573,11 +544,10 @@
if (!includeOverflowInterior && hasOverflowClip())
return bottom;
- for (RenderObject *row = firstChild(); row; row = row->nextSibling()) {
- for (RenderObject *cell = row->firstChild(); cell; cell = cell->nextSibling())
- if (cell->isTableCell()) {
- int bp = cell->yPos() + cell->lowestPosition(false);
- bottom = max(bottom, bp);
+ for (RenderObject* row = firstChild(); row; row = row->nextSibling()) {
+ for (RenderObject* cell = row->firstChild(); cell; cell = cell->nextSibling()) {
+ if (cell->isTableCell())
+ bottom = max(bottom, cell->yPos() + cell->lowestPosition(false));
}
}
@@ -590,11 +560,10 @@
if (!includeOverflowInterior && hasOverflowClip())
return right;
- for (RenderObject *row = firstChild(); row; row = row->nextSibling()) {
- for (RenderObject *cell = row->firstChild(); cell; cell = cell->nextSibling())
- if (cell->isTableCell()) {
- int rp = cell->xPos() + cell->rightmostPosition(false);
- right = max(right, rp);
+ for (RenderObject* row = firstChild(); row; row = row->nextSibling()) {
+ for (RenderObject* cell = row->firstChild(); cell; cell = cell->nextSibling()) {
+ if (cell->isTableCell())
+ right = max(right, cell->xPos() + cell->rightmostPosition(false));
}
}
@@ -607,11 +576,10 @@
if (!includeOverflowInterior && hasOverflowClip())
return left;
- for (RenderObject *row = firstChild(); row; row = row->nextSibling()) {
- for (RenderObject *cell = row->firstChild(); cell; cell = cell->nextSibling())
- if (cell->isTableCell()) {
- int lp = cell->xPos() + cell->leftmostPosition(false);
- left = min(left, lp);
+ for (RenderObject* row = firstChild(); row; row = row->nextSibling()) {
+ for (RenderObject* cell = row->firstChild(); cell; cell = cell->nextSibling()) {
+ if (cell->isTableCell())
+ left = min(left, cell->xPos() + cell->leftmostPosition(false));
}
}
@@ -621,7 +589,7 @@
int RenderTableSection::calcOuterBorderTop() const
{
int totalCols = table()->numEffCols();
- if (gridRows == 0 || totalCols == 0)
+ if (!m_gridRows || !totalCols)
return 0;
unsigned borderWidth = 0;
@@ -674,7 +642,7 @@
int RenderTableSection::calcOuterBorderBottom() const
{
int totalCols = table()->numEffCols();
- if (gridRows == 0 || totalCols == 0)
+ if (!m_gridRows || !totalCols)
return 0;
unsigned borderWidth = 0;
@@ -693,7 +661,7 @@
bool allHidden = true;
for (int c = 0; c < totalCols; c++) {
- const CellStruct& current = cellAt(gridRows - 1, c);
+ const CellStruct& current = cellAt(m_gridRows - 1, c);
if (current.inColSpan || !current.cell)
continue;
const BorderValue& cb = current.cell->style()->borderBottom();
@@ -727,7 +695,7 @@
int RenderTableSection::calcOuterBorderLeft(bool rtl) const
{
int totalCols = table()->numEffCols();
- if (gridRows == 0 || totalCols == 0)
+ if (!m_gridRows || !totalCols)
return 0;
unsigned borderWidth = 0;
@@ -749,7 +717,7 @@
}
bool allHidden = true;
- for (int r = 0; r < gridRows; r++) {
+ for (int r = 0; r < m_gridRows; r++) {
const CellStruct& current = cellAt(r, leftmostColumn);
if (!current.cell)
continue;
@@ -774,7 +742,7 @@
int RenderTableSection::calcOuterBorderRight(bool rtl) const
{
int totalCols = table()->numEffCols();
- if (gridRows == 0 || totalCols == 0)
+ if (!m_gridRows || !totalCols)
return 0;
unsigned borderWidth = 0;
@@ -796,7 +764,7 @@
}
bool allHidden = true;
- for (int r = 0; r < gridRows; r++) {
+ for (int r = 0; r < m_gridRows; r++) {
const CellStruct& current = cellAt(r, rightmostColumn);
if (!current.cell)
continue;
@@ -830,17 +798,17 @@
void RenderTableSection::paint(PaintInfo& paintInfo, int tx, int ty)
{
- unsigned int totalRows = gridRows;
- unsigned int totalCols = table()->columns.size();
+ unsigned totalRows = m_gridRows;
+ unsigned totalCols = table()->columns().size();
- if (totalRows == 0 || totalCols == 0)
+ if (!totalRows || !totalCols)
return;
tx += m_x;
ty += m_y;
- // check which rows and cols are visible and only paint these
- // ### fixme: could use a binary search here
+ // Check which rows and cols are visible and only paint these.
+ // FIXME: Could use a binary search here.
PaintPhase paintPhase = paintInfo.phase;
int x = paintInfo.rect.x();
int y = paintInfo.rect.y();
@@ -848,44 +816,44 @@
int h = paintInfo.rect.height();
int os = 2 * maximalOutlineSize(paintPhase);
- unsigned int startrow = 0;
- unsigned int endrow = totalRows;
+ unsigned startrow = 0;
+ unsigned endrow = totalRows;
for (; startrow < totalRows; startrow++) {
- if (ty + rowPos[startrow+1] >= y - os)
+ if (ty + m_rowPos[startrow + 1] >= y - os)
break;
}
- if (startrow == totalRows && ty + rowPos[totalRows] + table()->outerBorderBottom() >= y - os)
+ if (startrow == totalRows && ty + m_rowPos[totalRows] + table()->outerBorderBottom() >= y - os)
startrow--;
for (; endrow > 0; endrow--) {
- if (ty + rowPos[endrow-1] <= y + h + os)
+ if (ty + m_rowPos[endrow - 1] <= y + h + os)
break;
}
- if (endrow == 0 && ty + rowPos[0] - table()->outerBorderTop() <= y + h + os)
+ if (!endrow && ty + m_rowPos[0] - table()->outerBorderTop() <= y + h + os)
endrow++;
- unsigned int startcol = 0;
- unsigned int endcol = totalCols;
+ unsigned startcol = 0;
+ unsigned endcol = totalCols;
if (style()->direction() == LTR) {
for (; startcol < totalCols; startcol++) {
- if (tx + table()->columnPos[startcol + 1] >= x - os)
+ if (tx + table()->columnPositions()[startcol + 1] >= x - os)
break;
}
- if (startcol == totalCols && tx + table()->columnPos[totalCols] + table()->outerBorderRight() >= x - os)
+ if (startcol == totalCols && tx + table()->columnPositions()[totalCols] + table()->outerBorderRight() >= x - os)
startcol--;
for (; endcol > 0; endcol--) {
- if (tx + table()->columnPos[endcol - 1] <= x + w + os)
+ if (tx + table()->columnPositions()[endcol - 1] <= x + w + os)
break;
}
- if (endcol == 0 && tx + table()->columnPos[0] - table()->outerBorderLeft() <= y + w + os)
+ if (!endcol && tx + table()->columnPositions()[0] - table()->outerBorderLeft() <= y + w + os)
endcol++;
}
if (startcol < endcol) {
// draw the cells
- for (unsigned int r = startrow; r < endrow; r++) {
- unsigned int c = startcol;
+ for (unsigned r = startrow; r < endrow; r++) {
+ unsigned c = startcol;
// since a cell can be -1 (indicating a colspan) we might have to search backwards to include it
while (c && cellAt(r, c).inColSpan)
c--;
@@ -904,11 +872,9 @@
// the column group, column, row group, row, and then the cell.
RenderObject* col = table()->colElement(c);
RenderObject* colGroup = 0;
- if (col) {
- RenderStyle *style = col->parent()->style();
- if (style->display() == TABLE_COLUMN_GROUP)
- colGroup = col->parent();
- }
+ if (col && col->parent()->style()->display() == TABLE_COLUMN_GROUP)
+ colGroup = col->parent();
+
RenderObject* row = cell->parent();
// Column groups and columns first.
@@ -937,39 +903,40 @@
void RenderTableSection::recalcCells()
{
- cCol = 0;
- cRow = -1;
+ m_cCol = 0;
+ m_cRow = -1;
clearGrid();
- gridRows = 0;
+ m_gridRows = 0;
- for (RenderObject *row = firstChild(); row; row = row->nextSibling()) {
+ for (RenderObject* row = firstChild(); row; row = row->nextSibling()) {
if (row->isTableRow()) {
- cRow++;
- cCol = 0;
- ensureRows(cRow + 1);
- grid[cRow].rowRenderer = row;
+ m_cRow++;
+ m_cCol = 0;
+ ensureRows(m_cRow + 1);
+ m_grid[m_cRow].rowRenderer = row;
- for (RenderObject *cell = row->firstChild(); cell; cell = cell->nextSibling())
+ for (RenderObject* cell = row->firstChild(); cell; cell = cell->nextSibling()) {
if (cell->isTableCell())
- addCell(static_cast<RenderTableCell *>(cell), row);
+ addCell(static_cast<RenderTableCell*>(cell), row);
+ }
}
}
- needCellRecalc = false;
+ m_needsCellRecalc = false;
setNeedsLayout(true);
}
void RenderTableSection::clearGrid()
{
- int rows = gridRows;
+ int rows = m_gridRows;
while (rows--)
- delete grid[rows].row;
+ delete m_grid[rows].row;
}
int RenderTableSection::numColumns() const
{
int result = 0;
- for (int r = 0; r < gridRows; ++r) {
+ for (int r = 0; r < m_gridRows; ++r) {
for (int c = result; c < table()->numEffCols(); ++c) {
const CellStruct& cell = cellAt(r, c);
if (cell.cell || cell.inColSpan)
@@ -980,9 +947,32 @@
return result + 1;
}
+void RenderTableSection::appendColumn(int pos)
+{
+ for (int row = 0; row < m_gridRows; ++row) {
+ m_grid[row].row->resize(pos + 1);
+ CellStruct& c = cellAt(row, pos);
+ c.cell = 0;
+ c.inColSpan = false;
+ }
+}
+
+void RenderTableSection::splitColumn(int pos, int newSize)
+{
+ if (m_cCol > pos)
+ m_cCol++;
+ for (int row = 0; row < m_gridRows; ++row) {
+ m_grid[row].row->resize(newSize);
+ Row& r = *m_grid[row].row;
+ memmove(r.data() + pos + 1, r.data() + pos, (newSize - 1 - pos) * sizeof(CellStruct));
+ r[pos + 1].cell = 0;
+ r[pos + 1].inColSpan = r[pos].inColSpan || r[pos].cell;
+ }
+}
+
RenderObject* RenderTableSection::removeChildNode(RenderObject* child)
{
- setNeedCellRecalc();
+ setNeedsCellRecalc();
return RenderContainer::removeChildNode(child);
}
@@ -1009,12 +999,12 @@
}
#ifndef NDEBUG
-void RenderTableSection::dump(TextStream *stream, DeprecatedString ind) const
+void RenderTableSection::dump(TextStream* stream, DeprecatedString ind) const
{
- *stream << endl << ind << "grid=(" << gridRows << "," << table()->numEffCols() << ")" << endl << ind;
- for (int r = 0; r < gridRows; r++) {
+ *stream << endl << ind << "grid=(" << m_gridRows << "," << table()->numEffCols() << ")" << endl << ind;
+ for (int r = 0; r < m_gridRows; r++) {
for (int c = 0; c < table()->numEffCols(); c++) {
- if (cellAt( r, c).cell && !cellAt(r, c).inColSpan)
+ if (cellAt(r, c).cell && !cellAt(r, c).inColSpan)
*stream << "(" << cellAt(r, c).cell->row() << "," << cellAt(r, c).cell->col() << ","
<< cellAt(r, c).cell->rowSpan() << "," << cellAt(r, c).cell->colSpan() << ") ";
else
@@ -1026,4 +1016,4 @@
}
#endif
-}
+} // namespace WebCore