Bug 1298008 Part 3: Update ReflowInput::CalculateBlockSideMargins to store computed values in the UsedMargin property. draft
authorBrad Werth <bwerth@mozilla.com>
Fri, 23 Mar 2018 12:09:48 -0700
changeset 776039 f9b5bb4bee40c41b25ca09aca879aa4d074e3cd7
parent 776038 8ea7bb07b8a9b54b721151eb897ed0615fcfd936
child 776040 2c886e82566243bbe5283249d13458d9d8b0210f
push id104798
push userbwerth@mozilla.com
push dateMon, 02 Apr 2018 16:04:40 +0000
bugs1298008
milestone61.0a1
Bug 1298008 Part 3: Update ReflowInput::CalculateBlockSideMargins to store computed values in the UsedMargin property. MozReview-Commit-ID: 74u7rFkiVln
layout/generic/ReflowInput.cpp
--- a/layout/generic/ReflowInput.cpp
+++ b/layout/generic/ReflowInput.cpp
@@ -2526,17 +2526,17 @@ ReflowInput::InitConstraints(nsPresConte
   // Save our containing block dimensions
   mContainingBlockSize = aContainingBlockSize;
 }
 
 static void
 UpdateProp(nsIFrame* aFrame,
            const FramePropertyDescriptor<nsMargin>* aProperty,
            bool aNeeded,
-           nsMargin& aNewValue)
+           const nsMargin& aNewValue)
 {
   if (aNeeded) {
     nsMargin* propValue = aFrame->GetProperty(aProperty);
     if (propValue) {
       *propValue = aNewValue;
     } else {
       aFrame->AddProperty(aProperty, new nsMargin(aNewValue));
     }
@@ -2561,20 +2561,20 @@ SizeComputationInput::InitOffsets(Writin
   nsPresContext *presContext = mFrame->PresContext();
   mFrame->DeleteProperty(nsIFrame::UsedBorderProperty());
 
   // Compute margins from the specified margin style information. These
   // become the default computed values, and may be adjusted below
   // XXX fix to provide 0,0 for the top&bottom margins for
   // inline-non-replaced elements
   bool needMarginProp = ComputeMargin(aWM, aPercentBasis);
-  // XXX We need to include 'auto' horizontal margins in this too!
-  // ... but if we did that, we'd need to fix nsFrame::GetUsedMargin
-  // to use it even when the margins are all zero (since sometimes
-  // they get treated as auto)
+  // Note that ComputeMargin() simplistically resolves 'auto' margins to 0.
+  // In formatting contexts where this isn't correct, some later code will
+  // need to update the UsedMargin() property with the actual resolved value.
+  // One example of this is ::CalculateBlockSideMargins().
   ::UpdateProp(mFrame, nsIFrame::UsedMarginProperty(), needMarginProp,
                ComputedPhysicalMargin());
 
 
   const nsStyleDisplay* disp = mFrame->StyleDisplayWithOptionalParam(aDisplay);
   bool isThemed = mFrame->IsThemed(disp);
   bool needPaddingProp;
   nsIntMargin widget;
@@ -2795,17 +2795,26 @@ ReflowInput::CalculateBlockSideMargins(L
       margin.IStart(cbWM) += forStart;
       margin.IEnd(cbWM) += availMarginSpace - forStart;
     } else {
       margin.IStart(cbWM) += availMarginSpace;
     }
   } else if (isAutoEndMargin) {
     margin.IEnd(cbWM) += availMarginSpace;
   }
-  SetComputedLogicalMargin(margin.ConvertTo(mWritingMode, cbWM));
+  LogicalMargin marginInOurWM = margin.ConvertTo(mWritingMode, cbWM);
+  SetComputedLogicalMargin(marginInOurWM);
+
+  if (isAutoStartMargin || isAutoEndMargin) {
+    // Update the UsedMargin property if we were tracking it already.
+    nsMargin* propValue = mFrame->GetProperty(nsIFrame::UsedMarginProperty());
+    if (propValue) {
+      *propValue = marginInOurWM.GetPhysicalMargin(mWritingMode);
+    }
+  }
 }
 
 #define NORMAL_LINE_HEIGHT_FACTOR 1.2f    // in term of emHeight
 // For "normal" we use the font's normal line height (em height + leading).
 // If both internal leading and  external leading specified by font itself
 // are zeros, we should compensate this by creating extra (external) leading
 // in eCompensateLeading mode. This is necessary because without this
 // compensation, normal line height might looks too tight.