Address review comments

This commit is contained in:
David Zbarsky 2015-08-23 00:48:07 -04:00
parent 5ac205b3e5
commit cdae523cd4
8 changed files with 97 additions and 25 deletions

View file

@ -1908,15 +1908,14 @@ pub mod longhands {
}
/// <length> | <percentage> | <absolute-size> | <relative-size>
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
input.try(specified::LengthOrPercentage::parse_non_negative)
.map(|value| match value {
specified::LengthOrPercentage::Length(value) => value,
let value = try!(input.try(specified::LengthOrPercentage::parse_non_negative));
match value {
specified::LengthOrPercentage::Length(value) => Ok(value),
specified::LengthOrPercentage::Percentage(value) =>
specified::Length::FontRelative(specified::FontRelativeLength::Em(value.0)),
Ok(specified::Length::FontRelative(specified::FontRelativeLength::Em(value.0))),
// FIXME(dzbarsky) handle calc for font-size
specified::LengthOrPercentage::Calc(_) =>
specified::Length::FontRelative(specified::FontRelativeLength::Em(1.)),
})
specified::LengthOrPercentage::Calc(_) => return Err(())
}
.or_else(|()| {
match_ignore_ascii_case! { try!(input.expect_ident()),
"xx-small" => Ok(specified::Length::Absolute(Au::from_px(MEDIUM_PX) * 3 / 5)),

View file

@ -1300,7 +1300,7 @@ pub mod computed {
impl ::cssparser::ToCss for Calc {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match (self.length, self.percentage) {
(None, Some(p)) => write!(dest, "{}%", p),
(None, Some(p)) => write!(dest, "{}%", p * 100.),
(Some(l), None) => write!(dest, "{}px", Au::to_px(l)),
(Some(l), Some(p)) => write!(dest, "calc({}px + {}%)", Au::to_px(l), p * 100.),
_ => unreachable!()
@ -1318,14 +1318,14 @@ pub mod computed {
length = Some(length.unwrap_or(Au(0)) + absolute);
}
for val in vec!(self.vw, self.vh, self.vmin, self.vmax) {
if let Some(val) = val {
for val in &[self.vw, self.vh, self.vmin, self.vmax] {
if let Some(val) = *val {
length = Some(length.unwrap_or(Au(0)) +
val.to_computed_value(context.viewport_size));
}
}
for val in vec!(self.em, self.ex, self.rem) {
if let Some(val) = val {
for val in &[self.em, self.ex, self.rem] {
if let Some(val) = *val {
length = Some(length.unwrap_or(Au(0)) +
val.to_computed_value(context.font_size, context.root_font_size));
}