From b1ef70b4029d147a6c9415870e02559be8e6b778 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 21 Sep 2012 19:01:18 -0700 Subject: [PATCH] Add FlowContext.iter_boxes_for_node --- src/servo/dom/node.rs | 13 +++++++++++++ src/servo/layout/flow.rs | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/servo/dom/node.rs b/src/servo/dom/node.rs index 2982efbe1c0..d594a5b53a0 100644 --- a/src/servo/dom/node.rs +++ b/src/servo/dom/node.rs @@ -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. */ diff --git a/src/servo/layout/flow.rs b/src/servo/layout/flow.rs index 5fa791769ce..ce126bb8747 100644 --- a/src/servo/layout/flow.rs +++ b/src/servo/layout/flow.rs @@ -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(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 }