Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the amount of dom code used outside the script crate. #11656

Merged
merged 8 commits into from Jun 7, 2016
Next

Move the definition of ServoThreadSafeLayoutNode::selection to script.

  • Loading branch information
Ms2ger committed Jun 7, 2016
commit 093b7b7710a71955ccce8bef74c39178f378116b
@@ -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
}
}


ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.