Skip to content

Commit

Permalink
Prevent page breaks in table rows.
Browse files Browse the repository at this point in the history
This was part of a previous PhantomJS release but got reverted
when the Qt source tree was imported. See the old pull request
here: ariya#211

http://code.google.com/p/phantomjs/issues/detail?id=880
  • Loading branch information
milianw committed Nov 22, 2012
1 parent 9ba13ba commit 5c87852
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,8 @@ void RenderBlock::layoutRunsAndFloats(bool fullLayout, bool hasInlineChild, Vect
repaintLogicalBottom = max(repaintLogicalBottom, lineBox->logicalBottomVisualOverflow());
}

if (paginated) {
// table cell pagination is handled in RenderTableSection
if (paginated && !isTableCell()) {
int adjustment = 0;
adjustLinePositionForPagination(lineBox, adjustment);
if (adjustment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,40 @@ int RenderTableSection::layoutRows(int toAdd)

LayoutStateMaintainer statePusher(view(), this, IntSize(x(), y()), style()->isFlippedBlocksWritingMode());

WTF::Vector<int> logicalHeightsForPrinting;
// make sure that rows do not overlap a page break
if (view()->layoutState()->pageLogicalHeight()) {
logicalHeightsForPrinting.resize(totalRows);
int pageOffset = 0;
for(int r = 0; r < totalRows; ++r) {
const int childLogicalHeight = m_rowPos[r + 1] - m_rowPos[r] - (m_grid[r].rowRenderer ? vspacing : 0);
logicalHeightsForPrinting[r] = childLogicalHeight;
LayoutState* layoutState = view()->layoutState();
const int pageLogicalHeight = layoutState->m_pageLogicalHeight;
if (childLogicalHeight < pageLogicalHeight) {
const IntSize delta = layoutState->m_layoutOffset - layoutState->m_pageOffset;
const int logicalOffset = m_rowPos[r] + pageOffset;
const int offset = isHorizontalWritingMode() ? delta.height() : delta.width();
const int remainingLogicalHeight = (pageLogicalHeight - (offset + logicalOffset) % pageLogicalHeight) % pageLogicalHeight;
if (remainingLogicalHeight < childLogicalHeight) {
pageOffset += remainingLogicalHeight;
}
}
m_rowPos[r] += pageOffset;
}
m_rowPos[totalRows] += pageOffset;
}

for (int r = 0; r < totalRows; r++) {
// Set the row's x/y position and width/height.
if (RenderTableRow* rowRenderer = m_grid[r].rowRenderer) {
rowRenderer->setLocation(0, m_rowPos[r]);
rowRenderer->setLogicalWidth(logicalWidth());
rowRenderer->setLogicalHeight(m_rowPos[r + 1] - m_rowPos[r] - vspacing);
if (view()->layoutState()->pageLogicalHeight()) {
rowRenderer->setLogicalHeight(logicalHeightsForPrinting[r]);
} else {
rowRenderer->setLogicalHeight(m_rowPos[r + 1] - m_rowPos[r] - vspacing);
}
rowRenderer->updateLayerTransform();
}

Expand All @@ -513,7 +541,11 @@ int RenderTableSection::layoutRows(int toAdd)
continue;

rindx = cell->row();
rHeight = m_rowPos[rindx + cell->rowSpan()] - m_rowPos[rindx] - vspacing;
if (view()->layoutState()->pageLogicalHeight() && cell->rowSpan() == 1) {
rHeight = logicalHeightsForPrinting[rindx];
} else {
rHeight = m_rowPos[rindx + cell->rowSpan()] - m_rowPos[rindx] - vspacing;
}

// Force percent height children to lay themselves out again.
// This will cause these children to grow to fill the cell.
Expand Down

0 comments on commit 5c87852

Please sign in to comment.