mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Properly handle CR in textarea placeholders (fixes #19717)
This commit is contained in:
parent
e2c89df8ee
commit
6f9003c052
3 changed files with 10 additions and 10 deletions
|
@ -50,7 +50,7 @@ pub struct HTMLTextAreaElement {
|
|||
|
||||
pub trait LayoutHTMLTextAreaElementHelpers {
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_value_for_layout(self) -> String;
|
||||
unsafe fn value_for_layout(self) -> String;
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn selection_for_layout(self) -> Option<Range<usize>>;
|
||||
#[allow(unsafe_code)]
|
||||
|
@ -62,13 +62,16 @@ pub trait LayoutHTMLTextAreaElementHelpers {
|
|||
impl LayoutHTMLTextAreaElementHelpers for LayoutDom<HTMLTextAreaElement> {
|
||||
#[allow(unrooted_must_root)]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_value_for_layout(self) -> String {
|
||||
unsafe fn value_for_layout(self) -> String {
|
||||
let text = (*self.unsafe_get()).textinput.borrow_for_layout().get_content();
|
||||
String::from(if text.is_empty() {
|
||||
(*self.unsafe_get()).placeholder.borrow_for_layout().clone()
|
||||
if text.is_empty() {
|
||||
(*self.unsafe_get()).placeholder
|
||||
.borrow_for_layout()
|
||||
.replace("\r\n", "\n")
|
||||
.replace("\r", "\n")
|
||||
} else {
|
||||
text
|
||||
})
|
||||
text.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
|
@ -138,7 +141,6 @@ impl HTMLTextAreaElement {
|
|||
let has_value = !self.textinput.borrow().is_empty();
|
||||
let el = self.upcast::<Element>();
|
||||
el.set_placeholder_shown_state(has_placeholder && !has_value);
|
||||
el.set_placeholder_shown_state(has_placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1140,7 +1140,7 @@ impl LayoutNodeHelpers for LayoutDom<Node> {
|
|||
}
|
||||
|
||||
if let Some(area) = self.downcast::<HTMLTextAreaElement>() {
|
||||
return unsafe { area.get_value_for_layout() };
|
||||
return unsafe { area.value_for_layout() };
|
||||
}
|
||||
|
||||
panic!("not text!")
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
[multiline-placeholder-cr.html]
|
||||
expected: FAIL
|
Loading…
Add table
Add a link
Reference in a new issue