Support unit variants when deriving ToCss

This commit is contained in:
Anthony Ramine 2017-06-07 14:53:31 +02:00
parent 7d09ce0495
commit 45e8b0e8c7
14 changed files with 71 additions and 242 deletions

View file

@ -4,11 +4,8 @@
//! Generic types for CSS values related to backgrounds.
use std::fmt;
use style_traits::ToCss;
/// A generic value for the `background-size` property.
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum BackgroundSize<LengthOrPercentageOrAuto> {
/// `<width> <height>`
@ -32,21 +29,3 @@ impl<L> From<L> for BackgroundSize<L>
BackgroundSize::Explicit { width: value.clone(), height: value }
}
}
impl<L> ToCss for BackgroundSize<L>
where L: ToCss
{
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where W: fmt::Write
{
match *self {
BackgroundSize::Explicit { ref width, ref height } => {
width.to_css(dest)?;
dest.write_str(" ")?;
height.to_css(dest)
},
BackgroundSize::Cover => dest.write_str("cover"),
BackgroundSize::Contain => dest.write_str("contain"),
}
}
}