diff --git a/components/style/values/generics/mod.rs b/components/style/values/generics/mod.rs index 637735a0c66..d93ea570a71 100644 --- a/components/style/values/generics/mod.rs +++ b/components/style/values/generics/mod.rs @@ -255,7 +255,7 @@ impl ToCss for FontSettingTagFloat { /// /// https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -#[derive(Clone, Debug, PartialEq, ToAnimatedValue)] +#[derive(Clone, Debug, PartialEq, ToAnimatedValue, ToComputedValue, ToCss)] pub struct SVGPaint { /// The paint source pub kind: SVGPaintKind, @@ -269,7 +269,7 @@ pub struct SVGPaint { /// to have a fallback, Gecko lets the context /// properties have a fallback as well. #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -#[derive(Clone, Debug, PartialEq, ToAnimatedValue, ToCss)] +#[derive(Clone, Debug, PartialEq, ToAnimatedValue, ToComputedValue, ToCss)] pub enum SVGPaintKind { /// `none` None, @@ -283,35 +283,6 @@ pub enum SVGPaintKind { ContextStroke, } -impl SVGPaintKind { - /// Convert to a value with a different kind of color - pub fn convert(&self, f: F) -> SVGPaintKind - where F: Fn(&ColorType) -> OtherColor { - match *self { - SVGPaintKind::None => SVGPaintKind::None, - SVGPaintKind::ContextStroke => SVGPaintKind::ContextStroke, - SVGPaintKind::ContextFill => SVGPaintKind::ContextFill, - SVGPaintKind::Color(ref color) => { - SVGPaintKind::Color(f(color)) - } - SVGPaintKind::PaintServer(ref server) => { - SVGPaintKind::PaintServer(server.clone()) - } - } - } -} - -impl SVGPaint { - /// Convert to a value with a different kind of color - pub fn convert(&self, f: F) -> SVGPaint - where F: Fn(&ColorType) -> OtherColor { - SVGPaint { - kind: self.kind.convert(&f), - fallback: self.fallback.as_ref().map(|color| f(color)) - } - } -} - impl SVGPaintKind { /// Parse a keyword value only fn parse_ident<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { @@ -365,15 +336,3 @@ impl Parse for SVGPaint { } } } - -impl ToCss for SVGPaint { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - self.kind.to_css(dest)?; - if let Some(ref fallback) = self.fallback { - fallback.to_css(dest)?; - } - Ok(()) - } -} - - diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 8b8bced42e7..dd34f9bdbeb 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -701,40 +701,6 @@ pub type SVGPaint = ::values::generics::SVGPaint; /// Specified SVG Paint Kind value pub type SVGPaintKind = ::values::generics::SVGPaintKind; -impl ToComputedValue for SVGPaint { - type ComputedValue = super::computed::SVGPaint; - - #[inline] - fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { - super::computed::SVGPaint { - kind: self.kind.to_computed_value(context), - fallback: self.fallback.as_ref().map(|f| f.to_computed_value(context)) - } - } - - #[inline] - fn from_computed_value(computed: &Self::ComputedValue) -> Self { - SVGPaint { - kind: ToComputedValue::from_computed_value(&computed.kind), - fallback: computed.fallback.as_ref().map(ToComputedValue::from_computed_value) - } - } -} - -impl ToComputedValue for SVGPaintKind { - type ComputedValue = super::computed::SVGPaintKind; - - #[inline] - fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { - self.convert(|color| color.to_computed_value(context)) - } - - #[inline] - fn from_computed_value(computed: &Self::ComputedValue) -> Self { - computed.convert(ToComputedValue::from_computed_value) - } -} - /// | | pub type LengthOrPercentageOrNumber = Either;