Skip to main content

rustenium_cdp_definitions/browser_protocol/dom_snapshot/
command_builders.rs

1use super::commands::*;
2#[derive(Debug, Clone, Default)]
3pub struct DisableBuilder;
4impl DisableBuilder {
5    pub fn new() -> Self {
6        Self
7    }
8    pub fn build(self) -> Disable {
9        Disable {
10            method: DisableMethod::Disable,
11            params: DisableParams {},
12        }
13    }
14}
15impl Disable {
16    pub fn builder() -> DisableBuilder {
17        DisableBuilder
18    }
19}
20#[derive(Debug, Clone, Default)]
21pub struct EnableBuilder;
22impl EnableBuilder {
23    pub fn new() -> Self {
24        Self
25    }
26    pub fn build(self) -> Enable {
27        Enable {
28            method: EnableMethod::Enable,
29            params: EnableParams {},
30        }
31    }
32}
33impl Enable {
34    pub fn builder() -> EnableBuilder {
35        EnableBuilder
36    }
37}
38impl CaptureSnapshot {
39    pub fn builder() -> CaptureSnapshotBuilder {
40        <CaptureSnapshotBuilder as Default>::default()
41    }
42}
43#[derive(Default, Clone)]
44pub struct CaptureSnapshotBuilder {
45    computed_styles: Option<Vec<String>>,
46    include_paint_order: Option<bool>,
47    include_dom_rects: Option<bool>,
48    include_blended_background_colors: Option<bool>,
49    include_text_color_opacities: Option<bool>,
50}
51impl CaptureSnapshotBuilder {
52    pub fn computed_style(mut self, computed_style: impl Into<String>) -> Self {
53        let v = self.computed_styles.get_or_insert(Vec::new());
54        v.push(computed_style.into());
55        self
56    }
57    pub fn computed_styles<I, S>(mut self, computed_styles: I) -> Self
58    where
59        I: IntoIterator<Item = S>,
60        S: Into<String>,
61    {
62        let v = self.computed_styles.get_or_insert(Vec::new());
63        for val in computed_styles {
64            v.push(val.into());
65        }
66        self
67    }
68    pub fn include_paint_order(mut self, include_paint_order: impl Into<bool>) -> Self {
69        self.include_paint_order = Some(include_paint_order.into());
70        self
71    }
72    pub fn include_dom_rects(mut self, include_dom_rects: impl Into<bool>) -> Self {
73        self.include_dom_rects = Some(include_dom_rects.into());
74        self
75    }
76    pub fn include_blended_background_colors(
77        mut self,
78        include_blended_background_colors: impl Into<bool>,
79    ) -> Self {
80        self.include_blended_background_colors = Some(include_blended_background_colors.into());
81        self
82    }
83    pub fn include_text_color_opacities(
84        mut self,
85        include_text_color_opacities: impl Into<bool>,
86    ) -> Self {
87        self.include_text_color_opacities = Some(include_text_color_opacities.into());
88        self
89    }
90    pub fn build(self) -> Result<CaptureSnapshot, String> {
91        Ok(CaptureSnapshot {
92            method: CaptureSnapshotMethod::CaptureSnapshot,
93            params: CaptureSnapshotParams {
94                computed_styles: self.computed_styles.ok_or_else(|| {
95                    format!("Field `{}` is mandatory.", std::stringify!(computed_styles))
96                })?,
97                include_paint_order: self.include_paint_order,
98                include_dom_rects: self.include_dom_rects,
99                include_blended_background_colors: self.include_blended_background_colors,
100                include_text_color_opacities: self.include_text_color_opacities,
101            },
102        })
103    }
104}