Bug 1303643 part 2 - [css-grid] Apply percentages to grid item min-content contributions. r=dholbert
authorMats Palmgren <mats@mozilla.com>
Thu, 29 Sep 2016 21:49:54 +0200
changeset 315897 17341d12497d8be4efd9b8b9bb57926c371121b1
parent 315896 24a382443a0f871e38f4cb98ffd566c478308cd2
child 315898 32f744b48562b3d14e68d64ad74018658eb95281
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1303643
milestone52.0a1
Bug 1303643 part 2 - [css-grid] Apply percentages to grid item min-content contributions. r=dholbert
layout/base/nsLayoutUtils.cpp
layout/generic/nsGridContainerFrame.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -5126,16 +5126,19 @@ nsLayoutUtils::MinSizeContributionForAxi
 #ifdef DEBUG_INTRINSIC_WIDTH
   nsFrame::IndentBy(stderr, gNoiseIndent);
   static_cast<nsFrame*>(aFrame)->ListTag(stderr);
   printf_stderr(" %s min-isize for %s WM:\n",
                 aType == MIN_ISIZE ? "min" : "pref",
                 aWM.IsVertical() ? "vertical" : "horizontal");
 #endif
 
+  // Note: this method is only meant for grid/flex items which always
+  // include percentages in their intrinsic size.
+  aFlags |= nsLayoutUtils::ADD_PERCENTS;
   const nsStylePosition* const stylePos = aFrame->StylePosition();
   const nsStyleCoord* style = aAxis == eAxisHorizontal ? &stylePos->mMinWidth
                                                        : &stylePos->mMinHeight;
   nscoord minSize;
   nscoord* fixedMinSize = nullptr;
   auto minSizeUnit = style->GetUnit();
   if (minSizeUnit == eStyleUnit_Auto) {
     if (aFrame->StyleDisplay()->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE) {
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -3603,17 +3603,18 @@ ContentContribution(const GridItemInfo& 
                     WritingMode                       aCBWM,
                     LogicalAxis                       aAxis,
                     nsLayoutUtils::IntrinsicISizeType aConstraint,
                     uint32_t                          aFlags = 0)
 {
   nsIFrame* child = aGridItem.mFrame;
   PhysicalAxis axis(aCBWM.PhysicalAxis(aAxis));
   nscoord size = nsLayoutUtils::IntrinsicForAxis(axis, aRC, child, aConstraint,
-                   aFlags | nsLayoutUtils::BAIL_IF_REFLOW_NEEDED);
+                   aFlags | nsLayoutUtils::BAIL_IF_REFLOW_NEEDED |
+                            nsLayoutUtils::ADD_PERCENTS);
   if (size == NS_INTRINSIC_WIDTH_UNKNOWN) {
     // We need to reflow the child to find its BSize contribution.
     // XXX this will give mostly correct results for now (until bug 1174569).
     nscoord cbISize = INFINITE_ISIZE_COORD;
     nscoord cbBSize = NS_UNCONSTRAINEDSIZE;
     auto childWM = child->GetWritingMode();
     if (aState.mCols.mCanResolveLineRangeSize) {
       nscoord sz = aState.mCols.ResolveSize(aGridItem.mArea.mCols);
@@ -3622,17 +3623,24 @@ ContentContribution(const GridItemInfo& 
       } else {
         cbISize = sz;
       }
     }
     LogicalSize availableSize(childWM, cbISize, cbBSize);
     size = ::MeasuringReflow(child, aState.mReflowInput, aRC, availableSize);
     nsIFrame::IntrinsicISizeOffsetData offsets = child->IntrinsicBSizeOffsets();
     size += offsets.hMargin;
-    size = nsLayoutUtils::AddPercents(aConstraint, size, offsets.hPctMargin);
+    auto percent = offsets.hPctMargin;
+    if (!aState.mReflowInput) {
+      // We always want to add in percent padding too, but during Reflow we
+      // always have a definite percentage basis (the grid area) so any percent
+      // padding is already resolved and baked in to 'size' at this point.
+      percent += offsets.hPctPadding;
+    }
+    size = nsLayoutUtils::AddPercents(size, percent);
   }
   MOZ_ASSERT(aGridItem.mBaselineOffset[aAxis] >= 0,
              "baseline offset should be non-negative at this point");
   MOZ_ASSERT((aGridItem.mState[aAxis] & ItemState::eIsBaselineAligned) ||
              aGridItem.mBaselineOffset[aAxis] == nscoord(0),
              "baseline offset should be zero when not baseline-aligned");
   size += aGridItem.mBaselineOffset[aAxis];
   return std::max(size, 0);