Skip to content

Commit

Permalink
Bug 1573720 - Convert dom.forms.number.grouping to a static pref. r=m…
Browse files Browse the repository at this point in the history
…_kato

Differential Revision: https://phabricator.services.mozilla.com/D41911

--HG--
extra : moz-landing-system : lando
  • Loading branch information
nnethercote committed Aug 15, 2019
1 parent 53eecbb commit 28020e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
28 changes: 3 additions & 25 deletions intl/unicharutil/util/ICUUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions modules/libpref/init/StaticPrefList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 28020e4

Please sign in to comment.