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