Bug 1264607 - Treat track size <percentage> values as 'auto' when the grid container size is indefinite. r=dholbert
authorMats Palmgren <mats@mozilla.com>
Sat, 16 Apr 2016 18:16:24 +0200
changeset 331405 cb17b758fee2b02e615599c7b2e33f7d02255612
parent 331404 037893f93079315cf4dfaac7e6ae6691876abcc6
child 331406 6fbfa5372b24e58f2ed43b8e7633c6faa33f336c
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1264607
milestone48.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 1264607 - Treat track size <percentage> values as 'auto' when the grid container size is indefinite. r=dholbert
layout/generic/nsGridContainerFrame.cpp
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -147,32 +147,45 @@ struct IsPod<nsGridContainerFrame::Track
 
 void
 nsGridContainerFrame::TrackSize::Initialize(nscoord aPercentageBasis,
                                             const nsStyleCoord& aMinCoord,
                                             const nsStyleCoord& aMaxCoord)
 {
   MOZ_ASSERT(mBase == 0 && mLimit == 0 && mState == 0,
              "track size data is expected to be initialized to zero");
+  auto minSizeUnit = aMinCoord.GetUnit();
+  auto maxSizeUnit = aMaxCoord.GetUnit();
+  if (aPercentageBasis == NS_UNCONSTRAINEDSIZE) {
+    // https://drafts.csswg.org/css-grid/#valdef-grid-template-columns-percentage
+    // "If the inline or block size of the grid container is indefinite,
+    //  <percentage> values relative to that size are treated as 'auto'."
+    if (aMinCoord.HasPercent()) {
+      minSizeUnit = eStyleUnit_Auto;
+    }
+    if (aMaxCoord.HasPercent()) {
+      maxSizeUnit = eStyleUnit_Auto;
+    }
+  }
   // http://dev.w3.org/csswg/css-grid/#algo-init
-  switch (aMinCoord.GetUnit()) {
+  switch (minSizeUnit) {
     case eStyleUnit_Auto:
       mState = eAutoMinSizing;
       break;
     case eStyleUnit_Enumerated:
       mState = IsMinContent(aMinCoord) ? eMinContentMinSizing
                                        : eMaxContentMinSizing;
       break;
     case eStyleUnit_FlexFraction:
       mState = eFlexMinSizing;
       break;
     default:
       mBase = nsRuleNode::ComputeCoordPercentCalc(aMinCoord, aPercentageBasis);
   }
-  switch (aMaxCoord.GetUnit()) {
+  switch (maxSizeUnit) {
     case eStyleUnit_Auto:
       mState |= eAutoMaxSizing;
       mLimit = NS_UNCONSTRAINEDSIZE;
       break;
     case eStyleUnit_Enumerated:
       mState |= IsMinContent(aMaxCoord) ? eMinContentMaxSizing
                                         : eMaxContentMaxSizing;
       mLimit = NS_UNCONSTRAINEDSIZE;
@@ -3203,22 +3216,18 @@ nsGridContainerFrame::Tracks::Initialize
   nscoord                     aGridGap,
   uint32_t                    aNumTracks,
   nscoord                     aContentBoxSize)
 {
   MOZ_ASSERT(aNumTracks >= aFunctions.mExplicitGridOffset +
                              aFunctions.NumExplicitTracks());
   mSizes.SetLength(aNumTracks);
   PodZero(mSizes.Elements(), mSizes.Length());
-  nscoord percentageBasis = aContentBoxSize;
-  if (percentageBasis == NS_UNCONSTRAINEDSIZE) {
-    percentageBasis = 0;
-  }
   for (uint32_t i = 0, len = mSizes.Length(); i < len; ++i) {
-    mSizes[i].Initialize(percentageBasis,
+    mSizes[i].Initialize(aContentBoxSize,
                          aFunctions.MinSizingFor(i),
                          aFunctions.MaxSizingFor(i));
   }
   mGridGap = aGridGap;
   mContentBoxSize = aContentBoxSize;
   MOZ_ASSERT(mGridGap >= nscoord(0), "negative grid gap");
 }