Skip to main content

browser_protocol/input/
mod.rs

1use serde::{Serialize, Deserialize};
2
3
4#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5#[serde(rename_all = "camelCase")]
6pub struct TouchPoint {
7    /// X coordinate of the event relative to the main frame's viewport in CSS pixels.
8
9    pub x: f64,
10    /// Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to
11    /// the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
12
13    pub y: f64,
14    /// X radius of the touch area (default: 1.0).
15
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub radiusX: Option<f64>,
18    /// Y radius of the touch area (default: 1.0).
19
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub radiusY: Option<f64>,
22    /// Rotation angle (default: 0.0).
23
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub rotationAngle: Option<f64>,
26    /// Force (default: 1.0).
27
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub force: Option<f64>,
30    /// The normalized tangential pressure, which has a range of \[-1,1\] (default: 0).
31
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub tangentialPressure: Option<f64>,
34    /// The plane angle between the Y-Z plane and the plane containing both the stylus axis and the Y axis, in degrees of the range \[-90,90\], a positive tiltX is to the right (default: 0)
35
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub tiltX: Option<f64>,
38    /// The plane angle between the X-Z plane and the plane containing both the stylus axis and the X axis, in degrees of the range \[-90,90\], a positive tiltY is towards the user (default: 0).
39
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub tiltY: Option<f64>,
42    /// The clockwise rotation of a pen stylus around its own major axis, in degrees in the range \[0,359\] (default: 0).
43
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub twist: Option<i64>,
46    /// Identifier used to track touch sources between events, must be unique within an event.
47
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub id: Option<f64>,
50}
51
52
53#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
54pub enum GestureSourceType {
55    #[default]
56    Default,
57    Touch,
58    Mouse,
59}
60
61
62#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
63pub enum MouseButton {
64    #[default]
65    None,
66    Left,
67    Middle,
68    Right,
69    Back,
70    Forward,
71}
72
73/// UTC time in seconds, counted from January 1, 1970.
74
75pub type TimeSinceEpoch = f64;
76
77
78#[derive(Debug, Clone, Serialize, Deserialize, Default)]
79#[serde(rename_all = "camelCase")]
80pub struct DragDataItem {
81    /// Mime type of the dragged data.
82
83    pub mimeType: String,
84    /// Depending of the value of 'mimeType', it contains the dragged link,
85    /// text, HTML markup or any other data.
86
87    pub data: String,
88    /// Title associated with a link. Only valid when 'mimeType' == "text/uri-list".
89
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub title: Option<String>,
92    /// Stores the base URL for the contained markup. Only valid when 'mimeType'
93    /// == "text/html".
94
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub baseURL: Option<String>,
97}
98
99
100#[derive(Debug, Clone, Serialize, Deserialize, Default)]
101#[serde(rename_all = "camelCase")]
102pub struct DragData {
103
104    pub items: Vec<DragDataItem>,
105    /// List of filenames that should be included when dropping
106
107    #[serde(skip_serializing_if = "Option::is_none")]
108    pub files: Option<Vec<String>>,
109    /// Bit field representing allowed drag operations. Copy = 1, Link = 2, Move = 16
110
111    pub dragOperationsMask: i64,
112}
113
114/// Dispatches a drag event into the page.
115
116#[derive(Debug, Clone, Serialize, Deserialize, Default)]
117#[serde(rename_all = "camelCase")]
118pub struct DispatchDragEventParams {
119    /// Type of the drag event.
120
121    #[serde(rename = "type")]
122    pub type_: String,
123    /// X coordinate of the event relative to the main frame's viewport in CSS pixels.
124
125    pub x: f64,
126    /// Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to
127    /// the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
128
129    pub y: f64,
130
131    pub data: DragData,
132    /// Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
133    /// (default: 0).
134
135    #[serde(skip_serializing_if = "Option::is_none")]
136    pub modifiers: Option<i64>,
137}
138
139/// Dispatches a key event to the page.
140
141#[derive(Debug, Clone, Serialize, Deserialize, Default)]
142#[serde(rename_all = "camelCase")]
143pub struct DispatchKeyEventParams {
144    /// Type of the key event.
145
146    #[serde(rename = "type")]
147    pub type_: String,
148    /// Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
149    /// (default: 0).
150
151    #[serde(skip_serializing_if = "Option::is_none")]
152    pub modifiers: Option<i64>,
153    /// Time at which the event occurred.
154
155    #[serde(skip_serializing_if = "Option::is_none")]
156    pub timestamp: Option<TimeSinceEpoch>,
157    /// Text as generated by processing a virtual key code with a keyboard layout. Not needed for
158    /// for 'keyUp' and 'rawKeyDown' events (default: "")
159
160    #[serde(skip_serializing_if = "Option::is_none")]
161    pub text: Option<String>,
162    /// Text that would have been generated by the keyboard if no modifiers were pressed (except for
163    /// shift). Useful for shortcut (accelerator) key handling (default: "").
164
165    #[serde(skip_serializing_if = "Option::is_none")]
166    pub unmodifiedText: Option<String>,
167    /// Unique key identifier (e.g., 'U+0041') (default: "").
168
169    #[serde(skip_serializing_if = "Option::is_none")]
170    pub keyIdentifier: Option<String>,
171    /// Unique DOM defined string value for each physical key (e.g., 'KeyA') (default: "").
172
173    #[serde(skip_serializing_if = "Option::is_none")]
174    pub code: Option<String>,
175    /// Unique DOM defined string value describing the meaning of the key in the context of active
176    /// modifiers, keyboard layout, etc (e.g., 'AltGr') (default: "").
177
178    #[serde(skip_serializing_if = "Option::is_none")]
179    pub key: Option<String>,
180    /// Windows virtual key code (default: 0).
181
182    #[serde(skip_serializing_if = "Option::is_none")]
183    pub windowsVirtualKeyCode: Option<i64>,
184    /// Native virtual key code (default: 0).
185
186    #[serde(skip_serializing_if = "Option::is_none")]
187    pub nativeVirtualKeyCode: Option<i64>,
188    /// Whether the event was generated from auto repeat (default: false).
189
190    #[serde(skip_serializing_if = "Option::is_none")]
191    pub autoRepeat: Option<bool>,
192    /// Whether the event was generated from the keypad (default: false).
193
194    #[serde(skip_serializing_if = "Option::is_none")]
195    pub isKeypad: Option<bool>,
196    /// Whether the event was a system key event (default: false).
197
198    #[serde(skip_serializing_if = "Option::is_none")]
199    pub isSystemKey: Option<bool>,
200    /// Whether the event was from the left or right side of the keyboard. 1=Left, 2=Right (default:
201    /// 0).
202
203    #[serde(skip_serializing_if = "Option::is_none")]
204    pub location: Option<i64>,
205    /// Editing commands to send with the key event (e.g., 'selectAll') (default: \[\]).
206    /// These are related to but not equal the command names used in 'document.execCommand' and NSStandardKeyBindingResponding.
207    /// See <https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/commands/editor_command_names.h> for valid command names.
208
209    #[serde(skip_serializing_if = "Option::is_none")]
210    pub commands: Option<Vec<String>>,
211}
212
213/// This method emulates inserting text that doesn't come from a key press,
214/// for example an emoji keyboard or an IME.
215
216#[derive(Debug, Clone, Serialize, Deserialize, Default)]
217#[serde(rename_all = "camelCase")]
218pub struct InsertTextParams {
219    /// The text to insert.
220
221    pub text: String,
222}
223
224/// This method sets the current candidate text for IME.
225/// Use imeCommitComposition to commit the final text.
226/// Use imeSetComposition with empty string as text to cancel composition.
227
228#[derive(Debug, Clone, Serialize, Deserialize, Default)]
229#[serde(rename_all = "camelCase")]
230pub struct ImeSetCompositionParams {
231    /// The text to insert
232
233    pub text: String,
234    /// selection start
235
236    pub selectionStart: i64,
237    /// selection end
238
239    pub selectionEnd: i64,
240    /// replacement start
241
242    #[serde(skip_serializing_if = "Option::is_none")]
243    pub replacementStart: Option<i64>,
244    /// replacement end
245
246    #[serde(skip_serializing_if = "Option::is_none")]
247    pub replacementEnd: Option<i64>,
248}
249
250/// Dispatches a mouse event to the page.
251
252#[derive(Debug, Clone, Serialize, Deserialize, Default)]
253#[serde(rename_all = "camelCase")]
254pub struct DispatchMouseEventParams {
255    /// Type of the mouse event.
256
257    #[serde(rename = "type")]
258    pub type_: String,
259    /// X coordinate of the event relative to the main frame's viewport in CSS pixels.
260
261    pub x: f64,
262    /// Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to
263    /// the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
264
265    pub y: f64,
266    /// Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
267    /// (default: 0).
268
269    #[serde(skip_serializing_if = "Option::is_none")]
270    pub modifiers: Option<i64>,
271    /// Time at which the event occurred.
272
273    #[serde(skip_serializing_if = "Option::is_none")]
274    pub timestamp: Option<TimeSinceEpoch>,
275    /// Mouse button (default: "none").
276
277    #[serde(skip_serializing_if = "Option::is_none")]
278    pub button: Option<MouseButton>,
279    /// A number indicating which buttons are pressed on the mouse when a mouse event is triggered.
280    /// Left=1, Right=2, Middle=4, Back=8, Forward=16, None=0.
281
282    #[serde(skip_serializing_if = "Option::is_none")]
283    pub buttons: Option<i64>,
284    /// Number of times the mouse button was clicked (default: 0).
285
286    #[serde(skip_serializing_if = "Option::is_none")]
287    pub clickCount: Option<u64>,
288    /// The normalized pressure, which has a range of \[0,1\] (default: 0).
289
290    #[serde(skip_serializing_if = "Option::is_none")]
291    pub force: Option<f64>,
292    /// The normalized tangential pressure, which has a range of \[-1,1\] (default: 0).
293
294    #[serde(skip_serializing_if = "Option::is_none")]
295    pub tangentialPressure: Option<f64>,
296    /// The plane angle between the Y-Z plane and the plane containing both the stylus axis and the Y axis, in degrees of the range \[-90,90\], a positive tiltX is to the right (default: 0).
297
298    #[serde(skip_serializing_if = "Option::is_none")]
299    pub tiltX: Option<f64>,
300    /// The plane angle between the X-Z plane and the plane containing both the stylus axis and the X axis, in degrees of the range \[-90,90\], a positive tiltY is towards the user (default: 0).
301
302    #[serde(skip_serializing_if = "Option::is_none")]
303    pub tiltY: Option<f64>,
304    /// The clockwise rotation of a pen stylus around its own major axis, in degrees in the range \[0,359\] (default: 0).
305
306    #[serde(skip_serializing_if = "Option::is_none")]
307    pub twist: Option<i64>,
308    /// X delta in CSS pixels for mouse wheel event (default: 0).
309
310    #[serde(skip_serializing_if = "Option::is_none")]
311    pub deltaX: Option<f64>,
312    /// Y delta in CSS pixels for mouse wheel event (default: 0).
313
314    #[serde(skip_serializing_if = "Option::is_none")]
315    pub deltaY: Option<f64>,
316    /// Pointer type (default: "mouse").
317
318    #[serde(skip_serializing_if = "Option::is_none")]
319    pub pointerType: Option<String>,
320}
321
322/// Dispatches a touch event to the page.
323
324#[derive(Debug, Clone, Serialize, Deserialize, Default)]
325#[serde(rename_all = "camelCase")]
326pub struct DispatchTouchEventParams {
327    /// Type of the touch event. TouchEnd and TouchCancel must not contain any touch points, while
328    /// TouchStart and TouchMove must contains at least one.
329
330    #[serde(rename = "type")]
331    pub type_: String,
332    /// Active touch points on the touch device. One event per any changed point (compared to
333    /// previous touch event in a sequence) is generated, emulating pressing/moving/releasing points
334    /// one by one.
335
336    pub touchPoints: Vec<TouchPoint>,
337    /// Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
338    /// (default: 0).
339
340    #[serde(skip_serializing_if = "Option::is_none")]
341    pub modifiers: Option<i64>,
342    /// Time at which the event occurred.
343
344    #[serde(skip_serializing_if = "Option::is_none")]
345    pub timestamp: Option<TimeSinceEpoch>,
346}
347
348/// Emulates touch event from the mouse event parameters.
349
350#[derive(Debug, Clone, Serialize, Deserialize, Default)]
351#[serde(rename_all = "camelCase")]
352pub struct EmulateTouchFromMouseEventParams {
353    /// Type of the mouse event.
354
355    #[serde(rename = "type")]
356    pub type_: String,
357    /// X coordinate of the mouse pointer in DIP.
358
359    pub x: i32,
360    /// Y coordinate of the mouse pointer in DIP.
361
362    pub y: i32,
363    /// Mouse button. Only "none", "left", "right" are supported.
364
365    pub button: MouseButton,
366    /// Time at which the event occurred (default: current time).
367
368    #[serde(skip_serializing_if = "Option::is_none")]
369    pub timestamp: Option<TimeSinceEpoch>,
370    /// X delta in DIP for mouse wheel event (default: 0).
371
372    #[serde(skip_serializing_if = "Option::is_none")]
373    pub deltaX: Option<f64>,
374    /// Y delta in DIP for mouse wheel event (default: 0).
375
376    #[serde(skip_serializing_if = "Option::is_none")]
377    pub deltaY: Option<f64>,
378    /// Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
379    /// (default: 0).
380
381    #[serde(skip_serializing_if = "Option::is_none")]
382    pub modifiers: Option<i64>,
383    /// Number of times the mouse button was clicked (default: 0).
384
385    #[serde(skip_serializing_if = "Option::is_none")]
386    pub clickCount: Option<u64>,
387}
388
389/// Ignores input events (useful while auditing page).
390
391#[derive(Debug, Clone, Serialize, Deserialize, Default)]
392#[serde(rename_all = "camelCase")]
393pub struct SetIgnoreInputEventsParams {
394    /// Ignores input events processing when set to true.
395
396    pub ignore: bool,
397}
398
399/// Prevents default drag and drop behavior and instead emits 'Input.dragIntercepted' events.
400/// Drag and drop behavior can be directly controlled via 'Input.dispatchDragEvent'.
401
402#[derive(Debug, Clone, Serialize, Deserialize, Default)]
403#[serde(rename_all = "camelCase")]
404pub struct SetInterceptDragsParams {
405
406    pub enabled: bool,
407}
408
409/// Synthesizes a pinch gesture over a time period by issuing appropriate touch events.
410
411#[derive(Debug, Clone, Serialize, Deserialize, Default)]
412#[serde(rename_all = "camelCase")]
413pub struct SynthesizePinchGestureParams {
414    /// X coordinate of the start of the gesture in CSS pixels.
415
416    pub x: f64,
417    /// Y coordinate of the start of the gesture in CSS pixels.
418
419    pub y: f64,
420    /// Relative scale factor after zooming (\>1.0 zooms in, \<1.0 zooms out).
421
422    pub scaleFactor: f64,
423    /// Relative pointer speed in pixels per second (default: 800).
424
425    #[serde(skip_serializing_if = "Option::is_none")]
426    pub relativeSpeed: Option<i64>,
427    /// Which type of input events to be generated (default: 'default', which queries the platform
428    /// for the preferred input type).
429
430    #[serde(skip_serializing_if = "Option::is_none")]
431    pub gestureSourceType: Option<GestureSourceType>,
432}
433
434/// Synthesizes a scroll gesture over a time period by issuing appropriate touch events.
435
436#[derive(Debug, Clone, Serialize, Deserialize, Default)]
437#[serde(rename_all = "camelCase")]
438pub struct SynthesizeScrollGestureParams {
439    /// X coordinate of the start of the gesture in CSS pixels.
440
441    pub x: f64,
442    /// Y coordinate of the start of the gesture in CSS pixels.
443
444    pub y: f64,
445    /// The distance to scroll along the X axis (positive to scroll left).
446
447    #[serde(skip_serializing_if = "Option::is_none")]
448    pub xDistance: Option<f64>,
449    /// The distance to scroll along the Y axis (positive to scroll up).
450
451    #[serde(skip_serializing_if = "Option::is_none")]
452    pub yDistance: Option<f64>,
453    /// The number of additional pixels to scroll back along the X axis, in addition to the given
454    /// distance.
455
456    #[serde(skip_serializing_if = "Option::is_none")]
457    pub xOverscroll: Option<f64>,
458    /// The number of additional pixels to scroll back along the Y axis, in addition to the given
459    /// distance.
460
461    #[serde(skip_serializing_if = "Option::is_none")]
462    pub yOverscroll: Option<f64>,
463    /// Prevent fling (default: true).
464
465    #[serde(skip_serializing_if = "Option::is_none")]
466    pub preventFling: Option<bool>,
467    /// Swipe speed in pixels per second (default: 800).
468
469    #[serde(skip_serializing_if = "Option::is_none")]
470    pub speed: Option<i64>,
471    /// Which type of input events to be generated (default: 'default', which queries the platform
472    /// for the preferred input type).
473
474    #[serde(skip_serializing_if = "Option::is_none")]
475    pub gestureSourceType: Option<GestureSourceType>,
476    /// The number of times to repeat the gesture (default: 0).
477
478    #[serde(skip_serializing_if = "Option::is_none")]
479    pub repeatCount: Option<u64>,
480    /// The number of milliseconds delay between each repeat. (default: 250).
481
482    #[serde(skip_serializing_if = "Option::is_none")]
483    pub repeatDelayMs: Option<i64>,
484    /// The name of the interaction markers to generate, if not empty (default: "").
485
486    #[serde(skip_serializing_if = "Option::is_none")]
487    pub interactionMarkerName: Option<String>,
488}
489
490/// Synthesizes a tap gesture over a time period by issuing appropriate touch events.
491
492#[derive(Debug, Clone, Serialize, Deserialize, Default)]
493#[serde(rename_all = "camelCase")]
494pub struct SynthesizeTapGestureParams {
495    /// X coordinate of the start of the gesture in CSS pixels.
496
497    pub x: f64,
498    /// Y coordinate of the start of the gesture in CSS pixels.
499
500    pub y: f64,
501    /// Duration between touchdown and touchup events in ms (default: 50).
502
503    #[serde(skip_serializing_if = "Option::is_none")]
504    pub duration: Option<i64>,
505    /// Number of times to perform the tap (e.g. 2 for double tap, default: 1).
506
507    #[serde(skip_serializing_if = "Option::is_none")]
508    pub tapCount: Option<u64>,
509    /// Which type of input events to be generated (default: 'default', which queries the platform
510    /// for the preferred input type).
511
512    #[serde(skip_serializing_if = "Option::is_none")]
513    pub gestureSourceType: Option<GestureSourceType>,
514}