Changeset 48959 in webkit


Ignore:
Timestamp:
Sep 30, 2009 10:49:39 PM (15 years ago)
Author:
eric@webkit.org
Message:

2009-09-30 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

Add ValidityState.tooLong support for <input> and <textarea>.
https://bugs.webkit.org/show_bug.cgi?id=27454

  • fast/forms/ValidityState-tooLong-input-expected.txt: Added.
  • fast/forms/ValidityState-tooLong-input.html: Added.
  • fast/forms/ValidityState-tooLong-textarea-expected.txt: Added.
  • fast/forms/ValidityState-tooLong-textarea.html: Added.
  • fast/forms/script-tests/ValidityState-tooLong-input.js: Added.
  • fast/forms/script-tests/ValidityState-tooLong-textarea.js: Added.

2009-09-30 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

Adds ValidityState.tooLong support for <input> and <textarea>.

Introduces tooLong() in HTMLFormControlElement and it always returns false.
HTMLInputElement and HTMLTextAreaElement overrides it and checks the text
length and maxLength. tooLong() should work only for `dirty' values.
So, introduces m_isDirty flag for HTMLTextAreaElement, and
!m_data.value().isNull() works as a dirty flag for HTMLInputElement.

Renames parameter names of setMaxLength().

https://bugs.webkit.org/show_bug.cgi?id=27454

Tests: fast/forms/ValidityState-tooLong-input.html

fast/forms/ValidityState-tooLong-textarea.html

  • html/HTMLFormControlElement.h: (WebCore::HTMLFormControlElement::tooLong):
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::tooLong): (WebCore::HTMLInputElement::setMaxLength):
  • html/HTMLInputElement.h:
  • html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::HTMLTextAreaElement): (WebCore::HTMLTextAreaElement::reset): (WebCore::HTMLTextAreaElement::updateValue): (WebCore::HTMLTextAreaElement::setMaxLength): (WebCore::HTMLTextAreaElement::tooLong):
  • html/HTMLTextAreaElement.h:
  • html/ValidityState.h: (WebCore::ValidityState::tooLong):
Location:
trunk
Files:
6 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r48953 r48959  
     12009-09-30  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Add ValidityState.tooLong support for <input> and <textarea>.
     6        https://bugs.webkit.org/show_bug.cgi?id=27454
     7
     8        * fast/forms/ValidityState-tooLong-input-expected.txt: Added.
     9        * fast/forms/ValidityState-tooLong-input.html: Added.
     10        * fast/forms/ValidityState-tooLong-textarea-expected.txt: Added.
     11        * fast/forms/ValidityState-tooLong-textarea.html: Added.
     12        * fast/forms/script-tests/ValidityState-tooLong-input.js: Added.
     13        * fast/forms/script-tests/ValidityState-tooLong-textarea.js: Added.
     14
    1152009-09-30  Maciej Stachowiak  <mjs@apple.com>
    216
  • trunk/WebCore/ChangeLog

    r48958 r48959  
     12009-09-30  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Adds ValidityState.tooLong support for <input> and <textarea>.
     6
     7        Introduces tooLong() in HTMLFormControlElement and it always returns false.
     8        HTMLInputElement and HTMLTextAreaElement overrides it and checks the text
     9        length and maxLength.  tooLong() should work only for `dirty' values.
     10        So, introduces m_isDirty flag for HTMLTextAreaElement, and
     11        !m_data.value().isNull() works as a dirty flag for HTMLInputElement.
     12
     13        Renames parameter names of setMaxLength().
     14
     15        https://bugs.webkit.org/show_bug.cgi?id=27454
     16
     17        Tests: fast/forms/ValidityState-tooLong-input.html
     18               fast/forms/ValidityState-tooLong-textarea.html
     19
     20        * html/HTMLFormControlElement.h:
     21        (WebCore::HTMLFormControlElement::tooLong):
     22        * html/HTMLInputElement.cpp:
     23        (WebCore::HTMLInputElement::tooLong):
     24        (WebCore::HTMLInputElement::setMaxLength):
     25        * html/HTMLInputElement.h:
     26        * html/HTMLTextAreaElement.cpp:
     27        (WebCore::HTMLTextAreaElement::HTMLTextAreaElement):
     28        (WebCore::HTMLTextAreaElement::reset):
     29        (WebCore::HTMLTextAreaElement::updateValue):
     30        (WebCore::HTMLTextAreaElement::setMaxLength):
     31        (WebCore::HTMLTextAreaElement::tooLong):
     32        * html/HTMLTextAreaElement.h:
     33        * html/ValidityState.h:
     34        (WebCore::ValidityState::tooLong):
     35
    1362009-09-30  Adam Barth  <abarth@webkit.org>
    237
  • trunk/WebCore/html/HTMLFormControlElement.h

    r48792 r48959  
    111111    virtual bool valueMissing() const { return false; }
    112112    virtual bool patternMismatch() const { return false; }
     113    virtual bool tooLong() const { return false; }
    113114
    114115    void formDestroyed() { m_form = 0; }
  • trunk/WebCore/html/HTMLInputElement.cpp

    r48903 r48959  
    193193    }
    194194
     195    ASSERT_NOT_REACHED();
     196    return false;
     197}
     198
     199bool HTMLInputElement::tooLong() const
     200{
     201    switch (inputType()) {
     202    case EMAIL:
     203    case PASSWORD:
     204    case SEARCH:
     205    case TELEPHONE:
     206    case TEXT:
     207    case URL: {
     208        int max = maxLength();
     209        if (max < 0)
     210            return false;
     211        // Return false for the default value even if it is longer than maxLength.
     212        bool userEdited = !m_data.value().isNull();
     213        if (!userEdited)
     214            return false;
     215        return value().length() > static_cast<unsigned>(max);
     216    }
     217    case BUTTON:
     218    case CHECKBOX:
     219    case COLOR:
     220    case FILE:
     221    case HIDDEN:
     222    case IMAGE:
     223    case ISINDEX:
     224    case NUMBER:
     225    case RADIO:
     226    case RANGE:
     227    case RESET:
     228    case SUBMIT:
     229        return false;
     230    }
    195231    ASSERT_NOT_REACHED();
    196232    return false;
     
    16111647}
    16121648
    1613 void HTMLInputElement::setMaxLength(int _maxLength, ExceptionCode& exceptionCode)
    1614 {
    1615     if (_maxLength < 0)
    1616         exceptionCode = INDEX_SIZE_ERR;
     1649void HTMLInputElement::setMaxLength(int maxLength, ExceptionCode& ec)
     1650{
     1651    if (maxLength < 0)
     1652        ec = INDEX_SIZE_ERR;
    16171653    else
    1618         setAttribute(maxlengthAttr, String::number(_maxLength));
     1654        setAttribute(maxlengthAttr, String::number(maxLength));
    16191655}
    16201656
  • trunk/WebCore/html/HTMLInputElement.h

    r48903 r48959  
    9494    virtual bool valueMissing() const;
    9595    virtual bool patternMismatch() const;
     96    virtual bool tooLong() const;
    9697
    9798    bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; }
  • trunk/WebCore/html/HTMLTextAreaElement.cpp

    r48903 r48959  
    7171    , m_cachedSelectionStart(-1)
    7272    , m_cachedSelectionEnd(-1)
     73    , m_isDirty(false)
    7374{
    7475    ASSERT(hasTagName(textareaTag));
     
    232233{
    233234    setValue(defaultValue());
     235    m_isDirty = false;
    234236}
    235237
     
    317319    const_cast<HTMLTextAreaElement*>(this)->setFormControlValueMatchesRenderer(true);
    318320    notifyFormStateChanged(this);
     321    m_isDirty = true;
    319322}
    320323
     
    410413}
    411414
    412 void HTMLTextAreaElement::setMaxLength(int newValue, ExceptionCode& exceptionCode)
     415void HTMLTextAreaElement::setMaxLength(int newValue, ExceptionCode& ec)
    413416{
    414417    if (newValue < 0)
    415         exceptionCode = INDEX_SIZE_ERR;
     418        ec = INDEX_SIZE_ERR;
    416419    else
    417420        setAttribute(maxlengthAttr, String::number(newValue));
     421}
     422
     423bool HTMLTextAreaElement::tooLong() const
     424{
     425    // Return false for the default value even if it is longer than maxLength.
     426    if (!m_isDirty)
     427        return false;
     428
     429    int max = maxLength();
     430    if (max < 0)
     431        return false;
     432    return value().length() > static_cast<unsigned>(max);
    418433}
    419434
  • trunk/WebCore/html/HTMLTextAreaElement.h

    r48903 r48959  
    8282    int maxLength() const;
    8383    void setMaxLength(int, ExceptionCode&);
     84    virtual bool tooLong() const;
    8485   
    8586    void rendererWillBeDestroyed();
     
    117118    int m_cachedSelectionStart;
    118119    int m_cachedSelectionEnd;
     120    mutable bool m_isDirty;
    119121};
    120122
  • trunk/WebCore/html/ValidityState.h

    r48043 r48959  
    4444        bool typeMismatch();
    4545        bool patternMismatch() { return control()->patternMismatch(); }
    46         bool tooLong() { return false; }
     46        bool tooLong() { return control()->tooLong(); }
    4747        bool rangeUnderflow() { return false; }
    4848        bool rangeOverflow() { return false; }
Note: See TracChangeset for help on using the changeset viewer.