style/values/computed/
animation.rs1use crate::derives::*;
8use crate::typed_om::{KeywordValue, ToTyped, TypedValue};
9use crate::values::computed::{Context, LengthPercentage, Time, ToComputedValue};
10use crate::values::generics::animation as generics;
11use crate::values::specified::animation as specified;
12use crate::values::CSSFloat;
13use std::fmt::{self, Write};
14use style_traits::{CssString, CssWriter, ToCss};
15use thin_vec::ThinVec;
16
17pub use crate::values::specified::animation::{
18 AnimationComposition, AnimationDirection, AnimationFillMode, AnimationName, AnimationPlayState,
19 ScrollAxis, TimelineName, TransitionBehavior, TransitionProperty, ViewTransitionClass,
20 ViewTransitionName,
21};
22
23pub type AnimationDuration = generics::GenericAnimationDuration<Time>;
25
26impl AnimationDuration {
27 #[inline]
29 pub fn seconds(&self) -> CSSFloat {
30 match *self {
31 Self::Auto => 0.0,
32 Self::Time(ref t) => t.seconds(),
33 }
34 }
35}
36
37#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem)]
39#[repr(C)]
40pub struct AnimationIterationCount(pub f32);
41
42impl ToComputedValue for specified::AnimationIterationCount {
43 type ComputedValue = AnimationIterationCount;
44
45 #[inline]
46 fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
47 AnimationIterationCount(match self {
48 specified::AnimationIterationCount::Number(n) => n.to_computed_value(context).0,
49 specified::AnimationIterationCount::Infinite => f32::INFINITY,
50 })
51 }
52
53 #[inline]
54 fn from_computed_value(computed: &Self::ComputedValue) -> Self {
55 use crate::values::specified::NonNegativeNumber;
56 if computed.0.is_infinite() {
57 specified::AnimationIterationCount::Infinite
58 } else {
59 specified::AnimationIterationCount::Number(NonNegativeNumber::new(computed.0))
60 }
61 }
62}
63
64impl AnimationIterationCount {
65 #[inline]
67 pub fn one() -> Self {
68 Self(1.0)
69 }
70}
71
72impl ToCss for AnimationIterationCount {
73 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
74 where
75 W: Write,
76 {
77 if self.0.is_infinite() {
78 dest.write_str("infinite")
79 } else {
80 self.0.to_css(dest)
81 }
82 }
83}
84
85impl ToTyped for AnimationIterationCount {
86 fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
87 if self.0.is_infinite() {
88 dest.push(TypedValue::Keyword(KeywordValue(CssString::from(
89 "infinite",
90 ))));
91 Ok(())
92 } else {
93 self.0.to_typed(dest)
94 }
95 }
96}
97
98pub type AnimationTimeline = generics::GenericAnimationTimeline<LengthPercentage>;
100
101pub type ViewTimelineInset = generics::GenericViewTimelineInset<LengthPercentage>;
103
104pub type AnimationRangeStart = generics::GenericAnimationRangeStart<LengthPercentage>;
106impl AnimationRangeStart {
107 pub fn normal() -> Self {
109 Self(generics::GenericAnimationRangeValue::normal(
110 LengthPercentage::zero_percent(),
111 ))
112 }
113}
114
115pub type AnimationRangeEnd = generics::GenericAnimationRangeEnd<LengthPercentage>;
117impl AnimationRangeEnd {
118 pub fn normal() -> Self {
120 Self(generics::GenericAnimationRangeValue::normal(
121 LengthPercentage::hundred_percent(),
122 ))
123 }
124}