From ab58d64b9fd560b470e0e79e977fcd3c60e32115 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Tue, 16 Jun 2015 20:50:26 +0200 Subject: [PATCH] Repeat thead and tfoot when table contains page breaks This has been done a few times before[0][1], but seems to be broken again as reported in [2]. This commit is only reinstating what's missing from [1]. This was done by running: git log -p -1 2d778f6 | git apply -3 -p6 --directory=src/qt/qtwebkit And resolving the conflicts. There are still some compile errors. These will be fixed in the upcoming commits instead of in this one to clarify the changes. This change doesn't completely fix the issue. The thead/tfoot block is drawn again on the next page, however the other content is not shifted down accordingly. This means that the thead/tfoot block on the next page will be placed on top of the continued table instead of above it. [0]: https://github.com/ariya/phantomjs/pull/211 [1]: https://github.com/ariya/phantomjs/pull/344 [2]: https://github.com/ariya/phantomjs/issues/13324 --- .../Source/WebCore/rendering/RenderTable.cpp | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/qt/qtwebkit/Source/WebCore/rendering/RenderTable.cpp b/src/qt/qtwebkit/Source/WebCore/rendering/RenderTable.cpp index ab56cabcb7..ca9c8c0bb0 100644 --- a/src/qt/qtwebkit/Source/WebCore/rendering/RenderTable.cpp +++ b/src/qt/qtwebkit/Source/WebCore/rendering/RenderTable.cpp @@ -670,7 +670,59 @@ void RenderTable::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOffs child->paint(info, childPoint); } } - + + bool repaintedHead = false; + IntPoint repaintedHeadPoint; + bool repaintedFoot = false; + IntPoint repaintedFootPoint; + if (view()->pageLogicalHeight()) { + // re-paint header/footer if table is split over multiple pages + if (m_head) { + IntPoint childPoint = flipForWritingMode(m_head, IntPoint(tx, ty), ParentToChildFlippingAdjustment); + if (!info.rect.contains(childPoint.x() + m_head->x(), childPoint.y() + m_head->y())) { + repaintedHeadPoint = IntPoint(childPoint.x(), info.rect.y() - m_head->y()); + repaintedHead = true; + dynamic_cast(m_head)->paint(info, repaintedHeadPoint.x(), repaintedHeadPoint.y()); + } + } + if (m_foot) { + IntPoint childPoint = flipForWritingMode(m_foot, IntPoint(tx, ty), ParentToChildFlippingAdjustment); + if (!info.rect.contains(childPoint.x() + m_foot->x(), childPoint.y() + m_foot->y())) { + // find actual end of table on current page + int dy = 0; + const int max_dy = info.rect.y() + info.rect.height(); + const int vspace = vBorderSpacing(); + for (RenderObject* section = firstChild(); section; section = section->nextSibling()) { + if (section->isTableSection()) { + if (toRenderBox(section)->y() > max_dy) { + continue; + } + int i = 0; + for(RenderObject* row = section->firstChild(); row; row = row->nextSibling()) { + if (!row->isTableRow()) { + continue; + } + // get actual bottom-y position of this row - pretty complicated, how could this be simplified? + // note how we have to take the rowPoint and section's y-offset into account, see e.g. + // RenderTableSection::paint where this is also done... + IntPoint rowPoint = flipForWritingMode(toRenderBox(row), IntPoint(tx, ty), ParentToChildFlippingAdjustment); + int row_dy = rowPoint.y() + toRenderBox(row)->y() + toRenderBox(row)->logicalHeight() + toRenderBox(section)->y(); + if (row_dy < max_dy && row_dy > dy) { + dy = row_dy; + } else if (row_dy > max_dy) { + break; + } + i++; + } + } + } + repaintedFoot = true; + repaintedFootPoint = IntPoint(childPoint.x(), dy - m_foot->y()); + dynamic_cast(m_foot)->paint(info, repaintedFootPoint.x(), repaintedFootPoint.y()); + } + } + } + if (collapseBorders() && paintPhase == PaintPhaseChildBlockBackground && style()->visibility() == VISIBLE) { recalcCollapsedBorders(); // Using our cached sorted styles, we then do individual passes, @@ -681,6 +733,12 @@ void RenderTable::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOffs m_currentBorder = &m_collapsedBorders[i]; for (RenderTableSection* section = bottomSection(); section; section = sectionAbove(section)) { LayoutPoint childPoint = flipForWritingModeForChild(section, paintOffset); + // also repaint borders of header/footer if required + if (section == m_head && repaintedHead) { + childPoint = repaintedHeadPoint; + } else if (section == m_foot && repaintedFoot) { + childPoint = repaintedFootPoint; + } section->paint(info, childPoint); } }