From 9a1d4d593bda3a6c8f1353cceb679091f7008698 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 18 Jul 2013 19:31:52 -0600 Subject: [PATCH 1/5] Properly account for relative CSS units in borders, margins, padding, and widths. --- src/components/main/layout/block.rs | 14 ++-- src/components/main/layout/box.rs | 27 ++++--- src/components/main/layout/float.rs | 20 ++++-- src/components/main/layout/model.rs | 107 ++++++++++++++++------------ src/support/css/rust-css | 2 +- 5 files changed, 103 insertions(+), 67 deletions(-) diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index c73cbb2a494..73b4f1a7c7e 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -202,14 +202,16 @@ impl BlockFlowData { // Top and bottom margins for blocks are 0 if auto. let margin_top = MaybeAuto::from_margin(style.margin_top(), - remaining_width).spec_or_default(Au(0)); + remaining_width, + style.font_size()).spec_or_default(Au(0)); let margin_bottom = MaybeAuto::from_margin(style.margin_bottom(), - remaining_width).spec_or_default(Au(0)); + remaining_width, + style.font_size()).spec_or_default(Au(0)); let (width, margin_left, margin_right) = - (MaybeAuto::from_width(style.width(), remaining_width), - MaybeAuto::from_margin(style.margin_left(), remaining_width), - MaybeAuto::from_margin(style.margin_right(), remaining_width)); + (MaybeAuto::from_width(style.width(), remaining_width, style.font_size()), + MaybeAuto::from_margin(style.margin_left(), remaining_width, style.font_size()), + MaybeAuto::from_margin(style.margin_right(), remaining_width, style.font_size())); let (width, margin_left, margin_right) = self.compute_horiz(width, margin_left, @@ -297,7 +299,7 @@ impl BlockFlowData { for self.box.iter().advance |&box| { let style = box.style(); - let maybe_height = MaybeAuto::from_height(style.height(), Au(0)); + let maybe_height = MaybeAuto::from_height(style.height(), Au(0), style.font_size()); let maybe_height = maybe_height.spec_or_default(Au(0)); height = geometry::max(height, maybe_height); } diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index fe4cd77aa89..73f0def93f9 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -388,14 +388,25 @@ impl RenderBox { if(!base.node.is_element()) { Au(0) } else { - - let w = MaybeAuto::from_width(self.style().width(), Au(0)).spec_or_default(Au(0)); - let ml = MaybeAuto::from_margin(self.style().margin_left(), Au(0)).spec_or_default(Au(0)); - let mr = MaybeAuto::from_margin(self.style().margin_right(), Au(0)).spec_or_default(Au(0)); - let pl = base.model.compute_padding_length(self.style().padding_left(), Au(0)); - let pr = base.model.compute_padding_length(self.style().padding_right(), Au(0)); - let bl = base.model.compute_border_width(self.style().border_left_width()); - let br = base.model.compute_border_width(self.style().border_right_width()); + let style = self.style(); + let font_size = style.font_size(); + let w = MaybeAuto::from_width(style.width(), + Au(0), + font_size).spec_or_default(Au(0)); + let ml = MaybeAuto::from_margin(style.margin_left(), + Au(0), + font_size).spec_or_default(Au(0)); + let mr = MaybeAuto::from_margin(style.margin_right(), + Au(0), + font_size).spec_or_default(Au(0)); + let pl = base.model.compute_padding_length(style.padding_left(), + Au(0), + font_size); + let pr = base.model.compute_padding_length(style.padding_right(), + Au(0), + font_size); + let bl = base.model.compute_border_width(style.border_left_width(), font_size); + let br = base.model.compute_border_width(style.border_right_width(), font_size); w + ml + mr + pl + pr + bl + br } diff --git a/src/components/main/layout/float.rs b/src/components/main/layout/float.rs index 898ce9ebfe2..7f0399eef8e 100644 --- a/src/components/main/layout/float.rs +++ b/src/components/main/layout/float.rs @@ -106,13 +106,17 @@ impl FloatFlowData { // Margins for floats are 0 if auto. let margin_top = MaybeAuto::from_margin(style.margin_top(), - remaining_width).spec_or_default(Au(0)); + remaining_width, + style.font_size()).spec_or_default(Au(0)); let margin_bottom = MaybeAuto::from_margin(style.margin_bottom(), - remaining_width).spec_or_default(Au(0)); + remaining_width, + style.font_size()).spec_or_default(Au(0)); let margin_left = MaybeAuto::from_margin(style.margin_left(), - remaining_width).spec_or_default(Au(0)); + remaining_width, + style.font_size()).spec_or_default(Au(0)); let margin_right = MaybeAuto::from_margin(style.margin_right(), - remaining_width).spec_or_default(Au(0)); + remaining_width, + style.font_size()).spec_or_default(Au(0)); @@ -122,7 +126,8 @@ impl FloatFlowData { let width = MaybeAuto::from_width(style.width(), - remaining_width).spec_or_default(shrink_to_fit); + remaining_width, + style.font_size()).spec_or_default(shrink_to_fit); debug!("assign_widths_float -- width: %?", width); model.margin.top = margin_top; @@ -197,9 +202,10 @@ impl FloatFlowData { //TODO(eatkinson): compute heights properly using the 'height' property. for self.box.iter().advance |&box| { - let height_prop = - MaybeAuto::from_height(box.style().height(), Au(0)).spec_or_default(Au(0)); + MaybeAuto::from_height(box.style().height(), + Au(0), + box.style().font_size()).spec_or_default(Au(0)); 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 4bd45dabe17..b3fc4d8d0c1 100644 --- a/src/components/main/layout/model.rs +++ b/src/components/main/layout/model.rs @@ -10,7 +10,7 @@ use gfx::geometry::Au; use newcss::complete::CompleteStyle; use newcss::units::{Em, Pt, Px}; use newcss::values::{CSSBorderWidth, CSSBorderWidthLength, CSSBorderWidthMedium}; -use newcss::values::{CSSBorderWidthThick, CSSBorderWidthThin}; +use newcss::values::{CSSBorderWidthThick, CSSBorderWidthThin, CSSFontSize, CSSFontSizeLength}; use newcss::values::{CSSWidth, CSSWidthLength, CSSWidthPercentage, CSSWidthAuto}; use newcss::values::{CSSHeight, CSSHeightLength, CSSHeightPercentage, CSSHeightAuto}; use newcss::values::{CSSMargin, CSSMarginLength, CSSMarginPercentage, CSSMarginAuto}; @@ -30,45 +30,60 @@ pub enum MaybeAuto { Specified(Au), } -impl MaybeAuto{ - pub fn from_margin(margin: CSSMargin, cb_width: Au) -> MaybeAuto{ +impl MaybeAuto { + pub fn from_margin(margin: CSSMargin, cb_width: Au, font_size: CSSFontSize) -> MaybeAuto { match margin { CSSMarginAuto => Auto, - //FIXME(eatkinson): Compute percents properly CSSMarginPercentage(percent) => Specified(cb_width.scale_by(percent/100.0)), - //FIXME(eatkinson): Compute pt and em values properly - CSSMarginLength(Px(v)) | - CSSMarginLength(Pt(v)) | - CSSMarginLength(Em(v)) => Specified(Au::from_frac_px(v)), + CSSMarginLength(Px(v)) => Specified(Au::from_frac_px(v)), + CSSMarginLength(Pt(v)) => Specified(Au::from_pt(v)), + CSSMarginLength(Em(em)) => match font_size { + CSSFontSizeLength(Px(v)) => + Specified(Au::from_frac_px(em * v)), + CSSFontSizeLength(Pt(v)) => + Specified(Au::from_pt(em * v)), + _ => fail!(~"expected non-relative font size"), + } } } - pub fn from_width(width: CSSWidth, cb_width: Au) -> MaybeAuto{ - match width{ + pub fn from_width(width: CSSWidth, cb_width: Au, font_size: CSSFontSize) -> MaybeAuto { + match width { CSSWidthAuto => Auto, CSSWidthPercentage(percent) => Specified(cb_width.scale_by(percent/100.0)), - //FIXME(eatkinson): Compute pt and em values properly - CSSWidthLength(Px(v)) | - CSSWidthLength(Pt(v)) | - CSSWidthLength(Em(v)) => Specified(Au::from_frac_px(v)), + CSSWidthLength(Px(v)) => Specified(Au::from_frac_px(v)), + CSSWidthLength(Pt(v)) => Specified(Au::from_pt(v)), + CSSWidthLength(Em(em)) => match font_size { + CSSFontSizeLength(Px(v)) => + Specified(Au::from_frac_px(em * v)), + CSSFontSizeLength(Pt(v)) => + Specified(Au::from_pt(em * v)), + _ => fail!(~"expected non-relative font size"), + } } } - pub fn from_height(height: CSSHeight, cb_height: Au) -> MaybeAuto{ + pub fn from_height(height: CSSHeight, cb_height: Au, font_size: CSSFontSize) -> MaybeAuto { match height { CSSHeightAuto => Auto, CSSHeightPercentage(percent) => Specified(cb_height.scale_by(percent/100.0)), - //FIXME(eatkinson): Compute pt and em values properly - CSSHeightLength(Px(v)) | - CSSHeightLength(Pt(v)) | - CSSHeightLength(Em(v)) => Specified(Au::from_frac_px(v)), + CSSHeightLength(Px(v)) => Specified(Au::from_frac_px(v)), + CSSHeightLength(Pt(v)) => Specified(Au::from_pt(v)), + CSSHeightLength(Em(em)) => match font_size { + CSSFontSizeLength(Px(v)) => + Specified(Au::from_frac_px(em * v)), + CSSFontSizeLength(Pt(v)) => + Specified(Au::from_pt(em * v)), + _ => fail!(~"expected non-relative font size"), + } + } } - pub fn spec_or_default(&self, default: Au) -> Au{ - match *self{ + pub fn spec_or_default(&self, default: Au) -> Au { + match *self { Auto => default, - Specified(value) => value + Specified(value) => value, } } } @@ -92,17 +107,17 @@ impl BoxModel { /// Populates the box model parameters from the given computed style. pub fn compute_borders(&mut self, style: CompleteStyle) { // Compute the borders. - self.border.top = self.compute_border_width(style.border_top_width()); - self.border.right = self.compute_border_width(style.border_right_width()); - self.border.bottom = self.compute_border_width(style.border_bottom_width()); - self.border.left = self.compute_border_width(style.border_left_width()); + self.border.top = self.compute_border_width(style.border_top_width(), style.font_size()); + self.border.right = self.compute_border_width(style.border_right_width(), style.font_size()); + self.border.bottom = self.compute_border_width(style.border_bottom_width(), style.font_size()); + self.border.left = self.compute_border_width(style.border_left_width(), style.font_size()); } - pub fn compute_padding(&mut self, style: CompleteStyle, cb_width: Au){ - self.padding.top = self.compute_padding_length(style.padding_top(), cb_width); - self.padding.right = self.compute_padding_length(style.padding_right(), cb_width); - self.padding.bottom = self.compute_padding_length(style.padding_bottom(), cb_width); - self.padding.left = self.compute_padding_length(style.padding_left(), cb_width); + pub fn compute_padding(&mut self, style: CompleteStyle, cb_width: Au) { + self.padding.top = self.compute_padding_length(style.padding_top(), cb_width, style.font_size()); + self.padding.right = self.compute_padding_length(style.padding_right(), cb_width, style.font_size()); + self.padding.bottom = self.compute_padding_length(style.padding_bottom(), cb_width, style.font_size()); + self.padding.left = self.compute_padding_length(style.padding_left(), cb_width, style.font_size()); } pub fn noncontent_width(&self) -> Au { @@ -116,28 +131,30 @@ impl BoxModel { } /// Helper function to compute the border width in app units from the CSS border width. - pub fn compute_border_width(&self, width: CSSBorderWidth) -> Au { + pub fn compute_border_width(&self, width: CSSBorderWidth, font_size: CSSFontSize) -> Au { match width { - CSSBorderWidthLength(Px(v)) | - CSSBorderWidthLength(Em(v)) | - CSSBorderWidthLength(Pt(v)) => { - // FIXME(pcwalton): Handle `em` and `pt` correctly. - Au::from_frac_px(v) - } + CSSBorderWidthLength(Px(v)) => Au::from_frac_px(v), + CSSBorderWidthLength(Pt(v)) => Au::from_pt(v), + CSSBorderWidthLength(Em(em)) => match font_size { + CSSFontSizeLength(Px(v)) => Au::from_frac_px(em * v), + CSSFontSizeLength(Pt(v)) => Au::from_pt(em * v), + _ => fail!(~"expected non-relative font size"), + }, CSSBorderWidthThin => Au::from_px(1), CSSBorderWidthMedium => Au::from_px(5), CSSBorderWidthThick => Au::from_px(10), } } - pub fn compute_padding_length(&self, padding: CSSPadding, content_box_width: Au) -> Au { + pub fn compute_padding_length(&self, padding: CSSPadding, content_box_width: Au, font_size: CSSFontSize) -> Au { match padding { - CSSPaddingLength(Px(v)) | - CSSPaddingLength(Pt(v)) | - CSSPaddingLength(Em(v)) => { - // FIXME(eatkinson): Handle 'em' and 'pt' correctly - Au::from_frac_px(v) - } + CSSPaddingLength(Px(v)) => Au::from_frac_px(v), + CSSPaddingLength(Pt(v)) => Au::from_pt(v), + CSSPaddingLength(Em(em)) => match font_size { + CSSFontSizeLength(Px(v)) => Au::from_frac_px(em * v), + CSSFontSizeLength(Pt(v)) => Au::from_pt(em * v), + _ => fail!(~"expected non-relative font size"), + }, CSSPaddingPercentage(p) => content_box_width.scale_by(p/100.0) } } diff --git a/src/support/css/rust-css b/src/support/css/rust-css index 7a584804a98..8b9cf93fb03 160000 --- a/src/support/css/rust-css +++ b/src/support/css/rust-css @@ -1 +1 @@ -Subproject commit 7a584804a98b5731fb53d216c3f059e5a0c7ea5c +Subproject commit 8b9cf93fb03027d0f125afbd84cf758bd8d2d676 From 4d1e21bd8e9bddd576c3b60c02c0d341982068a7 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 18 Jul 2013 20:02:22 -0600 Subject: [PATCH 2/5] Renaming and refactoring `spec_or_default`. `spec_or_default` is now `specified_or_default` and `specified_or_zero` was added to handle the most common case. --- src/components/main/layout/block.rs | 10 +++++----- src/components/main/layout/box.rs | 6 +++--- src/components/main/layout/float.rs | 12 ++++++------ src/components/main/layout/model.rs | 6 +++++- 4 files changed, 19 insertions(+), 15 deletions(-) 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 { From b2c042df946d6c0223d44db598ad5e0186c0b1d1 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 18 Jul 2013 20:05:32 -0600 Subject: [PATCH 3/5] Brace multi-line match patterns per coding style. --- src/components/main/layout/model.rs | 56 +++++++++++++++-------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/components/main/layout/model.rs b/src/components/main/layout/model.rs index d7fd674f447..6aa21c9d6ba 100644 --- a/src/components/main/layout/model.rs +++ b/src/components/main/layout/model.rs @@ -37,12 +37,12 @@ impl MaybeAuto { CSSMarginPercentage(percent) => Specified(cb_width.scale_by(percent/100.0)), CSSMarginLength(Px(v)) => Specified(Au::from_frac_px(v)), CSSMarginLength(Pt(v)) => Specified(Au::from_pt(v)), - CSSMarginLength(Em(em)) => match font_size { - CSSFontSizeLength(Px(v)) => - Specified(Au::from_frac_px(em * v)), - CSSFontSizeLength(Pt(v)) => - Specified(Au::from_pt(em * v)), - _ => fail!(~"expected non-relative font size"), + CSSMarginLength(Em(em)) => { + match font_size { + CSSFontSizeLength(Px(v)) => Specified(Au::from_frac_px(em * v)), + CSSFontSizeLength(Pt(v)) => Specified(Au::from_pt(em * v)), + _ => fail!(~"expected non-relative font size"), + } } } } @@ -53,12 +53,12 @@ impl MaybeAuto { CSSWidthPercentage(percent) => Specified(cb_width.scale_by(percent/100.0)), CSSWidthLength(Px(v)) => Specified(Au::from_frac_px(v)), CSSWidthLength(Pt(v)) => Specified(Au::from_pt(v)), - CSSWidthLength(Em(em)) => match font_size { - CSSFontSizeLength(Px(v)) => - Specified(Au::from_frac_px(em * v)), - CSSFontSizeLength(Pt(v)) => - Specified(Au::from_pt(em * v)), - _ => fail!(~"expected non-relative font size"), + CSSWidthLength(Em(em)) => { + match font_size { + CSSFontSizeLength(Px(v)) => Specified(Au::from_frac_px(em * v)), + CSSFontSizeLength(Pt(v)) => Specified(Au::from_pt(em * v)), + _ => fail!(~"expected non-relative font size"), + } } } } @@ -69,12 +69,12 @@ impl MaybeAuto { CSSHeightPercentage(percent) => Specified(cb_height.scale_by(percent/100.0)), CSSHeightLength(Px(v)) => Specified(Au::from_frac_px(v)), CSSHeightLength(Pt(v)) => Specified(Au::from_pt(v)), - CSSHeightLength(Em(em)) => match font_size { - CSSFontSizeLength(Px(v)) => - Specified(Au::from_frac_px(em * v)), - CSSFontSizeLength(Pt(v)) => - Specified(Au::from_pt(em * v)), - _ => fail!(~"expected non-relative font size"), + CSSHeightLength(Em(em)) => { + match font_size { + CSSFontSizeLength(Px(v)) => Specified(Au::from_frac_px(em * v)), + CSSFontSizeLength(Pt(v)) => Specified(Au::from_pt(em * v)), + _ => fail!(~"expected non-relative font size"), + } } } @@ -139,10 +139,12 @@ impl BoxModel { match width { CSSBorderWidthLength(Px(v)) => Au::from_frac_px(v), CSSBorderWidthLength(Pt(v)) => Au::from_pt(v), - CSSBorderWidthLength(Em(em)) => match font_size { - CSSFontSizeLength(Px(v)) => Au::from_frac_px(em * v), - CSSFontSizeLength(Pt(v)) => Au::from_pt(em * v), - _ => fail!(~"expected non-relative font size"), + CSSBorderWidthLength(Em(em)) => { + match font_size { + CSSFontSizeLength(Px(v)) => Au::from_frac_px(em * v), + CSSFontSizeLength(Pt(v)) => Au::from_pt(em * v), + _ => fail!(~"expected non-relative font size"), + } }, CSSBorderWidthThin => Au::from_px(1), CSSBorderWidthMedium => Au::from_px(5), @@ -154,10 +156,12 @@ impl BoxModel { match padding { CSSPaddingLength(Px(v)) => Au::from_frac_px(v), CSSPaddingLength(Pt(v)) => Au::from_pt(v), - CSSPaddingLength(Em(em)) => match font_size { - CSSFontSizeLength(Px(v)) => Au::from_frac_px(em * v), - CSSFontSizeLength(Pt(v)) => Au::from_pt(em * v), - _ => fail!(~"expected non-relative font size"), + CSSPaddingLength(Em(em)) => { + match font_size { + CSSFontSizeLength(Px(v)) => Au::from_frac_px(em * v), + CSSFontSizeLength(Pt(v)) => Au::from_pt(em * v), + _ => fail!(~"expected non-relative font size"), + } }, CSSPaddingPercentage(p) => content_box_width.scale_by(p/100.0) } From e10b36210c3431897b3e70afc8d4f9d225418c30 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 18 Jul 2013 20:11:10 -0600 Subject: [PATCH 4/5] Rename `cb_width` to `containing_width`. --- src/components/main/layout/model.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/main/layout/model.rs b/src/components/main/layout/model.rs index 6aa21c9d6ba..148223a2a3d 100644 --- a/src/components/main/layout/model.rs +++ b/src/components/main/layout/model.rs @@ -31,10 +31,10 @@ pub enum MaybeAuto { } impl MaybeAuto { - pub fn from_margin(margin: CSSMargin, cb_width: Au, font_size: CSSFontSize) -> MaybeAuto { + pub fn from_margin(margin: CSSMargin, containing_width: Au, font_size: CSSFontSize) -> MaybeAuto { match margin { CSSMarginAuto => Auto, - CSSMarginPercentage(percent) => Specified(cb_width.scale_by(percent/100.0)), + CSSMarginPercentage(percent) => Specified(containing_width.scale_by(percent/100.0)), CSSMarginLength(Px(v)) => Specified(Au::from_frac_px(v)), CSSMarginLength(Pt(v)) => Specified(Au::from_pt(v)), CSSMarginLength(Em(em)) => { @@ -47,10 +47,10 @@ impl MaybeAuto { } } - pub fn from_width(width: CSSWidth, cb_width: Au, font_size: CSSFontSize) -> MaybeAuto { + pub fn from_width(width: CSSWidth, containing_width: Au, font_size: CSSFontSize) -> MaybeAuto { match width { CSSWidthAuto => Auto, - CSSWidthPercentage(percent) => Specified(cb_width.scale_by(percent/100.0)), + CSSWidthPercentage(percent) => Specified(containing_width.scale_by(percent/100.0)), CSSWidthLength(Px(v)) => Specified(Au::from_frac_px(v)), CSSWidthLength(Pt(v)) => Specified(Au::from_pt(v)), CSSWidthLength(Em(em)) => { @@ -117,11 +117,11 @@ impl BoxModel { self.border.left = self.compute_border_width(style.border_left_width(), style.font_size()); } - pub fn compute_padding(&mut self, style: CompleteStyle, cb_width: Au) { - self.padding.top = self.compute_padding_length(style.padding_top(), cb_width, style.font_size()); - self.padding.right = self.compute_padding_length(style.padding_right(), cb_width, style.font_size()); - self.padding.bottom = self.compute_padding_length(style.padding_bottom(), cb_width, style.font_size()); - self.padding.left = self.compute_padding_length(style.padding_left(), cb_width, style.font_size()); + pub fn compute_padding(&mut self, style: CompleteStyle, containing_width: Au) { + self.padding.top = self.compute_padding_length(style.padding_top(), containing_width, style.font_size()); + self.padding.right = self.compute_padding_length(style.padding_right(), containing_width, style.font_size()); + self.padding.bottom = self.compute_padding_length(style.padding_bottom(), containing_width, style.font_size()); + self.padding.left = self.compute_padding_length(style.padding_left(), containing_width, style.font_size()); } pub fn noncontent_width(&self) -> Au { From 11af5ffda6c17a6ed1bc95822ad1e17126255235 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 18 Jul 2013 20:11:35 -0600 Subject: [PATCH 5/5] Rename variables for clarity. --- src/components/main/layout/box.rs | 39 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index eddca30c436..1839d93dfc0 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -390,25 +390,28 @@ impl RenderBox { } else { let style = self.style(); let font_size = style.font_size(); - let w = MaybeAuto::from_width(style.width(), - Au(0), - font_size).specified_or_zero(); - let ml = MaybeAuto::from_margin(style.margin_left(), - Au(0), - font_size).specified_or_zero(); - let mr = MaybeAuto::from_margin(style.margin_right(), - Au(0), - font_size).specified_or_zero(); - let pl = base.model.compute_padding_length(style.padding_left(), - Au(0), - font_size); - let pr = base.model.compute_padding_length(style.padding_right(), - Au(0), - font_size); - let bl = base.model.compute_border_width(style.border_left_width(), font_size); - let br = base.model.compute_border_width(style.border_right_width(), font_size); + let width = MaybeAuto::from_width(style.width(), + Au(0), + font_size).specified_or_zero(); + let margin_left = MaybeAuto::from_margin(style.margin_left(), + Au(0), + font_size).specified_or_zero(); + let margin_right = MaybeAuto::from_margin(style.margin_right(), + Au(0), + font_size).specified_or_zero(); + let padding_left = base.model.compute_padding_length(style.padding_left(), + Au(0), + font_size); + let padding_right = base.model.compute_padding_length(style.padding_right(), + Au(0), + font_size); + let border_left = base.model.compute_border_width(style.border_left_width(), + font_size); + let border_right = base.model.compute_border_width(style.border_right_width(), + font_size); - w + ml + mr + pl + pr + bl + br + width + margin_left + margin_right + padding_left + padding_right + + border_left + border_right } } }