diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-04-04 08:24:48 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-04-04 08:24:48 -0600 |
commit | 4ffeb81aa73fa87120eabb569fd14d7193813bdf (patch) | |
tree | 1bc52b544701f337d69ccb1c6f9e3c214592eca3 /components/script/dom | |
parent | db104b738e1ff6b69c3983be6f50f8d7a048b182 (diff) | |
parent | 29387f6c4c10fa653abd92b4b03bf2a4d53e9bf2 (diff) | |
download | servo-4ffeb81aa73fa87120eabb569fd14d7193813bdf.tar.gz servo-4ffeb81aa73fa87120eabb569fd14d7193813bdf.zip |
auto merge of #5385 : genkku/servo/placeholder, r=jdm
I'm unsure whether I should wrap 'placeholder' in Cell, or DomRefCell, or leave as it is now.
Also, the spec says that the placeholder should be presented with line breaks stripped off,
should it be done in this stage?
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/htmlinputelement.rs | 25 | ||||
-rw-r--r-- | components/script/dom/webidls/HTMLInputElement.webidl | 2 |
2 files changed, 25 insertions, 2 deletions
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 46e841e79f8..e4ebabb9e13 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -65,6 +65,7 @@ pub struct HTMLInputElement { input_type: Cell<InputType>, checked: Cell<bool>, checked_changed: Cell<bool>, + placeholder: DOMRefCell<DOMString>, indeterminate: Cell<bool>, value_changed: Cell<bool>, size: Cell<u32>, @@ -112,6 +113,7 @@ impl HTMLInputElement { htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLInputElement, localName, prefix, document), input_type: Cell::new(InputType::InputText), checked: Cell::new(false), + placeholder: DOMRefCell::new("".to_owned()), indeterminate: Cell::new(false), checked_changed: Cell::new(false), value_changed: Cell::new(false), @@ -150,7 +152,12 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> { unsafe fn get_value_for_layout(self) -> String { #[allow(unsafe_code)] unsafe fn get_raw_textinput_value(input: LayoutJS<HTMLInputElement>) -> String { - (*input.unsafe_get()).textinput.borrow_for_layout().get_content() + let textinput = (*input.unsafe_get()).textinput.borrow_for_layout().get_content(); + if !textinput.is_empty() { + textinput + } else { + (*input.unsafe_get()).placeholder.borrow_for_layout().to_owned() + } } #[allow(unsafe_code)] @@ -274,6 +281,12 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> { // https://html.spec.whatwg.org/multipage/forms.html#attr-fe-name make_setter!(SetName, "name"); + // https://html.spec.whatwg.org/multipage/forms.html#attr-input-placeholder + make_getter!(Placeholder); + + // https://html.spec.whatwg.org/multipage/forms.html#attr-input-placeholder + make_setter!(SetPlaceholder, "placeholder"); + // https://html.spec.whatwg.org/multipage/forms.html#dom-input-formaction make_url_or_base_getter!(FormAction); @@ -490,6 +503,13 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { self.radio_group_updated(Some(value.as_slice())); } } + _ if attr.local_name() == &Atom::from_slice("placeholder") => { + let value = attr.value(); + let stripped = value.as_slice().chars() + .filter(|&c| c != '\n' && c != '\r') + .collect::<String>(); + *self.placeholder.borrow_mut() = stripped; + } _ => () } } @@ -534,6 +554,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { self.radio_group_updated(None); } } + _ if attr.local_name() == &Atom::from_slice("placeholder") => { + self.placeholder.borrow_mut().clear(); + } _ => () } } diff --git a/components/script/dom/webidls/HTMLInputElement.webidl b/components/script/dom/webidls/HTMLInputElement.webidl index 47180432736..f08f2334fbb 100644 --- a/components/script/dom/webidls/HTMLInputElement.webidl +++ b/components/script/dom/webidls/HTMLInputElement.webidl @@ -31,7 +31,7 @@ interface HTMLInputElement : HTMLElement { // attribute boolean multiple; attribute DOMString name; // attribute DOMString pattern; - // attribute DOMString placeholder; + attribute DOMString placeholder; attribute boolean readOnly; // attribute boolean required; attribute unsigned long size; |