servo: Merge #9072 - Fix placeholders for password inputs (from Manishearth:password-placeholder); r=eefriedman

currently they show dots instead of the placeholder text

Source-Repo: https://github.com/servo/servo
Source-Revision: 7f156b8c12833e9134d29c4c309963eaa48c4ce1
This commit is contained in:
Manish Goregaokar 2016-01-03 09:52:26 +05:01
Родитель 38405ee47e
Коммит e927e712c3
2 изменённых файлов: 20 добавлений и 11 удалений

Просмотреть файл

@ -157,12 +157,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() {
textinput
} else {
(*input.unsafe_get()).placeholder.borrow_for_layout().clone()
}
(*input.unsafe_get()).textinput.borrow_for_layout().get_content()
}
impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
@ -184,11 +179,23 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
InputType::InputSubmit => get_raw_attr_value(self, DEFAULT_SUBMIT_VALUE),
InputType::InputReset => get_raw_attr_value(self, DEFAULT_RESET_VALUE),
InputType::InputPassword => {
let raw = get_raw_textinput_value(self);
// The implementation of get_insertion_point_index_for_layout expects a 1:1 mapping of chars.
raw.chars().map(|_| '●').collect()
}
_ => String::from(get_raw_textinput_value(self)),
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())
}
},
}
}

Просмотреть файл

@ -14,6 +14,8 @@
<div><input type="submit"><input type="reset"><div>
<div><input id=ch type="checkbox" checked></div>
<div><input id=unch type="checkbox"></div>
<div><input type="text" size="30" placeholder="this is a placeholder"></div>
<div><input type="password" size="30" placeholder="this is a password placeholder"></div>
<script>
document.getElementById("ch").indeterminate = true;
document.getElementById("unch").indeterminate = true;