Changeset 51822 in webkit
- Timestamp:
- Dec 7, 2009 6:26:53 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 9 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r51819 r51822 1 2009-12-07 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 Add tests for HTMLInputElement::stepUp() and stepDown(). 6 https://bugs.webkit.org/show_bug.cgi?id=27451 7 8 * fast/forms/input-step-number-expected.txt: Added. 9 * fast/forms/input-step-number.html: Added. 10 * fast/forms/input-step-range-expected.txt: Added. 11 * fast/forms/input-step-range.html: Added. 12 * fast/forms/input-step-unsupported-expected.txt: Added. 13 * fast/forms/input-step-unsupported.html: Added. 14 * fast/forms/script-tests/input-step-number.js: Added. 15 * fast/forms/script-tests/input-step-range.js: Added. 16 * fast/forms/script-tests/input-step-unsupported.js: Added. 17 1 18 2009-12-07 Enrica Casucci <enrica@apple.com> 2 19 -
trunk/WebCore/ChangeLog
r51821 r51822 1 2009-12-07 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 Add support for HTMLInputElement::stepUp() and stepDown() for 6 type=number and type=range. 7 https://bugs.webkit.org/show_bug.cgi?id=27451 8 9 Our implementation of stepUp() and stepDown() rounds the resultant 10 value to conform to the step value. 11 Change the number-string conversion method for RenderSlider to be 12 consistent with type=number. 13 14 Tests: fast/forms/input-step-number.html 15 fast/forms/input-step-range.html 16 fast/forms/input-step-unsupported.html 17 18 * html/HTMLInputElement.cpp: 19 (WebCore::HTMLInputElement::rangeUnderflow): Unify the code for NUMBER and RANGE. 20 (WebCore::HTMLInputElement::rangeOverflow): Unify the code for NUMBER and RANGE. 21 (WebCore::HTMLInputElement::minimum): Renamed from rangeMinimum(), and support for NUMBER. 22 (WebCore::HTMLInputElement::maximum): Renamed from rangeMaximum(), and support for NUMBER. 23 (WebCore::HTMLInputElement::stepBase): 24 (WebCore::HTMLInputElement::stepMismatch): Use stepBase(). 25 (WebCore::HTMLInputElement::applyStepForNumberOrRange): 26 (WebCore::HTMLInputElement::stepUp): 27 (WebCore::HTMLInputElement::stepDown): 28 (WebCore::HTMLInputElement::formStringFromDouble): 29 * html/HTMLInputElement.h: 30 (WebCore::HTMLInputElement::stepUp): 31 (WebCore::HTMLInputElement::stepDown): 32 * html/HTMLInputElement.idl: Add stepUp() and stepDown(). 33 * rendering/RenderSlider.cpp: 34 (WebCore::SliderRange::SliderRange): Sync with rangeMinimum()/rangeMaximum() renaming. 35 (WebCore::RenderSlider::updateFromElement): Use formStringFromDouble(). 36 (WebCore::RenderSlider::setValueForPosition): Use formStringFromDouble(). 37 1 38 2009-12-07 Albert J. Wong <ajwong@chromium.org> 2 39 -
trunk/WebCore/html/HTMLInputElement.cpp
r51602 r51822 66 66 #include <wtf/MathExtras.h> 67 67 #include <wtf/StdLibExtras.h> 68 #include <wtf/dtoa.h> 68 69 69 70 using namespace std; … … 78 79 static const double numberDefaultStep = 1.0; 79 80 static const double numberStepScaleFactor = 1.0; 81 // Constant values for minimum(). 82 static const double numberDefaultMinimum = -DBL_MAX; 83 static const double rangeDefaultMinimum = 0.0; 84 // Constant values for maximum(). 85 static const double numberDefaultMaximum = DBL_MAX; 86 static const double rangeDefaultMaximum = 100.0; 80 87 81 88 HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f) … … 260 267 bool HTMLInputElement::rangeUnderflow() const 261 268 { 262 if (inputType() == NUMBER) { 263 double min = 0.0; 264 double doubleValue = 0.0; 265 if (formStringToDouble(getAttribute(minAttr), &min) && formStringToDouble(value(), &doubleValue)) 266 return doubleValue < min; 267 } else if (inputType() == RANGE) { 269 if (inputType() == NUMBER || inputType() == RANGE) { 268 270 double doubleValue; 269 271 if (formStringToDouble(value(), &doubleValue)) 270 return doubleValue < rangeMinimum();272 return doubleValue < minimum(); 271 273 } 272 274 return false; … … 275 277 bool HTMLInputElement::rangeOverflow() const 276 278 { 277 if (inputType() == NUMBER) { 278 double max = 0.0; 279 double doubleValue = 0.0; 280 if (formStringToDouble(getAttribute(maxAttr), &max) && formStringToDouble(value(), &doubleValue)) 281 return doubleValue > max; 282 } else if (inputType() == RANGE) { 279 if (inputType() == NUMBER || inputType() == RANGE) { 283 280 double doubleValue; 284 281 if (formStringToDouble(value(), &doubleValue)) 285 return doubleValue > rangeMaximum();282 return doubleValue > maximum(); 286 283 } 287 284 return false; 288 285 } 289 286 290 double HTMLInputElement::rangeMinimum() const 291 { 292 ASSERT(inputType() == RANGE); 293 // The range type's "default minimum" is 0. 294 double min = 0.0; 287 double HTMLInputElement::minimum() const 288 { 289 ASSERT(inputType() == NUMBER || inputType() == RANGE); 290 double min = inputType() == RANGE ? rangeDefaultMinimum : numberDefaultMinimum; 295 291 formStringToDouble(getAttribute(minAttr), &min); 296 292 return min; 297 293 } 298 294 299 double HTMLInputElement::rangeMaximum() const 300 { 301 ASSERT(inputType() == RANGE); 302 // The range type's "default maximum" is 100. 303 static const double defaultMaximum = 100.0; 295 double HTMLInputElement::maximum() const 296 { 297 ASSERT(inputType() == NUMBER || inputType() == RANGE); 298 double defaultMaximum = inputType() == RANGE ? rangeDefaultMaximum : numberDefaultMaximum; 304 299 double max = defaultMaximum; 305 300 formStringToDouble(getAttribute(maxAttr), &max); 306 const double min = rangeMinimum();307 308 if (max < min) {309 // A remedy for the inconsistent min/max values.310 // Sets the maxmimum to the default (100.0) or the minimum value.311 max = min < defaultMaximum ? defaultMaximum : min;301 if (inputType() == RANGE) { 302 // A remedy for the inconsistent min/max values for RANGE. 303 // Sets the maxmimum to the default or the minimum value. 304 double min = minimum(); 305 if (max < min) 306 max = std::max(min, defaultMaximum); 312 307 } 313 308 return max; 309 } 310 311 double HTMLInputElement::stepBase() const 312 { 313 if (inputType() == RANGE) 314 return minimum(); 315 if (inputType() == NUMBER) { 316 static const double defaultStepBase = 0.0; 317 double min = defaultStepBase; 318 formStringToDouble(getAttribute(minAttr), &min); 319 return min; 320 } 321 ASSERT_NOT_REACHED(); 322 return 0.0; 314 323 } 315 324 … … 323 332 if (!formStringToDouble(value(), &doubleValue)) 324 333 return false; 325 double stepBase = 0.0; 326 formStringToDouble(getAttribute(minAttr), &stepBase); 327 doubleValue = fabs(doubleValue - stepBase); 334 doubleValue = fabs(doubleValue - stepBase()); 328 335 if (isinf(doubleValue)) 329 336 return false; … … 405 412 } 406 413 *step = parsed * stepScaleFactor; 414 ASSERT(*step > 0); 407 415 return true; 416 } 417 418 void HTMLInputElement::applyStepForNumberOrRange(double count, ExceptionCode& ec) 419 { 420 ASSERT(inputType() == NUMBER || inputType() == RANGE); 421 double step; 422 if (!getAllowedValueStep(&step)) { 423 ec = INVALID_STATE_ERR; 424 return; 425 } 426 double current; 427 if (!formStringToDouble(value(), ¤t)) { 428 ec = INVALID_STATE_ERR; 429 return; 430 } 431 double newValue = current + step * count; 432 if (isinf(newValue)) { 433 ec = INVALID_STATE_ERR; 434 return; 435 } 436 if (newValue < minimum()) { 437 ec = INVALID_STATE_ERR; 438 return; 439 } 440 double base = stepBase(); 441 newValue = base + round((newValue - base) / step) * step; 442 if (newValue > maximum()) { 443 ec = INVALID_STATE_ERR; 444 return; 445 } 446 setValue(formStringFromDouble(newValue)); 447 } 448 449 void HTMLInputElement::stepUp(int n, ExceptionCode& ec) 450 { 451 if (inputType() != NUMBER && inputType() != RANGE) { 452 ec = INVALID_STATE_ERR; 453 return; 454 } 455 applyStepForNumberOrRange(n, ec); 456 } 457 458 void HTMLInputElement::stepDown(int n, ExceptionCode& ec) 459 { 460 if (inputType() != NUMBER && inputType() != RANGE) { 461 ec = INVALID_STATE_ERR; 462 return; 463 } 464 applyStepForNumberOrRange(-n, ec); 408 465 } 409 466 … … 1998 2055 } 1999 2056 2057 String HTMLInputElement::formStringFromDouble(double number) 2058 { 2059 // According to HTML5, "the best representation of the number n as a floating 2060 // point number" is a string produced by applying ToString() to n. 2061 DtoaBuffer buffer; 2062 unsigned length; 2063 doubleToStringInJavaScriptFormat(number, buffer, &length); 2064 return String(buffer, length); 2065 } 2066 2000 2067 bool HTMLInputElement::formStringToDouble(const String& src, double* out) 2001 2068 { -
trunk/WebCore/html/HTMLInputElement.h
r51602 r51822 107 107 bool rangeUnderflow() const; 108 108 bool rangeOverflow() const; 109 // Returns the minimum value for type= range. Don't call this for other types.110 double rangeMinimum() const;111 // Returns the maximum value for type= range. Don't call this for other types.112 // This always returns a value which is <= rangeMinimum().113 double rangeMaximum() const;109 // Returns the minimum value for type=number or range. Don't call this for other types. 110 double minimum() const; 111 // Returns the maximum value for type=number or range. Don't call this for other types. 112 // This always returns a value which is >= minimum(). 113 double maximum() const; 114 114 // Sets the "allowed value step" defined in the HTML spec to the specified double pointer. 115 115 // Returns false if there is no "allowed value step." … … 117 117 // For ValidityState. 118 118 bool stepMismatch() const; 119 // Implementations of HTMLInputElement::stepUp() and stepDown(). 120 void stepUp(int, ExceptionCode&); 121 void stepDown(int, ExceptionCode&); 122 void stepUp(ExceptionCode& ec) { stepUp(1, ec); } 123 void stepDown(ExceptionCode& ec) { stepDown(1, ec); } 119 124 120 125 bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; } … … 250 255 // The double* parameter may be 0. 251 256 static bool formStringToDouble(const String&, double*); 257 // Converts the specified number to a string. This is an implementation of 258 // HTML5's "algorithm to convert a number to a string" for NUMBER/RANGE types. 259 static String formStringFromDouble(double); 252 260 // Parses the specified string as the InputType, and returns true if it is successfully parsed. 253 261 // An instance pointed by the ISODateTime* parameter will have parsed values and be … … 279 287 // Helper for getAllowedValueStep(); 280 288 bool getStepParameters(double* defaultStep, double* stepScaleFactor) const; 289 // Helper for stepUp()/stepDown(). Adds step value * count to the current number/range value. 290 void applyStepForNumberOrRange(double count, ExceptionCode&); 291 // Helper for applyStepForNumberOrRange(). 292 double stepBase() const; 293 281 294 #if ENABLE(DATALIST) 282 295 HTMLDataListElement* dataList() const; -
trunk/WebCore/html/HTMLInputElement.idl
r51602 r51822 72 72 #endif 73 73 74 void stepUp(in [Optional] long n) 75 raises(DOMException); 76 void stepDown(in [Optional] long n) 77 raises(DOMException); 78 74 79 readonly attribute boolean willValidate; 75 80 readonly attribute DOMString validationMessage; -
trunk/WebCore/rendering/RenderSlider.cpp
r51159 r51822 83 83 hasStep = element->getAllowedValueStep(&step); 84 84 85 maximum = element-> rangeMaximum();86 minimum = element-> rangeMinimum();85 maximum = element->maximum(); 86 minimum = element->minimum(); 87 87 } 88 88 … … 380 380 double value = range.valueFromElement(element, &clamped); 381 381 if (clamped) 382 element->setValueFromRenderer( String::number(value));382 element->setValueFromRenderer(HTMLInputElement::formStringFromDouble(value)); 383 383 384 384 // Layout will take care of the thumb's size and position. … … 436 436 fraction = 1 - fraction; 437 437 double value = range.clampValue(range.valueFromProportion(fraction)); 438 element->setValueFromRenderer( String::number(value));438 element->setValueFromRenderer(HTMLInputElement::formStringFromDouble(value)); 439 439 440 440 // Also update the position if appropriate.
Note: See TracChangeset
for help on using the changeset viewer.