From 77b45e9dd28b37ef39c56407917f549846a6bd6a Mon Sep 17 00:00:00 2001 From: Tobias Schneider Date: Fri, 13 Nov 2015 13:15:00 +0100 Subject: [PATCH] Bug 1221677 - "[css-grid] Put the 'subgrid' support behind a pref, disabled by default". r=mats --- .../en-US/chrome/layout/css.properties | 1 + layout/base/nsLayoutUtils.cpp | 17 +++++ layout/base/nsLayoutUtils.h | 6 ++ layout/style/nsCSSParser.cpp | 12 ++++ layout/style/test/property_database.js | 66 +++++++++++-------- .../test/test_grid_container_shorthands.html | 29 ++++---- .../test_grid_shorthand_serialization.html | 5 +- modules/libpref/init/all.js | 3 + 8 files changed, 100 insertions(+), 39 deletions(-) diff --git a/dom/locales/en-US/chrome/layout/css.properties b/dom/locales/en-US/chrome/layout/css.properties index 1fafc694c31..5f8dde727e9 100644 --- a/dom/locales/en-US/chrome/layout/css.properties +++ b/dom/locales/en-US/chrome/layout/css.properties @@ -171,3 +171,4 @@ PEExpectedVariableNameEOF=identifier for variable name PEExpectedVariableName=Expected identifier for variable name but found '%1$S'. PEExpectedVariableFallback=Expected variable reference fallback after ','. PEExpectedVariableCommaOrCloseParen=Expected ',' or ')' after variable name in variable reference but found '%1$S'. +PESubgridNotSupported=Support for the 'subgrid' keyword of CSS Grid is not enabled. diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 0cb599d4194..71ddcdbe182 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -131,6 +131,7 @@ using namespace mozilla::layout; using namespace mozilla::gfx; #define GRID_ENABLED_PREF_NAME "layout.css.grid.enabled" +#define GRID_TEMPLATE_SUBGRID_ENABLED_PREF_NAME "layout.css.grid-template-subgrid-value.enabled" #define RUBY_ENABLED_PREF_NAME "layout.css.ruby.enabled" #define STICKY_ENABLED_PREF_NAME "layout.css.sticky.enabled" #define DISPLAY_CONTENTS_ENABLED_PREF_NAME "layout.css.display-contents.enabled" @@ -730,6 +731,22 @@ nsLayoutUtils::UnsetValueEnabled() return sUnsetValueEnabled; } +bool +nsLayoutUtils::IsGridTemplateSubgridValueEnabled() +{ + static bool sGridTemplateSubgridValueEnabled; + static bool sGridTemplateSubgridValueEnabledPrefCached = false; + + if (!sGridTemplateSubgridValueEnabledPrefCached) { + sGridTemplateSubgridValueEnabledPrefCached = true; + Preferences::AddBoolVarCache(&sGridTemplateSubgridValueEnabled, + GRID_TEMPLATE_SUBGRID_ENABLED_PREF_NAME, + false); + } + + return sGridTemplateSubgridValueEnabled; +} + bool nsLayoutUtils::IsTextAlignTrueValueEnabled() { diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 7f743994a8d..4990fcecc6e 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -2308,6 +2308,12 @@ public: */ static bool UnsetValueEnabled(); + /** + * Checks whether support for the CSS grid-template-{columns,rows} 'subgrid X' + * value is enabled. + */ + static bool IsGridTemplateSubgridValueEnabled(); + /** * Checks whether support for the CSS text-align (and -moz-text-align-last) * 'true' value is enabled. diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index b3a93e73395..a2f6a137e59 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -8775,6 +8775,10 @@ CSSParserImpl::ParseGridTemplateColumnsRows(nsCSSProperty aPropID) nsSubstring* ident = NextIdent(); if (ident) { if (ident->LowerCaseEqualsLiteral("subgrid")) { + if (!nsLayoutUtils::IsGridTemplateSubgridValueEnabled()) { + REPORT_UNEXPECTED(PESubgridNotSupported); + return false; + } if (!ParseOptionalLineNameListAfterSubgrid(value)) { return false; } @@ -8946,6 +8950,10 @@ CSSParserImpl::ParseGridTemplate() nsSubstring* ident = NextIdent(); if (ident) { if (ident->LowerCaseEqualsLiteral("subgrid")) { + if (!nsLayoutUtils::IsGridTemplateSubgridValueEnabled()) { + REPORT_UNEXPECTED(PESubgridNotSupported); + return false; + } if (!ParseOptionalLineNameListAfterSubgrid(value)) { return false; } @@ -9019,6 +9027,10 @@ CSSParserImpl::ParseGridTemplateAfterSlash(bool aColumnsIsTrackList) nsSubstring* ident = NextIdent(); if (ident) { if (ident->LowerCaseEqualsLiteral("subgrid")) { + if (!nsLayoutUtils::IsGridTemplateSubgridValueEnabled()) { + REPORT_UNEXPECTED(PESubgridNotSupported); + return false; + } if (!ParseOptionalLineNameListAfterSubgrid(rowsValue)) { return false; } diff --git a/layout/style/test/property_database.js b/layout/style/test/property_database.js index b51ba29b315..3c8176b8f0e 100644 --- a/layout/style/test/property_database.js +++ b/layout/style/test/property_database.js @@ -5703,6 +5703,9 @@ if (IsCSSPropertyPrefEnabled("layout.css.ruby.enabled")) { } if (IsCSSPropertyPrefEnabled("layout.css.grid.enabled")) { + var isGridTemplateSubgridValueEnabled = + IsCSSPropertyPrefEnabled("layout.css.grid-template-subgrid-value.enabled"); + gCSSProperties["display"].other_values.push("grid", "inline-grid"); gCSSProperties["grid-auto-flow"] = { domProp: "gridAutoFlow", @@ -5797,15 +5800,7 @@ if (IsCSSPropertyPrefEnabled("layout.css.grid.enabled")) { "[a] 2.5fr [z] Repeat(4, [a] 20px [] auto [b c]) [d]", "[a] 2.5fr [z] Repeat(4, [a] 20px [] auto) [d]", "[a] 2.5fr [z] Repeat(4, 20px [b c] auto [b c]) [d]", - "[a] 2.5fr [z] Repeat(4, 20px auto) [d]", - - // See https://bugzilla.mozilla.org/show_bug.cgi?id=981300 - "[none auto subgrid min-content max-content foo] 40px", - - "subgrid", - "subgrid [] [foo bar]", - "subgrid repeat(1, [])", - "subgrid Repeat(4, [a] [b c] [] [d])", + "[a] 2.5fr [z] Repeat(4, 20px auto) [d]" ], invalid_values: [ "", @@ -5842,6 +5837,23 @@ if (IsCSSPropertyPrefEnabled("layout.css.grid.enabled")) { "repeat(2.5, 20px)", "repeat(2, (foo))", "repeat(2, foo)", + "40px calc(0px + rubbish)" + ], + unbalanced_values: [ + "(foo] 40px", + ] + }; + if (isGridTemplateSubgridValueEnabled) { + gCSSProperties["grid-template-columns"].other_values.push( + // See https://bugzilla.mozilla.org/show_bug.cgi?id=981300 + "[none auto subgrid min-content max-content foo] 40px", + + "subgrid", + "subgrid [] [foo bar]", + "subgrid repeat(1, [])", + "subgrid Repeat(4, [a] [b c] [] [d])" + ); + gCSSProperties["grid-template-columns"].invalid_values.push( "subgrid (foo) 40px", "subgrid (foo 40px)", "(foo) subgrid", @@ -5854,13 +5866,9 @@ if (IsCSSPropertyPrefEnabled("layout.css.grid.enabled")) { "subgrid repeat(1)", "subgrid repeat(1, )", "subgrid repeat(2, (40px))", - "subgrid repeat(2, foo)", - "40px calc(0px + rubbish)", - ], - unbalanced_values: [ - "(foo] 40px", - ] - }; + "subgrid repeat(2, foo)" + ); + } gCSSProperties["grid-template-rows"] = { domProp: "gridTemplateRows", inherited: false, @@ -5910,18 +5918,11 @@ if (IsCSSPropertyPrefEnabled("layout.css.grid.enabled")) { "none / none", ], other_values: [ - "subgrid", // <'grid-template-columns'> / <'grid-template-rows'> "40px / 100px", "[foo] 40px [bar] / [baz] 100px [fizz]", " none/100px", "40px/none", - "subgrid/40px 20px", - "subgrid [foo] [] [bar baz] / 40px 20px", - "40px 20px/subgrid", - "40px 20px/subgrid [foo] [] repeat(3, [a] [b]) [bar baz]", - "subgrid/subgrid", - "subgrid [foo] [] [bar baz]/subgrid [foo] [] [bar baz]", // [ / ]? [ ? ? ? ]+ "'fizz'", "[bar] 'fizz'", @@ -5933,15 +5934,28 @@ if (IsCSSPropertyPrefEnabled("layout.css.grid.enabled")) { "[foo] 40px / [bar] 'fizz' 100px [buzz] \n [a] '.' 200px [b]", ], invalid_values: [ - "subgrid []", - "subgrid [] / 'fizz'", - "subgrid / 'fizz'", "[foo] [bar] 40px / 100px", "40px / [fizz] [buzz] 100px", "40px / [fizz] [buzz] 'foo'", "none / 'foo'" ] }; + if (isGridTemplateSubgridValueEnabled) { + gCSSProperties["grid-template"].other_values.push( + "subgrid", + "subgrid/40px 20px", + "subgrid [foo] [] [bar baz] / 40px 20px", + "40px 20px/subgrid", + "40px 20px/subgrid [foo] [] repeat(3, [a] [b]) [bar baz]", + "subgrid/subgrid", + "subgrid [foo] [] [bar baz]/subgrid [foo] [] [bar baz]" + ); + gCSSProperties["grid-template"].invalid_values.push( + "subgrid []", + "subgrid [] / 'fizz'", + "subgrid / 'fizz'" + ); + } gCSSProperties["grid"] = { domProp: "grid", diff --git a/layout/style/test/test_grid_container_shorthands.html b/layout/style/test/test_grid_container_shorthands.html index 4de4aacfc8c..4cef96369d6 100644 --- a/layout/style/test/test_grid_container_shorthands.html +++ b/layout/style/test/test_grid_container_shorthands.html @@ -12,6 +12,9 @@