Changeset 48903 in webkit


Ignore:
Timestamp:
Sep 29, 2009 2:25:54 PM (15 years ago)
Author:
eric@webkit.org
Message:

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

Reviewed by Darin Adler.

Update for .maxLength behavior change.
https://bugs.webkit.org/show_bug.cgi?id=29796

  • fast/forms/input-maxlength-expected.txt:
  • fast/forms/input-maxlength.html:
  • fast/forms/script-tests/textarea-maxlength.js:
  • fast/forms/textarea-maxlength-expected.txt:

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

Reviewed by Darin Adler.

Follows HTML5's maxLength change in September 2009.

  • Change HTMLTextAreaElement.maxLength type to signed.
  • HTMLTextAreaElement.maxLength returns -1 if maxlength= attribute is missing.
  • HTMLTextAreaElement.maxLength and HTMLInputElement.maxLength throw INDEX_SIZE_ERR for setting negative values. https://bugs.webkit.org/show_bug.cgi?id=29796
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::setMaxLength):
  • html/HTMLInputElement.h:
  • html/HTMLInputElement.idl:
  • html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::handleBeforeTextInsertedEvent): (WebCore::HTMLTextAreaElement::maxLength): (WebCore::HTMLTextAreaElement::setMaxLength):
  • html/HTMLTextAreaElement.h:
  • html/HTMLTextAreaElement.idl:
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r48896 r48903  
     12009-09-29  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Update for .maxLength behavior change.
     6        https://bugs.webkit.org/show_bug.cgi?id=29796
     7
     8        * fast/forms/input-maxlength-expected.txt:
     9        * fast/forms/input-maxlength.html:
     10        * fast/forms/script-tests/textarea-maxlength.js:
     11        * fast/forms/textarea-maxlength-expected.txt:
     12
    1132009-09-29  Dirk Schulze  <krit@webkit.org>
    214
  • trunk/LayoutTests/fast/forms/input-maxlength-expected.txt

    r48449 r48903  
    7373Attempting to insert 530000 characters with maxLength = 600000.
    7474PASS
     75Some tests for .maxLength property.
     76PASS input.maxLength is implicitMaxLength
     77PASS input.maxLength = -1 threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
     78PASS input.getAttribute('maxlength') is '100'
    7579PASS successfullyParsed is true
    7680
  • trunk/LayoutTests/fast/forms/input-maxlength.html

    r48449 r48903  
    4545    }
    4646
     47    debug('Some tests for .maxLength property.');
     48    input = document.createElement("input");
     49    shouldBe("input.maxLength", "implicitMaxLength");
     50    shouldThrow("input.maxLength = -1", "'Error: INDEX_SIZE_ERR: DOM Exception 1'");
     51    input.maxLength = 100;
     52    shouldBe("input.getAttribute('maxlength')", "'100'");
     53
    4754    var successfullyParsed = true;
    4855</script>
  • trunk/LayoutTests/fast/forms/script-tests/textarea-maxlength.js

    r48698 r48903  
    55
    66// No maxlength attribute
    7 shouldBe('textArea.maxLength', '0');
     7shouldBe('textArea.maxLength', '-1');
    88
    99// Invalid maxlength attributes
    1010textArea.setAttribute('maxlength', '-3');
    11 shouldBe('textArea.maxLength', '0');
     11shouldBe('textArea.maxLength', '-1');
    1212textArea.setAttribute('maxlength', 'xyz');
    13 shouldBe('textArea.maxLength', '0');
     13shouldBe('textArea.maxLength', '-1');
    1414
    1515// Valid maxlength attributes
     
    2323shouldBe('textArea.getAttribute("maxlength")', '"13"');
    2424
    25 textArea.maxLength = -1;
    26 shouldBe('textArea.maxLength', '4294967295');
    27 shouldBe('textArea.getAttribute("maxlength")', '"4294967295"');
     25shouldThrow('textArea.maxLength = -1', '"Error: INDEX_SIZE_ERR: DOM Exception 1"');
     26shouldBe('textArea.getAttribute("maxlength")', '"13"');  // Not changed
     27
     28textArea.maxLength = null;
     29shouldBe('textArea.maxLength', '0');
     30shouldBe('textArea.getAttribute("maxlength")', '"0"');
    2831
    2932// maxLength doesn't truncate the default value.
  • trunk/LayoutTests/fast/forms/textarea-maxlength-expected.txt

    r48698 r48903  
    44
    55
    6 PASS textArea.maxLength is 0
    7 PASS textArea.maxLength is 0
    8 PASS textArea.maxLength is 0
     6PASS textArea.maxLength is -1
     7PASS textArea.maxLength is -1
     8PASS textArea.maxLength is -1
    99PASS textArea.maxLength is 1
    1010PASS textArea.maxLength is 256
    1111PASS textArea.getAttribute("maxlength") is "13"
    12 PASS textArea.maxLength is 4294967295
    13 PASS textArea.getAttribute("maxlength") is "4294967295"
     12PASS textArea.maxLength = -1 threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
     13PASS textArea.getAttribute("maxlength") is "13"
     14PASS textArea.maxLength is 0
     15PASS textArea.getAttribute("maxlength") is "0"
    1416PASS textArea.value is "abcd"
    1517PASS textArea.value is "abcde"
  • trunk/WebCore/ChangeLog

    r48902 r48903  
     12009-09-29  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Follows HTML5's maxLength change in September 2009.
     6        - Change HTMLTextAreaElement.maxLength type to signed.
     7        - HTMLTextAreaElement.maxLength returns -1 if maxlength= attribute is missing.
     8        - HTMLTextAreaElement.maxLength and HTMLInputElement.maxLength
     9          throw INDEX_SIZE_ERR for setting negative values.
     10        https://bugs.webkit.org/show_bug.cgi?id=29796
     11
     12        * html/HTMLInputElement.cpp:
     13        (WebCore::HTMLInputElement::setMaxLength):
     14        * html/HTMLInputElement.h:
     15        * html/HTMLInputElement.idl:
     16        * html/HTMLTextAreaElement.cpp:
     17        (WebCore::HTMLTextAreaElement::handleBeforeTextInsertedEvent):
     18        (WebCore::HTMLTextAreaElement::maxLength):
     19        (WebCore::HTMLTextAreaElement::setMaxLength):
     20        * html/HTMLTextAreaElement.h:
     21        * html/HTMLTextAreaElement.idl:
     22
    1232009-09-29  Dimitri Glazkov  <dglazkov@chromium.org>
    224
  • trunk/WebCore/html/HTMLInputElement.cpp

    r48792 r48903  
    3535#include "EventHandler.h"
    3636#include "EventNames.h"
     37#include "ExceptionCode.h"
    3738#include "File.h"
    3839#include "FileList.h"
     
    16101611}
    16111612
    1612 void HTMLInputElement::setMaxLength(int _maxLength)
    1613 {
    1614     setAttribute(maxlengthAttr, String::number(_maxLength));
     1613void HTMLInputElement::setMaxLength(int _maxLength, ExceptionCode& exceptionCode)
     1614{
     1615    if (_maxLength < 0)
     1616        exceptionCode = INDEX_SIZE_ERR;
     1617    else
     1618        setAttribute(maxlengthAttr, String::number(_maxLength));
    16151619}
    16161620
  • trunk/WebCore/html/HTMLInputElement.h

    r48792 r48903  
    202202
    203203    int maxLength() const;
    204     void setMaxLength(int);
     204    void setMaxLength(int, ExceptionCode&);
    205205
    206206    bool multiple() const;
  • trunk/WebCore/html/HTMLInputElement.idl

    r47889 r48903  
    4343        readonly attribute HTMLElement     list;
    4444#endif
    45                  attribute long            maxLength;
     45                 attribute long            maxLength
     46                     setter raises(DOMException);
    4647                 attribute boolean         multiple;
    4748                 attribute [ConvertNullToNullString] DOMString name;
  • trunk/WebCore/html/HTMLTextAreaElement.cpp

    r48792 r48903  
    3333#include "Event.h"
    3434#include "EventNames.h"
     35#include "ExceptionCode.h"
    3536#include "FocusController.h"
    3637#include "FormDataList.h"
     
    284285    ASSERT(event);
    285286    ASSERT(renderer());
    286     bool ok;
    287     unsigned maxLength = getAttribute(maxlengthAttr).string().toUInt(&ok);
    288     if (!ok)
     287    int signedMaxLength = maxLength();
     288    if (signedMaxLength < 0)
    289289        return;
     290    unsigned unsignedMaxLength = static_cast<unsigned>(signedMaxLength);
    290291
    291292    unsigned currentLength = toRenderTextControl(renderer())->text().numGraphemeClusters();
     
    293294    ASSERT(currentLength >= selectionLength);
    294295    unsigned baseLength = currentLength - selectionLength;
    295     unsigned appendableLength = maxLength > baseLength ? maxLength - baseLength : 0;
     296    unsigned appendableLength = unsignedMaxLength > baseLength ? unsignedMaxLength - baseLength : 0;
    296297    event->setText(sanitizeUserInputValue(event->text(), appendableLength));
    297298}
     
    402403}
    403404
    404 unsigned HTMLTextAreaElement::maxLength() const
    405 {
    406     return getAttribute(maxlengthAttr).string().toUInt();
    407 }
    408 
    409 void HTMLTextAreaElement::setMaxLength(unsigned newValue)
    410 {
    411     setAttribute(maxlengthAttr, String::number(newValue));
     405int HTMLTextAreaElement::maxLength() const
     406{
     407    bool ok;
     408    int value = getAttribute(maxlengthAttr).string().toInt(&ok);
     409    return ok && value >= 0 ? value : -1;
     410}
     411
     412void HTMLTextAreaElement::setMaxLength(int newValue, ExceptionCode& exceptionCode)
     413{
     414    if (newValue < 0)
     415        exceptionCode = INDEX_SIZE_ERR;
     416    else
     417        setAttribute(maxlengthAttr, String::number(newValue));
    412418}
    413419
  • trunk/WebCore/html/HTMLTextAreaElement.h

    r48792 r48903  
    8080    void setDefaultValue(const String&);
    8181    int textLength() const { return value().length(); }
    82     unsigned maxLength() const;
    83     void setMaxLength(unsigned);
     82    int maxLength() const;
     83    void setMaxLength(int, ExceptionCode&);
    8484   
    8585    void rendererWillBeDestroyed();
  • trunk/WebCore/html/HTMLTextAreaElement.idl

    r48698 r48903  
    3535                 attribute  boolean              disabled;
    3636                 attribute  boolean              autofocus;
    37                  attribute  unsigned long        maxLength;
     37                 attribute  long                 maxLength
     38                     setter raises(DOMException);
    3839                 attribute  [ConvertNullToNullString] DOMString            name;
    3940                 attribute  [ConvertNullToNullString, Reflect] DOMString   placeholder;
Note: See TracChangeset for help on using the changeset viewer.