Changeset 80096 in webkit
- Timestamp:
- Mar 1, 2011 10:54:56 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 17 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r80091 r80096 1 2011-03-01 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Dimitri Glazkov. 4 5 Support localized numbers in <input type=number> 6 https://bugs.webkit.org/show_bug.cgi?id=42484 7 8 Update an existing test because of removing the keyboard input 9 restriction feature. 10 11 * fast/forms/input-number-keyoperation-expected.txt: 12 * fast/forms/script-tests/input-number-keyoperation.js: 13 1 14 2011-03-01 Victoria Kirst <vrk@chromium.org> 2 15 -
trunk/LayoutTests/fast/forms/input-number-keyoperation-expected.txt
r76662 r80096 5 5 6 6 Inserting "ab123cd": 7 PASS input.value is " 123"7 PASS input.value is "" 8 8 Press the up arrow key: 9 9 PASS input.value is "124" -
trunk/LayoutTests/fast/forms/script-tests/input-number-keyoperation.js
r76662 r80096 8 8 debug('Inserting "ab123cd":'); 9 9 document.execCommand('InsertText', false, 'ab123cd'); 10 shouldBe('input.value', '" 123"');10 shouldBe('input.value', '""'); 11 11 12 12 debug('Press the up arrow key:'); 13 input.valueAsNumber = 123; 13 14 eventSender.keyDown('upArrow'); 14 15 shouldBe('input.value', '"124"'); -
trunk/Source/WebCore/ChangeLog
r80092 r80096 1 2011-03-01 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Dimitri Glazkov. 4 5 Support localized numbers in <input type=number> 6 https://bugs.webkit.org/show_bug.cgi?id=42484 7 8 This change adds support of localized numbers in <input type=number>. 9 This affects only the UI, and not HTMLInputElement::value. 10 11 - Remove the keyboard input restriction feature because it is hard to 12 retrieve characters usable for localized numbers in ICU. 13 14 - Separate convertFromVisibleValue() from sanitizeValue(). 15 sanitizeValue() is used for not only converting a renderer value to a 16 DOM value. 17 18 - Implement LocalizedNumber functions for ICU and NSNumberFormatter. 19 It is used only in Chromium for now. 20 21 Test: manual-tests/input-number-localization.html 22 23 * WebCore.gypi: Use LocalizedNumberICU.cpp. 24 * WebCore.xcodeproj/project.pbxproj: 25 Add LocalizedNumberMac.mm and remove LocalizedNumberNone.cpp. 26 * dom/InputElement.h: Introduce convertFromVisibleValue(). 27 * html/HTMLInputElement.cpp: 28 (WebCore::HTMLInputElement::convertFromVisibleValue): 29 * html/HTMLInputElement.h: 30 * html/InputType.cpp: 31 (WebCore::InputType::convertFromVisibleValue): 32 * html/InputType.h: 33 * html/NumberInputType.cpp: Remove isHTMLNumberCharacter(), 34 isNumberCharacter(), and handleBeforeTextInsertedEvent() because we 35 remove the keyboard input restriction feature for type=number. 36 (WebCore::NumberInputType::convertFromVisibleValue): 37 (WebCore::NumberInputType::sanitizeValue): 38 * html/NumberInputType.h: 39 * manual-tests/input-number-localization.html: Add a manual test because 40 the behavior depends on the current locale. 41 * platform/text/LocalizedNumber.h: Remove isLocalizedNumberCharacter(). 42 * platform/text/LocalizedNumberICU.cpp: 43 Implement LocalizedNumber functions with ICU NumberFormat. 44 (WebCore::createFormatterForCurrentLocale): 45 (WebCore::parseLocalizedNumber): 46 (WebCore::formatLocalizedNumber): 47 * platform/text/LocalizedNumberNone.cpp: Remove isLocalizedNumberCharacter(). 48 * platform/text/mac/LocalizedNumberMac.mm: 49 Implement LocalizedNumber functions with NSNumberFormatter. 50 (WebCore::parseLocalizedNumber): 51 (WebCore::formatLocalizedNumber): 52 * rendering/RenderTextControlSingleLine.cpp: 53 (WebCore::RenderTextControlSingleLine::subtreeHasChanged): 54 * wml/WMLInputElement.h: 55 (WebCore::WMLInputElement::convertFromVisibleValue): 56 Implemented as a function doing nothing. 57 1 58 2011-03-01 Yuta Kitamura <yutak@chromium.org> 2 59 -
trunk/Source/WebCore/WebCore.gypi
r80081 r80096 3386 3386 'platform/text/LineEnding.h', 3387 3387 'platform/text/LocalizedNumber.h', 3388 'platform/text/LocalizedNumber None.cpp',3388 'platform/text/LocalizedNumberICU.cpp', 3389 3389 'platform/text/ParserUtilities.h', 3390 3390 'platform/text/PlatformString.h', -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r80074 r80096 5603 5603 F4EAF4AF10C742B1009100D3 /* OpenTypeSanitizer.h in Headers */ = {isa = PBXBuildFile; fileRef = F4EAF4AD10C742B1009100D3 /* OpenTypeSanitizer.h */; }; 5604 5604 F5142C69123F12B000F5BD4C /* LocalizedNumber.h in Headers */ = {isa = PBXBuildFile; fileRef = F5142C68123F12B000F5BD4C /* LocalizedNumber.h */; }; 5605 F5142C6B123F12C500F5BD4C /* LocalizedNumberNone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5142C6A123F12C500F5BD4C /* LocalizedNumberNone.cpp */; };5606 5605 F55B3DAD1251F12D003EF269 /* BaseTextInputType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F55B3D791251F12D003EF269 /* BaseTextInputType.cpp */; }; 5607 5606 F55B3DAE1251F12D003EF269 /* BaseTextInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = F55B3D7A1251F12D003EF269 /* BaseTextInputType.h */; }; … … 5667 5666 F5C041E60FFCA96D00839D4A /* JSHTMLDataListElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5C041E10FFCA96D00839D4A /* JSHTMLDataListElement.cpp */; }; 5668 5667 F5C041E70FFCA96D00839D4A /* JSHTMLDataListElement.h in Headers */ = {isa = PBXBuildFile; fileRef = F5C041E20FFCA96D00839D4A /* JSHTMLDataListElement.h */; }; 5668 F5CC42DC12F801CA00D5F7E3 /* LocalizedNumberMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = F5CC42DB12F801CA00D5F7E3 /* LocalizedNumberMac.mm */; }; 5669 5669 F5D3A57C106B83B300545297 /* DateComponents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5D3A57A106B83B300545297 /* DateComponents.cpp */; }; 5670 5670 F5D3A57D106B83B300545297 /* DateComponents.h in Headers */ = {isa = PBXBuildFile; fileRef = F5D3A57B106B83B300545297 /* DateComponents.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 12009 12009 F4EAF4AD10C742B1009100D3 /* OpenTypeSanitizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenTypeSanitizer.h; path = opentype/OpenTypeSanitizer.h; sourceTree = "<group>"; }; 12010 12010 F5142C68123F12B000F5BD4C /* LocalizedNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizedNumber.h; sourceTree = "<group>"; }; 12011 F5142C6A123F12C500F5BD4C /* LocalizedNumberNone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LocalizedNumberNone.cpp; sourceTree = "<group>"; };12012 12011 F523D23B02DE4396018635CA /* HTMLDocument.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLDocument.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; }; 12013 12012 F523D23C02DE4396018635CA /* HTMLDocument.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = HTMLDocument.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; }; … … 12095 12094 F5C2869402846DCD018635CA /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = "<absolute>"; }; 12096 12095 F5C2869502846DCD018635CA /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; }; 12096 F5CC42DB12F801CA00D5F7E3 /* LocalizedNumberMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalizedNumberMac.mm; sourceTree = "<group>"; }; 12097 12097 F5D3A57A106B83B300545297 /* DateComponents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DateComponents.cpp; sourceTree = "<group>"; }; 12098 12098 F5D3A57B106B83B300545297 /* DateComponents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DateComponents.h; sourceTree = "<group>"; }; … … 17594 17594 89B5EAA011E8003D00F2367E /* LineEnding.h */, 17595 17595 F5142C68123F12B000F5BD4C /* LocalizedNumber.h */, 17596 F5142C6A123F12C500F5BD4C /* LocalizedNumberNone.cpp */,17597 17596 BC76AC110DD7AD5C00415F34 /* ParserUtilities.h */, 17598 17597 B2C3D9FB0D006C1D00EF6F26 /* PlatformString.h */, … … 17643 17642 B2C3D9FA0D006C1D00EF6F26 /* CharsetData.h */, 17644 17643 375CD239119D44EA00A2A859 /* HyphenationMac.mm */, 17644 F5CC42DB12F801CA00D5F7E3 /* LocalizedNumberMac.mm */, 17645 17645 B2AFFC860D00A5DF0030074D /* mac-encodings.txt */, 17646 17646 B2AFFC870D00A5DF0030074D /* make-charset-table.pl */, … … 24362 24362 06E81EEC0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm in Sources */, 24363 24363 89878567122CA064003AABDA /* LocalFileSystem.cpp in Sources */, 24364 F5 142C6B123F12C500F5BD4C /* LocalizedNumberNone.cppin Sources */,24364 F5CC42DC12F801CA00D5F7E3 /* LocalizedNumberMac.mm in Sources */, 24365 24365 C046E1AC1208A9FE00BA2CF7 /* LocalizedStrings.cpp in Sources */, 24366 24366 BC25B52A131C6D3900180E10 /* LocalizedStringsMac.mm in Sources */, -
trunk/Source/WebCore/dom/InputElement.h
r79954 r80096 62 62 // The value which is drawn by a renderer. 63 63 virtual String visibleValue() const = 0; 64 virtual String convertFromVisibleValue(const String&) const = 0; 64 65 65 66 // Returns true if the specified string can be set as the value of InputElement. -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r79777 r80096 1151 1151 } 1152 1152 1153 String HTMLInputElement::convertFromVisibleValue(const String& visibleValue) const 1154 { 1155 return m_inputType->convertFromVisibleValue(visibleValue); 1156 } 1157 1153 1158 bool HTMLInputElement::isAcceptableValue(const String& proposedValue) const 1154 1159 { -
trunk/Source/WebCore/html/HTMLInputElement.h
r76664 r80096 261 261 262 262 virtual String visibleValue() const; 263 virtual String convertFromVisibleValue(const String&) const; 263 264 virtual bool isAcceptableValue(const String&) const; 264 265 virtual String sanitizeValue(const String&) const; -
trunk/Source/WebCore/html/InputType.cpp
r77500 r80096 516 516 } 517 517 518 String InputType::convertFromVisibleValue(const String& visibleValue) const 519 { 520 return visibleValue; 521 } 522 518 523 bool InputType::isAcceptableValue(const String&) 519 524 { -
trunk/Source/WebCore/html/InputType.h
r79954 r80096 150 150 virtual bool canSetStringValue() const; 151 151 virtual String visibleValue() const; 152 virtual String convertFromVisibleValue(const String&) const; 152 153 virtual bool isAcceptableValue(const String&); 153 154 // Returing the null string means "use the default value." -
trunk/Source/WebCore/html/NumberInputType.cpp
r79954 r80096 54 54 static const double numberStepScaleFactor = 1.0; 55 55 56 // Returns true if the specified character can be a part of 'valid floating57 // point number' of HTML5.58 static bool isHTMLNumberCharacter(UChar ch)59 {60 return ch == '+' || ch == '-' || ch == '.' || ch == 'e' || ch == 'E' || isASCIIDigit(ch);61 }62 63 static bool isNumberCharacter(UChar ch)64 {65 return isLocalizedNumberCharacter(ch) || isHTMLNumberCharacter(ch);66 }67 68 56 PassOwnPtr<InputType> NumberInputType::create(HTMLInputElement* element) 69 57 { … … 184 172 } 185 173 186 void NumberInputType::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent* event)187 {188 unsigned length = event->text().length();189 bool hasInvalidChar = false;190 for (unsigned i = 0; i < length; ++i) {191 if (!isNumberCharacter(event->text()[i])) {192 hasInvalidChar = true;193 break;194 }195 }196 if (hasInvalidChar) {197 Vector<UChar> stripped;198 stripped.reserveCapacity(length);199 for (unsigned i = 0; i < length; ++i) {200 UChar ch = event->text()[i];201 if (!isNumberCharacter(ch))202 continue;203 stripped.append(ch);204 }205 event->setText(String::adopt(stripped));206 }207 TextFieldInputType::handleBeforeTextInsertedEvent(event);208 }209 210 174 void NumberInputType::handleWheelEvent(WheelEvent* event) 211 175 { … … 265 229 } 266 230 231 String NumberInputType::convertFromVisibleValue(const String& visibleValue) const 232 { 233 if (visibleValue.isEmpty()) 234 return visibleValue; 235 double parsedNumber = parseLocalizedNumber(visibleValue); 236 return isfinite(parsedNumber) ? serializeForNumberType(parsedNumber) : visibleValue; 237 } 238 267 239 bool NumberInputType::isAcceptableValue(const String& proposedValue) 268 240 { … … 274 246 if (proposedValue.isEmpty()) 275 247 return proposedValue; 276 // Try to parse the value as a localized number, then try to parse it as277 // the standard format.278 double parsedValue = parseLocalizedNumber(proposedValue);279 if (isfinite(parsedValue))280 return serializeForNumberType(parsedValue);281 248 return parseToDoubleForNumberType(proposedValue, 0) ? proposedValue : emptyAtom.string(); 282 249 } -
trunk/Source/WebCore/html/NumberInputType.h
r76661 r80096 58 58 virtual double stepScaleFactor() const; 59 59 virtual void handleKeydownEvent(KeyboardEvent*); 60 virtual void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*);61 60 virtual void handleWheelEvent(WheelEvent*); 62 61 virtual double parseToDouble(const String&, double) const; … … 66 65 virtual void handleBlurEvent(); 67 66 virtual String visibleValue() const; 67 virtual String convertFromVisibleValue(const String&) const; 68 68 virtual bool isAcceptableValue(const String&); 69 69 virtual String sanitizeValue(const String&); -
trunk/Source/WebCore/platform/text/LocalizedNumber.h
r76661 r80096 50 50 String formatLocalizedNumber(double); 51 51 52 // Returns true if the input character can be used to represent a53 // number in the browser locale. For example, this should return true for 0-9 .54 // , + - for en-US locale.55 bool isLocalizedNumberCharacter(UChar32);56 57 52 } // namespace WebCore 58 53 -
trunk/Source/WebCore/platform/text/LocalizedNumberICU.cpp
r80095 r80096 29 29 */ 30 30 31 #i fndef LocalizedNumber_h32 # define LocalizedNumber_h31 #include "config.h" 32 #include "LocalizedNumber.h" 33 33 34 #include <wtf/text/WTFString.h> 34 #include <limits> 35 #include <unicode/numfmt.h> 36 #include <wtf/PassOwnPtr.h> 37 38 using namespace std; 35 39 36 40 namespace WebCore { 37 41 38 // Parses a string representation of a floating point number localized 39 // for the browser's current locale. If the input string is not valid 40 // or an implementation doesn't support localized numbers, this 41 // function returns NaN. This function doesn't need to support 42 // scientific notation, NaN, +Infinity and -Infinity, and doesn't need 43 // to support the standard representations of ECMAScript and HTML5. 44 double parseLocalizedNumber(const String&); 42 static inline PassOwnPtr<NumberFormat> createFormatterForCurrentLocale() 43 { 44 UErrorCode status = U_ZERO_ERROR; 45 return adoptPtr(NumberFormat::createInstance(status)); 46 } 45 47 46 // Serializes the specified floating point number for the browser's 47 // current locale. If an implementation doesn't support localized 48 // numbers or the input value is NaN or Infinitiy, the function should 49 // return an empty string. 50 String formatLocalizedNumber(double); 48 double parseLocalizedNumber(const String& numberString) 49 { 50 if (numberString.isEmpty()) 51 return numeric_limits<double>::quiet_NaN(); 52 OwnPtr<NumberFormat> formatter = createFormatterForCurrentLocale(); 53 if (!formatter) 54 return numeric_limits<double>::quiet_NaN(); 55 UnicodeString numberUnicodeString(numberString.characters(), numberString.length()); 56 UErrorCode status = U_ZERO_ERROR; 57 Formattable result; 58 formatter->parse(numberUnicodeString, result, status); 59 if (status != U_ZERO_ERROR) 60 return numeric_limits<double>::quiet_NaN(); 61 double numericResult = result.getDouble(status); 62 return status == U_ZERO_ERROR ? numericResult : numeric_limits<double>::quiet_NaN(); 63 } 51 64 52 // Returns true if the input character can be used to represent a 53 // number in the browser locale. For example, this should return true for 0-9 . 54 // , + - for en-US locale. 55 bool isLocalizedNumberCharacter(UChar32); 65 String formatLocalizedNumber(double number) 66 { 67 OwnPtr<NumberFormat> formatter = createFormatterForCurrentLocale(); 68 if (!formatter) 69 return String(); 70 UnicodeString result; 71 formatter->format(number, result); 72 return String(result.getBuffer(), result.length()); 73 } 56 74 57 75 } // namespace WebCore 58 59 #endif // LocalizedNumber_h -
trunk/Source/WebCore/platform/text/LocalizedNumberNone.cpp
r76661 r80096 48 48 } 49 49 50 bool isLocalizedNumberCharacter(UChar32)51 {52 return false;53 }54 55 50 } // namespace WebCore -
trunk/Source/WebCore/platform/text/mac/LocalizedNumberMac.mm
r80095 r80096 33 33 34 34 #include <limits> 35 #import <Foundation/NSNumberFormatter.h> 36 #include <wtf/RetainPtr.h> 37 #include <wtf/text/CString.h> 35 38 36 39 using namespace std; … … 38 41 namespace WebCore { 39 42 40 double parseLocalizedNumber(const String& )43 double parseLocalizedNumber(const String& numberString) 41 44 { 42 return numeric_limits<double>::quiet_NaN(); 45 if (numberString.isEmpty()) 46 return numeric_limits<double>::quiet_NaN(); 47 RetainPtr<NSNumberFormatter> formatter(AdoptNS, [[NSNumberFormatter alloc] init]); 48 [formatter.get() setLocalizesFormat:YES]; 49 [formatter.get() setNumberStyle:NSNumberFormatterDecimalStyle]; 50 NSNumber *number = [formatter.get() numberFromString:numberString]; 51 if (!number) 52 return numeric_limits<double>::quiet_NaN(); 53 return [number doubleValue]; 43 54 } 44 55 45 String formatLocalizedNumber(double )56 String formatLocalizedNumber(double inputNumber) 46 57 { 47 return String(); 48 } 49 50 bool isLocalizedNumberCharacter(UChar32) 51 { 52 return false; 58 RetainPtr<NSNumber> number(AdoptNS, [[NSNumber alloc] initWithDouble:inputNumber]); 59 RetainPtr<NSNumberFormatter> formatter(AdoptNS, [[NSNumberFormatter alloc] init]); 60 [formatter.get() setLocalizesFormat:YES]; 61 [formatter.get() setNumberStyle:NSNumberFormatterDecimalStyle]; 62 return String([formatter.get() stringFromNumber:number.get()]); 53 63 } 54 64 55 65 } // namespace WebCore 66 -
trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp
r79978 r80096 192 192 String value = text(); 193 193 if (input->isAcceptableValue(value)) 194 input->setValueFromRenderer(input->sanitizeValue( value));194 input->setValueFromRenderer(input->sanitizeValue(input->convertFromVisibleValue(value))); 195 195 if (node()->isHTMLElement()) { 196 196 // Recalc for :invalid and hasUnacceptableValue() change. -
trunk/Source/WebCore/wml/WMLInputElement.h
r78232 r80096 65 65 virtual void setValueForUser(const String&); 66 66 virtual String visibleValue() const { return value(); } 67 virtual String convertFromVisibleValue(const String& value) const { return value; } 67 68 virtual void setValueFromRenderer(const String&); 68 69
Note: See TracChangeset
for help on using the changeset viewer.