Bug 1300369 part 5 - Make nsFrame::ComputeSize and nsFrame::ShrinkWidthToFit handle margin-box min-size clamping. r=dholbert
authorMats Palmgren <mats@mozilla.com>
Sat, 05 Nov 2016 02:57:06 +0100
changeset 347944 8692ff0a6b3b1609d4422db0b549d5d2c5fa7d29
parent 347943 c9ee55e916c6b7661c294a57759cac1381e4a758
child 347945 e9dd8fc257887519b689603931153029df58ded7
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
bugs1300369
milestone52.0a1
Bug 1300369 part 5 - Make nsFrame::ComputeSize and nsFrame::ShrinkWidthToFit handle margin-box min-size clamping. r=dholbert
layout/generic/nsFrame.cpp
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -4738,16 +4738,30 @@ nsFrame::ComputeSize(nsRenderingContext*
         aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize,
         minISizeCoord);
   } else if (MOZ_UNLIKELY(isGridItem)) {
     // This implements "Implied Minimum Size of Grid Items".
     // https://drafts.csswg.org/css-grid/#min-size-auto
     minISize = std::min(maxISize, GetMinISize(aRenderingContext));
     if (inlineStyleCoord->IsCoordPercentCalcUnit()) {
       minISize = std::min(minISize, result.ISize(aWM));
+    } else if (aFlags & eIClampMarginBoxMinSize) {
+      auto cbSize = aCBSize.ISize(aWM);
+      if (cbSize != NS_UNCONSTRAINEDSIZE) {
+        // "if the grid item spans only grid tracks that have a fixed max track
+        // sizing function, its automatic minimum size in that dimension is
+        // further clamped to less than or equal to the size necessary to fit
+        // its margin box within the resulting grid area (flooring at zero)"
+        // https://drafts.csswg.org/css-grid/#min-size-auto
+        auto maxMinISize = std::max(nscoord(0), cbSize -
+                                                aPadding.ISize(aWM) -
+                                                aBorder.ISize(aWM) -
+                                                aMargin.ISize(aWM));
+        minISize = std::min(minISize, maxMinISize);
+      }
     }
   } else {
     // Treat "min-width: auto" as 0.
     // NOTE: Technically, "auto" is supposed to behave like "min-content" on
     // flex items. However, we don't need to worry about that here, because
     // flex items' min-sizes are intentionally ignored until the flex
     // container explicitly considers them during space distribution.
     minISize = 0;
@@ -4909,17 +4923,18 @@ nsFrame::ShrinkWidthToFit(nsRenderingCon
 {
   // If we're a container for font size inflation, then shrink
   // wrapping inside of us should not apply font size inflation.
   AutoMaybeDisableFontInflation an(this);
 
   nscoord result;
   nscoord minISize = GetMinISize(aRenderingContext);
   if (minISize > aISizeInCB) {
-    result = minISize;
+    const bool clamp = aFlags & ComputeSizeFlags::eIClampMarginBoxMinSize;
+    result = MOZ_UNLIKELY(clamp) ? aISizeInCB : minISize;
   } else {
     nscoord prefISize = GetPrefISize(aRenderingContext);
     if (prefISize > aISizeInCB) {
       result = aISizeInCB;
     } else {
       result = prefISize;
     }
   }