mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +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::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<E>(
|
|||
// 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);
|
||||
|
|
|
@ -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::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')}
|
||||
|
|
|
@ -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<LengthPercentage>;
|
||||
|
||||
/// 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.
|
||||
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.
|
||||
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.
|
||||
#[derive(
|
||||
Animate,
|
||||
|
|
|
@ -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<Number>;
|
||||
|
||||
impl Parse for AnimationIterationCount {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut ::cssparser::Parser<'i, 't>,
|
||||
) -> 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))
|
||||
}
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, Parse, SpecifiedValueInfo, ToCss, ToShmem)]
|
||||
pub enum AnimationIterationCount {
|
||||
/// A `<number>` 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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue