Bug 1305244 part 1 - [css-grid] Serialize minmax(auto, <flex>) track sizes as <flex>. r=dholbert
authorMats Palmgren <mats@mozilla.com>
Sat, 29 Oct 2016 01:30:10 +0200
changeset 320088 b727c67b91a3268e893f4f63057f6cb7fae1b4ba
parent 320087 b171726c465e305411429b29012f48e890598b3f
child 320089 1f4500ce11a744b7a6ae93b85020a4000213a40f
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1305244
milestone52.0a1
Bug 1305244 part 1 - [css-grid] Serialize minmax(auto, <flex>) track sizes as <flex>. r=dholbert
layout/style/nsCSSValue.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/test/test_grid_container_shorthands.html
layout/style/test/test_grid_shorthand_serialization.html
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -1305,20 +1305,34 @@ nsCSSValue::AppendToString(nsCSSProperty
   else if (eCSSUnit_Function == unit) {
     const nsCSSValue::Array* array = GetArrayValue();
     MOZ_ASSERT(array->Count() >= 1,
                "Functions must have at least one element for the name.");
 
     const nsCSSValue& functionName = array->Item(0);
     MOZ_ASSERT(functionName.GetUnit() == eCSSUnit_Enumerated,
                "Functions must have an enumerated name.");
+    // The first argument is always of nsCSSKeyword type.
+    const nsCSSKeyword functionId = functionName.GetKeywordValue();
+
+    // minmax(auto, <flex>) is equivalent to (and is our internal representation
+    // of) <flex>, and both are serialized as <flex>
+    if (functionId == eCSSKeyword_minmax &&
+        array->Count() == 3 &&
+        array->Item(1).GetUnit() == eCSSUnit_Auto &&
+        array->Item(2).GetUnit() == eCSSUnit_FlexFraction) {
+      array->Item(2).AppendToString(aProperty, aResult, aSerialization);
+      MOZ_ASSERT(aProperty == eCSSProperty_grid_template_columns ||
+                 aProperty == eCSSProperty_grid_template_rows ||
+                 aProperty == eCSSProperty_grid_auto_columns ||
+                 aProperty == eCSSProperty_grid_auto_rows);
+      return;
+    }
 
     /* Append the function name. */
-    // The first argument is always of nsCSSKeyword type.
-    const nsCSSKeyword functionId = functionName.GetKeywordValue();
     NS_ConvertASCIItoUTF16 ident(nsCSSKeywords::GetStringValue(functionId));
     // Bug 721136: Normalize the identifier to lowercase, except that things
     // like scaleX should have the last character capitalized.  This matches
     // what other browsers do.
     switch (functionId) {
       case eCSSKeyword_rotatex:
       case eCSSKeyword_scalex:
       case eCSSKeyword_skewx:
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -2554,16 +2554,25 @@ nsComputedDOMStyle::GetGridTrackSize(con
 
   if (aMinValue == aMaxValue) {
     RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
     SetValueToCoord(val, aMinValue, true,
                     nullptr, nsCSSProps::kGridTrackBreadthKTable);
     return val.forget();
   }
 
+  // minmax(auto, <flex>) is equivalent to (and is our internal representation
+  // of) <flex>, and both compute to <flex>
+  if (aMinValue.GetUnit() == eStyleUnit_Auto &&
+      aMaxValue.GetUnit() == eStyleUnit_FlexFraction) {
+    RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
+    SetValueToCoord(val, aMaxValue, true);
+    return val.forget();
+  }
+
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
   nsAutoString argumentStr, minmaxStr;
   minmaxStr.AppendLiteral("minmax(");
 
   SetValueToCoord(val, aMinValue, true,
                   nullptr, nsCSSProps::kGridTrackBreadthKTable);
   val->GetCssText(argumentStr);
   minmaxStr.Append(argumentStr);
--- a/layout/style/test/test_grid_container_shorthands.html
+++ b/layout/style/test/test_grid_container_shorthands.html
@@ -32,16 +32,21 @@ var grid_template_test_cases = [
         specified: "none",
     },
     {
         specified: "40px / 100px",
         gridTemplateRows: "40px",
         gridTemplateColumns: "100px",
     },
     {
+        specified: "minmax(auto,1fr) / minmax(auto,1fr)",
+        gridTemplateRows: "1fr",
+        gridTemplateColumns: "1fr",
+    },
+    {
         specified: "[foo] 40px [bar] / [baz] 100px [fizz]",
         gridTemplateRows: "[foo] 40px [bar]",
         gridTemplateColumns: "[baz] 100px [fizz]",
     },
     {
         specified: " none/100px",
         gridTemplateRows: "none",
         gridTemplateColumns: "100px",
@@ -198,27 +203,38 @@ grid_test_cases = grid_template_test_cas
     },
     {
         specified: "auto-flow dense / 0",
         gridAutoFlow: "row dense",
         gridAutoRows: "auto",
         gridTemplateColumns: "0px",
     },
     {
+        specified: "auto-flow minmax(auto,1fr) / none",
+        gridAutoFlow: "row",
+        gridAutoRows: "1fr",
+    },
+    {
         specified: "auto-flow 40px / none",
         gridAutoFlow: "row",
         gridAutoRows: "40px",
     },
     {
         specified: "none / auto-flow 40px",
         gridAutoFlow: "column",
         gridAutoRows: "auto",
         gridAutoColumns: "40px",
     },
     {
+        specified: "none / auto-flow minmax(auto,1fr)",
+        gridAutoFlow: "column",
+        gridAutoRows: "auto",
+        gridAutoColumns: "1fr",
+    },
+    {
         specified: "0 / auto-flow dense auto",
         gridAutoFlow: "column dense",
         gridAutoRows: "auto",
         gridAutoColumns: "auto",
         gridTemplateRows: "0px",
     },
     {
         specified: "dense auto-flow minmax(min-content, 2fr) / 0",
--- a/layout/style/test/test_grid_shorthand_serialization.html
+++ b/layout/style/test/test_grid_shorthand_serialization.html
@@ -29,16 +29,24 @@ var initial_values = {
 // For various specified values of the grid-template subproperties,
 // test the serialization of the shorthand.
 var grid_template_test_cases = [
     {
         gridTemplateColumns: "100px",
         shorthand: "none / 100px",
     },
     {
+        gridTemplateRows: "minmax(auto,1fr)",
+        shorthand: "1fr / none",
+    },
+    {
+        gridTemplateColumns: "minmax(auto,1fr)",
+        shorthand: "none / 1fr",
+    },
+    {
         gridTemplateRows: "40px",
         shorthand: "40px / none",
     },
     {
         gridTemplateRows: "40px",
         gridTemplateColumns: "subgrid",
         shorthand: isGridTemplateSubgridValueEnabled ? "40px / subgrid" : "",
     },
@@ -113,26 +121,35 @@ grid_test_cases = grid_template_test_cas
         gridAutoFlow: "row",
         shorthand: "none / none",
     },
     {
         gridAutoRows: "40px",
         shorthand: "auto-flow 40px / none",
     },
     {
+        gridAutoRows: "minmax(auto,1fr)",
+        shorthand: "auto-flow 1fr / none",
+    },
+    {
         gridAutoFlow: "column dense",
         gridAutoRows: "minmax(min-content, max-content)",
         shorthand: "",
     },
     {
         gridAutoFlow: "column dense",
         gridAutoColumns: "minmax(min-content, max-content)",
         shorthand: "none / auto-flow dense minmax(min-content, max-content)",
     },
     {
+        gridAutoFlow: "column",
+        gridAutoColumns: "minmax(auto,1fr)",
+        shorthand: "none / auto-flow 1fr",
+    },
+    {
         gridAutoFlow: "row dense",
         gridAutoColumns: "minmax(min-content, 2fr)",
         shorthand: "",
     },
     {
         gridAutoFlow: "row dense",
         gridAutoRows: "minmax(min-content, 2fr)",
         shorthand: "auto-flow dense minmax(min-content, 2fr) / none",