mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add the CSS SelectCtx to Layout
This commit is contained in:
parent
8c98b0e49c
commit
806517b9bb
3 changed files with 13 additions and 20 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -37,6 +37,7 @@ use layout::traverse::*;
|
|||
use comm::*;
|
||||
use task::*;
|
||||
use core::mutable::Mut;
|
||||
use newcss::SelectCtx;
|
||||
|
||||
pub type LayoutTask = comm::Chan<Msg>;
|
||||
|
||||
|
@ -82,7 +83,7 @@ struct Layout {
|
|||
font_matcher: @FontMatcher,
|
||||
// This is used to root auxilliary RCU reader data
|
||||
layout_refs: DVec<@LayoutData>,
|
||||
stylesheet: Mut<Option<Stylesheet>>
|
||||
css_select_ctx: Mut<SelectCtx>,
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue