From 28b9e9b1d4f1fa6c49a4e9774683a1ed06ee8040 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Thu, 30 Mar 2017 22:56:14 -0400 Subject: [PATCH] Bug 1351359 - Make nsGridContainerFrame call ReflowInput::SetBResize(true) because of auto-block-size swapping between measuring reflows and regular reflows. r=mats This fixes the failure of layout/reftests/css-grid/grid-min-max-content-sizing-002.html with the primary patch in bug 1308876 (which causes a child whose parent is dirty to pick up the dirty bit from the parent only the first reflow of the child if the parent reflows the child multiple times). A simplified testcase for that failure is https://bugzilla.mozilla.org/attachment.cgi?id=8849771 . The failure was caused by an error in height calculation of the first in the test. The div that is the parent of that x has a definite height (presumably due to rules in grid), and the x has a specified height. The div gets three reflows: two measuring reflows (from MinContentContribution and then from MaxContentContribution) and then a final reflow from nsGridContainerFrame::ReflowInFlowChild. Prior to the primary patch in this bug, the div was marked dirty on all three reflows, but with it it is marked dirty only on the first. This means that, without the block-resize flag, the div optimizes away the reflow of its children, since ShouldReflowAllKids returns false because IsBResize() is false, even though NS_FRAME_CONTAINS_RELATIVE_BSIZE is correctly set. In order to fix this, we need to make sure the BResize flag on the reflow state in at least some cases (see the comments in the patch for when, and for how the cases could be optimized in the future). Note that: * when the dirty bit is set on the grid container, the new behavior (with the combination of the patches) is strictly more efficient than the old, since we will sometimes do non-dirty reflows on the grid items (with the b-resize flag) * when the dirty bit is *not* set on the grid container, the new behavior is less efficient than the old, since we will set the b-resize flag when we did not do so before. However, this slowdown fixes existing bugs such as the one in the reftest. Given that I was able to construct a reftest that triggers the failure without the changes from bug 1308876, I've moved this to a separate bug. Without the patch, grid-measuring-reflow-resize-dynamic-001.html fails, but grid-measuring-reflow-resize-static-001.html passes. With the patch both tests pass. (And without the patch, doing a text zoom on the dynamic test fixes the layout error.) MozReview-Commit-ID: JQOdVTQIkU0 --HG-- extra : transplant_source : %8B%2ARO%3B%D0%7B%EC%C9_%B3%60Sp%F9T%14X%85%DC --- layout/generic/nsGridContainerFrame.cpp | 19 ++++++++++ .../grid-measuring-reflow-resize-001-ref.html | 24 ++++++++++++ ...d-measuring-reflow-resize-dynamic-001.html | 37 +++++++++++++++++++ ...id-measuring-reflow-resize-static-001.html | 32 ++++++++++++++++ layout/reftests/css-grid/reftest.list | 2 + 5 files changed, 114 insertions(+) create mode 100644 layout/reftests/css-grid/grid-measuring-reflow-resize-001-ref.html create mode 100644 layout/reftests/css-grid/grid-measuring-reflow-resize-dynamic-001.html create mode 100644 layout/reftests/css-grid/grid-measuring-reflow-resize-static-001.html diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index 6113f05d09db..b26e80e37616 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -3712,6 +3712,16 @@ MeasuringReflow(nsIFrame* aChild, aChild->Properties().Delete(nsIFrame::BClampMarginBoxMinSizeProperty()); } ReflowInput childRI(pc, *rs, aChild, aAvailableSize, &aCBSize, riFlags); + + // Because we pass ReflowInput::COMPUTE_SIZE_USE_AUTO_BSIZE, and the + // previous reflow of the child might not have, set the child's + // block-resize flag to true. + // FIXME (perf): It would be faster to do this only if the previous + // reflow of the child was not a measuring reflow, and only if the + // child does some of the things that are affected by + // ReflowInput::COMPUTE_SIZE_USE_AUTO_BSIZE. + childRI.SetBResize(true); + ReflowOutput childSize(childRI); nsReflowStatus childStatus; const uint32_t flags = NS_FRAME_NO_MOVE_FRAME | NS_FRAME_NO_SIZE_VIEW; @@ -5241,6 +5251,15 @@ nsGridContainerFrame::ReflowInFlowChild(nsIFrame* aChild, &percentBasis, flags); childRI.mFlags.mIsTopOfPage = aFragmentainer ? aFragmentainer->mIsTopOfPage : false; + // Because we pass ReflowInput::COMPUTE_SIZE_USE_AUTO_BSIZE, and the + // previous reflow of the child might not have, set the child's + // block-resize flag to true. + // FIXME (perf): It would be faster to do this only if the previous + // reflow of the child was a measuring reflow, and only if the child + // does some of the things that are affected by + // ReflowInput::COMPUTE_SIZE_USE_AUTO_BSIZE. + childRI.SetBResize(true); + // A table-wrapper needs to propagate the CB size we give it to its // inner table frame later. @see nsTableWrapperFrame::InitChildReflowInput. if (childType == nsGkAtoms::tableWrapperFrame) { diff --git a/layout/reftests/css-grid/grid-measuring-reflow-resize-001-ref.html b/layout/reftests/css-grid/grid-measuring-reflow-resize-001-ref.html new file mode 100644 index 000000000000..ab6732819cd9 --- /dev/null +++ b/layout/reftests/css-grid/grid-measuring-reflow-resize-001-ref.html @@ -0,0 +1,24 @@ + +Testcase simplified from layout/reftests/css-grid/grid-min-max-content-sizing-002.html + + +
+ blue should overflow fuchsia on right/bottom +
diff --git a/layout/reftests/css-grid/grid-measuring-reflow-resize-dynamic-001.html b/layout/reftests/css-grid/grid-measuring-reflow-resize-dynamic-001.html new file mode 100644 index 000000000000..43a5791991ed --- /dev/null +++ b/layout/reftests/css-grid/grid-measuring-reflow-resize-dynamic-001.html @@ -0,0 +1,37 @@ + +Testcase simplified from layout/reftests/css-grid/grid-min-max-content-sizing-002.html + + +
+
+ +
+
+ + diff --git a/layout/reftests/css-grid/grid-measuring-reflow-resize-static-001.html b/layout/reftests/css-grid/grid-measuring-reflow-resize-static-001.html new file mode 100644 index 000000000000..2cb510c918ed --- /dev/null +++ b/layout/reftests/css-grid/grid-measuring-reflow-resize-static-001.html @@ -0,0 +1,32 @@ + +Testcase simplified from layout/reftests/css-grid/grid-min-max-content-sizing-002.html + + +
+
+ blue should overflow fuchsia on right/bottom +
+
+ diff --git a/layout/reftests/css-grid/reftest.list b/layout/reftests/css-grid/reftest.list index 68910fa9ee49..8c7b2bbca73b 100644 --- a/layout/reftests/css-grid/reftest.list +++ b/layout/reftests/css-grid/reftest.list @@ -275,3 +275,5 @@ asserts(1-10) == grid-fragmentation-dyn4-021.html grid-fragmentation-021-ref.htm == grid-fragmentation-dyn2-031.html grid-fragmentation-031-ref.html == bug1306106.html bug1306106-ref.html == grid-percent-intrinsic-sizing-001.html grid-percent-intrinsic-sizing-001-ref.html +== grid-measuring-reflow-resize-static-001.html grid-measuring-reflow-resize-001-ref.html +== grid-measuring-reflow-resize-dynamic-001.html grid-measuring-reflow-resize-001-ref.html