From 65356b13f89fb08ab6aeef31fb2b9b43b9ca3c5e Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 6 Jun 2017 00:30:31 +0200 Subject: [PATCH 1/4] Use predefined_type for transition-property --- .../helpers/animated_properties.mako.rs | 9 ++-- .../style/properties/longhand/box.mako.rs | 41 +++++-------------- components/style/values/computed/mod.rs | 1 + components/style/values/specified/mod.rs | 1 + 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index f018967fb9a..d98b66b8e29 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -39,9 +39,8 @@ use values::CSSFloat; use values::{Auto, Either}; use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use values::computed::{BorderCornerRadius, ClipRect}; -use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage}; -use values::computed::{MaxLength, MozLength}; -use values::computed::ToComputedValue; +use values::computed::{CalcLengthOrPercentage, Context, ComputedValueAsSpecified}; +use values::computed::{LengthOrPercentage, MaxLength, MozLength, ToComputedValue}; use values::generics::{SVGPaint, SVGPaintKind}; use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius; use values::generics::position as generic_position; @@ -73,6 +72,10 @@ pub enum TransitionProperty { Unsupported(Atom) } +no_viewport_percentage!(TransitionProperty); + +impl ComputedValueAsSpecified for TransitionProperty {} + impl TransitionProperty { /// Iterates over each longhand property. pub fn each ()>(mut cb: F) { diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 8ab5e298dbf..1d08c759853 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -424,36 +424,17 @@ ${helpers.predefined_type("transition-timing-function", extra_prefixes="moz webkit", spec="https://drafts.csswg.org/css-transitions/#propdef-transition-timing-function")} -<%helpers:vector_longhand name="transition-property" - allow_empty="True" - need_index="True" - animation_value_type="none" - extra_prefixes="moz webkit" - spec="https://drafts.csswg.org/css-transitions/#propdef-transition-property"> - - use values::computed::ComputedValueAsSpecified; - - pub use properties::animated_properties::TransitionProperty; - pub use properties::animated_properties::TransitionProperty as SpecifiedValue; - - pub mod computed_value { - // NB: Can't generate the type here because it needs all the longhands - // generated beforehand. - pub use super::SpecifiedValue as T; - } - - pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - SpecifiedValue::parse(input) - } - - pub fn get_initial_specified_value() -> SpecifiedValue { - TransitionProperty::All - } - - no_viewport_percentage!(SpecifiedValue); - - impl ComputedValueAsSpecified for SpecifiedValue { } - +${helpers.predefined_type("transition-property", + "TransitionProperty", + "computed::TransitionProperty::All", + initial_specified_value="specified::TransitionProperty::All", + vector=True, + allow_empty=True, + need_index=True, + needs_context=False, + animation_value_type="none", + extra_prefixes="moz webkit", + spec="https://drafts.csswg.org/css-transitions/#propdef-transition-property")} ${helpers.predefined_type("transition-delay", "Time", diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 26165dc4e13..4f4bdd883cb 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -23,6 +23,7 @@ use super::specified; pub use app_units::Au; pub use cssparser::Color as CSSColor; +pub use properties::animated_properties::TransitionProperty; pub use self::background::BackgroundSize; pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth}; pub use self::border::{BorderRadius, BorderCornerRadius}; diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 2299362f6de..6dff0cad04a 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -27,6 +27,7 @@ use super::generics::grid::TrackList as GenericTrackList; use values::computed::ComputedValueAsSpecified; use values::specified::calc::CalcNode; +pub use properties::animated_properties::TransitionProperty; #[cfg(feature = "gecko")] pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems}; pub use self::background::BackgroundSize; From 8912a594c7dab237c9de781c804c2c6db2eb5d77 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 6 Jun 2017 00:46:58 +0200 Subject: [PATCH 2/4] Use predefined_type for animation-timing-function --- .../style/properties/longhand/box.mako.rs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 1d08c759853..7803e182fe1 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -528,18 +528,16 @@ ${helpers.predefined_type("animation-duration", extra_prefixes="moz webkit", spec="https://drafts.csswg.org/css-transitions/#propdef-transition-duration")} -<%helpers:vector_longhand name="animation-timing-function" - need_index="True" +${helpers.predefined_type("animation-timing-function", + "TimingFunction", + "computed::TimingFunction::ease()", + initial_specified_value="specified::TimingFunction::ease()", + vector=True, + need_index=True, animation_value_type="none", - extra_prefixes="moz webkit" - spec="https://drafts.csswg.org/css-animations/#propdef-animation-timing-function", - allowed_in_keyframe_block="True"> - pub use properties::longhands::transition_timing_function::single_value::computed_value; - pub use properties::longhands::transition_timing_function::single_value::get_initial_value; - pub use properties::longhands::transition_timing_function::single_value::get_initial_specified_value; - pub use properties::longhands::transition_timing_function::single_value::parse; - pub use properties::longhands::transition_timing_function::single_value::SpecifiedValue; - + extra_prefixes="moz webkit", + allowed_in_keyframe_block=True, + spec="https://drafts.csswg.org/css-transitions/#propdef-animation-timing-function")} <%helpers:vector_longhand name="animation-iteration-count" need_index="True" From bc1eef8f5e70ae8a45f204f8c7feed4e2994a29a Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 6 Jun 2017 00:52:09 +0200 Subject: [PATCH 3/4] Use predefined_type for transition-delay --- .../style/properties/longhand/box.mako.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 7803e182fe1..c3b73da9514 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -444,7 +444,7 @@ ${helpers.predefined_type("transition-delay", need_index=True, animation_value_type="none", extra_prefixes="moz webkit", - spec="https://drafts.csswg.org/css-transitions/#propdef-transition-duration")} + spec="https://drafts.csswg.org/css-transitions/#propdef-transition-delay")} <%helpers:vector_longhand name="animation-name" need_index="True" @@ -639,17 +639,16 @@ ${helpers.single_keyword("animation-fill-mode", spec="https://drafts.csswg.org/css-animations/#propdef-animation-fill-mode", allowed_in_keyframe_block=False)} -<%helpers:vector_longhand name="animation-delay" - need_index="True" +${helpers.predefined_type("animation-delay", + "Time", + "computed::Time::zero()", + initial_specified_value="specified::Time::zero()", + vector=True, + need_index=True, animation_value_type="none", extra_prefixes="moz webkit", spec="https://drafts.csswg.org/css-animations/#propdef-animation-delay", - allowed_in_keyframe_block="False"> - pub use properties::longhands::transition_delay::single_value::computed_value; - pub use properties::longhands::transition_delay::single_value::get_initial_specified_value; - pub use properties::longhands::transition_delay::single_value::{get_initial_value, parse}; - pub use properties::longhands::transition_delay::single_value::SpecifiedValue; - + allowed_in_keyframe_block=False)} <%helpers:longhand products="gecko" name="scroll-snap-points-y" animation_value_type="none" spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)"> From 195e98e74579b8a8fd65e6ac0708d615aaceadf5 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 6 Jun 2017 14:28:24 +0200 Subject: [PATCH 4/4] Use generics for scroll-snap-points-* --- components/style/properties/gecko.mako.rs | 25 ++--- .../style/properties/longhand/box.mako.rs | 104 ++---------------- components/style/values/computed/gecko.rs | 11 ++ components/style/values/computed/mod.rs | 4 + components/style/values/generics/gecko.rs | 54 +++++++++ components/style/values/generics/mod.rs | 2 + components/style/values/specified/gecko.rs | 26 +++++ components/style/values/specified/mod.rs | 6 +- 8 files changed, 122 insertions(+), 110 deletions(-) create mode 100644 components/style/values/computed/gecko.rs create mode 100644 components/style/values/generics/gecko.rs create mode 100644 components/style/values/specified/gecko.rs diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 2186967279a..3c8e359e4de 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -2232,23 +2232,16 @@ fn static_assert() { } % endfor - pub fn set_scroll_snap_points_x(&mut self, v: longhands::scroll_snap_points_x::computed_value::T) { - match v.0 { - None => self.gecko.mScrollSnapPointsX.set_value(CoordDataValue::None), - Some(l) => l.to_gecko_style_coord(&mut self.gecko.mScrollSnapPointsX), - }; - } + % for axis in ["x", "y"]: + pub fn set_scroll_snap_points_${axis}(&mut self, v: longhands::scroll_snap_points_${axis}::computed_value::T) { + match v.repeated() { + None => self.gecko.mScrollSnapPoints${axis.upper()}.set_value(CoordDataValue::None), + Some(l) => l.to_gecko_style_coord(&mut self.gecko.mScrollSnapPoints${axis.upper()}), + }; + } - ${impl_coord_copy('scroll_snap_points_x', 'mScrollSnapPointsX')} - - pub fn set_scroll_snap_points_y(&mut self, v: longhands::scroll_snap_points_y::computed_value::T) { - match v.0 { - None => self.gecko.mScrollSnapPointsY.set_value(CoordDataValue::None), - Some(l) => l.to_gecko_style_coord(&mut self.gecko.mScrollSnapPointsY), - }; - } - - ${impl_coord_copy('scroll_snap_points_y', 'mScrollSnapPointsY')} + ${impl_coord_copy('scroll_snap_points_' + axis, 'mScrollSnapPoints' + axis.upper())} + % endfor pub fn set_scroll_snap_coordinate(&mut self, v: I) where I: IntoIterator, diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index c3b73da9514..623810c8724 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -650,99 +650,17 @@ ${helpers.predefined_type("animation-delay", spec="https://drafts.csswg.org/css-animations/#propdef-animation-delay", allowed_in_keyframe_block=False)} -<%helpers:longhand products="gecko" name="scroll-snap-points-y" animation_value_type="none" - spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)"> - use std::fmt; - use style_traits::ToCss; - use values::specified::LengthOrPercentage; - - pub mod computed_value { - use values::computed::LengthOrPercentage; - - #[derive(Debug, Clone, PartialEq)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub struct T(pub Option); - } - - #[derive(Clone, Debug, HasViewportPercentage, PartialEq)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub enum SpecifiedValue { - None, - Repeat(LengthOrPercentage), - } - - impl ToCss for computed_value::T { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match self.0 { - None => dest.write_str("none"), - Some(ref l) => { - try!(dest.write_str("repeat(")); - try!(l.to_css(dest)); - dest.write_str(")") - }, - } - } - } - impl ToCss for SpecifiedValue { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - SpecifiedValue::None => dest.write_str("none"), - SpecifiedValue::Repeat(ref l) => { - try!(dest.write_str("repeat(")); - try!(l.to_css(dest)); - dest.write_str(")") - }, - } - } - } - - #[inline] - pub fn get_initial_value() -> computed_value::T { - computed_value::T(None) - } - - impl ToComputedValue for SpecifiedValue { - type ComputedValue = computed_value::T; - - #[inline] - fn to_computed_value(&self, context: &Context) -> computed_value::T { - match *self { - SpecifiedValue::None => computed_value::T(None), - SpecifiedValue::Repeat(ref l) => - computed_value::T(Some(l.to_computed_value(context))), - } - } - #[inline] - fn from_computed_value(computed: &computed_value::T) -> Self { - match *computed { - computed_value::T(None) => SpecifiedValue::None, - computed_value::T(Some(l)) => - SpecifiedValue::Repeat(ToComputedValue::from_computed_value(&l)) - } - } - } - - pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { - if input.try(|input| input.expect_ident_matching("none")).is_ok() { - Ok(SpecifiedValue::None) - } else if input.try(|input| input.expect_function_matching("repeat")).is_ok() { - input.parse_nested_block(|input| { - LengthOrPercentage::parse_non_negative(context, input).map(SpecifiedValue::Repeat) - }) - } else { - Err(()) - } - } - - -<%helpers:longhand products="gecko" name="scroll-snap-points-x" animation_value_type="none" - spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)"> - pub use super::scroll_snap_points_y::SpecifiedValue; - pub use super::scroll_snap_points_y::computed_value; - pub use super::scroll_snap_points_y::get_initial_value; - pub use super::scroll_snap_points_y::parse; - - +% for axis in ["x", "y"]: + ${helpers.predefined_type( + "scroll-snap-points-" + axis, + "ScrollSnapPoint", + "computed::ScrollSnapPoint::none()", + animation_value_type="none", + products="gecko", + disable_when_testing=True, + spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)", + )} +% endfor ${helpers.predefined_type("scroll-snap-destination", "Position", diff --git a/components/style/values/computed/gecko.rs b/components/style/values/computed/gecko.rs new file mode 100644 index 00000000000..96ca82669cd --- /dev/null +++ b/components/style/values/computed/gecko.rs @@ -0,0 +1,11 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Computed types for legacy Gecko-only properties. + +use values::computed::length::LengthOrPercentage; +use values::generics::gecko::ScrollSnapPoint as GenericScrollSnapPoint; + +/// A computed type for scroll snap points. +pub type ScrollSnapPoint = GenericScrollSnapPoint; diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 4f4bdd883cb..acfc09f5c80 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -28,6 +28,8 @@ pub use self::background::BackgroundSize; pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth}; pub use self::border::{BorderRadius, BorderCornerRadius}; pub use self::image::{Gradient, GradientItem, ImageLayer, LineDirection, Image, ImageRect}; +#[cfg(feature = "gecko")] +pub use self::gecko::ScrollSnapPoint; pub use self::rect::LengthOrNumberRect; pub use super::{Auto, Either, None_}; #[cfg(feature = "gecko")] @@ -46,6 +48,8 @@ pub mod background; pub mod basic_shape; pub mod border; pub mod image; +#[cfg(feature = "gecko")] +pub mod gecko; pub mod length; pub mod position; pub mod rect; diff --git a/components/style/values/generics/gecko.rs b/components/style/values/generics/gecko.rs new file mode 100644 index 00000000000..52c7b130992 --- /dev/null +++ b/components/style/values/generics/gecko.rs @@ -0,0 +1,54 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Generic types for legacy Gecko-only properties that should probably be +//! unshipped at some point in the future. + +use std::fmt; +use style_traits::ToCss; + +/// A generic value for scroll snap points. +#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)] +pub enum ScrollSnapPoint { + /// `none` + None, + /// `repeat()` + Repeat(LengthOrPercentage) +} + +impl ScrollSnapPoint { + /// Returns `none`. + #[inline] + pub fn none() -> Self { + ScrollSnapPoint::None + } + + /// Returns the repeat argument, if any. + #[inline] + pub fn repeated(&self) -> Option<&L> { + match *self { + ScrollSnapPoint::None => None, + ScrollSnapPoint::Repeat(ref length) => Some(length), + } + } +} + +impl ToCss for ScrollSnapPoint +where + L: ToCss, +{ + fn to_css(&self, dest: &mut W) -> fmt::Result + where + W: fmt::Write, + { + match *self { + ScrollSnapPoint::None => dest.write_str("none"), + ScrollSnapPoint::Repeat(ref length) => { + dest.write_str("repeat(")?; + length.to_css(dest)?; + dest.write_str(")") + }, + } + } +} diff --git a/components/style/values/generics/mod.rs b/components/style/values/generics/mod.rs index 3ff55fda6c8..ef88d7c342c 100644 --- a/components/style/values/generics/mod.rs +++ b/components/style/values/generics/mod.rs @@ -16,6 +16,8 @@ use values::specified::url::SpecifiedUrl; pub mod background; pub mod basic_shape; pub mod border; +#[cfg(feature = "gecko")] +pub mod gecko; pub mod grid; pub mod image; pub mod position; diff --git a/components/style/values/specified/gecko.rs b/components/style/values/specified/gecko.rs new file mode 100644 index 00000000000..08af968463e --- /dev/null +++ b/components/style/values/specified/gecko.rs @@ -0,0 +1,26 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Specified types for legacy Gecko-only properties. + +use cssparser::Parser; +use parser::{Parse, ParserContext}; +use values::generics::gecko::ScrollSnapPoint as GenericScrollSnapPoint; +use values::specified::length::LengthOrPercentage; + +/// A specified type for scroll snap points. +pub type ScrollSnapPoint = GenericScrollSnapPoint; + +impl Parse for ScrollSnapPoint { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + if input.try(|i| i.expect_ident_matching("none")).is_ok() { + return Ok(GenericScrollSnapPoint::None); + } + input.expect_function_matching("repeat")?; + let length = input.parse_nested_block(|i| { + LengthOrPercentage::parse_non_negative(context, i) + })?; + Ok(GenericScrollSnapPoint::Repeat(length)) + } +} diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 6dff0cad04a..b198295064f 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -35,7 +35,8 @@ pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth}; pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth}; pub use self::color::Color; pub use self::rect::LengthOrNumberRect; -pub use super::generics::grid::GridLine; +#[cfg(feature = "gecko")] +pub use self::gecko::ScrollSnapPoint; pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient}; pub use self::image::{GradientItem, GradientKind, Image, ImageRect, ImageLayer}; pub use self::length::AbsoluteLength; @@ -46,6 +47,7 @@ pub use self::length::{MaxLength, MozLength}; pub use self::position::{Position, PositionComponent}; pub use self::text::{LetterSpacing, LineHeight, WordSpacing}; pub use self::transform::{TimingFunction, TransformOrigin}; +pub use super::generics::grid::GridLine; #[cfg(feature = "gecko")] pub mod align; @@ -54,6 +56,8 @@ pub mod basic_shape; pub mod border; pub mod calc; pub mod color; +#[cfg(feature = "gecko")] +pub mod gecko; pub mod grid; pub mod image; pub mod length;