diff options
author | Anthony Ramine <nox@nox.paris> | 2020-04-01 11:35:07 +0200 |
---|---|---|
committer | Anthony Ramine <nox@nox.paris> | 2020-04-01 11:40:56 +0200 |
commit | d9e4f7a0ba3f5853174d1aa0185932de9cb5ae06 (patch) | |
tree | 8c8e31d12678a36e692b3271025984614fd1a3aa /components/script/dom/htmltextareaelement.rs | |
parent | 28e5abe60667653464336ce04a274a907c807d83 (diff) | |
download | servo-d9e4f7a0ba3f5853174d1aa0185932de9cb5ae06.tar.gz servo-d9e4f7a0ba3f5853174d1aa0185932de9cb5ae06.zip |
Introduce more layout helpers to make selection_for_layout be safe
Diffstat (limited to 'components/script/dom/htmltextareaelement.rs')
-rwxr-xr-x | components/script/dom/htmltextareaelement.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 1cfd6903302..38fa642ca4c 100755 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -57,8 +57,7 @@ pub struct HTMLTextAreaElement { pub trait LayoutHTMLTextAreaElementHelpers { fn value_for_layout(self) -> String; - #[allow(unsafe_code)] - unsafe fn selection_for_layout(self) -> Option<Range<usize>>; + fn selection_for_layout(self) -> Option<Range<usize>>; fn get_cols(self) -> u32; fn get_rows(self) -> u32; } @@ -74,6 +73,15 @@ impl<'dom> LayoutDom<'dom, HTMLTextAreaElement> { } } + fn textinput_sorted_selection_offsets_range(self) -> Range<UTF8Bytes> { + unsafe { + self.unsafe_get() + .textinput + .borrow_for_layout() + .sorted_selection_offsets_range() + } + } + fn placeholder(self) -> &'dom str { unsafe { self.unsafe_get().placeholder.borrow_for_layout() } } @@ -94,14 +102,12 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> { } } - #[allow(unsafe_code)] - unsafe fn selection_for_layout(self) -> Option<Range<usize>> { + fn selection_for_layout(self) -> Option<Range<usize>> { if !self.upcast::<Element>().focus_state() { return None; } - let textinput = (*self.unsafe_get()).textinput.borrow_for_layout(); Some(UTF8Bytes::unwrap_range( - textinput.sorted_selection_offsets_range(), + self.textinput_sorted_selection_offsets_range(), )) } |