style/values/computed/
animation.rs1use crate::values::computed::{Context, LengthPercentage, Time, ToComputedValue};
8use crate::values::generics::animation as generics;
9use crate::values::specified::animation as specified;
10use crate::values::CSSFloat;
11use std::fmt::{self, Write};
12use style_traits::{CssWriter, ToCss};
13
14pub use crate::values::specified::animation::{
15 AnimationComposition, AnimationDirection, AnimationFillMode, AnimationName, AnimationPlayState,
16 ScrollAxis, TimelineName, TransitionBehavior, TransitionProperty, ViewTransitionClass,
17 ViewTransitionName,
18};
19
20pub type AnimationDuration = generics::GenericAnimationDuration<Time>;
22
23impl AnimationDuration {
24 #[inline]
26 pub fn seconds(&self) -> CSSFloat {
27 match *self {
28 Self::Auto => 0.0,
29 Self::Time(ref t) => t.seconds(),
30 }
31 }
32}
33
34#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem)]
36#[repr(C)]
37pub struct AnimationIterationCount(pub f32);
38
39impl ToComputedValue for specified::AnimationIterationCount {
40 type ComputedValue = AnimationIterationCount;
41
42 #[inline]
43 fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
44 AnimationIterationCount(match *self {
45 specified::AnimationIterationCount::Number(n) => n.to_computed_value(context).0,
46 specified::AnimationIterationCount::Infinite => f32::INFINITY,
47 })
48 }
49
50 #[inline]
51 fn from_computed_value(computed: &Self::ComputedValue) -> Self {
52 use crate::values::specified::NonNegativeNumber;
53 if computed.0.is_infinite() {
54 specified::AnimationIterationCount::Infinite
55 } else {
56 specified::AnimationIterationCount::Number(NonNegativeNumber::new(computed.0))
57 }
58 }
59}
60
61impl AnimationIterationCount {
62 #[inline]
64 pub fn one() -> Self {
65 Self(1.0)
66 }
67}
68
69impl ToCss for AnimationIterationCount {
70 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
71 where
72 W: Write,
73 {
74 if self.0.is_infinite() {
75 dest.write_str("infinite")
76 } else {
77 self.0.to_css(dest)
78 }
79 }
80}
81
82pub type AnimationTimeline = generics::GenericAnimationTimeline<LengthPercentage>;
84
85pub type ViewTimelineInset = generics::GenericViewTimelineInset<LengthPercentage>;