diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 128fff10a72..a71d6e7e95e 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -314,6 +314,24 @@ impl Clone for PropertyDeclaration { } } +impl PropertyDeclaration { + /// Like the method on ToCss, but without the type parameter to avoid + /// accidentally monomorphizing this large function multiple times for + /// different writers. + pub fn to_css(&self, dest: &mut CssStringWriter) -> fmt::Result { + use self::PropertyDeclaration::*; + + let mut dest = CssWriter::new(dest); + match *self { + % for ty, variants in groups.iteritems(): + ${" | ".join("{}(ref value)".format(v) for v in variants)} => { + value.to_css(&mut dest) + } + % endfor + } + } +} + /// A longhand or shorthand porperty #[derive(Clone, Copy, Debug)] pub struct NonCustomPropertyId(usize); @@ -1563,6 +1581,15 @@ pub struct WideKeywordDeclaration { keyword: CSSWideKeyword, } +impl ToCss for WideKeywordDeclaration { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: fmt::Write, + { + self.keyword.to_css(dest) + } +} + /// An unparsed declaration that contains `var()` functions. #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[derive(Clone, PartialEq)] @@ -1572,6 +1599,29 @@ pub struct VariableDeclaration { value: Arc, } +impl ToCss for VariableDeclaration { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: fmt::Write, + { + // https://drafts.csswg.org/css-variables/#variables-in-shorthands + match self.value.from_shorthand { + // Normally, we shouldn't be printing variables here if they came from + // shorthands. But we should allow properties that came from shorthand + // aliases. That also matches with the Gecko behavior. + // FIXME(emilio): This is just a hack for `-moz-transform`. + Some(shorthand) if shorthand.flags().contains(PropertyFlags::SHORTHAND_ALIAS_PROPERTY) => { + dest.write_str(&*self.value.css)? + } + None => { + dest.write_str(&*self.value.css)? + } + _ => {}, + } + Ok(()) + } +} + /// A custom property declaration with the property name and the declared value. #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[derive(Clone, PartialEq)] @@ -1583,6 +1633,15 @@ pub struct CustomDeclaration { pub value: DeclaredValueOwned>, } +impl ToCss for CustomDeclaration { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: fmt::Write, + { + self.value.borrow().to_css(dest) + } +} + impl fmt::Debug for PropertyDeclaration { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.id().to_css(&mut CssWriter::new(f))?; @@ -1597,40 +1656,6 @@ impl fmt::Debug for PropertyDeclaration { } } -impl PropertyDeclaration { - /// Like the method on ToCss, but without the type parameter to avoid - /// accidentally monomorphizing this large function multiple times for - /// different writers. - pub fn to_css(&self, dest: &mut CssStringWriter) -> fmt::Result { - match *self { - % for property in data.longhands: - PropertyDeclaration::${property.camel_case}(ref value) => { - value.to_css(&mut CssWriter::new(dest)) - } - % endfor - PropertyDeclaration::CSSWideKeyword(ref declaration) => { - declaration.keyword.to_css(&mut CssWriter::new(dest)) - }, - PropertyDeclaration::WithVariables(ref declaration) => { - // https://drafts.csswg.org/css-variables/#variables-in-shorthands - match declaration.value.from_shorthand { - // Normally, we shouldn't be printing variables here if they came from - // shorthands. But we should allow properties that came from shorthand - // aliases. That also matches with the Gecko behavior. - Some(shorthand) if shorthand.flags().contains(PropertyFlags::SHORTHAND_ALIAS_PROPERTY) => - dest.write_str(&*declaration.value.css)?, - None => dest.write_str(&*declaration.value.css)?, - _ => {}, - } - Ok(()) - }, - PropertyDeclaration::Custom(ref declaration) => { - declaration.value.borrow().to_css(&mut CssWriter::new(dest)) - }, - } - } -} - impl PropertyDeclaration { /// Given a property declaration, return the property declaration id. pub fn id(&self) -> PropertyDeclarationId {