From 4a23556c4ba70d8a6efbcd736f780bf512efc6ec Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Mon, 23 Sep 2019 19:56:33 +0000 Subject: [PATCH] style: Add offset shorthand. Also, update the serialization by the shorter perference because this is a new feature and using older syntax doesn't make sense. Besides, use `cssOffset` for web animation IDL attribute name. Differential Revision: https://phabricator.services.mozilla.com/D45607 --- .../properties/counted_unknown_properties.py | 4 +- .../style/properties/shorthands/box.mako.rs | 76 +++++++++++++++++++ components/style/values/specified/motion.rs | 17 +++++ 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/components/style/properties/counted_unknown_properties.py b/components/style/properties/counted_unknown_properties.py index 628d7463ded..826bbf740a3 100644 --- a/components/style/properties/counted_unknown_properties.py +++ b/components/style/properties/counted_unknown_properties.py @@ -9,7 +9,8 @@ # "column-span", # "offset-distance", # "offset-path", -# "offset-rotate" +# "offset-rotate", +# "offset" COUNTED_UNKNOWN_PROPERTIES = [ "-webkit-font-smoothing", "zoom", @@ -82,7 +83,6 @@ COUNTED_UNKNOWN_PROPERTIES = [ "-webkit-ruby-position", "-webkit-column-break-after", "-webkit-margin-collapse", - "offset", "-webkit-border-before", "-webkit-border-end", "-webkit-border-after", diff --git a/components/style/properties/shorthands/box.mako.rs b/components/style/properties/shorthands/box.mako.rs index b0893e110b9..84d2cb220bd 100644 --- a/components/style/properties/shorthands/box.mako.rs +++ b/components/style/properties/shorthands/box.mako.rs @@ -365,3 +365,79 @@ ${helpers.two_properties_shorthand( } } + +<%helpers:shorthand name="offset" + engines="gecko" + sub_properties="offset-path offset-distance offset-rotate offset-anchor" + 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::Zero; + + pub fn parse_value<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + // FIXME: Bug 1559232: Support offset-position. + // Per the spec, this must have offet-position and/or offset-path. However, we don't + // support offset-position, so offset-path is necessary now. + let offset_path = OffsetPath::parse(context, input)?; + + let mut offset_distance = None; + let mut offset_rotate = None; + loop { + if offset_distance.is_none() { + if let Ok(value) = input.try(|i| LengthPercentage::parse(context, i)) { + offset_distance = Some(value); + } + } + + if offset_rotate.is_none() { + if let Ok(value) = input.try(|i| OffsetRotate::parse(context, i)) { + offset_rotate = Some(value); + continue; + } + } + break; + } + + let offset_anchor = input.try(|i| { + i.expect_delim('/')?; + PositionOrAuto::parse(context, i) + }).ok(); + + Ok(expanded! { + offset_path: offset_path, + offset_distance: offset_distance.unwrap_or(LengthPercentage::zero()), + offset_rotate: offset_rotate.unwrap_or(OffsetRotate::auto()), + offset_anchor: offset_anchor.unwrap_or(PositionOrAuto::auto()), + }) + } + + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { + // FIXME: Bug 1559232: Support offset-position. We don't support offset-position, + // so always serialize offset-path now. + self.offset_path.to_css(dest)?; + + if !self.offset_distance.is_zero() { + dest.write_str(" ")?; + self.offset_distance.to_css(dest)?; + } + + if !self.offset_rotate.is_auto() { + dest.write_str(" ")?; + self.offset_rotate.to_css(dest)?; + } + + if *self.offset_anchor != PositionOrAuto::auto() { + dest.write_str(" / ")?; + self.offset_anchor.to_css(dest)?; + } + Ok(()) + } + } + diff --git a/components/style/values/specified/motion.rs b/components/style/values/specified/motion.rs index 68800c405dd..90652b5ed64 100644 --- a/components/style/values/specified/motion.rs +++ b/components/style/values/specified/motion.rs @@ -130,6 +130,23 @@ pub struct OffsetRotate { angle: Angle, } +impl OffsetRotate { + /// Returns the initial value, auto. + #[inline] + pub fn auto() -> Self { + OffsetRotate { + direction: OffsetRotateDirection::Auto, + angle: Angle::zero(), + } + } + + /// Returns true if self is auto 0deg. + #[inline] + pub fn is_auto(&self) -> bool { + self.direction == OffsetRotateDirection::Auto && self.angle.is_zero() + } +} + impl Parse for OffsetRotate { fn parse<'i, 't>( context: &ParserContext,