style: Make <ray-size> optional and default to 'closest-side'

Per the spec update, the new syntax is:
  `ray() = ray( <angle> && <ray-size>? && contain? )`
And for `<ray-size>`:
  "If no <ray-size> is specified it defaults to closest-side."

So `<ray-size>` 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
This commit is contained in:
Boris Chiou 2023-03-07 00:02:52 +00:00 committed by Martin Robinson
parent 860a6c2fe6
commit a41194a318
2 changed files with 13 additions and 12 deletions

View file

@ -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( [ <angle> && <size> && contain? ] )`
///
/// https://drafts.fxtf.org/motion-1/#valdef-offsetpath-ray
@ -62,6 +70,7 @@ pub struct RayFunction<Angle> {
/// 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.

View file

@ -16,21 +16,12 @@ use style_traits::{ParseError, StyleParseErrorKind};
/// The specified value of `offset-path`.
pub type OffsetPath = GenericOffsetPath<Angle>;
#[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<Angle> {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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<Angle> {
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 <ray-size> is specified it defaults to closest-side.
size: size.unwrap_or(RaySize::ClosestSide),
contain,
})
}