Auto merge of #9072 - Manishearth:password-placeholder, r=eefriedman

Fix placeholders for password inputs

currently they show dots instead of the placeholder text

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9072)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-01-03 10:21:26 +05:30
commit 7f156b8c12
5 changed files with 78 additions and 11 deletions

View file

@ -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())
}
},
}
}

View file

@ -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;

View file

@ -2419,6 +2419,30 @@
"url": "/_mozilla/css/input_height_a.html"
}
],
"css/input_placeholder.html": [
{
"path": "css/input_placeholder.html",
"references": [
[
"/_mozilla/css/input_placeholder_ref.html",
"=="
]
],
"url": "/_mozilla/css/input_placeholder.html"
}
],
"css/input_placeholder_ref.html": [
{
"path": "css/input_placeholder_ref.html",
"references": [
[
"/_mozilla/css/input_placeholder_ref.html",
"=="
]
],
"url": "/_mozilla/css/input_placeholder_ref.html"
}
],
"css/inset.html": [
{
"path": "css/inset.html",
@ -8328,6 +8352,30 @@
"url": "/_mozilla/css/input_height_a.html"
}
],
"css/input_placeholder.html": [
{
"path": "css/input_placeholder.html",
"references": [
[
"/_mozilla/css/input_placeholder_ref.html",
"=="
]
],
"url": "/_mozilla/css/input_placeholder.html"
}
],
"css/input_placeholder_ref.html": [
{
"path": "css/input_placeholder_ref.html",
"references": [
[
"/_mozilla/css/input_placeholder_ref.html",
"=="
]
],
"url": "/_mozilla/css/input_placeholder_ref.html"
}
],
"css/inset.html": [
{
"path": "css/inset.html",

View file

@ -0,0 +1,5 @@
<!doctype html>
<meta charset="utf-8">
<title></title>
<link rel="match" href="input_placeholder_ref.html">
<input type=text placeholder="foo bar"><input type=text placeholder="foo bar">

View file

@ -0,0 +1,5 @@
<!doctype html>
<meta charset="utf-8">
<title></title>
<link rel="match" href="input_placeholder_ref.html">
<input type=text value="foo bar"><input type=text value="foo bar">