From 1937f594ac4f88dab9c392935706464ae39260d4 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 4 Mar 2018 15:16:09 +0100 Subject: [PATCH 1/2] Implement ToCss for UnparsedValue --- .../style/properties/properties.mako.rs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index f8d13d33a82..ff6dd747d82 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1360,6 +1360,19 @@ pub struct UnparsedValue { from_shorthand: Option, } +impl ToCss for UnparsedValue { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { + // https://drafts.csswg.org/css-variables/#variables-in-shorthands + if self.from_shorthand.is_none() { + dest.write_str(&*self.css)?; + } + Ok(()) + } +} + impl UnparsedValue { fn substitute_variables( &self, @@ -1432,13 +1445,7 @@ impl<'a, T: ToCss> ToCss for DeclaredValue<'a, T> { { match *self { DeclaredValue::Value(ref inner) => inner.to_css(dest), - DeclaredValue::WithVariables(ref with_variables) => { - // https://drafts.csswg.org/css-variables/#variables-in-shorthands - if with_variables.from_shorthand.is_none() { - dest.write_str(&*with_variables.css)? - } - Ok(()) - }, + DeclaredValue::WithVariables(ref with_variables) => with_variables.to_css(dest), DeclaredValue::CSSWideKeyword(ref keyword) => keyword.to_css(dest), } } @@ -1742,14 +1749,7 @@ impl ToCss for VariableDeclaration { where W: fmt::Write, { - // https://drafts.csswg.org/css-variables/#variables-in-shorthands - match self.value.from_shorthand { - None => { - dest.write_str(&*self.value.css)? - } - Some(..) => {}, - } - Ok(()) + self.value.to_css(dest) } } From 886554dba5fa52379f17972636239fc3181bf9ca Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 4 Mar 2018 15:21:11 +0100 Subject: [PATCH 2/2] Derive ToCss for DeclaredValue --- components/style/properties/properties.mako.rs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index ff6dd747d82..595a9078141 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1308,7 +1308,7 @@ impl ShorthandId { /// Servo's representation of a declared value for a given `T`, which is the /// declared value for that property. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, ToCss)] pub enum DeclaredValue<'a, T: 'a> { /// A known specified value from the stylesheet. Value(&'a T), @@ -1438,19 +1438,6 @@ impl UnparsedValue { } } -impl<'a, T: ToCss> ToCss for DeclaredValue<'a, T> { - fn to_css(&self, dest: &mut CssWriter) -> fmt::Result - where - W: Write, - { - match *self { - DeclaredValue::Value(ref inner) => inner.to_css(dest), - DeclaredValue::WithVariables(ref with_variables) => with_variables.to_css(dest), - DeclaredValue::CSSWideKeyword(ref keyword) => keyword.to_css(dest), - } - } -} - /// An identifier for a given property declaration, which can be either a /// longhand or a custom property. #[derive(Clone, Copy, PartialEq)]