From 24657db6290c7bbd3829cc38ff3321a725218dc1 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Fri, 23 Oct 2020 10:36:09 +0000 Subject: [layout] Avoid negative availSize.BSizes in paginated table reflow. --- layout/tables/nsTableFrame.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'layout/tables') diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp index 59a6d0f1a..6d3527307 100644 --- a/layout/tables/nsTableFrame.cpp +++ b/layout/tables/nsTableFrame.cpp @@ -104,6 +104,14 @@ struct TableReflowInput { availSize.BSize(wm) = std::max(0, availSize.BSize(wm)); } } + + void ReduceAvailableBSizeBy(WritingMode aWM, nscoord aAmount) { + if (availSize.BSize(aWM) == NS_UNCONSTRAINEDSIZE) { + return; + } + availSize.BSize(aWM) -= aAmount; + availSize.BSize(aWM) = std::max(0, availSize.BSize(aWM)); + } }; } // namespace mozilla @@ -2682,9 +2690,7 @@ nsTableFrame::PlaceChild(TableReflowInput& aReflowInput, aReflowInput.bCoord += aKidDesiredSize.BSize(wm); // If our bsize is constrained, then update the available bsize - if (NS_UNCONSTRAINEDSIZE != aReflowInput.availSize.BSize(wm)) { - aReflowInput.availSize.BSize(wm) -= aKidDesiredSize.BSize(wm); - } + aReflowInput.ReduceAvailableBSizeBy(wm, aKidDesiredSize.BSize(wm)); } void @@ -3004,9 +3010,7 @@ nsTableFrame::ReflowChildren(TableReflowInput& aReflowInput, kidReflowInput.mFlags.mIsTopOfPage = false; } aReflowInput.bCoord += cellSpacingB; - if (NS_UNCONSTRAINEDSIZE != aReflowInput.availSize.BSize(wm)) { - aReflowInput.availSize.BSize(wm) -= cellSpacingB; - } + aReflowInput.ReduceAvailableBSizeBy(wm, cellSpacingB); // record the presence of a next in flow, it might get destroyed so we // need to reorder the row group array bool reorder = false; @@ -3171,9 +3175,7 @@ nsTableFrame::ReflowChildren(TableReflowInput& aReflowInput, aReflowInput.bCoord += kidRect.BSize(wm); // If our bsize is constrained then update the available bsize. - if (NS_UNCONSTRAINEDSIZE != aReflowInput.availSize.BSize(wm)) { - aReflowInput.availSize.BSize(wm) -= cellSpacingB + kidRect.BSize(wm); - } + aReflowInput.ReduceAvailableBSizeBy(wm, cellSpacingB + kidRect.BSize(wm)); } } -- cgit v1.2.3 From fcc0241430167671b9049b8e6eebcbff0b587b21 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Fri, 23 Oct 2020 11:10:13 +0000 Subject: [layout] Re-order rowgroups if reflowing. This logic was missing for tfoot. See existing code in second hunk. --- layout/tables/nsTableFrame.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'layout/tables') diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp index 6d3527307..eb8efb0ec 100644 --- a/layout/tables/nsTableFrame.cpp +++ b/layout/tables/nsTableFrame.cpp @@ -2934,17 +2934,28 @@ nsTableFrame::ReflowChildren(TableReflowInput& aReflowInput, // using the footer's prev-in-flow's height instead of reflowing it again, // but there's no real need. if (isPaginated) { + bool reorder = false; if (thead && !GetPrevInFlow()) { + if (thead->GetNextInFlow()) { + reorder = true; + } nscoord desiredHeight; nsresult rv = SetupHeaderFooterChild(aReflowInput, thead, &desiredHeight); if (NS_FAILED(rv)) return; } if (tfoot) { + if (tfoot->GetNextInFlow()) { + reorder = true; + } nsresult rv = SetupHeaderFooterChild(aReflowInput, tfoot, &footerHeight); if (NS_FAILED(rv)) return; } + if (reorder) { + // Reorder row groups, because the reflow may have changed what's next-in-flow. + OrderRowGroups(rowGroups, &thead, &tfoot); + } } // if the child is a tbody in paginated mode reduce the height by a repeated footer bool allowRepeatedFooter = false; @@ -3014,8 +3025,9 @@ nsTableFrame::ReflowChildren(TableReflowInput& aReflowInput, // record the presence of a next in flow, it might get destroyed so we // need to reorder the row group array bool reorder = false; - if (kidFrame->GetNextInFlow()) + if (kidFrame->GetNextInFlow()) { reorder = true; + } LogicalPoint kidPosition(wm, aReflowInput.iCoord, aReflowInput.bCoord); ReflowChild(kidFrame, presContext, desiredSize, kidReflowInput, @@ -3023,7 +3035,7 @@ nsTableFrame::ReflowChildren(TableReflowInput& aReflowInput, kidReflowInput.ApplyRelativePositioning(&kidPosition, containerSize); if (reorder) { - // reorder row groups the reflow may have changed the nextinflows + // Reorder row groups, because the reflow may have changed what's next-in-flow. OrderRowGroups(rowGroups, &thead, &tfoot); childX = rowGroups.IndexOf(kidFrame); if (childX == RowGroupArray::NoIndex) { -- cgit v1.2.3