Changeset 139036 in webkit


Ignore:
Timestamp:
Jan 7, 2013 11:19:15 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

INPUT_MULTIPLE_FIELDS_UI: Step-up/-down of month/day field should respect min/max attributes
https://bugs.webkit.org/show_bug.cgi?id=106212

Patch by Kunihiko Sakamoto <ksakamoto@chromium.org> on 2013-01-07
Reviewed by Kent Tamura.

Source/WebCore:

Make step-up/-down of the month and day fields respect the min/max
attributes of the element.
Note that these fields still accept any keyboard inputs (the element
becomes 'invalid' state when out-of-bounds values entered).

Tests: fast/forms/date-multiple-fields/date-multiple-fields-readonly-subfield.html

fast/forms/date-multiple-fields/date-multiple-fields-stepup-stepdown-from-renderer.html
fast/forms/month-multiple-fields/month-multiple-fields-readonly-subfield.html
fast/forms/month-multiple-fields/month-multiple-fields-stepup-stepdown-from-renderer.html

  • css/html.css: Add CSS rules for month and day fields.
  • html/shadow/DateTimeEditElement.cpp:

(WebCore::DateTimeEditBuilder::visitField):
Compute minimum/maximum values of month/day fields from the min/max
parameters of the element. If minimum, maximum, and current value is
the same, makes the field read-only.

  • html/shadow/DateTimeFieldElements.cpp:

(WebCore::DateTimeAMPMFieldElement::DateTimeAMPMFieldElement): Add mininum/maximum arguments.
(WebCore::DateTimeDayFieldElement::DateTimeDayFieldElement): Ditto.
(WebCore::DateTimeDayFieldElement::create): Ditto.
(WebCore::DateTimeDayFieldElement::clampValueForHardLimits): Added.
(WebCore::DateTimeMonthFieldElement::DateTimeMonthFieldElement): Add mininum/maximum arguments.
(WebCore::DateTimeMonthFieldElement::create): Ditto.
(WebCore::DateTimeMonthFieldElement::clampValueForHardLimits): Added.
(WebCore::DateTimeSymbolicMonthFieldElement::DateTimeSymbolicMonthFieldElement): Add mininum/maximum arguments.
(WebCore::DateTimeSymbolicMonthFieldElement::create): Ditto.

  • html/shadow/DateTimeFieldElements.h:

(DateTimeDayFieldElement): Add mininum/maximum arguments and declare clampValueForHardLimits.
(DateTimeMonthFieldElement): Ditto.
(DateTimeSymbolicMonthFieldElement): Add mininum/maximum arguments.

  • html/shadow/DateTimeSymbolicFieldElement.cpp:

(WebCore::DateTimeSymbolicFieldElement::DateTimeSymbolicFieldElement): Add mininum/maximum arguments.
(WebCore::DateTimeSymbolicFieldElement::maximum): Returns m_maximumIndex + 1 as it assumes 1-origin value.
(WebCore::DateTimeSymbolicFieldElement::minimum): Ditto.
(WebCore::DateTimeSymbolicFieldElement::stepDown): Restrict value to m_minimumIndex-m_maximumIndex.
(WebCore::DateTimeSymbolicFieldElement::stepUp): Ditto.

  • html/shadow/DateTimeSymbolicFieldElement.h:

(DateTimeSymbolicFieldElement): Add m_minimumIndex and m_maximumIndex.
(WebCore::DateTimeSymbolicFieldElement::isInRange): Added.

LayoutTests:

  • fast/forms/date-multiple-fields/date-multiple-fields-readonly-subfield-expected.txt:
  • fast/forms/date-multiple-fields/date-multiple-fields-readonly-subfield.html: Add tests for month and day fields.
  • fast/forms/date-multiple-fields/date-multiple-fields-stepup-stepdown-from-renderer-expected.txt: Added.
  • fast/forms/date-multiple-fields/date-multiple-fields-stepup-stepdown-from-renderer.html: Added.
  • fast/forms/month-multiple-fields/month-multiple-fields-readonly-subfield-expected.txt: Added.
  • fast/forms/month-multiple-fields/month-multiple-fields-readonly-subfield.html: Added.
  • fast/forms/month-multiple-fields/month-multiple-fields-stepup-stepdown-from-renderer-expected.txt: Added.
  • fast/forms/month-multiple-fields/month-multiple-fields-stepup-stepdown-from-renderer.html: Added.
Location:
trunk
Files:
6 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r139034 r139036  
     12013-01-07  Kunihiko Sakamoto  <ksakamoto@chromium.org>
     2
     3        INPUT_MULTIPLE_FIELDS_UI: Step-up/-down of month/day field should respect min/max attributes
     4        https://bugs.webkit.org/show_bug.cgi?id=106212
     5
     6        Reviewed by Kent Tamura.
     7
     8        * fast/forms/date-multiple-fields/date-multiple-fields-readonly-subfield-expected.txt:
     9        * fast/forms/date-multiple-fields/date-multiple-fields-readonly-subfield.html: Add tests for month and day fields.
     10        * fast/forms/date-multiple-fields/date-multiple-fields-stepup-stepdown-from-renderer-expected.txt: Added.
     11        * fast/forms/date-multiple-fields/date-multiple-fields-stepup-stepdown-from-renderer.html: Added.
     12        * fast/forms/month-multiple-fields/month-multiple-fields-readonly-subfield-expected.txt: Added.
     13        * fast/forms/month-multiple-fields/month-multiple-fields-readonly-subfield.html: Added.
     14        * fast/forms/month-multiple-fields/month-multiple-fields-stepup-stepdown-from-renderer-expected.txt: Added.
     15        * fast/forms/month-multiple-fields/month-multiple-fields-stepup-stepdown-from-renderer.html: Added.
     16
    1172013-01-07  Christophe Dumez  <christophe.dumez@intel.com>
    218
  • trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-readonly-subfield-expected.txt

    r138148 r139036  
    1515PASS isReadOnlyField(createDateInput("2012-01-01", "2012-12-31", "2012-05-30"), pseudoYear) is true
    1616PASS isReadOnlyField(createDateInput("2012-01-01", "2012-12-31", "2013-01-01"), pseudoYear) is false
     17Month field:
     18PASS isReadOnlyField(createDateInput("", "", ""), pseudoMonth) is false
     19PASS isReadOnlyField(createDateInput("2012-12-17", "", ""), pseudoMonth) is false
     20PASS isReadOnlyField(createDateInput("", "2012-12-17", ""), pseudoMonth) is false
     21PASS isReadOnlyField(createDateInput("", "", "2012-12-17"), pseudoMonth) is false
     22PASS isReadOnlyField(createDateInput("2012-12-01", "2012-12-31", ""), pseudoMonth) is true
     23PASS isReadOnlyField(createDateInput("2012-11-01", "2013-12-31", ""), pseudoMonth) is false
     24PASS isReadOnlyField(createDateInput("2012-12-01", "2013-12-31", ""), pseudoMonth) is false
     25PASS isReadOnlyField(createDateInput("2012-12-01", "2012-12-31", "2012-12-15"), pseudoMonth) is true
     26PASS isReadOnlyField(createDateInput("2012-12-01", "2012-12-31", "2012-11-30"), pseudoMonth) is false
     27Day field:
     28PASS isReadOnlyField(createDateInput("", "", ""), pseudoDay) is false
     29PASS isReadOnlyField(createDateInput("2012-12-17", "", ""), pseudoDay) is false
     30PASS isReadOnlyField(createDateInput("", "2012-12-17", ""), pseudoDay) is false
     31PASS isReadOnlyField(createDateInput("", "", "2012-12-17"), pseudoDay) is false
     32PASS isReadOnlyField(createDateInput("2012-12-17", "2012-12-17", ""), pseudoDay) is true
     33PASS isReadOnlyField(createDateInput("2012-12-17", "2013-12-18", ""), pseudoDay) is false
     34PASS isReadOnlyField(createDateInput("2012-11-17", "2012-12-17", ""), pseudoDay) is false
     35PASS isReadOnlyField(createDateInput("2012-12-17", "2013-12-17", ""), pseudoDay) is false
     36PASS isReadOnlyField(createDateInput("2012-12-17", "2012-12-17", "2012-12-17"), pseudoDay) is true
     37PASS isReadOnlyField(createDateInput("2012-12-17", "2012-12-17", "2012-12-18"), pseudoDay) is false
    1738PASS successfullyParsed is true
    1839
  • trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-readonly-subfield.html

    r138148 r139036  
    4040shouldBeFalse('isReadOnlyField(createDateInput("2012-01-01", "2012-12-31", "2013-01-01"), pseudoYear)');
    4141
     42debug('Month field:');
     43shouldBeFalse('isReadOnlyField(createDateInput("", "", ""), pseudoMonth)');
     44shouldBeFalse('isReadOnlyField(createDateInput("2012-12-17", "", ""), pseudoMonth)');
     45shouldBeFalse('isReadOnlyField(createDateInput("", "2012-12-17", ""), pseudoMonth)');
     46shouldBeFalse('isReadOnlyField(createDateInput("", "", "2012-12-17"), pseudoMonth)');
     47shouldBeTrue('isReadOnlyField(createDateInput("2012-12-01", "2012-12-31", ""), pseudoMonth)');
     48shouldBeFalse('isReadOnlyField(createDateInput("2012-11-01", "2013-12-31", ""), pseudoMonth)');
     49shouldBeFalse('isReadOnlyField(createDateInput("2012-12-01", "2013-12-31", ""), pseudoMonth)');
     50shouldBeTrue('isReadOnlyField(createDateInput("2012-12-01", "2012-12-31", "2012-12-15"), pseudoMonth)');
     51shouldBeFalse('isReadOnlyField(createDateInput("2012-12-01", "2012-12-31", "2012-11-30"), pseudoMonth)');
     52
     53debug('Day field:');
     54shouldBeFalse('isReadOnlyField(createDateInput("", "", ""), pseudoDay)');
     55shouldBeFalse('isReadOnlyField(createDateInput("2012-12-17", "", ""), pseudoDay)');
     56shouldBeFalse('isReadOnlyField(createDateInput("", "2012-12-17", ""), pseudoDay)');
     57shouldBeFalse('isReadOnlyField(createDateInput("", "", "2012-12-17"), pseudoDay)');
     58shouldBeTrue('isReadOnlyField(createDateInput("2012-12-17", "2012-12-17", ""), pseudoDay)');
     59shouldBeFalse('isReadOnlyField(createDateInput("2012-12-17", "2013-12-18", ""), pseudoDay)');
     60shouldBeFalse('isReadOnlyField(createDateInput("2012-11-17", "2012-12-17", ""), pseudoDay)');
     61shouldBeFalse('isReadOnlyField(createDateInput("2012-12-17", "2013-12-17", ""), pseudoDay)');
     62shouldBeTrue('isReadOnlyField(createDateInput("2012-12-17", "2012-12-17", "2012-12-17"), pseudoDay)');
     63shouldBeFalse('isReadOnlyField(createDateInput("2012-12-17", "2012-12-17", "2012-12-18"), pseudoDay)');
     64
    4265</script>
    4366<script src="../../js/resources/js-test-post.js"></script>
  • trunk/Source/WebCore/ChangeLog

    r139033 r139036  
     12013-01-07  Kunihiko Sakamoto  <ksakamoto@chromium.org>
     2
     3        INPUT_MULTIPLE_FIELDS_UI: Step-up/-down of month/day field should respect min/max attributes
     4        https://bugs.webkit.org/show_bug.cgi?id=106212
     5
     6        Reviewed by Kent Tamura.
     7
     8        Make step-up/-down of the month and day fields respect the min/max
     9        attributes of the element.
     10        Note that these fields still accept any keyboard inputs (the element
     11        becomes 'invalid' state when out-of-bounds values entered).
     12
     13        Tests: fast/forms/date-multiple-fields/date-multiple-fields-readonly-subfield.html
     14               fast/forms/date-multiple-fields/date-multiple-fields-stepup-stepdown-from-renderer.html
     15               fast/forms/month-multiple-fields/month-multiple-fields-readonly-subfield.html
     16               fast/forms/month-multiple-fields/month-multiple-fields-stepup-stepdown-from-renderer.html
     17
     18        * css/html.css: Add CSS rules for month and day fields.
     19        * html/shadow/DateTimeEditElement.cpp:
     20        (WebCore::DateTimeEditBuilder::visitField):
     21        Compute minimum/maximum values of month/day fields from the min/max
     22        parameters of the element. If minimum, maximum, and current value is
     23        the same, makes the field read-only.
     24        * html/shadow/DateTimeFieldElements.cpp:
     25        (WebCore::DateTimeAMPMFieldElement::DateTimeAMPMFieldElement): Add mininum/maximum arguments.
     26        (WebCore::DateTimeDayFieldElement::DateTimeDayFieldElement): Ditto.
     27        (WebCore::DateTimeDayFieldElement::create): Ditto.
     28        (WebCore::DateTimeDayFieldElement::clampValueForHardLimits): Added.
     29        (WebCore::DateTimeMonthFieldElement::DateTimeMonthFieldElement): Add mininum/maximum arguments.
     30        (WebCore::DateTimeMonthFieldElement::create): Ditto.
     31        (WebCore::DateTimeMonthFieldElement::clampValueForHardLimits): Added.
     32        (WebCore::DateTimeSymbolicMonthFieldElement::DateTimeSymbolicMonthFieldElement): Add mininum/maximum arguments.
     33        (WebCore::DateTimeSymbolicMonthFieldElement::create): Ditto.
     34        * html/shadow/DateTimeFieldElements.h:
     35        (DateTimeDayFieldElement): Add mininum/maximum arguments and declare clampValueForHardLimits.
     36        (DateTimeMonthFieldElement): Ditto.
     37        (DateTimeSymbolicMonthFieldElement): Add mininum/maximum arguments.
     38        * html/shadow/DateTimeSymbolicFieldElement.cpp:
     39        (WebCore::DateTimeSymbolicFieldElement::DateTimeSymbolicFieldElement): Add mininum/maximum arguments.
     40        (WebCore::DateTimeSymbolicFieldElement::maximum): Returns m_maximumIndex + 1 as it assumes 1-origin value.
     41        (WebCore::DateTimeSymbolicFieldElement::minimum): Ditto.
     42        (WebCore::DateTimeSymbolicFieldElement::stepDown): Restrict value to m_minimumIndex-m_maximumIndex.
     43        (WebCore::DateTimeSymbolicFieldElement::stepUp): Ditto.
     44        * html/shadow/DateTimeSymbolicFieldElement.h:
     45        (DateTimeSymbolicFieldElement): Add m_minimumIndex and m_maximumIndex.
     46        (WebCore::DateTimeSymbolicFieldElement::isInRange): Added.
     47
    1482013-01-07  Viatcheslav Ostapenko  <sl.ostapenko@samsung.com>
    249
  • trunk/Source/WebCore/css/html.css

    r138709 r139036  
    581581
    582582input::-webkit-datetime-edit-year-field[readonly],
     583input::-webkit-datetime-edit-month-field[readonly],
     584input::-webkit-datetime-edit-day-field[readonly],
    583585input::-webkit-datetime-edit-ampm-field[readonly],
    584586input::-webkit-datetime-edit-hour-field[readonly],
  • trunk/Source/WebCore/html/shadow/DateTimeEditElement.cpp

    r138254 r139036  
    106106
    107107    switch (fieldType) {
    108     case DateTimeFormat::FieldTypeDayOfMonth:
    109         m_editElement.addField(DateTimeDayFieldElement::create(document, m_editElement, m_parameters.placeholderForDay));
    110         return;
     108    case DateTimeFormat::FieldTypeDayOfMonth: {
     109        int minDay = 1, maxDay = 31;
     110        if (m_parameters.minimum.type() != DateComponents::Invalid
     111            && m_parameters.maximum.type() != DateComponents::Invalid
     112            && m_parameters.minimum.fullYear() == m_parameters.maximum.fullYear()
     113            && m_parameters.minimum.month() == m_parameters.maximum.month()
     114            && m_parameters.minimum.monthDay() <= m_parameters.maximum.monthDay()) {
     115            minDay = m_parameters.minimum.monthDay();
     116            maxDay = m_parameters.maximum.monthDay();
     117        }
     118        RefPtr<DateTimeFieldElement> field = DateTimeDayFieldElement::create(document, m_editElement, m_parameters.placeholderForDay, minDay, maxDay);
     119        m_editElement.addField(field);
     120        if (minDay == maxDay && minDay == m_dateValue.monthDay()) {
     121            field->setValueAsDate(m_dateValue);
     122            field->setReadOnly();
     123        }
     124        return;
     125    }
    111126
    112127    case DateTimeFormat::FieldTypeHour11: {
     
    165180    }
    166181
    167     case DateTimeFormat::FieldTypeMonth:
     182    case DateTimeFormat::FieldTypeMonth: // Fallthrough.
     183    case DateTimeFormat::FieldTypeMonthStandAlone: {
     184        int minMonth = 0, maxMonth = 11;
     185        if (m_parameters.minimum.type() != DateComponents::Invalid
     186            && m_parameters.maximum.type() != DateComponents::Invalid
     187            && m_parameters.minimum.fullYear() == m_parameters.maximum.fullYear()
     188            && m_parameters.minimum.month() <= m_parameters.maximum.month()) {
     189            minMonth = m_parameters.minimum.month();
     190            maxMonth = m_parameters.maximum.month();
     191        }
     192        RefPtr<DateTimeFieldElement> field;
    168193        switch (count) {
    169194        case countForNarrowMonth: // Fallthrough.
    170195        case countForAbbreviatedMonth:
    171             m_editElement.addField(DateTimeSymbolicMonthFieldElement::create(document, m_editElement, m_parameters.locale.shortMonthLabels()));
     196            field = DateTimeSymbolicMonthFieldElement::create(document, m_editElement, fieldType == DateTimeFormat::FieldTypeMonth ? m_parameters.locale.shortMonthLabels() : m_parameters.locale.shortStandAloneMonthLabels(), minMonth, maxMonth);
    172197            break;
    173198        case countForFullMonth:
    174             m_editElement.addField(DateTimeSymbolicMonthFieldElement::create(document, m_editElement, m_parameters.locale.monthLabels()));
     199            field = DateTimeSymbolicMonthFieldElement::create(document, m_editElement, fieldType == DateTimeFormat::FieldTypeMonth ? m_parameters.locale.monthLabels() : m_parameters.locale.standAloneMonthLabels(), minMonth, maxMonth);
    175200            break;
    176201        default:
    177             m_editElement.addField(DateTimeMonthFieldElement::create(document, m_editElement, m_parameters.placeholderForMonth));
     202            field = DateTimeMonthFieldElement::create(document, m_editElement, m_parameters.placeholderForMonth, minMonth + 1, maxMonth + 1);
    178203            break;
    179204        }
    180         return;
    181 
    182     case DateTimeFormat::FieldTypeMonthStandAlone:
    183         switch (count) {
    184         case countForNarrowMonth: // Fallthrough.
    185         case countForAbbreviatedMonth:
    186             m_editElement.addField(DateTimeSymbolicMonthFieldElement::create(document, m_editElement, m_parameters.locale.shortStandAloneMonthLabels()));
    187             break;
    188         case countForFullMonth:
    189             m_editElement.addField(DateTimeSymbolicMonthFieldElement::create(document, m_editElement, m_parameters.locale.standAloneMonthLabels()));
    190             break;
    191         default:
    192             m_editElement.addField(DateTimeMonthFieldElement::create(document, m_editElement, m_parameters.placeholderForMonth));
    193             break;
    194         }
    195         return;
     205        m_editElement.addField(field);
     206        if (minMonth == maxMonth && minMonth == m_dateValue.month()) {
     207            field->setValueAsDate(m_dateValue);
     208            field->setReadOnly();
     209        }
     210        return;
     211    }
    196212
    197213    case DateTimeFormat::FieldTypePeriod: {
  • trunk/Source/WebCore/html/shadow/DateTimeFieldElements.cpp

    r137733 r139036  
    3737
    3838DateTimeAMPMFieldElement::DateTimeAMPMFieldElement(Document* document, FieldOwner& fieldOwner, const Vector<String>& ampmLabels)
    39     : DateTimeSymbolicFieldElement(document, fieldOwner, ampmLabels)
     39    : DateTimeSymbolicFieldElement(document, fieldOwner, ampmLabels, 0, 1)
    4040{
    4141}
     
    7272// ----------------------------
    7373
    74 DateTimeDayFieldElement::DateTimeDayFieldElement(Document* document, FieldOwner& fieldOwner, const String& placeholder)
    75     : DateTimeNumericFieldElement(document, fieldOwner, 1, 31, placeholder)
    76 {
    77 }
    78 
    79 PassRefPtr<DateTimeDayFieldElement> DateTimeDayFieldElement::create(Document* document, FieldOwner& fieldOwner, const String& placeholder)
     74DateTimeDayFieldElement::DateTimeDayFieldElement(Document* document, FieldOwner& fieldOwner, const String& placeholder, int minimum, int maximum)
     75    : DateTimeNumericFieldElement(document, fieldOwner, minimum, maximum, placeholder)
     76{
     77}
     78
     79PassRefPtr<DateTimeDayFieldElement> DateTimeDayFieldElement::create(Document* document, FieldOwner& fieldOwner, const String& placeholder, int minimum, int maximum)
    8080{
    8181    DEFINE_STATIC_LOCAL(AtomicString, dayPsuedoId, ("-webkit-datetime-edit-day-field", AtomicString::ConstructFromLiteral));
    82     RefPtr<DateTimeDayFieldElement> field = adoptRef(new DateTimeDayFieldElement(document, fieldOwner, placeholder.isEmpty() ? ASCIILiteral("--") : placeholder));
     82    RefPtr<DateTimeDayFieldElement> field = adoptRef(new DateTimeDayFieldElement(document, fieldOwner, placeholder.isEmpty() ? ASCIILiteral("--") : placeholder, minimum, maximum));
    8383    field->initialize(dayPsuedoId, AXDayOfMonthFieldText());
    8484    return field.release();
     
    109109
    110110    setEmptyValue();
     111}
     112
     113int DateTimeDayFieldElement::clampValueForHardLimits(int value) const
     114{
     115    return Range(1, 31).clampValue(value);
    111116}
    112117
     
    300305// ----------------------------
    301306
    302 DateTimeMonthFieldElement::DateTimeMonthFieldElement(Document* document, FieldOwner& fieldOwner, const String& placeholder)
    303     : DateTimeNumericFieldElement(document, fieldOwner, 1, 12, placeholder)
    304 {
    305 }
    306 
    307 PassRefPtr<DateTimeMonthFieldElement> DateTimeMonthFieldElement::create(Document* document, FieldOwner& fieldOwner, const String& placeholder)
     307DateTimeMonthFieldElement::DateTimeMonthFieldElement(Document* document, FieldOwner& fieldOwner, const String& placeholder, int minimum, int maximum)
     308    : DateTimeNumericFieldElement(document, fieldOwner, minimum, maximum, placeholder)
     309{
     310}
     311
     312PassRefPtr<DateTimeMonthFieldElement> DateTimeMonthFieldElement::create(Document* document, FieldOwner& fieldOwner, const String& placeholder, int minimum, int maximum)
    308313{
    309314    DEFINE_STATIC_LOCAL(AtomicString, monthPsuedoId, ("-webkit-datetime-edit-month-field", AtomicString::ConstructFromLiteral));
    310     RefPtr<DateTimeMonthFieldElement> field = adoptRef(new DateTimeMonthFieldElement(document, fieldOwner, placeholder.isEmpty() ? ASCIILiteral("--") : placeholder));
     315    RefPtr<DateTimeMonthFieldElement> field = adoptRef(new DateTimeMonthFieldElement(document, fieldOwner, placeholder.isEmpty() ? ASCIILiteral("--") : placeholder, minimum, maximum));
    311316    field->initialize(monthPsuedoId, AXMonthFieldText());
    312317    return field.release();
     
    339344}
    340345
     346int DateTimeMonthFieldElement::clampValueForHardLimits(int value) const
     347{
     348    return Range(1, 12).clampValue(value);
     349}
     350
    341351// ----------------------------
    342352
     
    382392// ----------------------------
    383393
    384 DateTimeSymbolicMonthFieldElement::DateTimeSymbolicMonthFieldElement(Document* document, FieldOwner& fieldOwner, const Vector<String>& labels)
    385     : DateTimeSymbolicFieldElement(document, fieldOwner, labels)
    386 {
    387 }
    388 
    389 PassRefPtr<DateTimeSymbolicMonthFieldElement> DateTimeSymbolicMonthFieldElement::create(Document* document, FieldOwner& fieldOwner, const Vector<String>& labels)
     394DateTimeSymbolicMonthFieldElement::DateTimeSymbolicMonthFieldElement(Document* document, FieldOwner& fieldOwner, const Vector<String>& labels, int minimum, int maximum)
     395    : DateTimeSymbolicFieldElement(document, fieldOwner, labels, minimum, maximum)
     396{
     397}
     398
     399PassRefPtr<DateTimeSymbolicMonthFieldElement> DateTimeSymbolicMonthFieldElement::create(Document* document, FieldOwner& fieldOwner, const Vector<String>& labels, int minimum, int maximum)
    390400{
    391401    DEFINE_STATIC_LOCAL(AtomicString, monthPsuedoId, ("-webkit-datetime-edit-month-field", AtomicString::ConstructFromLiteral));
    392     RefPtr<DateTimeSymbolicMonthFieldElement> field = adoptRef(new DateTimeSymbolicMonthFieldElement(document, fieldOwner, labels));
     402    RefPtr<DateTimeSymbolicMonthFieldElement> field = adoptRef(new DateTimeSymbolicMonthFieldElement(document, fieldOwner, labels, minimum, maximum));
    393403    field->initialize(monthPsuedoId, AXMonthFieldText());
    394404    return field.release();
  • trunk/Source/WebCore/html/shadow/DateTimeFieldElements.h

    r137733 r139036  
    5252
    5353public:
    54     static PassRefPtr<DateTimeDayFieldElement> create(Document*, FieldOwner&, const String& placeholder);
    55 
    56 private:
    57     DateTimeDayFieldElement(Document*, FieldOwner&, const String& placeholder);
    58 
    59     // DateTimeFieldElement functions.
    60     virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL;
    61     virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL;
    62     virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL;
     54    static PassRefPtr<DateTimeDayFieldElement> create(Document*, FieldOwner&, const String& placeholder, int minimum, int maximum);
     55
     56private:
     57    DateTimeDayFieldElement(Document*, FieldOwner&, const String& placeholder, int minimum, int maximum);
     58
     59    // DateTimeFieldElement functions.
     60    virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL;
     61    virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL;
     62    virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL;
     63
     64    // DateTimeNumericFieldElement function.
     65    virtual int clampValueForHardLimits(int) const OVERRIDE FINAL;
    6366};
    6467
     
    122125
    123126public:
    124     static PassRefPtr<DateTimeMonthFieldElement> create(Document*, FieldOwner&, const String& placeholder);
    125 
    126 private:
    127     DateTimeMonthFieldElement(Document*, FieldOwner&, const String& placeholder);
    128 
    129     // DateTimeFieldElement functions.
    130     virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL;
    131     virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL;
    132     virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL;
     127    static PassRefPtr<DateTimeMonthFieldElement> create(Document*, FieldOwner&, const String& placeholder, int minimum, int maximum);
     128
     129private:
     130    DateTimeMonthFieldElement(Document*, FieldOwner&, const String& placeholder, int minimum, int maximum);
     131
     132    // DateTimeFieldElement functions.
     133    virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL;
     134    virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL;
     135    virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL;
     136
     137    // DateTimeNumericFieldElement function.
     138    virtual int clampValueForHardLimits(int) const OVERRIDE FINAL;
    133139};
    134140
     
    152158
    153159public:
    154     static PassRefPtr<DateTimeSymbolicMonthFieldElement> create(Document*, FieldOwner&, const Vector<String>&);
    155 
    156 private:
    157     DateTimeSymbolicMonthFieldElement(Document*, FieldOwner&, const Vector<String>&);
     160    static PassRefPtr<DateTimeSymbolicMonthFieldElement> create(Document*, FieldOwner&, const Vector<String>&, int minimum, int maximum);
     161
     162private:
     163    DateTimeSymbolicMonthFieldElement(Document*, FieldOwner&, const Vector<String>&, int minimum, int maximum);
    158164
    159165    // DateTimeFieldElement functions.
  • trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp

    r136808 r139036  
    4848}
    4949
    50 DateTimeSymbolicFieldElement::DateTimeSymbolicFieldElement(Document* document, FieldOwner& fieldOwner, const Vector<String>& symbols)
     50DateTimeSymbolicFieldElement::DateTimeSymbolicFieldElement(Document* document, FieldOwner& fieldOwner, const Vector<String>& symbols, int minimum, int maximum)
    5151    : DateTimeFieldElement(document, fieldOwner)
    5252    , m_symbols(symbols)
     
    5454    , m_selectedIndex(-1)
    5555    , m_typeAhead(this)
     56    , m_minimumIndex(minimum)
     57    , m_maximumIndex(maximum)
    5658{
    5759    ASSERT(!symbols.isEmpty());
     60    ASSERT(m_minimumIndex >= 0);
     61    ASSERT(m_maximumIndex < static_cast<int>(m_symbols.size()));
     62    ASSERT(m_minimumIndex <= m_maximumIndex);
    5863}
    5964
     
    9095int DateTimeSymbolicFieldElement::maximum() const
    9196{
    92     return static_cast<int>(m_symbols.size());
     97    return m_maximumIndex + 1;
    9398}
    9499
    95100int DateTimeSymbolicFieldElement::minimum() const
    96101{
    97     return 1;
     102    return m_minimumIndex + 1;
    98103}
    99104
     
    114119void DateTimeSymbolicFieldElement::stepDown()
    115120{
    116     const int size = m_symbols.size();
    117     m_selectedIndex = hasValue() ? (m_selectedIndex + size - 1) % size : size - 1;
     121    if (hasValue()) {
     122        if (!isInRange(--m_selectedIndex))
     123            m_selectedIndex = m_maximumIndex;
     124    } else
     125        m_selectedIndex = m_maximumIndex;
    118126    updateVisibleValue(DispatchEvent);
    119127}
     
    121129void DateTimeSymbolicFieldElement::stepUp()
    122130{
    123     m_selectedIndex = hasValue() ? (m_selectedIndex + 1) % m_symbols.size() : 0;
     131    if (hasValue()) {
     132        if (!isInRange(++m_selectedIndex))
     133            m_selectedIndex = m_minimumIndex;
     134    } else
     135        m_selectedIndex = m_minimumIndex;
    124136    updateVisibleValue(DispatchEvent);
    125137}
  • trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h

    r136808 r139036  
    3939
    4040protected:
    41     DateTimeSymbolicFieldElement(Document*, FieldOwner&, const Vector<String>&);
     41    DateTimeSymbolicFieldElement(Document*, FieldOwner&, const Vector<String>&, int minimum, int maximum);
    4242    size_t symbolsSize() const { return m_symbols.size(); }
    4343    virtual bool hasValue() const OVERRIDE FINAL;
     
    5050
    5151    String visibleEmptyValue() const;
     52    bool isInRange(int index) const { return index >= m_minimumIndex && index <= m_maximumIndex; }
    5253
    5354    // DateTimeFieldElement functions.
     
    7374    int m_selectedIndex;
    7475    TypeAhead m_typeAhead;
     76    const int m_minimumIndex;
     77    const int m_maximumIndex;
    7578};
    7679
Note: See TracChangeset for help on using the changeset viewer.