Changeset 53445 in webkit


Ignore:
Timestamp:
Jan 18, 2010 5:49:42 PM (14 years ago)
Author:
tkent@chromium.org
Message:

2010-01-18 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

HTMLInputElement::valueAsDate setter support for type=month.
https://bugs.webkit.org/show_bug.cgi?id=33021

Expose the following functions to be used by WebCore:

  • WTF::msToyear()
  • WTF::dayInYear()
  • WTF::monthFromDayInYear()
  • WTF::dayInMonthFromDayInYear()
  • JavaScriptCore.exp:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
  • wtf/DateMath.cpp: (WTF::msToYear): Remove "static inline". (WTF::dayInYear): Remove "static inline". (WTF::monthFromDayInYear): Remove "static inline". (WTF::dayInMonthFromDayInYear): Remove "static inline".
  • wtf/DateMath.h: Declare the above functions.

2010-01-18 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

HTMLInputElement::valueAsDate setter support for type=month.
https://bugs.webkit.org/show_bug.cgi?id=33021

Add setter tests to input-valueasdate-month.js, and update the
expectation.

  • fast/forms/input-valueasdate-expected.txt:
  • fast/forms/input-valueasdate-month-expected.txt:
  • fast/forms/script-tests/input-valueasdate-month.js:
  • fast/forms/script-tests/input-valueasdate.js:

2010-01-18 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

HTMLInputElement::valueAsDate setter support for type=month.
https://bugs.webkit.org/show_bug.cgi?id=33021

Introduce ISODateTime::setMillisecondsSinceEpochForMonth() and
toString() for the Month type, and HTMLInputElement::setValueAsDate()
calls them.

  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::setValueAsDate):
  • html/ISODateTime.cpp: (WebCore::beforeGregorianStartDate): (WebCore::ISODateTime::addDay): Use beforeGregorianStartDate(). (WebCore::ISODateTime::parseMonth): Use beforeGregorianStartDate(). (WebCore::ISODateTime::setMillisecondsSinceEpochForDateInternal): (WebCore::ISODateTime::setMillisecondsSinceEpochForMonth): (WebCore::ISODateTime::toString): Implement only for the Month type.
  • html/ISODateTime.h:
Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r53444 r53445  
     12010-01-18  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        HTMLInputElement::valueAsDate setter support for type=month.
     6        https://bugs.webkit.org/show_bug.cgi?id=33021
     7
     8        Expose the following functions to be used by WebCore:
     9         - WTF::msToyear()
     10         - WTF::dayInYear()
     11         - WTF::monthFromDayInYear()
     12         - WTF::dayInMonthFromDayInYear()
     13
     14        * JavaScriptCore.exp:
     15        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
     16        * wtf/DateMath.cpp:
     17        (WTF::msToYear): Remove "static inline".
     18        (WTF::dayInYear): Remove "static inline".
     19        (WTF::monthFromDayInYear): Remove "static inline".
     20        (WTF::dayInMonthFromDayInYear): Remove "static inline".
     21        * wtf/DateMath.h: Declare the above functions.
     22
    1232010-01-18  Darin Adler  <darin@apple.com>
    224
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r53320 r53445  
    320320__ZN3WTF16fastZeroedMallocEm
    321321__ZN3WTF18dateToDaysFrom1970Eiii
     322__ZN3WTF18monthFromDayInYearEib
    322323__ZN3WTF19initializeThreadingEv
    323324__ZN3WTF20fastMallocStatisticsEv
     
    329330__ZN3WTF21RefCountedLeakCounterD1Ev
    330331__ZN3WTF23callOnMainThreadAndWaitEPFvPvES0_
     332__ZN3WTF23dayInMonthFromDayInYearEib
    331333__ZN3WTF23waitForThreadCompletionEjPPv
    332334__ZN3WTF27releaseFastMallocFreeMemoryEv
     
    347349__ZN3WTF8CollatorD1Ev
    348350__ZN3WTF8fastFreeEPv
     351__ZN3WTF8msToYearEd
     352__ZN3WTF9dayInYearEdi
    349353__ZN3WTF9ByteArray6createEm
    350354__ZNK3JSC10JSFunction23isHostFunctionNonInlineEv
  • trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r53320 r53445  
    8787    ?currentTime@WTF@@YANXZ
    8888    ?dateToDaysFrom1970@WTF@@YANHHH@Z
     89    ?dayInMonthFromDayInYear@WTF@@YAHH_N@Z
     90    ?dayInYear@WTF@@YAHNH@Z
    8991    ?decrement@RefCountedLeakCounter@WTF@@QAEXXZ
    9092    ?defaultAttributes@PropertyDescriptor@JSC@@0IA
     
    195197    ?markChildren@JSWrapperObject@JSC@@EAEXAAVMarkStack@2@@Z
    196198    ?materializePropertyMap@Structure@JSC@@AAEXXZ
     199    ?monthFromDayInYear@WTF@@YAHH_N@Z
     200    ?msToYear@WTF@@YAHN@Z
    197201    ?name@InternalFunction@JSC@@QAEABVUString@2@PAVExecState@2@@Z
    198202    ?nonInlineNaN@JSC@@YANXZ
  • trunk/JavaScriptCore/wtf/DateMath.cpp

    r52791 r53445  
    173173}
    174174
    175 static inline int msToYear(double ms)
     175int msToYear(double ms)
    176176{
    177177    int approxYear = static_cast<int>(floor(ms / (msPerDay * 365.2425)) + 1970);
     
    184184}
    185185
    186 static inline int dayInYear(double ms, int year)
     186int dayInYear(double ms, int year)
    187187{
    188188    return static_cast<int>(msToDays(ms) - daysFrom1970ToYear(year));
     
    230230}
    231231
    232 static inline int monthFromDayInYear(int dayInYear, bool leapYear)
     232int monthFromDayInYear(int dayInYear, bool leapYear)
    233233{
    234234    const int d = dayInYear;
     
    268268}
    269269
    270 static inline int dayInMonthFromDayInYear(int dayInYear, bool leapYear)
     270int dayInMonthFromDayInYear(int dayInYear, bool leapYear)
    271271{
    272272    const int d = dayInYear;
  • trunk/JavaScriptCore/wtf/DateMath.h

    r52524 r53445  
    7979// Returns the number of days from 1970-01-01 to the specified date.
    8080double dateToDaysFrom1970(int year, int month, int day);
     81int msToYear(double ms);
     82int dayInYear(double ms, int year);
     83int monthFromDayInYear(int dayInYear, bool leapYear);
     84int dayInMonthFromDayInYear(int dayInYear, bool leapYear);
    8185
    8286} // namespace WTF
    8387
    8488using WTF::dateToDaysFrom1970;
     89using WTF::dayInMonthFromDayInYear;
     90using WTF::dayInYear;
    8591using WTF::minutesPerHour;
     92using WTF::monthFromDayInYear;
    8693using WTF::msPerDay;
    8794using WTF::msPerSecond;
     95using WTF::msToYear;
    8896using WTF::secondsPerMinute;
    8997
  • trunk/LayoutTests/ChangeLog

    r53442 r53445  
     12010-01-18  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        HTMLInputElement::valueAsDate setter support for type=month.
     6        https://bugs.webkit.org/show_bug.cgi?id=33021
     7
     8        Add setter tests to input-valueasdate-month.js, and update the
     9        expectation.
     10
     11        * fast/forms/input-valueasdate-expected.txt:
     12        * fast/forms/input-valueasdate-month-expected.txt:
     13        * fast/forms/script-tests/input-valueasdate-month.js:
     14        * fast/forms/script-tests/input-valueasdate.js:
     15
    1162010-01-18  Enrica Casucci  <enrica@apple.com>
    217
  • trunk/LayoutTests/fast/forms/input-valueasdate-expected.txt

    r52434 r53445  
    1919PASS input.valueAsDate.getTime() is 0
    2020Sets other types:
    21 PASS input.valueAsDate = null threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
    22 PASS input.valueAsDate = undefined threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
    23 PASS input.valueAsDate = document threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
     21PASS input.value is ""
     22PASS input.value is ""
     23PASS input.value is ""
    2424PASS successfullyParsed is true
    2525
  • trunk/LayoutTests/fast/forms/input-valueasdate-month-expected.txt

    r52524 r53445  
    88PASS valueAsDateFor("1970-01").getTime() is Date.UTC(1970, 0, 1)
    99PASS valueAsDateFor("2009-12").getTime() is Date.UTC(2009, 11, 1)
     10PASS setValueAsDateAndGetValue(1969, 11, 1) is "1969-12"
     11PASS setValueAsDateAndGetValue(1970, 0, 1) is "1970-01"
     12PASS setValueAsDateAndGetValue(2009, 11, 31) is "2009-12"
     13PASS setValueAsDateAndGetValue(10000, 0, 1) is "10000-01"
     14PASS setValueAsDateAndGetValue(794, 9, 22) is ""
     15PASS setValueAsDateAndGetValue(1582, 8, 30) is ""
     16PASS setValueAsDateAndGetValue(1582, 9, 1) is "1582-10"
     17PASS setValueAsDateAndGetValue(1582, 9, 31) is "1582-10"
     18PASS setValueAsDateAndGetValue(275760, 8, 13) is "275760-09"
     19PASS setValueAsDateAndGetValue(275760, 8, 14) is ""
     20Sets null to valueAsDate:
     21PASS input.value is ""
    1022PASS successfullyParsed is true
    1123
  • trunk/LayoutTests/fast/forms/script-tests/input-valueasdate-month.js

    r52524 r53445  
    99}
    1010
     11function setValueAsDateAndGetValue(year, month, day) {
     12    var date = new Date();
     13    date.setTime(Date.UTC(year, month, day));
     14    input.valueAsDate = date;
     15    return input.value;
     16}
     17
    1118shouldBe('valueAsDateFor("")', 'null');
    1219shouldBe('valueAsDateFor("1969-12").getTime()', 'Date.UTC(1969, 11, 1, 0, 0, 0, 0)');
     
    1421shouldBe('valueAsDateFor("2009-12").getTime()', 'Date.UTC(2009, 11, 1)');
    1522
     23shouldBe('setValueAsDateAndGetValue(1969, 11, 1)', '"1969-12"');
     24shouldBe('setValueAsDateAndGetValue(1970, 0, 1)', '"1970-01"');
     25shouldBe('setValueAsDateAndGetValue(2009, 11, 31)', '"2009-12"');
     26shouldBe('setValueAsDateAndGetValue(10000, 0, 1)', '"10000-01"');
     27
     28shouldBe('setValueAsDateAndGetValue(794, 9, 22)', '""');
     29shouldBe('setValueAsDateAndGetValue(1582, 8, 30)', '""');
     30shouldBe('setValueAsDateAndGetValue(1582, 9, 1)', '"1582-10"');
     31shouldBe('setValueAsDateAndGetValue(1582, 9, 31)', '"1582-10"');
     32shouldBe('setValueAsDateAndGetValue(275760, 8, 13)', '"275760-09"');
     33shouldBe('setValueAsDateAndGetValue(275760, 8, 14)', '""'); // Date of JavaScript can't represent this.
     34
     35debug('Sets null to valueAsDate:');
     36input.value = '2009-12';
     37input.valueAsDate = null;
     38shouldBe('input.value', '""');
     39
    1640var successfullyParsed = true;
  • trunk/LayoutTests/fast/forms/script-tests/input-valueasdate.js

    r52434 r53445  
    2929shouldBe('input.valueAsDate.getTime()', '0');
    3030debug('Sets other types:');
    31 shouldThrow('input.valueAsDate = null', 'invalidStateError');
    32 shouldThrow('input.valueAsDate = undefined', 'invalidStateError');
    33 shouldThrow('input.valueAsDate = document', 'invalidStateError');
     31input.value = '1970-01';
     32input.valueAsDate = null;
     33shouldBe('input.value', '""');
     34input.value = '1970-01';
     35input.valueAsDate = undefined;
     36shouldBe('input.value', '""');
     37input.value = '1970-01';
     38input.valueAsDate = document;
     39shouldBe('input.value', '""');
     40
    3441
    3542var successfullyParsed = true;
  • trunk/WebCore/ChangeLog

    r53443 r53445  
     12010-01-18  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        HTMLInputElement::valueAsDate setter support for type=month.
     6        https://bugs.webkit.org/show_bug.cgi?id=33021
     7
     8        Introduce ISODateTime::setMillisecondsSinceEpochForMonth() and
     9        toString() for the Month type, and HTMLInputElement::setValueAsDate()
     10        calls them.
     11
     12        * html/HTMLInputElement.cpp:
     13        (WebCore::HTMLInputElement::setValueAsDate):
     14        * html/ISODateTime.cpp:
     15        (WebCore::beforeGregorianStartDate):
     16        (WebCore::ISODateTime::addDay): Use beforeGregorianStartDate().
     17        (WebCore::ISODateTime::parseMonth): Use beforeGregorianStartDate().
     18        (WebCore::ISODateTime::setMillisecondsSinceEpochForDateInternal):
     19        (WebCore::ISODateTime::setMillisecondsSinceEpochForMonth):
     20        (WebCore::ISODateTime::toString): Implement only for the Month type.
     21        * html/ISODateTime.h:
     22
    1232010-01-18  Enrica Casucci  <enrica@apple.com>
    224
  • trunk/WebCore/html/HTMLInputElement.cpp

    r52967 r53445  
    13961396void HTMLInputElement::setValueAsDate(double value, ExceptionCode& ec)
    13971397{
    1398     // FIXME: This is a temporary implementation to check Date binding.
    1399     if (!isnan(value) && !isinf(value) && inputType() == MONTH) {
    1400         setValue(String("1970-01"));
     1398    ISODateTime dateTime;
     1399    bool success;
     1400    switch (inputType()) {
     1401    case MONTH:
     1402        success = dateTime.setMillisecondsSinceEpochForMonth(value);
     1403        break;
     1404    // FIXME: implementations for other supported types.
     1405    default:
     1406        ec = INVALID_STATE_ERR;
    14011407        return;
    14021408    }
    1403     ec = INVALID_STATE_ERR;
     1409    if (!success) {
     1410        setValue(String());
     1411        return;
     1412    }
     1413    setValue(dateTime.toString());
    14041414}
    14051415
  • trunk/WebCore/html/ISODateTime.cpp

    r52524 r53445  
    3232#include "ISODateTime.h"
    3333
     34#include "PlatformString.h"
    3435#include <limits.h>
    3536#include <wtf/ASCIICType.h>
    3637#include <wtf/DateMath.h>
     38#include <wtf/MathExtras.h>
    3739
    3840namespace WebCore {
     
    137139    end = start + digitsLength;
    138140    return true;
     141}
     142
     143static bool beforeGregorianStartDate(int year, int month, int monthDay)
     144{
     145    return year < gregorianStartYear
     146        || year == gregorianStartYear && month < gregorianStartMonth
     147        || year == gregorianStartYear && month == gregorianStartMonth && monthDay < gregorianStartDay;
    139148}
    140149
     
    179188                day = maxDayOfMonth(year, month);
    180189            }
    181             if (year < gregorianStartYear
    182                     || (year == gregorianStartYear && month < gregorianStartMonth)
    183                     || (year == gregorianStartYear && month == gregorianStartMonth && day < gregorianStartDay))
     190            if (beforeGregorianStartDate(year, month, day))
    184191                return false;
    185192        }
     
    291298    --month;
    292299    // No support for months before Gregorian calendar.
    293     if (m_year == gregorianStartYear && month < gregorianStartMonth)
     300    if (beforeGregorianStartDate(m_year, month, gregorianStartDay))
    294301        return false;
    295302    m_month = month;
     
    444451}
    445452
     453bool ISODateTime::setMillisecondsSinceEpochForDateInternal(double ms)
     454{
     455    m_year = msToYear(ms);
     456    int yearDay = dayInYear(ms, m_year);
     457    m_month = monthFromDayInYear(yearDay, isLeapYear(m_year));
     458    m_monthDay = dayInMonthFromDayInYear(yearDay, isLeapYear(m_year));
     459    return true;
     460}
     461
     462bool ISODateTime::setMillisecondsSinceEpochForMonth(double ms)
     463{
     464    if (!isfinite(ms))
     465        return false;
     466    if (!setMillisecondsSinceEpochForDateInternal(ms))
     467        return false;
     468    // Ignore m_monthDay updated by setMillisecondsSinceEpochForDateInternal().
     469    if (beforeGregorianStartDate(m_year, m_month, gregorianStartDay))
     470        return false;
     471    m_type = Month;
     472    return true;
     473}
     474
    446475double ISODateTime::millisecondsSinceEpochForTime() const
    447476{
     
    477506}
    478507
     508String ISODateTime::toString() const
     509{
     510    switch (m_type) {
     511    case Month:
     512        return String::format("%04d-%02d", m_year, m_month + 1);
     513
     514    // FIXME: implementations for other types.
     515    default:
     516        break;
     517    }
     518    ASSERT_NOT_REACHED();
     519    return String("(Invalid ISODateTime)");
     520}
     521
    479522} // namespace WebCore
  • trunk/WebCore/html/ISODateTime.h

    r52524 r53445  
    3737namespace WebCore {
    3838
     39class String;
     40
    3941// An ISODateTime instance represents one of the following date and time combinations:
    40 // * year-month
    41 // * year-month-day
    42 // * year-week
    43 // * hour-minute-second-millisecond
    44 // * year-month-day hour-minute-second-millisecond
     42// * Month type: year-month
     43// * Date type: year-month-day
     44// * Week type: year-week
     45// * Time type: hour-minute-second-millisecond
     46// * DateTime or DateTimeLocal type: year-month-day hour-minute-second-millisecond
    4547class ISODateTime {
    4648public:
     
    6769    int week() const { return m_week; }
    6870
    69     // The following six functions parse the input `src' whose length is
    70     // `length', and updates some fields of this instance. The parsing starts at
     71    // Returns an ISO 8601 representation for this instance.
     72    String toString() const;
     73
     74    // The following six functions parse the input 'src' whose length is
     75    // 'length', and updates some fields of this instance. The parsing starts at
    7176    // src[start] and examines characters before src[length].
    72     // `src' `date' must be non-null. The `src' string doesn't need to be
     77    // 'src' must be non-null. The 'src' string doesn't need to be
    7378    // null-terminated.
    74     // The functions return true if the parsing succeeds, and set `end' to the
     79    // The functions return true if the parsing succeeds, and set 'end' to the
    7580    // next index after the last consumed. Extra leading characters cause parse
    7681    // failures, and the trailing extra characters don't cause parse failures.
     
    8893    // Sets year, month, monthDay, hour, minute, second and millisecond, and adjusts timezone.
    8994    bool parseDateTime(const UChar* src, unsigned length, unsigned start, unsigned& end);
     95
     96    // The following setMillisecondsSinceEpochFor*() function takes
     97    // the number of milliseconds since 1970-01-01 00:00:00.000 UTC as
     98    // the argument, and update all fields for the corresponding
     99    // ISODateTime type. The function returns true if it succeeds, and
     100    // false if it fails.
     101
     102    // For Month type.  Updates m_year and m_month.
     103    bool setMillisecondsSinceEpochForMonth(double ms);
     104    // FIXME: Add setMillisecondsSinceEpochFor*() for other types.
    90105
    91106    // Returns the number of milliseconds from 1970-01-01 00:00:00 UTC.
     
    105120    // Helper for millisecondsSinceEpoch().
    106121    double millisecondsSinceEpochForTime() const;
     122    // Helper for setMillisecondsSinceEpochFor*().
     123    bool setMillisecondsSinceEpochForDateInternal(double ms);
    107124
    108125    // m_weekDay values
Note: See TracChangeset for help on using the changeset viewer.