mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Let stylesheets live in layout instead of content
This commit is contained in:
parent
23b6b386cb
commit
813b1d2a84
4 changed files with 41 additions and 18 deletions
|
@ -20,7 +20,7 @@ use dom::event::{Event, ResizeEvent, ReflowEvent};
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
use layout::layout_task;
|
use layout::layout_task;
|
||||||
use layout_task::{LayoutTask, BuildMsg, BuildData};
|
use layout_task::{LayoutTask, BuildMsg, BuildData, AddStylesheet};
|
||||||
use resource::image_cache_task::ImageCacheTask;
|
use resource::image_cache_task::ImageCacheTask;
|
||||||
|
|
||||||
use newcss::values::Stylesheet;
|
use newcss::values::Stylesheet;
|
||||||
|
@ -193,15 +193,18 @@ impl Content {
|
||||||
self.image_cache_task.clone());
|
self.image_cache_task.clone());
|
||||||
|
|
||||||
let root = result.root;
|
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();
|
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);
|
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());
|
let window = Window(self.control_chan.clone());
|
||||||
self.relayout(&document, &url);
|
self.relayout(&document, &url);
|
||||||
self.document = Some(@move document);
|
self.document = Some(@move document);
|
||||||
|
@ -306,7 +309,6 @@ impl Content {
|
||||||
|
|
||||||
let data = BuildData {
|
let data = BuildData {
|
||||||
node: document.root,
|
node: document.root,
|
||||||
style: clone(&document.css_rules),
|
|
||||||
url: copy *doc_url,
|
url: copy *doc_url,
|
||||||
dom_event_chan: self.event_chan.clone(),
|
dom_event_chan: self.event_chan.clone(),
|
||||||
window_size: self.window_size,
|
window_size: self.window_size,
|
||||||
|
|
|
@ -107,7 +107,7 @@ trait StyleMethods {
|
||||||
|
|
||||||
fn style() -> SpecifiedStyle;
|
fn style() -> SpecifiedStyle;
|
||||||
fn initialize_style_for_subtree(ctx: &LayoutContext, refs: &DVec<@LayoutData>);
|
fn initialize_style_for_subtree(ctx: &LayoutContext, refs: &DVec<@LayoutData>);
|
||||||
fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &ARC<Stylesheet>);
|
fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &Stylesheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Node : StyleMethods {
|
impl Node : StyleMethods {
|
||||||
|
@ -160,7 +160,7 @@ impl Node : StyleMethods {
|
||||||
* the node (the reader-auxiliary box in the COW model) with the
|
* the node (the reader-auxiliary box in the COW model) with the
|
||||||
* computed style.
|
* computed style.
|
||||||
*/
|
*/
|
||||||
fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &ARC<Stylesheet>) {
|
fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &Stylesheet) {
|
||||||
let mut i = 0u;
|
let mut i = 0u;
|
||||||
|
|
||||||
// Compute the styles of each of our children in parallel
|
// Compute the styles of each of our children in parallel
|
||||||
|
@ -169,7 +169,7 @@ impl Node : StyleMethods {
|
||||||
kid.recompute_style_for_subtree(ctx, styles);
|
kid.recompute_style_for_subtree(ctx, styles);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.match_css_style(get(styles));
|
self.match_css_style(styles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,11 @@ use std::arc::ARC;
|
||||||
struct Document {
|
struct Document {
|
||||||
root: Node,
|
root: Node,
|
||||||
scope: NodeScope,
|
scope: NodeScope,
|
||||||
css_rules: ARC<Stylesheet>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Document(root: Node, scope: NodeScope, css_rules: Stylesheet) -> Document {
|
fn Document(root: Node, scope: NodeScope) -> Document {
|
||||||
Document {
|
Document {
|
||||||
root : root,
|
root : root,
|
||||||
scope : scope,
|
scope : scope,
|
||||||
css_rules : ARC(move css_rules),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ use std::cell::Cell;
|
||||||
use layout::traverse::*;
|
use layout::traverse::*;
|
||||||
use comm::*;
|
use comm::*;
|
||||||
use task::*;
|
use task::*;
|
||||||
|
use core::mutable::Mut;
|
||||||
|
|
||||||
pub type LayoutTask = comm::Chan<Msg>;
|
pub type LayoutTask = comm::Chan<Msg>;
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@ enum LayoutQueryResponse_ {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Msg {
|
pub enum Msg {
|
||||||
|
AddStylesheet(Stylesheet),
|
||||||
BuildMsg(BuildData),
|
BuildMsg(BuildData),
|
||||||
QueryMsg(LayoutQuery, comm::Chan<LayoutQueryResponse>),
|
QueryMsg(LayoutQuery, comm::Chan<LayoutQueryResponse>),
|
||||||
ExitMsg
|
ExitMsg
|
||||||
|
@ -57,7 +59,6 @@ pub enum Msg {
|
||||||
|
|
||||||
struct BuildData {
|
struct BuildData {
|
||||||
node: Node,
|
node: Node,
|
||||||
style: ARC<Stylesheet>,
|
|
||||||
url: Url,
|
url: Url,
|
||||||
dom_event_chan: pipes::SharedChan<Event>,
|
dom_event_chan: pipes::SharedChan<Event>,
|
||||||
window_size: Size2D<uint>,
|
window_size: Size2D<uint>,
|
||||||
|
@ -80,7 +81,8 @@ struct Layout {
|
||||||
font_cache: @FontCache,
|
font_cache: @FontCache,
|
||||||
font_matcher: @FontMatcher,
|
font_matcher: @FontMatcher,
|
||||||
// This is used to root auxilliary RCU reader data
|
// This is used to root auxilliary RCU reader data
|
||||||
layout_refs: DVec<@LayoutData>
|
layout_refs: DVec<@LayoutData>,
|
||||||
|
stylesheet: Mut<Option<Stylesheet>>
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Layout(render_task: RenderTask,
|
fn Layout(render_task: RenderTask,
|
||||||
|
@ -96,7 +98,8 @@ fn Layout(render_task: RenderTask,
|
||||||
from_content: from_content,
|
from_content: from_content,
|
||||||
font_matcher: @FontMatcher::new(fctx),
|
font_matcher: @FontMatcher::new(fctx),
|
||||||
font_cache: @FontCache::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 {
|
fn handle_request() -> bool {
|
||||||
|
|
||||||
match self.from_content.recv() {
|
match self.from_content.recv() {
|
||||||
|
AddStylesheet(move sheet) => {
|
||||||
|
self.handle_add_stylesheet(move sheet);
|
||||||
|
}
|
||||||
BuildMsg(move data) => {
|
BuildMsg(move data) => {
|
||||||
let data = Cell(move data);
|
let data = Cell(move data);
|
||||||
|
|
||||||
|
@ -133,6 +139,14 @@ impl Layout {
|
||||||
true
|
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) {
|
fn handle_build(data: BuildData) {
|
||||||
|
|
||||||
let node = &data.node;
|
let node = &data.node;
|
||||||
|
@ -161,7 +175,16 @@ impl Layout {
|
||||||
let layout_root: @FlowContext = do time("layout: tree construction") {
|
let layout_root: @FlowContext = do time("layout: tree construction") {
|
||||||
// TODO: this is dumb. we don't need 3 separate traversals.
|
// TODO: this is dumb. we don't need 3 separate traversals.
|
||||||
node.initialize_style_for_subtree(&layout_ctx, &self.layout_refs);
|
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 */
|
/* resolve styles (convert relative values) down the node tree */
|
||||||
apply_style(&layout_ctx, *node);
|
apply_style(&layout_ctx, *node);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue