mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Move unsafe code out of <LayoutDom<HTMLTextAreaElement>>::value_for_layout
This commit is contained in:
parent
f8af8176de
commit
4636507fa1
1 changed files with 19 additions and 10 deletions
|
@ -59,32 +59,41 @@ pub trait LayoutHTMLTextAreaElementHelpers {
|
||||||
fn value_for_layout(self) -> String;
|
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)]
|
|
||||||
fn get_cols(self) -> u32;
|
fn get_cols(self) -> u32;
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_rows(self) -> u32;
|
fn get_rows(self) -> u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> {
|
#[allow(unsafe_code)]
|
||||||
#[allow(unsafe_code)]
|
impl<'dom> LayoutDom<'dom, HTMLTextAreaElement> {
|
||||||
fn value_for_layout(self) -> String {
|
fn textinput_content(self) -> DOMString {
|
||||||
let text = unsafe {
|
unsafe {
|
||||||
self.unsafe_get()
|
self.unsafe_get()
|
||||||
.textinput
|
.textinput
|
||||||
.borrow_for_layout()
|
.borrow_for_layout()
|
||||||
.get_content()
|
.get_content()
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn placeholder(self) -> &'dom str {
|
||||||
|
unsafe { self.unsafe_get().placeholder.borrow_for_layout() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> {
|
||||||
|
fn value_for_layout(self) -> String {
|
||||||
|
let text = self.textinput_content();
|
||||||
if text.is_empty() {
|
if text.is_empty() {
|
||||||
let placeholder = unsafe { self.unsafe_get().placeholder.borrow_for_layout() };
|
|
||||||
// FIXME(nox): Would be cool to not allocate a new string if the
|
// FIXME(nox): Would be cool to not allocate a new string if the
|
||||||
// placeholder is single line, but that's an unimportant detail.
|
// placeholder is single line, but that's an unimportant detail.
|
||||||
placeholder.replace("\r\n", "\n").replace("\r", "\n").into()
|
self.placeholder()
|
||||||
|
.replace("\r\n", "\n")
|
||||||
|
.replace("\r", "\n")
|
||||||
|
.into()
|
||||||
} else {
|
} else {
|
||||||
text.into()
|
text.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn selection_for_layout(self) -> Option<Range<usize>> {
|
unsafe fn selection_for_layout(self) -> Option<Range<usize>> {
|
||||||
if !(*self.unsafe_get()).upcast::<Element>().focus_state() {
|
if !(*self.unsafe_get()).upcast::<Element>().focus_state() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue