viewpoint_cdp/protocol/emulation/
mod.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct ScreenOrientation {
11 #[serde(rename = "type")]
13 pub orientation_type: ScreenOrientationType,
14 pub angle: i32,
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
20#[serde(rename_all = "camelCase")]
21pub enum ScreenOrientationType {
22 PortraitPrimary,
24 PortraitSecondary,
26 LandscapePrimary,
28 LandscapeSecondary,
30}
31
32#[derive(Debug, Clone, Serialize)]
34#[serde(rename_all = "camelCase")]
35pub struct DisplayFeature {
36 pub orientation: DisplayFeatureOrientation,
38 pub offset: i32,
40 pub mask_length: i32,
42}
43
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
46#[serde(rename_all = "camelCase")]
47pub enum DisplayFeatureOrientation {
48 Vertical,
50 Horizontal,
52}
53
54#[derive(Debug, Clone, Serialize)]
56#[serde(rename_all = "camelCase")]
57pub struct DevicePosture {
58 #[serde(rename = "type")]
60 pub posture_type: DevicePostureType,
61}
62
63#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
65#[serde(rename_all = "camelCase")]
66pub enum DevicePostureType {
67 Continuous,
69 Folded,
71}
72
73#[derive(Debug, Clone, Serialize)]
75#[serde(rename_all = "camelCase")]
76pub struct SetDeviceMetricsOverrideParams {
77 pub width: i32,
79 pub height: i32,
81 pub device_scale_factor: f64,
83 pub mobile: bool,
85 #[serde(skip_serializing_if = "Option::is_none")]
87 pub scale: Option<f64>,
88 #[serde(skip_serializing_if = "Option::is_none")]
90 pub screen_width: Option<i32>,
91 #[serde(skip_serializing_if = "Option::is_none")]
93 pub screen_height: Option<i32>,
94 #[serde(skip_serializing_if = "Option::is_none")]
96 pub position_x: Option<i32>,
97 #[serde(skip_serializing_if = "Option::is_none")]
99 pub position_y: Option<i32>,
100 #[serde(skip_serializing_if = "Option::is_none")]
102 pub dont_set_visible_size: Option<bool>,
103 #[serde(skip_serializing_if = "Option::is_none")]
105 pub screen_orientation: Option<ScreenOrientation>,
106 #[serde(skip_serializing_if = "Option::is_none")]
108 pub viewport: Option<Viewport>,
109 #[serde(skip_serializing_if = "Option::is_none")]
111 pub display_feature: Option<DisplayFeature>,
112 #[serde(skip_serializing_if = "Option::is_none")]
114 pub device_posture: Option<DevicePosture>,
115}
116
117#[derive(Debug, Clone, Serialize)]
119pub struct Viewport {
120 pub x: f64,
122 pub y: f64,
124 pub width: f64,
126 pub height: f64,
128 pub scale: f64,
130}
131
132#[derive(Debug, Clone, Serialize, Default)]
134pub struct ClearDeviceMetricsOverrideParams {}
135
136#[derive(Debug, Clone, Serialize)]
138#[serde(rename_all = "lowercase")]
139pub enum MediaType {
140 Print,
142 Screen,
144}
145
146#[derive(Debug, Clone, Serialize)]
148#[serde(rename_all = "camelCase")]
149pub struct SetEmulatedMediaParams {
150 #[serde(skip_serializing_if = "Option::is_none")]
152 pub media: Option<String>,
153 #[serde(skip_serializing_if = "Option::is_none")]
155 pub features: Option<Vec<MediaFeature>>,
156}
157
158#[derive(Debug, Clone, Serialize)]
160pub struct MediaFeature {
161 pub name: String,
163 pub value: String,
165}
166
167#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
169pub struct ViewportSize {
170 pub width: i32,
172 pub height: i32,
174}
175
176impl ViewportSize {
177 pub fn new(width: i32, height: i32) -> Self {
179 Self { width, height }
180 }
181}
182
183#[derive(Debug, Clone, Serialize)]
185#[serde(rename_all = "camelCase")]
186pub struct SetTouchEmulationEnabledParams {
187 pub enabled: bool,
189 #[serde(skip_serializing_if = "Option::is_none")]
191 pub max_touch_points: Option<i32>,
192}
193
194#[derive(Debug, Clone, Serialize, Default)]
200#[serde(rename_all = "camelCase")]
201pub struct SetGeolocationOverrideParams {
202 #[serde(skip_serializing_if = "Option::is_none")]
204 pub latitude: Option<f64>,
205 #[serde(skip_serializing_if = "Option::is_none")]
207 pub longitude: Option<f64>,
208 #[serde(skip_serializing_if = "Option::is_none")]
210 pub accuracy: Option<f64>,
211}
212
213impl SetGeolocationOverrideParams {
214 pub fn new(latitude: f64, longitude: f64) -> Self {
216 Self {
217 latitude: Some(latitude),
218 longitude: Some(longitude),
219 accuracy: Some(0.0), }
221 }
222
223 pub fn with_accuracy(latitude: f64, longitude: f64, accuracy: f64) -> Self {
225 Self {
226 latitude: Some(latitude),
227 longitude: Some(longitude),
228 accuracy: Some(accuracy),
229 }
230 }
231
232 pub fn unavailable() -> Self {
234 Self::default()
235 }
236}
237
238#[derive(Debug, Clone, Serialize, Default)]
240pub struct ClearGeolocationOverrideParams {}
241
242#[derive(Debug, Clone, Serialize)]
248#[serde(rename_all = "camelCase")]
249pub struct SetTimezoneOverrideParams {
250 pub timezone_id: String,
252}
253
254impl SetTimezoneOverrideParams {
255 pub fn new(timezone_id: impl Into<String>) -> Self {
257 Self {
258 timezone_id: timezone_id.into(),
259 }
260 }
261}
262
263#[derive(Debug, Clone, Serialize)]
269#[serde(rename_all = "camelCase")]
270pub struct SetLocaleOverrideParams {
271 #[serde(skip_serializing_if = "Option::is_none")]
273 pub locale: Option<String>,
274}
275
276impl SetLocaleOverrideParams {
277 pub fn new(locale: impl Into<String>) -> Self {
279 Self {
280 locale: Some(locale.into()),
281 }
282 }
283
284 pub fn clear() -> Self {
286 Self { locale: None }
287 }
288}
289
290#[derive(Debug, Clone, Serialize)]
296#[serde(rename_all = "camelCase")]
297pub struct SetUserAgentOverrideParams {
298 pub user_agent: String,
300 #[serde(skip_serializing_if = "Option::is_none")]
302 pub accept_language: Option<String>,
303 #[serde(skip_serializing_if = "Option::is_none")]
305 pub platform: Option<String>,
306 #[serde(skip_serializing_if = "Option::is_none")]
308 pub user_agent_metadata: Option<UserAgentMetadata>,
309}
310
311impl SetUserAgentOverrideParams {
312 pub fn new(user_agent: impl Into<String>) -> Self {
314 Self {
315 user_agent: user_agent.into(),
316 accept_language: None,
317 platform: None,
318 user_agent_metadata: None,
319 }
320 }
321}
322
323#[derive(Debug, Clone, Serialize)]
325#[serde(rename_all = "camelCase")]
326pub struct UserAgentMetadata {
327 #[serde(skip_serializing_if = "Option::is_none")]
329 pub brands: Option<Vec<UserAgentBrandVersion>>,
330 #[serde(skip_serializing_if = "Option::is_none")]
332 pub full_version_list: Option<Vec<UserAgentBrandVersion>>,
333 #[serde(skip_serializing_if = "Option::is_none")]
335 pub full_version: Option<String>,
336 pub platform: String,
338 pub platform_version: String,
340 pub architecture: String,
342 pub model: String,
344 pub mobile: bool,
346 #[serde(skip_serializing_if = "Option::is_none")]
348 pub bitness: Option<String>,
349 #[serde(skip_serializing_if = "Option::is_none")]
351 pub wow64: Option<bool>,
352}
353
354#[derive(Debug, Clone, Serialize)]
356pub struct UserAgentBrandVersion {
357 pub brand: String,
359 pub version: String,
361}
362
363#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
369#[serde(rename_all = "camelCase")]
370#[derive(Default)]
371pub enum VisionDeficiency {
372 #[default]
374 None,
375 Achromatopsia,
377 BlurredVision,
379 Deuteranopia,
381 Protanopia,
383 Tritanopia,
385}
386
387
388#[derive(Debug, Clone, Serialize)]
390#[serde(rename_all = "camelCase")]
391pub struct SetEmulatedVisionDeficiencyParams {
392 #[serde(rename = "type")]
394 pub deficiency_type: VisionDeficiency,
395}
396
397impl SetEmulatedVisionDeficiencyParams {
398 pub fn new(deficiency_type: VisionDeficiency) -> Self {
400 Self { deficiency_type }
401 }
402
403 pub fn clear() -> Self {
405 Self {
406 deficiency_type: VisionDeficiency::None,
407 }
408 }
409}