From 2bc9e662577f15a84b00f670c189a8c0b8cd54f2 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Tue, 9 Oct 2012 11:42:01 -0700 Subject: [PATCH] Create a trait for RenderBox. --- src/servo/layout/box.rs | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/servo/layout/box.rs b/src/servo/layout/box.rs index f1b566d7226..e898c55a24e 100644 --- a/src/servo/layout/box.rs +++ b/src/servo/layout/box.rs @@ -97,15 +97,19 @@ pub enum RenderBox { UnscannedTextBox(RenderBoxData, ~str) } -impl RenderBox { - pure fn d(&self) -> &self/RenderBoxData { - match *self { - GenericBox(ref d) => d, - ImageBox(ref d, _) => d, - TextBox(ref d, _) => d, - UnscannedTextBox(ref d, _) => d, - } - } +trait RenderBoxMethods { + pure fn d(&self) -> &self/RenderBoxData; + + pure fn is_replaced() -> bool; + pure fn content_box() -> Rect; + pure fn border_box() -> Rect; + + fn get_min_width(&LayoutContext) -> au; + fn get_pref_width(&LayoutContext) -> au; + fn get_used_width() -> (au, au); + fn get_used_height() -> (au, au); + fn build_display_list(&dl::DisplayListBuilder, dirty: &Rect, + offset: &Point2D, &dl::DisplayList); } fn RenderBoxData(node: Node, ctx: @FlowContext, id: int) -> RenderBoxData { @@ -120,7 +124,16 @@ fn RenderBoxData(node: Node, ctx: @FlowContext, id: int) -> RenderBoxData { } } -impl RenderBox { +impl RenderBox : RenderBoxMethods { + pure fn d(&self) -> &self/RenderBoxData { + match *self { + GenericBox(ref d) => d, + ImageBox(ref d, _) => d, + TextBox(ref d, _) => d, + UnscannedTextBox(ref d, _) => d, + } + } + pure fn is_replaced() -> bool { match self { ImageBox(*) => true, // TODO: form elements, etc @@ -238,7 +251,7 @@ impl RenderBox { /* The box formed by the border edge, as defined in CSS 2.1 Section 8.1. Coordinates are relative to the owning flow. */ - fn border_box() -> Rect { + pure fn border_box() -> Rect { // TODO: actually compute content_box + padding + border self.content_box() } @@ -296,10 +309,6 @@ impl RenderBox { } } -trait ImageBoxMethods { - -} - /** * The tree holding render box relations. These are only defined for * nested CSS boxes that are nested in an otherwise inline flow