Use generics for border-image-slice property

This commit is contained in:
Anthony Ramine 2017-05-23 10:56:03 +02:00
parent c8eb277ca5
commit 078d4ed40c
8 changed files with 77 additions and 157 deletions

View file

@ -6,6 +6,7 @@
use std::fmt;
use style_traits::ToCss;
use values::generics::rect::Rect;
/// A generic value for a single side of a `border-image-width` property.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
@ -19,6 +20,16 @@ pub enum BorderImageWidthSide<LengthOrPercentage, Number> {
Auto,
}
/// A generic value for the `border-image-slice` property.
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct BorderImageSlice<NumberOrPercentage> {
/// The offsets.
pub offsets: Rect<NumberOrPercentage>,
/// Whether to fill the middle part.
pub fill: bool,
}
impl<L, N> ToCss for BorderImageWidthSide<L, N>
where L: ToCss, N: ToCss,
{
@ -32,3 +43,29 @@ impl<L, N> ToCss for BorderImageWidthSide<L, N>
}
}
}
impl<N> From<N> for BorderImageSlice<N>
where N: Clone,
{
#[inline]
fn from(value: N) -> Self {
Self {
offsets: value.into(),
fill: false,
}
}
}
impl<N> ToCss for BorderImageSlice<N>
where N: PartialEq + ToCss,
{
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where W: fmt::Write
{
self.offsets.to_css(dest)?;
if self.fill {
dest.write_str(" fill")?;
}
Ok(())
}
}