Bug 976787 part 4: Add the grid-auto-flow property to the style system. r=dholbert
authorSimon Sapin <simon.sapin@exyr.org>
Mon, 10 Mar 2014 15:54:16 -0700
changeset 183888 8db3c07e2bad36a11cf1ec622fd0c155fa305126
parent 183887 a9fb5a9c8ada58a4bff8c4da681c1dee5e41d2aa
child 183889 7aa032d90c9120737fbd0963f042e27e31616568
push idunknown
push userunknown
push dateunknown
reviewersdholbert
bugs976787
milestone30.0a1
Bug 976787 part 4: Add the grid-auto-flow property to the style system. r=dholbert
layout/style/nsCSSKeywordList.h
layout/style/nsCSSParser.cpp
layout/style/nsCSSPropList.h
layout/style/nsCSSProps.cpp
layout/style/nsCSSProps.h
layout/style/nsCSSValue.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsComputedDOMStyle.h
layout/style/nsComputedDOMStylePropertyList.h
layout/style/nsRuleNode.cpp
layout/style/nsStyleConsts.h
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
layout/style/test/property_database.js
--- a/layout/style/nsCSSKeywordList.h
+++ b/layout/style/nsCSSKeywordList.h
@@ -235,16 +235,17 @@ CSS_KEY(copy, copy)
 CSS_KEY(contextual, contextual)
 CSS_KEY(cover, cover)
 CSS_KEY(crop, crop)
 CSS_KEY(cross, cross)
 CSS_KEY(crosshair, crosshair)
 CSS_KEY(currentcolor, currentcolor)
 CSS_KEY(darken, darken)
 CSS_KEY(dashed, dashed)
+CSS_KEY(dense, dense)
 CSS_KEY(decimal, decimal)
 CSS_KEY(decimal-leading-zero, decimal_leading_zero)
 CSS_KEY(default, default)
 CSS_KEY(deg, deg)
 CSS_KEY(diagonal-fractions, diagonal_fractions)
 CSS_KEY(dialog, dialog)
 CSS_KEY(difference, difference)
 CSS_KEY(digits, digits)
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -627,16 +627,17 @@ protected:
   bool RequireWhitespace();
 
   // For "flex" shorthand property, defined in CSS Flexbox spec
   bool ParseFlex();
   // For "flex-flow" shorthand property, defined in CSS Flexbox spec
   bool ParseFlexFlow();
 
   // CSS Grid
+  bool ParseGridAutoFlow();
   bool ParseGridLineNames(nsCSSValue& aValue);
   bool ParseGridTrackBreadth(nsCSSValue& aValue);
   bool ParseGridTrackSize(nsCSSValue& aValue);
   bool ParseGridAutoColumnsRows(nsCSSProperty aPropID);
   bool ParseGridTrackList(nsCSSProperty aPropID);
   bool ParseGridTemplateAreasLine(const nsAutoString& aInput,
                                   nsTArray<nsCSSGridNamedArea>& aNamedAreas,
                                   uint32_t aRow,
@@ -6870,16 +6871,73 @@ CSSParserImpl::ParseFlexFlow()
 
   // Store these values and declare success!
   for (size_t i = 0; i < numProps; i++) {
     AppendValue(kFlexFlowSubprops[i], values[i]);
   }
   return true;
 }
 
+bool
+CSSParserImpl::ParseGridAutoFlow()
+{
+  nsCSSValue value;
+  if (ParseVariant(value, VARIANT_INHERIT | VARIANT_NONE, nullptr)) {
+    AppendValue(eCSSProperty_grid_auto_flow, value);
+    return true;
+  }
+
+  bool gotDense = false;
+  bool gotColumn = false;
+  bool gotRow = false;
+  do {
+    if (!GetToken(true)) {
+      return false;
+    }
+    if (mToken.mType != eCSSToken_Ident) {
+      UngetToken();
+      return false;
+    }
+    nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(mToken.mIdent);
+    if (keyword == eCSSKeyword_dense && !gotDense) {
+      gotDense = true;
+    } else if (keyword == eCSSKeyword_column && !gotColumn && !gotRow) {
+      gotColumn = true;
+    } else if (keyword == eCSSKeyword_row && !gotColumn && !gotRow) {
+      gotRow = true;
+    } else {
+      return false;
+    }
+  } while (!CheckEndProperty());
+
+  if (!(gotColumn || gotRow)) {
+    return false;
+  }
+
+  int32_t bitField;
+  if (gotColumn) {
+    MOZ_ASSERT(!gotRow,
+               "code above should've rejected values with both row and column");
+    bitField = NS_STYLE_GRID_AUTO_FLOW_COLUMN;
+  } else if (gotRow) {
+    bitField = NS_STYLE_GRID_AUTO_FLOW_ROW;
+  } else {
+    // got neither row nor column; invalid.
+    return false;
+  }
+
+  if (gotDense) {
+    bitField |= NS_STYLE_GRID_AUTO_FLOW_DENSE;
+  }
+
+  value.SetIntValue(bitField, eCSSUnit_Enumerated);
+  AppendValue(eCSSProperty_grid_auto_flow, value);
+  return true;
+}
+
 // Parse an optional <line-names> expression.
 // If successful, leaves aValue with eCSSUnit_Null for the empty list,
 // or sets it to a eCSSUnit_List of eCSSUnit_Ident.
 // Not finding an open paren is considered the same as an empty list.
 
 // aPropertyKeywords contains additional keywords for the 'grid' shorthand.
 bool
 CSSParserImpl::ParseGridLineNames(nsCSSValue& aValue)
@@ -8136,16 +8194,18 @@ CSSParserImpl::ParsePropertyByFunction(n
   case eCSSProperty_filter:
     return ParseFilter();
   case eCSSProperty_flex:
     return ParseFlex();
   case eCSSProperty_flex_flow:
     return ParseFlexFlow();
   case eCSSProperty_font:
     return ParseFont();
+  case eCSSProperty_grid_auto_flow:
+    return ParseGridAutoFlow();
   case eCSSProperty_grid_auto_columns:
   case eCSSProperty_grid_auto_rows:
     return ParseGridAutoColumnsRows(aPropID);
   case eCSSProperty_grid_template_areas:
     return ParseGridTemplateAreas();
   case eCSSProperty_grid_template_columns:
   case eCSSProperty_grid_template_rows:
     return ParseGridTrackList(aPropID);
--- a/layout/style/nsCSSPropList.h
+++ b/layout/style/nsCSSPropList.h
@@ -2004,16 +2004,26 @@ CSS_PROP_UIRESET(
     CSS_PROPERTY_PARSE_VALUE |
         CSS_PROPERTY_VALUE_NONNEGATIVE,
     "",
     VARIANT_HI,
     nullptr,
     CSS_PROP_NO_OFFSET,
     eStyleAnimType_None) // bug 58646
 CSS_PROP_POSITION(
+    grid-auto-flow,
+    grid_auto_flow,
+    GridAutoFlow,
+    CSS_PROPERTY_PARSE_FUNCTION,
+    "layout.css.grid.enabled",
+    0,
+    kGridAutoFlowKTable,
+    CSS_PROP_NO_OFFSET,
+    eStyleAnimType_None)
+CSS_PROP_POSITION(
     grid-auto-columns,
     grid_auto_columns,
     GridAutoColumns,
     CSS_PROPERTY_PARSE_FUNCTION |
         CSS_PROPERTY_STORES_CALC,
     "layout.css.grid.enabled",
     0,
     kGridTrackBreadthKTable,
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -1246,16 +1246,24 @@ const KTableValue nsCSSProps::kFontVaria
 const KTableValue nsCSSProps::kFontWeightKTable[] = {
   eCSSKeyword_normal, NS_STYLE_FONT_WEIGHT_NORMAL,
   eCSSKeyword_bold, NS_STYLE_FONT_WEIGHT_BOLD,
   eCSSKeyword_bolder, NS_STYLE_FONT_WEIGHT_BOLDER,
   eCSSKeyword_lighter, NS_STYLE_FONT_WEIGHT_LIGHTER,
   eCSSKeyword_UNKNOWN,-1
 };
 
+const KTableValue nsCSSProps::kGridAutoFlowKTable[] = {
+  eCSSKeyword_none, NS_STYLE_GRID_AUTO_FLOW_NONE,
+  eCSSKeyword_column, NS_STYLE_GRID_AUTO_FLOW_COLUMN,
+  eCSSKeyword_row, NS_STYLE_GRID_AUTO_FLOW_ROW,
+  eCSSKeyword_dense, NS_STYLE_GRID_AUTO_FLOW_DENSE,
+  eCSSKeyword_UNKNOWN,-1
+};
+
 const KTableValue nsCSSProps::kGridTrackBreadthKTable[] = {
   eCSSKeyword_min_content, NS_STYLE_GRID_TRACK_BREADTH_MIN_CONTENT,
   eCSSKeyword_max_content, NS_STYLE_GRID_TRACK_BREADTH_MAX_CONTENT,
   eCSSKeyword_UNKNOWN,-1
 };
 
 const KTableValue nsCSSProps::kImageOrientationKTable[] = {
   eCSSKeyword_flip, NS_STYLE_IMAGE_ORIENTATION_FLIP,
--- a/layout/style/nsCSSProps.h
+++ b/layout/style/nsCSSProps.h
@@ -567,16 +567,17 @@ public:
   static const KTableValue kFontVariantAlternatesKTable[];
   static const KTableValue kFontVariantAlternatesFuncsKTable[];
   static const KTableValue kFontVariantCapsKTable[];
   static const KTableValue kFontVariantEastAsianKTable[];
   static const KTableValue kFontVariantLigaturesKTable[];
   static const KTableValue kFontVariantNumericKTable[];
   static const KTableValue kFontVariantPositionKTable[];
   static const KTableValue kFontWeightKTable[];
+  static const KTableValue kGridAutoFlowKTable[];
   static const KTableValue kGridTrackBreadthKTable[];
   static const KTableValue kImageOrientationKTable[];
   static const KTableValue kImageOrientationFlipKTable[];
   static const KTableValue kIMEModeKTable[];
   static const KTableValue kLineHeightKTable[];
   static const KTableValue kListStylePositionKTable[];
   static const KTableValue kListStyleKTable[];
   static const KTableValue kMaskTypeKTable[];
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -1020,16 +1020,23 @@ nsCSSValue::AppendToString(nsCSSProperty
 
     case eCSSProperty_font_variant_numeric:
       nsStyleUtil::AppendBitmaskCSSValue(aProperty, intValue,
                                          NS_FONT_VARIANT_NUMERIC_LINING,
                                          NS_FONT_VARIANT_NUMERIC_ORDINAL,
                                          aResult);
       break;
 
+    case eCSSProperty_grid_auto_flow:
+      nsStyleUtil::AppendBitmaskCSSValue(aProperty, intValue,
+                                         NS_STYLE_GRID_AUTO_FLOW_NONE,
+                                         NS_STYLE_GRID_AUTO_FLOW_DENSE,
+                                         aResult);
+      break;
+
     case eCSSProperty_touch_action:
       nsStyleUtil::AppendBitmaskCSSValue(aProperty, intValue,
                                          NS_STYLE_TOUCH_ACTION_PAN_X,
                                          NS_STYLE_TOUCH_ACTION_PAN_Y,
                                          aResult);
       break;
 
     default:
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -2379,16 +2379,30 @@ nsComputedDOMStyle::GetGridTrackList(con
     valueList->AppendCSSValue(GetGridTrackSize(aTrackList.mMinTrackSizingFunctions[i],
                                                aTrackList.mMaxTrackSizingFunctions[i]));
   }
 
   return valueList;
 }
 
 CSSValue*
+nsComputedDOMStyle::DoGetGridAutoFlow()
+{
+  nsAutoString str;
+  nsStyleUtil::AppendBitmaskCSSValue(eCSSProperty_grid_auto_flow,
+                                     StylePosition()->mGridAutoFlow,
+                                     NS_STYLE_GRID_AUTO_FLOW_NONE,
+                                     NS_STYLE_GRID_AUTO_FLOW_DENSE,
+                                     str);
+  nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
+  val->SetString(str);
+  return val;
+}
+
+CSSValue*
 nsComputedDOMStyle::DoGetGridAutoColumns()
 {
   return GetGridTrackSize(StylePosition()->mGridAutoColumnsMin,
                           StylePosition()->mGridAutoColumnsMax);
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetGridAutoRows()
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -258,16 +258,17 @@ private:
   mozilla::dom::CSSValue* DoGetFontVariantCaps();
   mozilla::dom::CSSValue* DoGetFontVariantEastAsian();
   mozilla::dom::CSSValue* DoGetFontVariantLigatures();
   mozilla::dom::CSSValue* DoGetFontVariantNumeric();
   mozilla::dom::CSSValue* DoGetFontVariantPosition();
   mozilla::dom::CSSValue* DoGetFontWeight();
 
   /* Grid properties */
+  mozilla::dom::CSSValue* DoGetGridAutoFlow();
   mozilla::dom::CSSValue* DoGetGridAutoColumns();
   mozilla::dom::CSSValue* DoGetGridAutoRows();
   mozilla::dom::CSSValue* DoGetGridTemplateAreas();
   mozilla::dom::CSSValue* DoGetGridTemplateColumns();
   mozilla::dom::CSSValue* DoGetGridTemplateRows();
 
   /* Background properties */
   mozilla::dom::CSSValue* DoGetBackgroundAttachment();
--- a/layout/style/nsComputedDOMStylePropertyList.h
+++ b/layout/style/nsComputedDOMStylePropertyList.h
@@ -126,16 +126,17 @@ COMPUTED_STYLE_PROP(font_variant,       
 COMPUTED_STYLE_PROP(font_variant_alternates,       FontVariantAlternates)
 COMPUTED_STYLE_PROP(font_variant_caps,             FontVariantCaps)
 COMPUTED_STYLE_PROP(font_variant_east_asian,       FontVariantEastAsian)
 COMPUTED_STYLE_PROP(font_variant_ligatures,        FontVariantLigatures)
 COMPUTED_STYLE_PROP(font_variant_numeric,          FontVariantNumeric)
 COMPUTED_STYLE_PROP(font_variant_position,         FontVariantPosition)
 COMPUTED_STYLE_PROP(font_weight,                   FontWeight)
 COMPUTED_STYLE_PROP(grid_auto_columns,             GridAutoColumns)
+COMPUTED_STYLE_PROP(grid_auto_flow,                GridAutoFlow)
 COMPUTED_STYLE_PROP(grid_auto_rows,                GridAutoRows)
 COMPUTED_STYLE_PROP(grid_template_areas,           GridTemplateAreas)
 COMPUTED_STYLE_PROP(grid_template_columns,         GridTemplateColumns)
 COMPUTED_STYLE_PROP(grid_template_rows,            GridTemplateRows)
 COMPUTED_STYLE_PROP(height,                        Height)
 COMPUTED_STYLE_PROP(image_orientation,             ImageOrientation)
 COMPUTED_STYLE_PROP(ime_mode,                      IMEMode)
 COMPUTED_STYLE_PROP(justify_content,               JustifyContent)
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -7422,16 +7422,36 @@ nsRuleNode::ComputePositionData(void* aS
 
   // justify-content: enum, inherit, initial
   SetDiscrete(*aRuleData->ValueForJustifyContent(),
               pos->mJustifyContent, canStoreInRuleTree,
               SETDSC_ENUMERATED | SETDSC_UNSET_INITIAL,
               parentPos->mJustifyContent,
               NS_STYLE_JUSTIFY_CONTENT_FLEX_START, 0, 0, 0, 0);
 
+  // grid-auto-flow
+  const nsCSSValue& gridAutoFlow = *aRuleData->ValueForGridAutoFlow();
+  switch (gridAutoFlow.GetUnit()) {
+    case eCSSUnit_Null:
+      break;
+    case eCSSUnit_Inherit:
+      canStoreInRuleTree = false;
+      pos->mGridAutoFlow = parentPos->mGridAutoFlow;
+      break;
+    case eCSSUnit_Initial:
+    case eCSSUnit_Unset:
+    case eCSSUnit_None:
+      pos->mGridAutoFlow = NS_STYLE_GRID_AUTO_FLOW_NONE;
+      break;
+    default:
+      NS_ASSERTION(gridAutoFlow.GetUnit() == eCSSUnit_Enumerated,
+                   "Unexpected unit");
+      pos->mGridAutoFlow = gridAutoFlow.GetIntValue();
+  }
+
   // grid-auto-columns
   SetGridAutoColumnsRows(*aRuleData->ValueForGridAutoColumns(),
                          pos->mGridAutoColumnsMin,
                          pos->mGridAutoColumnsMax,
                          parentPos->mGridAutoColumnsMin,
                          parentPos->mGridAutoColumnsMax,
                          aContext, mPresContext, canStoreInRuleTree);
 
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -534,16 +534,22 @@ static inline mozilla::css::Side operato
 #define NS_STYLE_FONT_DESKTOP                   10
 #define NS_STYLE_FONT_INFO                      11
 #define NS_STYLE_FONT_DIALOG                    12
 #define NS_STYLE_FONT_BUTTON                    13
 #define NS_STYLE_FONT_PULL_DOWN_MENU            14
 #define NS_STYLE_FONT_LIST                      15
 #define NS_STYLE_FONT_FIELD                     16
 
+// grid-auto-flow keywords
+#define NS_STYLE_GRID_AUTO_FLOW_NONE            (1 << 0)
+#define NS_STYLE_GRID_AUTO_FLOW_COLUMN          (1 << 1)
+#define NS_STYLE_GRID_AUTO_FLOW_ROW             (1 << 2)
+#define NS_STYLE_GRID_AUTO_FLOW_DENSE           (1 << 3)
+
 // CSS Grid <track-breadth> keywords
 #define NS_STYLE_GRID_TRACK_BREADTH_MAX_CONTENT 1
 #define NS_STYLE_GRID_TRACK_BREADTH_MIN_CONTENT 2
 
 // defaults per MathML spec
 #define NS_MATHML_DEFAULT_SCRIPT_SIZE_MULTIPLIER 0.71f
 #define NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT 8
 
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -1235,16 +1235,17 @@ nsStylePosition::nsStylePosition(void)
                                   eStyleUnit_Enumerated);
   mGridAutoColumnsMax.SetIntValue(NS_STYLE_GRID_TRACK_BREADTH_MAX_CONTENT,
                                   eStyleUnit_Enumerated);
   mGridAutoRowsMin.SetIntValue(NS_STYLE_GRID_TRACK_BREADTH_MIN_CONTENT,
                                eStyleUnit_Enumerated);
   mGridAutoRowsMax.SetIntValue(NS_STYLE_GRID_TRACK_BREADTH_MAX_CONTENT,
                                eStyleUnit_Enumerated);
 
+  mGridAutoFlow = NS_STYLE_GRID_AUTO_FLOW_NONE;
   mBoxSizing = NS_STYLE_BOX_SIZING_CONTENT;
   mAlignContent = NS_STYLE_ALIGN_CONTENT_STRETCH;
   mAlignItems = NS_STYLE_ALIGN_ITEMS_INITIAL_VALUE;
   mAlignSelf = NS_STYLE_ALIGN_SELF_AUTO;
   mFlexDirection = NS_STYLE_FLEX_DIRECTION_ROW;
   mFlexWrap = NS_STYLE_FLEX_WRAP_NOWRAP;
   mJustifyContent = NS_STYLE_JUSTIFY_CONTENT_FLEX_START;
   mOrder = NS_STYLE_ORDER_INITIAL;
@@ -1334,17 +1335,18 @@ nsChangeHint nsStylePosition::CalcDiffer
 
   // Properties that apply to grid containers:
   if (mGridTemplateColumns != aOther.mGridTemplateColumns ||
       mGridTemplateRows != aOther.mGridTemplateRows ||
       mGridTemplateAreas != aOther.mGridTemplateAreas ||
       mGridAutoColumnsMin != aOther.mGridAutoColumnsMin ||
       mGridAutoColumnsMax != aOther.mGridAutoColumnsMax ||
       mGridAutoRowsMin != aOther.mGridAutoRowsMin ||
-      mGridAutoRowsMax != aOther.mGridAutoRowsMax) {
+      mGridAutoRowsMax != aOther.mGridAutoRowsMax ||
+      mGridAutoFlow != aOther.mGridAutoFlow) {
     return NS_CombineHint(hint, nsChangeHint_AllReflowHints);
   }
 
 
   // Changing justify-content on a flexbox might affect the positioning of its
   // children, but it won't affect any sizing.
   if (mJustifyContent != aOther.mJustifyContent) {
     NS_UpdateHint(hint, nsChangeHint_NeedReflow);
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -1216,16 +1216,17 @@ struct nsStylePosition {
   nsStyleCoord  mHeight;                // [reset] coord, percent, calc, auto
   nsStyleCoord  mMinHeight;             // [reset] coord, percent, calc
   nsStyleCoord  mMaxHeight;             // [reset] coord, percent, calc, none
   nsStyleCoord  mFlexBasis;             // [reset] coord, percent, enum, calc, auto
   nsStyleCoord  mGridAutoColumnsMin;    // [reset] coord, percent, enum, calc, flex
   nsStyleCoord  mGridAutoColumnsMax;    // [reset] coord, percent, enum, calc, flex
   nsStyleCoord  mGridAutoRowsMin;       // [reset] coord, percent, enum, calc, flex
   nsStyleCoord  mGridAutoRowsMax;       // [reset] coord, percent, enum, calc, flex
+  uint8_t       mGridAutoFlow;          // [reset] enumerated. See nsStyleConsts.h
   uint8_t       mBoxSizing;             // [reset] see nsStyleConsts.h
   uint8_t       mAlignContent;          // [reset] see nsStyleConsts.h
   uint8_t       mAlignItems;            // [reset] see nsStyleConsts.h
   uint8_t       mAlignSelf;             // [reset] see nsStyleConsts.h
   uint8_t       mFlexDirection;         // [reset] see nsStyleConsts.h
   uint8_t       mFlexWrap;              // [reset] see nsStyleConsts.h
   uint8_t       mJustifyContent;        // [reset] see nsStyleConsts.h
   int32_t       mOrder;                 // [reset] integer
--- a/layout/style/test/property_database.js
+++ b/layout/style/test/property_database.js
@@ -4787,16 +4787,41 @@ if (SpecialPowers.getBoolPref("layout.cs
 			"sepia(10px)",
 			"sepia(-1)",
 		]
 	};
 }
 
 if (SpecialPowers.getBoolPref("layout.css.grid.enabled")) {
 	gCSSProperties["display"].other_values.push("grid", "inline-grid");
+	gCSSProperties["grid-auto-flow"] = {
+		domProp: "gridAutoFlow",
+		inherited: false,
+		type: CSS_TYPE_LONGHAND,
+		initial_values: [ "none" ],
+		other_values: [
+			"column",
+			"row",
+			"column dense",
+			"row dense",
+			"dense column",
+			"dense row",
+		],
+		invalid_values: [
+			"",
+			"auto",
+			"10px",
+			"dense",
+			"none row",
+			"none dense",
+			"column row",
+			"dense row dense",
+		]
+	};
+
 	gCSSProperties["grid-auto-columns"] = {
 		domProp: "gridAutoColumns",
 		inherited: false,
 		type: CSS_TYPE_LONGHAND,
 		initial_values: [ "auto" ],
 		other_values: [
 			"40px",
 			"2em",