Changeset 53975 in webkit
- Timestamp:
- Jan 27, 2010 11:29:39 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r53973 r53975 1 2010-01-27 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 rangeOverflow/rangeUnderflow support for type=date 6 https://bugs.webkit.org/show_bug.cgi?id=34209 7 8 * fast/forms/ValidityState-rangeOverflow-date-expected.txt: Added. 9 * fast/forms/ValidityState-rangeOverflow-date.html: Added. 10 * fast/forms/ValidityState-rangeUnderflow-date-expected.txt: Added. 11 * fast/forms/ValidityState-rangeUnderflow-date.html: Added. 12 * fast/forms/script-tests/ValidityState-rangeOverflow-date.js: Added. 13 * fast/forms/script-tests/ValidityState-rangeUnderflow-date.js: Added. 14 1 15 2010-01-27 Csaba Osztrogonác <ossy@webkit.org> 2 16 -
trunk/WebCore/ChangeLog
r53974 r53975 1 2010-01-27 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 rangeOverflow/rangeUnderflow support for type=date 6 https://bugs.webkit.org/show_bug.cgi?id=34209 7 8 Add DATE type support to rangeUnderflow(), rangeOverflow(), 9 minimum(), and maximum() of HTMLInputElement. 10 In order to unify parsing code for value, min, and max strings, 11 introduce parseToDouble() function and it is called by 12 valueAsDate() and valueAsNumber() too. 13 14 Tests: fast/forms/ValidityState-rangeOverflow-date.html 15 fast/forms/ValidityState-rangeUnderflow-date.html 16 17 * html/HTMLInputElement.cpp: 18 (WebCore::HTMLInputElement::rangeUnderflow): Support DATE type, and use parseToDouble(). 19 (WebCore::HTMLInputElement::rangeOverflow): ditto. 20 (WebCore::HTMLInputElement::minimum): ditto. 21 (WebCore::HTMLInputElement::maximum): ditto. 22 (WebCore::HTMLInputElement::doubleValueFor): Added. 23 (WebCore::HTMLInputElement::valueAsDate): Use parseToDouble(). 24 (WebCore::HTMLInputElement::valueAsNumber): Use parseToDouble(). 25 * html/HTMLInputElement.h: Declare parseToDouble(). 26 1 27 2010-01-27 Darin Fisher <darin@chromium.org> 2 28 -
trunk/WebCore/html/HTMLInputElement.cpp
r53964 r53975 80 80 static const double numberStepScaleFactor = 1.0; 81 81 // Constant values for minimum(). 82 static const double dateDefaultMinimum = -12219292800000.0; // This means 1582-10-15T00:00Z. 82 83 static const double numberDefaultMinimum = -DBL_MAX; 83 84 static const double rangeDefaultMinimum = 0.0; 84 85 // Constant values for maximum(). 86 static const double dateDefaultMaximum = DBL_MAX; 85 87 static const double numberDefaultMaximum = DBL_MAX; 86 88 static const double rangeDefaultMaximum = 100.0; … … 267 269 bool HTMLInputElement::rangeUnderflow() const 268 270 { 269 if (inputType() == NUMBER || inputType() == RANGE) { 270 double doubleValue; 271 if (formStringToDouble(value(), &doubleValue)) 272 return doubleValue < minimum(); 271 const double nan = numeric_limits<double>::quiet_NaN(); 272 switch (inputType()) { 273 case DATE: 274 case NUMBER: 275 case RANGE: { 276 double doubleValue = parseToDouble(value(), nan); 277 return isfinite(doubleValue) && doubleValue < minimum(); 278 } 279 case BUTTON: 280 case CHECKBOX: 281 case COLOR: 282 case DATETIME: 283 case DATETIMELOCAL: 284 case EMAIL: 285 case FILE: 286 case HIDDEN: 287 case IMAGE: 288 case ISINDEX: 289 case MONTH: 290 case PASSWORD: 291 case RADIO: 292 case RESET: 293 case SEARCH: 294 case SUBMIT: 295 case TELEPHONE: 296 case TEXT: 297 case TIME: 298 case URL: 299 case WEEK: 300 break; 273 301 } 274 302 return false; … … 277 305 bool HTMLInputElement::rangeOverflow() const 278 306 { 279 if (inputType() == NUMBER || inputType() == RANGE) { 280 double doubleValue; 281 if (formStringToDouble(value(), &doubleValue)) 282 return doubleValue > maximum(); 307 const double nan = numeric_limits<double>::quiet_NaN(); 308 switch (inputType()) { 309 case DATE: 310 case NUMBER: 311 case RANGE: { 312 double doubleValue = parseToDouble(value(), nan); 313 return isfinite(doubleValue) && doubleValue > maximum(); 314 } 315 case BUTTON: 316 case CHECKBOX: 317 case COLOR: 318 case DATETIME: 319 case DATETIMELOCAL: 320 case EMAIL: 321 case FILE: 322 case HIDDEN: 323 case IMAGE: 324 case ISINDEX: 325 case MONTH: 326 case PASSWORD: 327 case RADIO: 328 case RESET: 329 case SEARCH: 330 case SUBMIT: 331 case TELEPHONE: 332 case TEXT: 333 case TIME: 334 case URL: 335 case WEEK: 336 break; 283 337 } 284 338 return false; … … 287 341 double HTMLInputElement::minimum() const 288 342 { 289 ASSERT(inputType() == NUMBER || inputType() == RANGE); 290 double min = inputType() == RANGE ? rangeDefaultMinimum : numberDefaultMinimum; 291 formStringToDouble(getAttribute(minAttr), &min); 292 return min; 343 switch (inputType()) { 344 case DATE: 345 return parseToDouble(getAttribute(minAttr), dateDefaultMinimum); 346 case NUMBER: 347 return parseToDouble(getAttribute(minAttr), numberDefaultMinimum); 348 case RANGE: 349 return parseToDouble(getAttribute(minAttr), rangeDefaultMinimum); 350 case BUTTON: 351 case CHECKBOX: 352 case COLOR: 353 case DATETIME: 354 case DATETIMELOCAL: 355 case EMAIL: 356 case FILE: 357 case HIDDEN: 358 case IMAGE: 359 case ISINDEX: 360 case MONTH: 361 case PASSWORD: 362 case RADIO: 363 case RESET: 364 case SEARCH: 365 case SUBMIT: 366 case TELEPHONE: 367 case TEXT: 368 case TIME: 369 case URL: 370 case WEEK: 371 break; 372 } 373 ASSERT_NOT_REACHED(); 374 return 0; 293 375 } 294 376 295 377 double HTMLInputElement::maximum() const 296 378 { 297 ASSERT(inputType() == NUMBER || inputType() == RANGE); 298 double defaultMaximum = inputType() == RANGE ? rangeDefaultMaximum : numberDefaultMaximum; 299 double max = defaultMaximum; 300 formStringToDouble(getAttribute(maxAttr), &max); 301 if (inputType() == RANGE) { 379 switch (inputType()) { 380 case DATE: 381 return parseToDouble(getAttribute(maxAttr), dateDefaultMaximum); 382 case NUMBER: 383 return parseToDouble(getAttribute(maxAttr), numberDefaultMaximum); 384 case RANGE: { 385 double max = parseToDouble(getAttribute(maxAttr), rangeDefaultMaximum); 302 386 // A remedy for the inconsistent min/max values for RANGE. 303 387 // Sets the maximum to the default or the minimum value. 304 388 double min = minimum(); 305 389 if (max < min) 306 max = std::max(min, defaultMaximum); 307 } 308 return max; 390 max = std::max(min, rangeDefaultMaximum); 391 return max; 392 } 393 case BUTTON: 394 case CHECKBOX: 395 case COLOR: 396 case DATETIME: 397 case DATETIMELOCAL: 398 case EMAIL: 399 case FILE: 400 case HIDDEN: 401 case IMAGE: 402 case ISINDEX: 403 case MONTH: 404 case PASSWORD: 405 case RADIO: 406 case RESET: 407 case SEARCH: 408 case SUBMIT: 409 case TELEPHONE: 410 case TEXT: 411 case TIME: 412 case URL: 413 case WEEK: 414 break; 415 } 416 ASSERT_NOT_REACHED(); 417 return 0; 309 418 } 310 419 … … 1375 1484 } 1376 1485 1486 double HTMLInputElement::parseToDouble(const String& src, double defaultValue) const 1487 { 1488 switch (inputType()) { 1489 case DATE: 1490 case DATETIME: 1491 case DATETIMELOCAL: 1492 case MONTH: 1493 case TIME: 1494 case WEEK: { 1495 ISODateTime dateTime; 1496 if (!formStringToISODateTime(inputType(), src, &dateTime)) 1497 return defaultValue; 1498 double msec = dateTime.millisecondsSinceEpoch(); 1499 ASSERT(isfinite(msec)); 1500 return msec; 1501 } 1502 case NUMBER: 1503 case RANGE: { 1504 double numberValue; 1505 if (!formStringToDouble(src, &numberValue)) 1506 return defaultValue; 1507 ASSERT(isfinite(numberValue)); 1508 return numberValue; 1509 } 1510 1511 case BUTTON: 1512 case CHECKBOX: 1513 case COLOR: 1514 case EMAIL: 1515 case FILE: 1516 case HIDDEN: 1517 case IMAGE: 1518 case ISINDEX: 1519 case PASSWORD: 1520 case RADIO: 1521 case RESET: 1522 case SEARCH: 1523 case SUBMIT: 1524 case TELEPHONE: 1525 case TEXT: 1526 case URL: 1527 return defaultValue; 1528 } 1529 ASSERT_NOT_REACHED(); 1530 return defaultValue; 1531 } 1532 1377 1533 double HTMLInputElement::valueAsDate() const 1378 1534 { … … 1382 1538 case MONTH: 1383 1539 case TIME: 1384 case WEEK: { 1385 ISODateTime dateTime; 1386 if (!formStringToISODateTime(inputType(), value(), &dateTime)) 1387 return ISODateTime::invalidMilliseconds(); 1388 return dateTime.millisecondsSinceEpoch(); 1389 } 1540 case WEEK: 1541 return parseToDouble(value(), ISODateTime::invalidMilliseconds()); 1542 1390 1543 case BUTTON: 1391 1544 case CHECKBOX: … … 1476 1629 case DATETIMELOCAL: 1477 1630 case MONTH: 1631 case NUMBER: 1632 case RANGE: 1478 1633 case TIME: 1479 case WEEK: { 1480 ISODateTime dateTime; 1481 if (!formStringToISODateTime(inputType(), value(), &dateTime)) 1482 return nan; 1483 return dateTime.millisecondsSinceEpoch(); 1484 } 1485 case NUMBER: 1486 case RANGE: { 1487 double numberValue; 1488 if (!formStringToDouble(value(), &numberValue)) 1489 return nan; 1490 return numberValue; 1491 } 1634 case WEEK: 1635 return parseToDouble(value(), nan); 1492 1636 1493 1637 case BUTTON: -
trunk/WebCore/html/HTMLInputElement.h
r53893 r53975 107 107 bool rangeUnderflow() const; 108 108 bool rangeOverflow() const; 109 // Returns the minimum value for type= numberor range. Don't call this for other types.109 // Returns the minimum value for type=date, number, or range. Don't call this for other types. 110 110 double minimum() const; 111 // Returns the maximum value for type= numberor range. Don't call this for other types.111 // Returns the maximum value for type=date, number, or range. Don't call this for other types. 112 112 // This always returns a value which is >= minimum(). 113 113 double maximum() const; … … 300 300 // Helper for applyStepForNumberOrRange(). 301 301 double stepBase() const; 302 303 // Parses the specified string for the current type, and return 304 // the double value for the parsing result if the parsing 305 // succeeds; Returns defaultValue otherwise. This function can 306 // return NaN or Infinity only if defaultValue is NaN or Infinity. 307 double parseToDouble(const String&, double defaultValue) const; 302 308 303 309 #if ENABLE(DATALIST)
Note: See TracChangeset
for help on using the changeset viewer.