style: Update the syntax of offset-position

Now it supports "normal" keyword. Also, offset-position doesn't create
stacking context and it doesn't have offset transform, so we can
simplify CompareMotionValues() a little bit.

Note: We don't have to add test in [1] because Blink added one to WPT
upstream repo already.

[1] css/motion/parsing/offset-position-parsing-valid.html

Note: the usage of offset-position is in other bugs.

Differential Revision: https://phabricator.services.mozilla.com/D179623
This commit is contained in:
Boris Chiou 2023-06-01 20:04:52 +00:00 committed by Martin Robinson
parent 0fd2f08da1
commit e1b6632313
7 changed files with 72 additions and 13 deletions

View file

@ -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",

View file

@ -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<Longhands, ParseError<'i>> {
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)?;
}

View file

@ -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};

View file

@ -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<Angle>;
/// The computed value of `offset-position`.
pub type OffsetPosition = GenericOffsetPosition<LengthPercentage, LengthPercentage>;
#[inline]
fn is_auto_zero_angle(auto: &bool, angle: &Angle) -> bool {
*auto && angle.is_zero()

View file

@ -4,6 +4,7 @@
//! Generic types for CSS Motion Path.
use crate::values::generics::position::GenericPosition;
use crate::values::specified::SVGPathData;
/// The <size> in ray() function.
@ -123,3 +124,51 @@ impl<Angle> OffsetPath<Angle> {
OffsetPath::None
}
}
/// The offset-position property, which specifies the offset starting position that is used by the
/// <offset-path> functions if they dont 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<H, V> {
/// 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 <position> to position a 0x0 object
/// area within the boxs containing block.
Position(
#[css(field_bound)]
#[parse(field_bound)]
GenericPosition<H, V>,
),
}
pub use self::GenericOffsetPosition as OffsetPosition;
impl<H, V> OffsetPosition<H, V> {
/// Returns the initial value, auto.
#[inline]
pub fn auto() -> Self {
Self::Auto
}
}

View file

@ -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};

View file

@ -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<Angle>;
/// The specified value of `offset-position`.
pub type OffsetPosition = GenericOffsetPosition<HorizontalPosition, VerticalPosition>;
#[cfg(feature = "gecko")]
fn is_ray_enabled() -> bool {
static_prefs::pref!("layout.css.motion-path-ray.enabled")