From bd9a9421d273a3ff945651d313a4ef09d972f2e3 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 31 Oct 2012 19:13:57 -0700 Subject: [PATCH] Move aux pointer initialization to layout::aux --- src/servo/css/styles.rs | 37 +--------------------------- src/servo/layout/aux.rs | 43 +++++++++++++++++++++++++++++++++ src/servo/layout/layout_task.rs | 2 +- src/servo/servo.rc | 1 + 4 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 src/servo/layout/aux.rs diff --git a/src/servo/css/styles.rs b/src/servo/css/styles.rs index 6c6b7e8d5dc..c5d088f3fbc 100644 --- a/src/servo/css/styles.rs +++ b/src/servo/css/styles.rs @@ -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. diff --git a/src/servo/layout/aux.rs b/src/servo/layout/aux.rs new file mode 100644 index 00000000000..e640a3c68d8 --- /dev/null +++ b/src/servo/layout/aux.rs @@ -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 => {} + } + } + } + +} \ No newline at end of file diff --git a/src/servo/layout/layout_task.rs b/src/servo/layout/layout_task.rs index cd2187ebf44..b2e249c7a91 100644 --- a/src/servo/layout/layout_task.rs +++ b/src/servo/layout/layout_task.rs @@ -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); } diff --git a/src/servo/servo.rc b/src/servo/servo.rc index 67724a8bf7c..20f0be1778a 100755 --- a/src/servo/servo.rc +++ b/src/servo/servo.rc @@ -64,6 +64,7 @@ pub mod layout { pub mod root; pub mod text; pub mod traverse; + mod aux; } pub mod gfx {