aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/layout_interface.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2014-08-07 15:14:32 -0400
committerJosh Matthews <josh@joshmatthews.net>2014-08-08 16:17:17 -0400
commit015b07f1e0d0f81f246b11dbc60cac0d527357e2 (patch)
tree73fe9a7deebd54bf4aba4c54c9004fed8d9b6e89 /src/components/script/layout_interface.rs
parent8b3c9f64016fe05048f8d774dc7bf0b842bdbd9c (diff)
downloadservo-015b07f1e0d0f81f246b11dbc60cac0d527357e2.tar.gz
servo-015b07f1e0d0f81f246b11dbc60cac0d527357e2.zip
Decouple compositing and script crates.
Diffstat (limited to 'src/components/script/layout_interface.rs')
-rw-r--r--src/components/script/layout_interface.rs31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/components/script/layout_interface.rs b/src/components/script/layout_interface.rs
index 0e84554c8a7..892c64414c3 100644
--- a/src/components/script/layout_interface.rs
+++ b/src/components/script/layout_interface.rs
@@ -12,11 +12,13 @@ use dom::node::{Node, LayoutDataRef};
use geom::point::Point2D;
use geom::rect::Rect;
use libc::c_void;
-use script_task::{ScriptChan};
+use script_traits::{ScriptControlChan, OpaqueScriptLayoutChannel};
use servo_msg::constellation_msg::WindowSizeData;
use servo_util::geometry::Au;
+use std::any::{Any, AnyRefExt};
use std::cmp;
use std::comm::{channel, Receiver, Sender};
+use std::owned::BoxAny;
use style::Stylesheet;
use url::Url;
@@ -135,7 +137,7 @@ pub struct Reflow {
/// The URL of the page.
pub url: Url,
/// The channel through which messages can be sent back to the script task.
- pub script_chan: ScriptChan,
+ pub script_chan: ScriptControlChan,
/// The current window size.
pub window_size: WindowSizeData,
/// The channel that we send a notification to.
@@ -155,6 +157,31 @@ impl LayoutChan {
}
}
+/// A trait to manage opaque references to script<->layout channels without needing
+/// to expose the message type to crates that don't need to know about them.
+pub trait ScriptLayoutChan {
+ fn new(sender: Sender<Msg>, receiver: Receiver<Msg>) -> Self;
+ fn sender(&self) -> Sender<Msg>;
+ fn receiver(self) -> Receiver<Msg>;
+}
+
+impl ScriptLayoutChan for OpaqueScriptLayoutChannel {
+ fn new(sender: Sender<Msg>, receiver: Receiver<Msg>) -> OpaqueScriptLayoutChannel {
+ let inner = (box sender as Box<Any+Send>, box receiver as Box<Any+Send>);
+ OpaqueScriptLayoutChannel(inner)
+ }
+
+ fn sender(&self) -> Sender<Msg> {
+ let &OpaqueScriptLayoutChannel((ref sender, _)) = self;
+ (*sender.as_ref::<Sender<Msg>>().unwrap()).clone()
+ }
+
+ fn receiver(self) -> Receiver<Msg> {
+ let OpaqueScriptLayoutChannel((_, receiver)) = self;
+ *receiver.downcast::<Receiver<Msg>>().unwrap()
+ }
+}
+
#[test]
fn test_add_damage() {
fn assert_add(mut a: DocumentDamageLevel, b: DocumentDamageLevel,