Changeset 51159 in webkit
- Timestamp:
- Nov 18, 2009 5:48:52 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 12 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r51154 r51159 1 2009-11-18 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 Add tests for ValidityState.stepMismatch. 6 https://bugs.webkit.org/show_bug.cgi?id=31331 7 8 * fast/forms/ValidityState-stepMismatch-number-expected.txt: Added. 9 * fast/forms/ValidityState-stepMismatch-number.html: Added. 10 * fast/forms/ValidityState-stepMismatch-range-expected.txt: Added. 11 * fast/forms/ValidityState-stepMismatch-range.html: Added. 12 * fast/forms/ValidityState-stepMismatch-unsupported-expected.txt: Added. 13 * fast/forms/ValidityState-stepMismatch-unsupported.html: Added. 14 * fast/forms/input-step-expected.txt: Added. 15 * fast/forms/input-step.html: Added. 16 * fast/forms/script-tests/ValidityState-stepMismatch-number.js: Added. 17 * fast/forms/script-tests/ValidityState-stepMismatch-range.js: Added. 18 * fast/forms/script-tests/ValidityState-stepMismatch-unsupported.js: Added. 19 * fast/forms/script-tests/input-step.js: Added. 20 1 21 2009-11-18 Shu Chang <Chang.Shu@nokia.com> 2 22 -
trunk/WebCore/ChangeLog
r51158 r51159 1 2009-11-18 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 Support for step attribute and ValidityStae.stepMismatch for 6 type=number and range. stepMismatch will be false if the 7 difference between the current value and a multiple of the step 8 value is very small. 9 10 Change the behavior of RenderSlider so that it always has a value 11 rounded to the step attribute value. 12 13 https://bugs.webkit.org/show_bug.cgi?id=31331 14 15 Tests: fast/forms/ValidityState-stepMismatch-number.html 16 fast/forms/ValidityState-stepMismatch-range.html 17 fast/forms/ValidityState-stepMismatch-unsupported.html 18 fast/forms/input-step.html 19 20 * html/HTMLAttributeNames.in: Add "step". 21 * html/HTMLInputElement.cpp: 22 (WebCore::HTMLInputElement::stepMismatch): 23 (WebCore::HTMLInputElement::getStepParameters): 24 (WebCore::HTMLInputElement::getAllowedValueStep): 25 * html/HTMLInputElement.h: 26 * html/HTMLInputElement.idl: Add "step". 27 * html/ValidityState.cpp: 28 (WebCore::ValidityState::stepMismatch): Forward to HTMLInputElement::stepMismatch(). 29 * html/ValidityState.h: 30 * rendering/RenderSlider.cpp: 31 (WebCore::SliderRange::SliderRange): 32 (WebCore::SliderRange::clampValue): 33 1 34 2009-11-18 Dmitry Titov <dimich@chromium.org> 2 35 -
trunk/WebCore/html/HTMLAttributeNames.in
r50893 r51159 236 236 standby 237 237 start 238 step 238 239 style 239 240 summary -
trunk/WebCore/html/HTMLInputElement.cpp
r51148 r51159 74 74 const int maxSavedResults = 256; 75 75 76 // Constant values for getAllowedValueStep(). 77 static const double numberDefaultStep = 1.0; 78 static const double numberStepScaleFactor = 1.0; 79 76 80 HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f) 77 81 : HTMLTextFormControlElement(tagName, doc, f) … … 307 311 } 308 312 return max; 313 } 314 315 bool HTMLInputElement::stepMismatch() const 316 { 317 double step; 318 if (!getAllowedValueStep(&step)) 319 return false; 320 if (inputType() == NUMBER) { 321 double doubleValue; 322 if (!formStringToDouble(value(), &doubleValue)) 323 return false; 324 double stepBase = 0.0; 325 formStringToDouble(getAttribute(minAttr), &stepBase); 326 doubleValue = fabs(doubleValue - stepBase); 327 if (isinf(doubleValue)) 328 return false; 329 // double's fractional part size is DBL_MAN_DIG-bit. If the current 330 // value is greater than step*2^DBL_MANT_DIG, the following fmod() makes 331 // no sense. 332 if (doubleValue / pow(2, DBL_MANT_DIG) > step) 333 return false; 334 double remainder = fmod(doubleValue, step); 335 // Accepts errors in lower 7-bit. 336 double acceptableError = step / pow(2, DBL_MANT_DIG - 7); 337 return acceptableError < remainder && remainder < (step - acceptableError); 338 } 339 // Non-RANGE types should be rejected by getAllowedValueStep(). 340 ASSERT(inputType() == RANGE); 341 // stepMismatch doesn't occur for RANGE. RenderSlider guarantees the 342 // value matches to step. 343 return false; 344 } 345 346 bool HTMLInputElement::getStepParameters(double* defaultStep, double* stepScaleFactor) const 347 { 348 ASSERT(defaultStep); 349 ASSERT(stepScaleFactor); 350 switch (inputType()) { 351 case NUMBER: 352 case RANGE: 353 *defaultStep = numberDefaultStep; 354 *stepScaleFactor = numberStepScaleFactor; 355 return true; 356 case DATE: 357 case DATETIME: 358 case DATETIMELOCAL: 359 case MONTH: 360 case TIME: 361 case WEEK: 362 // FIXME: Implement for these types. 363 return false; 364 case BUTTON: 365 case CHECKBOX: 366 case COLOR: 367 case EMAIL: 368 case FILE: 369 case HIDDEN: 370 case IMAGE: 371 case ISINDEX: 372 case PASSWORD: 373 case RADIO: 374 case RESET: 375 case SEARCH: 376 case SUBMIT: 377 case TELEPHONE: 378 case TEXT: 379 case URL: 380 return false; 381 } 382 ASSERT_NOT_REACHED(); 383 return false; 384 } 385 386 bool HTMLInputElement::getAllowedValueStep(double* step) const 387 { 388 ASSERT(step); 389 double defaultStep; 390 double stepScaleFactor; 391 if (!getStepParameters(&defaultStep, &stepScaleFactor)) 392 return false; 393 const AtomicString& stepString = getAttribute(stepAttr); 394 if (stepString.isEmpty()) { 395 *step = defaultStep * stepScaleFactor; 396 return true; 397 } 398 if (equalIgnoringCase(stepString, "any")) 399 return false; 400 double parsed; 401 if (!formStringToDouble(stepString, &parsed) || parsed <= 0.0) { 402 *step = defaultStep * stepScaleFactor; 403 return true; 404 } 405 *step = parsed * stepScaleFactor; 406 return true; 309 407 } 310 408 -
trunk/WebCore/html/HTMLInputElement.h
r50996 r51159 111 111 // This always returns a value which is <= rangeMinimum(). 112 112 double rangeMaximum() const; 113 // Sets the "allowed value step" defined in the HTML spec to the specified double pointer. 114 // Returns false if there is no "allowed value step." 115 bool getAllowedValueStep(double*) const; 116 // For ValidityState. 117 bool stepMismatch() const; 113 118 114 119 bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; } … … 266 271 267 272 PassRefPtr<HTMLFormElement> createTemporaryFormForIsIndex(); 268 273 // Helper for getAllowedValueStep(); 274 bool getStepParameters(double* defaultStep, double* stepScaleFactor) const; 269 275 #if ENABLE(DATALIST) 270 276 HTMLDataListElement* dataList() const; -
trunk/WebCore/html/HTMLInputElement.idl
r49199 r51159 64 64 #endif 65 65 attribute [ConvertNullToNullString] DOMString src; 66 attribute [Reflect] DOMString step; 66 67 attribute [ConvertNullToNullString, JSCCustomGetter] DOMString type; // readonly dropped as part of DOM level 2 67 68 attribute [ConvertNullToNullString] DOMString useMap; … … 70 71 readonly attribute HTMLOptionElement selectedOption; 71 72 #endif 73 72 74 readonly attribute boolean willValidate; 73 75 boolean checkValidity(); -
trunk/WebCore/html/ValidityState.cpp
r49508 r51159 94 94 } 95 95 96 bool ValidityState::stepMismatch() 97 { 98 if (!control()->hasTagName(inputTag)) 99 return false; 100 return static_cast<HTMLInputElement*>(control())->stepMismatch(); 101 } 102 96 103 bool ValidityState::valid() 97 104 { -
trunk/WebCore/html/ValidityState.h
r49508 r51159 47 47 bool rangeUnderflow(); 48 48 bool rangeOverflow(); 49 bool stepMismatch() { return false; }49 bool stepMismatch(); 50 50 bool customError() { return !m_customErrorMessage.isEmpty(); } 51 51 bool valid(); -
trunk/WebCore/rendering/RenderSlider.cpp
r50417 r51159 49 49 // and could be put with HTMLInputElement (possibly with a new name) instead of here. 50 50 struct SliderRange { 51 bool isIntegral; 51 bool hasStep; 52 double step; 52 53 double minimum; 53 54 double maximum; // maximum must be >= minimum. … … 76 77 SliderRange::SliderRange(HTMLInputElement* element) 77 78 { 78 // FIXME: What's the right way to handle an integral range with non-integral minimum and maximum? 79 // Currently values are guaranteed to be integral but could be outside the range in that case. 80 81 isIntegral = !equalIgnoringCase(element->getAttribute(precisionAttr), "float"); 79 if (element->hasAttribute(precisionAttr)) { 80 step = 1.0; 81 hasStep = !equalIgnoringCase(element->getAttribute(precisionAttr), "float"); 82 } else 83 hasStep = element->getAllowedValueStep(&step); 82 84 83 85 maximum = element->rangeMaximum(); … … 88 90 { 89 91 double clampedValue = max(minimum, min(value, maximum)); 90 return isIntegral ? round(clampedValue) : clampedValue; 92 if (!hasStep) 93 return clampedValue; 94 // Rounds clampedValue to minimum + N * step. 95 clampedValue = minimum + round((clampedValue - minimum) / step) * step; 96 if (clampedValue > maximum) 97 clampedValue -= step; 98 ASSERT(clampedValue >= minimum); 99 ASSERT(clampedValue <= maximum); 100 return clampedValue; 91 101 } 92 102
Note: See TracChangeset
for help on using the changeset viewer.