diff --git a/components/style/animation.rs b/components/style/animation.rs index b8b98dcb4e4..aafe7067dc9 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -26,7 +26,6 @@ use crate::stylesheets::keyframes_rule::{KeyframesAnimation, KeyframesStep, Keyf use crate::stylesheets::layer_rule::LayerOrder; use crate::values::animated::{Animate, Procedure}; use crate::values::computed::{Time, TimingFunction}; -use crate::values::generics::box_::AnimationIterationCount; use crate::values::generics::easing::BeforeFlag; use crate::Atom; use fxhash::FxHashMap; @@ -1338,9 +1337,11 @@ pub fn maybe_start_animations( // animation begins in a finished state. let delay = style.animation_delay_mod(i).seconds(); - let iteration_state = match style.animation_iteration_count_mod(i) { - AnimationIterationCount::Infinite => KeyframesIterationState::Infinite(0.0), - AnimationIterationCount::Number(n) => KeyframesIterationState::Finite(0.0, n.into()), + let iteration_count = style.animation_iteration_count_mod(i); + let iteration_state = if iteration_count.0.is_infinite() { + KeyframesIterationState::Infinite(0.0) + } else { + KeyframesIterationState::Finite(0.0, iteration_count.0 as f64) }; let animation_direction = style.animation_direction_mod(i); diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 63316c09b07..c799ebdb03f 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1949,9 +1949,6 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask- I: IntoIterator, I::IntoIter: ExactSizeIterator + Clone { - use std::f32; - use crate::values::generics::box_::AnimationIterationCount; - let v = v.into_iter(); debug_assert_ne!(v.len(), 0); @@ -1960,10 +1957,7 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask- self.gecko.mAnimationIterationCountCount = input_len as u32; for (gecko, servo) in self.gecko.mAnimations.iter_mut().take(input_len as usize).zip(v) { - match servo { - AnimationIterationCount::Number(n) => gecko.mIterationCount = n, - AnimationIterationCount::Infinite => gecko.mIterationCount = f32::INFINITY, - } + gecko.mIterationCount = servo; } } @@ -1971,13 +1965,7 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask- &self, index: usize, ) -> values::computed::AnimationIterationCount { - use crate::values::generics::box_::AnimationIterationCount; - - if self.gecko.mAnimations[index].mIterationCount.is_infinite() { - AnimationIterationCount::Infinite - } else { - AnimationIterationCount::Number(self.gecko.mAnimations[index].mIterationCount) - } + self.gecko.mAnimations[index].mIterationCount } ${impl_animation_count('iteration_count', 'IterationCount')} diff --git a/components/style/values/computed/box.rs b/components/style/values/computed/box.rs index a390d69a029..06f83aa70ad 100644 --- a/components/style/values/computed/box.rs +++ b/components/style/values/computed/box.rs @@ -6,8 +6,7 @@ use crate::values::animated::{Animate, Procedure}; use crate::values::computed::length::{LengthPercentage, NonNegativeLength}; -use crate::values::computed::{Context, Integer, Number, ToComputedValue}; -use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount; +use crate::values::computed::{Context, Integer, ToComputedValue}; use crate::values::generics::box_::{ GenericContainIntrinsicSize, GenericLineClamp, GenericPerspective, GenericVerticalAlign, }; @@ -22,11 +21,59 @@ pub use crate::values::specified::box_::{ WillChange, }; +use std::fmt::{self, Write}; +use style_traits::{ToCss, CssWriter}; + /// A computed value for the `vertical-align` property. pub type VerticalAlign = GenericVerticalAlign; /// A computed value for the `animation-iteration-count` property. -pub type AnimationIterationCount = GenericAnimationIterationCount; +#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem)] +#[repr(C)] +pub struct AnimationIterationCount(pub f32); + +impl ToComputedValue for specified::AnimationIterationCount { + type ComputedValue = AnimationIterationCount; + + #[inline] + fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { + AnimationIterationCount(match *self { + specified::AnimationIterationCount::Number(n) => n.to_computed_value(context).0, + specified::AnimationIterationCount::Infinite => std::f32::INFINITY, + }) + } + + #[inline] + fn from_computed_value(computed: &Self::ComputedValue) -> Self { + use crate::values::specified::NonNegativeNumber; + if computed.0.is_infinite() { + specified::AnimationIterationCount::Infinite + } else { + specified::AnimationIterationCount::Number(NonNegativeNumber::new(computed.0)) + } + } +} + +impl AnimationIterationCount { + /// Returns the value `1.0`. + #[inline] + pub fn one() -> Self { + Self(1.0) + } +} + +impl ToCss for AnimationIterationCount { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { + if self.0.is_infinite() { + dest.write_str("infinite") + } else { + self.0.to_css(dest) + } + } +} /// A computed value for the `contain-intrinsic-size` property. pub type ContainIntrinsicSize = GenericContainIntrinsicSize; @@ -47,14 +94,6 @@ impl Animate for LineClamp { } } -impl AnimationIterationCount { - /// Returns the value `1.0`. - #[inline] - pub fn one() -> Self { - GenericAnimationIterationCount::Number(1.0) - } -} - /// A computed value for the `perspective` property. pub type Perspective = GenericPerspective; diff --git a/components/style/values/generics/box.rs b/components/style/values/generics/box.rs index 1885017cc22..3cc2b051455 100644 --- a/components/style/values/generics/box.rs +++ b/components/style/values/generics/box.rs @@ -171,27 +171,6 @@ impl ToCss for LineClamp { } } -/// https://drafts.csswg.org/css-animations/#animation-iteration-count -#[derive( - Clone, - Debug, - MallocSizeOf, - PartialEq, - SpecifiedValueInfo, - ToComputedValue, - ToCss, - ToResolvedValue, - ToShmem, -)] -pub enum GenericAnimationIterationCount { - /// A `` value. - Number(Number), - /// The `infinite` keyword. - Infinite, -} - -pub use self::GenericAnimationIterationCount as AnimationIterationCount; - /// A generic value for the `perspective` property. #[derive( Animate, diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 582d1502bd3..c6c6d3f1bcc 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -9,13 +9,11 @@ use crate::parser::{Parse, ParserContext}; use crate::properties::{LonghandId, PropertyDeclarationId}; use crate::properties::{PropertyId, ShorthandId}; use crate::values::generics::box_::{ - GenericAnimationIterationCount, GenericLineClamp, GenericPerspective, -}; -use crate::values::generics::box_::{ - GenericContainIntrinsicSize, GenericVerticalAlign, VerticalAlignKeyword, + GenericLineClamp, GenericPerspective, GenericContainIntrinsicSize, GenericVerticalAlign, + VerticalAlignKeyword, }; use crate::values::specified::length::{LengthPercentage, NonNegativeLength}; -use crate::values::specified::{AllowQuirks, Integer, Number}; +use crate::values::specified::{AllowQuirks, Integer, NonNegativeNumber}; use crate::values::{CustomIdent, KeyframesName, TimelineName}; use crate::Atom; use cssparser::Parser; @@ -634,30 +632,19 @@ impl Parse for VerticalAlign { } /// https://drafts.csswg.org/css-animations/#animation-iteration-count -pub type AnimationIterationCount = GenericAnimationIterationCount; - -impl Parse for AnimationIterationCount { - fn parse<'i, 't>( - context: &ParserContext, - input: &mut ::cssparser::Parser<'i, 't>, - ) -> Result> { - if input - .try_parse(|input| input.expect_ident_matching("infinite")) - .is_ok() - { - return Ok(GenericAnimationIterationCount::Infinite); - } - - let number = Number::parse_non_negative(context, input)?; - Ok(GenericAnimationIterationCount::Number(number)) - } +#[derive(Clone, Debug, MallocSizeOf, PartialEq, Parse, SpecifiedValueInfo, ToCss, ToShmem)] +pub enum AnimationIterationCount { + /// A `` value. + Number(NonNegativeNumber), + /// The `infinite` keyword. + Infinite, } impl AnimationIterationCount { /// Returns the value `1.0`. #[inline] pub fn one() -> Self { - GenericAnimationIterationCount::Number(Number::new(1.0)) + Self::Number(NonNegativeNumber::new(1.0)) } }