Bug 1471894 Part 1: Ensure that absolute positioned blocks with auto margins update their UsedMargin property. r=dholbert
☠☠ backed out by 2f009f26663d ☠ ☠
authorBrad Werth <bwerth@mozilla.com>
Wed, 11 Jul 2018 16:52:33 -0700
changeset 482954 9a6e53d96b83b4c44eeb21f823121a532fc2e5b0
parent 482953 d126a6593e8f3db13211170a90c11dd69763fc70
child 482955 82b13a9a70e618cde0c76ce69498767dfe0d984b
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1471894
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1471894 Part 1: Ensure that absolute positioned blocks with auto margins update their UsedMargin property. r=dholbert MozReview-Commit-ID: EFIQVvazkTg
layout/generic/ReflowInput.cpp
--- a/layout/generic/ReflowInput.cpp
+++ b/layout/generic/ReflowInput.cpp
@@ -1232,26 +1232,30 @@ ReflowInput::CalculateBorderPaddingMargi
   nsMargin styleMargin;
   if (mStyleMargin->GetMargin(styleMargin)) {
     marginStartEnd =
       styleMargin.Side(startSide) + styleMargin.Side(endSide);
   } else {
     nscoord start, end;
     // We have to compute the start and end values
     if (eStyleUnit_Auto == mStyleMargin->mMargin.GetUnit(startSide)) {
-      // XXX FIXME (or does CalculateBlockSideMargins do this?)
-      start = 0;  // just ignore
+      // We set this to 0 for now, and fix it up later in
+      // InitAbsoluteConstraints (which is caller of this function, via
+      // CalculateHypotheticalPosition).
+      start = 0;
     } else {
       start = nsLayoutUtils::
         ComputeCBDependentValue(aContainingBlockSize,
                                 mStyleMargin->mMargin.Get(startSide));
     }
     if (eStyleUnit_Auto == mStyleMargin->mMargin.GetUnit(endSide)) {
-      // XXX FIXME (or does CalculateBlockSideMargins do this?)
-      end = 0;  // just ignore
+      // We set this to 0 for now, and fix it up later in
+      // InitAbsoluteConstraints (which is caller of this function, via
+      // CalculateHypotheticalPosition).
+      end = 0;
     } else {
       end = nsLayoutUtils::
         ComputeCBDependentValue(aContainingBlockSize,
                                 mStyleMargin->mMargin.Get(endSide));
     }
     marginStartEnd = start + end;
   }
 
@@ -1760,16 +1764,20 @@ ReflowInput::InitAbsoluteConstraints(nsP
   // XXX Now that we have ComputeSize, can we condense many of the
   // branches off of widthIsAuto?
 
   LogicalMargin margin = ComputedLogicalMargin().ConvertTo(cbwm, wm);
   const LogicalMargin borderPadding =
     ComputedLogicalBorderPadding().ConvertTo(cbwm, wm);
 
   bool iSizeIsAuto = eStyleUnit_Auto == mStylePosition->ISize(cbwm).GetUnit();
+  bool marginIStartIsAuto = false;
+  bool marginIEndIsAuto = false;
+  bool marginBStartIsAuto = false;
+  bool marginBEndIsAuto = false;
   if (iStartIsAuto) {
     // We know 'right' is not 'auto' anymore thanks to the hypothetical
     // box code above.
     // Solve for 'left'.
     if (iSizeIsAuto) {
       // XXXldb This, and the corresponding code in
       // nsAbsoluteContainingBlock.cpp, could probably go away now that
       // we always compute widths.
@@ -1830,19 +1838,19 @@ ReflowInput::InitAbsoluteConstraints(nsP
     // shrink-wrap) in case:
     //  * inline-size was specified
     //  * we're dealing with a replaced element
     //  * width was constrained by min- or max-inline-size.
 
     nscoord availMarginSpace =
       aCBSize.ISize(cbwm) - offsets.IStartEnd(cbwm) - margin.IStartEnd(cbwm) -
       borderPadding.IStartEnd(cbwm) - computedSize.ISize(cbwm);
-    bool marginIStartIsAuto =
+    marginIStartIsAuto =
       eStyleUnit_Auto == mStyleMargin->mMargin.GetIStartUnit(cbwm);
-    bool marginIEndIsAuto =
+    marginIEndIsAuto =
       eStyleUnit_Auto == mStyleMargin->mMargin.GetIEndUnit(cbwm);
 
     if (marginIStartIsAuto) {
       if (marginIEndIsAuto) {
         if (availMarginSpace < 0) {
           // Note that this case is different from the neither-'auto'
           // case below, where the spec says to ignore 'left'/'right'.
           // Ignore the specified value for 'margin-right'.
@@ -1918,19 +1926,19 @@ ReflowInput::InitAbsoluteConstraints(nsP
       }
     }
 
     // The block-size might still not fill all the available space in case:
     //  * bsize was specified
     //  * we're dealing with a replaced element
     //  * bsize was constrained by min- or max-bsize.
     nscoord availMarginSpace = autoBSize - computedSize.BSize(cbwm);
-    bool marginBStartIsAuto =
+    marginBStartIsAuto =
       eStyleUnit_Auto == mStyleMargin->mMargin.GetBStartUnit(cbwm);
-    bool marginBEndIsAuto =
+    marginBEndIsAuto =
       eStyleUnit_Auto == mStyleMargin->mMargin.GetBEndUnit(cbwm);
 
     if (marginBStartIsAuto) {
       if (marginBEndIsAuto) {
         // Both 'margin-top' and 'margin-bottom' are 'auto', so they get
         // equal values
         margin.BStart(cbwm) = availMarginSpace / 2;
         margin.BEnd(cbwm) = availMarginSpace - margin.BStart(cbwm);
@@ -1949,17 +1957,29 @@ ReflowInput::InitAbsoluteConstraints(nsP
         offsets.BEnd(cbwm) += availMarginSpace;
       }
     }
   }
   ComputedBSize() = computedSize.ConvertTo(wm, cbwm).BSize(wm);
   ComputedISize() = computedSize.ConvertTo(wm, cbwm).ISize(wm);
 
   SetComputedLogicalOffsets(offsets.ConvertTo(wm, cbwm));
-  SetComputedLogicalMargin(margin.ConvertTo(wm, cbwm));
+
+  LogicalMargin marginInOurWM = margin.ConvertTo(wm, cbwm);
+  SetComputedLogicalMargin(marginInOurWM);
+
+  // If we have auto margins, update our UsedMarginProperty. The property
+  // will have already been created by InitOffsets if it is needed.
+  if (marginIStartIsAuto || marginIEndIsAuto ||
+      marginBStartIsAuto || marginBEndIsAuto) {
+    nsMargin* propValue = mFrame->GetProperty(nsIFrame::UsedMarginProperty());
+    MOZ_ASSERT(propValue, "UsedMarginProperty should have been created "
+                          "by InitOffsets.");
+    *propValue = marginInOurWM.GetPhysicalMargin(wm);
+  }
 }
 
 // This will not be converted to abstract coordinates because it's only
 // used in CalcQuirkContainingBlockHeight
 static nscoord
 GetBlockMarginBorderPadding(const ReflowInput* aReflowInput)
 {
   nscoord result = 0;