mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Move the definition of ServoThreadSafeLayoutNode::selection to script.
This commit is contained in:
parent
0f1f99a4bf
commit
093b7b7710
2 changed files with 19 additions and 11 deletions
|
@ -49,8 +49,6 @@ use script::dom::element::{Element, LayoutElementHelpers, RawLayoutElementHelper
|
|||
use script::dom::htmlcanvaselement::{LayoutHTMLCanvasElementHelpers, HTMLCanvasData};
|
||||
use script::dom::htmliframeelement::HTMLIFrameElement;
|
||||
use script::dom::htmlimageelement::LayoutHTMLImageElementHelpers;
|
||||
use script::dom::htmlinputelement::{HTMLInputElement, LayoutHTMLInputElementHelpers};
|
||||
use script::dom::htmltextareaelement::{HTMLTextAreaElement, LayoutHTMLTextAreaElementHelpers};
|
||||
use script::dom::node::{CAN_BE_FRAGMENTED, HAS_CHANGED, HAS_DIRTY_DESCENDANTS, IS_DIRTY};
|
||||
use script::dom::node::{LayoutNodeHelpers, Node, OpaqueStyleAndLayoutData};
|
||||
use script::dom::text::Text;
|
||||
|
@ -1142,15 +1140,10 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
|
|||
fn selection(&self) -> Option<Range<ByteIndex>> {
|
||||
let this = unsafe { self.get_jsmanaged() };
|
||||
|
||||
let selection = if let Some(area) = this.downcast::<HTMLTextAreaElement>() {
|
||||
unsafe { area.selection_for_layout() }
|
||||
} else if let Some(input) = this.downcast::<HTMLInputElement>() {
|
||||
unsafe { input.selection_for_layout() }
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
selection.map(|range| Range::new(ByteIndex(range.start as isize),
|
||||
ByteIndex(range.len() as isize)))
|
||||
this.selection().map(|range| {
|
||||
Range::new(ByteIndex(range.start as isize),
|
||||
ByteIndex(range.len() as isize))
|
||||
})
|
||||
}
|
||||
|
||||
fn image_url(&self) -> Option<Url> {
|
||||
|
|
|
@ -68,6 +68,7 @@ use std::cmp::max;
|
|||
use std::default::Default;
|
||||
use std::iter::{self, FilterMap, Peekable};
|
||||
use std::mem;
|
||||
use std::ops::Range;
|
||||
use string_cache::{Atom, Namespace, QualName};
|
||||
use style::selector_impl::ServoSelectorImpl;
|
||||
use util::thread_state;
|
||||
|
@ -960,6 +961,7 @@ pub trait LayoutNodeHelpers {
|
|||
unsafe fn init_style_and_layout_data(&self, OpaqueStyleAndLayoutData);
|
||||
|
||||
fn text_content(&self) -> String;
|
||||
fn selection(&self) -> Option<Range<usize>>;
|
||||
}
|
||||
|
||||
impl LayoutNodeHelpers for LayoutJS<Node> {
|
||||
|
@ -1067,6 +1069,19 @@ impl LayoutNodeHelpers for LayoutJS<Node> {
|
|||
|
||||
panic!("not text!")
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn selection(&self) -> Option<Range<usize>> {
|
||||
if let Some(area) = self.downcast::<HTMLTextAreaElement>() {
|
||||
return unsafe { area.selection_for_layout() };
|
||||
}
|
||||
|
||||
if let Some(input) = self.downcast::<HTMLInputElement>() {
|
||||
return unsafe { input.selection_for_layout() };
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue