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 199054 a8591c466832aa509fcb05ee4adc8587c45dde21
parent 199053 3c2296328968c216085e1bc6e8580eab581026ef
child 199055 84046431c8309ce5cd3c18931164b18dd429a65a
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, sylvestre
bugs1004327
milestone31.0a2
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||Android) == number-min-height-1.html number-min-height-1-ref.html
 skip-if(B2G||Android) == number-min-height-2.html number-min-height-2-ref.html
 skip-if(B2G||Android) == number-max-height-1.html number-max-height-1-ref.html
 skip-if(B2G||Android) == 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