Title: [197458] trunk
Revision
197458
Author
[email protected]
Date
2016-03-02 12:38:23 -0800 (Wed, 02 Mar 2016)

Log Message

Align HTMLInputElement.maxLength with the specification
https://bugs.webkit.org/show_bug.cgi?id=154906

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline W3C tests now that more checks are passing.

* web-platform-tests/html/dom/reflection-forms-expected.txt:
* web-platform-tests/html/semantics/forms/the-input-element/maxlength-expected.txt:

Source/WebCore:

Align HTMLInputElement.maxLength with the specification:
- https://html.spec.whatwg.org/multipage/forms.html#dom-input-maxlength
- https://html.spec.whatwg.org/multipage/forms.html#attr-input-maxlength

In particular, the following Web-facing change was made:
- HTMLInputElement.maxLength returns -1 instead of 524288 when
  the corresponding content attribute is missing, cannot be parsed
  or out of range (i.e. negative), as per:
  - https://html.spec.whatwg.org/multipage/infrastructure.html#limited-to-only-non-negative-numbers

Note that HTMLTextAreaElement.maxLength was already returning -1 in
this case.

The new behavior matches Firefox. Chrome however, still seems to
return 524288.

Note that we keep using 524288 as a maximum maxLength internally for
performance reasons. However, we stop exposing this arbitrary value to
the Web as this is an internal limitation.

No new tests, already covered by existing tests.

* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::HTMLInputElement):
Initialize m_maxLength to -1 initially, instead of 524288.

(WebCore::HTMLInputElement::tooLong):
Call effectiveMaxLength() instead of maxLength(), which no longer
exists. effectiveMaxLength() makes sure of returning a value in
the range [0, 524288].

(WebCore::HTMLInputElement::parseAttribute):

(WebCore::HTMLInputElement::effectiveMaxLength):
Split maxLength() into maxLengthForBindings() and effectiveMaxLength().
effectiveMaxLength() returns a value in the range [0, 524288], while
maxLengthForBindings() returns values in the range [-1, 2147483647].

(WebCore::HTMLInputElement::setMaxLength): Deleted.
The implementation was moved to the parent class so that it can be
shared with HTMLTextAreaElement.

(WebCore::HTMLInputElement::maxLengthAttributeChanged):
Rename for clarity.

* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::parseAttribute):
(WebCore::HTMLTextAreaElement::maxLengthAttributeChanged):
Cache the parsed maxLength when the content attribute changes, similarly
to what is already done in HTMLInputElement.

(WebCore::HTMLTextAreaElement::handleBeforeTextInsertedEvent):
(WebCore::HTMLTextAreaElement::validationMessage):
(WebCore::HTMLTextAreaElement::tooLong):
Call effectiveMaxLength() instead of maxLength() which no longer exists.
effectiveMaxLength() returns a cached value and is therefore a lot more
efficient.

* html/HTMLTextAreaElement.h:
* html/HTMLTextAreaElement.idl:
* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::setMaxLengthForBindings):
This was moved up from HTMLInputElement / HTMLTextAreaElement to avoid code
duplication.

* html/HTMLTextFormControlElement.h:

* html/InputType.cpp:
(WebCore::InputType::validationMessage):
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::handleBeforeTextInsertedEvent):
Call HTMLInputElement::effectiveMaxLength() instead of
HTMLInputElement::maxLength() which no longer exists.

LayoutTests:

Update test now that input.maxLength initially returns -1
instead of 524288.

* fast/forms/input-maxlength-expected.txt:
* fast/forms/input-maxlength.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (197457 => 197458)


--- trunk/LayoutTests/ChangeLog	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/LayoutTests/ChangeLog	2016-03-02 20:38:23 UTC (rev 197458)
@@ -1,3 +1,16 @@
+2016-03-02  Chris Dumez  <[email protected]>
+
+        Align HTMLInputElement.maxLength with the specification
+        https://bugs.webkit.org/show_bug.cgi?id=154906
+
+        Reviewed by Ryosuke Niwa.
+
+        Update test now that input.maxLength initially returns -1
+        instead of 524288.
+
+        * fast/forms/input-maxlength-expected.txt:
+        * fast/forms/input-maxlength.html:
+
 2016-03-02  Zalan Bujtas  <[email protected]>
 
         Subpixel layout: Enable vertical/horizontal subpixel spacing for tables.

Modified: trunk/LayoutTests/fast/forms/input-maxlength-expected.txt (197457 => 197458)


--- trunk/LayoutTests/fast/forms/input-maxlength-expected.txt	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/LayoutTests/fast/forms/input-maxlength-expected.txt	2016-03-02 20:38:23 UTC (rev 197458)
@@ -73,7 +73,7 @@
 Attempting to insert 530000 characters with maxLength = 600000.
 PASS 
 Some tests for .maxLength property.
-PASS input.maxLength is implicitMaxLength
+PASS input.maxLength is -1
 PASS input.maxLength = -1 threw exception Error: IndexSizeError: DOM Exception 1.
 PASS input.getAttribute('maxlength') is '100'
 PASS successfullyParsed is true

Modified: trunk/LayoutTests/fast/forms/input-maxlength.html (197457 => 197458)


--- trunk/LayoutTests/fast/forms/input-maxlength.html	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/LayoutTests/fast/forms/input-maxlength.html	2016-03-02 20:38:23 UTC (rev 197458)
@@ -46,7 +46,7 @@
 
     debug('Some tests for .maxLength property.');
     input = document.createElement("input");
-    shouldBe("input.maxLength", "implicitMaxLength");
+    shouldBe("input.maxLength", "-1");
     shouldThrow("input.maxLength = -1", "'Error: IndexSizeError: DOM Exception 1'");
     input.maxLength = 100;
     shouldBe("input.getAttribute('maxlength')", "'100'");

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (197457 => 197458)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-03-02 20:38:23 UTC (rev 197458)
@@ -1,3 +1,15 @@
+2016-03-02  Chris Dumez  <[email protected]>
+
+        Align HTMLInputElement.maxLength with the specification
+        https://bugs.webkit.org/show_bug.cgi?id=154906
+
+        Reviewed by Ryosuke Niwa.
+
+        Rebaseline W3C tests now that more checks are passing.
+
+        * web-platform-tests/html/dom/reflection-forms-expected.txt:
+        * web-platform-tests/html/semantics/forms/the-input-element/maxlength-expected.txt:
+
 2016-03-01  Youenn Fablet  <[email protected]>
 
         [Fetch API] Support Request and Response blob() when body data is a blob

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/reflection-forms-expected.txt (197457 => 197458)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/reflection-forms-expected.txt	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/reflection-forms-expected.txt	2016-03-02 20:38:23 UTC (rev 197458)
@@ -6173,15 +6173,15 @@
 PASS input.max: IDL set to object "test-valueOf" followed by getAttribute() 
 PASS input.max: IDL set to object "test-valueOf" followed by IDL get 
 PASS input.maxLength: typeof IDL attribute 
-FAIL input.maxLength: IDL get with DOM attribute unset assert_equals: expected -1 but got 524288
+PASS input.maxLength: IDL get with DOM attribute unset 
 PASS input.maxLength: setAttribute() to -2147483649 followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to -2147483649 followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to -2147483649 followed by IDL get 
 PASS input.maxLength: setAttribute() to -2147483648 followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to -2147483648 followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to -2147483648 followed by IDL get 
 PASS input.maxLength: setAttribute() to -36 followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to -36 followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to -36 followed by IDL get 
 PASS input.maxLength: setAttribute() to -1 followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to -1 followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to -1 followed by IDL get 
 PASS input.maxLength: setAttribute() to -0 followed by getAttribute() 
 PASS input.maxLength: setAttribute() to -0 followed by IDL get 
 PASS input.maxLength: setAttribute() to 0 followed by getAttribute() 
@@ -6189,17 +6189,17 @@
 PASS input.maxLength: setAttribute() to 1 followed by getAttribute() 
 PASS input.maxLength: setAttribute() to 1 followed by IDL get 
 PASS input.maxLength: setAttribute() to 2147483647 followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to 2147483647 followed by IDL get assert_equals: expected 2147483647 but got 524288
+PASS input.maxLength: setAttribute() to 2147483647 followed by IDL get 
 PASS input.maxLength: setAttribute() to 2147483648 followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to 2147483648 followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to 2147483648 followed by IDL get 
 PASS input.maxLength: setAttribute() to 4294967295 followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to 4294967295 followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to 4294967295 followed by IDL get 
 PASS input.maxLength: setAttribute() to 4294967296 followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to 4294967296 followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to 4294967296 followed by IDL get 
 PASS input.maxLength: setAttribute() to "" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to "" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to "" followed by IDL get 
 PASS input.maxLength: setAttribute() to "-1" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to "-1" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to "-1" followed by IDL get 
 PASS input.maxLength: setAttribute() to "-0" followed by getAttribute() 
 PASS input.maxLength: setAttribute() to "-0" followed by IDL get 
 PASS input.maxLength: setAttribute() to "0" followed by getAttribute() 
@@ -6207,79 +6207,79 @@
 PASS input.maxLength: setAttribute() to "1" followed by getAttribute() 
 PASS input.maxLength: setAttribute() to "1" followed by IDL get 
 PASS input.maxLength: setAttribute() to " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo " followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo " followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo " followed by IDL get 
 PASS input.maxLength: setAttribute() to "\t7" followed by getAttribute() 
 PASS input.maxLength: setAttribute() to "\t7" followed by IDL get 
 PASS input.maxLength: setAttribute() to "\v7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to "\v7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to "\v7" followed by IDL get 
 PASS input.maxLength: setAttribute() to "\f7" followed by getAttribute() 
 PASS input.maxLength: setAttribute() to "\f7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
 PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to "7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to "7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to "7" followed by IDL get 
 PASS input.maxLength: setAttribute() to "\n7" followed by getAttribute() 
 PASS input.maxLength: setAttribute() to "\n7" followed by IDL get 
 PASS input.maxLength: setAttribute() to "\r7" followed by getAttribute() 
 PASS input.maxLength: setAttribute() to "\r7" followed by IDL get 
 PASS input.maxLength: setAttribute() to "
7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to "
7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to "
7" followed by IDL get 
 PASS input.maxLength: setAttribute() to "
7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to "
7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to "
7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to "᠎7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to "᠎7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to "᠎7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to " 7" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to " 7" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to " 7" followed by IDL get 
 PASS input.maxLength: setAttribute() to undefined followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to undefined followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to undefined followed by IDL get 
 PASS input.maxLength: setAttribute() to 1.5 followed by getAttribute() 
 PASS input.maxLength: setAttribute() to 1.5 followed by IDL get 
 PASS input.maxLength: setAttribute() to true followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to true followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to true followed by IDL get 
 PASS input.maxLength: setAttribute() to false followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to false followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to false followed by IDL get 
 PASS input.maxLength: setAttribute() to object "[object Object]" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to object "[object Object]" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to object "[object Object]" followed by IDL get 
 PASS input.maxLength: setAttribute() to NaN followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to NaN followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to NaN followed by IDL get 
 PASS input.maxLength: setAttribute() to Infinity followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to Infinity followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to Infinity followed by IDL get 
 PASS input.maxLength: setAttribute() to -Infinity followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to -Infinity followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to -Infinity followed by IDL get 
 PASS input.maxLength: setAttribute() to "\0" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to "\0" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to "\0" followed by IDL get 
 PASS input.maxLength: setAttribute() to object "2" followed by getAttribute() 
 PASS input.maxLength: setAttribute() to object "2" followed by IDL get 
 PASS input.maxLength: setAttribute() to object "3" followed by getAttribute() 
-FAIL input.maxLength: setAttribute() to object "3" followed by IDL get assert_equals: expected -1 but got 524288
+PASS input.maxLength: setAttribute() to object "3" followed by IDL get 
 PASS input.maxLength: IDL set to -2147483648 must throw INDEX_SIZE_ERR 
 PASS input.maxLength: IDL set to -36 must throw INDEX_SIZE_ERR 
 PASS input.maxLength: IDL set to -1 must throw INDEX_SIZE_ERR 
@@ -6291,7 +6291,7 @@
 PASS input.maxLength: IDL set to 1 followed by IDL get 
 PASS input.maxLength: IDL set to 2147483647 should not throw 
 PASS input.maxLength: IDL set to 2147483647 followed by getAttribute() 
-FAIL input.maxLength: IDL set to 2147483647 followed by IDL get assert_equals: expected 2147483647 but got 524288
+PASS input.maxLength: IDL set to 2147483647 followed by IDL get 
 PASS input.min: typeof IDL attribute 
 PASS input.min: IDL get with DOM attribute unset 
 PASS input.min: setAttribute() to "" followed by getAttribute() 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/maxlength-expected.txt (197457 => 197458)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/maxlength-expected.txt	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/maxlength-expected.txt	2016-03-02 20:38:23 UTC (rev 197458)
@@ -1,9 +1,9 @@
 Text input element
 
 
-FAIL Unset maxlength is -1 assert_equals: expected -1 but got 524288
-FAIL Negative maxlength is always -1 assert_equals: expected -1 but got 524288
-FAIL Non-numeric maxlength is -1 assert_equals: expected -1 but got 524288
+PASS Unset maxlength is -1 
+PASS Negative maxlength is always -1 
+PASS Non-numeric maxlength is -1 
 PASS Assigning negative integer throws IndexSizeError 
 PASS Assigning non-numeric to maxlength sets maxlength to 0 
 

Modified: trunk/Source/WebCore/ChangeLog (197457 => 197458)


--- trunk/Source/WebCore/ChangeLog	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/Source/WebCore/ChangeLog	2016-03-02 20:38:23 UTC (rev 197458)
@@ -1,3 +1,84 @@
+2016-03-02  Chris Dumez  <[email protected]>
+
+        Align HTMLInputElement.maxLength with the specification
+        https://bugs.webkit.org/show_bug.cgi?id=154906
+
+        Reviewed by Ryosuke Niwa.
+
+        Align HTMLInputElement.maxLength with the specification:
+        - https://html.spec.whatwg.org/multipage/forms.html#dom-input-maxlength
+        - https://html.spec.whatwg.org/multipage/forms.html#attr-input-maxlength
+
+        In particular, the following Web-facing change was made:
+        - HTMLInputElement.maxLength returns -1 instead of 524288 when
+          the corresponding content attribute is missing, cannot be parsed
+          or out of range (i.e. negative), as per:
+          - https://html.spec.whatwg.org/multipage/infrastructure.html#limited-to-only-non-negative-numbers
+
+        Note that HTMLTextAreaElement.maxLength was already returning -1 in
+        this case.
+
+        The new behavior matches Firefox. Chrome however, still seems to
+        return 524288.
+
+        Note that we keep using 524288 as a maximum maxLength internally for
+        performance reasons. However, we stop exposing this arbitrary value to
+        the Web as this is an internal limitation.
+
+        No new tests, already covered by existing tests.
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::HTMLInputElement):
+        Initialize m_maxLength to -1 initially, instead of 524288.
+
+        (WebCore::HTMLInputElement::tooLong):
+        Call effectiveMaxLength() instead of maxLength(), which no longer
+        exists. effectiveMaxLength() makes sure of returning a value in
+        the range [0, 524288].
+
+        (WebCore::HTMLInputElement::parseAttribute):
+
+        (WebCore::HTMLInputElement::effectiveMaxLength):
+        Split maxLength() into maxLengthForBindings() and effectiveMaxLength().
+        effectiveMaxLength() returns a value in the range [0, 524288], while
+        maxLengthForBindings() returns values in the range [-1, 2147483647].
+
+        (WebCore::HTMLInputElement::setMaxLength): Deleted.
+        The implementation was moved to the parent class so that it can be
+        shared with HTMLTextAreaElement.
+
+        (WebCore::HTMLInputElement::maxLengthAttributeChanged):
+        Rename for clarity.
+
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::parseAttribute):
+        (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged):
+        Cache the parsed maxLength when the content attribute changes, similarly
+        to what is already done in HTMLInputElement.
+
+        (WebCore::HTMLTextAreaElement::handleBeforeTextInsertedEvent):
+        (WebCore::HTMLTextAreaElement::validationMessage):
+        (WebCore::HTMLTextAreaElement::tooLong):
+        Call effectiveMaxLength() instead of maxLength() which no longer exists.
+        effectiveMaxLength() returns a cached value and is therefore a lot more
+        efficient.
+
+        * html/HTMLTextAreaElement.h:
+        * html/HTMLTextAreaElement.idl:
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::HTMLTextFormControlElement::setMaxLengthForBindings):
+        This was moved up from HTMLInputElement / HTMLTextAreaElement to avoid code
+        duplication.
+
+        * html/HTMLTextFormControlElement.h:
+
+        * html/InputType.cpp:
+        (WebCore::InputType::validationMessage):
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::handleBeforeTextInsertedEvent):
+        Call HTMLInputElement::effectiveMaxLength() instead of
+        HTMLInputElement::maxLength() which no longer exists.
+
 2016-03-02  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r197434 and r197436.

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (197457 => 197458)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2016-03-02 20:38:23 UTC (rev 197458)
@@ -89,14 +89,14 @@
 // large. However, due to https://bugs.webkit.org/show_bug.cgi?id=14536 things
 // get rather sluggish when a text field has a larger number of characters than
 // this, even when just clicking in the text field.
-const int HTMLInputElement::maximumLength = 524288;
+const unsigned HTMLInputElement::maxEffectiveLength = 524288;
 const int defaultSize = 20;
 const int maxSavedResults = 256;
 
 HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document& document, HTMLFormElement* form, bool createdByParser)
     : HTMLTextFormControlElement(tagName, document, form)
     , m_size(defaultSize)
-    , m_maxLength(maximumLength)
+    , m_maxLength(-1)
     , m_maxResults(-1)
     , m_isChecked(false)
     , m_reflectsCheckedAttribute(true)
@@ -283,16 +283,14 @@
     // 'virtual' overhead.
     if (!isTextType())
         return false;
-    int max = maxLength();
-    if (max < 0)
-        return false;
+    unsigned max = effectiveMaxLength();
     if (check == CheckDirtyFlag) {
         // Return false for the default value or a value set by a script even if
         // it is longer than maxLength.
         if (!hasDirtyValue() || !m_wasModifiedByUser)
             return false;
     }
-    return numGraphemeClusters(value) > static_cast<unsigned>(max);
+    return numGraphemeClusters(value) > max;
 }
 
 bool HTMLInputElement::rangeUnderflow() const
@@ -682,7 +680,7 @@
             m_reflectsCheckedAttribute = true;
         }
     } else if (name == maxlengthAttr)
-        parseMaxLengthAttribute(value);
+        maxLengthAttributeChanged(value);
     else if (name == sizeAttr) {
         unsigned oldSize = m_size;
         m_size = limitToOnlyHTMLNonNegativeNumbersGreaterThanZero(value, defaultSize);
@@ -1254,19 +1252,12 @@
     return fastGetAttribute(altAttr);
 }
 
-int HTMLInputElement::maxLength() const
+unsigned HTMLInputElement::effectiveMaxLength() const
 {
-    return m_maxLength;
+    // The number -1 represents no maximum at all; conveniently it becomes a super-large value when converted to unsigned.
+    return std::min<unsigned>(m_maxLength, maxEffectiveLength);
 }
 
-void HTMLInputElement::setMaxLength(int maxLength, ExceptionCode& ec)
-{
-    if (maxLength < 0)
-        ec = INDEX_SIZE_ERR;
-    else
-        setIntegralAttribute(maxlengthAttr, maxLength);
-}
-
 bool HTMLInputElement::multiple() const
 {
     return fastHasAttribute(multipleAttr);
@@ -1740,13 +1731,14 @@
     return m_inputType->isEmptyValue();
 }
 
-void HTMLInputElement::parseMaxLengthAttribute(const AtomicString& value)
+void HTMLInputElement::maxLengthAttributeChanged(const AtomicString& newValue)
 {
-    int maxLength = std::min(parseHTMLNonNegativeInteger(value).valueOr(maximumLength), maximumLength);
-    int oldMaxLength = m_maxLength;
-    m_maxLength = maxLength;
-    if (oldMaxLength != maxLength)
+    unsigned oldEffectiveMaxLength = effectiveMaxLength();
+    m_maxLength = parseHTMLNonNegativeInteger(newValue).valueOr(-1);
+    if (oldEffectiveMaxLength != effectiveMaxLength())
         updateValueIfNeeded();
+
+    // FIXME: Do we really need to do this if the effective maxLength has not changed?
     setNeedsStyleRecalc();
     updateValidity();
 }

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (197457 => 197458)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2016-03-02 20:38:23 UTC (rev 197458)
@@ -232,8 +232,8 @@
 
     URL src() const;
 
-    virtual int maxLength() const override final;
-    void setMaxLength(int, ExceptionCode&);
+    int maxLengthForBindings() const { return m_maxLength; }
+    unsigned effectiveMaxLength() const;
 
     bool multiple() const;
 
@@ -292,7 +292,7 @@
     bool shouldUseMediaCapture() const;
 #endif
 
-    static const int maximumLength;
+    static const unsigned maxEffectiveLength;
 
     unsigned height() const;
     unsigned width() const;
@@ -414,7 +414,7 @@
 #if ENABLE(DATALIST_ELEMENT)
     void resetListAttributeTargetObserver();
 #endif
-    void parseMaxLengthAttribute(const AtomicString&);
+    void maxLengthAttributeChanged(const AtomicString& newValue);
     void updateValueIfNeeded();
 
     // Returns null if this isn't associated with any radio button group.

Modified: trunk/Source/WebCore/html/HTMLInputElement.idl (197457 => 197458)


--- trunk/Source/WebCore/html/HTMLInputElement.idl	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/Source/WebCore/html/HTMLInputElement.idl	2016-03-02 20:38:23 UTC (rev 197458)
@@ -42,7 +42,7 @@
     attribute boolean indeterminate;
     [Conditional=DATALIST_ELEMENT] readonly attribute HTMLElement list;
     [Reflect] attribute DOMString max;
-    [SetterRaisesException] attribute long maxLength;
+    [ImplementedAs=maxLengthForBindings, SetterRaisesException] attribute long maxLength;
     [Reflect] attribute DOMString min;
     [Reflect] attribute boolean multiple;
     [Reflect] attribute DOMString name;

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (197457 => 197458)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2016-03-02 20:38:23 UTC (rev 197458)
@@ -201,11 +201,17 @@
     } else if (name == accesskeyAttr) {
         // ignore for the moment
     } else if (name == maxlengthAttr)
-        updateValidity();
+        maxLengthAttributeChanged(value);
     else
         HTMLTextFormControlElement::parseAttribute(name, value);
 }
 
+void HTMLTextAreaElement::maxLengthAttributeChanged(const AtomicString& newValue)
+{
+    m_maxLength = parseHTMLNonNegativeInteger(newValue).valueOr(-1);
+    updateValidity();
+}
+
 RenderPtr<RenderElement> HTMLTextAreaElement::createElementRenderer(Ref<RenderStyle>&& style, const RenderTreePosition&)
 {
     return createRenderer<RenderTextControlMultiLine>(*this, WTFMove(style));
@@ -291,7 +297,7 @@
 {
     ASSERT(event);
     ASSERT(renderer());
-    int signedMaxLength = maxLength();
+    int signedMaxLength = effectiveMaxLength();
     if (signedMaxLength < 0)
         return;
     unsigned unsignedMaxLength = static_cast<unsigned>(signedMaxLength);
@@ -421,19 +427,6 @@
         setNonDirtyValue(value);
 }
 
-int HTMLTextAreaElement::maxLength() const
-{
-    return parseHTMLNonNegativeInteger(fastGetAttribute(maxlengthAttr)).valueOr(-1);
-}
-
-void HTMLTextAreaElement::setMaxLength(int newValue, ExceptionCode& ec)
-{
-    if (newValue < 0)
-        ec = INDEX_SIZE_ERR;
-    else
-        setIntegralAttribute(maxlengthAttr, newValue);
-}
-
 String HTMLTextAreaElement::validationMessage() const
 {
     if (!willValidate())
@@ -446,7 +439,7 @@
         return validationMessageValueMissingText();
 
     if (tooLong())
-        return validationMessageTooLongText(computeLengthForSubmission(value()), maxLength());
+        return validationMessageTooLongText(computeLengthForSubmission(value()), effectiveMaxLength());
 
     return String();
 }
@@ -468,7 +461,7 @@
     if (check == CheckDirtyFlag && !m_wasModifiedByUser)
         return false;
 
-    int max = maxLength();
+    int max = effectiveMaxLength();
     if (max < 0)
         return false;
     unsigned unsignedMax = static_cast<unsigned>(max);

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.h (197457 => 197458)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.h	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.h	2016-03-02 20:38:23 UTC (rev 197458)
@@ -45,8 +45,8 @@
     String defaultValue() const;
     void setDefaultValue(const String&);
     int textLength() const { return value().length(); }
-    virtual int maxLength() const override;
-    void setMaxLength(int, ExceptionCode&);
+    int maxLengthForBindings() const { return m_maxLength; }
+    int effectiveMaxLength() const { return m_maxLength; }
     // For ValidityState
     virtual String validationMessage() const override;
     virtual bool valueMissing() const override;
@@ -71,6 +71,8 @@
     virtual void didAddUserAgentShadowRoot(ShadowRoot*) override;
     virtual bool canHaveUserAgentShadowRoot() const override final { return true; }
 
+    void maxLengthAttributeChanged(const AtomicString& newValue);
+
     void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*) const;
     static String sanitizeUserInputValue(const String&, unsigned maxLength);
     void updateValue() const;
@@ -121,6 +123,7 @@
 
     unsigned m_rows;
     unsigned m_cols;
+    int m_maxLength { -1 };
     WrapMethod m_wrap;
     HTMLElement* m_placeholder;
     mutable String m_value;

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.idl (197457 => 197458)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.idl	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.idl	2016-03-02 20:38:23 UTC (rev 197458)
@@ -24,7 +24,7 @@
     [Reflect] attribute DOMString dirName;
     [Reflect] attribute boolean disabled;
     readonly attribute HTMLFormElement form;
-    [SetterRaisesException] attribute long maxLength;
+    [ImplementedAs=maxLengthForBindings, SetterRaisesException] attribute long maxLength;
     [Reflect] attribute DOMString name;
     [Reflect] attribute DOMString placeholder;
     [Reflect] attribute boolean readOnly;

Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp (197457 => 197458)


--- trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2016-03-02 20:38:23 UTC (rev 197458)
@@ -37,6 +37,7 @@
 #include "HTMLFormElement.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
+#include "HTMLParserIdioms.h"
 #include "NodeTraversal.h"
 #include "Page.h"
 #include "RenderBlockFlow.h"
@@ -759,6 +760,14 @@
     return "ltr";
 }
 
+void HTMLTextFormControlElement::setMaxLengthForBindings(int maxLength, ExceptionCode& ec)
+{
+    if (maxLength < 0)
+        ec = INDEX_SIZE_ERR;
+    else
+        setIntegralAttribute(maxlengthAttr, maxLength);
+}
+
 void HTMLTextFormControlElement::adjustInnerTextStyle(const RenderStyle& parentStyle, RenderStyle& textBlockStyle) const
 {
     // The inner block, if present, always has its direction set to LTR,

Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.h (197457 => 197458)


--- trunk/Source/WebCore/html/HTMLTextFormControlElement.h	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.h	2016-03-02 20:38:23 UTC (rev 197458)
@@ -48,6 +48,8 @@
     void didEditInnerTextValue();
     void forwardEvent(Event*);
 
+    void setMaxLengthForBindings(int, ExceptionCode&);
+
     virtual InsertionNotificationRequest insertedInto(ContainerNode&) override;
 
     // The derived class should return true if placeholder processing is needed.
@@ -75,7 +77,6 @@
 
     virtual void dispatchFormControlChangeEvent() override final;
 
-    virtual int maxLength() const = 0;
     virtual String value() const = 0;
 
     virtual TextControlInnerTextElement* innerTextElement() const = 0;

Modified: trunk/Source/WebCore/html/InputType.cpp (197457 => 197458)


--- trunk/Source/WebCore/html/InputType.cpp	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/Source/WebCore/html/InputType.cpp	2016-03-02 20:38:23 UTC (rev 197458)
@@ -406,7 +406,7 @@
         return validationMessagePatternMismatchText();
 
     if (element().tooLong())
-        return validationMessageTooLongText(numGraphemeClusters(value), element().maxLength());
+        return validationMessageTooLongText(numGraphemeClusters(value), element().effectiveMaxLength());
 
     if (!isSteppable())
         return emptyString();

Modified: trunk/Source/WebCore/html/TextFieldInputType.cpp (197457 => 197458)


--- trunk/Source/WebCore/html/TextFieldInputType.cpp	2016-03-02 19:17:18 UTC (rev 197457)
+++ trunk/Source/WebCore/html/TextFieldInputType.cpp	2016-03-02 20:38:23 UTC (rev 197458)
@@ -430,7 +430,7 @@
 
 String TextFieldInputType::sanitizeValue(const String& proposedValue) const
 {
-    return limitLength(proposedValue.removeCharacters(isASCIILineBreak), HTMLInputElement::maximumLength);
+    return limitLength(proposedValue.removeCharacters(isASCIILineBreak), HTMLInputElement::maxEffectiveLength);
 }
 
 void TextFieldInputType::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent* event)
@@ -460,7 +460,7 @@
 
     // Selected characters will be removed by the next text event.
     unsigned baseLength = oldLength - selectionLength;
-    unsigned maxLength = static_cast<unsigned>(isTextType() ? element().maxLength() : HTMLInputElement::maximumLength); // maxLength can never be negative.
+    unsigned maxLength = isTextType() ? element().effectiveMaxLength() : HTMLInputElement::maxEffectiveLength;
     unsigned appendableLength = maxLength > baseLength ? maxLength - baseLength : 0;
 
     // Truncate the inserted text to avoid violating the maxLength and other constraints.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to