mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Share computed animation-iteration-count representation between Servo and Gecko
This removes the special AnimationIterationCount -> f32 conversion from gecko.mako.rs which will be useful to simplify coordinated properties. Differential Revision: https://phabricator.services.mozilla.com/D167123
This commit is contained in:
parent
fa297196ef
commit
b96f8f748c
5 changed files with 67 additions and 73 deletions
|
@ -26,7 +26,6 @@ use crate::stylesheets::keyframes_rule::{KeyframesAnimation, KeyframesStep, Keyf
|
||||||
use crate::stylesheets::layer_rule::LayerOrder;
|
use crate::stylesheets::layer_rule::LayerOrder;
|
||||||
use crate::values::animated::{Animate, Procedure};
|
use crate::values::animated::{Animate, Procedure};
|
||||||
use crate::values::computed::{Time, TimingFunction};
|
use crate::values::computed::{Time, TimingFunction};
|
||||||
use crate::values::generics::box_::AnimationIterationCount;
|
|
||||||
use crate::values::generics::easing::BeforeFlag;
|
use crate::values::generics::easing::BeforeFlag;
|
||||||
use crate::Atom;
|
use crate::Atom;
|
||||||
use fxhash::FxHashMap;
|
use fxhash::FxHashMap;
|
||||||
|
@ -1338,9 +1337,11 @@ pub fn maybe_start_animations<E>(
|
||||||
// animation begins in a finished state.
|
// animation begins in a finished state.
|
||||||
let delay = style.animation_delay_mod(i).seconds();
|
let delay = style.animation_delay_mod(i).seconds();
|
||||||
|
|
||||||
let iteration_state = match style.animation_iteration_count_mod(i) {
|
let iteration_count = style.animation_iteration_count_mod(i);
|
||||||
AnimationIterationCount::Infinite => KeyframesIterationState::Infinite(0.0),
|
let iteration_state = if iteration_count.0.is_infinite() {
|
||||||
AnimationIterationCount::Number(n) => KeyframesIterationState::Finite(0.0, n.into()),
|
KeyframesIterationState::Infinite(0.0)
|
||||||
|
} else {
|
||||||
|
KeyframesIterationState::Finite(0.0, iteration_count.0 as f64)
|
||||||
};
|
};
|
||||||
|
|
||||||
let animation_direction = style.animation_direction_mod(i);
|
let animation_direction = style.animation_direction_mod(i);
|
||||||
|
|
|
@ -1949,9 +1949,6 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-
|
||||||
I: IntoIterator<Item = values::computed::AnimationIterationCount>,
|
I: IntoIterator<Item = values::computed::AnimationIterationCount>,
|
||||||
I::IntoIter: ExactSizeIterator + Clone
|
I::IntoIter: ExactSizeIterator + Clone
|
||||||
{
|
{
|
||||||
use std::f32;
|
|
||||||
use crate::values::generics::box_::AnimationIterationCount;
|
|
||||||
|
|
||||||
let v = v.into_iter();
|
let v = v.into_iter();
|
||||||
|
|
||||||
debug_assert_ne!(v.len(), 0);
|
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;
|
self.gecko.mAnimationIterationCountCount = input_len as u32;
|
||||||
for (gecko, servo) in self.gecko.mAnimations.iter_mut().take(input_len as usize).zip(v) {
|
for (gecko, servo) in self.gecko.mAnimations.iter_mut().take(input_len as usize).zip(v) {
|
||||||
match servo {
|
gecko.mIterationCount = servo;
|
||||||
AnimationIterationCount::Number(n) => gecko.mIterationCount = n,
|
|
||||||
AnimationIterationCount::Infinite => gecko.mIterationCount = f32::INFINITY,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1971,13 +1965,7 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-
|
||||||
&self,
|
&self,
|
||||||
index: usize,
|
index: usize,
|
||||||
) -> values::computed::AnimationIterationCount {
|
) -> values::computed::AnimationIterationCount {
|
||||||
use crate::values::generics::box_::AnimationIterationCount;
|
self.gecko.mAnimations[index].mIterationCount
|
||||||
|
|
||||||
if self.gecko.mAnimations[index].mIterationCount.is_infinite() {
|
|
||||||
AnimationIterationCount::Infinite
|
|
||||||
} else {
|
|
||||||
AnimationIterationCount::Number(self.gecko.mAnimations[index].mIterationCount)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
${impl_animation_count('iteration_count', 'IterationCount')}
|
${impl_animation_count('iteration_count', 'IterationCount')}
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
|
|
||||||
use crate::values::animated::{Animate, Procedure};
|
use crate::values::animated::{Animate, Procedure};
|
||||||
use crate::values::computed::length::{LengthPercentage, NonNegativeLength};
|
use crate::values::computed::length::{LengthPercentage, NonNegativeLength};
|
||||||
use crate::values::computed::{Context, Integer, Number, ToComputedValue};
|
use crate::values::computed::{Context, Integer, ToComputedValue};
|
||||||
use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
|
|
||||||
use crate::values::generics::box_::{
|
use crate::values::generics::box_::{
|
||||||
GenericContainIntrinsicSize, GenericLineClamp, GenericPerspective, GenericVerticalAlign,
|
GenericContainIntrinsicSize, GenericLineClamp, GenericPerspective, GenericVerticalAlign,
|
||||||
};
|
};
|
||||||
|
@ -22,11 +21,59 @@ pub use crate::values::specified::box_::{
|
||||||
WillChange,
|
WillChange,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use std::fmt::{self, Write};
|
||||||
|
use style_traits::{ToCss, CssWriter};
|
||||||
|
|
||||||
/// A computed value for the `vertical-align` property.
|
/// A computed value for the `vertical-align` property.
|
||||||
pub type VerticalAlign = GenericVerticalAlign<LengthPercentage>;
|
pub type VerticalAlign = GenericVerticalAlign<LengthPercentage>;
|
||||||
|
|
||||||
/// A computed value for the `animation-iteration-count` property.
|
/// A computed value for the `animation-iteration-count` property.
|
||||||
pub type AnimationIterationCount = GenericAnimationIterationCount<Number>;
|
#[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<W>(&self, dest: &mut CssWriter<W>) -> 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.
|
/// A computed value for the `contain-intrinsic-size` property.
|
||||||
pub type ContainIntrinsicSize = GenericContainIntrinsicSize<NonNegativeLength>;
|
pub type ContainIntrinsicSize = GenericContainIntrinsicSize<NonNegativeLength>;
|
||||||
|
@ -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.
|
/// A computed value for the `perspective` property.
|
||||||
pub type Perspective = GenericPerspective<NonNegativeLength>;
|
pub type Perspective = GenericPerspective<NonNegativeLength>;
|
||||||
|
|
||||||
|
|
|
@ -171,27 +171,6 @@ impl<I: crate::Zero + ToCss> ToCss for LineClamp<I> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-animations/#animation-iteration-count
|
|
||||||
#[derive(
|
|
||||||
Clone,
|
|
||||||
Debug,
|
|
||||||
MallocSizeOf,
|
|
||||||
PartialEq,
|
|
||||||
SpecifiedValueInfo,
|
|
||||||
ToComputedValue,
|
|
||||||
ToCss,
|
|
||||||
ToResolvedValue,
|
|
||||||
ToShmem,
|
|
||||||
)]
|
|
||||||
pub enum GenericAnimationIterationCount<Number> {
|
|
||||||
/// A `<number>` value.
|
|
||||||
Number(Number),
|
|
||||||
/// The `infinite` keyword.
|
|
||||||
Infinite,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub use self::GenericAnimationIterationCount as AnimationIterationCount;
|
|
||||||
|
|
||||||
/// A generic value for the `perspective` property.
|
/// A generic value for the `perspective` property.
|
||||||
#[derive(
|
#[derive(
|
||||||
Animate,
|
Animate,
|
||||||
|
|
|
@ -9,13 +9,11 @@ use crate::parser::{Parse, ParserContext};
|
||||||
use crate::properties::{LonghandId, PropertyDeclarationId};
|
use crate::properties::{LonghandId, PropertyDeclarationId};
|
||||||
use crate::properties::{PropertyId, ShorthandId};
|
use crate::properties::{PropertyId, ShorthandId};
|
||||||
use crate::values::generics::box_::{
|
use crate::values::generics::box_::{
|
||||||
GenericAnimationIterationCount, GenericLineClamp, GenericPerspective,
|
GenericLineClamp, GenericPerspective, GenericContainIntrinsicSize, GenericVerticalAlign,
|
||||||
};
|
VerticalAlignKeyword,
|
||||||
use crate::values::generics::box_::{
|
|
||||||
GenericContainIntrinsicSize, GenericVerticalAlign, VerticalAlignKeyword,
|
|
||||||
};
|
};
|
||||||
use crate::values::specified::length::{LengthPercentage, NonNegativeLength};
|
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::values::{CustomIdent, KeyframesName, TimelineName};
|
||||||
use crate::Atom;
|
use crate::Atom;
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
|
@ -634,30 +632,19 @@ impl Parse for VerticalAlign {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-animations/#animation-iteration-count
|
/// https://drafts.csswg.org/css-animations/#animation-iteration-count
|
||||||
pub type AnimationIterationCount = GenericAnimationIterationCount<Number>;
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, Parse, SpecifiedValueInfo, ToCss, ToShmem)]
|
||||||
|
pub enum AnimationIterationCount {
|
||||||
impl Parse for AnimationIterationCount {
|
/// A `<number>` value.
|
||||||
fn parse<'i, 't>(
|
Number(NonNegativeNumber),
|
||||||
context: &ParserContext,
|
/// The `infinite` keyword.
|
||||||
input: &mut ::cssparser::Parser<'i, 't>,
|
Infinite,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnimationIterationCount {
|
impl AnimationIterationCount {
|
||||||
/// Returns the value `1.0`.
|
/// Returns the value `1.0`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn one() -> Self {
|
pub fn one() -> Self {
|
||||||
GenericAnimationIterationCount::Number(Number::new(1.0))
|
Self::Number(NonNegativeNumber::new(1.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue