Changeset 54647 in webkit
- Timestamp:
- Feb 11, 2010 12:34:10 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r54646 r54647 1 2010-02-11 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 Step attribute support for date&time types. 6 https://bugs.webkit.org/show_bug.cgi?id=30847 7 8 Add tests for ValidityState.stepMismatch, stepUp() and stepDown() 9 for date, datetime, datetime-local, month, time, week types. 10 Update valueAsDate and valueAsNumber tests for a string representation 11 change. 12 13 * fast/forms/ValidityState-stepMismatch-expected.txt: Added. 14 * fast/forms/ValidityState-stepMismatch.html: Added. 15 * fast/forms/input-stepup-stepdown-expected.txt: Added. 16 * fast/forms/input-stepup-stepdown.html: Added. 17 * fast/forms/input-valueasdate-datetime-expected.txt: 18 * fast/forms/input-valueasdate-time-expected.txt: 19 * fast/forms/input-valueasnumber-datetime-expected.txt: 20 * fast/forms/input-valueasnumber-datetimelocal-expected.txt: 21 * fast/forms/input-valueasnumber-time-expected.txt: 22 * fast/forms/script-tests/ValidityState-stepMismatch.js: Added. 23 * fast/forms/script-tests/input-stepup-stepdown.js: Added. 24 * fast/forms/script-tests/input-valueasdate-datetime.js: 25 * fast/forms/script-tests/input-valueasnumber-datetime.js: 26 1 27 2010-02-10 Oliver Hunt <oliver@apple.com> 2 28 -
trunk/LayoutTests/fast/forms/input-valueasdate-datetime-expected.txt
r53669 r54647 21 21 PASS input.value = "2010-01-01T00:00Z"; input.valueAsDate = null; input.value is "" 22 22 Step attribute value and string representation: 23 FAIL input.step = "1"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0) should be 2010-01-21T00:00:00. Was 2010-01-21T00:00Z. 24 FAIL input.step = "0.001"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0) should be 2010-01-21T00:00:00.000. Was 2010-01-21T00:00Z. 23 PASS input.step = "1"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0) is "2010-01-21T00:00:00Z" 24 PASS input.step = "0.001"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0) is "2010-01-21T00:00:00.000Z" 25 25 PASS successfullyParsed is true 26 26 -
trunk/LayoutTests/fast/forms/input-valueasdate-time-expected.txt
r53551 r54647 23 23 PASS input.value = "00:00"; input.valueAsDate = null; input.value is "" 24 24 Step attribute value and string representation: 25 FAIL input.step = "1"; setValueAsDateAndGetValue(0, 0, 0, 0) should be 00:00:00. Was 00:00. 26 FAIL input.step = "0.001"; setValueAsDateAndGetValue(0, 0, 0, 0) should be 00:00:00.000. Was 00:00. 25 PASS input.step = "1"; setValueAsDateAndGetValue(0, 0, 0, 0) is "00:00:00" 26 PASS input.step = "0.001"; setValueAsDateAndGetValue(0, 0, 0, 0) is "00:00:00.000" 27 27 PASS successfullyParsed is true 28 28 -
trunk/LayoutTests/fast/forms/input-valueasnumber-datetime-expected.txt
r54121 r54647 26 26 PASS input.valueAsNumber = Number.NEGATIVE_INFINITY threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9. 27 27 Step attribute value and string representation: 28 FAIL input.step = "1"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) should be 2010-01-21T00:00:00. Was 2010-01-21T00:00Z. 29 FAIL input.step = "0.001"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) should be 2010-01-21T00:00:00.000. Was 2010-01-21T00:00Z. 28 PASS input.step = "1"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) is "2010-01-21T00:00:00Z" 29 PASS input.step = "0.001"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) is "2010-01-21T00:00:00.000Z" 30 30 PASS successfullyParsed is true 31 31 -
trunk/LayoutTests/fast/forms/input-valueasnumber-datetimelocal-expected.txt
r53991 r54647 25 25 PASS input.valueAsNumber = Number.NEGATIVE_INFINITY threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9. 26 26 Step attribute value and string representation: 27 FAIL input.step = "1"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) should be 2010-01-21T00:00:00. Was 2010-01-21T00:00. 28 FAIL input.step = "0.001"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) should be 2010-01-21T00:00:00.000. Was 2010-01-21T00:00. 27 PASS input.step = "1"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) is "2010-01-21T00:00:00" 28 PASS input.step = "0.001"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) is "2010-01-21T00:00:00.000" 29 29 PASS successfullyParsed is true 30 30 -
trunk/LayoutTests/fast/forms/input-valueasnumber-time-expected.txt
r53893 r54647 26 26 PASS input.valueAsNumber = Number.NEGATIVE_INFINITY threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9. 27 27 Step attribute value and string representation: 28 FAIL input.step = "1"; setValueAsNumberAndGetValue(0, 0, 0, 0) should be 00:00:00. Was 00:00. 29 FAIL input.step = "0.001"; setValueAsNumberAndGetValue(0, 0, 0, 0) should be 00:00:00.000. Was 00:00. 28 PASS input.step = "1"; setValueAsNumberAndGetValue(0, 0, 0, 0) is "00:00:00" 29 PASS input.step = "0.001"; setValueAsNumberAndGetValue(0, 0, 0, 0) is "00:00:00.000" 30 30 PASS successfullyParsed is true 31 31 -
trunk/LayoutTests/fast/forms/script-tests/input-valueasdate-datetime.js
r53669 r54647 38 38 debug('Step attribute value and string representation:'); 39 39 // If the step attribute value is 1 second and the second part is 0, we should show the second part. 40 shouldBe('input.step = "1"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00 "');40 shouldBe('input.step = "1"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00Z"'); 41 41 // If the step attribute value is 0.001 second and the millisecond part is 0, we should show the millisecond part. 42 shouldBe('input.step = "0.001"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00.000 "');42 shouldBe('input.step = "0.001"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00.000Z"'); 43 43 44 44 var successfullyParsed = true; -
trunk/LayoutTests/fast/forms/script-tests/input-valueasnumber-datetime.js
r54121 r54647 43 43 debug('Step attribute value and string representation:'); 44 44 // If the step attribute value is 1 second and the second part is 0, we should show the second part. 45 shouldBe('input.step = "1"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00 "');45 shouldBe('input.step = "1"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00Z"'); 46 46 // If the step attribute value is 0.001 second and the millisecond part is 0, we should show the millisecond part. 47 shouldBe('input.step = "0.001"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00.000 "');47 shouldBe('input.step = "0.001"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00.000Z"'); 48 48 49 49 var successfullyParsed = true; -
trunk/WebCore/ChangeLog
r54646 r54647 1 2010-02-11 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 Step attribute support for date&time types. 6 https://bugs.webkit.org/show_bug.cgi?id=30847 7 8 - Add implementation for ValidityState.stepMismatch, stepUp() and 9 stepDown() for date, datetime, datetime-local, month, time, week types. 10 - Fix string representation of DateComponents. 11 12 Tests: fast/forms/ValidityState-stepMismatch.html 13 fast/forms/input-stepup-stepdown.html 14 15 * html/HTMLInputElement.cpp: 16 - Change monthDefaultMaximum so that DateComponents::m_year doesn't overflow. 17 (WebCore::HTMLInputElement::stepBase): 18 (WebCore::HTMLInputElement::stepMismatch): 19 (WebCore::HTMLInputElement::getStepParameters): 20 (WebCore::HTMLInputElement::getAllowedValueStep): 21 (WebCore::HTMLInputElement::applyStep): 22 Renamed from applyStepForNumberOrRange(), and add support for other types. 23 (WebCore::HTMLInputElement::stepUp): Rename applyStepForNumberOrRange(). 24 (WebCore::HTMLInputElement::stepDown): Rename applyStepForNumberOrRange(). 25 (WebCore::HTMLInputElement::setValueAsDate): Use setDateValue(). 26 (WebCore::HTMLInputElement::setDateValue): 27 A helper function to make the best representation of DateComponents. 28 (WebCore::HTMLInputElement::setValueAsNumber): Use setDateValue(). 29 * html/HTMLInputElement.h: 30 1 31 2010-02-10 Oliver Hunt <oliver@apple.com> 2 32 -
trunk/WebCore/html/HTMLInputElement.cpp
r54438 r54647 77 77 78 78 // Constant values for getAllowedValueStep(). 79 static const double dateDefaultStep = 1.0; 80 static const double dateStepScaleFactor = 86400000.0; 81 static const double dateTimeDefaultStep = 60.0; 82 static const double dateTimeStepScaleFactor = 1000.0; 83 static const double monthDefaultStep = 1.0; 84 static const double monthStepScaleFactor = 1.0; 79 85 static const double numberDefaultStep = 1.0; 80 86 static const double numberStepScaleFactor = 1.0; 87 static const double timeDefaultStep = 60.0; 88 static const double timeStepScaleFactor = 1000.0; 89 static const double weekDefaultStep = 1.0; 90 static const double weekStepScaleFactor = 604800000.0; 91 81 92 // Constant values for minimum(). 82 93 static const double dateDefaultMinimum = -12219292800000.0; // This means 1582-10-15T00:00Z. … … 87 98 static const double timeDefaultMinimum = 0.0; // 00:00:00.000 88 99 static const double weekDefaultMinimum = -12212380800000.0; // 1583-01-03, the first Monday of 1583. 100 89 101 // Constant values for maximum(). 90 102 static const double dateDefaultMaximum = DBL_MAX; 91 103 static const double dateTimeDefaultMaximum = DBL_MAX; 92 static const double monthDefaultMaximum = DBL_MAX; 104 // DateComponents::m_year can't represent a year greater than INT_MAX. 105 static const double monthDefaultMaximum = (INT_MAX - 1970) * 12.0 + 12 - 1; 93 106 static const double numberDefaultMaximum = DBL_MAX; 94 107 static const double rangeDefaultMaximum = 100.0; 95 108 static const double timeDefaultMaximum = 86399999.0; // 23:59:59.999 96 109 static const double weekDefaultMaximum = DBL_MAX; 110 111 static const double defaultStepBase = 0.0; 112 static const double weekDefaultStepBase = -259200000.0; // The first day of 1970-W01. 113 114 static const double msecPerMinute = 60 * 1000; 115 static const double msecPerSecond = 1000; 97 116 98 117 HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f) … … 436 455 double HTMLInputElement::stepBase() const 437 456 { 438 if (inputType() == RANGE) 457 switch (inputType()) { 458 case RANGE: 439 459 return minimum(); 440 if (inputType() == NUMBER) { 441 static const double defaultStepBase = 0.0; 442 double min = defaultStepBase; 443 formStringToDouble(getAttribute(minAttr), &min); 444 return min; 460 case DATE: 461 case DATETIME: 462 case DATETIMELOCAL: 463 case MONTH: 464 case NUMBER: 465 case TIME: 466 return parseToDouble(getAttribute(minAttr), defaultStepBase); 467 case WEEK: 468 return parseToDouble(getAttribute(minAttr), weekDefaultStepBase); 469 case BUTTON: 470 case CHECKBOX: 471 case COLOR: 472 case EMAIL: 473 case FILE: 474 case HIDDEN: 475 case IMAGE: 476 case ISINDEX: 477 case PASSWORD: 478 case RADIO: 479 case RESET: 480 case SEARCH: 481 case SUBMIT: 482 case TELEPHONE: 483 case TEXT: 484 case URL: 485 break; 445 486 } 446 487 ASSERT_NOT_REACHED(); … … 453 494 if (!getAllowedValueStep(&step)) 454 495 return false; 455 if (inputType() == NUMBER) { 496 switch (inputType()) { 497 case RANGE: 498 // stepMismatch doesn't occur for RANGE. RenderSlider guarantees the 499 // value matches to step. 500 return false; 501 case NUMBER: { 456 502 double doubleValue; 457 503 if (!formStringToDouble(value(), &doubleValue)) … … 470 516 return acceptableError < remainder && remainder < (step - acceptableError); 471 517 } 472 // Non-RANGE types should be rejected by getAllowedValueStep(). 473 ASSERT(inputType() == RANGE); 474 // stepMismatch doesn't occur for RANGE. RenderSlider guarantees the 475 // value matches to step. 518 case DATE: 519 case DATETIME: 520 case DATETIMELOCAL: 521 case MONTH: 522 case TIME: 523 case WEEK: { 524 const double nan = numeric_limits<double>::quiet_NaN(); 525 double doubleValue = parseToDouble(value(), nan); 526 doubleValue = fabs(doubleValue - stepBase()); 527 if (!isfinite(doubleValue)) 528 return false; 529 ASSERT(round(doubleValue) == doubleValue); 530 ASSERT(round(step) == step); 531 return fmod(doubleValue, step); 532 } 533 case BUTTON: 534 case CHECKBOX: 535 case COLOR: 536 case EMAIL: 537 case FILE: 538 case HIDDEN: 539 case IMAGE: 540 case ISINDEX: 541 case PASSWORD: 542 case RADIO: 543 case RESET: 544 case SEARCH: 545 case SUBMIT: 546 case TELEPHONE: 547 case TEXT: 548 case URL: 549 break; 550 } 551 // Non-supported types should be rejected by getAllowedValueStep(). 552 ASSERT_NOT_REACHED(); 476 553 return false; 477 554 } … … 488 565 return true; 489 566 case DATE: 567 *defaultStep = dateDefaultStep; 568 *stepScaleFactor = dateStepScaleFactor; 569 return true; 490 570 case DATETIME: 491 571 case DATETIMELOCAL: 572 *defaultStep = dateTimeDefaultStep; 573 *stepScaleFactor = dateTimeStepScaleFactor; 574 return true; 492 575 case MONTH: 576 *defaultStep = monthDefaultStep; 577 *stepScaleFactor = monthStepScaleFactor; 578 return true; 493 579 case TIME: 580 *defaultStep = timeDefaultStep; 581 *stepScaleFactor = timeStepScaleFactor; 582 return true; 494 583 case WEEK: 495 // FIXME: Implement for these types. 496 return false; 584 *defaultStep = weekDefaultStep; 585 *stepScaleFactor = weekStepScaleFactor; 586 return true; 497 587 case BUTTON: 498 588 case CHECKBOX: … … 536 626 return true; 537 627 } 538 *step = parsed * stepScaleFactor; 539 ASSERT(*step > 0); 628 // For DATE, MONTH, WEEK, the parsed value should be an integer. 629 if (inputType() == DATE || inputType() == MONTH || inputType() == WEEK) 630 parsed = max(round(parsed), 1.0); 631 double result = parsed * stepScaleFactor; 632 // For DATETIME, DATETIMELOCAL, TIME, the result should be an integer. 633 if (inputType() == DATETIME || inputType() == DATETIMELOCAL || inputType() == TIME) 634 result = max(round(result), 1.0); 635 ASSERT(result > 0); 636 *step = result; 540 637 return true; 541 638 } 542 639 543 void HTMLInputElement::applyStepForNumberOrRange(double count, ExceptionCode& ec) 544 { 545 ASSERT(inputType() == NUMBER || inputType() == RANGE); 640 void HTMLInputElement::applyStep(double count, ExceptionCode& ec) 641 { 546 642 double step; 547 643 if (!getAllowedValueStep(&step)) { … … 549 645 return; 550 646 } 551 double current; 552 if (!formStringToDouble(value(), ¤t)) { 647 const double nan = numeric_limits<double>::quiet_NaN(); 648 double current = parseToDouble(value(), nan); 649 if (!isfinite(current)) { 553 650 ec = INVALID_STATE_ERR; 554 651 return; … … 569 666 return; 570 667 } 571 setValue (formStringFromDouble(newValue));668 setValueAsNumber(newValue, ec); 572 669 } 573 670 574 671 void HTMLInputElement::stepUp(int n, ExceptionCode& ec) 575 672 { 576 if (inputType() != NUMBER && inputType() != RANGE) { 577 ec = INVALID_STATE_ERR; 578 return; 579 } 580 applyStepForNumberOrRange(n, ec); 673 applyStep(n, ec); 581 674 } 582 675 583 676 void HTMLInputElement::stepDown(int n, ExceptionCode& ec) 584 677 { 585 if (inputType() != NUMBER && inputType() != RANGE) { 586 ec = INVALID_STATE_ERR; 587 return; 588 } 589 applyStepForNumberOrRange(-n, ec); 678 applyStep(-n, ec); 590 679 } 591 680 … … 1655 1744 return; 1656 1745 } 1657 // FIXME: We should specify SecondFormat. 1658 // e.g. If the step value is 60, use SecondFormat::None. 1659 // If the step value is 1, use SecondFormat::Second. 1660 setValue(date.toString()); 1746 setDateValue(date); 1747 } 1748 1749 void HTMLInputElement::setDateValue(const DateComponents& date) 1750 { 1751 double step; 1752 if (!getAllowedValueStep(&step)) { 1753 setValue(date.toString()); 1754 return; 1755 } 1756 if (!fmod(step, msecPerMinute)) { 1757 setValue(date.toString(DateComponents::None)); 1758 return; 1759 } 1760 if (!fmod(step, msecPerSecond)) { 1761 setValue(date.toString(DateComponents::Second)); 1762 return; 1763 } 1764 setValue(date.toString(DateComponents::Millisecond)); 1661 1765 } 1662 1766 … … 1725 1829 return; 1726 1830 } 1727 // FIXME: We should specify SecondFormat. 1728 // e.g. If the step value is 60, use SecondFormat::None. 1729 // If the step value is 1, use SecondFormat::Second. 1730 setValue(date.toString()); 1831 setDateValue(date); 1731 1832 return; 1732 1833 } -
trunk/WebCore/html/HTMLInputElement.h
r54003 r54647 296 296 // Helper for getAllowedValueStep(); 297 297 bool getStepParameters(double* defaultStep, double* stepScaleFactor) const; 298 // Helper for stepUp()/stepDown(). Adds step value * count to the current number/rangevalue.299 void applyStep ForNumberOrRange(double count, ExceptionCode&);298 // Helper for stepUp()/stepDown(). Adds step value * count to the current value. 299 void applyStep(double count, ExceptionCode&); 300 300 // Helper for applyStepForNumberOrRange(). 301 301 double stepBase() const; … … 306 306 // return NaN or Infinity only if defaultValue is NaN or Infinity. 307 307 double parseToDouble(const String&, double defaultValue) const; 308 309 // Generates a suitable string for the specified DateComponents and the 310 // step value, and calls setValue() with it. 311 void setDateValue(const DateComponents&); 312 308 313 309 314 #if ENABLE(DATALIST)
Note: See TracChangeset
for help on using the changeset viewer.