mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Move aux pointer initialization to layout::aux
This commit is contained in:
parent
85293b61ca
commit
bd9a9421d2
4 changed files with 46 additions and 37 deletions
|
@ -2,51 +2,16 @@
|
||||||
* High-level interface to CSS selector matching.
|
* High-level interface to CSS selector matching.
|
||||||
*/
|
*/
|
||||||
use std::arc::{ARC, get, clone};
|
use std::arc::{ARC, get, clone};
|
||||||
use dom::node::{Node, LayoutData, NodeTree};
|
use dom::node::{Node, NodeTree};
|
||||||
use core::dvec::DVec;
|
|
||||||
use newcss::values::*;
|
|
||||||
use newcss::{SelectCtx, SelectResults};
|
use newcss::{SelectCtx, SelectResults};
|
||||||
use newcss::color::{Color, rgb};
|
|
||||||
use newcss::color::css_colors::{white, black};
|
|
||||||
use layout::context::LayoutContext;
|
use layout::context::LayoutContext;
|
||||||
use select_handler::NodeSelectHandler;
|
use select_handler::NodeSelectHandler;
|
||||||
|
|
||||||
trait StyleMethods {
|
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);
|
fn recompute_style_for_subtree(ctx: &LayoutContext, select_ctx: &SelectCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Node : StyleMethods {
|
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.
|
* Performs CSS selector matching on a subtree.
|
||||||
|
|
||||||
|
|
43
src/servo/layout/aux.rs
Normal file
43
src/servo/layout/aux.rs
Normal 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 => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -173,7 +173,7 @@ 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 2 separate traversals.
|
// 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| {
|
do self.css_select_ctx.borrow_imm |ctx| {
|
||||||
node.recompute_style_for_subtree(&layout_ctx, ctx);
|
node.recompute_style_for_subtree(&layout_ctx, ctx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ pub mod layout {
|
||||||
pub mod root;
|
pub mod root;
|
||||||
pub mod text;
|
pub mod text;
|
||||||
pub mod traverse;
|
pub mod traverse;
|
||||||
|
mod aux;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod gfx {
|
pub mod gfx {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue