From 75a6958d1c8f4f345193d71101041911fde437d8 Mon Sep 17 00:00:00 2001 From: Eric Atkinson Date: Fri, 31 May 2013 18:24:42 -0700 Subject: [PATCH] Allow margins, widths, heights, and padding to take on percent values --- computed.rs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/computed.rs b/computed.rs index 973246b..cbb8185 100644 --- a/computed.rs +++ b/computed.rs @@ -187,7 +187,13 @@ fn convert_net_border_width(width: n::v::CssBorderWidthValue) -> CSSValue CSSValue { match margin { n::v::CssMarginInherit => Inherit, - n::v::CssMarginSet(length) => Specified(CSSMarginLength(convert_net_unit_to_length(length))), + n::v::CssMarginSet(value) => { + let length = convert_net_unit_to_length_or_percent(value); + match length { + Left(abs) => Specified(CSSMarginLength(abs)), + Right(percent) => Specified(CSSMarginPercentage(percent)) + } + } n::v::CssMarginAuto => Specified(CSSMarginAuto) } } @@ -195,14 +201,26 @@ fn convert_net_margin(margin: n::v::CssMarginValue) -> CSSValue { fn convert_net_padding(padding: n::v::CssPaddingValue) -> CSSValue { match padding { n::v::CssPaddingInherit => Inherit, - n::v::CssPaddingSet(length) => Specified(CSSPaddingLength(convert_net_unit_to_length(length))) + n::v::CssPaddingSet(value) => { + let length = convert_net_unit_to_length_or_percent(value); + match length { + Left(abs) => Specified(CSSPaddingLength(abs)), + Right(percent) => Specified(CSSPaddingPercentage(percent)) + } + } } } fn convert_net_width_value(value: n::v::CssWidthValue) -> CSSValue { match value { n::v::CssWidthInherit => Inherit, - n::v::CssWidthSet(length) => Specified(CSSWidthLength(convert_net_unit_to_length(length))), + n::v::CssWidthSet(value) => { + let length = convert_net_unit_to_length_or_percent(value); + match length { + Left(abs) => Specified(CSSWidthLength(abs)), + Right(percent) => Specified(CSSWidthPercentage(percent)) + } + } n::v::CssWidthAuto => Specified(CSSWidthAuto) } } @@ -210,7 +228,13 @@ fn convert_net_width_value(value: n::v::CssWidthValue) -> CSSValue { fn convert_net_height_value(value: n::v::CssHeightValue) -> CSSValue { match value { n::v::CssHeightInherit => Inherit, - n::v::CssHeightSet(length) => Specified(CSSHeightLength(convert_net_unit_to_length(length))), + n::v::CssHeightSet(value) => { + let length = convert_net_unit_to_length_or_percent(value); + match length { + Left(abs) => Specified(CSSHeightLength(abs)), + Right(percent) => Specified(CSSHeightPercentage(percent)) + } + } n::v::CssHeightAuto => Specified(CSSHeightAuto) } } @@ -364,7 +388,7 @@ fn convert_net_line_height_value(value: n::v::CssLineHeightValue) -> CSSValue Length { match convert_net_unit_to_length_or_percent(unit) { Left(v) => v, - Right(*) => Px(100.0), // FIXME(pcwalton): fill this in. + Right(*) => fail!(~"unexpected percentage unit"), } }