From bdb6706f19167890aef895e5aa04bccc9de3695f Mon Sep 17 00:00:00 2001 From: tigercosmos Date: Sun, 17 Jun 2018 06:33:22 -0700 Subject: [PATCH] textarea minLength/maxLength --- components/script/dom/htmltextareaelement.rs | 49 +- .../dom/webidls/HTMLTextAreaElement.webidl | 8 +- tests/wpt/metadata/MANIFEST.json | 20 + .../html/dom/reflection-forms.html.ini | 543 ------------------ .../textarea-maxlength.html | 51 ++ .../textarea-minlength.html | 51 ++ 6 files changed, 173 insertions(+), 549 deletions(-) create mode 100644 tests/wpt/web-platform-tests/html/semantics/forms/the-textarea-element/textarea-maxlength.html create mode 100644 tests/wpt/web-platform-tests/html/semantics/forms/the-textarea-element/textarea-minlength.html diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index d03fb1a348c..459500da9a1 100755 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -105,10 +105,13 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutDom { } // https://html.spec.whatwg.org/multipage/#attr-textarea-cols-value -static DEFAULT_COLS: u32 = 20; +const DEFAULT_COLS: u32 = 20; // https://html.spec.whatwg.org/multipage/#attr-textarea-rows-value -static DEFAULT_ROWS: u32 = 2; +const DEFAULT_ROWS: u32 = 2; + +const DEFAULT_MAX_LENGTH: i32 = -1; +const DEFAULT_MIN_LENGTH: i32 = -1; impl HTMLTextAreaElement { fn new_inherited(local_name: LocalName, @@ -192,6 +195,18 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement { // https://html.spec.whatwg.org/multipage/#dom-textarea-placeholder make_setter!(SetPlaceholder, "placeholder"); + // https://html.spec.whatwg.org/multipage/#attr-textarea-maxlength + make_int_getter!(MaxLength, "maxlength", DEFAULT_MAX_LENGTH); + + // https://html.spec.whatwg.org/multipage/#attr-textarea-maxlength + make_limited_int_setter!(SetMaxLength, "maxlength", DEFAULT_MAX_LENGTH); + + // https://html.spec.whatwg.org/multipage/#attr-textarea-minlength + make_int_getter!(MinLength, "minlength", DEFAULT_MIN_LENGTH); + + // https://html.spec.whatwg.org/multipage/#attr-textarea-minlength + make_limited_int_setter!(SetMinLength, "minlength", DEFAULT_MIN_LENGTH); + // https://html.spec.whatwg.org/multipage/#attr-textarea-readonly make_bool_getter!(ReadOnly, "readonly"); @@ -369,6 +384,34 @@ impl VirtualMethods for HTMLTextAreaElement { } } }, + local_name!("maxlength") => { + match *attr.value() { + AttrValue::Int(_, value) => { + let mut textinput = self.textinput.borrow_mut(); + + if value < 0 { + textinput.set_max_length(None); + } else { + textinput.set_max_length(Some(value as usize)) + } + }, + _ => panic!("Expected an AttrValue::Int"), + } + }, + local_name!("minlength") => { + match *attr.value() { + AttrValue::Int(_, value) => { + let mut textinput = self.textinput.borrow_mut(); + + if value < 0 { + textinput.set_min_length(None); + } else { + textinput.set_min_length(Some(value as usize)) + } + }, + _ => panic!("Expected an AttrValue::Int"), + } + }, local_name!("placeholder") => { { let mut placeholder = self.placeholder.borrow_mut(); @@ -409,6 +452,8 @@ impl VirtualMethods for HTMLTextAreaElement { match *name { local_name!("cols") => AttrValue::from_limited_u32(value.into(), DEFAULT_COLS), local_name!("rows") => AttrValue::from_limited_u32(value.into(), DEFAULT_ROWS), + local_name!("maxlength") => AttrValue::from_limited_i32(value.into(), DEFAULT_MAX_LENGTH), + local_name!("minlength") => AttrValue::from_limited_i32(value.into(), DEFAULT_MIN_LENGTH), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } diff --git a/components/script/dom/webidls/HTMLTextAreaElement.webidl b/components/script/dom/webidls/HTMLTextAreaElement.webidl index f8f52c82b92..3839be24f5e 100644 --- a/components/script/dom/webidls/HTMLTextAreaElement.webidl +++ b/components/script/dom/webidls/HTMLTextAreaElement.webidl @@ -18,10 +18,10 @@ interface HTMLTextAreaElement : HTMLElement { readonly attribute HTMLFormElement? form; // [CEReactions] // attribute DOMString inputMode; - // [CEReactions] - // attribute long maxLength; - // [CEReactions] - // attribute long minLength; + [CEReactions, SetterThrows] + attribute long maxLength; + [CEReactions, SetterThrows] + attribute long minLength; attribute DOMString name; [CEReactions] attribute DOMString placeholder; diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index 79fcf7083e3..aec0bf3f927 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -347338,6 +347338,18 @@ {} ] ], + "html/semantics/forms/the-textarea-element/textarea-maxlength.html": [ + [ + "/html/semantics/forms/the-textarea-element/textarea-maxlength.html", + {} + ] + ], + "html/semantics/forms/the-textarea-element/textarea-minlength.html": [ + [ + "/html/semantics/forms/the-textarea-element/textarea-minlength.html", + {} + ] + ], "html/semantics/forms/the-textarea-element/textarea-type.html": [ [ "/html/semantics/forms/the-textarea-element/textarea-type.html", @@ -585051,6 +585063,14 @@ "b61235681689807b5d46b8aaca9ae6c7a18039f7", "testharness" ], + "html/semantics/forms/the-textarea-element/textarea-maxlength.html": [ + "fb2796fe7e542bd9551c18c0176a4f822ee347cd", + "testharness" + ], + "html/semantics/forms/the-textarea-element/textarea-minlength.html": [ + "fcccb00d0db7222af1fb03e7481ccf31e51ec924", + "testharness" + ], "html/semantics/forms/the-textarea-element/textarea-newline-bidi-ref.html": [ "26eb3e615f8b0e15cf02b7ee18d39fd71b04da70", "support" diff --git a/tests/wpt/metadata/html/dom/reflection-forms.html.ini b/tests/wpt/metadata/html/dom/reflection-forms.html.ini index 886ddb659db..e66f44b15d7 100644 --- a/tests/wpt/metadata/html/dom/reflection-forms.html.ini +++ b/tests/wpt/metadata/html/dom/reflection-forms.html.ini @@ -10263,189 +10263,6 @@ [textarea.inputMode: IDL set to "URL" followed by IDL get] expected: FAIL - [textarea.maxLength: typeof IDL attribute] - expected: FAIL - - [textarea.maxLength: IDL get with DOM attribute unset] - expected: FAIL - - [textarea.maxLength: setAttribute() to -2147483649 followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to -2147483648 followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to -36 followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to -1 followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to -0 followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to 0 followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to 1 followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to 2147483647 followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to 2147483648 followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to 4294967295 followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to 4294967296 followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "-1" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "-0" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "0" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "1" followed by IDL get] - expected: FAIL - - [textarea.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] - expected: FAIL - - [textarea.maxLength: setAttribute() to "\\t7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "\\v7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "\\f7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "\\n7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "\\r7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "
7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "
7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "᠎7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to undefined followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to 1.5 followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to true followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to false followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to object "[object Object\]" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to NaN followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to Infinity followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to -Infinity followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to "\\0" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to object "2" followed by IDL get] - expected: FAIL - - [textarea.maxLength: setAttribute() to object "3" followed by IDL get] - expected: FAIL - - [textarea.maxLength: IDL set to -2147483648 must throw INDEX_SIZE_ERR] - expected: FAIL - - [textarea.maxLength: IDL set to -36 must throw INDEX_SIZE_ERR] - expected: FAIL - - [textarea.maxLength: IDL set to -1 must throw INDEX_SIZE_ERR] - expected: FAIL - - [textarea.maxLength: IDL set to 0 followed by getAttribute()] - expected: FAIL - - [textarea.maxLength: IDL set to 1 followed by getAttribute()] - expected: FAIL - - [textarea.maxLength: IDL set to 2147483647 followed by getAttribute()] - expected: FAIL - [textarea.itemScope: typeof IDL attribute] expected: FAIL @@ -21909,183 +21726,6 @@ [textarea.inputMode: IDL set to "URL"] expected: FAIL - [textarea.maxLength: setAttribute() to -2147483649] - expected: FAIL - - [textarea.maxLength: setAttribute() to -2147483648] - expected: FAIL - - [textarea.maxLength: setAttribute() to -36] - expected: FAIL - - [textarea.maxLength: setAttribute() to -1] - expected: FAIL - - [textarea.maxLength: setAttribute() to -0] - expected: FAIL - - [textarea.maxLength: setAttribute() to 0] - expected: FAIL - - [textarea.maxLength: setAttribute() to 1] - expected: FAIL - - [textarea.maxLength: setAttribute() to 2147483647] - expected: FAIL - - [textarea.maxLength: setAttribute() to 2147483648] - expected: FAIL - - [textarea.maxLength: setAttribute() to 4294967295] - expected: FAIL - - [textarea.maxLength: setAttribute() to 4294967296] - expected: FAIL - - [textarea.maxLength: setAttribute() to ""] - expected: FAIL - - [textarea.maxLength: setAttribute() to "-1"] - expected: FAIL - - [textarea.maxLength: setAttribute() to "-0"] - expected: FAIL - - [textarea.maxLength: setAttribute() to "0"] - expected: FAIL - - [textarea.maxLength: setAttribute() to "1"] - expected: FAIL - - [textarea.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 "] - expected: FAIL - - [textarea.maxLength: setAttribute() to "\\t7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to "\\v7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to "\\f7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to "7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to "\\n7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to "\\r7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to "
7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to "
7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to "᠎7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.maxLength: setAttribute() to undefined] - expected: FAIL - - [textarea.maxLength: setAttribute() to 1.5] - expected: FAIL - - [textarea.maxLength: setAttribute() to true] - expected: FAIL - - [textarea.maxLength: setAttribute() to false] - expected: FAIL - - [textarea.maxLength: setAttribute() to object "[object Object\]"] - expected: FAIL - - [textarea.maxLength: setAttribute() to NaN] - expected: FAIL - - [textarea.maxLength: setAttribute() to Infinity] - expected: FAIL - - [textarea.maxLength: setAttribute() to -Infinity] - expected: FAIL - - [textarea.maxLength: setAttribute() to "\\0"] - expected: FAIL - - [textarea.maxLength: setAttribute() to object "2"] - expected: FAIL - - [textarea.maxLength: setAttribute() to object "3"] - expected: FAIL - - [textarea.maxLength: IDL set to -2147483648] - expected: FAIL - - [textarea.maxLength: IDL set to -36] - expected: FAIL - - [textarea.maxLength: IDL set to -1] - expected: FAIL - - [textarea.maxLength: IDL set to 0] - expected: FAIL - - [textarea.maxLength: IDL set to 1] - expected: FAIL - - [textarea.maxLength: IDL set to 2147483647] - expected: FAIL - [textarea.rows: IDL set to 0] expected: FAIL @@ -24261,189 +23901,6 @@ [textarea.inputMode: IDL set to "Kana-name"] expected: FAIL - [textarea.minLength: typeof IDL attribute] - expected: FAIL - - [textarea.minLength: IDL get with DOM attribute unset] - expected: FAIL - - [textarea.minLength: setAttribute() to -2147483649] - expected: FAIL - - [textarea.minLength: setAttribute() to -2147483648] - expected: FAIL - - [textarea.minLength: setAttribute() to -36] - expected: FAIL - - [textarea.minLength: setAttribute() to -1] - expected: FAIL - - [textarea.minLength: setAttribute() to -0] - expected: FAIL - - [textarea.minLength: setAttribute() to 0] - expected: FAIL - - [textarea.minLength: setAttribute() to 1] - expected: FAIL - - [textarea.minLength: setAttribute() to 2147483647] - expected: FAIL - - [textarea.minLength: setAttribute() to 2147483648] - expected: FAIL - - [textarea.minLength: setAttribute() to 4294967295] - expected: FAIL - - [textarea.minLength: setAttribute() to 4294967296] - expected: FAIL - - [textarea.minLength: setAttribute() to ""] - expected: FAIL - - [textarea.minLength: setAttribute() to "-1"] - expected: FAIL - - [textarea.minLength: setAttribute() to "-0"] - expected: FAIL - - [textarea.minLength: setAttribute() to "0"] - expected: FAIL - - [textarea.minLength: setAttribute() to "1"] - expected: FAIL - - [textarea.minLength: 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 "] - expected: FAIL - - [textarea.minLength: setAttribute() to "\\t7"] - expected: FAIL - - [textarea.minLength: setAttribute() to "\\v7"] - expected: FAIL - - [textarea.minLength: setAttribute() to "\\f7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to "7"] - expected: FAIL - - [textarea.minLength: setAttribute() to "\\n7"] - expected: FAIL - - [textarea.minLength: setAttribute() to "\\r7"] - expected: FAIL - - [textarea.minLength: setAttribute() to "
7"] - expected: FAIL - - [textarea.minLength: setAttribute() to "
7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to "᠎7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to " 7"] - expected: FAIL - - [textarea.minLength: setAttribute() to undefined] - expected: FAIL - - [textarea.minLength: setAttribute() to 1.5] - expected: FAIL - - [textarea.minLength: setAttribute() to true] - expected: FAIL - - [textarea.minLength: setAttribute() to false] - expected: FAIL - - [textarea.minLength: setAttribute() to object "[object Object\]"] - expected: FAIL - - [textarea.minLength: setAttribute() to NaN] - expected: FAIL - - [textarea.minLength: setAttribute() to Infinity] - expected: FAIL - - [textarea.minLength: setAttribute() to -Infinity] - expected: FAIL - - [textarea.minLength: setAttribute() to "\\0"] - expected: FAIL - - [textarea.minLength: setAttribute() to object "2"] - expected: FAIL - - [textarea.minLength: setAttribute() to object "3"] - expected: FAIL - - [textarea.minLength: IDL set to -2147483648] - expected: FAIL - - [textarea.minLength: IDL set to -36] - expected: FAIL - - [textarea.minLength: IDL set to -1] - expected: FAIL - - [textarea.minLength: IDL set to 0] - expected: FAIL - - [textarea.minLength: IDL set to 1] - expected: FAIL - - [textarea.minLength: IDL set to 2147483647] - expected: FAIL - [meter.value: typeof IDL attribute] expected: FAIL diff --git a/tests/wpt/web-platform-tests/html/semantics/forms/the-textarea-element/textarea-maxlength.html b/tests/wpt/web-platform-tests/html/semantics/forms/the-textarea-element/textarea-maxlength.html new file mode 100644 index 00000000000..ff4e8f1b65c --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/forms/the-textarea-element/textarea-maxlength.html @@ -0,0 +1,51 @@ + + + + + textarea maxlength + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/forms/the-textarea-element/textarea-minlength.html b/tests/wpt/web-platform-tests/html/semantics/forms/the-textarea-element/textarea-minlength.html new file mode 100644 index 00000000000..9a15a129392 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/forms/the-textarea-element/textarea-minlength.html @@ -0,0 +1,51 @@ + + + + + textarea minlength + + + + + + + + + + + + + + + + + + \ No newline at end of file