From a41194a318830ddccbfb62bab85405df07dc14ae Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Tue, 7 Mar 2023 00:02:52 +0000 Subject: [PATCH] style: Make optional and default to 'closest-side' Per the spec update, the new syntax is: `ray() = ray( && ? && contain? )` And for ``: "If no is specified it defaults to closest-side." So `` is optional and we omit it if it's default value, for serialization. By the way, offset=* properties are supported only in Gecko, so we don't need a servo function to check the preference. Differential Revision: https://phabricator.services.mozilla.com/D171625 --- components/style/values/generics/motion.rs | 9 +++++++++ components/style/values/specified/motion.rs | 16 ++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/components/style/values/generics/motion.rs b/components/style/values/generics/motion.rs index 912ba01e6c4..c5b1f786457 100644 --- a/components/style/values/generics/motion.rs +++ b/components/style/values/generics/motion.rs @@ -35,6 +35,14 @@ pub enum RaySize { Sides, } +impl RaySize { + /// Returns true if it is the default value. + #[inline] + pub fn is_default(&self) -> bool { + *self == RaySize::ClosestSide + } +} + /// The `ray()` function, `ray( [ && && contain? ] )` /// /// https://drafts.fxtf.org/motion-1/#valdef-offsetpath-ray @@ -62,6 +70,7 @@ pub struct RayFunction { /// Decide the path length used when `offset-distance` is expressed /// as a percentage. #[animation(constant)] + #[css(skip_if = "RaySize::is_default")] pub size: RaySize, /// Clamp `offset-distance` so that the box is entirely contained /// within the path. diff --git a/components/style/values/specified/motion.rs b/components/style/values/specified/motion.rs index 944a0110840..57cdfac4806 100644 --- a/components/style/values/specified/motion.rs +++ b/components/style/values/specified/motion.rs @@ -16,21 +16,12 @@ use style_traits::{ParseError, StyleParseErrorKind}; /// The specified value of `offset-path`. pub type OffsetPath = GenericOffsetPath; -#[cfg(feature = "gecko")] -fn is_ray_enabled() -> bool { - static_prefs::pref!("layout.css.motion-path-ray.enabled") -} -#[cfg(feature = "servo")] -fn is_ray_enabled() -> bool { - false -} - impl Parse for RayFunction { fn parse<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if !is_ray_enabled() { + if !static_prefs::pref!("layout.css.motion-path-ray.enabled") { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); } @@ -60,13 +51,14 @@ impl Parse for RayFunction { break; } - if angle.is_none() || size.is_none() { + if angle.is_none() { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); } Ok(RayFunction { angle: angle.unwrap(), - size: size.unwrap(), + // If no is specified it defaults to closest-side. + size: size.unwrap_or(RaySize::ClosestSide), contain, }) }