aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/htmlinputelement.rs34
-rw-r--r--components/script/dom/htmltextareaelement.rs4
-rw-r--r--components/script/dom/webidls/HTMLInputElement.webidl2
3 files changed, 36 insertions, 4 deletions
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index 524f70e1288..554030c288a 100644
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -8,8 +8,8 @@ use dom::attr::{Attr, AttrValue};
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
-use dom::bindings::codegen::Bindings::HTMLInputElementBinding;
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
+use dom::bindings::codegen::Bindings::HTMLInputElementBinding;
use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods;
use dom::bindings::global::GlobalRef;
use dom::bindings::inheritance::Castable;
@@ -32,6 +32,7 @@ use msg::constellation_msg::ScriptMsg as ConstellationMsg;
use selectors::states::*;
use std::borrow::ToOwned;
use std::cell::Cell;
+use std::i32;
use string_cache::Atom;
use textinput::KeyReaction::{DispatchInput, Nothing, RedrawSelection, TriggerDefaultAction};
use textinput::Lines::Single;
@@ -116,7 +117,7 @@ impl HTMLInputElement {
checked_changed: Cell::new(false),
value_changed: Cell::new(false),
size: Cell::new(DEFAULT_INPUT_SIZE),
- textinput: DOMRefCell::new(TextInput::new(Single, DOMString::new(), chan)),
+ textinput: DOMRefCell::new(TextInput::new(Single, DOMString::new(), chan, None)),
activation_state: DOMRefCell::new(InputActivationState::new())
}
}
@@ -337,6 +338,21 @@ impl HTMLInputElementMethods for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#dom-input-formtarget
make_setter!(SetFormTarget, "formtarget");
+ // https://html.spec.whatwg.org/multipage/#dom-input-maxlength
+ fn MaxLength(&self) -> i32 {
+ match self.textinput.borrow().max_length {
+ Some(max_length) => max_length as i32,
+ None => i32::MAX
+ }
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-input-maxlength
+ fn SetMaxLength(&self, max_length: i32) {
+ if max_length > 0 {
+ self.textinput.borrow_mut().max_length = Some(max_length as usize)
+ }
+ }
+
// https://html.spec.whatwg.org/multipage/#dom-input-indeterminate
fn Indeterminate(&self) -> bool {
self.upcast::<Element>().get_state().contains(IN_INDETERMINATE_STATE)
@@ -511,6 +527,7 @@ impl VirtualMethods for HTMLInputElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
+
match attr.local_name() {
&atom!("disabled") => {
let disabled_state = match mutation {
@@ -581,6 +598,18 @@ impl VirtualMethods for HTMLInputElement {
self.radio_group_updated(
mutation.new_value(attr).as_ref().map(|name| name.as_atom()));
},
+ &atom!("maxlength") => {
+ match *attr.value() {
+ AttrValue::Int(_, value) => {
+ if value < 0 {
+ self.textinput.borrow_mut().max_length = None
+ } else {
+ self.textinput.borrow_mut().max_length = Some(value as usize)
+ }
+ },
+ _ => panic!("Expected an AttrValue::UInt"),
+ }
+ }
&atom!("placeholder") => {
// FIXME(ajeffrey): Should we do in-place mutation of the placeholder?
let mut placeholder = self.placeholder.borrow_mut();
@@ -599,6 +628,7 @@ impl VirtualMethods for HTMLInputElement {
&atom!("name") => AttrValue::from_atomic(value),
&atom!("size") => AttrValue::from_limited_u32(value, DEFAULT_INPUT_SIZE),
&atom!("type") => AttrValue::from_atomic(value),
+ &atom!("maxlength") => AttrValue::from_i32(value, i32::MAX),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index d4e1729f662..94057d4eee0 100644
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -30,6 +30,7 @@ use script_task::ScriptTaskEventCategory::InputEvent;
use script_task::{CommonScriptMsg, Runnable};
use selectors::states::*;
use std::cell::Cell;
+use std::i32;
use string_cache::Atom;
use textinput::{KeyReaction, Lines, TextInput};
use util::str::DOMString;
@@ -89,6 +90,7 @@ impl<'a> RawLayoutHTMLTextAreaElementHelpers for &'a HTMLTextAreaElement {
static DEFAULT_COLS: u32 = 20;
static DEFAULT_ROWS: u32 = 2;
+static DEFAULT_MAX_LENGTH: i32 = i32::MAX;
impl HTMLTextAreaElement {
fn new_inherited(localName: DOMString,
@@ -99,7 +101,7 @@ impl HTMLTextAreaElement {
htmlelement:
HTMLElement::new_inherited_with_state(IN_ENABLED_STATE,
localName, prefix, document),
- textinput: DOMRefCell::new(TextInput::new(Lines::Multiple, DOMString::new(), chan)),
+ textinput: DOMRefCell::new(TextInput::new(Lines::Multiple, DOMString::new(), chan, None)),
cols: Cell::new(DEFAULT_COLS),
rows: Cell::new(DEFAULT_ROWS),
value_changed: Cell::new(false),
diff --git a/components/script/dom/webidls/HTMLInputElement.webidl b/components/script/dom/webidls/HTMLInputElement.webidl
index a5472818afe..b2b7992f5e0 100644
--- a/components/script/dom/webidls/HTMLInputElement.webidl
+++ b/components/script/dom/webidls/HTMLInputElement.webidl
@@ -25,7 +25,7 @@ interface HTMLInputElement : HTMLElement {
// attribute DOMString inputMode;
//readonly attribute HTMLElement? list;
// attribute DOMString max;
- // attribute long maxLength;
+ attribute long maxLength;
// attribute DOMString min;
// attribute long minLength;
// attribute boolean multiple;