Bug 1366956 part 1 - Move CSS prefs from nsCSSParser into an independent class. r=heycam
authorXidorn Quan <me@upsuper.org>
Tue, 18 Jul 2017 10:54:32 +1000
changeset 371953 3ba584a59aa7dab3e35c7a6980e0a65a9c5df432
parent 371952 7b5773c5820946d344eebd2316febb7374ea7644
child 371954 01dd3ada68f209d3fbac8501668dc29501bac00c
push id32259
push userarchaeopteryx@coole-files.de
push dateMon, 31 Jul 2017 09:10:01 +0000
treeherdermozilla-central@b1dcb20102b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1366956
milestone56.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 1366956 part 1 - Move CSS prefs from nsCSSParser into an independent class. r=heycam MozReview-Commit-ID: S5xaJcP1jb
layout/build/nsLayoutStatics.cpp
layout/style/ServoBindings.toml
layout/style/StylePrefs.cpp
layout/style/StylePrefs.h
layout/style/moz.build
layout/style/nsCSSParser.cpp
layout/style/nsCSSParser.h
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -116,16 +116,17 @@
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/dom/HTMLVideoElement.h"
 #include "TouchManager.h"
 #include "MediaDecoder.h"
 #include "MediaPrefs.h"
 #include "mozilla/ServoBindings.h"
 #include "mozilla/StaticPresData.h"
+#include "mozilla/StylePrefs.h"
 #include "mozilla/dom/WebIDLGlobalNameHash.h"
 #include "mozilla/dom/ipc/IPCBlobInputStreamStorage.h"
 #include "mozilla/dom/U2FTokenManager.h"
 
 using namespace mozilla;
 using namespace mozilla::net;
 using namespace mozilla::dom;
 using namespace mozilla::dom::ipc;
@@ -229,17 +230,17 @@ nsLayoutStatics::Initialize()
   }
 
   rv = nsCCUncollectableMarker::Init();
   if (NS_FAILED(rv)) {
     NS_ERROR("Could not initialize nsCCUncollectableMarker");
     return rv;
   }
 
-  nsCSSParser::Startup();
+  StylePrefs::Init();
   nsCSSRuleProcessor::Startup();
 
 #ifdef MOZ_XUL
   rv = nsXULPopupManager::Init();
   if (NS_FAILED(rv)) {
     NS_ERROR("Could not initialize nsXULPopupManager");
     return rv;
   }
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -56,16 +56,17 @@ headers = [
     "mozilla/Keyframe.h",
     "mozilla/ServoElementSnapshot.h",
     "mozilla/ServoElementSnapshotTable.h",
     "mozilla/css/ErrorReporter.h",
     "mozilla/dom/Element.h",
     "mozilla/dom/ChildIterator.h",
     "mozilla/dom/NameSpaceConstants.h",
     "mozilla/LookAndFeel.h",
+    "mozilla/StylePrefs.h",
     "mozilla/ServoBindings.h",
     "mozilla/ServoMediaList.h",
     "mozilla/ServoStyleContext.h",
     "nsCSSCounterStyleRule.h",
     "nsCSSFontFaceRule.h",
     "nsMediaFeatures.h",
     "nsMediaList.h",
     "nsXBLBinding.h",
@@ -131,16 +132,17 @@ whitelist-types = [
     "mozilla::css::SheetParsingMode",
     "mozilla::css::URLMatchingFunction",
     "mozilla::dom::IterationCompositeOperation",
     "mozilla::dom::StyleChildrenIterator",
     "mozilla::HalfCorner",
     "mozilla::MallocSizeOf",
     "mozilla::PropertyStyleAnimationValuePair",
     "mozilla::ServoTraversalFlags",
+    "mozilla::StylePrefs",
     "mozilla::StyleShapeRadius",
     "mozilla::StyleGrid.*",
     "mozilla::UpdateAnimationsTasks",
     "mozilla::LookAndFeel",
     "mozilla::gfx::Float",
     "mozilla::gfx::FontVariation",
     ".*ThreadSafe.*Holder",
     "AnonymousContent",
new file mode 100644
--- /dev/null
+++ b/layout/style/StylePrefs.cpp
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/StylePrefs.h"
+
+#include "mozilla/Preferences.h"
+
+namespace mozilla {
+
+bool StylePrefs::sOpentypeSVGEnabled;
+bool StylePrefs::sWebkitPrefixedAliasesEnabled;
+bool StylePrefs::sWebkitDevicePixelRatioEnabled;
+bool StylePrefs::sMozGradientsEnabled;
+bool StylePrefs::sControlCharVisibility;
+bool StylePrefs::sFramesTimingFunctionEnabled;
+
+/* static */ void
+StylePrefs::Init()
+{
+  Preferences::AddBoolVarCache(&sOpentypeSVGEnabled,
+                               "gfx.font_rendering.opentype_svg.enabled");
+  Preferences::AddBoolVarCache(&sWebkitPrefixedAliasesEnabled,
+                               "layout.css.prefixes.webkit");
+  Preferences::AddBoolVarCache(&sWebkitDevicePixelRatioEnabled,
+                               "layout.css.prefixes.device-pixel-ratio-webkit");
+  Preferences::AddBoolVarCache(&sMozGradientsEnabled,
+                               "layout.css.prefixes.gradients");
+  Preferences::AddBoolVarCache(&sControlCharVisibility,
+                               "layout.css.control-characters.visible");
+  Preferences::AddBoolVarCache(&sFramesTimingFunctionEnabled,
+                               "layout.css.frames-timing.enabled");
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/layout/style/StylePrefs.h
@@ -0,0 +1,28 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* A namespace class for style system prefs */
+
+#ifndef mozilla_StylePrefs_h
+#define mozilla_StylePrefs_h
+
+namespace mozilla {
+
+struct StylePrefs
+{
+  static bool sOpentypeSVGEnabled;
+  static bool sWebkitPrefixedAliasesEnabled;
+  static bool sWebkitDevicePixelRatioEnabled;
+  static bool sMozGradientsEnabled;
+  static bool sControlCharVisibility;
+  static bool sFramesTimingFunctionEnabled;
+
+  static void Init();
+};
+
+} // namespace mozilla
+
+#endif // mozilla_StylePrefs_h
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -126,16 +126,17 @@ EXPORTS.mozilla += [
     'ServoStyleSheet.h',
     'ServoSupportsRule.h',
     'ServoTypes.h',
     'ServoUtils.h',
     'SheetType.h',
     'StyleAnimationValue.h',
     'StyleBackendType.h',
     'StyleComplexColor.h',
+    'StylePrefs.h',
     'StyleSetHandle.h',
     'StyleSetHandleInlines.h',
     'StyleSheet.h',
     'StyleSheetInfo.h',
     'StyleSheetInlines.h',
     'URLExtraData.h',
 ]
 
@@ -261,16 +262,17 @@ UNIFIED_SOURCES += [
     'ServoPageRule.cpp',
     'ServoSpecifiedValues.cpp',
     'ServoStyleContext.cpp',
     'ServoStyleRule.cpp',
     'ServoStyleSet.cpp',
     'ServoStyleSheet.cpp',
     'ServoSupportsRule.cpp',
     'StyleAnimationValue.cpp',
+    'StylePrefs.cpp',
     'StyleRule.cpp',
     'StyleSheet.cpp',
     'URLExtraData.cpp',
 ]
 
 # - nsLayoutStylesheetCache.cpp needs to be built separately because it uses
 # nsExceptionHandler.h, which includes windows.h.
 SOURCES += [
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -54,35 +54,28 @@
 #include "mozilla/Sprintf.h"
 #include "nsContentUtils.h"
 #include "nsAutoPtr.h"
 #include "CSSCalc.h"
 #include "nsMediaFeatures.h"
 #include "nsLayoutUtils.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/StylePrefs.h"
 #include "nsRuleData.h"
 #include "mozilla/CSSVariableValues.h"
 #include "mozilla/dom/AnimationEffectReadOnlyBinding.h"
 #include "mozilla/dom/URL.h"
 #include "gfxFontFamilyList.h"
 
 using namespace mozilla;
 using namespace mozilla::css;
 
 typedef nsCSSProps::KTableEntry KTableEntry;
 
-// pref-backed bool values (hooked up in nsCSSParser::Startup)
-static bool sOpentypeSVGEnabled;
-static bool sWebkitPrefixedAliasesEnabled;
-static bool sWebkitDevicePixelRatioEnabled;
-static bool sMozGradientsEnabled;
-static bool sControlCharVisibility;
-static bool sFramesTimingFunctionEnabled;
-
 const uint32_t
 nsCSSProps::kParserVariantTable[eCSSProperty_COUNT_no_shorthands] = {
 #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, \
                  stylestruct_, stylestructoffset_, animtype_)                 \
   parsevariant_,
 #define CSS_PROP_LIST_INCLUDE_LOGICAL
 #include "nsCSSPropList.h"
 #undef CSS_PROP_LIST_INCLUDE_LOGICAL
@@ -3502,22 +3495,22 @@ CSSParserImpl::ParseMediaQueryExpression
   nsMediaExpression *expr = aQuery->NewExpression();
 
   // case insensitive from CSS - must be lower cased
   nsContentUtils::ASCIIToLower(mToken.mIdent);
   nsDependentString featureString(mToken.mIdent, 0);
   uint8_t satisfiedReqFlags = 0;
 
   // Strip off "-webkit-" prefix from featureString:
-  if (sWebkitPrefixedAliasesEnabled &&
+  if (StylePrefs::sWebkitPrefixedAliasesEnabled &&
       StringBeginsWith(featureString, NS_LITERAL_STRING("-webkit-"))) {
     satisfiedReqFlags |= nsMediaFeature::eHasWebkitPrefix;
     featureString.Rebind(featureString, 8);
   }
-  if (sWebkitDevicePixelRatioEnabled) {
+  if (StylePrefs::sWebkitDevicePixelRatioEnabled) {
     satisfiedReqFlags |= nsMediaFeature::eWebkitDevicePixelRatioPrefEnabled;
   }
 
   // Strip off "min-"/"max-" prefix from featureString:
   if (StringBeginsWith(featureString, NS_LITERAL_STRING("min-"))) {
     expr->mRange = nsMediaExpression::eMin;
     featureString.Rebind(featureString, 4);
   } else if (StringBeginsWith(featureString, NS_LITERAL_STRING("max-"))) {
@@ -7023,17 +7016,17 @@ CSSParserImpl::ParseTreePseudoElement(ns
 #endif
 
 nsCSSKeyword
 CSSParserImpl::LookupKeywordPrefixAware(nsAString& aKeywordStr,
                                         const KTableEntry aKeywordTable[])
 {
   nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(aKeywordStr);
 
-  if (!sWebkitPrefixedAliasesEnabled) {
+  if (!StylePrefs::sWebkitPrefixedAliasesEnabled) {
     // Not accepting webkit-prefixed keywords -> don't do anything special.
     return keyword;
   }
 
   if (aKeywordTable == nsCSSProps::kDisplayKTable) {
     if ((keyword == eCSSKeyword__webkit_box ||
          keyword == eCSSKeyword__webkit_inline_box)) {
       // Make a note that we're accepting some "-webkit-{inline-}box" styling,
@@ -7048,17 +7041,17 @@ CSSParserImpl::LookupKeywordPrefixAware(
       // If we've seen "display: -webkit-box" (or "-webkit-inline-box") in an
       // earlier declaration and we honored it, then we have to watch out for
       // later "display: -moz-box" (and "-moz-inline-box") declarations; they're
       // likely just a halfhearted attempt at compatibility, and they actually
       // end up stomping on our emulation of the earlier -webkit-box
       // display-value, via the CSS cascade. To prevent this problem, we treat
       // "display: -moz-box" & "-moz-inline-box" as if they were simply a
       // repetition of the webkit equivalent that we already parsed.
-      MOZ_ASSERT(sWebkitPrefixedAliasesEnabled,
+      MOZ_ASSERT(StylePrefs::sWebkitPrefixedAliasesEnabled,
                  "The only way mWebkitBoxUnprefixState can be eHaveUnprefixed "
                  "is if we're supporting webkit-prefixed aliases");
       return (keyword == eCSSKeyword__moz_box) ?
         eCSSKeyword__webkit_box : eCSSKeyword__webkit_inline_box;
     }
   }
 
   return keyword;
@@ -7643,17 +7636,17 @@ CSSParserImpl::ParseVariant(nsCSSValue& 
       if ((aVariantMask & VARIANT_SYSFONT) != 0) {
         if (eCSSKeyword__moz_use_system_font == keyword &&
             !IsParsingCompoundProperty()) {
           aValue.SetSystemFontValue();
           return CSSParseResult::Ok;
         }
       }
       if ((aVariantMask & VARIANT_OPENTYPE_SVG_KEYWORD) != 0) {
-        if (sOpentypeSVGEnabled) {
+        if (StylePrefs::sOpentypeSVGEnabled) {
           aVariantMask |= VARIANT_KEYWORD;
         }
       }
       if ((aVariantMask & VARIANT_KEYWORD) != 0) {
         int32_t value;
         if (nsCSSProps::FindKeyword(keyword, aKeywordTable, value)) {
           aValue.SetIntValue(value, eCSSUnit_Enumerated);
           return CSSParseResult::Ok;
@@ -7721,21 +7714,21 @@ CSSParserImpl::ParseVariant(nsCSSValue& 
     SetValueToURL(aValue, tk->mIdent);
     return CSSParseResult::Ok;
   }
   if ((aVariantMask & VARIANT_GRADIENT) != 0 &&
       eCSSToken_Function == tk->mType) {
     // a generated gradient
     nsDependentString tmp(tk->mIdent, 0);
     uint8_t gradientFlags = 0;
-    if (sMozGradientsEnabled &&
+    if (StylePrefs::sMozGradientsEnabled &&
         StringBeginsWith(tmp, NS_LITERAL_STRING("-moz-"))) {
       tmp.Rebind(tmp, 5);
       gradientFlags |= eGradient_MozLegacy;
-    } else if (sWebkitPrefixedAliasesEnabled &&
+    } else if (StylePrefs::sWebkitPrefixedAliasesEnabled &&
                StringBeginsWith(tmp, NS_LITERAL_STRING("-webkit-"))) {
       tmp.Rebind(tmp, 8);
       gradientFlags |= eGradient_WebkitLegacy;
     }
     if (StringBeginsWith(tmp, NS_LITERAL_STRING("repeating-"))) {
       tmp.Rebind(tmp, 10);
       gradientFlags |= eGradient_Repeating;
     }
@@ -7843,17 +7836,17 @@ CSSParserImpl::ParseVariant(nsCSSValue& 
     }
     if (tk->mIdent.LowerCaseEqualsLiteral("steps")) {
       if (!ParseTransitionStepTimingFunctionValues(aValue)) {
         SkipUntil(')');
         return CSSParseResult::Error;
       }
       return CSSParseResult::Ok;
     }
-    if (sFramesTimingFunctionEnabled &&
+    if (StylePrefs::sFramesTimingFunctionEnabled &&
         tk->mIdent.LowerCaseEqualsLiteral("frames")) {
       if (!ParseTransitionFramesTimingFunctionValues(aValue)) {
         SkipUntil(')');
         return CSSParseResult::Error;
       }
       return CSSParseResult::Ok;
     }
   }
@@ -12211,17 +12204,17 @@ CSSParserImpl::IsFunctionTokenValidForIm
     funcName.LowerCaseEqualsLiteral("repeating-linear-gradient") ||
     funcName.LowerCaseEqualsLiteral("repeating-radial-gradient") ||
     funcName.LowerCaseEqualsLiteral("-moz-linear-gradient") ||
     funcName.LowerCaseEqualsLiteral("-moz-radial-gradient") ||
     funcName.LowerCaseEqualsLiteral("-moz-repeating-linear-gradient") ||
     funcName.LowerCaseEqualsLiteral("-moz-repeating-radial-gradient") ||
     funcName.LowerCaseEqualsLiteral("-moz-image-rect") ||
     funcName.LowerCaseEqualsLiteral("-moz-element") ||
-    (sWebkitPrefixedAliasesEnabled &&
+    (StylePrefs::sWebkitPrefixedAliasesEnabled &&
      (funcName.LowerCaseEqualsLiteral("-webkit-gradient") ||
       funcName.LowerCaseEqualsLiteral("-webkit-linear-gradient") ||
       funcName.LowerCaseEqualsLiteral("-webkit-radial-gradient") ||
       funcName.LowerCaseEqualsLiteral("-webkit-repeating-linear-gradient") ||
       funcName.LowerCaseEqualsLiteral("-webkit-repeating-radial-gradient")));
 }
 
 // Parse one item of the background shorthand property.
@@ -17868,33 +17861,16 @@ CSSParserImpl::IsValueValidForProperty(c
 }
 
 } // namespace
 
 // Recycling of parser implementation objects
 
 static CSSParserImpl* gFreeList = nullptr;
 
-/* static */ void
-nsCSSParser::Startup()
-{
-  Preferences::AddBoolVarCache(&sOpentypeSVGEnabled,
-                               "gfx.font_rendering.opentype_svg.enabled");
-  Preferences::AddBoolVarCache(&sWebkitPrefixedAliasesEnabled,
-                               "layout.css.prefixes.webkit");
-  Preferences::AddBoolVarCache(&sWebkitDevicePixelRatioEnabled,
-                               "layout.css.prefixes.device-pixel-ratio-webkit");
-  Preferences::AddBoolVarCache(&sMozGradientsEnabled,
-                               "layout.css.prefixes.gradients");
-  Preferences::AddBoolVarCache(&sControlCharVisibility,
-                               "layout.css.control-characters.visible");
-  Preferences::AddBoolVarCache(&sFramesTimingFunctionEnabled,
-                               "layout.css.frames-timing.enabled");
-}
-
 nsCSSParser::nsCSSParser(mozilla::css::Loader* aLoader,
                          CSSStyleSheet* aSheet)
 {
   CSSParserImpl *impl = gFreeList;
   if (impl) {
     gFreeList = impl->mNextFree;
     impl->mNextFree = nullptr;
   } else {
@@ -18226,12 +18202,12 @@ nsCSSParser::IsValueValidForProperty(con
   return static_cast<CSSParserImpl*>(mImpl)->
     IsValueValidForProperty(aPropID, aPropValue);
 }
 
 /* static */
 uint8_t
 nsCSSParser::ControlCharVisibilityDefault()
 {
-  return sControlCharVisibility
+  return StylePrefs::sControlCharVisibility
     ? NS_STYLE_CONTROL_CHARACTER_VISIBILITY_VISIBLE
     : NS_STYLE_CONTROL_CHARACTER_VISIBILITY_HIDDEN;
 }
--- a/layout/style/nsCSSParser.h
+++ b/layout/style/nsCSSParser.h
@@ -46,17 +46,16 @@ enum class SupportsParsingSettings {
 // Interface to the css parser.
 
 class MOZ_STACK_CLASS nsCSSParser {
 public:
   explicit nsCSSParser(mozilla::css::Loader* aLoader = nullptr,
                        mozilla::CSSStyleSheet* aSheet = nullptr);
   ~nsCSSParser();
 
-  static void Startup();
   static void Shutdown();
 
 private:
   nsCSSParser(nsCSSParser const&) = delete;
   nsCSSParser& operator=(nsCSSParser const&) = delete;
 
 public:
   /**