Bug 1259889 Part 1 - Add @supports -moz-bool-pref for internal-only style sheets. r=heycam
authorTing-Yu Lin <tlin@mozilla.com>
Fri, 01 Apr 2016 21:11:11 +0800
changeset 291529 6559f99e1805147da0fb0c56e52a09397d36cc3b
parent 291528 600f96d25f8c94c73849dc98f0ad36769f9b57d3
child 291530 30aaf3805b5682774b3053528c3e675c73967b0b
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1259889
milestone48.0a1
Bug 1259889 Part 1 - Add @supports -moz-bool-pref for internal-only style sheets. r=heycam This is a internal-only syntax for guarding rules from a boolean preference. Nothing causes @supports rules to be re-evaluated except html.css registered in Part 2. This is needed for rendering the disclosure triangle of the summary element by using "display: list-item". Usage example: @supports -moz-bool-pref("dom.details_element.enabled") { /* css rules */ } MozReview-Commit-ID: HDCa8zHxYTA
layout/reftests/css-parsing/reftest.list
layout/reftests/css-parsing/supports-moz-bool-pref-ref.html
layout/reftests/css-parsing/supports-moz-bool-pref.html
layout/style/nsCSSParser.cpp
layout/tools/reftest/reftest-preferences.js
--- a/layout/reftests/css-parsing/reftest.list
+++ b/layout/reftests/css-parsing/reftest.list
@@ -1,8 +1,9 @@
 == at-rule-013.html at-rule-013-ref.html
 == invalid-url-handling.xhtml invalid-url-handling-ref.xhtml
 == pseudo-elements-1.html pseudo-elements-1-ref.html
 == invalid-attr-1.html invalid-attr-1-ref.html
 == at-rule-error-handling-import-1.html at-rule-error-handling-ref.html
 == at-rule-error-handling-media-1.html at-rule-error-handling-ref.html
 == invalid-font-face-descriptor-1.html invalid-font-face-descriptor-1-ref.html
 == two-dash-identifiers.html two-dash-identifiers-ref.html
+== supports-moz-bool-pref.html supports-moz-bool-pref-ref.html
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-parsing/supports-moz-bool-pref-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<!-- Any copyright is dedicated to the Public Domain.
+   - http://creativecommons.org/publicdomain/zero/1.0/ -->
+
+<html>
+  <body>
+    <p>This text should not have background color.</p>
+  </body>
+</html>
+
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-parsing/supports-moz-bool-pref.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<!-- Any copyright is dedicated to the Public Domain.
+   - http://creativecommons.org/publicdomain/zero/1.0/ -->
+
+<html>
+  <style>
+  /* This is not a user agent style sheet, so the style will be ignored.
+     "testing.supports.moz-bool-pref" is set to true in
+     layout/tools/reftest/reftest-preferences.js. */
+  @supports -moz-bool-pref("testing.supports.moz-bool-pref") {
+    p {
+      background-color: red;
+    }
+  }
+  </style>
+  <body>
+    <p>This text should not have background color.</p>
+  </body>
+</html>
+
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -689,16 +689,17 @@ protected:
   bool ParseKeyframesRule(RuleAppendFunc aAppendFunc, void* aProcessData);
   already_AddRefed<nsCSSKeyframeRule> ParseKeyframeRule();
   bool ParseKeyframeSelectorList(InfallibleTArray<float>& aSelectorList);
 
   bool ParseSupportsRule(RuleAppendFunc aAppendFunc, void* aProcessData);
   bool ParseSupportsCondition(bool& aConditionMet);
   bool ParseSupportsConditionNegation(bool& aConditionMet);
   bool ParseSupportsConditionInParens(bool& aConditionMet);
+  bool ParseSupportsMozBoolPrefName(bool& aConditionMet);
   bool ParseSupportsConditionInParensInsideParens(bool& aConditionMet);
   bool ParseSupportsConditionTerms(bool& aConditionMet);
   enum SupportsConditionTermOperator { eAnd, eOr };
   bool ParseSupportsConditionTermsAfterOperator(
                                        bool& aConditionMet,
                                        SupportsConditionTermOperator aOperator);
 
   bool ParseCounterStyleRule(RuleAppendFunc aAppendFunc, void* aProcessData);
@@ -4521,31 +4522,38 @@ CSSParserImpl::ParseSupportsConditionNeg
     return true;
   }
 
   return false;
 }
 
 // supports_condition_in_parens
 //   : '(' S* supports_condition_in_parens_inside_parens ')' S*
+//   | supports_condition_pref
 //   | general_enclosed
 //   ;
 bool
 CSSParserImpl::ParseSupportsConditionInParens(bool& aConditionMet)
 {
   if (!GetToken(true)) {
     REPORT_UNEXPECTED_EOF(PESupportsConditionInParensStartEOF);
     return false;
   }
 
   if (mToken.mType == eCSSToken_URL) {
     aConditionMet = false;
     return true;
   }
 
+  if (AgentRulesEnabled() &&
+      mToken.mType == eCSSToken_Function &&
+      mToken.mIdent.LowerCaseEqualsLiteral("-moz-bool-pref")) {
+    return ParseSupportsMozBoolPrefName(aConditionMet);
+  }
+
   if (mToken.mType == eCSSToken_Function ||
       mToken.mType == eCSSToken_Bad_URL) {
     if (!SkipUntil(')')) {
       REPORT_UNEXPECTED_EOF(PESupportsConditionInParensEOF);
       return false;
     }
     aConditionMet = false;
     return true;
@@ -4570,16 +4578,42 @@ CSSParserImpl::ParseSupportsConditionInP
     SkipUntil(')');
     aConditionMet = false;
     return true;
   }
 
   return true;
 }
 
+// supports_condition_pref
+//   : '-moz-bool-pref(' bool_pref_name ')'
+//   ;
+bool
+CSSParserImpl::ParseSupportsMozBoolPrefName(bool& aConditionMet)
+{
+  if (!GetToken(true)) {
+    return false;
+  }
+
+  if (mToken.mType != eCSSToken_String) {
+    SkipUntil(')');
+    return false;
+  }
+
+  aConditionMet = Preferences::GetBool(
+    NS_ConvertUTF16toUTF8(mToken.mIdent).get());
+
+  if (!ExpectSymbol(')', true)) {
+    SkipUntil(')');
+    return false;
+  }
+
+  return true;
+}
+
 // supports_condition_in_parens_inside_parens
 //   : core_declaration
 //   | supports_condition_negation
 //   | supports_condition_in_parens supports_condition_terms
 //   ;
 bool
 CSSParserImpl::ParseSupportsConditionInParensInsideParens(bool& aConditionMet)
 {
--- a/layout/tools/reftest/reftest-preferences.js
+++ b/layout/tools/reftest/reftest-preferences.js
@@ -109,8 +109,11 @@ user_pref("browser.tabs.remote.autostart
 user_pref("browser.tabs.remote.autostart.2", false);
 
 user_pref("startup.homepage_welcome_url", "");
 user_pref("startup.homepage_welcome_url.additional", "");
 user_pref("startup.homepage_override_url", "");
 user_pref("browser.usedOnWindows10.introURL", "");
 
 user_pref("media.gmp-manager.url.override", "http://localhost/dummy-gmp-manager.xml");
+
+// A fake bool pref for "@supports -moz-bool-pref" sanify test.
+user_pref("testing.supports.moz-bool-pref", true);