aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-09-21 08:49:14 -0500
committerGitHub <noreply@github.com>2016-09-21 08:49:14 -0500
commitc0bcd6fa5ed183e9b4a2f6ead4926773dfb637f1 (patch)
tree1fc6dc87b0ad505db24482d180c306bbe0b8bf9c /components/script/dom
parent236c687b66ff47f68b4d469db6bc35cdf415fcbf (diff)
parent2cb5adf6c6bee44e6aac6b6e875a1cda7eb50c87 (diff)
downloadservo-c0bcd6fa5ed183e9b4a2f6ead4926773dfb637f1.tar.gz
servo-c0bcd6fa5ed183e9b4a2f6ead4926773dfb637f1.zip
Auto merge of #13315 - Phrohdoh:textinput-minlength-13313, r=ConnorGBrewster
Implement minlength attribute for text inputs <!-- Please describe your changes on the following line: --> **This is not ready to be merged: I need help writing tests as I am not familiar with the methods used in the `maxlength` tests (introduced in tests/unit/script/textinput.rs).** I also need to write the `minlength-manual` test. Closes #13313 This depends on #13314 (and includes the commit from it so will need to be rebased once that patch lands). I am just looking for a quick review to make sure I am on the right path. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #13313 <!-- Either: --> - [X] There ~~are~~ *will be* tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13315) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/htmlinputelement.rs31
-rw-r--r--components/script/dom/htmltextareaelement.rs2
-rw-r--r--components/script/dom/webidls/HTMLInputElement.webidl3
3 files changed, 32 insertions, 4 deletions
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index aded18162ba..d9cda98b284 100644
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -85,6 +85,7 @@ pub struct HTMLInputElement {
value_changed: Cell<bool>,
size: Cell<u32>,
maxlength: Cell<i32>,
+ minlength: Cell<i32>,
#[ignore_heap_size_of = "#7193"]
textinput: DOMRefCell<TextInput<IpcSender<ConstellationMsg>>>,
activation_state: DOMRefCell<InputActivationState>,
@@ -123,6 +124,7 @@ impl InputActivationState {
static DEFAULT_INPUT_SIZE: u32 = 20;
static DEFAULT_MAX_LENGTH: i32 = -1;
+static DEFAULT_MIN_LENGTH: i32 = -1;
impl HTMLInputElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLInputElement {
@@ -136,8 +138,14 @@ impl HTMLInputElement {
checked_changed: Cell::new(false),
value_changed: Cell::new(false),
maxlength: Cell::new(DEFAULT_MAX_LENGTH),
+ minlength: Cell::new(DEFAULT_MIN_LENGTH),
size: Cell::new(DEFAULT_INPUT_SIZE),
- textinput: DOMRefCell::new(TextInput::new(Single, DOMString::new(), chan, None, SelectionDirection::None)),
+ textinput: DOMRefCell::new(TextInput::new(Single,
+ DOMString::new(),
+ chan,
+ None,
+ None,
+ SelectionDirection::None)),
activation_state: DOMRefCell::new(InputActivationState::new()),
value_dirty: Cell::new(false),
filelist: MutNullableHeap::new(None),
@@ -479,6 +487,12 @@ impl HTMLInputElementMethods for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#dom-input-maxlength
make_limited_int_setter!(SetMaxLength, "maxlength", DEFAULT_MAX_LENGTH);
+ // https://html.spec.whatwg.org/multipage/#dom-input-minlength
+ make_int_getter!(MinLength, "minlength", DEFAULT_MIN_LENGTH);
+
+ // https://html.spec.whatwg.org/multipage/#dom-input-minlength
+ make_limited_int_setter!(SetMinLength, "minlength", DEFAULT_MIN_LENGTH);
+
// https://html.spec.whatwg.org/multipage/#dom-input-min
make_getter!(Min, "min");
@@ -993,7 +1007,19 @@ impl VirtualMethods for HTMLInputElement {
},
_ => panic!("Expected an AttrValue::Int"),
}
- }
+ },
+ &atom!("minlength") => {
+ match *attr.value() {
+ AttrValue::Int(_, value) => {
+ if value < 0 {
+ self.textinput.borrow_mut().min_length = None
+ } else {
+ self.textinput.borrow_mut().min_length = Some(value as usize)
+ }
+ },
+ _ => panic!("Expected an AttrValue::Int"),
+ }
+ },
&atom!("placeholder") => {
{
let mut placeholder = self.placeholder.borrow_mut();
@@ -1027,6 +1053,7 @@ impl VirtualMethods for HTMLInputElement {
&atom!("size") => AttrValue::from_limited_u32(value.into(), DEFAULT_INPUT_SIZE),
&atom!("type") => AttrValue::from_atomic(value.into()),
&atom!("maxlength") => AttrValue::from_limited_i32(value.into(), DEFAULT_MAX_LENGTH),
+ &atom!("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/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index b43f4f75d5c..3a4418d713d 100644
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -105,7 +105,7 @@ impl HTMLTextAreaElement {
HTMLElement::new_inherited_with_state(IN_ENABLED_STATE | IN_READ_WRITE_STATE,
local_name, prefix, document),
textinput: DOMRefCell::new(TextInput::new(
- Lines::Multiple, DOMString::new(), chan, None, SelectionDirection::None)),
+ Lines::Multiple, DOMString::new(), chan, None, None, SelectionDirection::None)),
value_changed: Cell::new(false),
}
}
diff --git a/components/script/dom/webidls/HTMLInputElement.webidl b/components/script/dom/webidls/HTMLInputElement.webidl
index 1d6160b14cd..5c644894bbf 100644
--- a/components/script/dom/webidls/HTMLInputElement.webidl
+++ b/components/script/dom/webidls/HTMLInputElement.webidl
@@ -27,7 +27,8 @@ interface HTMLInputElement : HTMLElement {
[SetterThrows]
attribute long maxLength;
attribute DOMString min;
- // attribute long minLength;
+ [SetterThrows]
+ attribute long minLength;
attribute boolean multiple;
attribute DOMString name;
attribute DOMString pattern;