Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Unified Diff: Source/core/rendering/RenderTableSection.cpp

Issue 18050007: Height of fixed height cell is not proper when cell's row is under row spanning cell. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review comments addressed Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/rendering/RenderTableSection.cpp
diff --git a/Source/core/rendering/RenderTableSection.cpp b/Source/core/rendering/RenderTableSection.cpp
index 41ad27591186675bdfe59ef7837d5c6d0c22ba4a..24904de9bf684523310ae37924607fa1ba8739e1 100644
--- a/Source/core/rendering/RenderTableSection.cpp
+++ b/Source/core/rendering/RenderTableSection.cpp
@@ -255,6 +255,102 @@ void RenderTableSection::addCell(RenderTableCell* cell, RenderTableRow* row)
cell->setCol(table()->effColToCol(col));
}
+void RenderTableSection::calcRowsHeightInRowSpan(RenderTableCell* cell, struct SpanningRowsHeight& spanningRowsHeight)
Julien - ping for review 2013/07/16 17:22:13 Not a huge fan of the name (calc is an abbreviatio
a.suchit 2013/07/18 17:05:32 Done.
+{
+ const unsigned rowSpan = cell->rowSpan();
+ const unsigned rowIndex = cell->rowIndex();
+
+ spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing = cell->logicalHeightForRowSizing();
+
+ spanningRowsHeight.rowHeight.resize(rowSpan);
+ spanningRowsHeight.totalRowsHeight = 0;
+ for (unsigned row = 0; row < rowSpan; row++) {
+ unsigned actualRow = row + rowIndex;
+ spanningRowsHeight.rowHeight[row] = m_rowPos[actualRow + 1] - m_rowPos[actualRow] - borderSpacingForRow(actualRow);
+ spanningRowsHeight.totalRowsHeight += spanningRowsHeight.rowHeight[row];
+ spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing -= borderSpacingForRow(actualRow);
+ }
+ spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing += borderSpacingForRow(rowIndex + rowSpan - 1);
Julien - ping for review 2013/07/16 17:22:13 This is typically the line of code that would requ
a.suchit 2013/07/18 17:05:32 Done.
+}
+
+void RenderTableSection::distributeExtraRowSpanHeightToPercentRows(RenderTableCell* cell, int tableHeight, int totalPercent, int& extraRowSpanningHeight)
+{
+ if (!extraRowSpanningHeight || !totalPercent)
+ return;
+
+ const unsigned rowSpan = cell->rowSpan();
+ const unsigned rowIndex = cell->rowIndex();
+ int percent = min(totalPercent, 100);
+ int remainingRowSpanningHeight = extraRowSpanningHeight;
Julien - ping for review 2013/07/16 17:22:13 tableHeight + extraRowSpanningHeight is the only r
a.suchit 2013/07/18 17:05:32 Done.
+
+ int accumulatedPositionIncrease = 0;
+ for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) {
+ if (percent > 0 && remainingRowSpanningHeight > 0) {
+ if (m_grid[row].logicalHeight.isPercent()) {
+ int toAdd = (tableHeight + extraRowSpanningHeight) * m_grid[row].logicalHeight.percent() / 100;
Julien - ping for review 2013/07/16 17:22:13 The whole algorithm really need some explanations,
+
+ toAdd = min(toAdd, remainingRowSpanningHeight);
+ accumulatedPositionIncrease += toAdd;
+ remainingRowSpanningHeight -= toAdd;
+ percent -= m_grid[row].logicalHeight.percent();
+ }
+ }
+ m_rowPos[row + 1] += accumulatedPositionIncrease;
+ }
+
+ extraRowSpanningHeight = remainingRowSpanningHeight;
+}
+
+void RenderTableSection::distributeExtraRowSpanHeightToAutoRows(RenderTableCell* cell, int totalAutoRowsHeight, int& extraRowSpanningHeight, Vector<int>& rowsHeight)
+{
+ if (!extraRowSpanningHeight || !totalAutoRowsHeight)
+ return;
+
+ const unsigned rowSpan = cell->rowSpan();
+ const unsigned rowIndex = cell->rowIndex();
+ int accumulatedPositionIncrease = 0;
+
+ for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) {
+ if (m_grid[row].logicalHeight.isAuto())
+ accumulatedPositionIncrease += (extraRowSpanningHeight * rowsHeight[row - rowIndex]) / totalAutoRowsHeight;
+ m_rowPos[row + 1] += accumulatedPositionIncrease;
+ }
+
+ extraRowSpanningHeight -= accumulatedPositionIncrease;
+
+ // FIXME: In some cases extraRowSpanning height is remain which is very small and cannot be again distributed in
+ // spanning rows. So this remaining height added to last spanning row to maintain the spanning cell height and
+ // set extra row spanning height to 0.
+ // Value should be round properly in the algorithm.
+ m_rowPos[rowIndex + rowSpan] += extraRowSpanningHeight;
+ extraRowSpanningHeight = 0;
+}
+
+void RenderTableSection::distributeExtraRowSpanHeightToRemainingRows(RenderTableCell* cell, int totalRemainingRowsHeight, int& extraRowSpanningHeight, Vector<int>& rowsHeight)
+{
+ if (!extraRowSpanningHeight || !totalRemainingRowsHeight)
+ return;
+
+ const unsigned rowSpan = cell->rowSpan();
+ const unsigned rowIndex = cell->rowIndex();
+ int accumulatedPositionIncrease = 0;
+
+ for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) {
+ if (!m_grid[row].logicalHeight.isPercent())
+ accumulatedPositionIncrease += (extraRowSpanningHeight * rowsHeight[row - rowIndex]) / totalRemainingRowsHeight;
+ m_rowPos[row + 1] += accumulatedPositionIncrease;
+ }
+
+ extraRowSpanningHeight -= accumulatedPositionIncrease;
+
+ // FIXME: In some cases extraRowSpanning height is remain which is very small and cannot be again distributed in
+ // spanning rows. So this remaining height added to last spanning row to maintain the spanning cell height and
+ // set extra row spanning height to 0.
+ // Value should be round properly in the algorithm.
Julien - ping for review 2013/07/16 17:22:13 Can't we do the rounding properly instead of swipi
a.suchit 2013/07/18 17:05:32 Done.
+ m_rowPos[rowIndex + rowSpan] += extraRowSpanningHeight;
+ extraRowSpanningHeight = 0;
+}
+
// Distribute rowSpan cell height in rows those comes in rowSpan cell based on the ratio of row's height if
// 1. RowSpan cell height is greater then the total height of rows in rowSpan cell
void RenderTableSection::distributeRowSpanHeightToRows(SpanningRenderTableCells& rowSpanCells)
@@ -265,38 +361,38 @@ void RenderTableSection::distributeRowSpanHeightToRows(SpanningRenderTableCells&
RenderTableCell* cell = rowSpanCells[0];
unsigned rowSpan = cell->rowSpan();
- unsigned rowIndex = cell->rowIndex();
- int initialPos = m_rowPos[rowIndex + rowSpan];
- int totalRowsHeight = 0;
- int rowSpanCellHeight = cell->logicalHeightForRowSizing();
- Vector<int> rowsHeight(rowSpan);
+ struct SpanningRowsHeight spanningRowsHeight;
- // Getting height of rows in current rowSpan cell, getting total height of rows and adjusting rowSpan cell height with border spacing.
- for (unsigned row = 0; row < rowSpan; row++) {
- unsigned actualRow = row + rowIndex;
- rowsHeight[row] = m_rowPos[actualRow + 1] - m_rowPos[actualRow] - borderSpacingForRow(actualRow);
- totalRowsHeight += rowsHeight[row];
- rowSpanCellHeight -= borderSpacingForRow(actualRow);
- }
- rowSpanCellHeight += borderSpacingForRow(rowIndex + rowSpan - 1);
+ calcRowsHeightInRowSpan(cell, spanningRowsHeight);
- if (!totalRowsHeight || rowSpanCellHeight <= totalRowsHeight)
+ if (!spanningRowsHeight.totalRowsHeight || spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing <= spanningRowsHeight.totalRowsHeight)
return;
- // Recalculating the height of rows based on rowSpan cell height if rowSpan cell height is more than total height of rows.
- int remainingHeight = rowSpanCellHeight;
+ unsigned rowIndex = cell->rowIndex();
+ int totalPercent = 0;
+ int totalAutoRowsHeight = 0;
+ int totalRemainingRowsHeight = spanningRowsHeight.totalRowsHeight;
+ // Calculate total percentage, total auto rows height and total rows height except percent rows.
for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) {
- int rowHeight = (rowSpanCellHeight * rowsHeight[row - rowIndex]) / totalRowsHeight;
- remainingHeight -= rowHeight;
- m_rowPos[row + 1] = m_rowPos[row] + rowHeight + borderSpacingForRow(row);
+ if (m_grid[row].logicalHeight.isPercent()) {
+ totalPercent += m_grid[row].logicalHeight.percent();
+ totalRemainingRowsHeight -= spanningRowsHeight.rowHeight[row - rowIndex];
+ } else if (m_grid[row].logicalHeight.isAuto()) {
+ totalAutoRowsHeight += spanningRowsHeight.rowHeight[row - rowIndex];
+ }
}
- // Remaining height added in the last row under rowSpan cell
- m_rowPos[rowIndex + rowSpan] += remainingHeight;
+
+ int initialPos = m_rowPos[rowIndex + rowSpan];
+ int extraRowSpanningHeight = spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing - spanningRowsHeight.totalRowsHeight;
+
+ distributeExtraRowSpanHeightToPercentRows(cell, m_rowPos[m_grid.size()], totalPercent, extraRowSpanningHeight);
+ distributeExtraRowSpanHeightToAutoRows(cell, totalAutoRowsHeight, extraRowSpanningHeight, spanningRowsHeight.rowHeight);
+ distributeExtraRowSpanHeightToRemainingRows(cell, totalRemainingRowsHeight, extraRowSpanningHeight, spanningRowsHeight.rowHeight);
Julien - ping for review 2013/07/16 17:22:13 The ASSERT was really important, what I wasn't hap
a.suchit 2013/07/18 17:05:32 Done.
// Getting total changed height in the table
- unsigned changedHeight = changedHeight = m_rowPos[rowIndex + rowSpan] - initialPos;
+ unsigned changedHeight = m_rowPos[rowIndex + rowSpan] - initialPos;
if (changedHeight) {
unsigned totalRows = m_grid.size();
« Source/core/rendering/RenderTableSection.h ('K') | « Source/core/rendering/RenderTableSection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698