diff --git a/components/style/properties/longhands/box.mako.rs b/components/style/properties/longhands/box.mako.rs index e09885e80c7..dd3cfb2c78c 100644 --- a/components/style/properties/longhands/box.mako.rs +++ b/components/style/properties/longhands/box.mako.rs @@ -268,8 +268,8 @@ ${helpers.predefined_type( // Motion Path Module Level 1 ${helpers.predefined_type( "offset-position", - "PositionOrAuto", - "computed::PositionOrAuto::auto()", + "OffsetPosition", + "computed::OffsetPosition::auto()", engines="gecko", animation_value_type="ComputedValue", gecko_pref="layout.css.motion-path-offset-position.enabled", diff --git a/components/style/properties/shorthands/box.mako.rs b/components/style/properties/shorthands/box.mako.rs index 16ab741018c..b9885492cd8 100644 --- a/components/style/properties/shorthands/box.mako.rs +++ b/components/style/properties/shorthands/box.mako.rs @@ -152,9 +152,8 @@ ${helpers.two_properties_shorthand( gecko_pref="layout.css.motion-path.enabled", spec="https://drafts.fxtf.org/motion-1/#offset-shorthand"> use crate::parser::Parse; - use crate::values::specified::motion::{OffsetPath, OffsetRotate}; - use crate::values::specified::position::PositionOrAuto; - use crate::values::specified::LengthPercentage; + use crate::values::specified::motion::{OffsetPath, OffsetPosition, OffsetRotate}; + use crate::values::specified::{LengthPercentage, PositionOrAuto}; use crate::Zero; pub fn parse_value<'i, 't>( @@ -163,7 +162,7 @@ ${helpers.two_properties_shorthand( ) -> Result> { let offset_position = if static_prefs::pref!("layout.css.motion-path-offset-position.enabled") { - input.try_parse(|i| PositionOrAuto::parse(context, i)).ok() + input.try_parse(|i| OffsetPosition::parse(context, i)).ok() } else { None }; @@ -171,6 +170,8 @@ ${helpers.two_properties_shorthand( let offset_path = input.try_parse(|i| OffsetPath::parse(context, i)).ok(); // Must have one of [offset-position, offset-path]. + // FIXME: The syntax is out-of-date after the update of the spec. + // https://github.com/w3c/fxtf-drafts/issues/515 if offset_position.is_none() && offset_path.is_none() { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); } @@ -202,7 +203,7 @@ ${helpers.two_properties_shorthand( }).ok(); Ok(expanded! { - offset_position: offset_position.unwrap_or(PositionOrAuto::auto()), + offset_position: offset_position.unwrap_or(OffsetPosition::auto()), offset_path: offset_path.unwrap_or(OffsetPath::none()), offset_distance: offset_distance.unwrap_or(LengthPercentage::zero()), offset_rotate: offset_rotate.unwrap_or(OffsetRotate::auto()), @@ -217,7 +218,7 @@ ${helpers.two_properties_shorthand( // offset-path group means "offset-path offset-distance offset-rotate". let must_serialize_path = *self.offset_path != OffsetPath::None || (!self.offset_distance.is_zero() || !self.offset_rotate.is_auto()); - let position_is_default = *offset_position == PositionOrAuto::auto(); + let position_is_default = matches!(offset_position, OffsetPosition::Auto); if !position_is_default || !must_serialize_path { offset_position.to_css(dest)?; } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index b40ac08f1da..b9f4d38cdef 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -79,7 +79,7 @@ pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageO #[cfg(feature = "gecko")] pub use self::list::ListStyleType; pub use self::list::Quotes; -pub use self::motion::{OffsetPath, OffsetRotate}; +pub use self::motion::{OffsetPath, OffsetPosition, OffsetRotate}; pub use self::outline::OutlineStyle; pub use self::page::{PageName, PageOrientation, PageSize, PageSizeOrientation, PaperSize}; pub use self::percentage::{NonNegativePercentage, Percentage}; diff --git a/components/style/values/computed/motion.rs b/components/style/values/computed/motion.rs index e2565ff3468..704d10b68ab 100644 --- a/components/style/values/computed/motion.rs +++ b/components/style/values/computed/motion.rs @@ -4,13 +4,16 @@ //! Computed types for CSS values that are related to motion path. -use crate::values::computed::Angle; -use crate::values::generics::motion::GenericOffsetPath; +use crate::values::computed::{Angle, LengthPercentage}; +use crate::values::generics::motion::{GenericOffsetPath, GenericOffsetPosition}; use crate::Zero; /// The computed value of `offset-path`. pub type OffsetPath = GenericOffsetPath; +/// The computed value of `offset-position`. +pub type OffsetPosition = GenericOffsetPosition; + #[inline] fn is_auto_zero_angle(auto: &bool, angle: &Angle) -> bool { *auto && angle.is_zero() diff --git a/components/style/values/generics/motion.rs b/components/style/values/generics/motion.rs index c5b1f786457..768ef52ff7c 100644 --- a/components/style/values/generics/motion.rs +++ b/components/style/values/generics/motion.rs @@ -4,6 +4,7 @@ //! Generic types for CSS Motion Path. +use crate::values::generics::position::GenericPosition; use crate::values::specified::SVGPathData; /// The in ray() function. @@ -123,3 +124,51 @@ impl OffsetPath { OffsetPath::None } } + +/// The offset-position property, which specifies the offset starting position that is used by the +/// functions if they don’t specify their own starting position. +/// +/// https://drafts.fxtf.org/motion-1/#offset-position-property +#[derive( + Animate, + Clone, + ComputeSquaredDistance, + Copy, + Debug, + Deserialize, + MallocSizeOf, + Parse, + PartialEq, + Serialize, + SpecifiedValueInfo, + ToAnimatedValue, + ToAnimatedZero, + ToComputedValue, + ToCss, + ToResolvedValue, + ToShmem, +)] +#[repr(C, u8)] +pub enum GenericOffsetPosition { + /// The element does not have an offset starting position. + Normal, + /// The offset starting position is the top-left corner of the box. + Auto, + /// The offset starting position is the result of using the to position a 0x0 object + /// area within the box’s containing block. + Position( + #[css(field_bound)] + #[parse(field_bound)] + GenericPosition, + ), +} + +pub use self::GenericOffsetPosition as OffsetPosition; + +impl OffsetPosition { + /// Returns the initial value, auto. + #[inline] + pub fn auto() -> Self { + Self::Auto + } +} diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index d3a4373fd09..27aa1a85c77 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -73,7 +73,7 @@ pub use self::length::{ #[cfg(feature = "gecko")] pub use self::list::ListStyleType; pub use self::list::Quotes; -pub use self::motion::{OffsetPath, OffsetRotate}; +pub use self::motion::{OffsetPath, OffsetPosition, OffsetRotate}; pub use self::outline::OutlineStyle; pub use self::page::{PageName, PageOrientation, PageSize, PageSizeOrientation, PaperSize}; pub use self::percentage::{NonNegativePercentage, Percentage}; diff --git a/components/style/values/specified/motion.rs b/components/style/values/specified/motion.rs index d2831d27b79..bf36e973232 100644 --- a/components/style/values/specified/motion.rs +++ b/components/style/values/specified/motion.rs @@ -7,7 +7,10 @@ use crate::parser::{Parse, ParserContext}; use crate::values::computed::motion::OffsetRotate as ComputedOffsetRotate; use crate::values::computed::{Context, ToComputedValue}; -use crate::values::generics::motion::{GenericOffsetPath, RayFunction, RaySize}; +use crate::values::generics::motion::{ + GenericOffsetPath, GenericOffsetPosition, RayFunction, RaySize, +}; +use crate::values::specified::position::{HorizontalPosition, VerticalPosition}; use crate::values::specified::{Angle, SVGPathData}; use crate::Zero; use cssparser::Parser; @@ -16,6 +19,9 @@ use style_traits::{ParseError, StyleParseErrorKind}; /// The specified value of `offset-path`. pub type OffsetPath = GenericOffsetPath; +/// The specified value of `offset-position`. +pub type OffsetPosition = GenericOffsetPosition; + #[cfg(feature = "gecko")] fn is_ray_enabled() -> bool { static_prefs::pref!("layout.css.motion-path-ray.enabled")