1use std::future::Future;
2use rustenium_bidi_definitions::browsing_context::types::BrowsingContext;
3use crate::error::bidi::InputError;
4
5#[derive(Debug, Clone, Default)]
6pub struct MouseMoveOptions {
7 pub steps: Option<usize>,
8 pub origin: Option<rustenium_bidi_definitions::input::types::Origin>,
9}
10
11
12#[derive(Default, Clone)]
13pub struct MouseMoveOptionsBuilder {
14 steps: Option<usize>,
15 origin: Option<rustenium_bidi_definitions::input::types::Origin>,
16}
17
18impl MouseMoveOptionsBuilder {
19 pub fn steps(mut self, v: usize) -> Self { self.steps = Some(v); self }
20 pub fn origin(mut self, v: rustenium_bidi_definitions::input::types::Origin) -> Self { self.origin = Some(v); self }
21 pub fn build(self) -> MouseMoveOptions {
22 MouseMoveOptions { steps: self.steps, origin: self.origin }
23 }
24}
25
26#[derive(Debug, Clone, Default)]
27pub struct MouseClickOptions {
28 pub button: Option<MouseButton>,
29 pub count: Option<u64>,
30 pub delay: Option<u64>,
31 pub origin: Option<rustenium_bidi_definitions::input::types::Origin>,
32}
33
34
35#[derive(Default, Clone)]
36pub struct MouseClickOptionsBuilder {
37 button: Option<MouseButton>,
38 count: Option<u64>,
39 delay: Option<u64>,
40 origin: Option<rustenium_bidi_definitions::input::types::Origin>,
41}
42
43impl MouseClickOptionsBuilder {
44 pub fn button(mut self, v: MouseButton) -> Self { self.button = Some(v); self }
45 pub fn count(mut self, v: u64) -> Self { self.count = Some(v); self }
46 pub fn delay(mut self, v: u64) -> Self { self.delay = Some(v); self }
47 pub fn origin(mut self, v: rustenium_bidi_definitions::input::types::Origin) -> Self { self.origin = Some(v); self }
48 pub fn build(self) -> MouseClickOptions {
49 MouseClickOptions { button: self.button, count: self.count, delay: self.delay, origin: self.origin }
50 }
51}
52
53#[derive(Debug, Clone, Default)]
54pub struct MouseOptions {
55 pub button: Option<MouseButton>,
56}
57
58
59#[derive(Default, Clone)]
60pub struct MouseOptionsBuilder {
61 button: Option<MouseButton>,
62}
63
64impl MouseOptionsBuilder {
65 pub fn button(mut self, v: MouseButton) -> Self { self.button = Some(v); self }
66 pub fn build(self) -> MouseOptions {
67 MouseOptions { button: self.button }
68 }
69}
70
71#[derive(Debug, Clone, Default)]
72pub struct MouseWheelOptions {
73 pub delta_x: Option<i64>,
74 pub delta_y: Option<i64>,
75}
76
77
78#[derive(Default, Clone)]
79pub struct MouseWheelOptionsBuilder {
80 delta_x: Option<i64>,
81 delta_y: Option<i64>,
82}
83
84impl MouseWheelOptionsBuilder {
85 pub fn delta_x(mut self, v: i64) -> Self { self.delta_x = Some(v); self }
86 pub fn delta_y(mut self, v: i64) -> Self { self.delta_y = Some(v); self }
87 pub fn build(self) -> MouseWheelOptions {
88 MouseWheelOptions { delta_x: self.delta_x, delta_y: self.delta_y }
89 }
90}
91
92#[derive(Debug, Clone, Copy, PartialEq, Eq)]
93pub enum MouseButton {
94 Left = 0,
95 Middle = 1,
96 Right = 2,
97 Back = 3,
98 Forward = 4,
99}
100
101#[derive(Debug, Clone, Copy, Default)]
102pub struct Point {
103 pub x: f64,
104 pub y: f64,
105}
106
107pub trait Mouse {
108 fn get_last_position(&self) -> Point;
109
110 fn set_last_position(&self, point: Point);
111
112 fn reset(&self, context: &BrowsingContext) -> impl Future<Output = Result<(), InputError>>;
113
114 fn move_to(
115 &self,
116 point: Point,
117 context: &BrowsingContext,
118 options: MouseMoveOptions,
119 ) -> impl Future<Output = Result<(), InputError>>;
120
121 fn down(
122 &self,
123 context: &BrowsingContext,
124 options: MouseOptions,
125 ) -> impl Future<Output = Result<(), InputError>>;
126
127 fn up(
128 &self,
129 context: &BrowsingContext,
130 options: MouseOptions,
131 ) -> impl Future<Output = Result<(), InputError>>;
132
133 fn click(
134 &self,
135 point: Option<Point>,
136 context: &BrowsingContext,
137 options: MouseClickOptions,
138 ) -> impl Future<Output = Result<(), InputError>>;
139
140 fn wheel(
141 &self,
142 context: &BrowsingContext,
143 options: MouseWheelOptions,
144 ) -> impl Future<Output = Result<(), InputError>>;
145}