diff options
Diffstat (limited to 'src/components/script')
-rw-r--r-- | src/components/script/compositor_interface.rs | 4 | ||||
-rw-r--r-- | src/components/script/dom/event.rs | 2 | ||||
-rw-r--r-- | src/components/script/dom/window.rs | 14 | ||||
-rw-r--r-- | src/components/script/engine_interface.rs | 16 | ||||
-rw-r--r-- | src/components/script/layout_interface.rs | 19 | ||||
-rw-r--r-- | src/components/script/script_task.rs | 96 |
6 files changed, 91 insertions, 60 deletions
diff --git a/src/components/script/compositor_interface.rs b/src/components/script/compositor_interface.rs index 8e48e9f1492..b0041e49298 100644 --- a/src/components/script/compositor_interface.rs +++ b/src/components/script/compositor_interface.rs @@ -14,6 +14,8 @@ pub enum ReadyState { FinishedLoading, } -pub trait CompositorInterface : Clone { +/// The interface used by the script task to tell the compositor to update its ready state, +/// which is used in displaying the appropriate message in the window's title. +pub trait ScriptListener : Clone { fn set_ready_state(&self, ReadyState); } diff --git a/src/components/script/dom/event.rs b/src/components/script/dom/event.rs index 6c11bcd3411..6b4be15b701 100644 --- a/src/components/script/dom/event.rs +++ b/src/components/script/dom/event.rs @@ -10,7 +10,7 @@ use dom::bindings::utils::{DOMString, ErrorResult, WrapperCache}; use geom::point::Point2D; pub enum Event { - ResizeEvent(uint, uint, comm::Chan<()>), + ResizeEvent(uint, uint), ReflowEvent, ClickEvent(uint, Point2D<f32>), MouseDownEvent(uint, Point2D<f32>), diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index aa375a4d614..0c48008827d 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -6,9 +6,9 @@ use dom::bindings::utils::WrapperCache; use dom::bindings::window; use layout_interface::ReflowForScriptQuery; -use script_task::{ExitMsg, FireTimerMsg, ScriptMsg, ScriptContext}; +use script_task::{ExitMsg, FireTimerMsg, ScriptChan, ScriptContext}; -use core::comm::{Chan, SharedChan}; +use core::comm::Chan; use js::jsapi::JSVal; use std::timer; use std::uv_global_loop; @@ -23,7 +23,7 @@ pub enum TimerControlMsg { // only used for querying layout from arbitrary script. pub struct Window { timer_chan: Chan<TimerControlMsg>, - script_chan: SharedChan<ScriptMsg>, + script_chan: ScriptChan, script_context: *mut ScriptContext, wrapper: WrapperCache } @@ -88,9 +88,9 @@ pub impl Window { } } - pub fn new(script_chan: SharedChan<ScriptMsg>, script_context: *mut ScriptContext) + pub fn new(script_chan: ScriptChan, script_context: *mut ScriptContext) -> @mut Window { - let script_chan_copy = script_chan.clone(); + let script_chan_clone = script_chan.clone(); let win = @mut Window { wrapper: WrapperCache::new(), script_chan: script_chan, @@ -100,8 +100,8 @@ pub impl Window { loop { match timer_port.recv() { TimerMessage_Close => break, - TimerMessage_Fire(td) => script_chan_copy.send(FireTimerMsg(td)), - TimerMessage_TriggerExit => script_chan_copy.send(ExitMsg), + TimerMessage_Fire(td) => script_chan_clone.chan.send(FireTimerMsg(td)), + TimerMessage_TriggerExit => script_chan_clone.chan.send(ExitMsg), } } } diff --git a/src/components/script/engine_interface.rs b/src/components/script/engine_interface.rs index 2705ebdb137..c7a33334c97 100644 --- a/src/components/script/engine_interface.rs +++ b/src/components/script/engine_interface.rs @@ -8,7 +8,21 @@ use core::comm::{Chan, SharedChan}; use std::net::url::Url; -pub type EngineTask = SharedChan<Msg>; +#[deriving(Clone)] +pub struct EngineChan { + chan: SharedChan<Msg>, +} + +impl EngineChan { + pub fn new(chan: Chan<Msg>) -> EngineChan { + EngineChan { + chan: SharedChan::new(chan), + } + } + pub fn send(&self, msg: Msg) { + self.chan.send(msg); + } +} pub enum Msg { LoadUrlMsg(Url), diff --git a/src/components/script/layout_interface.rs b/src/components/script/layout_interface.rs index f9ab0a8eb2e..d4d0aef7cf3 100644 --- a/src/components/script/layout_interface.rs +++ b/src/components/script/layout_interface.rs @@ -7,7 +7,7 @@ /// from layout. use dom::node::{AbstractNode, ScriptView, LayoutView}; -use script_task::ScriptMsg; +use script_task::{ScriptMsg, ScriptChan}; use core::comm::{Chan, SharedChan}; use geom::rect::Rect; @@ -32,6 +32,9 @@ pub enum Msg { /// FIXME(pcwalton): As noted below, this isn't very type safe. QueryMsg(LayoutQuery, Chan<Result<LayoutResponse,()>>), + /// Routes a message (usually from the compositor) to the appropriate script task + RouteScriptMsg(ScriptMsg), + /// Requests that the layout task shut down and exit. ExitMsg, } @@ -110,7 +113,7 @@ pub struct Reflow { /// The URL of the page. url: Url, /// The channel through which messages can be sent back to the script task. - script_chan: SharedChan<ScriptMsg>, + script_chan: ScriptChan, /// The current window size. window_size: Size2D<uint>, /// The channel that we send a notification to. @@ -119,7 +122,17 @@ pub struct Reflow { /// Encapsulates a channel to the layout task. #[deriving(Clone)] -pub struct LayoutTask { +pub struct LayoutChan { chan: SharedChan<Msg>, } +impl LayoutChan { + pub fn new(chan: Chan<Msg>) -> LayoutChan { + LayoutChan { + chan: SharedChan::new(chan), + } + } + pub fn send(&self, msg: Msg) { + self.chan.send(msg); + } +} diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index 69890abb5cb..39ef337b2f1 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -13,11 +13,11 @@ use dom::event::{Event, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, Mo use dom::node::{AbstractNode, ScriptView, define_bindings}; use dom::window::Window; use layout_interface::{AddStylesheetMsg, DocumentDamage, DocumentDamageLevel, HitTestQuery}; -use layout_interface::{HitTestResponse, LayoutQuery, LayoutResponse, LayoutTask}; +use layout_interface::{HitTestResponse, LayoutQuery, LayoutResponse, LayoutChan}; use layout_interface::{MatchSelectorsDocumentDamage, QueryMsg, Reflow, ReflowDocumentDamage}; use layout_interface::{ReflowForDisplay, ReflowForScriptQuery, ReflowGoal, ReflowMsg}; use layout_interface; -use engine_interface::{EngineTask, LoadUrlMsg}; +use engine_interface::{EngineChan, LoadUrlMsg}; use core::cast::transmute; use core::cell::Cell; @@ -61,42 +61,22 @@ pub enum ScriptMsg { } /// Encapsulates external communication with the script task. -pub struct ScriptTask { +#[deriving(Clone)] +pub struct ScriptChan { /// The channel used to send messages to the script task. chan: SharedChan<ScriptMsg>, } -impl ScriptTask { +impl ScriptChan { /// Creates a new script task. - pub fn new(script_port: Port<ScriptMsg>, - script_chan: SharedChan<ScriptMsg>, - engine_task: EngineTask, - //FIXME(rust #5192): workaround for lack of working ~Trait - compositor_task: ~fn(ReadyState), - layout_task: LayoutTask, - resource_task: ResourceTask, - image_cache_task: ImageCacheTask) - -> ScriptTask { - let (script_chan_copy, script_port) = (script_chan.clone(), Cell(script_port)); - let compositor_task = Cell(compositor_task); - // FIXME: rust#6399 - let mut the_task = task(); - the_task.sched_mode(SingleThreaded); - do the_task.spawn { - let script_context = ScriptContext::new(layout_task.clone(), - script_port.take(), - script_chan_copy.clone(), - engine_task.clone(), - compositor_task.take(), - resource_task.clone(), - image_cache_task.clone()); - script_context.start(); - } - - ScriptTask { - chan: script_chan + pub fn new(chan: Chan<ScriptMsg>) -> ScriptChan { + ScriptChan { + chan: SharedChan::new(chan) } } + pub fn send(&self, msg: ScriptMsg) { + self.chan.send(msg); + } } /// Information for one frame in the browsing context. @@ -112,7 +92,7 @@ pub struct Frame { /// FIXME: Rename to `Page`, following WebKit? pub struct ScriptContext { /// A handle to the layout task. - layout_task: LayoutTask, + layout_chan: LayoutChan, /// A handle to the image cache task. image_cache_task: ImageCacheTask, /// A handle to the resource task. @@ -125,10 +105,10 @@ pub struct ScriptContext { script_port: Port<ScriptMsg>, /// A channel for us to hand out when we want some other task to be able to send us script /// messages. - script_chan: SharedChan<ScriptMsg>, + script_chan: ScriptChan, /// For communicating load url messages to the engine - engine_task: EngineTask, + engine_chan: EngineChan, /// For communicating loading messages to the compositor compositor_task: ~fn(ReadyState), @@ -180,10 +160,10 @@ impl Drop for ScriptContext { impl ScriptContext { /// Creates a new script context. - pub fn new(layout_task: LayoutTask, + pub fn new(layout_chan: LayoutChan, script_port: Port<ScriptMsg>, - script_chan: SharedChan<ScriptMsg>, - engine_task: EngineTask, + script_chan: ScriptChan, + engine_chan: EngineChan, compositor_task: ~fn(ReadyState), resource_task: ResourceTask, img_cache_task: ImageCacheTask) @@ -200,7 +180,7 @@ impl ScriptContext { }; let script_context = @mut ScriptContext { - layout_task: layout_task, + layout_chan: layout_chan, image_cache_task: img_cache_task, resource_task: resource_task, @@ -208,7 +188,7 @@ impl ScriptContext { script_port: script_port, script_chan: script_chan, - engine_task: engine_task, + engine_chan: engine_chan, compositor_task: compositor_task, js_runtime: js_runtime, @@ -245,6 +225,30 @@ impl ScriptContext { } } + pub fn create_script_context(layout_chan: LayoutChan, + script_port: Port<ScriptMsg>, + script_chan: ScriptChan, + engine_chan: EngineChan, + compositor_task: ~fn(ReadyState), + resource_task: ResourceTask, + image_cache_task: ImageCacheTask) { + let script_port = Cell(script_port); + let compositor_task = Cell(compositor_task); + // FIXME: rust#6399 + let mut the_task = task(); + the_task.sched_mode(SingleThreaded); + do the_task.spawn { + let script_context = ScriptContext::new(layout_chan.clone(), + script_port.take(), + script_chan.clone(), + engine_chan.clone(), + compositor_task.take(), + resource_task.clone(), + image_cache_task.clone()); + script_context.start(); + } + } + /// Handles an incoming control message. fn handle_msg(&mut self) -> bool { match self.script_port.recv() { @@ -325,7 +329,7 @@ impl ScriptContext { frame.document.teardown(); } - self.layout_task.chan.send(layout_interface::ExitMsg) + self.layout_chan.send(layout_interface::ExitMsg) } // tells the compositor when loading starts and finishes @@ -361,7 +365,7 @@ impl ScriptContext { // in the script task. loop { match html_parsing_result.style_port.recv() { - Some(sheet) => self.layout_task.chan.send(AddStylesheetMsg(sheet)), + Some(sheet) => self.layout_chan.send(AddStylesheetMsg(sheet)), None => break, } } @@ -457,7 +461,7 @@ impl ScriptContext { damage: replace(&mut self.damage, None).unwrap(), }; - self.layout_task.chan.send(ReflowMsg(reflow)) + self.layout_chan.send(ReflowMsg(reflow)) } } @@ -482,7 +486,7 @@ impl ScriptContext { self.join_layout(); let (response_port, response_chan) = comm::stream(); - self.layout_task.chan.send(QueryMsg(query, response_chan)); + self.layout_chan.send(QueryMsg(query, response_chan)); response_port.recv() } @@ -511,7 +515,7 @@ impl ScriptContext { /// TODO: Actually perform DOM event dispatch. fn handle_event(&mut self, event: Event) { match event { - ResizeEvent(new_width, new_height, response_chan) => { + ResizeEvent(new_width, new_height) => { debug!("script got resize event: %u, %u", new_width, new_height); self.window_size = Size2D(new_width, new_height); @@ -525,8 +529,6 @@ impl ScriptContext { if self.root_frame.is_some() { self.reflow(ReflowForDisplay) } - - response_chan.send(()) } // FIXME(pcwalton): This reflows the entire document and is not incremental-y. @@ -595,7 +597,7 @@ impl ScriptContext { None => None }; let url = make_url(attr.value.clone(), current_url); - self.engine_task.send(LoadUrlMsg(url)); + self.engine_chan.send(LoadUrlMsg(url)); } } } |