mirror of
https://github.com/servo/servo.git
synced 2025-07-29 10:10:34 +01:00
textarea minLength/maxLength
This commit is contained in:
parent
440e855c33
commit
bdb6706f19
6 changed files with 173 additions and 549 deletions
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue