Bug 1291110 Part 3 - Enforce float available space never grow on either side. draft
authorTing-Yu Lin <tlin@mozilla.com>
Tue, 08 Nov 2016 15:20:58 +0800
changeset 436963 07cf7b6315f2b8360f8e8cb052d37fdbeb34c40f
parent 435284 fa7a8ff8b85cb627c3a2ec9dfda832a076169ea9
child 436964 d1b79d342d375ff470ca51de36b6d023491ecaec
push id35259
push userbmo:tlin@mozilla.com
push dateThu, 10 Nov 2016 03:46:52 +0000
bugs1291110
milestone52.0a1
Bug 1291110 Part 3 - Enforce float available space never grow on either side. This patch is based on bug 1291110 comment 29, but |aCanGrow| is preserved, since the set of float available spaces we'll be testing in Part 4 are difference from the one we enforced here. MozReview-Commit-ID: LswbIaRukVR
layout/generic/nsBlockFrame.cpp
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -4481,16 +4481,31 @@ nsBlockFrame::PlaceLine(BlockReflowInput
   aFloatAvailableSpace =
     aState.GetFloatAvailableSpaceForBSize(aLine->BStart(),
                                           aAvailableSpaceBSize,
                                           aFloatStateBeforeLine).mRect;
   NS_ASSERTION(aFloatAvailableSpace.BStart(wm) ==
                oldFloatAvailableSpace.BStart(wm), "yikes");
   // Restore the BSize to the position of the next band.
   aFloatAvailableSpace.BSize(wm) = oldFloatAvailableSpace.BSize(wm);
+
+  // Enforce both IStart() and IEnd() never move outwards to prevent
+  // infinite grow-shrink loops.
+  const nscoord iStartDiff =
+    aFloatAvailableSpace.IStart(wm) - oldFloatAvailableSpace.IStart(wm);
+  const nscoord iEndDiff =
+    aFloatAvailableSpace.IEnd(wm) - oldFloatAvailableSpace.IEnd(wm);
+  if (iStartDiff < 0) {
+    aFloatAvailableSpace.IStart(wm) -= iStartDiff;
+    aFloatAvailableSpace.ISize(wm) += iStartDiff;
+  }
+  if (iEndDiff > 0) {
+    aFloatAvailableSpace.ISize(wm) -= iEndDiff;
+  }
+
   // If the available space between the floats is smaller now that we
   // know the BSize, return false (and cause another pass with
   // LineReflowStatus::RedoMoreFloats).  We ensure aAvailableSpaceBSize
   // never decreases, which means that we can't reduce the set of floats
   // we intersect, which means that the available space cannot grow.
   if (AvailableSpaceShrunk(wm, oldFloatAvailableSpace, aFloatAvailableSpace,
                            false)) {
     return false;