mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Support unit variants when deriving ToCss
This commit is contained in:
parent
7d09ce0495
commit
45e8b0e8c7
14 changed files with 71 additions and 242 deletions
|
@ -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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue