textarea minLength/maxLength

This commit is contained in:
tigercosmos 2018-06-17 06:33:22 -07:00
parent 440e855c33
commit bdb6706f19
6 changed files with 173 additions and 549 deletions

View file

@ -105,10 +105,13 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutDom<HTMLTextAreaElement> {
}
// 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),
}
}

View file

@ -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;

View file

@ -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"

View file

@ -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 "ana-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

View file

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<title>textarea maxlength</title>
<link rel="author" title="tigercosmos" href="mailto:phy.tiger@gmail.com">
<link rel=help href="https://html.spec.whatwg.org/multipage/#attr-textarea-maxlength">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<textarea id="none"></textarea>
<textarea id="negative" maxlength="-5"></textarea>
<textarea id="non-numeric" maxlength="not-a-number"></textarea>
<textarea id="assign-negative"></textarea>
<textarea id="assign-non-numeric"></textarea>
<script>
test(
function () {
assert_equals(document.getElementById("none").maxLength, -1);
}, "Unset maxlength is -1");
test(
function () {
assert_equals(document.getElementById("negative").maxLength, -1);
}, "Negative maxlength is always -1");
test(
function () {
assert_equals(document.getElementById("non-numeric").maxLength, -1);
}, "Non-numeric maxlength is -1");
test(
function () {
assert_throws("INDEX_SIZE_ERR", function () {
document.getElementById("assign-negative").maxLength = -5;
});
}, "Assigning negative integer throws IndexSizeError");
test(
function () {
document.getElementById("assign-non-numeric").maxLength = "not-a-number";
assert_equals(document.getElementById("assign-non-numeric").maxLength, 0);
}, "Assigning non-numeric to maxlength sets maxlength to 0");
</script>
</body>
</html>

View file

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<title>textarea minlength</title>
<link rel="author" title="tigercosmos" href="mailto:phy.tiger@gmail.com">
<link rel=help href="https://html.spec.whatwg.org/multipage/#attr-textarea-minlength">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<textarea id="none"></textarea>
<textarea id="negative" minlength=-5></textarea>
<textarea id="non-numeric" minlength="not-a-number"></textarea>
<textarea id="assign-negative"></textarea>
<textarea id="assign-non-numeric"></textarea>
<script>
test(
function () {
assert_equals(document.getElementById("none").minLength, -1);
}, "Unset minlength is -1");
test(
function () {
assert_equals(document.getElementById("negative").minLength, -1);
}, "Negative minlength is always -1");
test(
function () {
assert_equals(document.getElementById("non-numeric").minLength, -1);
}, "Non-numeric minlength is -1");
test(
function () {
assert_throws("INDEX_SIZE_ERR", function () {
document.getElementById("assign-negative").minLength = -5;
});
}, "Assigning negative integer throws IndexSizeError");
test(
function () {
document.getElementById("assign-non-numeric").minLength = "not-a-number";
assert_equals(document.getElementById("assign-non-numeric").minLength, 0);
}, "Assigning non-numeric to minlength sets minlength to 0");
</script>
</body>
</html>