diff --git a/src/servo/content/content_task.rs b/src/servo/content/content_task.rs index b32e1e6c5b4..f79a22b21a0 100644 --- a/src/servo/content/content_task.rs +++ b/src/servo/content/content_task.rs @@ -20,7 +20,7 @@ use dom::event::{Event, ResizeEvent, ReflowEvent}; use dom::window::Window; use geom::size::Size2D; use layout::layout_task; -use layout_task::{LayoutTask, BuildMsg, BuildData}; +use layout_task::{LayoutTask, BuildMsg, BuildData, AddStylesheet}; use resource::image_cache_task::ImageCacheTask; use newcss::values::Stylesheet; @@ -193,15 +193,18 @@ impl Content { self.image_cache_task.clone()); let root = result.root; - let css_rules = result.style_port.recv(); + + // Send stylesheets over to layout + // FIXME: Need these should be streamed to layout as they are parsed + // and do not need to stop here in the content task + // FIXME: This currently expects exactly one stylesheet + let sheet = result.style_port.recv(); + self.layout_task.send(AddStylesheet(move sheet)); + let js_scripts = result.js_port.recv(); - - // Apply the css rules to the dom tree: - debug!("css_rules: %?", css_rules); - debug!("js_scripts: %?", js_scripts); - let document = Document(root, self.scope, move css_rules); + let document = Document(root, self.scope); let window = Window(self.control_chan.clone()); self.relayout(&document, &url); self.document = Some(@move document); @@ -306,7 +309,6 @@ impl Content { let data = BuildData { node: document.root, - style: clone(&document.css_rules), url: copy *doc_url, dom_event_chan: self.event_chan.clone(), window_size: self.window_size, diff --git a/src/servo/css/styles.rs b/src/servo/css/styles.rs index fcc19880a02..c1e770a327b 100644 --- a/src/servo/css/styles.rs +++ b/src/servo/css/styles.rs @@ -107,7 +107,7 @@ trait StyleMethods { fn style() -> SpecifiedStyle; fn initialize_style_for_subtree(ctx: &LayoutContext, refs: &DVec<@LayoutData>); - fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &ARC); + fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &Stylesheet); } impl Node : StyleMethods { @@ -160,7 +160,7 @@ impl Node : StyleMethods { * the node (the reader-auxiliary box in the COW model) with the * computed style. */ - fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &ARC) { + fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &Stylesheet) { let mut i = 0u; // Compute the styles of each of our children in parallel @@ -169,7 +169,7 @@ impl Node : StyleMethods { kid.recompute_style_for_subtree(ctx, styles); } - self.match_css_style(get(styles)); + self.match_css_style(styles); } } diff --git a/src/servo/dom/document.rs b/src/servo/dom/document.rs index e464a2ed041..b0253005747 100644 --- a/src/servo/dom/document.rs +++ b/src/servo/dom/document.rs @@ -5,13 +5,11 @@ use std::arc::ARC; struct Document { root: Node, scope: NodeScope, - css_rules: ARC, } -fn Document(root: Node, scope: NodeScope, css_rules: Stylesheet) -> Document { +fn Document(root: Node, scope: NodeScope) -> Document { Document { root : root, scope : scope, - css_rules : ARC(move css_rules), } } diff --git a/src/servo/layout/layout_task.rs b/src/servo/layout/layout_task.rs index b059aafcbfe..e34bf6fd32f 100644 --- a/src/servo/layout/layout_task.rs +++ b/src/servo/layout/layout_task.rs @@ -36,6 +36,7 @@ use std::cell::Cell; use layout::traverse::*; use comm::*; use task::*; +use core::mutable::Mut; pub type LayoutTask = comm::Chan; @@ -50,6 +51,7 @@ enum LayoutQueryResponse_ { } pub enum Msg { + AddStylesheet(Stylesheet), BuildMsg(BuildData), QueryMsg(LayoutQuery, comm::Chan), ExitMsg @@ -57,7 +59,6 @@ pub enum Msg { struct BuildData { node: Node, - style: ARC, url: Url, dom_event_chan: pipes::SharedChan, window_size: Size2D, @@ -80,7 +81,8 @@ struct Layout { font_cache: @FontCache, font_matcher: @FontMatcher, // This is used to root auxilliary RCU reader data - layout_refs: DVec<@LayoutData> + layout_refs: DVec<@LayoutData>, + stylesheet: Mut> } fn Layout(render_task: RenderTask, @@ -96,7 +98,8 @@ fn Layout(render_task: RenderTask, from_content: from_content, font_matcher: @FontMatcher::new(fctx), font_cache: @FontCache::new(fctx), - layout_refs: DVec() + layout_refs: DVec(), + stylesheet: Mut(None) } } @@ -111,6 +114,9 @@ impl Layout { fn handle_request() -> bool { match self.from_content.recv() { + AddStylesheet(move sheet) => { + self.handle_add_stylesheet(move sheet); + } BuildMsg(move data) => { let data = Cell(move data); @@ -133,6 +139,14 @@ impl Layout { true } + fn handle_add_stylesheet(sheet: Stylesheet) { + let sheet = Cell(move sheet); + do self.stylesheet.borrow_mut |mysheet| { + assert mysheet.is_none(); // FIXME: Support multiple sheets + *mysheet = Some(sheet.take()); + } + } + fn handle_build(data: BuildData) { let node = &data.node; @@ -161,7 +175,16 @@ impl Layout { let layout_root: @FlowContext = do time("layout: tree construction") { // TODO: this is dumb. we don't need 3 separate traversals. node.initialize_style_for_subtree(&layout_ctx, &self.layout_refs); - node.recompute_style_for_subtree(&layout_ctx, &data.style); + do self.stylesheet.borrow_imm |sheet| { + match *sheet { + Some(ref sheet) => { + unsafe { + node.recompute_style_for_subtree(&layout_ctx, sheet); + } + } + None => () + } + } /* resolve styles (convert relative values) down the node tree */ apply_style(&layout_ctx, *node);