diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index 0dee3e1c45f..03e9c62dcf7 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -106,8 +106,9 @@ impl BlockFlowData { these widths will not include child elements, just padding etc. */ self.box.map(|&box| { //Can compute border width here since it doesn't depend on anything + let style = box.style(); do box.with_model |model| { - model.compute_borders(box.style()) + model.compute_borders(style) } min_width = min_width.add(&box.get_min_width(ctx)); pref_width = pref_width.add(&box.get_pref_width(ctx)); @@ -184,17 +185,18 @@ impl BlockFlowData { let mut x_offset = Au(0); self.box.map(|&box| { + let style = box.style(); do box.with_model |model| { - model.compute_padding(box.style(), remaining_width); + model.compute_padding(style, remaining_width); let available_width = remaining_width - model.noncontent_width(); - let margin_top = MaybeAuto::from_margin(box.style().margin_top()).spec_or_default(Au(0)); - let margin_bottom = MaybeAuto::from_margin(box.style().margin_bottom()).spec_or_default(Au(0)); + 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)); - let (width, margin_left, margin_right) = (MaybeAuto::from_width(box.style().width()), - MaybeAuto::from_margin(box.style().margin_left()), - MaybeAuto::from_margin(box.style().margin_right())); + let (width, margin_left, margin_right) = (MaybeAuto::from_width(style.width()), + MaybeAuto::from_margin(style.margin_left()), + MaybeAuto::from_margin(style.margin_right())); let (width, margin_left, margin_right) = self.compute_horiz(width, margin_left, margin_right, available_width); diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index 2b825ba67a1..3cfeaa9c10e 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -8,7 +8,7 @@ use css::node_style::StyledNode; use layout::context::LayoutContext; use layout::display_list_builder::{DisplayListBuilder, ExtraDisplayListData, ToGfxColor}; use layout::flow::FlowContext; -use layout::model::{BoxModel}; +use layout::model::BoxModel; use layout::text; use core::cell::Cell; @@ -454,41 +454,15 @@ pub impl RenderBox { } } - fn compute_borders(&self){ - do self.with_mut_base |base| { - base.model.compute_borders(base.node.style()); - } - } - fn get_noncontent_width(&self) -> Au { do self.with_imm_base |base| { - base.model.border.left + base.model.padding.left + base.model.border.right + - base.model.padding.right - } - } - - fn compute_width(&self, - cb_width: Au, - callback: &fn(MaybeAuto, MaybeAuto, MaybeAuto) -> (Au, Au, Au)) { - let computed_width = MaybeAuto::from_width(self.style().width()); - let computed_margin_left = MaybeAuto::from_margin(self.style().margin_left()); - let computed_margin_right = MaybeAuto::from_margin(self.style().margin_right()); - - let (used_width, used_margin_left, used_margin_right) = - callback(computed_width, computed_margin_left, computed_margin_right); - - let noncontent_width = self.get_noncontent_width(); - - do self.with_mut_base |base| { - base.model.margin.left = used_margin_left; - base.model.margin.right = used_margin_right; - base.position.size.width = used_width + noncontent_width; - base.position.origin.x = used_margin_left; + base.model.border.left + base.model.padding.left + + base.model.border.right + base.model.padding.right } } fn with_model(&self, callback: &fn(&mut BoxModel) -> R) -> R { - do self.with_imm_base |base| { + do self.with_mut_base |base| { callback(&mut base.model) } } @@ -496,6 +470,15 @@ pub impl RenderBox { /// The box formed by the content edge as defined in CSS 2.1 § 8.1. Coordinates are relative to /// the owning flow. fn content_box(&self) -> Rect { + do self.with_imm_base |base| { + let origin = Point2D(base.position.origin.x + + base.model.border.left + + base.model.padding.left, + base.position.origin.y); + let size = Size2D(base.position.size.width - self.get_noncontent_width(), + base.position.size.height); + Rect(origin, size) + } } /// The box formed by the border edge as defined in CSS 2.1 § 8.1. Coordinates are relative to diff --git a/src/components/main/layout/model.rs b/src/components/main/layout/model.rs index 765ac12e5b1..cc38cffcc40 100644 --- a/src/components/main/layout/model.rs +++ b/src/components/main/layout/model.rs @@ -31,12 +31,12 @@ pub struct BoxModel { } /// Useful helper data type when computing values for blocks and positioned elements. -pub enum MaybeAuto{ +pub enum MaybeAuto { Auto, Specified(Au), } -impl MaybeAuto{ +impl MaybeAuto { pub fn from_margin(margin: CSSMargin) -> MaybeAuto{ match margin { CSSMarginAuto => Auto, diff --git a/src/support/css/rust-css b/src/support/css/rust-css index 7a59bc7f27a..2f3f03cbafb 160000 --- a/src/support/css/rust-css +++ b/src/support/css/rust-css @@ -1 +1 @@ -Subproject commit 7a59bc7f27a2135668b9ca0f681f31a17dd68879 +Subproject commit 2f3f03cbafb88608d4f89216da7172d3b754fbef