Skip to main content

rustenium_bidi_definitions/browsing_context/
command_builders.rs

1use super::commands::*;
2impl Activate {
3    pub fn builder() -> ActivateBuilder {
4        <ActivateBuilder as Default>::default()
5    }
6}
7#[derive(Default, Clone)]
8pub struct ActivateBuilder {
9    context: Option<super::types::BrowsingContext>,
10}
11impl ActivateBuilder {
12    pub fn context(mut self, context: impl Into<super::types::BrowsingContext>) -> Self {
13        self.context = Some(context.into());
14        self
15    }
16    pub fn build(self) -> Result<Activate, String> {
17        Ok(Activate {
18            method: ActivateMethod::Activate,
19            params: ActivateParams {
20                context: self
21                    .context
22                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(context)))?,
23            },
24        })
25    }
26}
27impl CaptureScreenshot {
28    pub fn builder() -> CaptureScreenshotBuilder {
29        <CaptureScreenshotBuilder as Default>::default()
30    }
31}
32#[derive(Default, Clone)]
33pub struct CaptureScreenshotBuilder {
34    context: Option<super::types::BrowsingContext>,
35    origin: Option<CaptureScreenshotOrigin>,
36    format: Option<super::types::ImageFormat>,
37    clip: Option<super::types::ClipRectangle>,
38}
39impl CaptureScreenshotBuilder {
40    pub fn context(mut self, context: impl Into<super::types::BrowsingContext>) -> Self {
41        self.context = Some(context.into());
42        self
43    }
44    pub fn origin(mut self, origin: impl Into<CaptureScreenshotOrigin>) -> Self {
45        self.origin = Some(origin.into());
46        self
47    }
48    pub fn format(mut self, format: impl Into<super::types::ImageFormat>) -> Self {
49        self.format = Some(format.into());
50        self
51    }
52    pub fn clip(mut self, clip: impl Into<super::types::ClipRectangle>) -> Self {
53        self.clip = Some(clip.into());
54        self
55    }
56    pub fn build(self) -> Result<CaptureScreenshot, String> {
57        Ok(CaptureScreenshot {
58            method: CaptureScreenshotMethod::CaptureScreenshot,
59            params: CaptureScreenshotParams {
60                context: self
61                    .context
62                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(context)))?,
63                origin: self.origin,
64                format: self.format,
65                clip: self.clip,
66            },
67        })
68    }
69}
70impl Close {
71    pub fn builder() -> CloseBuilder {
72        <CloseBuilder as Default>::default()
73    }
74}
75#[derive(Default, Clone)]
76pub struct CloseBuilder {
77    context: Option<super::types::BrowsingContext>,
78    prompt_unload: Option<bool>,
79}
80impl CloseBuilder {
81    pub fn context(mut self, context: impl Into<super::types::BrowsingContext>) -> Self {
82        self.context = Some(context.into());
83        self
84    }
85    pub fn prompt_unload(mut self, prompt_unload: impl Into<bool>) -> Self {
86        self.prompt_unload = Some(prompt_unload.into());
87        self
88    }
89    pub fn build(self) -> Result<Close, String> {
90        Ok(Close {
91            method: CloseMethod::Close,
92            params: CloseParams {
93                context: self
94                    .context
95                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(context)))?,
96                prompt_unload: self.prompt_unload,
97            },
98        })
99    }
100}
101impl Create {
102    pub fn builder() -> CreateBuilder {
103        <CreateBuilder as Default>::default()
104    }
105}
106#[derive(Default, Clone)]
107pub struct CreateBuilder {
108    r#type: Option<super::types::CreateType>,
109    reference_context: Option<super::types::BrowsingContext>,
110    background: Option<bool>,
111    user_context: Option<crate::browser::types::UserContext>,
112}
113impl CreateBuilder {
114    pub fn r#type(mut self, r#type: impl Into<super::types::CreateType>) -> Self {
115        self.r#type = Some(r#type.into());
116        self
117    }
118    pub fn reference_context(
119        mut self,
120        reference_context: impl Into<super::types::BrowsingContext>,
121    ) -> Self {
122        self.reference_context = Some(reference_context.into());
123        self
124    }
125    pub fn background(mut self, background: impl Into<bool>) -> Self {
126        self.background = Some(background.into());
127        self
128    }
129    pub fn user_context(
130        mut self,
131        user_context: impl Into<crate::browser::types::UserContext>,
132    ) -> Self {
133        self.user_context = Some(user_context.into());
134        self
135    }
136    pub fn build(self) -> Result<Create, String> {
137        Ok(Create {
138            method: CreateMethod::Create,
139            params: CreateParams {
140                r#type: self
141                    .r#type
142                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(r#type)))?,
143                reference_context: self.reference_context,
144                background: self.background,
145                user_context: self.user_context,
146            },
147        })
148    }
149}
150impl GetTree {
151    pub fn builder() -> GetTreeBuilder {
152        <GetTreeBuilder as Default>::default()
153    }
154}
155#[derive(Default, Clone)]
156pub struct GetTreeBuilder {
157    max_depth: Option<u64>,
158    root: Option<super::types::BrowsingContext>,
159}
160impl GetTreeBuilder {
161    pub fn max_depth(mut self, max_depth: impl Into<u64>) -> Self {
162        self.max_depth = Some(max_depth.into());
163        self
164    }
165    pub fn root(mut self, root: impl Into<super::types::BrowsingContext>) -> Self {
166        self.root = Some(root.into());
167        self
168    }
169    pub fn build(self) -> GetTree {
170        GetTree {
171            method: GetTreeMethod::GetTree,
172            params: GetTreeParams {
173                max_depth: self.max_depth,
174                root: self.root,
175            },
176        }
177    }
178}
179impl HandleUserPrompt {
180    pub fn builder() -> HandleUserPromptBuilder {
181        <HandleUserPromptBuilder as Default>::default()
182    }
183}
184#[derive(Default, Clone)]
185pub struct HandleUserPromptBuilder {
186    context: Option<super::types::BrowsingContext>,
187    accept: Option<bool>,
188    user_text: Option<String>,
189}
190impl HandleUserPromptBuilder {
191    pub fn context(mut self, context: impl Into<super::types::BrowsingContext>) -> Self {
192        self.context = Some(context.into());
193        self
194    }
195    pub fn accept(mut self, accept: impl Into<bool>) -> Self {
196        self.accept = Some(accept.into());
197        self
198    }
199    pub fn user_text(mut self, user_text: impl Into<String>) -> Self {
200        self.user_text = Some(user_text.into());
201        self
202    }
203    pub fn build(self) -> Result<HandleUserPrompt, String> {
204        Ok(HandleUserPrompt {
205            method: HandleUserPromptMethod::HandleUserPrompt,
206            params: HandleUserPromptParams {
207                context: self
208                    .context
209                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(context)))?,
210                accept: self.accept,
211                user_text: self.user_text,
212            },
213        })
214    }
215}
216impl LocateNodes {
217    pub fn builder() -> LocateNodesBuilder {
218        <LocateNodesBuilder as Default>::default()
219    }
220}
221#[derive(Default, Clone)]
222pub struct LocateNodesBuilder {
223    context: Option<super::types::BrowsingContext>,
224    locator: Option<super::types::Locator>,
225    max_node_count: Option<u64>,
226    serialization_options: Option<crate::script::types::SerializationOptions>,
227    start_nodes: Option<Vec<crate::script::types::SharedReference>>,
228}
229impl LocateNodesBuilder {
230    pub fn context(mut self, context: impl Into<super::types::BrowsingContext>) -> Self {
231        self.context = Some(context.into());
232        self
233    }
234    pub fn locator(mut self, locator: impl Into<super::types::Locator>) -> Self {
235        self.locator = Some(locator.into());
236        self
237    }
238    pub fn max_node_count(mut self, max_node_count: impl Into<u64>) -> Self {
239        self.max_node_count = Some(max_node_count.into());
240        self
241    }
242    pub fn serialization_options(
243        mut self,
244        serialization_options: impl Into<crate::script::types::SerializationOptions>,
245    ) -> Self {
246        self.serialization_options = Some(serialization_options.into());
247        self
248    }
249    pub fn start_node(
250        mut self,
251        start_node: impl Into<crate::script::types::SharedReference>,
252    ) -> Self {
253        let v = self.start_nodes.get_or_insert(Vec::new());
254        v.push(start_node.into());
255        self
256    }
257    pub fn start_nodes<I, S>(mut self, start_nodes: I) -> Self
258    where
259        I: IntoIterator<Item = S>,
260        S: Into<crate::script::types::SharedReference>,
261    {
262        let v = self.start_nodes.get_or_insert(Vec::new());
263        for val in start_nodes {
264            v.push(val.into());
265        }
266        self
267    }
268    pub fn build(self) -> Result<LocateNodes, String> {
269        Ok(LocateNodes {
270            method: LocateNodesMethod::LocateNodes,
271            params: LocateNodesParams {
272                context: self
273                    .context
274                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(context)))?,
275                locator: self
276                    .locator
277                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(locator)))?,
278                max_node_count: self.max_node_count,
279                serialization_options: self.serialization_options,
280                start_nodes: self.start_nodes,
281            },
282        })
283    }
284}
285impl Navigate {
286    pub fn builder() -> NavigateBuilder {
287        <NavigateBuilder as Default>::default()
288    }
289}
290#[derive(Default, Clone)]
291pub struct NavigateBuilder {
292    context: Option<super::types::BrowsingContext>,
293    url: Option<String>,
294    wait: Option<super::types::ReadinessState>,
295}
296impl NavigateBuilder {
297    pub fn context(mut self, context: impl Into<super::types::BrowsingContext>) -> Self {
298        self.context = Some(context.into());
299        self
300    }
301    pub fn url(mut self, url: impl Into<String>) -> Self {
302        self.url = Some(url.into());
303        self
304    }
305    pub fn wait(mut self, wait: impl Into<super::types::ReadinessState>) -> Self {
306        self.wait = Some(wait.into());
307        self
308    }
309    pub fn build(self) -> Result<Navigate, String> {
310        Ok(Navigate {
311            method: NavigateMethod::Navigate,
312            params: NavigateParams {
313                context: self
314                    .context
315                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(context)))?,
316                url: self
317                    .url
318                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(url)))?,
319                wait: self.wait,
320            },
321        })
322    }
323}
324impl Print {
325    pub fn builder() -> PrintBuilder {
326        <PrintBuilder as Default>::default()
327    }
328}
329#[derive(Default, Clone)]
330pub struct PrintBuilder {
331    context: Option<super::types::BrowsingContext>,
332    background: Option<bool>,
333    margin: Option<super::types::PrintMarginParameters>,
334    orientation: Option<PrintOrientation>,
335    page: Option<super::types::PrintPageParameters>,
336    page_ranges: Option<Vec<serde_json::Value>>,
337    scale: Option<f64>,
338    shrink_to_fit: Option<bool>,
339}
340impl PrintBuilder {
341    pub fn context(mut self, context: impl Into<super::types::BrowsingContext>) -> Self {
342        self.context = Some(context.into());
343        self
344    }
345    pub fn background(mut self, background: impl Into<bool>) -> Self {
346        self.background = Some(background.into());
347        self
348    }
349    pub fn margin(mut self, margin: impl Into<super::types::PrintMarginParameters>) -> Self {
350        self.margin = Some(margin.into());
351        self
352    }
353    pub fn orientation(mut self, orientation: impl Into<PrintOrientation>) -> Self {
354        self.orientation = Some(orientation.into());
355        self
356    }
357    pub fn page(mut self, page: impl Into<super::types::PrintPageParameters>) -> Self {
358        self.page = Some(page.into());
359        self
360    }
361    pub fn page_range(mut self, page_range: impl Into<serde_json::Value>) -> Self {
362        let v = self.page_ranges.get_or_insert(Vec::new());
363        v.push(page_range.into());
364        self
365    }
366    pub fn page_ranges<I, S>(mut self, page_ranges: I) -> Self
367    where
368        I: IntoIterator<Item = S>,
369        S: Into<serde_json::Value>,
370    {
371        let v = self.page_ranges.get_or_insert(Vec::new());
372        for val in page_ranges {
373            v.push(val.into());
374        }
375        self
376    }
377    pub fn scale(mut self, scale: impl Into<f64>) -> Self {
378        self.scale = Some(scale.into());
379        self
380    }
381    pub fn shrink_to_fit(mut self, shrink_to_fit: impl Into<bool>) -> Self {
382        self.shrink_to_fit = Some(shrink_to_fit.into());
383        self
384    }
385    pub fn build(self) -> Result<Print, String> {
386        Ok(Print {
387            method: PrintMethod::Print,
388            params: PrintParams {
389                context: self
390                    .context
391                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(context)))?,
392                background: self.background,
393                margin: self.margin,
394                orientation: self.orientation,
395                page: self.page,
396                page_ranges: self.page_ranges,
397                scale: self.scale,
398                shrink_to_fit: self.shrink_to_fit,
399            },
400        })
401    }
402}
403impl Reload {
404    pub fn builder() -> ReloadBuilder {
405        <ReloadBuilder as Default>::default()
406    }
407}
408#[derive(Default, Clone)]
409pub struct ReloadBuilder {
410    context: Option<super::types::BrowsingContext>,
411    ignore_cache: Option<bool>,
412    wait: Option<super::types::ReadinessState>,
413}
414impl ReloadBuilder {
415    pub fn context(mut self, context: impl Into<super::types::BrowsingContext>) -> Self {
416        self.context = Some(context.into());
417        self
418    }
419    pub fn ignore_cache(mut self, ignore_cache: impl Into<bool>) -> Self {
420        self.ignore_cache = Some(ignore_cache.into());
421        self
422    }
423    pub fn wait(mut self, wait: impl Into<super::types::ReadinessState>) -> Self {
424        self.wait = Some(wait.into());
425        self
426    }
427    pub fn build(self) -> Result<Reload, String> {
428        Ok(Reload {
429            method: ReloadMethod::Reload,
430            params: ReloadParams {
431                context: self
432                    .context
433                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(context)))?,
434                ignore_cache: self.ignore_cache,
435                wait: self.wait,
436            },
437        })
438    }
439}
440impl SetViewport {
441    pub fn builder() -> SetViewportBuilder {
442        <SetViewportBuilder as Default>::default()
443    }
444}
445#[derive(Default, Clone)]
446pub struct SetViewportBuilder {
447    context: Option<super::types::BrowsingContext>,
448    viewport: Option<super::types::Viewport>,
449    device_pixel_ratio: Option<f64>,
450    user_contexts: Option<Vec<crate::browser::types::UserContext>>,
451}
452impl SetViewportBuilder {
453    pub fn context(mut self, context: impl Into<super::types::BrowsingContext>) -> Self {
454        self.context = Some(context.into());
455        self
456    }
457    pub fn viewport(mut self, viewport: impl Into<super::types::Viewport>) -> Self {
458        self.viewport = Some(viewport.into());
459        self
460    }
461    pub fn device_pixel_ratio(mut self, device_pixel_ratio: impl Into<f64>) -> Self {
462        self.device_pixel_ratio = Some(device_pixel_ratio.into());
463        self
464    }
465    pub fn user_context(
466        mut self,
467        user_context: impl Into<crate::browser::types::UserContext>,
468    ) -> Self {
469        let v = self.user_contexts.get_or_insert(Vec::new());
470        v.push(user_context.into());
471        self
472    }
473    pub fn user_contexts<I, S>(mut self, user_contexts: I) -> Self
474    where
475        I: IntoIterator<Item = S>,
476        S: Into<crate::browser::types::UserContext>,
477    {
478        let v = self.user_contexts.get_or_insert(Vec::new());
479        for val in user_contexts {
480            v.push(val.into());
481        }
482        self
483    }
484    pub fn build(self) -> SetViewport {
485        SetViewport {
486            method: SetViewportMethod::SetViewport,
487            params: SetViewportParams {
488                context: self.context,
489                viewport: self.viewport,
490                device_pixel_ratio: self.device_pixel_ratio,
491                user_contexts: self.user_contexts,
492            },
493        }
494    }
495}
496impl TraverseHistory {
497    pub fn builder() -> TraverseHistoryBuilder {
498        <TraverseHistoryBuilder as Default>::default()
499    }
500}
501#[derive(Default, Clone)]
502pub struct TraverseHistoryBuilder {
503    context: Option<super::types::BrowsingContext>,
504    delta: Option<i64>,
505}
506impl TraverseHistoryBuilder {
507    pub fn context(mut self, context: impl Into<super::types::BrowsingContext>) -> Self {
508        self.context = Some(context.into());
509        self
510    }
511    pub fn delta(mut self, delta: impl Into<i64>) -> Self {
512        self.delta = Some(delta.into());
513        self
514    }
515    pub fn build(self) -> Result<TraverseHistory, String> {
516        Ok(TraverseHistory {
517            method: TraverseHistoryMethod::TraverseHistory,
518            params: TraverseHistoryParams {
519                context: self
520                    .context
521                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(context)))?,
522                delta: self
523                    .delta
524                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(delta)))?,
525            },
526        })
527    }
528}