Bug 1316029 - [css-grid] Implement Automatic Minimum Size clamping for grid items with an intrinsic size but without an intrinsic ratio. r=dholbert
authorMats Palmgren <mats@mozilla.com>
Fri, 11 Nov 2016 18:28:43 +0100
changeset 348960 f250ead28c6975a8822dad4d4cd544d77fcc3a87
parent 348959 db459d69392805f291ec28965cfd89b8a71e3522
child 348961 410135b3dd561a6d6e7f8664504cc7afee67d142
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1316029
milestone52.0a1
Bug 1316029 - [css-grid] Implement Automatic Minimum Size clamping for grid items with an intrinsic size but without an intrinsic ratio. r=dholbert
layout/generic/nsFrame.cpp
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -4711,29 +4711,35 @@ nsFrame::ComputeSize(nsRenderingContext*
 
   if (inlineStyleCoord->GetUnit() != eStyleUnit_Auto) {
     result.ISize(aWM) =
       ComputeISizeValue(aRenderingContext, aCBSize.ISize(aWM),
                         boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize,
                         *inlineStyleCoord, aFlags);
   } else if (MOZ_UNLIKELY(isGridItem) &&
              !IS_TRUE_OVERFLOW_CONTAINER(this)) {
+    // 'auto' inline-size for grid-level box - fill the CB for 'stretch' /
+    // 'normal' and clamp it to the CB if requested:
+    bool stretch = false;
     if (!(aFlags & nsIFrame::eShrinkWrap) &&
         !StyleMargin()->HasInlineAxisAuto(aWM)) {
-      // 'auto' inline-size for grid-level box - apply 'stretch' as needed:
       auto inlineAxisAlignment =
         aWM.IsOrthogonalTo(GetParent()->GetWritingMode()) ?
           StylePosition()->UsedAlignSelf(GetParent()->StyleContext()) :
           StylePosition()->UsedJustifySelf(GetParent()->StyleContext());
-      if (inlineAxisAlignment == NS_STYLE_ALIGN_NORMAL ||
-          inlineAxisAlignment == NS_STYLE_ALIGN_STRETCH) {
-        result.ISize(aWM) = std::max(nscoord(0), aCBSize.ISize(aWM) -
-                                                 aPadding.ISize(aWM) -
-                                                 aBorder.ISize(aWM) -
-                                                 aMargin.ISize(aWM));
+      stretch = inlineAxisAlignment == NS_STYLE_ALIGN_NORMAL ||
+                inlineAxisAlignment == NS_STYLE_ALIGN_STRETCH;
+    }
+    if (stretch || (aFlags & ComputeSizeFlags::eIClampMarginBoxMinSize)) {
+      auto iSizeToFillCB = std::max(nscoord(0), aCBSize.ISize(aWM) -
+                                                aPadding.ISize(aWM) -
+                                                aBorder.ISize(aWM) -
+                                                aMargin.ISize(aWM));
+      if (stretch || result.ISize(aWM) > iSizeToFillCB) {
+        result.ISize(aWM) = iSizeToFillCB;
       }
     }
   }
 
   // Flex items ignore their min & max sizing properties in their
   // flex container's main-axis.  (Those properties get applied later in
   // the flexbox algorithm.)
   const nsStyleCoord& maxISizeCoord = stylePos->MaxISize(aWM);
@@ -4791,30 +4797,38 @@ nsFrame::ComputeSize(nsRenderingContext*
     if (!nsLayoutUtils::IsAutoBSize(*blockStyleCoord, aCBSize.BSize(aWM))) {
       result.BSize(aWM) =
         nsLayoutUtils::ComputeBSizeValue(aCBSize.BSize(aWM),
                                          boxSizingAdjust.BSize(aWM),
                                          *blockStyleCoord);
     } else if (MOZ_UNLIKELY(isGridItem) &&
                blockStyleCoord->GetUnit() == eStyleUnit_Auto &&
                !IS_TRUE_OVERFLOW_CONTAINER(this)) {
-      // 'auto' block-size for grid-level box - apply 'stretch' as needed:
       auto cbSize = aCBSize.BSize(aWM);
-      if (cbSize != NS_AUTOHEIGHT &&
-          !StyleMargin()->HasBlockAxisAuto(aWM)) {
-        auto blockAxisAlignment =
-          !aWM.IsOrthogonalTo(GetParent()->GetWritingMode()) ?
-            StylePosition()->UsedAlignSelf(StyleContext()->GetParent()) :
-            StylePosition()->UsedJustifySelf(StyleContext()->GetParent());
-        if (blockAxisAlignment == NS_STYLE_ALIGN_NORMAL ||
-            blockAxisAlignment == NS_STYLE_ALIGN_STRETCH) {
-          result.BSize(aWM) = std::max(nscoord(0), cbSize -
-                                                   aPadding.BSize(aWM) -
-                                                   aBorder.BSize(aWM) -
-                                                   aMargin.BSize(aWM));
+      if (cbSize != NS_AUTOHEIGHT) {
+        // 'auto' block-size for grid-level box - fill the CB for 'stretch' /
+        // 'normal' and clamp it to the CB if requested:
+        bool stretch = false;
+        if (!StyleMargin()->HasBlockAxisAuto(aWM)) {
+          auto blockAxisAlignment =
+            !aWM.IsOrthogonalTo(GetParent()->GetWritingMode()) ?
+              StylePosition()->UsedAlignSelf(StyleContext()->GetParent()) :
+              StylePosition()->UsedJustifySelf(StyleContext()->GetParent());
+          stretch = blockAxisAlignment == NS_STYLE_ALIGN_NORMAL ||
+                    blockAxisAlignment == NS_STYLE_ALIGN_STRETCH;
+        }
+        if (stretch || (aFlags & ComputeSizeFlags::eBClampMarginBoxMinSize)) {
+          auto bSizeToFillCB = std::max(nscoord(0), cbSize -
+                                                    aPadding.BSize(aWM) -
+                                                    aBorder.BSize(aWM) -
+                                                    aMargin.BSize(aWM));
+          if (stretch || (result.BSize(aWM) != NS_AUTOHEIGHT &&
+                          result.BSize(aWM) > bSizeToFillCB)) {
+            result.BSize(aWM) = bSizeToFillCB;
+          }
         }
       }
     }
   }
 
   const nsStyleCoord& maxBSizeCoord = stylePos->MaxBSize(aWM);
 
   if (result.BSize(aWM) != NS_UNCONSTRAINEDSIZE) {