Bug 1532134 - Use skip_if for translate serialization. r=xidorn
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sun, 03 Mar 2019 11:31:30 +0000
changeset 520056 5a4a2f2465b0142e901d52f1850c2fc1a6e0cc6b
parent 520055 7aa72a6aa1b501c6f7a0efc7a4a4ea14d15f0030
child 520057 2b811ffbed9b8b4c71092e90cbb11201c8d9a7c6
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1532134
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1532134 - Use skip_if for translate serialization. r=xidorn Trivial drive-by cleanup. Differential Revision: https://phabricator.services.mozilla.com/D21860
servo/components/style/values/generics/transform.rs
--- a/servo/components/style/values/generics/transform.rs
+++ b/servo/components/style/values/generics/transform.rs
@@ -624,65 +624,44 @@ impl<Number: ToCss + PartialEq> ToCss fo
                 dest.write_char(' ')?;
                 z.to_css(dest)
             },
         }
     }
 }
 
 #[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
 ///
 /// <https://drafts.csswg.org/css-transforms-2/#individual-transforms>
-pub enum Translate<LengthPercentage, Length> {
+pub enum Translate<LengthPercentage, Length>
+where
+    LengthPercentage: Zero,
+{
     /// 'none'
     None,
     /// '<length-percentage>' or '<length-percentage> <length-percentage>'
-    Translate(LengthPercentage, LengthPercentage),
+    Translate(LengthPercentage, #[css(skip_if = "Zero::is_zero")] LengthPercentage),
     /// '<length-percentage> <length-percentage> <length>'
     Translate3D(LengthPercentage, LengthPercentage, Length),
 }
 
-impl<LoP: ToCss + Zero, L: ToCss> ToCss for Translate<LoP, L> {
-    fn to_css<W>(&self, dest: &mut CssWriter<W>) -> 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,
 )]
 pub enum TransformStyle {
     #[cfg(feature = "servo")]
     Auto,
     Flat,