Add FlowContext.iter_boxes_for_node

This commit is contained in:
Brian J. Burg 2012-09-21 19:01:18 -07:00
parent 6e9b2ed6af
commit b1ef70b402
2 changed files with 36 additions and 0 deletions

View file

@ -49,6 +49,19 @@ impl Node {
}
}
/* TODO: LayoutData is just a pointer, but we must circumvent the type
system to actually compare the pointers. This should be fixed in
with a generic implementation of rcu::Handle */
impl Node : cmp::Eq {
pure fn eq(other : &Node) -> bool unsafe {
let my_data : @LayoutData = @self.aux(|a| a);
let ot_data : @LayoutData = @other.aux(|a| a);
core::box::ptr_eq(my_data, ot_data)
}
pure fn ne(other : &Node) -> bool unsafe {
!self.eq(other)
}
}
impl Node : DebugMethods {
/* Dumps the subtree rooted at this node, for debugging. */

View file

@ -6,6 +6,7 @@ use geom::rect::Rect;
use geom::point::Point2D;
// TODO: pub-use these
use layout::block::BlockFlowData;
use layout::box::RenderBox;
use layout::context::LayoutContext;
use layout::debug::DebugMethods;
use layout::inline::InlineFlowData;
@ -137,6 +138,28 @@ impl @FlowContext {
}
}
// Actual methods that do not require much flow-specific logic
impl @FlowContext {
fn iter_boxes_for_node<T>(node: Node, cb: pure fn&(@RenderBox) -> T) {
match self.kind {
RootFlow(d) => match d.box {
Some(box) if box.node == node => { cb(box); },
_ => {}
},
BlockFlow(d) => match d.box {
Some(box) if box.node == node => { cb(box); },
_ => {}
},
InlineFlow(d) => {
for d.boxes.each |box| {
if box.node == node { cb(*box); }
}
},
_ => fail fmt!("Don't know how to iterate node's RenderBoxes for %?", self.kind)
}
}
}
/* The tree holding FlowContexts */
enum FlowTree { FlowTree }