From b675618a7b68d162674d9e1df9affee7c609e766 Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Mon, 11 Nov 2013 15:51:57 +0900 Subject: [PATCH] Add some basic debug info for dumping flows. --- src/components/main/layout/block.rs | 14 ++++++++++++++ src/components/main/layout/float.rs | 3 +++ src/components/main/layout/flow.rs | 24 ++++++++++++++++++++++-- src/components/main/layout/inline.rs | 4 ++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index b0745e1050f3..1f336e48da78 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -506,5 +506,19 @@ impl FlowContext for BlockFlow { *first_in_flow = false; } + + fn debug_str(&self) -> ~str { + if self.is_root { + ~"BlockFlow(root)" + } else { + let txt = ~"BlockFlow: "; + txt.append(match self.box { + Some(rb) => { + rb.debug_str() + } + None => { ~"" } + }) + } + } } diff --git a/src/components/main/layout/float.rs b/src/components/main/layout/float.rs index 47f6dd12f9b3..faa8571955c3 100644 --- a/src/components/main/layout/float.rs +++ b/src/components/main/layout/float.rs @@ -315,5 +315,8 @@ impl FlowContext for FloatFlow { // Margins between a floated box and any other box do not collapse. *collapsing = Au::new(0); } + fn debug_str(&self) -> ~str { + ~"FloatFlow" + } } diff --git a/src/components/main/layout/flow.rs b/src/components/main/layout/flow.rs index abbc39a50d9a..afa0f80b258a 100644 --- a/src/components/main/layout/flow.rs +++ b/src/components/main/layout/flow.rs @@ -35,7 +35,7 @@ use layout::float_context::{FloatContext, Invalid}; use layout::incremental::RestyleDamage; use layout::inline::InlineFlow; -use extra::dlist::{DList,MutDListIterator}; +use extra::dlist::{DList, DListIterator, MutDListIterator}; use extra::container::Deque; use geom::point::Point2D; use geom::rect::Rect; @@ -127,6 +127,11 @@ pub fn base<'a>(this: &'a FlowContext) -> &'a FlowData { } } +/// Iterates over the children of this immutable flow. +pub fn imm_child_iter<'a>(flow: &'a FlowContext) -> DListIterator<'a,~FlowContext:> { + base(flow).children.iter() +} + #[inline(always)] pub fn mut_base<'a>(this: &'a mut FlowContext) -> &'a mut FlowData { unsafe { @@ -162,6 +167,9 @@ pub trait ImmutableFlowUtils { /// Dumps the flow tree for debugging. fn dump(self); + + /// Dumps the flow tree for debugging, with a prefix to indicate that we're at the given level. + fn dump_with_level(self, level: uint); } pub trait MutableFlowUtils { @@ -411,7 +419,19 @@ impl<'self> ImmutableFlowUtils for &'self FlowContext { /// Dumps the flow tree for debugging. fn dump(self) { - // TODO(pcwalton): Fill this in. + self.dump_with_level(0) + } + + /// Dumps the flow tree for debugging, with a prefix to indicate that we're at the given level. + fn dump_with_level(self, level: uint) { + let mut indent = ~""; + for _ in range(0, level) { + indent.push_str("| ") + } + debug!("{}+ {}", indent, self.debug_str()); + for kid in imm_child_iter(self) { + kid.dump_with_level(level + 1) + } } } diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs index a15f739ba05f..d598e9356ab1 100644 --- a/src/components/main/layout/inline.rs +++ b/src/components/main/layout/inline.rs @@ -891,5 +891,9 @@ impl FlowContext for InlineFlow { *collapsible = Au::new(0); } } + + fn debug_str(&self) -> ~str { + ~"InlineFlow" + } }