From 28020e48321294b8a84a84fda0504536d3cd414e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 15 Aug 2019 05:29:16 +0000 Subject: [PATCH] Bug 1573720 - Convert dom.forms.number.grouping to a static pref. r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D41911 --HG-- extra : moz-landing-system : lando --- intl/unicharutil/util/ICUUtils.cpp | 28 +++--------------------- modules/libpref/init/StaticPrefList.yaml | 8 +++++++ 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/intl/unicharutil/util/ICUUtils.cpp b/intl/unicharutil/util/ICUUtils.cpp index cc9657ba4ea7..512780b94807 100644 --- a/intl/unicharutil/util/ICUUtils.cpp +++ b/intl/unicharutil/util/ICUUtils.cpp @@ -8,7 +8,7 @@ # include "mozilla/UniquePtr.h" # include "ICUUtils.h" -# include "mozilla/Preferences.h" +# include "mozilla/StaticPrefs_dom.h" # include "mozilla/intl/LocaleService.h" # include "nsIContent.h" # include "mozilla/dom/Document.h" @@ -30,28 +30,6 @@ class NumberFormatDeleter { using UniqueUNumberFormat = UniquePtr; -/** - * This pref just controls whether we format the number with grouping separator - * characters when the internal value is set or updated. It does not stop the - * user from typing in a number and using grouping separators. - */ -static bool gLocaleNumberGroupingEnabled; -static const char LOCALE_NUMBER_GROUPING_PREF_STR[] = - "dom.forms.number.grouping"; - -static bool LocaleNumberGroupingIsEnabled() { - static bool sInitialized = false; - - if (!sInitialized) { - /* check and register ourselves with the pref */ - Preferences::AddBoolVarCache(&gLocaleNumberGroupingEnabled, - LOCALE_NUMBER_GROUPING_PREF_STR, false); - sInitialized = true; - } - - return gLocaleNumberGroupingEnabled; -} - void ICUUtils::LanguageTagIterForContent::GetNext(nsACString& aBCP47LangTag) { if (mCurrentFallbackIndex < 0) { mCurrentFallbackIndex = 0; @@ -115,7 +93,7 @@ bool ICUUtils::LocalizeNumber(double aValue, continue; } unum_setAttribute(format.get(), UNUM_GROUPING_USED, - LocaleNumberGroupingIsEnabled()); + StaticPrefs::dom_forms_number_grouping()); // ICU default is a maximum of 3 significant fractional digits. We don't // want that limit, so we set it to the maximum that a double can represent // (14-16 decimal fractional digits). @@ -151,7 +129,7 @@ double ICUUtils::ParseNumber(nsAString& aValue, UErrorCode status = U_ZERO_ERROR; UniqueUNumberFormat format( unum_open(UNUM_DECIMAL, nullptr, 0, langTag.get(), nullptr, &status)); - if (!LocaleNumberGroupingIsEnabled()) { + if (!StaticPrefs::dom_forms_number_grouping()) { unum_setAttribute(format.get(), UNUM_GROUPING_USED, UBool(0)); } int32_t parsePos = 0; diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index f5642472df4b..2f487e1b1aec 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -1397,6 +1397,14 @@ value: false mirror: always +# This pref just controls whether we format the number with grouping separator +# characters when the internal value is set or updated. It does not stop the +# user from typing in a number and using grouping separators. +- name: dom.forms.number.grouping + type: bool + value: false + mirror: always + # Whether the Gamepad API is enabled - name: dom.gamepad.enabled type: bool