mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Introduce more layout helpers to make selection_for_layout be safe
This commit is contained in:
parent
28e5abe606
commit
d9e4f7a0ba
3 changed files with 30 additions and 18 deletions
|
@ -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(),
|
||||
))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue