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
This commit is contained in:
Nicholas Nethercote 2019-08-15 05:29:16 +00:00
Родитель 53eecbbb23
Коммит 28020e4832
2 изменённых файлов: 11 добавлений и 25 удалений

Просмотреть файл

@ -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<UNumberFormat, NumberFormatDeleter>;
/**
* 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;

Просмотреть файл

@ -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