Bug 1269046 part 9: Add a flag to control whether CSSAlignUtils::AlignJustifySelf() expands "auto" margins. r=mats
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 31 Oct 2016 08:59:40 -0700
changeset 320292 c8965356a17237420621f7089af5146275e5efff
parent 320291 7085eed57189b0b50cc466683c153af6325ee4d4
child 320293 5c85b7c93c5e86011e180451c86bae49dcc49f4e
push id83346
push userdholbert@mozilla.com
push dateMon, 31 Oct 2016 15:59:57 +0000
treeherdermozilla-inbound@995211b23a55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1269046
milestone52.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 1269046 part 9: Add a flag to control whether CSSAlignUtils::AlignJustifySelf() expands "auto" margins. r=mats MozReview-Commit-ID: I0UdEIfiOqX
layout/generic/CSSAlignUtils.cpp
layout/generic/CSSAlignUtils.h
layout/generic/nsAbsoluteContainingBlock.cpp
--- a/layout/generic/CSSAlignUtils.cpp
+++ b/layout/generic/CSSAlignUtils.cpp
@@ -79,20 +79,24 @@ CSSAlignUtils::AlignJustifySelf(uint8_t 
       marginStart = margin.IEnd(wm);
       marginEnd = margin.IStart(wm);
     }
   }
 
   const auto& styleMargin = aRI.mStyleMargin->mMargin;
   bool hasAutoMarginStart;
   bool hasAutoMarginEnd;
-  if (aAxis == eLogicalAxisBlock) {
+  if (aFlags & AlignJustifyFlags::eIgnoreAutoMargins) {
+    // (Note: ReflowInput will have treated "auto" margins as 0, so we
+    // don't need to do anything special to avoid expanding them.)
+    hasAutoMarginStart = hasAutoMarginEnd = false;
+  } else if (aAxis == eLogicalAxisBlock) {
     hasAutoMarginStart = styleMargin.GetBStartUnit(wm) == eStyleUnit_Auto;
     hasAutoMarginEnd = styleMargin.GetBEndUnit(wm) == eStyleUnit_Auto;
-  } else {
+  } else { /* aAxis == eLogicalAxisInline */
     hasAutoMarginStart = styleMargin.GetIStartUnit(wm) == eStyleUnit_Auto;
     hasAutoMarginEnd = styleMargin.GetIEndUnit(wm) == eStyleUnit_Auto;
   }
 
   // https://drafts.csswg.org/css-align-3/#overflow-values
   // This implements <overflow-position> = 'safe'.
   // And auto-margins: https://drafts.csswg.org/css-grid/#auto-margins
   if ((MOZ_UNLIKELY(isOverflowSafe) && aAlignment != NS_STYLE_ALIGN_START) ||
--- a/layout/generic/CSSAlignUtils.h
+++ b/layout/generic/CSSAlignUtils.h
@@ -19,16 +19,20 @@ public:
    */
   enum class AlignJustifyFlags {
     eNoFlags           = 0,
     // Indicates that we have <overflow-position> = safe.
     eOverflowSafe      = 1 << 0,
     // Indicates that the container's start side in aAxis is the same
     // as the child's start side in the child's parallel axis.
     eSameSide          = 1 << 1,
+    // Indicates that AlignJustifySelf() shouldn't expand "auto" margins.
+    // (By default, AlignJustifySelf() *will* expand such margins, to fill the
+    // available space before any alignment is done.)
+    eIgnoreAutoMargins = 1 << 2,
   };
 
   /**
    * This computes the aligned offset of a CSS-aligned child within its
    * alignment container. The returned offset is distance between the
    * logical "start" edge of the alignment container & the logical "start" edge
    * of the aligned child (in terms of the alignment container's writing mode).
    *
--- a/layout/generic/nsAbsoluteContainingBlock.cpp
+++ b/layout/generic/nsAbsoluteContainingBlock.cpp
@@ -418,17 +418,17 @@ OffsetToAlignedStaticPos(const ReflowInp
     NS_ERROR("Unsupported container for abpsos CSS Box Alignment");
     return 0; // (leave the child at the start of its alignment container)
   }
 
   nscoord alignAreaSizeInAxis = (pcAxis == eLogicalAxisInline)
     ? alignAreaSize.ISize(pcWM)
     : alignAreaSize.BSize(pcWM);
 
-  AlignJustifyFlags flags = AlignJustifyFlags::eNoFlags;
+  AlignJustifyFlags flags = AlignJustifyFlags::eIgnoreAutoMargins;
   uint16_t alignConst =
     aPlaceholderContainer->CSSAlignmentForAbsPosChild(aKidReflowInput, pcAxis);
   // XXXdholbert: Handle <overflow-position> in bug 1311892 (by conditionally
   // setting AlignJustifyFlags::eOverflowSafe in |flags|.)  For now, we behave
   // as if "unsafe" was the specified value (which is basically equivalent to
   // the default behavior, when no value is specified -- though the default
   // behavior also has some [at-risk] extra nuance about scroll containers...)
   // For now we ignore & strip off <overflow-position> bits, until bug 1311892.