Change the range of percentages to 0..1 in specified and computed values.

This commit is contained in:
Simon Sapin 2013-10-14 19:41:43 +01:00
parent 2fe127f880
commit 9a0cabb38c
2 changed files with 5 additions and 5 deletions

View file

@ -69,7 +69,7 @@ pub mod specified {
#[deriving(Clone)] #[deriving(Clone)]
pub enum LengthOrPercentage { pub enum LengthOrPercentage {
LP_Length(Length), LP_Length(Length),
LP_Percentage(Float), LP_Percentage(Float), // [0 .. 100%] maps to [0.0 .. 1.0]
} }
impl LengthOrPercentage { impl LengthOrPercentage {
fn parse_internal(input: &ComponentValue, negative_ok: bool) fn parse_internal(input: &ComponentValue, negative_ok: bool)
@ -78,7 +78,7 @@ pub mod specified {
&Dimension(ref value, ref unit) if negative_ok || value.value >= 0. &Dimension(ref value, ref unit) if negative_ok || value.value >= 0.
=> Length::parse_dimension(value.value, unit.as_slice()).map_move(LP_Length), => Length::parse_dimension(value.value, unit.as_slice()).map_move(LP_Length),
&ast::Percentage(ref value) if negative_ok || value.value >= 0. &ast::Percentage(ref value) if negative_ok || value.value >= 0.
=> Some(LP_Percentage(value.value)), => Some(LP_Percentage(value.value / 100.)),
&Number(ref value) if value.value == 0. => Some(LP_Length(Au(0))), &Number(ref value) if value.value == 0. => Some(LP_Length(Au(0))),
_ => None _ => None
} }
@ -96,7 +96,7 @@ pub mod specified {
#[deriving(Clone)] #[deriving(Clone)]
pub enum LengthOrPercentageOrAuto { pub enum LengthOrPercentageOrAuto {
LPA_Length(Length), LPA_Length(Length),
LPA_Percentage(Float), LPA_Percentage(Float), // [0 .. 100%] maps to [0.0 .. 1.0]
LPA_Auto, LPA_Auto,
} }
impl LengthOrPercentageOrAuto { impl LengthOrPercentageOrAuto {
@ -106,7 +106,7 @@ pub mod specified {
&Dimension(ref value, ref unit) if negative_ok || value.value >= 0. &Dimension(ref value, ref unit) if negative_ok || value.value >= 0.
=> Length::parse_dimension(value.value, unit.as_slice()).map_move(LPA_Length), => Length::parse_dimension(value.value, unit.as_slice()).map_move(LPA_Length),
&ast::Percentage(ref value) if negative_ok || value.value >= 0. &ast::Percentage(ref value) if negative_ok || value.value >= 0.
=> Some(LPA_Percentage(value.value)), => Some(LPA_Percentage(value.value / 100.)),
&Number(ref value) if value.value == 0. => Some(LPA_Length(Au(0))), &Number(ref value) if value.value == 0. => Some(LPA_Length(Au(0))),
&Ident(ref value) if value.eq_ignore_ascii_case("auto") => Some(LPA_Auto), &Ident(ref value) if value.eq_ignore_ascii_case("auto") => Some(LPA_Auto),
_ => None _ => None

View file

@ -240,7 +240,7 @@ pub mod longhands {
&ast::Number(ref value) if value.value >= 0. &ast::Number(ref value) if value.value >= 0.
=> Some(SpecifiedNumber(value.value)), => Some(SpecifiedNumber(value.value)),
&ast::Percentage(ref value) if value.value >= 0. &ast::Percentage(ref value) if value.value >= 0.
=> Some(SpecifiedLength(specified::Em(value.value))), => Some(SpecifiedLength(specified::Em(value.value / 100.))),
&Dimension(ref value, ref unit) if value.value >= 0. &Dimension(ref value, ref unit) if value.value >= 0.
=> specified::Length::parse_dimension(value.value, unit.as_slice()) => specified::Length::parse_dimension(value.value, unit.as_slice())
.map_move(SpecifiedLength), .map_move(SpecifiedLength),