mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
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:
parent
0fd2f08da1
commit
e1b6632313
7 changed files with 72 additions and 13 deletions
|
@ -268,8 +268,8 @@ ${helpers.predefined_type(
|
||||||
// Motion Path Module Level 1
|
// Motion Path Module Level 1
|
||||||
${helpers.predefined_type(
|
${helpers.predefined_type(
|
||||||
"offset-position",
|
"offset-position",
|
||||||
"PositionOrAuto",
|
"OffsetPosition",
|
||||||
"computed::PositionOrAuto::auto()",
|
"computed::OffsetPosition::auto()",
|
||||||
engines="gecko",
|
engines="gecko",
|
||||||
animation_value_type="ComputedValue",
|
animation_value_type="ComputedValue",
|
||||||
gecko_pref="layout.css.motion-path-offset-position.enabled",
|
gecko_pref="layout.css.motion-path-offset-position.enabled",
|
||||||
|
|
|
@ -152,9 +152,8 @@ ${helpers.two_properties_shorthand(
|
||||||
gecko_pref="layout.css.motion-path.enabled",
|
gecko_pref="layout.css.motion-path.enabled",
|
||||||
spec="https://drafts.fxtf.org/motion-1/#offset-shorthand">
|
spec="https://drafts.fxtf.org/motion-1/#offset-shorthand">
|
||||||
use crate::parser::Parse;
|
use crate::parser::Parse;
|
||||||
use crate::values::specified::motion::{OffsetPath, OffsetRotate};
|
use crate::values::specified::motion::{OffsetPath, OffsetPosition, OffsetRotate};
|
||||||
use crate::values::specified::position::PositionOrAuto;
|
use crate::values::specified::{LengthPercentage, PositionOrAuto};
|
||||||
use crate::values::specified::LengthPercentage;
|
|
||||||
use crate::Zero;
|
use crate::Zero;
|
||||||
|
|
||||||
pub fn parse_value<'i, 't>(
|
pub fn parse_value<'i, 't>(
|
||||||
|
@ -163,7 +162,7 @@ ${helpers.two_properties_shorthand(
|
||||||
) -> Result<Longhands, ParseError<'i>> {
|
) -> Result<Longhands, ParseError<'i>> {
|
||||||
let offset_position =
|
let offset_position =
|
||||||
if static_prefs::pref!("layout.css.motion-path-offset-position.enabled") {
|
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 {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
@ -171,6 +170,8 @@ ${helpers.two_properties_shorthand(
|
||||||
let offset_path = input.try_parse(|i| OffsetPath::parse(context, i)).ok();
|
let offset_path = input.try_parse(|i| OffsetPath::parse(context, i)).ok();
|
||||||
|
|
||||||
// Must have one of [offset-position, offset-path].
|
// 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() {
|
if offset_position.is_none() && offset_path.is_none() {
|
||||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||||
}
|
}
|
||||||
|
@ -202,7 +203,7 @@ ${helpers.two_properties_shorthand(
|
||||||
}).ok();
|
}).ok();
|
||||||
|
|
||||||
Ok(expanded! {
|
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_path: offset_path.unwrap_or(OffsetPath::none()),
|
||||||
offset_distance: offset_distance.unwrap_or(LengthPercentage::zero()),
|
offset_distance: offset_distance.unwrap_or(LengthPercentage::zero()),
|
||||||
offset_rotate: offset_rotate.unwrap_or(OffsetRotate::auto()),
|
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".
|
// offset-path group means "offset-path offset-distance offset-rotate".
|
||||||
let must_serialize_path = *self.offset_path != OffsetPath::None
|
let must_serialize_path = *self.offset_path != OffsetPath::None
|
||||||
|| (!self.offset_distance.is_zero() || !self.offset_rotate.is_auto());
|
|| (!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 {
|
if !position_is_default || !must_serialize_path {
|
||||||
offset_position.to_css(dest)?;
|
offset_position.to_css(dest)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageO
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use self::list::ListStyleType;
|
pub use self::list::ListStyleType;
|
||||||
pub use self::list::Quotes;
|
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::outline::OutlineStyle;
|
||||||
pub use self::page::{PageName, PageOrientation, PageSize, PageSizeOrientation, PaperSize};
|
pub use self::page::{PageName, PageOrientation, PageSize, PageSizeOrientation, PaperSize};
|
||||||
pub use self::percentage::{NonNegativePercentage, Percentage};
|
pub use self::percentage::{NonNegativePercentage, Percentage};
|
||||||
|
|
|
@ -4,13 +4,16 @@
|
||||||
|
|
||||||
//! Computed types for CSS values that are related to motion path.
|
//! Computed types for CSS values that are related to motion path.
|
||||||
|
|
||||||
use crate::values::computed::Angle;
|
use crate::values::computed::{Angle, LengthPercentage};
|
||||||
use crate::values::generics::motion::GenericOffsetPath;
|
use crate::values::generics::motion::{GenericOffsetPath, GenericOffsetPosition};
|
||||||
use crate::Zero;
|
use crate::Zero;
|
||||||
|
|
||||||
/// The computed value of `offset-path`.
|
/// The computed value of `offset-path`.
|
||||||
pub type OffsetPath = GenericOffsetPath<Angle>;
|
pub type OffsetPath = GenericOffsetPath<Angle>;
|
||||||
|
|
||||||
|
/// The computed value of `offset-position`.
|
||||||
|
pub type OffsetPosition = GenericOffsetPosition<LengthPercentage, LengthPercentage>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_auto_zero_angle(auto: &bool, angle: &Angle) -> bool {
|
fn is_auto_zero_angle(auto: &bool, angle: &Angle) -> bool {
|
||||||
*auto && angle.is_zero()
|
*auto && angle.is_zero()
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
//! Generic types for CSS Motion Path.
|
//! Generic types for CSS Motion Path.
|
||||||
|
|
||||||
|
use crate::values::generics::position::GenericPosition;
|
||||||
use crate::values::specified::SVGPathData;
|
use crate::values::specified::SVGPathData;
|
||||||
|
|
||||||
/// The <size> in ray() function.
|
/// The <size> in ray() function.
|
||||||
|
@ -123,3 +124,51 @@ impl<Angle> OffsetPath<Angle> {
|
||||||
OffsetPath::None
|
OffsetPath::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The offset-position property, which specifies the offset starting position that is used by the
|
||||||
|
/// <offset-path> 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<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 box’s 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ pub use self::length::{
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use self::list::ListStyleType;
|
pub use self::list::ListStyleType;
|
||||||
pub use self::list::Quotes;
|
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::outline::OutlineStyle;
|
||||||
pub use self::page::{PageName, PageOrientation, PageSize, PageSizeOrientation, PaperSize};
|
pub use self::page::{PageName, PageOrientation, PageSize, PageSizeOrientation, PaperSize};
|
||||||
pub use self::percentage::{NonNegativePercentage, Percentage};
|
pub use self::percentage::{NonNegativePercentage, Percentage};
|
||||||
|
|
|
@ -7,7 +7,10 @@
|
||||||
use crate::parser::{Parse, ParserContext};
|
use crate::parser::{Parse, ParserContext};
|
||||||
use crate::values::computed::motion::OffsetRotate as ComputedOffsetRotate;
|
use crate::values::computed::motion::OffsetRotate as ComputedOffsetRotate;
|
||||||
use crate::values::computed::{Context, ToComputedValue};
|
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::values::specified::{Angle, SVGPathData};
|
||||||
use crate::Zero;
|
use crate::Zero;
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
|
@ -16,6 +19,9 @@ use style_traits::{ParseError, StyleParseErrorKind};
|
||||||
/// The specified value of `offset-path`.
|
/// The specified value of `offset-path`.
|
||||||
pub type OffsetPath = GenericOffsetPath<Angle>;
|
pub type OffsetPath = GenericOffsetPath<Angle>;
|
||||||
|
|
||||||
|
/// The specified value of `offset-position`.
|
||||||
|
pub type OffsetPosition = GenericOffsetPosition<HorizontalPosition, VerticalPosition>;
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
fn is_ray_enabled() -> bool {
|
fn is_ray_enabled() -> bool {
|
||||||
static_prefs::pref!("layout.css.motion-path-ray.enabled")
|
static_prefs::pref!("layout.css.motion-path-ray.enabled")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue