mirror of
https://github.com/servo/servo.git
synced 2025-06-09 09:03:23 +00:00
Move placeholder logic out of get_raw_textinput_value
This commit is contained in:
parent
728ec11628
commit
cc5844a373
1 changed files with 19 additions and 12 deletions
|
@ -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())
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue