зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #19727 - Properly handle CR in textarea placeholders (fixes #19717) (from nox:cr-placeholder); r=emilio
Source-Repo: https://github.com/servo/servo Source-Revision: 2065fa6da23c304093b0fdbbf7c068e0b0c67366 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 25a0a5700a81ef4eaf1bbd56035434758c5987f4
This commit is contained in:
Родитель
bc628a0f94
Коммит
8e84d8fe5c
|
@ -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!")
|
||||
|
|
Загрузка…
Ссылка в новой задаче