style/values/generics/
easing.rs1use crate::parser::ParserContext;
9
10#[derive(
12    Clone,
13    Debug,
14    MallocSizeOf,
15    PartialEq,
16    SpecifiedValueInfo,
17    ToCss,
18    ToShmem,
19    Serialize,
20    Deserialize,
21)]
22#[value_info(ty = "TIMING_FUNCTION")]
23#[repr(u8, C)]
24pub enum TimingFunction<Integer, Number, LinearStops> {
25    Keyword(TimingKeyword),
27    #[allow(missing_docs)]
29    #[css(comma, function)]
30    CubicBezier {
31        x1: Number,
32        y1: Number,
33        x2: Number,
34        y2: Number,
35    },
36    #[css(comma, function)]
39    #[value_info(other_values = "step-start,step-end")]
40    Steps(Integer, #[css(skip_if = "is_end")] StepPosition),
41    #[css(function = "linear")]
45    LinearFunction(LinearStops),
46}
47
48#[allow(missing_docs)]
49#[derive(
50    Clone,
51    Copy,
52    Debug,
53    Eq,
54    MallocSizeOf,
55    Parse,
56    PartialEq,
57    SpecifiedValueInfo,
58    ToComputedValue,
59    ToCss,
60    ToResolvedValue,
61    ToShmem,
62    Serialize,
63    Deserialize,
64)]
65#[repr(u8)]
66pub enum TimingKeyword {
67    Linear,
68    Ease,
69    EaseIn,
70    EaseOut,
71    EaseInOut,
72}
73
74#[allow(missing_docs)]
77#[derive(PartialEq)]
78#[repr(u8)]
79pub enum BeforeFlag {
80    Unset,
81    Set,
82}
83
84#[cfg(feature = "gecko")]
85fn step_position_jump_enabled(_context: &ParserContext) -> bool {
86    true
87}
88
89#[cfg(feature = "servo")]
90fn step_position_jump_enabled(_context: &ParserContext) -> bool {
91    false
92}
93
94#[allow(missing_docs)]
95#[derive(
96    Clone,
97    Copy,
98    Debug,
99    Eq,
100    MallocSizeOf,
101    Parse,
102    PartialEq,
103    ToComputedValue,
104    ToCss,
105    ToResolvedValue,
106    ToShmem,
107    Serialize,
108    Deserialize,
109)]
110#[repr(u8)]
111pub enum StepPosition {
112    #[parse(condition = "step_position_jump_enabled")]
113    JumpStart,
114    #[parse(condition = "step_position_jump_enabled")]
115    JumpEnd,
116    #[parse(condition = "step_position_jump_enabled")]
117    JumpNone,
118    #[parse(condition = "step_position_jump_enabled")]
119    JumpBoth,
120    Start,
121    End,
122}
123
124#[inline]
125fn is_end(position: &StepPosition) -> bool {
126    *position == StepPosition::JumpEnd || *position == StepPosition::End
127}
128
129impl<Integer, Number, LinearStops> TimingFunction<Integer, Number, LinearStops> {
130    #[inline]
132    pub fn ease() -> Self {
133        TimingFunction::Keyword(TimingKeyword::Ease)
134    }
135
136    #[inline]
138    pub fn is_ease(&self) -> bool {
139        matches!(*self, TimingFunction::Keyword(TimingKeyword::Ease))
140    }
141}