Parse min-width and max-width

This commit is contained in:
Ilyong Cho 2013-10-29 20:09:46 +09:00
parent 6357b2fa1b
commit d73fc68209
2 changed files with 53 additions and 1 deletions

View file

@ -123,6 +123,35 @@ pub mod specified {
LengthOrPercentageOrAuto::parse_internal(input, /* negative_ok = */ false)
}
}
#[deriving(Clone)]
pub enum LengthOrPercentageOrNone {
LPN_Length(Length),
LPN_Percentage(CSSFloat), // [0 .. 100%] maps to [0.0 .. 1.0]
LPN_None,
}
impl LengthOrPercentageOrNone {
fn parse_internal(input: &ComponentValue, negative_ok: bool)
-> Option<LengthOrPercentageOrNone> {
match input {
&Dimension(ref value, ref unit) if negative_ok || value.value >= 0.
=> Length::parse_dimension(value.value, unit.as_slice()).map(LPN_Length),
&ast::Percentage(ref value) if negative_ok || value.value >= 0.
=> Some(LPN_Percentage(value.value / 100.)),
&Number(ref value) if value.value == 0. => Some(LPN_Length(Au_(Au(0)))),
&Ident(ref value) if value.eq_ignore_ascii_case("none") => Some(LPN_None),
_ => None
}
}
#[inline]
pub fn parse(input: &ComponentValue) -> Option<LengthOrPercentageOrNone> {
LengthOrPercentageOrNone::parse_internal(input, /* negative_ok = */ true)
}
#[inline]
pub fn parse_non_negative(input: &ComponentValue) -> Option<LengthOrPercentageOrNone> {
LengthOrPercentageOrNone::parse_internal(input, /* negative_ok = */ false)
}
}
}
pub mod computed {
@ -185,4 +214,19 @@ pub mod computed {
specified::LPA_Auto => LPA_Auto,
}
}
#[deriving(Eq, Clone)]
pub enum LengthOrPercentageOrNone {
LPN_Length(Au),
LPN_Percentage(CSSFloat),
LPN_None,
}
pub fn compute_LengthOrPercentageOrNone(value: specified::LengthOrPercentageOrNone,
context: &Context) -> LengthOrPercentageOrNone {
match value {
specified::LPN_Length(value) => LPN_Length(compute_Au(value, context)),
specified::LPN_Percentage(value) => LPN_Percentage(value),
specified::LPN_None => LPN_None,
}
}
}

View file

@ -267,6 +267,13 @@ pub mod longhands {
"computed::LPA_Auto",
"parse_non_negative")}
${predefined_type("min-width", "LengthOrPercentage",
"computed::LP_Length(Au(0))",
"parse_non_negative")}
${predefined_type("max-width", "LengthOrPercentageOrNone",
"computed::LPN_None",
"parse_non_negative")}
<%self:single_component_value name="line-height">
#[deriving(Clone)]
pub enum SpecifiedValue {
@ -1123,5 +1130,6 @@ pub mod computed_values {
pub use cssparser::RGBA;
pub use super::common_types::computed::{
LengthOrPercentage, LP_Length, LP_Percentage,
LengthOrPercentageOrAuto, LPA_Length, LPA_Percentage, LPA_Auto};
LengthOrPercentageOrAuto, LPA_Length, LPA_Percentage, LPA_Auto,
LengthOrPercentageOrNone, LPN_Length, LPN_Percentage, LPN_None};
}