Skip to main content

browser_protocol/animation/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3
4/// Animation instance.
5
6#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7#[serde(rename_all = "camelCase")]
8pub struct Animation {
9    /// 'Animation''s id.
10
11    pub id: String,
12    /// 'Animation''s name.
13
14    pub name: String,
15    /// 'Animation''s internal paused state.
16
17    pub pausedState: bool,
18    /// 'Animation''s play state.
19
20    pub playState: String,
21    /// 'Animation''s playback rate.
22
23    pub playbackRate: f64,
24    /// 'Animation''s start time.
25    /// Milliseconds for time based animations and
26    /// percentage [0 - 100] for scroll driven animations
27    /// (i.e. when viewOrScrollTimeline exists).
28
29    pub startTime: f64,
30    /// 'Animation''s current time.
31
32    pub currentTime: f64,
33    /// Animation type of 'Animation'.
34
35    #[serde(rename = "type")]
36    pub type_: String,
37    /// 'Animation''s source animation node.
38
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub source: Option<AnimationEffect>,
41    /// A unique ID for 'Animation' representing the sources that triggered this CSS
42    /// animation/transition.
43
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub cssId: Option<String>,
46    /// View or scroll timeline
47
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub viewOrScrollTimeline: Option<ViewOrScrollTimeline>,
50}
51
52/// Timeline instance
53
54#[derive(Debug, Clone, Serialize, Deserialize, Default)]
55#[serde(rename_all = "camelCase")]
56pub struct ViewOrScrollTimeline {
57    /// Scroll container node
58
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub sourceNodeId: Option<crate::dom::BackendNodeId>,
61    /// Represents the starting scroll position of the timeline
62    /// as a length offset in pixels from scroll origin.
63
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub startOffset: Option<f64>,
66    /// Represents the ending scroll position of the timeline
67    /// as a length offset in pixels from scroll origin.
68
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub endOffset: Option<f64>,
71    /// The element whose principal box's visibility in the
72    /// scrollport defined the progress of the timeline.
73    /// Does not exist for animations with ScrollTimeline
74
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub subjectNodeId: Option<crate::dom::BackendNodeId>,
77    /// Orientation of the scroll
78
79    pub axis: crate::dom::ScrollOrientation,
80}
81
82/// AnimationEffect instance
83
84#[derive(Debug, Clone, Serialize, Deserialize, Default)]
85#[serde(rename_all = "camelCase")]
86pub struct AnimationEffect {
87    /// 'AnimationEffect''s delay.
88
89    pub delay: f64,
90    /// 'AnimationEffect''s end delay.
91
92    pub endDelay: f64,
93    /// 'AnimationEffect''s iteration start.
94
95    pub iterationStart: f64,
96    /// 'AnimationEffect''s iterations. Omitted if the value is infinite.
97
98    #[serde(skip_serializing_if = "Option::is_none")]
99    pub iterations: Option<f64>,
100    /// 'AnimationEffect''s iteration duration.
101    /// Milliseconds for time based animations and
102    /// percentage [0 - 100] for scroll driven animations
103    /// (i.e. when viewOrScrollTimeline exists).
104
105    pub duration: f64,
106    /// 'AnimationEffect''s playback direction.
107
108    pub direction: String,
109    /// 'AnimationEffect''s fill mode.
110
111    pub fill: String,
112    /// 'AnimationEffect''s target node.
113
114    #[serde(skip_serializing_if = "Option::is_none")]
115    pub backendNodeId: Option<crate::dom::BackendNodeId>,
116    /// 'AnimationEffect''s keyframes.
117
118    #[serde(skip_serializing_if = "Option::is_none")]
119    pub keyframesRule: Option<KeyframesRule>,
120    /// 'AnimationEffect''s timing function.
121
122    pub easing: String,
123}
124
125/// Keyframes Rule
126
127#[derive(Debug, Clone, Serialize, Deserialize, Default)]
128#[serde(rename_all = "camelCase")]
129pub struct KeyframesRule {
130    /// CSS keyframed animation's name.
131
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub name: Option<String>,
134    /// List of animation keyframes.
135
136    pub keyframes: Vec<KeyframeStyle>,
137}
138
139/// Keyframe Style
140
141#[derive(Debug, Clone, Serialize, Deserialize, Default)]
142#[serde(rename_all = "camelCase")]
143pub struct KeyframeStyle {
144    /// Keyframe's time offset.
145
146    pub offset: String,
147    /// 'AnimationEffect''s timing function.
148
149    pub easing: String,
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize, Default)]
153pub struct DisableParams {}
154
155impl DisableParams { pub const METHOD: &'static str = "Animation.disable"; }
156
157impl crate::CdpCommand for DisableParams {
158    const METHOD: &'static str = "Animation.disable";
159    type Response = crate::EmptyReturns;
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize, Default)]
163pub struct EnableParams {}
164
165impl EnableParams { pub const METHOD: &'static str = "Animation.enable"; }
166
167impl crate::CdpCommand for EnableParams {
168    const METHOD: &'static str = "Animation.enable";
169    type Response = crate::EmptyReturns;
170}
171
172/// Returns the current time of the an animation.
173
174#[derive(Debug, Clone, Serialize, Deserialize, Default)]
175#[serde(rename_all = "camelCase")]
176pub struct GetCurrentTimeParams {
177    /// Id of animation.
178
179    pub id: String,
180}
181
182/// Returns the current time of the an animation.
183
184#[derive(Debug, Clone, Serialize, Deserialize, Default)]
185#[serde(rename_all = "camelCase")]
186pub struct GetCurrentTimeReturns {
187    /// Current time of the page.
188
189    pub currentTime: f64,
190}
191
192impl GetCurrentTimeParams { pub const METHOD: &'static str = "Animation.getCurrentTime"; }
193
194impl crate::CdpCommand for GetCurrentTimeParams {
195    const METHOD: &'static str = "Animation.getCurrentTime";
196    type Response = GetCurrentTimeReturns;
197}
198
199/// Gets the playback rate of the document timeline.
200
201#[derive(Debug, Clone, Serialize, Deserialize, Default)]
202#[serde(rename_all = "camelCase")]
203pub struct GetPlaybackRateReturns {
204    /// Playback rate for animations on page.
205
206    pub playbackRate: f64,
207}
208
209#[derive(Debug, Clone, Serialize, Deserialize, Default)]
210pub struct GetPlaybackRateParams {}
211
212impl GetPlaybackRateParams { pub const METHOD: &'static str = "Animation.getPlaybackRate"; }
213
214impl crate::CdpCommand for GetPlaybackRateParams {
215    const METHOD: &'static str = "Animation.getPlaybackRate";
216    type Response = GetPlaybackRateReturns;
217}
218
219/// Releases a set of animations to no longer be manipulated.
220
221#[derive(Debug, Clone, Serialize, Deserialize, Default)]
222#[serde(rename_all = "camelCase")]
223pub struct ReleaseAnimationsParams {
224    /// List of animation ids to seek.
225
226    pub animations: Vec<String>,
227}
228
229impl ReleaseAnimationsParams { pub const METHOD: &'static str = "Animation.releaseAnimations"; }
230
231impl crate::CdpCommand for ReleaseAnimationsParams {
232    const METHOD: &'static str = "Animation.releaseAnimations";
233    type Response = crate::EmptyReturns;
234}
235
236/// Gets the remote object of the Animation.
237
238#[derive(Debug, Clone, Serialize, Deserialize, Default)]
239#[serde(rename_all = "camelCase")]
240pub struct ResolveAnimationParams {
241    /// Animation id.
242
243    pub animationId: String,
244}
245
246/// Gets the remote object of the Animation.
247
248#[derive(Debug, Clone, Serialize, Deserialize, Default)]
249#[serde(rename_all = "camelCase")]
250pub struct ResolveAnimationReturns {
251    /// Corresponding remote object.
252
253    pub remoteObject: crate::runtime::RemoteObject,
254}
255
256impl ResolveAnimationParams { pub const METHOD: &'static str = "Animation.resolveAnimation"; }
257
258impl crate::CdpCommand for ResolveAnimationParams {
259    const METHOD: &'static str = "Animation.resolveAnimation";
260    type Response = ResolveAnimationReturns;
261}
262
263/// Seek a set of animations to a particular time within each animation.
264
265#[derive(Debug, Clone, Serialize, Deserialize, Default)]
266#[serde(rename_all = "camelCase")]
267pub struct SeekAnimationsParams {
268    /// List of animation ids to seek.
269
270    pub animations: Vec<String>,
271    /// Set the current time of each animation.
272
273    pub currentTime: f64,
274}
275
276impl SeekAnimationsParams { pub const METHOD: &'static str = "Animation.seekAnimations"; }
277
278impl crate::CdpCommand for SeekAnimationsParams {
279    const METHOD: &'static str = "Animation.seekAnimations";
280    type Response = crate::EmptyReturns;
281}
282
283/// Sets the paused state of a set of animations.
284
285#[derive(Debug, Clone, Serialize, Deserialize, Default)]
286#[serde(rename_all = "camelCase")]
287pub struct SetPausedParams {
288    /// Animations to set the pause state of.
289
290    pub animations: Vec<String>,
291    /// Paused state to set to.
292
293    pub paused: bool,
294}
295
296impl SetPausedParams { pub const METHOD: &'static str = "Animation.setPaused"; }
297
298impl crate::CdpCommand for SetPausedParams {
299    const METHOD: &'static str = "Animation.setPaused";
300    type Response = crate::EmptyReturns;
301}
302
303/// Sets the playback rate of the document timeline.
304
305#[derive(Debug, Clone, Serialize, Deserialize, Default)]
306#[serde(rename_all = "camelCase")]
307pub struct SetPlaybackRateParams {
308    /// Playback rate for animations on page
309
310    pub playbackRate: f64,
311}
312
313impl SetPlaybackRateParams { pub const METHOD: &'static str = "Animation.setPlaybackRate"; }
314
315impl crate::CdpCommand for SetPlaybackRateParams {
316    const METHOD: &'static str = "Animation.setPlaybackRate";
317    type Response = crate::EmptyReturns;
318}
319
320/// Sets the timing of an animation node.
321
322#[derive(Debug, Clone, Serialize, Deserialize, Default)]
323#[serde(rename_all = "camelCase")]
324pub struct SetTimingParams {
325    /// Animation id.
326
327    pub animationId: String,
328    /// Duration of the animation.
329
330    pub duration: f64,
331    /// Delay of the animation.
332
333    pub delay: f64,
334}
335
336impl SetTimingParams { pub const METHOD: &'static str = "Animation.setTiming"; }
337
338impl crate::CdpCommand for SetTimingParams {
339    const METHOD: &'static str = "Animation.setTiming";
340    type Response = crate::EmptyReturns;
341}