Bug #3811 - Extracted the script task handlers into methods

This commit is contained in:
Shing Lyu 2014-11-06 18:16:45 +08:00
parent ffae110498
commit 783c6703ca

View file

@ -42,7 +42,7 @@ use script_traits::{CompositorEvent, ResizeEvent, ReflowEvent, ClickEvent, Mouse
use script_traits::{MouseMoveEvent, MouseUpEvent, ConstellationControlMsg, ScriptTaskFactory}; use script_traits::{MouseMoveEvent, MouseUpEvent, ConstellationControlMsg, ScriptTaskFactory};
use script_traits::{ResizeMsg, AttachLayoutMsg, LoadMsg, SendEventMsg, ResizeInactiveMsg}; use script_traits::{ResizeMsg, AttachLayoutMsg, LoadMsg, SendEventMsg, ResizeInactiveMsg};
use script_traits::{ExitPipelineMsg, NewLayoutInfo, OpaqueScriptLayoutChannel, ScriptControlChan}; use script_traits::{ExitPipelineMsg, NewLayoutInfo, OpaqueScriptLayoutChannel, ScriptControlChan};
use script_traits::ReflowCompleteMsg; use script_traits::{ReflowCompleteMsg, UntrustedNodeAddress};
use servo_msg::compositor_msg::{FinishedLoading, LayerId, Loading}; use servo_msg::compositor_msg::{FinishedLoading, LayerId, Loading};
use servo_msg::compositor_msg::{ScriptListener}; use servo_msg::compositor_msg::{ScriptListener};
use servo_msg::constellation_msg::{ConstellationChan, LoadCompleteMsg, LoadUrlMsg, NavigationDirection}; use servo_msg::constellation_msg::{ConstellationChan, LoadCompleteMsg, LoadUrlMsg, NavigationDirection};
@ -885,6 +885,47 @@ impl ScriptTask {
fn handle_event(&self, pipeline_id: PipelineId, event: CompositorEvent) { fn handle_event(&self, pipeline_id: PipelineId, event: CompositorEvent) {
match event { match event {
ResizeEvent(new_size) => { ResizeEvent(new_size) => {
self.handle_resize_event(pipeline_id, new_size);
}
// FIXME(pcwalton): This reflows the entire document and is not incremental-y.
ReflowEvent(to_dirty) => {
self.handle_reflow_event(pipeline_id, to_dirty);
}
ClickEvent(_button, point) => {
self.handle_click_event(pipeline_id, _button, point);
}
MouseDownEvent(..) => {}
MouseUpEvent(..) => {}
MouseMoveEvent(point) => {
self.handle_mouse_move_event(pipeline_id, point);
}
}
}
/// The entry point for content to notify that a new load has been requested
/// for the given pipeline.
fn trigger_load(&self, pipeline_id: PipelineId, load_data: LoadData) {
let ConstellationChan(ref const_chan) = self.constellation_chan;
const_chan.send(LoadUrlMsg(pipeline_id, load_data));
}
/// The entry point for content to notify that a fragment url has been requested
/// for the given pipeline.
fn trigger_fragment(&self, pipeline_id: PipelineId, url: Url) {
let page = get_page(&*self.page.borrow(), pipeline_id);
match page.find_fragment_node(url.fragment.unwrap()).root() {
Some(node) => {
self.scroll_fragment_point(pipeline_id, *node);
}
None => {}
}
}
fn handle_resize_event(&self, pipeline_id: PipelineId, new_size: WindowSizeData) {
debug!("script got resize event: {:?}", new_size); debug!("script got resize event: {:?}", new_size);
let window = { let window = {
@ -927,8 +968,7 @@ impl ScriptTask {
} }
} }
// FIXME(pcwalton): This reflows the entire document and is not incremental-y. fn handle_reflow_event(&self, pipeline_id: PipelineId, to_dirty: SmallVec1<UntrustedNodeAddress>) {
ReflowEvent(to_dirty) => {
debug!("script got reflow event"); debug!("script got reflow event");
assert_eq!(to_dirty.len(), 0); assert_eq!(to_dirty.len(), 0);
let page = get_page(&*self.page.borrow(), pipeline_id); let page = get_page(&*self.page.borrow(), pipeline_id);
@ -943,7 +983,7 @@ impl ScriptTask {
} }
} }
ClickEvent(_button, point) => { fn handle_click_event(&self, pipeline_id: PipelineId, _button: uint, point: Point2D<f32>) {
debug!("ClickEvent: clicked at {:?}", point); debug!("ClickEvent: clicked at {:?}", point);
let page = get_page(&*self.page.borrow(), pipeline_id); let page = get_page(&*self.page.borrow(), pipeline_id);
match page.hit_test(&point) { match page.hit_test(&point) {
@ -987,9 +1027,9 @@ impl ScriptTask {
None => {} None => {}
} }
} }
MouseDownEvent(..) => {}
MouseUpEvent(..) => {}
MouseMoveEvent(point) => { fn handle_mouse_move_event(&self, pipeline_id: PipelineId, point: Point2D<f32>) {
let page = get_page(&*self.page.borrow(), pipeline_id); let page = get_page(&*self.page.borrow(), pipeline_id);
match page.get_nodes_under_mouse(&point) { match page.get_nodes_under_mouse(&point) {
Some(node_address) => { Some(node_address) => {
@ -1049,27 +1089,6 @@ impl ScriptTask {
} }
} }
None => {}
}
}
}
}
/// The entry point for content to notify that a new load has been requested
/// for the given pipeline.
fn trigger_load(&self, pipeline_id: PipelineId, load_data: LoadData) {
let ConstellationChan(ref const_chan) = self.constellation_chan;
const_chan.send(LoadUrlMsg(pipeline_id, load_data));
}
/// The entry point for content to notify that a fragment url has been requested
/// for the given pipeline.
fn trigger_fragment(&self, pipeline_id: PipelineId, url: Url) {
let page = get_page(&*self.page.borrow(), pipeline_id);
match page.find_fragment_node(url.fragment.unwrap()).root() {
Some(node) => {
self.scroll_fragment_point(pipeline_id, *node);
}
None => {} None => {}
} }
} }
@ -1117,3 +1136,4 @@ fn get_page(page: &Rc<Page>, pipeline_id: PipelineId) -> Rc<Page> {
message for a layout channel that is not associated with this script task.\ message for a layout channel that is not associated with this script task.\
This is a bug.") This is a bug.")
} }