diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index 73b4f1a7c7e..6057a7a20bf 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -134,8 +134,8 @@ impl BlockFlowData { let (left_margin, right_margin) = match width{ Auto => (left_margin, right_margin), Specified(width) => { - let left = left_margin.spec_or_default(Au(0)); - let right = right_margin.spec_or_default(Au(0)); + let left = left_margin.specified_or_zero(); + let right = right_margin.specified_or_zero(); if((left + right + width) > available_width) { (Specified(left), Specified(right)) @@ -203,10 +203,10 @@ impl BlockFlowData { // Top and bottom margins for blocks are 0 if auto. let margin_top = MaybeAuto::from_margin(style.margin_top(), remaining_width, - style.font_size()).spec_or_default(Au(0)); + style.font_size()).specified_or_zero(); let margin_bottom = MaybeAuto::from_margin(style.margin_bottom(), remaining_width, - style.font_size()).spec_or_default(Au(0)); + style.font_size()).specified_or_zero(); let (width, margin_left, margin_right) = (MaybeAuto::from_width(style.width(), remaining_width, style.font_size()), @@ -300,7 +300,7 @@ impl BlockFlowData { for self.box.iter().advance |&box| { let style = box.style(); let maybe_height = MaybeAuto::from_height(style.height(), Au(0), style.font_size()); - let maybe_height = maybe_height.spec_or_default(Au(0)); + let maybe_height = maybe_height.specified_or_zero(); height = geometry::max(height, maybe_height); } diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index 73f0def93f9..eddca30c436 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -392,13 +392,13 @@ impl RenderBox { let font_size = style.font_size(); let w = MaybeAuto::from_width(style.width(), Au(0), - font_size).spec_or_default(Au(0)); + font_size).specified_or_zero(); let ml = MaybeAuto::from_margin(style.margin_left(), Au(0), - font_size).spec_or_default(Au(0)); + font_size).specified_or_zero(); let mr = MaybeAuto::from_margin(style.margin_right(), Au(0), - font_size).spec_or_default(Au(0)); + font_size).specified_or_zero(); let pl = base.model.compute_padding_length(style.padding_left(), Au(0), font_size); diff --git a/src/components/main/layout/float.rs b/src/components/main/layout/float.rs index 7f0399eef8e..9681f6e1f64 100644 --- a/src/components/main/layout/float.rs +++ b/src/components/main/layout/float.rs @@ -107,16 +107,16 @@ impl FloatFlowData { // Margins for floats are 0 if auto. let margin_top = MaybeAuto::from_margin(style.margin_top(), remaining_width, - style.font_size()).spec_or_default(Au(0)); + style.font_size()).specified_or_zero(); let margin_bottom = MaybeAuto::from_margin(style.margin_bottom(), remaining_width, - style.font_size()).spec_or_default(Au(0)); + style.font_size()).specified_or_zero(); let margin_left = MaybeAuto::from_margin(style.margin_left(), remaining_width, - style.font_size()).spec_or_default(Au(0)); + style.font_size()).specified_or_zero(); let margin_right = MaybeAuto::from_margin(style.margin_right(), remaining_width, - style.font_size()).spec_or_default(Au(0)); + style.font_size()).specified_or_zero(); @@ -127,7 +127,7 @@ impl FloatFlowData { let width = MaybeAuto::from_width(style.width(), remaining_width, - style.font_size()).spec_or_default(shrink_to_fit); + style.font_size()).specified_or_default(shrink_to_fit); debug!("assign_widths_float -- width: %?", width); model.margin.top = margin_top; @@ -205,7 +205,7 @@ impl FloatFlowData { let height_prop = MaybeAuto::from_height(box.style().height(), Au(0), - box.style().font_size()).spec_or_default(Au(0)); + box.style().font_size()).specified_or_zero(); height = geometry::max(height, height_prop) + noncontent_height; debug!("assign_height_float -- height: %?", height); diff --git a/src/components/main/layout/model.rs b/src/components/main/layout/model.rs index b3fc4d8d0c1..d7fd674f447 100644 --- a/src/components/main/layout/model.rs +++ b/src/components/main/layout/model.rs @@ -80,12 +80,16 @@ impl MaybeAuto { } } - pub fn spec_or_default(&self, default: Au) -> Au { + pub fn specified_or_default(&self, default: Au) -> Au { match *self { Auto => default, Specified(value) => value, } } + + pub fn specified_or_zero(&self) -> Au { + self.specified_or_default(Au(0)) + } } impl Zero for BoxModel {