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