From 2bd1ff0450f52ae998f8ca3ce015bd8c4957777c Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 7 Jun 2017 13:16:54 +1000 Subject: [PATCH] Move ToCss impl for Shadow types to values mod. --- .../style/properties/longhand/effects.mako.rs | 42 ------------------- components/style/values/computed/mod.rs | 18 ++++++++ components/style/values/specified/mod.rs | 21 ++++++++++ 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/components/style/properties/longhand/effects.mako.rs b/components/style/properties/longhand/effects.mako.rs index 5ebf602262ae..0a672851ab40 100644 --- a/components/style/properties/longhand/effects.mako.rs +++ b/components/style/properties/longhand/effects.mako.rs @@ -19,56 +19,14 @@ ${helpers.predefined_type("opacity", extra_prefixes="webkit" ignored_when_colors_disabled="True" spec="https://drafts.csswg.org/css-backgrounds/#box-shadow"> - use std::fmt; - use style_traits::ToCss; - pub type SpecifiedValue = specified::Shadow; - impl ToCss for SpecifiedValue { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - if self.inset { - try!(dest.write_str("inset ")); - } - try!(self.offset_x.to_css(dest)); - try!(dest.write_str(" ")); - try!(self.offset_y.to_css(dest)); - try!(dest.write_str(" ")); - try!(self.blur_radius.to_css(dest)); - try!(dest.write_str(" ")); - try!(self.spread_radius.to_css(dest)); - - if let Some(ref color) = self.color { - try!(dest.write_str(" ")); - try!(color.to_css(dest)); - } - Ok(()) - } - } - pub mod computed_value { use values::computed::Shadow; pub type T = Shadow; } - impl ToCss for computed_value::T { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - if self.inset { - try!(dest.write_str("inset ")); - } - try!(self.blur_radius.to_css(dest)); - try!(dest.write_str(" ")); - try!(self.spread_radius.to_css(dest)); - try!(dest.write_str(" ")); - try!(self.offset_x.to_css(dest)); - try!(dest.write_str(" ")); - try!(self.offset_y.to_css(dest)); - try!(dest.write_str(" ")); - try!(self.color.to_css(dest)); - Ok(()) - } - } - pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { specified::Shadow::parse(context, input, false) } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index acfc09f5c808..44a646171aab 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -483,6 +483,24 @@ pub struct Shadow { pub inset: bool, } +impl ToCss for Shadow { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + if self.inset { + dest.write_str("inset ")?; + } + self.blur_radius.to_css(dest)?; + dest.write_str(" ")?; + self.spread_radius.to_css(dest)?; + dest.write_str(" ")?; + self.offset_x.to_css(dest)?; + dest.write_str(" ")?; + self.offset_y.to_css(dest)?; + dest.write_str(" ")?; + self.color.to_css(dest)?; + Ok(()) + } +} + /// A `` value. pub type Number = CSSFloat; diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index b198295064f6..ca86d8d2664b 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -878,6 +878,27 @@ impl ToComputedValue for Shadow { } } +impl ToCss for Shadow { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + if self.inset { + dest.write_str("inset ")?; + } + self.offset_x.to_css(dest)?; + dest.write_str(" ")?; + self.offset_y.to_css(dest)?; + dest.write_str(" ")?; + self.blur_radius.to_css(dest)?; + dest.write_str(" ")?; + self.spread_radius.to_css(dest)?; + + if let Some(ref color) = self.color { + dest.write_str(" ")?; + color.to_css(dest)?; + } + Ok(()) + } +} + impl Shadow { // disable_spread_and_inset is for filter: drop-shadow(...) #[allow(missing_docs)]