Changeset 81649 in webkit
- Timestamp:
- Mar 22, 2011 12:43:21 AM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r81647 r81649 1 2011-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 1 13 2011-03-21 Adam Barth <abarth@webkit.org> 2 14 -
trunk/Source/JavaScriptCore/wtf/MathExtras.h
r81081 r81649 234 234 } 235 235 236 inline int clampToInteger(unsigned value) 237 { 238 return static_cast<int>(std::min(value, static_cast<unsigned>(std::numeric_limits<int>::max()))); 239 } 240 236 241 #if !COMPILER(MSVC) && !COMPILER(WINSCW) && !(COMPILER(RVCT) && (OS(SYMBIAN) || PLATFORM(BREWMP))) 237 242 using std::isfinite; -
trunk/Source/WebCore/ChangeLog
r81648 r81649 1 2011-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 1 34 2011-03-21 Abhishek Arya <inferno@chromium.org> 2 35 -
trunk/Source/WebCore/html/NumberInputType.cpp
r80096 r81649 224 224 return currentValue; 225 225 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); 228 229 return localized.isEmpty() ? currentValue : localized; 229 230 } -
trunk/Source/WebCore/manual-tests/input-number-localization.html
r80096 r81649 13 13 <div id="console"></div> 14 14 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". 16 e.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> 18 18 19 19 <p>Input test: Type a localized representation of a number into the following text field. -
trunk/Source/WebCore/platform/text/LocalizedNumber.h
r80096 r81649 48 48 // numbers or the input value is NaN or Infinitiy, the function should 49 49 // return an empty string. 50 String formatLocalizedNumber(double); 50 // fractionDigits is the maximum length of the fractional parts of the 51 // resultant string. 52 String formatLocalizedNumber(double, unsigned fractionDigits); 51 53 52 54 } // namespace WebCore -
trunk/Source/WebCore/platform/text/LocalizedNumberICU.cpp
r80203 r81649 35 35 #include <unicode/numfmt.h> 36 36 #include <unicode/parsepos.h> 37 #include <wtf/MathExtras.h> 37 38 #include <wtf/PassOwnPtr.h> 38 39 … … 74 75 } 75 76 76 String formatLocalizedNumber(double number )77 String formatLocalizedNumber(double number, unsigned fractionDigits) 77 78 { 78 79 NumberFormat* formatter = numberFormatter(); … … 80 81 return String(); 81 82 UnicodeString result; 83 formatter->setMaximumFractionDigits(clampToInteger(fractionDigits)); 82 84 formatter->format(number, result); 83 85 return String(result.getBuffer(), result.length()); -
trunk/Source/WebCore/platform/text/LocalizedNumberNone.cpp
r80096 r81649 43 43 } 44 44 45 String formatLocalizedNumber(double )45 String formatLocalizedNumber(double, unsigned) 46 46 { 47 47 return String(); -
trunk/Source/WebCore/platform/text/mac/LocalizedNumberMac.mm
r80198 r81649 66 66 } 67 67 68 String formatLocalizedNumber(double inputNumber )68 String formatLocalizedNumber(double inputNumber, unsigned fractionDigits) 69 69 { 70 70 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()]); 72 74 } 73 75
Note: See TracChangeset
for help on using the changeset viewer.