Derive ToCss for EndingShape

This commit is contained in:
Anthony Ramine 2017-06-13 11:29:46 +02:00
parent fe19c3810c
commit 53b465895f

View file

@ -69,7 +69,7 @@ pub enum GradientKind<LineDirection, Length, LengthOrPercentage, Position> {
} }
/// A radial gradient's ending shape. /// A radial gradient's ending shape.
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)] #[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum EndingShape<Length, LengthOrPercentage> { pub enum EndingShape<Length, LengthOrPercentage> {
/// A circular gradient. /// A circular gradient.
@ -89,7 +89,7 @@ pub enum Circle<Length> {
} }
/// An ellipse shape. /// An ellipse shape.
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)] #[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum Ellipse<LengthOrPercentage> { pub enum Ellipse<LengthOrPercentage> {
/// An ellipse pair of radii. /// An ellipse pair of radii.
@ -286,30 +286,26 @@ pub trait LineDirection {
where W: fmt::Write; where W: fmt::Write;
} }
impl<L, LoP> ToCss for EndingShape<L, LoP> impl<L> ToCss for Circle<L>
where L: ToCss, LoP: ToCss, where
L: ToCss,
{ {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where
W: fmt::Write,
{
match *self { match *self {
EndingShape::Circle(Circle::Extent(ShapeExtent::FarthestCorner)) | Circle::Extent(ShapeExtent::FarthestCorner) |
EndingShape::Circle(Circle::Extent(ShapeExtent::Cover)) => { Circle::Extent(ShapeExtent::Cover) => {
dest.write_str("circle") dest.write_str("circle")
}, },
EndingShape::Circle(Circle::Extent(keyword)) => { Circle::Extent(keyword) => {
dest.write_str("circle ")?; dest.write_str("circle ")?;
keyword.to_css(dest) keyword.to_css(dest)
}, },
EndingShape::Circle(Circle::Radius(ref length)) => { Circle::Radius(ref length) => {
length.to_css(dest) length.to_css(dest)
}, },
EndingShape::Ellipse(Ellipse::Extent(keyword)) => {
keyword.to_css(dest)
},
EndingShape::Ellipse(Ellipse::Radii(ref x, ref y)) => {
x.to_css(dest)?;
dest.write_str(" ")?;
y.to_css(dest)
},
} }
} }
} }