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