From 93d3004c17552b8db2855c3add483bc4e44f2e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 3 Mar 2019 11:31:30 +0000 Subject: [PATCH] style: Use skip_if for translate serialization. Trivial drive-by cleanup. Differential Revision: https://phabricator.services.mozilla.com/D21860 --- components/style/values/generics/transform.rs | 57 ++++++------------- 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/components/style/values/generics/transform.rs b/components/style/values/generics/transform.rs index d25d2d3a653..b0a121fd6e9 100644 --- a/components/style/values/generics/transform.rs +++ b/components/style/values/generics/transform.rs @@ -629,55 +629,34 @@ impl ToCss for Scale { } #[derive( - Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToAnimatedZero, ToComputedValue, + Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToAnimatedZero, ToComputedValue, ToCss )] -/// A value of the `Translate` property +/// A value of the `translate` property +/// +/// https://drafts.csswg.org/css-transforms-2/#individual-transform-serialization: +/// +/// If a 2d translation is specified, the property must serialize with only one +/// or two values (per usual, if the second value is 0px, the default, it must +/// be omitted when serializing). +/// +/// If a 3d translation is specified, all three values must be serialized. +/// +/// We don't omit the 3rd component even if it is 0px for now, and the +/// related spec issue is https://github.com/w3c/csswg-drafts/issues/3305 /// /// -pub enum Translate { +pub enum Translate +where + LengthPercentage: Zero, +{ /// 'none' None, /// '' or ' ' - Translate(LengthPercentage, LengthPercentage), + Translate(LengthPercentage, #[css(skip_if = "Zero::is_zero")] LengthPercentage), /// ' ' Translate3D(LengthPercentage, LengthPercentage, Length), } -impl ToCss for Translate { - fn to_css(&self, dest: &mut CssWriter) -> fmt::Result - where - W: fmt::Write, - { - // The spec says: - // 1. If a 2d translation is specified, the property must serialize with only one or two - // values (per usual, if the second value is 0px, the default, it must be omitted when - // serializing). - // 2. If a 3d translation is specified, all three values must be serialized. - // https://drafts.csswg.org/css-transforms-2/#individual-transform-serialization - // - // We don't omit the 3rd component even if it is 0px for now, and the related - // spec issue is https://github.com/w3c/csswg-drafts/issues/3305 - match *self { - Translate::None => dest.write_str("none"), - Translate::Translate(ref x, ref y) => { - x.to_css(dest)?; - if !y.is_zero() { - dest.write_char(' ')?; - y.to_css(dest)?; - } - Ok(()) - }, - Translate::Translate3D(ref x, ref y, ref z) => { - x.to_css(dest)?; - dest.write_char(' ')?; - y.to_css(dest)?; - dest.write_char(' ')?; - z.to_css(dest) - }, - } - } -} - #[allow(missing_docs)] #[derive( Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss,