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

Eliminate the somewhat arbitrary distinction between "control messages" and "events" #458

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -3,8 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use compositing::resize_rate_limiter::ResizeRateLimiter;
use dom::event::Event;
use platform::{Application, Window};
use scripting::script_task::ControlMsg;
use windowing::{ApplicationMethods, WindowMethods};

use azure::azure_hl::{BackendType, B8G8R8A8, DataSourceSurface, DrawTarget, SourceSurfaceMethods};
@@ -30,11 +30,11 @@ pub struct CompositorImpl {

impl CompositorImpl {
/// Creates a new compositor instance.
pub fn new(dom_event_chan: SharedChan<Event>, opts: Opts) -> CompositorImpl {
let dom_event_chan = Cell(dom_event_chan);
pub fn new(control_chan: SharedChan<ControlMsg>, opts: Opts) -> CompositorImpl {
let control_chan = Cell(control_chan);
let chan: Chan<Msg> = do on_osmain |port| {
debug!("preparing to enter main loop");
mainloop(port, dom_event_chan.take(), &opts);
mainloop(port, control_chan.take(), &opts);
};

CompositorImpl {
@@ -76,7 +76,7 @@ impl layers::layers::ImageData for AzureDrawTargetImageData {
}
}

fn mainloop(po: Port<Msg>, dom_event_chan: SharedChan<Event>, opts: &Opts) {
fn mainloop(po: Port<Msg>, control_chan: SharedChan<ControlMsg>, opts: &Opts) {
let key_handlers: @mut ~[Chan<()>] = @mut ~[];

let app: Application = ApplicationMethods::new();
@@ -110,7 +110,7 @@ fn mainloop(po: Port<Msg>, dom_event_chan: SharedChan<Event>, opts: &Opts) {
identity());

let done = @mut false;
let resize_rate_limiter = @mut ResizeRateLimiter(dom_event_chan);
let resize_rate_limiter = @mut ResizeRateLimiter(control_chan);
let check_for_messages: @fn() = || {
// Periodically check if the script task responded to our last resize event
resize_rate_limiter.check_resize_response();
@@ -2,27 +2,28 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*!
A little class that rate limits the number of resize events sent to the script task
based on how fast script dispatches those events. It waits until each event is handled
before sending the next. If the window is resized multiple times before an event is handled
then some events will never be sent.
*/
//! A little class that rate limits the number of resize events sent to the script task
/// based on how fast script dispatches those events. It waits until each event is handled
/// before sending the next. If the window is resized multiple times before an event is handled
/// then some events will never be sent.

use dom::event::{Event, ResizeEvent};
use dom::event::ResizeEvent;
use scripting::script_task::{ControlMsg, SendEventMsg};

use core::comm::{Port, SharedChan};

pub struct ResizeRateLimiter {
/// The channel we send resize events on
/* priv */ dom_event_chan: comm::SharedChan<Event>,
priv content_chan: SharedChan<ControlMsg>,
/// The port we are waiting on for a response to the last resize event
/* priv */ last_response_port: Option<comm::Port<()>>,
priv last_response_port: Option<Port<()>>,
/// The next window resize event we should fire
/* priv */ next_resize_event: Option<(uint, uint)>
priv next_resize_event: Option<(uint, uint)>
}

pub fn ResizeRateLimiter(dom_event_chan: comm::SharedChan<Event>) -> ResizeRateLimiter {
pub fn ResizeRateLimiter(content_chan: SharedChan<ControlMsg>) -> ResizeRateLimiter {
ResizeRateLimiter {
dom_event_chan: dom_event_chan,
content_chan: content_chan,
last_response_port: None,
next_resize_event: None
}
@@ -64,7 +65,7 @@ pub impl ResizeRateLimiter {

priv fn send_event(&mut self, width: uint, height: uint) {
let (port, chan) = comm::stream();
self.dom_event_chan.send(ResizeEvent(width, height, chan));
self.content_chan.send(SendEventMsg(ResizeEvent(width, height, chan)));
self.last_response_port = Some(port);
}
}
@@ -8,7 +8,7 @@ use dom::event::ReflowEvent;
use dom::htmlcollection::HTMLCollection;
use dom::node::AbstractNode;
use dom::window::Window;
use scripting::script_task::global_script_context;
use scripting::script_task::{SendEventMsg, global_script_context};

use js::jsapi::bindgen::{JS_AddObjectRoot, JS_RemoveObjectRoot};
use servo_util::tree::{TreeNodeRef, TreeUtils};
@@ -64,9 +64,9 @@ pub impl Document {
}

fn content_changed(&self) {
do self.window.map |window| {
let chan = &mut window.dom_event_chan;
chan.send(ReflowEvent)
};
for self.window.each |window| {
window.control_chan.send(SendEventMsg(ReflowEvent))
}
}
}

@@ -4,7 +4,6 @@

use dom::bindings::utils::WrapperCache;
use dom::bindings::window;
use dom::event::Event;
use scripting::script_task::{ControlMsg, ExitMsg, FireTimerMsg, ScriptContext};
use scripting::script_task::{global_script_context};
use util::task::spawn_listener;
@@ -24,7 +23,7 @@ pub enum TimerControlMsg {
// only used for querying layout from arbitrary script.
pub struct Window {
timer_chan: Chan<TimerControlMsg>,
dom_event_chan: SharedChan<Event>,
control_chan: SharedChan<ControlMsg>,
script_context: *mut ScriptContext,
wrapper: WrapperCache
}
@@ -82,30 +81,30 @@ pub impl Window {
&self.timer_chan,
TimerMessage_Fire(~TimerData(argc, argv)));
}
}

pub fn Window(script_chan: comm::SharedChan<ControlMsg>,
dom_event_chan: comm::SharedChan<Event>,
script_context: *mut ScriptContext)
-> @mut Window {
let win = @mut Window {
wrapper: WrapperCache::new(),
dom_event_chan: dom_event_chan,
timer_chan: {
do spawn_listener |timer_port: Port<TimerControlMsg>| {
loop {
match timer_port.recv() {
TimerMessage_Close => break,
TimerMessage_Fire(td) => script_chan.send(FireTimerMsg(td)),
TimerMessage_TriggerExit => script_chan.send(ExitMsg),
pub fn new(control_chan: SharedChan<ControlMsg>, script_context: *mut ScriptContext)
-> @mut Window {
let control_chan_copy = control_chan.clone();
let win = @mut Window {
wrapper: WrapperCache::new(),
control_chan: control_chan,
timer_chan: {
do spawn_listener |timer_port: Port<TimerControlMsg>| {
loop {
match timer_port.recv() {
TimerMessage_Close => break,
TimerMessage_Fire(td) => control_chan_copy.send(FireTimerMsg(td)),
TimerMessage_TriggerExit => control_chan_copy.send(ExitMsg),
}
}
}
}
},
script_context: script_context,
};

let compartment = global_script_context().js_compartment;
window::create(compartment, win);
win
},
script_context: script_context,
};

let compartment = global_script_context().js_compartment;
window::create(compartment, win);
win
}
}

@@ -3,10 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use compositing::CompositorImpl;
use dom::event::Event;
use layout::layout_task::LayoutTask;
use layout::layout_task;
use scripting::script_task::{ExecuteMsg, LoadMsg, ScriptTask};
use scripting::script_task::{ControlMsg, ExecuteMsg, LoadMsg, ScriptTask};
use scripting::script_task;
use util::task::spawn_listener;

@@ -40,13 +39,13 @@ pub struct Engine {
impl Engine {
pub fn start(compositor: CompositorImpl,
opts: &Opts,
dom_event_port: Port<Event>,
dom_event_chan: SharedChan<Event>,
control_port: Port<ControlMsg>,
control_chan: SharedChan<ControlMsg>,
resource_task: ResourceTask,
image_cache_task: ImageCacheTask)
-> EngineTask {
let dom_event_port = Cell(dom_event_port);
let dom_event_chan = Cell(dom_event_chan);
let control_port = Cell(control_port);
let control_chan = Cell(control_chan);

let opts = Cell(copy *opts);
do spawn_listener::<Msg> |request| {
@@ -55,9 +54,9 @@ impl Engine {
let opts = opts.take();
let layout_task = LayoutTask(render_task.clone(), image_cache_task.clone(), opts);

let script_task = ScriptTask::new(layout_task.clone(),
dom_event_port.take(),
dom_event_chan.take(),
let script_task = ScriptTask::new(control_port.take(),
control_chan.take(),
layout_task.clone(),
resource_task.clone(),
image_cache_task.clone());

@@ -7,14 +7,15 @@

use css::matching::MatchMethods;
use css::select::new_css_select_ctx;
use dom::event::{Event, ReflowEvent};
use dom::event::ReflowEvent;
use dom::node::{AbstractNode, LayoutData};
use layout::aux::LayoutAuxMethods;
use layout::box_builder::LayoutTreeBuilder;
use layout::context::LayoutContext;
use layout::debug::{BoxedMutDebugMethods, DebugMethods};
use layout::display_list_builder::{DisplayListBuilder, FlowDisplayListBuilderMethods};
use layout::flow::FlowContext;
use scripting::script_task::{ControlMsg, SendEventMsg};
use util::task::spawn_listener;
use util::time::time;

@@ -79,7 +80,7 @@ impl Damage {
pub struct BuildData {
node: AbstractNode,
url: Url,
dom_event_chan: comm::SharedChan<Event>,
control_chan: SharedChan<ControlMsg>,
window_size: Size2D<uint>,
script_join_chan: comm::Chan<()>,
damage: Damage,
@@ -88,10 +89,10 @@ pub struct BuildData {
pub fn LayoutTask(render_task: RenderTask,
img_cache_task: ImageCacheTask,
opts: Opts) -> LayoutTask {
SharedChan::new(spawn_listener::<Msg>(|from_script| {
SharedChan::new(do spawn_listener::<Msg> |from_script| {
let mut layout = Layout(render_task.clone(), img_cache_task.clone(), from_script, &opts);
layout.start();
}))
})
}

struct Layout {
@@ -170,16 +171,15 @@ impl Layout {
let node = &data.node;
// FIXME: Bad copy!
let doc_url = copy data.url;
// FIXME: Bad clone!
let dom_event_chan = data.dom_event_chan.clone();
let control_chan = data.control_chan.clone();

debug!("layout: received layout request for: %s", doc_url.to_str());
debug!("layout: damage is %?", data.damage);
debug!("layout: parsed Node tree");
debug!("%?", node.dump());

// Reset the image cache.
self.local_image_cache.next_round(self.make_on_image_available_cb(dom_event_chan));
self.local_image_cache.next_round(self.make_on_image_available_cb(control_chan));

let screen_size = Size2D(Au::from_px(data.window_size.width as int),
Au::from_px(data.window_size.height as int));
@@ -315,15 +315,16 @@ impl Layout {
// to the script task, and ultimately cause the image to be
// re-requested. We probably don't need to go all the way back to
// the script task for this.
fn make_on_image_available_cb(&self, dom_event_chan: comm::SharedChan<Event>) -> @fn() -> ~fn(ImageResponseMsg) {
fn make_on_image_available_cb(&self, control_chan: SharedChan<ControlMsg>)
-> @fn() -> ~fn(ImageResponseMsg) {
// This has a crazy signature because the image cache needs to
// make multiple copies of the callback, and the dom event
// channel is not a copyable type, so this is actually a
// little factory to produce callbacks
let f: @fn() -> ~fn(ImageResponseMsg) = || {
let dom_event_chan = dom_event_chan.clone();
let control_chan = control_chan.clone();
let f: ~fn(ImageResponseMsg) = |_| {
dom_event_chan.send(ReflowEvent)
control_chan.send(SendEventMsg(ReflowEvent))
};
f
};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.