Bug 1386871 - Move font-display pref into StylePrefs. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Thu, 03 Aug 2017 10:37:02 +1000
changeset 620085 bbde7837c30b00d92b59b1a1ca5bb8c894cdc037
parent 620083 8f4d1916f25057f237df0ef44f00444d9f7cc88c
child 620086 6e68969e09e5b08bddf76a440791808e1c1e8457
push id71903
push userxquan@mozilla.com
push dateThu, 03 Aug 2017 00:46:00 +0000
reviewersheycam
bugs1386871
milestone57.0a1
Bug 1386871 - Move font-display pref into StylePrefs. r?heycam MozReview-Commit-ID: 9CDZSdTOacs
layout/style/StylePrefs.cpp
layout/style/StylePrefs.h
layout/style/nsCSSParser.cpp
layout/style/nsCSSProps.cpp
layout/style/nsFontFaceLoader.cpp
--- a/layout/style/StylePrefs.cpp
+++ b/layout/style/StylePrefs.cpp
@@ -5,26 +5,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/StylePrefs.h"
 
 #include "mozilla/Preferences.h"
 
 namespace mozilla {
 
+bool StylePrefs::sFontDisplayEnabled;
 bool StylePrefs::sOpentypeSVGEnabled;
 bool StylePrefs::sWebkitPrefixedAliasesEnabled;
 bool StylePrefs::sWebkitDevicePixelRatioEnabled;
 bool StylePrefs::sMozGradientsEnabled;
 bool StylePrefs::sControlCharVisibility;
 bool StylePrefs::sFramesTimingFunctionEnabled;
 
 /* static */ void
 StylePrefs::Init()
 {
+  Preferences::AddBoolVarCache(&sFontDisplayEnabled,
+                               "layout.css.font-display.enabled");
   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");
--- a/layout/style/StylePrefs.h
+++ b/layout/style/StylePrefs.h
@@ -8,16 +8,17 @@
 
 #ifndef mozilla_StylePrefs_h
 #define mozilla_StylePrefs_h
 
 namespace mozilla {
 
 struct StylePrefs
 {
+  static bool sFontDisplayEnabled;
   static bool sOpentypeSVGEnabled;
   static bool sWebkitPrefixedAliasesEnabled;
   static bool sWebkitDevicePixelRatioEnabled;
   static bool sMozGradientsEnabled;
   static bool sControlCharVisibility;
   static bool sFramesTimingFunctionEnabled;
 
   static void Init();
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -3968,18 +3968,17 @@ CSSParserImpl::ParseFontDescriptor(nsCSS
     OUTPUT_ERROR();
     return false;
   }
 
   nsCSSFontDesc descID = nsCSSProps::LookupFontDesc(descName);
   nsCSSValue value;
 
   if (descID == eCSSFontDesc_UNKNOWN ||
-      (descID == eCSSFontDesc_Display &&
-       !Preferences::GetBool("layout.css.font-display.enabled"))) {
+      (descID == eCSSFontDesc_Display && !StylePrefs::sFontDisplayEnabled)) {
     if (NonMozillaVendorIdentifier(descName)) {
       // silently skip other vendors' extensions
       Unused << SkipDeclaration(true);
       return true;
     } else {
       REPORT_UNEXPECTED_P(PEUnknownFontDesc, descName);
       return false;
     }
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -20,16 +20,17 @@
 
 #include "mozilla/dom/AnimationEffectReadOnlyBinding.h" // for PlaybackDirection
 #include "mozilla/LookAndFeel.h" // for system colors
 
 #include "nsString.h"
 #include "nsStaticNameTable.h"
 
 #include "mozilla/Preferences.h"
+#include "mozilla/StylePrefs.h"
 
 using namespace mozilla;
 
 typedef nsCSSProps::KTableEntry KTableEntry;
 
 // By wrapping internal-only properties in this macro, we are not
 // exposing them in the CSSOM. Since currently it is not necessary to
 // allow accessing them in that way, it is easier and cheaper to just
@@ -607,18 +608,17 @@ nsCSSProps::LookupPropertyByIDLName(cons
 }
 
 nsCSSFontDesc
 nsCSSProps::LookupFontDesc(const nsACString& aFontDesc)
 {
   MOZ_ASSERT(gFontDescTable, "no lookup table, needs addref");
   nsCSSFontDesc which = nsCSSFontDesc(gFontDescTable->Lookup(aFontDesc));
 
-  if (which == eCSSFontDesc_Display &&
-      !Preferences::GetBool("layout.css.font-display.enabled")) {
+  if (which == eCSSFontDesc_Display && !StylePrefs::sFontDisplayEnabled) {
     which = eCSSFontDesc_UNKNOWN;
   } else if (which == eCSSFontDesc_UNKNOWN) {
     // check for unprefixed font-feature-settings/font-language-override
     nsAutoCString prefixedProp;
     prefixedProp.AppendLiteral("-moz-");
     prefixedProp.Append(aFontDesc);
     which = nsCSSFontDesc(gFontDescTable->Lookup(prefixedProp));
   }
@@ -626,18 +626,17 @@ nsCSSProps::LookupFontDesc(const nsACStr
 }
 
 nsCSSFontDesc
 nsCSSProps::LookupFontDesc(const nsAString& aFontDesc)
 {
   MOZ_ASSERT(gFontDescTable, "no lookup table, needs addref");
   nsCSSFontDesc which = nsCSSFontDesc(gFontDescTable->Lookup(aFontDesc));
 
-  if (which == eCSSFontDesc_Display &&
-      !Preferences::GetBool("layout.css.font-display.enabled")) {
+  if (which == eCSSFontDesc_Display && !StylePrefs::sFontDisplayEnabled) {
     which = eCSSFontDesc_UNKNOWN;
   } else if (which == eCSSFontDesc_UNKNOWN) {
     // check for unprefixed font-feature-settings/font-language-override
     nsAutoString prefixedProp;
     prefixedProp.AppendLiteral("-moz-");
     prefixedProp.Append(aFontDesc);
     which = nsCSSFontDesc(gFontDescTable->Lookup(prefixedProp));
   }
--- a/layout/style/nsFontFaceLoader.cpp
+++ b/layout/style/nsFontFaceLoader.cpp
@@ -9,16 +9,17 @@
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Logging.h"
 
 #include "nsFontFaceLoader.h"
 
 #include "nsError.h"
 #include "nsContentUtils.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/StylePrefs.h"
 #include "mozilla/Telemetry.h"
 #include "FontFaceSet.h"
 #include "nsPresContext.h"
 #include "nsIPrincipal.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIHttpChannel.h"
 #include "nsIContentPolicy.h"
 #include "nsContentPolicyUtils.h"
@@ -302,13 +303,13 @@ nsFontFaceLoader::Cancel()
   }
   mChannel->Cancel(NS_BINDING_ABORTED);
 }
 
 uint8_t
 nsFontFaceLoader::GetFontDisplay()
 {
   uint8_t fontDisplay = NS_FONT_DISPLAY_AUTO;
-  if (Preferences::GetBool("layout.css.font-display.enabled")) {
+  if (StylePrefs::sFontDisplayEnabled) {
     fontDisplay = mUserFontEntry->GetFontDisplay();
   }
   return fontDisplay;
 }