Commit b1d0b76c authored by tkent@chromium.org's avatar tkent@chromium.org

2011-03-22 Kent Tamura <tkent@chromium.org>

        Reviewed by Eric Seidel.

        REGRESSION(r80096): Number type input unexpectedly rounds fractional values
        https://bugs.webkit.org/show_bug.cgi?id=56367

        Introduce clampToInteger(unsigned).

        * wtf/MathExtras.h:
        (clampToInteger): Added.
2011-03-22  Kent Tamura  <tkent@chromium.org>

        Reviewed by Eric Seidel.

        REGRESSION(r80096): Number type input unexpectedly rounds fractional values
        https://bugs.webkit.org/show_bug.cgi?id=56367

        Because the default value of the maximum fractional digits of NSNumberFormatter
        and ICU NumberFormat is 3, the value 0.55555 is rounded to 0.556 in a
        localized representation. This bug affects only in Mac and Chromium.

        To fix this bug,
         - Add "maximum fractional digits" parameter to formatLocalizedNumber(), and
         - NumberInputType::visibleValue uses parseToDoubleForNumberTypeWithDecimalPlaces()
          instead of parseToDoubleForNumberType().

        No automated tests because the behavior is locale-dependent. This change
        updates a manual test.

        * html/NumberInputType.cpp:
        (WebCore::NumberInputType::visibleValue):
          Use parseToDoubleForNumberTypeWithDecimalPlaces() and passing fractional
          part length to formatLocalizedNumber().
        * manual-tests/input-number-localization.html:
          Update the test to cover this change.
        * platform/text/LocalizedNumber.h: Add a parameter to formatLocalizedNumber().
        * platform/text/LocalizedNumberICU.cpp:
        (WebCore::formatLocalizedNumber): Call setMaximumFractionalDigits().
        * platform/text/LocalizedNumberNone.cpp:
        (WebCore::formatLocalizedNumber):
        * platform/text/mac/LocalizedNumberMac.mm:
        (WebCore::formatLocalizedNumber): Call setMaximumFractionalDigits().

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@81649 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bf1568f3
2011-03-22 Kent Tamura <tkent@chromium.org>
Reviewed by Eric Seidel.
REGRESSION(r80096): Number type input unexpectedly rounds fractional values
https://bugs.webkit.org/show_bug.cgi?id=56367
Introduce clampToInteger(unsigned).
* wtf/MathExtras.h:
(clampToInteger): Added.
2011-03-21 Adam Barth <abarth@webkit.org>
Reviewed by Eric Seidel.
......
......@@ -233,6 +233,11 @@ inline int clampToPositiveInteger(float d)
return static_cast<int>(std::max<float>(std::min(d, maxIntAsFloat), 0));
}
inline int clampToInteger(unsigned value)
{
return static_cast<int>(std::min(value, static_cast<unsigned>(std::numeric_limits<int>::max())));
}
#if !COMPILER(MSVC) && !COMPILER(WINSCW) && !(COMPILER(RVCT) && (OS(SYMBIAN) || PLATFORM(BREWMP)))
using std::isfinite;
using std::isinf;
......
2011-03-22 Kent Tamura <tkent@chromium.org>
Reviewed by Eric Seidel.
REGRESSION(r80096): Number type input unexpectedly rounds fractional values
https://bugs.webkit.org/show_bug.cgi?id=56367
Because the default value of the maximum fractional digits of NSNumberFormatter
and ICU NumberFormat is 3, the value 0.55555 is rounded to 0.556 in a
localized representation. This bug affects only in Mac and Chromium.
To fix this bug,
- Add "maximum fractional digits" parameter to formatLocalizedNumber(), and
- NumberInputType::visibleValue uses parseToDoubleForNumberTypeWithDecimalPlaces()
instead of parseToDoubleForNumberType().
No automated tests because the behavior is locale-dependent. This change
updates a manual test.
* html/NumberInputType.cpp:
(WebCore::NumberInputType::visibleValue):
Use parseToDoubleForNumberTypeWithDecimalPlaces() and passing fractional
part length to formatLocalizedNumber().
* manual-tests/input-number-localization.html:
Update the test to cover this change.
* platform/text/LocalizedNumber.h: Add a parameter to formatLocalizedNumber().
* platform/text/LocalizedNumberICU.cpp:
(WebCore::formatLocalizedNumber): Call setMaximumFractionalDigits().
* platform/text/LocalizedNumberNone.cpp:
(WebCore::formatLocalizedNumber):
* platform/text/mac/LocalizedNumberMac.mm:
(WebCore::formatLocalizedNumber): Call setMaximumFractionalDigits().
2011-03-21 Abhishek Arya <inferno@chromium.org>
Reviewed by Eric Seidel.
......@@ -223,8 +223,9 @@ String NumberInputType::visibleValue() const
if (currentValue.isEmpty())
return currentValue;
double doubleValue = numeric_limits<double>::quiet_NaN();
parseToDoubleForNumberType(currentValue, &doubleValue);
String localized = formatLocalizedNumber(doubleValue);
unsigned decimalPlace;
parseToDoubleForNumberTypeWithDecimalPlaces(currentValue, &doubleValue, &decimalPlace);
String localized = formatLocalizedNumber(doubleValue, decimalPlace);
return localized.isEmpty() ? currentValue : localized;
}
......
......@@ -12,9 +12,9 @@
<body>
<div id="console"></div>
<p>Output test: The following text field should have a localized representation for "-1234.56".
e.g. "-1,234.56" for en_US locale, "-1.234,56" for fr_FR locale.</p>
<div><input type=number value="-1234.56" step=any></div>
<p>Output test: The following text field should have a localized representation for "-1234.5678".
e.g. "-1,234.5678" for en_US locale, "-1.234,5678" for fr_FR locale.</p>
<div><input type=number value="-1234.5678" step=any></div>
<p>Input test: Type a localized representation of a number into the following text field.
You'll see an equivalent number in the standard format on the bottom of the text field.</p>
......
......@@ -47,7 +47,9 @@ double parseLocalizedNumber(const String&);
// current locale. If an implementation doesn't support localized
// numbers or the input value is NaN or Infinitiy, the function should
// return an empty string.
String formatLocalizedNumber(double);
// fractionDigits is the maximum length of the fractional parts of the
// resultant string.
String formatLocalizedNumber(double, unsigned fractionDigits);
} // namespace WebCore
......
......@@ -34,6 +34,7 @@
#include <limits>
#include <unicode/numfmt.h>
#include <unicode/parsepos.h>
#include <wtf/MathExtras.h>
#include <wtf/PassOwnPtr.h>
using namespace std;
......@@ -73,12 +74,13 @@ double parseLocalizedNumber(const String& numberString)
return U_SUCCESS(status) ? numericResult : numeric_limits<double>::quiet_NaN();
}
String formatLocalizedNumber(double number)
String formatLocalizedNumber(double number, unsigned fractionDigits)
{
NumberFormat* formatter = numberFormatter();
if (!formatter)
return String();
UnicodeString result;
formatter->setMaximumFractionDigits(clampToInteger(fractionDigits));
formatter->format(number, result);
return String(result.getBuffer(), result.length());
}
......
......@@ -42,7 +42,7 @@ double parseLocalizedNumber(const String&)
return numeric_limits<double>::quiet_NaN();
}
String formatLocalizedNumber(double)
String formatLocalizedNumber(double, unsigned)
{
return String();
}
......
......@@ -65,10 +65,12 @@ double parseLocalizedNumber(const String& numberString)
return [number doubleValue];
}
String formatLocalizedNumber(double inputNumber)
String formatLocalizedNumber(double inputNumber, unsigned fractionDigits)
{
RetainPtr<NSNumber> number(AdoptNS, [[NSNumber alloc] initWithDouble:inputNumber]);
return String([numberFormatter() stringFromNumber:number.get()]);
RetainPtr<NSNumberFormatter> formatter = numberFormatter();
[formatter.get() setMaximumFractionDigits:fractionDigits];
return String([formatter.get() stringFromNumber:number.get()]);
}
} // namespace WebCore
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment