Changeset 107196 in webkit


Ignore:
Timestamp:
Feb 9, 2012 1:33:54 AM (12 years ago)
Author:
tkent@chromium.org
Message:

Do not localize numbers in scientific notation
https://bugs.webkit.org/show_bug.cgi?id=78208

Reviewed by Hajime Morita.

.:

  • ManualTests/input-number-localization.html: Updated for scientific notation.

Source/WebCore:

For a preparation of fixing http://wkb.ug/62939, we stop supporting
localized numbers in scientific notation in <input type=number>.

We're going to change number localization processing so that it replaces
letters one by one. It will be very hard to support scientific notation.

  • html/NumberInputType.cpp:

(WebCore::isE): A helper functio for String::find() to detect scientific notation.
(WebCore::NumberInputType::visibleValue): Avoid localization for scientific notation.
(WebCore::NumberInputType::convertFromVisibleValue): ditto.
(WebCore::NumberInputType::isAcceptableValue):
Use convertFromVisibleValue, also stop accepting a standard format as a fallback.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r107190 r107196  
     12012-02-09  Kent Tamura  <tkent@chromium.org>
     2
     3        Do not localize numbers in scientific notation
     4        https://bugs.webkit.org/show_bug.cgi?id=78208
     5
     6        Reviewed by Hajime Morita.
     7
     8        * ManualTests/input-number-localization.html: Updated for scientific notation.
     9
    1102012-02-09  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
    211
  • trunk/ManualTests/input-number-localization.html

    r91636 r107196  
    1313<div id="console"></div>
    1414
    15 <p>Output test: The following text field should have a localized representation for "-1234.5678".
     15<p>Output test 1: The following text field should have a localized representation for "-1234.5678".
    1616e.g. "-1234.5678" for en_US locale, "-1234,5678" for fr_FR locale. The thousand separator is
    1717currently off.</p>
    1818<div><input type=number value="-1234.5678" step=any></div>
    1919
    20 <p>Input test: Type a localized representation of a number (e.g. -1,234.5678 for en_US locale,
     20<p>Output test 2: The following text field should have "-1234.5678E+12" in any locale.
     21</p>
     22<div><input type=number value="-1234.5678E+12" step=any></div>
     23
     24<p>Input test 1: Type a localized representation of a number (e.g. -1,234.5678 for en_US locale,
    2125-1.234,5678 for fr_FR locale) into the following text field.
    2226You'll see an equivalent number in the standard format on the bottom of the text field.</p>
     27<p>Input test 2: Type a number in the scientific notation (e.g. 0.1234e-10.)
     28You'll see the same number string on the bottom of the text field.</p>
    2329<div><input type=number id=target step=any oninput="handleInput()"></div>
    2430<div>Standard format: <output id=output></output></div>
  • trunk/Source/WebCore/ChangeLog

    r107194 r107196  
     12012-02-09  Kent Tamura  <tkent@chromium.org>
     2
     3        Do not localize numbers in scientific notation
     4        https://bugs.webkit.org/show_bug.cgi?id=78208
     5
     6        Reviewed by Hajime Morita.
     7
     8        For a preparation of fixing http://wkb.ug/62939, we stop supporting
     9        localized numbers in scientific notation in <input type=number>.
     10
     11        We're going to change number localization processing so that it replaces
     12        letters one by one. It will be very hard to support scientific notation.
     13
     14        * html/NumberInputType.cpp:
     15        (WebCore::isE): A helper functio for String::find() to detect scientific notation.
     16        (WebCore::NumberInputType::visibleValue): Avoid localization for scientific notation.
     17        (WebCore::NumberInputType::convertFromVisibleValue): ditto.
     18        (WebCore::NumberInputType::isAcceptableValue):
     19        Use convertFromVisibleValue, also stop accepting a standard format as a fallback.
     20
    1212012-02-09  Leo Yang  <leo.yang@torchmobile.com.cn>
    222
  • trunk/Source/WebCore/html/NumberInputType.cpp

    r105490 r107196  
    284284}
    285285
     286static bool isE(UChar ch)
     287{
     288    return ch == 'e' || ch == 'E';
     289}
     290
    286291String NumberInputType::visibleValue() const
    287292{
    288293    String currentValue = element()->value();
    289294    if (currentValue.isEmpty())
     295        return currentValue;
     296    // We don't localize scientific notations.
     297    if (currentValue.find(isE) != notFound)
    290298        return currentValue;
    291299    // FIXME: The following three lines should be removed when we
     
    301309    if (visibleValue.isEmpty())
    302310        return visibleValue;
     311    // We don't localize scientific notations.
     312    if (visibleValue.find(isE) != notFound)
     313        return visibleValue;
    303314    return convertFromLocalizedNumber(visibleValue);
    304315}
     
    306317bool NumberInputType::isAcceptableValue(const String& proposedValue)
    307318{
    308     return proposedValue.isEmpty() || parseToDoubleForNumberType(convertFromLocalizedNumber(proposedValue), 0) || parseToDoubleForNumberType(proposedValue, 0);
     319    String standardValue = convertFromVisibleValue(proposedValue);
     320    return standardValue.isEmpty() || parseToDoubleForNumberType(standardValue, 0);
    309321}
    310322
Note: See TracChangeset for help on using the changeset viewer.