aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-12-28 17:15:56 +0530
committerManish Goregaokar <manishsmail@gmail.com>2016-01-03 09:47:30 +0530
commitcc5844a373c3d09a29b73a2e47ad8adee7f28d4c (patch)
tree32fde1b5f0396d9b9b583f09cfd4a0163c265137 /components/script/dom
parent728ec11628e389ce7ee20ee6cd8bac4e0ef13244 (diff)
downloadservo-cc5844a373c3d09a29b73a2e47ad8adee7f28d4c.tar.gz
servo-cc5844a373c3d09a29b73a2e47ad8adee7f28d4c.zip
Move placeholder logic out of get_raw_textinput_value
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/htmlinputelement.rs31
1 files changed, 19 insertions, 12 deletions
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index bc90edae19e..611c1082fc4 100644
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -154,17 +154,7 @@ pub trait LayoutHTMLInputElementHelpers {
#[allow(unsafe_code)]
unsafe fn get_raw_textinput_value(input: LayoutJS<HTMLInputElement>) -> DOMString {
- let textinput = (*input.unsafe_get()).textinput.borrow_for_layout().get_content();
- if !textinput.is_empty() {
- if let InputType::InputPassword = (*input.unsafe_get()).input_type.get() {
- // The implementation of get_insertion_point_index_for_layout expects a 1:1 mapping of chars.
- DOMString::from(textinput.chars().map(|_| '●').collect::<String>())
- } else {
- textinput
- }
- } else {
- (*input.unsafe_get()).placeholder.borrow_for_layout().clone()
- }
+ (*input.unsafe_get()).textinput.borrow_for_layout().get_content()
}
impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
@@ -185,7 +175,24 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
InputType::InputButton => get_raw_attr_value(self, ""),
InputType::InputSubmit => get_raw_attr_value(self, DEFAULT_SUBMIT_VALUE),
InputType::InputReset => get_raw_attr_value(self, DEFAULT_RESET_VALUE),
- _ => String::from(get_raw_textinput_value(self)),
+ InputType::InputPassword => {
+ let text = get_raw_textinput_value(self);
+ if !text.is_empty() {
+ // The implementation of get_insertion_point_index_for_layout expects a 1:1 mapping of chars.
+ text.chars().map(|_| '●').collect()
+ } else {
+ String::from((*self.unsafe_get()).placeholder.borrow_for_layout().clone())
+ }
+ },
+ _ => {
+ let text = get_raw_textinput_value(self);
+ if !text.is_empty() {
+ // The implementation of get_insertion_point_index_for_layout expects a 1:1 mapping of chars.
+ String::from(text)
+ } else {
+ String::from((*self.unsafe_get()).placeholder.borrow_for_layout().clone())
+ }
+ },
}
}