From 59c4da3130acb6f32f70727dc133b9ee54bda243 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Wed, 10 Oct 2012 09:39:40 -0700 Subject: [PATCH] Add a trait for FlowContext. --- src/servo/layout/flow.rs | 84 +++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/src/servo/layout/flow.rs b/src/servo/layout/flow.rs index a269bf85e93..380ab5d32f9 100644 --- a/src/servo/layout/flow.rs +++ b/src/servo/layout/flow.rs @@ -62,7 +62,50 @@ enum FlowContextType { Flow_Table } -impl FlowContext { +trait FlowContextMethods { + pure fn d(&self) -> &self/FlowData; + pure fn inline(&self) -> &self/InlineFlowData; + pure fn block(&self) -> &self/BlockFlowData; + pure fn root(&self) -> &self/RootFlowData; + fn bubble_widths(@self, &LayoutContext); + fn assign_widths(@self, &LayoutContext); + fn assign_height(@self, &LayoutContext); + fn build_display_list_recurse(@self, &dl::DisplayListBuilder, dirty: &Rect, + offset: &Point2D, &dl::DisplayList); + pure fn foldl_boxes_for_node(Node, +seed: B, cb: pure fn&(+a: B,@RenderBox) -> B) -> B; + pure fn iter_boxes_for_node(Node, cb: pure fn&(@RenderBox) -> T); +} + +/* A particular kind of layout context. It manages the positioning of + render boxes within the context. */ +struct FlowData { + mut node: Option, + /* reference to parent, children flow contexts */ + tree: tree::Tree<@FlowContext>, + /* TODO (Issue #87): debug only */ + mut id: int, + + /* layout computations */ + // TODO: min/pref and position are used during disjoint phases of + // layout; maybe combine into a single enum to save space. + mut min_width: au, + mut pref_width: au, + mut position: Rect, +} + +fn FlowData(id: int) -> FlowData { + FlowData { + node: None, + tree: tree::empty(), + id: id, + + min_width: au(0), + pref_width: au(0), + position: au::zero_rect() + } +} + +impl FlowContext : FlowContextMethods { pure fn d(&self) -> &self/FlowData { match *self { AbsoluteFlow(ref d) => d, @@ -96,40 +139,6 @@ impl FlowContext { } } -} - -/* A particular kind of layout context. It manages the positioning of - render boxes within the context. */ -struct FlowData { - mut node: Option, - /* reference to parent, children flow contexts */ - tree: tree::Tree<@FlowContext>, - /* TODO (Issue #87): debug only */ - mut id: int, - - /* layout computations */ - // TODO: min/pref and position are used during disjoint phases of - // layout; maybe combine into a single enum to save space. - mut min_width: au, - mut pref_width: au, - mut position: Rect, -} - - -fn FlowData(id: int) -> FlowData { - FlowData { - node: None, - tree: tree::empty(), - id: id, - - min_width: au(0), - pref_width: au(0), - position: au::zero_rect() - } -} - -/* Flow context disambiguation methods: the verbose alternative to virtual methods */ -impl FlowContext { fn bubble_widths(@self, ctx: &LayoutContext) { match self { @BlockFlow(*) => self.bubble_widths_block(ctx), @@ -166,10 +175,8 @@ impl FlowContext { _ => fail fmt!("Tried to build_display_list_recurse of flow: %?", self) } } -} -// Actual methods that do not require much flow-specific logic -impl FlowContext { + // Actual methods that do not require much flow-specific logic pure fn foldl_boxes_for_node(node: Node, +seed: B, blk: pure fn&(+a: B,@RenderBox) -> B) -> B { match self { RootFlow(*) => match self.root().box { @@ -209,7 +216,6 @@ impl FlowContext { } } - /* The tree holding FlowContexts */ enum FlowTree { FlowTree }