Changeset 81649 in webkit


Ignore:
Timestamp:
Mar 22, 2011 12:43:21 AM (13 years ago)
Author:
tkent@chromium.org
Message:

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().
Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r81647 r81649  
     12011-03-22  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        REGRESSION(r80096): Number type input unexpectedly rounds fractional values
     6        https://bugs.webkit.org/show_bug.cgi?id=56367
     7
     8        Introduce clampToInteger(unsigned).
     9       
     10        * wtf/MathExtras.h:
     11        (clampToInteger): Added.
     12
    1132011-03-21  Adam Barth  <abarth@webkit.org>
    214
  • trunk/Source/JavaScriptCore/wtf/MathExtras.h

    r81081 r81649  
    234234}
    235235
     236inline int clampToInteger(unsigned value)
     237{
     238    return static_cast<int>(std::min(value, static_cast<unsigned>(std::numeric_limits<int>::max())));
     239}
     240
    236241#if !COMPILER(MSVC) && !COMPILER(WINSCW) && !(COMPILER(RVCT) && (OS(SYMBIAN) || PLATFORM(BREWMP)))
    237242using std::isfinite;
  • trunk/Source/WebCore/ChangeLog

    r81648 r81649  
     12011-03-22  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        REGRESSION(r80096): Number type input unexpectedly rounds fractional values
     6        https://bugs.webkit.org/show_bug.cgi?id=56367
     7       
     8        Because the default value of the maximum fractional digits of NSNumberFormatter
     9        and ICU NumberFormat is 3, the value 0.55555 is rounded to 0.556 in a
     10        localized representation. This bug affects only in Mac and Chromium.
     11
     12        To fix this bug,
     13         - Add "maximum fractional digits" parameter to formatLocalizedNumber(), and
     14         - NumberInputType::visibleValue uses parseToDoubleForNumberTypeWithDecimalPlaces()
     15          instead of parseToDoubleForNumberType().
     16
     17        No automated tests because the behavior is locale-dependent. This change
     18        updates a manual test.
     19
     20        * html/NumberInputType.cpp:
     21        (WebCore::NumberInputType::visibleValue):
     22          Use parseToDoubleForNumberTypeWithDecimalPlaces() and passing fractional
     23          part length to formatLocalizedNumber().
     24        * manual-tests/input-number-localization.html:
     25          Update the test to cover this change.
     26        * platform/text/LocalizedNumber.h: Add a parameter to formatLocalizedNumber().
     27        * platform/text/LocalizedNumberICU.cpp:
     28        (WebCore::formatLocalizedNumber): Call setMaximumFractionalDigits().
     29        * platform/text/LocalizedNumberNone.cpp:
     30        (WebCore::formatLocalizedNumber):
     31        * platform/text/mac/LocalizedNumberMac.mm:
     32        (WebCore::formatLocalizedNumber): Call setMaximumFractionalDigits().
     33
    1342011-03-21  Abhishek Arya  <inferno@chromium.org>
    235
  • trunk/Source/WebCore/html/NumberInputType.cpp

    r80096 r81649  
    224224        return currentValue;
    225225    double doubleValue = numeric_limits<double>::quiet_NaN();
    226     parseToDoubleForNumberType(currentValue, &doubleValue);
    227     String localized = formatLocalizedNumber(doubleValue);
     226    unsigned decimalPlace;
     227    parseToDoubleForNumberTypeWithDecimalPlaces(currentValue, &doubleValue, &decimalPlace);
     228    String localized = formatLocalizedNumber(doubleValue, decimalPlace);
    228229    return localized.isEmpty() ? currentValue : localized;
    229230}
  • trunk/Source/WebCore/manual-tests/input-number-localization.html

    r80096 r81649  
    1313<div id="console"></div>
    1414
    15 <p>Output test: The following text field should have a localized representation for "-1234.56".
    16 e.g. "-1,234.56" for en_US locale, "-1.234,56" for fr_FR locale.</p>
    17 <div><input type=number value="-1234.56" step=any></div>
     15<p>Output test: The following text field should have a localized representation for "-1234.5678".
     16e.g. "-1,234.5678" for en_US locale, "-1.234,5678" for fr_FR locale.</p>
     17<div><input type=number value="-1234.5678" step=any></div>
    1818
    1919<p>Input test: Type a localized representation of a number into the following text field.
  • trunk/Source/WebCore/platform/text/LocalizedNumber.h

    r80096 r81649  
    4848// numbers or the input value is NaN or Infinitiy, the function should
    4949// return an empty string.
    50 String formatLocalizedNumber(double);
     50// fractionDigits is the maximum length of the fractional parts of the
     51// resultant string.
     52String formatLocalizedNumber(double, unsigned fractionDigits);
    5153
    5254} // namespace WebCore
  • trunk/Source/WebCore/platform/text/LocalizedNumberICU.cpp

    r80203 r81649  
    3535#include <unicode/numfmt.h>
    3636#include <unicode/parsepos.h>
     37#include <wtf/MathExtras.h>
    3738#include <wtf/PassOwnPtr.h>
    3839
     
    7475}
    7576
    76 String formatLocalizedNumber(double number)
     77String formatLocalizedNumber(double number, unsigned fractionDigits)
    7778{
    7879    NumberFormat* formatter = numberFormatter();
     
    8081        return String();
    8182    UnicodeString result;
     83    formatter->setMaximumFractionDigits(clampToInteger(fractionDigits));
    8284    formatter->format(number, result);
    8385    return String(result.getBuffer(), result.length());
  • trunk/Source/WebCore/platform/text/LocalizedNumberNone.cpp

    r80096 r81649  
    4343}
    4444
    45 String formatLocalizedNumber(double)
     45String formatLocalizedNumber(double, unsigned)
    4646{
    4747    return String();
  • trunk/Source/WebCore/platform/text/mac/LocalizedNumberMac.mm

    r80198 r81649  
    6666}
    6767
    68 String formatLocalizedNumber(double inputNumber)
     68String formatLocalizedNumber(double inputNumber, unsigned fractionDigits)
    6969{
    7070    RetainPtr<NSNumber> number(AdoptNS, [[NSNumber alloc] initWithDouble:inputNumber]);
    71     return String([numberFormatter() stringFromNumber:number.get()]);
     71    RetainPtr<NSNumberFormatter> formatter = numberFormatter();
     72    [formatter.get() setMaximumFractionDigits:fractionDigits];
     73    return String([formatter.get() stringFromNumber:number.get()]);
    7274}
    7375
Note: See TracChangeset for help on using the changeset viewer.