From 806517b9bb6f38b1e3acd1468fe9cb30bfa5f56f Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 31 Oct 2012 00:19:39 -0700 Subject: [PATCH] Add the CSS SelectCtx to Layout --- src/servo/css/matching.rs | 6 +++--- src/servo/css/styles.rs | 6 +++--- src/servo/layout/layout_task.rs | 21 +++++++-------------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/servo/css/matching.rs b/src/servo/css/matching.rs index 76f6dd49834..d3e62a5f17e 100644 --- a/src/servo/css/matching.rs +++ b/src/servo/css/matching.rs @@ -6,7 +6,7 @@ use dom::node::{LayoutData, Node, Text}; use dom::element::ElementData; use newcss::values::*; -use newcss::Stylesheet; +use newcss::SelectCtx; use styles::{SpecifiedStyle}; /** @@ -196,7 +196,7 @@ impl Node : PrivStyleMethods { } trait MatchingMethods { - fn match_css_style(styles : &Stylesheet); + fn match_css_style(styles : &SelectCtx); } impl Node : MatchingMethods { @@ -204,7 +204,7 @@ impl Node : MatchingMethods { Compare an html element to a list of css rules and update its style according to the rules matching it. */ - fn match_css_style(styles : &Stylesheet) { + fn match_css_style(styles : &SelectCtx) { // Loop over each rule, see if our node matches what is // described in the rule. If it matches, update its style. As // we don't currently have priorities of style information, diff --git a/src/servo/css/styles.rs b/src/servo/css/styles.rs index db0fc44090e..8f5737e2b26 100644 --- a/src/servo/css/styles.rs +++ b/src/servo/css/styles.rs @@ -5,7 +5,7 @@ use std::arc::{ARC, get, clone}; use core::dvec::DVec; use newcss::values::*; -use newcss::Stylesheet; +use newcss::SelectCtx; use dom::element::{HTMLDivElement, HTMLHeadElement, HTMLImageElement, UnknownElement, HTMLScriptElement}; use dom::node::{Comment, Doctype, Element, Text, Node, NodeKind, NodeTree, LayoutData}; @@ -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 : &Stylesheet); + fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &SelectCtx); } 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 : &Stylesheet) { + fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &SelectCtx) { let mut i = 0u; // Compute the styles of each of our children in parallel diff --git a/src/servo/layout/layout_task.rs b/src/servo/layout/layout_task.rs index 5faba84f661..dbbbb33e1e6 100644 --- a/src/servo/layout/layout_task.rs +++ b/src/servo/layout/layout_task.rs @@ -37,6 +37,7 @@ use layout::traverse::*; use comm::*; use task::*; use core::mutable::Mut; +use newcss::SelectCtx; pub type LayoutTask = comm::Chan; @@ -82,7 +83,7 @@ struct Layout { font_matcher: @FontMatcher, // This is used to root auxilliary RCU reader data layout_refs: DVec<@LayoutData>, - stylesheet: Mut> + css_select_ctx: Mut, } fn Layout(render_task: RenderTask, @@ -99,7 +100,7 @@ fn Layout(render_task: RenderTask, font_matcher: @FontMatcher::new(fctx), font_cache: @FontCache::new(fctx), layout_refs: DVec(), - stylesheet: Mut(None) + css_select_ctx: Mut(SelectCtx::new()) } } @@ -141,9 +142,8 @@ impl Layout { 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()); + do self.css_select_ctx.borrow_mut |ctx| { + ctx.append_sheet(sheet.take()); } } @@ -175,15 +175,8 @@ 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); - do self.stylesheet.borrow_imm |sheet| { - match *sheet { - Some(ref sheet) => { - unsafe { - node.recompute_style_for_subtree(&layout_ctx, sheet); - } - } - None => () - } + do self.css_select_ctx.borrow_imm |ctx| { + node.recompute_style_for_subtree(&layout_ctx, ctx); } /* resolve styles (convert relative values) down the node tree */ apply_style(&layout_ctx, *node);