mirror of
https://github.com/servo/servo.git
synced 2025-08-01 11:40:30 +01:00
Make LayoutHTMLTextAreaElementHelpers::value_for_layout safe
This commit is contained in:
parent
e1e913d33c
commit
00c5ec202c
2 changed files with 13 additions and 14 deletions
|
@ -56,8 +56,7 @@ pub struct HTMLTextAreaElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LayoutHTMLTextAreaElementHelpers {
|
pub trait LayoutHTMLTextAreaElementHelpers {
|
||||||
#[allow(unsafe_code)]
|
fn value_for_layout(self) -> String;
|
||||||
unsafe fn value_for_layout(self) -> String;
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn selection_for_layout(self) -> Option<Range<usize>>;
|
unsafe fn selection_for_layout(self) -> Option<Range<usize>>;
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
@ -67,19 +66,19 @@ pub trait LayoutHTMLTextAreaElementHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> {
|
impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> {
|
||||||
#[allow(unrooted_must_root)]
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn value_for_layout(self) -> String {
|
fn value_for_layout(self) -> String {
|
||||||
let text = (*self.unsafe_get())
|
let text = unsafe {
|
||||||
|
self.unsafe_get()
|
||||||
.textinput
|
.textinput
|
||||||
.borrow_for_layout()
|
.borrow_for_layout()
|
||||||
.get_content();
|
.get_content()
|
||||||
|
};
|
||||||
if text.is_empty() {
|
if text.is_empty() {
|
||||||
(*self.unsafe_get())
|
let placeholder = unsafe { self.unsafe_get().placeholder.borrow_for_layout() };
|
||||||
.placeholder
|
// FIXME(nox): Would be cool to not allocate a new string if the
|
||||||
.borrow_for_layout()
|
// placeholder is single line, but that's an unimportant detail.
|
||||||
.replace("\r\n", "\n")
|
placeholder.replace("\r\n", "\n").replace("\r", "\n").into()
|
||||||
.replace("\r", "\n")
|
|
||||||
} else {
|
} else {
|
||||||
text.into()
|
text.into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1467,7 +1467,7 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(area) = self.downcast::<HTMLTextAreaElement>() {
|
if let Some(area) = self.downcast::<HTMLTextAreaElement>() {
|
||||||
return unsafe { area.value_for_layout() };
|
return area.value_for_layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
panic!("not text!")
|
panic!("not text!")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue