Bug 1004327 - Don't limit the number of significant fractional digits for <input type=number>. r=bz, a=sylvestre
authorJonathan Watt <jwatt@jwatt.org>
Fri, 02 May 2014 10:25:40 +0100
changeset 192191 8c9e76ede410
parent 192190 2ad68daa2b58
child 192192 b955f950df88
push id3518
push userjwatt@jwatt.org
push date2014-05-04 13:08 +0000
treeherdermozilla-beta@8c9e76ede410 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, sylvestre
bugs1004327
milestone30.0
Bug 1004327 - Don't limit the number of significant fractional digits for <input type=number>. r=bz, a=sylvestre
intl/unicharutil/util/ICUUtils.cpp
layout/reftests/forms/input/number/number-significant-fractional-digits-ref.html
layout/reftests/forms/input/number/number-significant-fractional-digits.html
layout/reftests/forms/input/number/reftest.list
--- a/intl/unicharutil/util/ICUUtils.cpp
+++ b/intl/unicharutil/util/ICUUtils.cpp
@@ -103,16 +103,20 @@ ICUUtils::LocalizeNumber(double aValue,
   nsAutoCString langTag;
   aLangTags.GetNext(langTag);
   while (!langTag.IsEmpty()) {
     UErrorCode status = U_ZERO_ERROR;
     AutoCloseUNumberFormat format(unum_open(UNUM_DECIMAL, nullptr, 0,
                                             langTag.get(), nullptr, &status));
     unum_setAttribute(format, UNUM_GROUPING_USED,
                       LocaleNumberGroupingIsEnabled());
+    // 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).
+    unum_setAttribute(format, UNUM_MAX_FRACTION_DIGITS, 16);
     int32_t length = unum_formatDouble(format, aValue, buffer, kBufferSize,
                                        nullptr, &status);
     NS_ASSERTION(length < kBufferSize &&
                  status != U_BUFFER_OVERFLOW_ERROR &&
                  status != U_STRING_NOT_TERMINATED_WARNING,
                  "Need a bigger buffer?!");
     if (U_SUCCESS(status)) {
       ICUUtils::AssignUCharArrayToString(buffer, length, aLocalizedValue);
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/input/number/number-significant-fractional-digits-ref.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    <input type="number" value="1.00100000000001" style="width:100%;">
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/input/number/number-significant-fractional-digits.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+  <head>
+    <script>
+
+document.addEventListener("MozReftestInvalidate", function() {
+  document.getElementById("i").stepUp();
+  document.documentElement.className = "";
+}, false);
+
+    </script>
+  </head>
+  <body>
+    <input id="i" type="number" value="1.001" step="0.00000000000001"
+           style="width:100%;">
+  </body>
+</html>
--- a/layout/reftests/forms/input/number/reftest.list
+++ b/layout/reftests/forms/input/number/reftest.list
@@ -24,16 +24,19 @@ fuzzy-if(/^Windows\x20NT\x205\.1/.test(h
 == number-auto-width-1.html number-auto-width-1-ref.html
 
 # min-height/max-height tests:
 skip-if(B2G) == number-min-height-1.html number-min-height-1-ref.html
 skip-if(B2G) == number-min-height-2.html number-min-height-2-ref.html
 skip-if(B2G) == number-max-height-1.html number-max-height-1-ref.html
 skip-if(B2G) == number-max-height-2.html number-max-height-2-ref.html
 
+# number of significant fractional digits:
+== number-significant-fractional-digits.html number-significant-fractional-digits-ref.html
+
 # focus
 # autofocus is disabled on B2G
 # https://bugzilla.mozilla.org/show_bug.cgi?id=965763
 skip-if(B2G) needs-focus == focus-handling.html focus-handling-ref.html
 
 # select
 == number-selected.html number-selected-ref.html