diff options
author | Anthony Ramine <nox@nox.paris> | 2020-04-01 00:02:37 +0200 |
---|---|---|
committer | Anthony Ramine <nox@nox.paris> | 2020-04-01 11:40:55 +0200 |
commit | 4636507fa1f218d4c0d858089946b3e6f9b9aabc (patch) | |
tree | 6bbfa05f670e2034e340bd9ddab696962e4d55da /components/script/dom/htmltextareaelement.rs | |
parent | f8af8176dedd87de86c61ff05b4026ad32ebe86c (diff) | |
download | servo-4636507fa1f218d4c0d858089946b3e6f9b9aabc.tar.gz servo-4636507fa1f218d4c0d858089946b3e6f9b9aabc.zip |
Move unsafe code out of <LayoutDom<HTMLTextAreaElement>>::value_for_layout
Diffstat (limited to 'components/script/dom/htmltextareaelement.rs')
-rwxr-xr-x | components/script/dom/htmltextareaelement.rs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 248dfa33047..1e1e04ee4cb 100755 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -59,32 +59,41 @@ pub trait LayoutHTMLTextAreaElementHelpers { fn value_for_layout(self) -> String; #[allow(unsafe_code)] unsafe fn selection_for_layout(self) -> Option<Range<usize>>; - #[allow(unsafe_code)] fn get_cols(self) -> u32; - #[allow(unsafe_code)] fn get_rows(self) -> u32; } -impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> { - #[allow(unsafe_code)] - fn value_for_layout(self) -> String { - let text = unsafe { +#[allow(unsafe_code)] +impl<'dom> LayoutDom<'dom, HTMLTextAreaElement> { + fn textinput_content(self) -> DOMString { + unsafe { self.unsafe_get() .textinput .borrow_for_layout() .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() { - let placeholder = unsafe { self.unsafe_get().placeholder.borrow_for_layout() }; // FIXME(nox): Would be cool to not allocate a new string if the // 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 { text.into() } } - #[allow(unrooted_must_root)] #[allow(unsafe_code)] unsafe fn selection_for_layout(self) -> Option<Range<usize>> { if !(*self.unsafe_get()).upcast::<Element>().focus_state() { |