mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Implement Calc for LengthOrPercentageOrAuto
This commit is contained in:
parent
9556141e57
commit
cb4d878169
7 changed files with 44 additions and 0 deletions
|
@ -490,6 +490,7 @@ pub mod specified {
|
|||
Length(Length),
|
||||
Percentage(CSSFloat), // [0 .. 100%] maps to [0.0 .. 1.0]
|
||||
Auto,
|
||||
Calc(Calc),
|
||||
}
|
||||
|
||||
impl ToCss for LengthOrPercentageOrAuto {
|
||||
|
@ -499,6 +500,7 @@ pub mod specified {
|
|||
&LengthOrPercentageOrAuto::Percentage(percentage)
|
||||
=> write!(dest, "{}%", percentage * 100.),
|
||||
&LengthOrPercentageOrAuto::Auto => dest.write_str("auto"),
|
||||
&LengthOrPercentageOrAuto::Calc(calc) => calc.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -516,6 +518,10 @@ pub mod specified {
|
|||
Ok(LengthOrPercentageOrAuto::Length(Length::Absolute(Au(0)))),
|
||||
Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") =>
|
||||
Ok(LengthOrPercentageOrAuto::Auto),
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
|
||||
let calc = try!(input.parse_nested_block(Calc::parse));
|
||||
Ok(LengthOrPercentageOrAuto::Calc(calc))
|
||||
},
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
|
@ -1122,6 +1128,7 @@ pub mod computed {
|
|||
Length(Au),
|
||||
Percentage(CSSFloat),
|
||||
Auto,
|
||||
Calc(Calc),
|
||||
}
|
||||
impl fmt::Debug for LengthOrPercentageOrAuto {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
@ -1129,6 +1136,8 @@ pub mod computed {
|
|||
&LengthOrPercentageOrAuto::Length(length) => write!(f, "{:?}", length),
|
||||
&LengthOrPercentageOrAuto::Percentage(percentage) => write!(f, "{}%", percentage * 100.),
|
||||
&LengthOrPercentageOrAuto::Auto => write!(f, "auto"),
|
||||
// XXX HACK WRONG
|
||||
&LengthOrPercentageOrAuto::Calc(calc) => write!(f, "{}%", 100.),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1148,6 +1157,9 @@ pub mod computed {
|
|||
specified::LengthOrPercentageOrAuto::Auto => {
|
||||
LengthOrPercentageOrAuto::Auto
|
||||
}
|
||||
specified::LengthOrPercentageOrAuto::Calc(calc) => {
|
||||
LengthOrPercentageOrAuto::Calc(calc.to_computed_value(context))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1159,6 +1171,7 @@ pub mod computed {
|
|||
&LengthOrPercentageOrAuto::Percentage(percentage)
|
||||
=> write!(dest, "{}%", percentage * 100.),
|
||||
&LengthOrPercentageOrAuto::Auto => dest.write_str("auto"),
|
||||
&LengthOrPercentageOrAuto::Calc(calc) => calc.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue