From f1fcd4d32320667bb7b47df3a8af6be517a869be Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 31 May 2013 17:28:14 -0700 Subject: [PATCH] Add comments and compute heights properly --- src/components/main/layout/block.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index 03e9c62dcf7..48626c7f087 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -187,10 +187,13 @@ impl BlockFlowData { self.box.map(|&box| { let style = box.style(); do box.with_model |model| { + //Can compute padding here since we know containing block width model.compute_padding(style, remaining_width); + //Margins are 0 right now so model.noncontent_width() is just borders + padding. let available_width = remaining_width - model.noncontent_width(); + //Top and bottom margins for blocks are 0 if auto let margin_top = MaybeAuto::from_margin(style.margin_top()).spec_or_default(Au(0)); let margin_bottom = MaybeAuto::from_margin(style.margin_bottom()).spec_or_default(Au(0)); @@ -211,11 +214,12 @@ impl BlockFlowData { } do box.with_mut_base |base| { - let bp_width = base.model.padding.left + base.model.padding.right + - base.model.border.left + base.model.border.right; - - base.position.size.width = remaining_width + bp_width; + //The associated box is the border box of this flow base.position.origin.x = base.model.margin.left; + + let pb = base.model.padding.left + base.model.padding.right + + base.model.border.left + base.model.border.right; + base.position.size.width = remaining_width + pb; } }); @@ -232,6 +236,12 @@ impl BlockFlowData { pub fn assign_height_block(@mut self, ctx: &LayoutContext) { let mut cur_y = Au(0); + self.box.map(|&box| { + do box.with_model |model| { + cur_y += model.margin.top + model.border.top + model.padding.top; + } + }); + for BlockFlow(self).each_child |kid| { do kid.with_mut_base |child_node| { child_node.position.origin.y = cur_y; @@ -245,9 +255,18 @@ impl BlockFlowData { cur_y }; + //TODO(eatkinson): compute heights using the 'height' property. self.common.position.size.height = height; self.box.map(|&box| { + do box.with_mut_base |base| { + //The associated box is the border box of this flow + base.position.origin.y = base.model.margin.top; + + let pb = base.model.padding.top + base.model.padding.bottom + + base.model.border.top + base.model.border.bottom; + base.position.size.height = height + pb; + } }); }