Move aux pointer initialization to layout::aux

This commit is contained in:
Brian Anderson 2012-10-31 19:13:57 -07:00
parent 85293b61ca
commit bd9a9421d2
4 changed files with 46 additions and 37 deletions

View file

@ -2,51 +2,16 @@
* High-level interface to CSS selector matching.
*/
use std::arc::{ARC, get, clone};
use dom::node::{Node, LayoutData, NodeTree};
use core::dvec::DVec;
use newcss::values::*;
use dom::node::{Node, NodeTree};
use newcss::{SelectCtx, SelectResults};
use newcss::color::{Color, rgb};
use newcss::color::css_colors::{white, black};
use layout::context::LayoutContext;
use select_handler::NodeSelectHandler;
trait StyleMethods {
fn initialize_layout_data() -> Option<@LayoutData>;
fn initialize_style_for_subtree(ctx: &LayoutContext, refs: &DVec<@LayoutData>);
fn recompute_style_for_subtree(ctx: &LayoutContext, select_ctx: &SelectCtx);
}
impl Node : StyleMethods {
/** If none exists, creates empty layout data for the node (the reader-auxiliary
* box in the COW model) and populates it with an empty style object.
*/
fn initialize_layout_data() -> Option<@LayoutData> {
match self.has_aux() {
false => {
let data = @LayoutData({
mut style : None,
mut flow : None
});
self.set_aux(data); Some(data)
},
true => None
}
}
/**
* Initializes layout data and styles for a Node tree, if any nodes do not have
* this data already. Append created layout data to the task's GC roots.
*/
fn initialize_style_for_subtree(_ctx: &LayoutContext, refs: &DVec<@LayoutData>) {
do self.traverse_preorder |n| {
match n.initialize_layout_data() {
Some(r) => refs.push(r),
None => {}
}
}
}
/**
* Performs CSS selector matching on a subtree.

43
src/servo/layout/aux.rs Normal file
View file

@ -0,0 +1,43 @@
/**
Code for managing the DOM aux pointer
*/
use dom::node::{Node, LayoutData};
use core::dvec::DVec;
pub trait LayoutAuxMethods {
fn initialize_layout_data() -> Option<@LayoutData>;
fn initialize_style_for_subtree(refs: &DVec<@LayoutData>);
}
impl Node : LayoutAuxMethods {
/** If none exists, creates empty layout data for the node (the reader-auxiliary
* box in the COW model) and populates it with an empty style object.
*/
fn initialize_layout_data() -> Option<@LayoutData> {
match self.has_aux() {
false => {
let data = @LayoutData({
mut style : None,
mut flow : None
});
self.set_aux(data); Some(data)
},
true => None
}
}
/**
* Initializes layout data and styles for a Node tree, if any nodes do not have
* this data already. Append created layout data to the task's GC roots.
*/
fn initialize_style_for_subtree(refs: &DVec<@LayoutData>) {
do self.traverse_preorder |n| {
match n.initialize_layout_data() {
Some(r) => refs.push(r),
None => {}
}
}
}
}

View file

@ -173,7 +173,7 @@ impl Layout {
let layout_root: @FlowContext = do time("layout: tree construction") {
// TODO: this is dumb. we don't need 2 separate traversals.
node.initialize_style_for_subtree(&layout_ctx, &self.layout_refs);
node.initialize_style_for_subtree(&self.layout_refs);
do self.css_select_ctx.borrow_imm |ctx| {
node.recompute_style_for_subtree(&layout_ctx, ctx);
}

View file

@ -64,6 +64,7 @@ pub mod layout {
pub mod root;
pub mod text;
pub mod traverse;
mod aux;
}
pub mod gfx {