Skip to main content

browser_protocol/domsnapshot/
mod.rs

1//! This domain facilitates obtaining document snapshots with DOM, layout, and style information.
2
3
4use serde::{Serialize, Deserialize};
5use serde_json::Value as JsonValue;
6use std::borrow::Cow;
7
8/// A Node in the DOM tree.
9
10#[derive(Debug, Clone, Serialize, Deserialize, Default)]
11#[serde(rename_all = "camelCase")]
12pub struct DOMNode<'a> {
13    /// 'Node''s nodeType.
14    nodeType: i64,
15    /// 'Node''s nodeName.
16    nodeName: Cow<'a, str>,
17    /// 'Node''s nodeValue.
18    nodeValue: Cow<'a, str>,
19    /// Only set for textarea elements, contains the text value.
20    #[serde(skip_serializing_if = "Option::is_none")]
21    textValue: Option<Cow<'a, str>>,
22    /// Only set for input elements, contains the input's associated text value.
23    #[serde(skip_serializing_if = "Option::is_none")]
24    inputValue: Option<Cow<'a, str>>,
25    /// Only set for radio and checkbox input elements, indicates if the element has been checked
26    #[serde(skip_serializing_if = "Option::is_none")]
27    inputChecked: Option<bool>,
28    /// Only set for option elements, indicates if the element has been selected
29    #[serde(skip_serializing_if = "Option::is_none")]
30    optionSelected: Option<bool>,
31    /// 'Node''s id, corresponds to DOM.Node.backendNodeId.
32    backendNodeId: crate::dom::BackendNodeId,
33    /// The indexes of the node's child nodes in the 'domNodes' array returned by 'getSnapshot', if
34    /// any.
35    #[serde(skip_serializing_if = "Option::is_none")]
36    childNodeIndexes: Option<Vec<i64>>,
37    /// Attributes of an 'Element' node.
38    #[serde(skip_serializing_if = "Option::is_none")]
39    attributes: Option<Vec<NameValue<'a>>>,
40    /// Indexes of pseudo elements associated with this node in the 'domNodes' array returned by
41    /// 'getSnapshot', if any.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pseudoElementIndexes: Option<Vec<i64>>,
44    /// The index of the node's related layout tree node in the 'layoutTreeNodes' array returned by
45    /// 'getSnapshot', if any.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    layoutNodeIndex: Option<u64>,
48    /// Document URL that 'Document' or 'FrameOwner' node points to.
49    #[serde(skip_serializing_if = "Option::is_none")]
50    documentURL: Option<Cow<'a, str>>,
51    /// Base URL that 'Document' or 'FrameOwner' node uses for URL completion.
52    #[serde(skip_serializing_if = "Option::is_none")]
53    baseURL: Option<Cow<'a, str>>,
54    /// Only set for documents, contains the document's content language.
55    #[serde(skip_serializing_if = "Option::is_none")]
56    contentLanguage: Option<Cow<'a, str>>,
57    /// Only set for documents, contains the document's character set encoding.
58    #[serde(skip_serializing_if = "Option::is_none")]
59    documentEncoding: Option<Cow<'a, str>>,
60    /// 'DocumentType' node's publicId.
61    #[serde(skip_serializing_if = "Option::is_none")]
62    publicId: Option<Cow<'a, str>>,
63    /// 'DocumentType' node's systemId.
64    #[serde(skip_serializing_if = "Option::is_none")]
65    systemId: Option<Cow<'a, str>>,
66    /// Frame ID for frame owner elements and also for the document node.
67    #[serde(skip_serializing_if = "Option::is_none")]
68    frameId: Option<crate::page::FrameId<'a>>,
69    /// The index of a frame owner element's content document in the 'domNodes' array returned by
70    /// 'getSnapshot', if any.
71    #[serde(skip_serializing_if = "Option::is_none")]
72    contentDocumentIndex: Option<u64>,
73    /// Type of a pseudo element node.
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pseudoType: Option<crate::dom::PseudoType>,
76    /// Shadow root type.
77    #[serde(skip_serializing_if = "Option::is_none")]
78    shadowRootType: Option<crate::dom::ShadowRootType>,
79    /// Whether this DOM node responds to mouse clicks. This includes nodes that have had click
80    /// event listeners attached via JavaScript as well as anchor tags that naturally navigate when
81    /// clicked.
82    #[serde(skip_serializing_if = "Option::is_none")]
83    isClickable: Option<bool>,
84    /// Details of the node's event listeners, if any.
85    #[serde(skip_serializing_if = "Option::is_none")]
86    eventListeners: Option<Vec<crate::domdebugger::EventListener<'a>>>,
87    /// The selected url for nodes with a srcset attribute.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    currentSourceURL: Option<Cow<'a, str>>,
90    /// The url of the script (if any) that generates this node.
91    #[serde(skip_serializing_if = "Option::is_none")]
92    originURL: Option<Cow<'a, str>>,
93    /// Scroll offsets, set when this node is a Document.
94    #[serde(skip_serializing_if = "Option::is_none")]
95    scrollOffsetX: Option<f64>,
96    #[serde(skip_serializing_if = "Option::is_none")]
97    scrollOffsetY: Option<f64>,
98}
99
100impl<'a> DOMNode<'a> {
101    pub fn builder(nodeType: i64, nodeName: impl Into<Cow<'a, str>>, nodeValue: impl Into<Cow<'a, str>>, backendNodeId: crate::dom::BackendNodeId) -> DOMNodeBuilder<'a> {
102        DOMNodeBuilder {
103            nodeType: nodeType,
104            nodeName: nodeName.into(),
105            nodeValue: nodeValue.into(),
106            textValue: None,
107            inputValue: None,
108            inputChecked: None,
109            optionSelected: None,
110            backendNodeId: backendNodeId,
111            childNodeIndexes: None,
112            attributes: None,
113            pseudoElementIndexes: None,
114            layoutNodeIndex: None,
115            documentURL: None,
116            baseURL: None,
117            contentLanguage: None,
118            documentEncoding: None,
119            publicId: None,
120            systemId: None,
121            frameId: None,
122            contentDocumentIndex: None,
123            pseudoType: None,
124            shadowRootType: None,
125            isClickable: None,
126            eventListeners: None,
127            currentSourceURL: None,
128            originURL: None,
129            scrollOffsetX: None,
130            scrollOffsetY: None,
131        }
132    }
133    pub fn nodeType(&self) -> i64 { self.nodeType }
134    pub fn nodeName(&self) -> &str { self.nodeName.as_ref() }
135    pub fn nodeValue(&self) -> &str { self.nodeValue.as_ref() }
136    pub fn textValue(&self) -> Option<&str> { self.textValue.as_deref() }
137    pub fn inputValue(&self) -> Option<&str> { self.inputValue.as_deref() }
138    pub fn inputChecked(&self) -> Option<bool> { self.inputChecked }
139    pub fn optionSelected(&self) -> Option<bool> { self.optionSelected }
140    pub fn backendNodeId(&self) -> &crate::dom::BackendNodeId { &self.backendNodeId }
141    pub fn childNodeIndexes(&self) -> Option<&[i64]> { self.childNodeIndexes.as_deref() }
142    pub fn attributes(&self) -> Option<&[NameValue<'a>]> { self.attributes.as_deref() }
143    pub fn pseudoElementIndexes(&self) -> Option<&[i64]> { self.pseudoElementIndexes.as_deref() }
144    pub fn layoutNodeIndex(&self) -> Option<u64> { self.layoutNodeIndex }
145    pub fn documentURL(&self) -> Option<&str> { self.documentURL.as_deref() }
146    pub fn baseURL(&self) -> Option<&str> { self.baseURL.as_deref() }
147    pub fn contentLanguage(&self) -> Option<&str> { self.contentLanguage.as_deref() }
148    pub fn documentEncoding(&self) -> Option<&str> { self.documentEncoding.as_deref() }
149    pub fn publicId(&self) -> Option<&str> { self.publicId.as_deref() }
150    pub fn systemId(&self) -> Option<&str> { self.systemId.as_deref() }
151    pub fn frameId(&self) -> Option<&crate::page::FrameId<'a>> { self.frameId.as_ref() }
152    pub fn contentDocumentIndex(&self) -> Option<u64> { self.contentDocumentIndex }
153    pub fn pseudoType(&self) -> Option<&crate::dom::PseudoType> { self.pseudoType.as_ref() }
154    pub fn shadowRootType(&self) -> Option<&crate::dom::ShadowRootType> { self.shadowRootType.as_ref() }
155    pub fn isClickable(&self) -> Option<bool> { self.isClickable }
156    pub fn eventListeners(&self) -> Option<&[crate::domdebugger::EventListener<'a>]> { self.eventListeners.as_deref() }
157    pub fn currentSourceURL(&self) -> Option<&str> { self.currentSourceURL.as_deref() }
158    pub fn originURL(&self) -> Option<&str> { self.originURL.as_deref() }
159    pub fn scrollOffsetX(&self) -> Option<f64> { self.scrollOffsetX }
160    pub fn scrollOffsetY(&self) -> Option<f64> { self.scrollOffsetY }
161}
162
163
164pub struct DOMNodeBuilder<'a> {
165    nodeType: i64,
166    nodeName: Cow<'a, str>,
167    nodeValue: Cow<'a, str>,
168    textValue: Option<Cow<'a, str>>,
169    inputValue: Option<Cow<'a, str>>,
170    inputChecked: Option<bool>,
171    optionSelected: Option<bool>,
172    backendNodeId: crate::dom::BackendNodeId,
173    childNodeIndexes: Option<Vec<i64>>,
174    attributes: Option<Vec<NameValue<'a>>>,
175    pseudoElementIndexes: Option<Vec<i64>>,
176    layoutNodeIndex: Option<u64>,
177    documentURL: Option<Cow<'a, str>>,
178    baseURL: Option<Cow<'a, str>>,
179    contentLanguage: Option<Cow<'a, str>>,
180    documentEncoding: Option<Cow<'a, str>>,
181    publicId: Option<Cow<'a, str>>,
182    systemId: Option<Cow<'a, str>>,
183    frameId: Option<crate::page::FrameId<'a>>,
184    contentDocumentIndex: Option<u64>,
185    pseudoType: Option<crate::dom::PseudoType>,
186    shadowRootType: Option<crate::dom::ShadowRootType>,
187    isClickable: Option<bool>,
188    eventListeners: Option<Vec<crate::domdebugger::EventListener<'a>>>,
189    currentSourceURL: Option<Cow<'a, str>>,
190    originURL: Option<Cow<'a, str>>,
191    scrollOffsetX: Option<f64>,
192    scrollOffsetY: Option<f64>,
193}
194
195impl<'a> DOMNodeBuilder<'a> {
196    /// Only set for textarea elements, contains the text value.
197    pub fn textValue(mut self, textValue: impl Into<Cow<'a, str>>) -> Self { self.textValue = Some(textValue.into()); self }
198    /// Only set for input elements, contains the input's associated text value.
199    pub fn inputValue(mut self, inputValue: impl Into<Cow<'a, str>>) -> Self { self.inputValue = Some(inputValue.into()); self }
200    /// Only set for radio and checkbox input elements, indicates if the element has been checked
201    pub fn inputChecked(mut self, inputChecked: bool) -> Self { self.inputChecked = Some(inputChecked); self }
202    /// Only set for option elements, indicates if the element has been selected
203    pub fn optionSelected(mut self, optionSelected: bool) -> Self { self.optionSelected = Some(optionSelected); self }
204    /// The indexes of the node's child nodes in the 'domNodes' array returned by 'getSnapshot', if
205    /// any.
206    pub fn childNodeIndexes(mut self, childNodeIndexes: Vec<i64>) -> Self { self.childNodeIndexes = Some(childNodeIndexes); self }
207    /// Attributes of an 'Element' node.
208    pub fn attributes(mut self, attributes: Vec<NameValue<'a>>) -> Self { self.attributes = Some(attributes); self }
209    /// Indexes of pseudo elements associated with this node in the 'domNodes' array returned by
210    /// 'getSnapshot', if any.
211    pub fn pseudoElementIndexes(mut self, pseudoElementIndexes: Vec<i64>) -> Self { self.pseudoElementIndexes = Some(pseudoElementIndexes); self }
212    /// The index of the node's related layout tree node in the 'layoutTreeNodes' array returned by
213    /// 'getSnapshot', if any.
214    pub fn layoutNodeIndex(mut self, layoutNodeIndex: u64) -> Self { self.layoutNodeIndex = Some(layoutNodeIndex); self }
215    /// Document URL that 'Document' or 'FrameOwner' node points to.
216    pub fn documentURL(mut self, documentURL: impl Into<Cow<'a, str>>) -> Self { self.documentURL = Some(documentURL.into()); self }
217    /// Base URL that 'Document' or 'FrameOwner' node uses for URL completion.
218    pub fn baseURL(mut self, baseURL: impl Into<Cow<'a, str>>) -> Self { self.baseURL = Some(baseURL.into()); self }
219    /// Only set for documents, contains the document's content language.
220    pub fn contentLanguage(mut self, contentLanguage: impl Into<Cow<'a, str>>) -> Self { self.contentLanguage = Some(contentLanguage.into()); self }
221    /// Only set for documents, contains the document's character set encoding.
222    pub fn documentEncoding(mut self, documentEncoding: impl Into<Cow<'a, str>>) -> Self { self.documentEncoding = Some(documentEncoding.into()); self }
223    /// 'DocumentType' node's publicId.
224    pub fn publicId(mut self, publicId: impl Into<Cow<'a, str>>) -> Self { self.publicId = Some(publicId.into()); self }
225    /// 'DocumentType' node's systemId.
226    pub fn systemId(mut self, systemId: impl Into<Cow<'a, str>>) -> Self { self.systemId = Some(systemId.into()); self }
227    /// Frame ID for frame owner elements and also for the document node.
228    pub fn frameId(mut self, frameId: crate::page::FrameId<'a>) -> Self { self.frameId = Some(frameId); self }
229    /// The index of a frame owner element's content document in the 'domNodes' array returned by
230    /// 'getSnapshot', if any.
231    pub fn contentDocumentIndex(mut self, contentDocumentIndex: u64) -> Self { self.contentDocumentIndex = Some(contentDocumentIndex); self }
232    /// Type of a pseudo element node.
233    pub fn pseudoType(mut self, pseudoType: crate::dom::PseudoType) -> Self { self.pseudoType = Some(pseudoType); self }
234    /// Shadow root type.
235    pub fn shadowRootType(mut self, shadowRootType: crate::dom::ShadowRootType) -> Self { self.shadowRootType = Some(shadowRootType); self }
236    /// Whether this DOM node responds to mouse clicks. This includes nodes that have had click
237    /// event listeners attached via JavaScript as well as anchor tags that naturally navigate when
238    /// clicked.
239    pub fn isClickable(mut self, isClickable: bool) -> Self { self.isClickable = Some(isClickable); self }
240    /// Details of the node's event listeners, if any.
241    pub fn eventListeners(mut self, eventListeners: Vec<crate::domdebugger::EventListener<'a>>) -> Self { self.eventListeners = Some(eventListeners); self }
242    /// The selected url for nodes with a srcset attribute.
243    pub fn currentSourceURL(mut self, currentSourceURL: impl Into<Cow<'a, str>>) -> Self { self.currentSourceURL = Some(currentSourceURL.into()); self }
244    /// The url of the script (if any) that generates this node.
245    pub fn originURL(mut self, originURL: impl Into<Cow<'a, str>>) -> Self { self.originURL = Some(originURL.into()); self }
246    /// Scroll offsets, set when this node is a Document.
247    pub fn scrollOffsetX(mut self, scrollOffsetX: f64) -> Self { self.scrollOffsetX = Some(scrollOffsetX); self }
248    pub fn scrollOffsetY(mut self, scrollOffsetY: f64) -> Self { self.scrollOffsetY = Some(scrollOffsetY); self }
249    pub fn build(self) -> DOMNode<'a> {
250        DOMNode {
251            nodeType: self.nodeType,
252            nodeName: self.nodeName,
253            nodeValue: self.nodeValue,
254            textValue: self.textValue,
255            inputValue: self.inputValue,
256            inputChecked: self.inputChecked,
257            optionSelected: self.optionSelected,
258            backendNodeId: self.backendNodeId,
259            childNodeIndexes: self.childNodeIndexes,
260            attributes: self.attributes,
261            pseudoElementIndexes: self.pseudoElementIndexes,
262            layoutNodeIndex: self.layoutNodeIndex,
263            documentURL: self.documentURL,
264            baseURL: self.baseURL,
265            contentLanguage: self.contentLanguage,
266            documentEncoding: self.documentEncoding,
267            publicId: self.publicId,
268            systemId: self.systemId,
269            frameId: self.frameId,
270            contentDocumentIndex: self.contentDocumentIndex,
271            pseudoType: self.pseudoType,
272            shadowRootType: self.shadowRootType,
273            isClickable: self.isClickable,
274            eventListeners: self.eventListeners,
275            currentSourceURL: self.currentSourceURL,
276            originURL: self.originURL,
277            scrollOffsetX: self.scrollOffsetX,
278            scrollOffsetY: self.scrollOffsetY,
279        }
280    }
281}
282
283/// Details of post layout rendered text positions. The exact layout should not be regarded as
284/// stable and may change between versions.
285
286#[derive(Debug, Clone, Serialize, Deserialize, Default)]
287#[serde(rename_all = "camelCase")]
288pub struct InlineTextBox {
289    /// The bounding box in document coordinates. Note that scroll offset of the document is ignored.
290    boundingBox: crate::dom::Rect,
291    /// The starting index in characters, for this post layout textbox substring. Characters that
292    /// would be represented as a surrogate pair in UTF-16 have length 2.
293    startCharacterIndex: u64,
294    /// The number of characters in this post layout textbox substring. Characters that would be
295    /// represented as a surrogate pair in UTF-16 have length 2.
296    numCharacters: i64,
297}
298
299impl InlineTextBox {
300    pub fn builder(boundingBox: crate::dom::Rect, startCharacterIndex: u64, numCharacters: i64) -> InlineTextBoxBuilder {
301        InlineTextBoxBuilder {
302            boundingBox: boundingBox,
303            startCharacterIndex: startCharacterIndex,
304            numCharacters: numCharacters,
305        }
306    }
307    pub fn boundingBox(&self) -> &crate::dom::Rect { &self.boundingBox }
308    pub fn startCharacterIndex(&self) -> u64 { self.startCharacterIndex }
309    pub fn numCharacters(&self) -> i64 { self.numCharacters }
310}
311
312
313pub struct InlineTextBoxBuilder {
314    boundingBox: crate::dom::Rect,
315    startCharacterIndex: u64,
316    numCharacters: i64,
317}
318
319impl InlineTextBoxBuilder {
320    pub fn build(self) -> InlineTextBox {
321        InlineTextBox {
322            boundingBox: self.boundingBox,
323            startCharacterIndex: self.startCharacterIndex,
324            numCharacters: self.numCharacters,
325        }
326    }
327}
328
329/// Details of an element in the DOM tree with a LayoutObject.
330
331#[derive(Debug, Clone, Serialize, Deserialize, Default)]
332#[serde(rename_all = "camelCase")]
333pub struct LayoutTreeNode<'a> {
334    /// The index of the related DOM node in the 'domNodes' array returned by 'getSnapshot'.
335    domNodeIndex: u64,
336    /// The bounding box in document coordinates. Note that scroll offset of the document is ignored.
337    boundingBox: crate::dom::Rect,
338    /// Contents of the LayoutText, if any.
339    #[serde(skip_serializing_if = "Option::is_none")]
340    layoutText: Option<Cow<'a, str>>,
341    /// The post-layout inline text nodes, if any.
342    #[serde(skip_serializing_if = "Option::is_none")]
343    inlineTextNodes: Option<Vec<InlineTextBox>>,
344    /// Index into the 'computedStyles' array returned by 'getSnapshot'.
345    #[serde(skip_serializing_if = "Option::is_none")]
346    styleIndex: Option<u64>,
347    /// Global paint order index, which is determined by the stacking order of the nodes. Nodes
348    /// that are painted together will have the same index. Only provided if includePaintOrder in
349    /// getSnapshot was true.
350    #[serde(skip_serializing_if = "Option::is_none")]
351    paintOrder: Option<i64>,
352    /// Set to true to indicate the element begins a new stacking context.
353    #[serde(skip_serializing_if = "Option::is_none")]
354    isStackingContext: Option<bool>,
355}
356
357impl<'a> LayoutTreeNode<'a> {
358    pub fn builder(domNodeIndex: u64, boundingBox: crate::dom::Rect) -> LayoutTreeNodeBuilder<'a> {
359        LayoutTreeNodeBuilder {
360            domNodeIndex: domNodeIndex,
361            boundingBox: boundingBox,
362            layoutText: None,
363            inlineTextNodes: None,
364            styleIndex: None,
365            paintOrder: None,
366            isStackingContext: None,
367        }
368    }
369    pub fn domNodeIndex(&self) -> u64 { self.domNodeIndex }
370    pub fn boundingBox(&self) -> &crate::dom::Rect { &self.boundingBox }
371    pub fn layoutText(&self) -> Option<&str> { self.layoutText.as_deref() }
372    pub fn inlineTextNodes(&self) -> Option<&[InlineTextBox]> { self.inlineTextNodes.as_deref() }
373    pub fn styleIndex(&self) -> Option<u64> { self.styleIndex }
374    pub fn paintOrder(&self) -> Option<i64> { self.paintOrder }
375    pub fn isStackingContext(&self) -> Option<bool> { self.isStackingContext }
376}
377
378
379pub struct LayoutTreeNodeBuilder<'a> {
380    domNodeIndex: u64,
381    boundingBox: crate::dom::Rect,
382    layoutText: Option<Cow<'a, str>>,
383    inlineTextNodes: Option<Vec<InlineTextBox>>,
384    styleIndex: Option<u64>,
385    paintOrder: Option<i64>,
386    isStackingContext: Option<bool>,
387}
388
389impl<'a> LayoutTreeNodeBuilder<'a> {
390    /// Contents of the LayoutText, if any.
391    pub fn layoutText(mut self, layoutText: impl Into<Cow<'a, str>>) -> Self { self.layoutText = Some(layoutText.into()); self }
392    /// The post-layout inline text nodes, if any.
393    pub fn inlineTextNodes(mut self, inlineTextNodes: Vec<InlineTextBox>) -> Self { self.inlineTextNodes = Some(inlineTextNodes); self }
394    /// Index into the 'computedStyles' array returned by 'getSnapshot'.
395    pub fn styleIndex(mut self, styleIndex: u64) -> Self { self.styleIndex = Some(styleIndex); self }
396    /// Global paint order index, which is determined by the stacking order of the nodes. Nodes
397    /// that are painted together will have the same index. Only provided if includePaintOrder in
398    /// getSnapshot was true.
399    pub fn paintOrder(mut self, paintOrder: i64) -> Self { self.paintOrder = Some(paintOrder); self }
400    /// Set to true to indicate the element begins a new stacking context.
401    pub fn isStackingContext(mut self, isStackingContext: bool) -> Self { self.isStackingContext = Some(isStackingContext); self }
402    pub fn build(self) -> LayoutTreeNode<'a> {
403        LayoutTreeNode {
404            domNodeIndex: self.domNodeIndex,
405            boundingBox: self.boundingBox,
406            layoutText: self.layoutText,
407            inlineTextNodes: self.inlineTextNodes,
408            styleIndex: self.styleIndex,
409            paintOrder: self.paintOrder,
410            isStackingContext: self.isStackingContext,
411        }
412    }
413}
414
415/// A subset of the full ComputedStyle as defined by the request whitelist.
416
417#[derive(Debug, Clone, Serialize, Deserialize, Default)]
418#[serde(rename_all = "camelCase")]
419pub struct ComputedStyle<'a> {
420    /// Name/value pairs of computed style properties.
421    properties: Vec<NameValue<'a>>,
422}
423
424impl<'a> ComputedStyle<'a> {
425    pub fn builder(properties: Vec<NameValue<'a>>) -> ComputedStyleBuilder<'a> {
426        ComputedStyleBuilder {
427            properties: properties,
428        }
429    }
430    pub fn properties(&self) -> &[NameValue<'a>] { &self.properties }
431}
432
433
434pub struct ComputedStyleBuilder<'a> {
435    properties: Vec<NameValue<'a>>,
436}
437
438impl<'a> ComputedStyleBuilder<'a> {
439    pub fn build(self) -> ComputedStyle<'a> {
440        ComputedStyle {
441            properties: self.properties,
442        }
443    }
444}
445
446/// A name/value pair.
447
448#[derive(Debug, Clone, Serialize, Deserialize, Default)]
449#[serde(rename_all = "camelCase")]
450pub struct NameValue<'a> {
451    /// Attribute/property name.
452    name: Cow<'a, str>,
453    /// Attribute/property value.
454    value: Cow<'a, str>,
455}
456
457impl<'a> NameValue<'a> {
458    pub fn builder(name: impl Into<Cow<'a, str>>, value: impl Into<Cow<'a, str>>) -> NameValueBuilder<'a> {
459        NameValueBuilder {
460            name: name.into(),
461            value: value.into(),
462        }
463    }
464    pub fn name(&self) -> &str { self.name.as_ref() }
465    pub fn value(&self) -> &str { self.value.as_ref() }
466}
467
468
469pub struct NameValueBuilder<'a> {
470    name: Cow<'a, str>,
471    value: Cow<'a, str>,
472}
473
474impl<'a> NameValueBuilder<'a> {
475    pub fn build(self) -> NameValue<'a> {
476        NameValue {
477            name: self.name,
478            value: self.value,
479        }
480    }
481}
482
483/// Index of the string in the strings table.
484
485pub type StringIndex = i64;
486
487/// Index of the string in the strings table.
488
489pub type ArrayOfStrings = Vec<StringIndex>;
490
491/// Data that is only present on rare nodes.
492
493#[derive(Debug, Clone, Serialize, Deserialize, Default)]
494#[serde(rename_all = "camelCase")]
495pub struct RareStringData {
496    index: Vec<i64>,
497    value: Vec<StringIndex>,
498}
499
500impl RareStringData {
501    pub fn builder(index: Vec<i64>, value: Vec<StringIndex>) -> RareStringDataBuilder {
502        RareStringDataBuilder {
503            index: index,
504            value: value,
505        }
506    }
507    pub fn index(&self) -> &[i64] { &self.index }
508    pub fn value(&self) -> &[StringIndex] { &self.value }
509}
510
511
512pub struct RareStringDataBuilder {
513    index: Vec<i64>,
514    value: Vec<StringIndex>,
515}
516
517impl RareStringDataBuilder {
518    pub fn build(self) -> RareStringData {
519        RareStringData {
520            index: self.index,
521            value: self.value,
522        }
523    }
524}
525
526
527#[derive(Debug, Clone, Serialize, Deserialize, Default)]
528#[serde(rename_all = "camelCase")]
529pub struct RareBooleanData {
530    index: Vec<i64>,
531}
532
533impl RareBooleanData {
534    pub fn builder(index: Vec<i64>) -> RareBooleanDataBuilder {
535        RareBooleanDataBuilder {
536            index: index,
537        }
538    }
539    pub fn index(&self) -> &[i64] { &self.index }
540}
541
542
543pub struct RareBooleanDataBuilder {
544    index: Vec<i64>,
545}
546
547impl RareBooleanDataBuilder {
548    pub fn build(self) -> RareBooleanData {
549        RareBooleanData {
550            index: self.index,
551        }
552    }
553}
554
555
556#[derive(Debug, Clone, Serialize, Deserialize, Default)]
557#[serde(rename_all = "camelCase")]
558pub struct RareIntegerData {
559    index: Vec<i64>,
560    value: Vec<i64>,
561}
562
563impl RareIntegerData {
564    pub fn builder(index: Vec<i64>, value: Vec<i64>) -> RareIntegerDataBuilder {
565        RareIntegerDataBuilder {
566            index: index,
567            value: value,
568        }
569    }
570    pub fn index(&self) -> &[i64] { &self.index }
571    pub fn value(&self) -> &[i64] { &self.value }
572}
573
574
575pub struct RareIntegerDataBuilder {
576    index: Vec<i64>,
577    value: Vec<i64>,
578}
579
580impl RareIntegerDataBuilder {
581    pub fn build(self) -> RareIntegerData {
582        RareIntegerData {
583            index: self.index,
584            value: self.value,
585        }
586    }
587}
588
589
590pub type Rectangle = Vec<f64>;
591
592/// Document snapshot.
593
594#[derive(Debug, Clone, Serialize, Deserialize, Default)]
595#[serde(rename_all = "camelCase")]
596pub struct DocumentSnapshot {
597    /// Document URL that 'Document' or 'FrameOwner' node points to.
598    documentURL: StringIndex,
599    /// Document title.
600    title: StringIndex,
601    /// Base URL that 'Document' or 'FrameOwner' node uses for URL completion.
602    baseURL: StringIndex,
603    /// Contains the document's content language.
604    contentLanguage: StringIndex,
605    /// Contains the document's character set encoding.
606    encodingName: StringIndex,
607    /// 'DocumentType' node's publicId.
608    publicId: StringIndex,
609    /// 'DocumentType' node's systemId.
610    systemId: StringIndex,
611    /// Frame ID for frame owner elements and also for the document node.
612    frameId: StringIndex,
613    /// A table with dom nodes.
614    nodes: NodeTreeSnapshot,
615    /// The nodes in the layout tree.
616    layout: LayoutTreeSnapshot,
617    /// The post-layout inline text nodes.
618    textBoxes: TextBoxSnapshot,
619    /// Horizontal scroll offset.
620    #[serde(skip_serializing_if = "Option::is_none")]
621    scrollOffsetX: Option<f64>,
622    /// Vertical scroll offset.
623    #[serde(skip_serializing_if = "Option::is_none")]
624    scrollOffsetY: Option<f64>,
625    /// Document content width.
626    #[serde(skip_serializing_if = "Option::is_none")]
627    contentWidth: Option<f64>,
628    /// Document content height.
629    #[serde(skip_serializing_if = "Option::is_none")]
630    contentHeight: Option<f64>,
631}
632
633impl DocumentSnapshot {
634    pub fn builder(documentURL: StringIndex, title: StringIndex, baseURL: StringIndex, contentLanguage: StringIndex, encodingName: StringIndex, publicId: StringIndex, systemId: StringIndex, frameId: StringIndex, nodes: NodeTreeSnapshot, layout: LayoutTreeSnapshot, textBoxes: TextBoxSnapshot) -> DocumentSnapshotBuilder {
635        DocumentSnapshotBuilder {
636            documentURL: documentURL,
637            title: title,
638            baseURL: baseURL,
639            contentLanguage: contentLanguage,
640            encodingName: encodingName,
641            publicId: publicId,
642            systemId: systemId,
643            frameId: frameId,
644            nodes: nodes,
645            layout: layout,
646            textBoxes: textBoxes,
647            scrollOffsetX: None,
648            scrollOffsetY: None,
649            contentWidth: None,
650            contentHeight: None,
651        }
652    }
653    pub fn documentURL(&self) -> &StringIndex { &self.documentURL }
654    pub fn title(&self) -> &StringIndex { &self.title }
655    pub fn baseURL(&self) -> &StringIndex { &self.baseURL }
656    pub fn contentLanguage(&self) -> &StringIndex { &self.contentLanguage }
657    pub fn encodingName(&self) -> &StringIndex { &self.encodingName }
658    pub fn publicId(&self) -> &StringIndex { &self.publicId }
659    pub fn systemId(&self) -> &StringIndex { &self.systemId }
660    pub fn frameId(&self) -> &StringIndex { &self.frameId }
661    pub fn nodes(&self) -> &NodeTreeSnapshot { &self.nodes }
662    pub fn layout(&self) -> &LayoutTreeSnapshot { &self.layout }
663    pub fn textBoxes(&self) -> &TextBoxSnapshot { &self.textBoxes }
664    pub fn scrollOffsetX(&self) -> Option<f64> { self.scrollOffsetX }
665    pub fn scrollOffsetY(&self) -> Option<f64> { self.scrollOffsetY }
666    pub fn contentWidth(&self) -> Option<f64> { self.contentWidth }
667    pub fn contentHeight(&self) -> Option<f64> { self.contentHeight }
668}
669
670
671pub struct DocumentSnapshotBuilder {
672    documentURL: StringIndex,
673    title: StringIndex,
674    baseURL: StringIndex,
675    contentLanguage: StringIndex,
676    encodingName: StringIndex,
677    publicId: StringIndex,
678    systemId: StringIndex,
679    frameId: StringIndex,
680    nodes: NodeTreeSnapshot,
681    layout: LayoutTreeSnapshot,
682    textBoxes: TextBoxSnapshot,
683    scrollOffsetX: Option<f64>,
684    scrollOffsetY: Option<f64>,
685    contentWidth: Option<f64>,
686    contentHeight: Option<f64>,
687}
688
689impl DocumentSnapshotBuilder {
690    /// Horizontal scroll offset.
691    pub fn scrollOffsetX(mut self, scrollOffsetX: f64) -> Self { self.scrollOffsetX = Some(scrollOffsetX); self }
692    /// Vertical scroll offset.
693    pub fn scrollOffsetY(mut self, scrollOffsetY: f64) -> Self { self.scrollOffsetY = Some(scrollOffsetY); self }
694    /// Document content width.
695    pub fn contentWidth(mut self, contentWidth: f64) -> Self { self.contentWidth = Some(contentWidth); self }
696    /// Document content height.
697    pub fn contentHeight(mut self, contentHeight: f64) -> Self { self.contentHeight = Some(contentHeight); self }
698    pub fn build(self) -> DocumentSnapshot {
699        DocumentSnapshot {
700            documentURL: self.documentURL,
701            title: self.title,
702            baseURL: self.baseURL,
703            contentLanguage: self.contentLanguage,
704            encodingName: self.encodingName,
705            publicId: self.publicId,
706            systemId: self.systemId,
707            frameId: self.frameId,
708            nodes: self.nodes,
709            layout: self.layout,
710            textBoxes: self.textBoxes,
711            scrollOffsetX: self.scrollOffsetX,
712            scrollOffsetY: self.scrollOffsetY,
713            contentWidth: self.contentWidth,
714            contentHeight: self.contentHeight,
715        }
716    }
717}
718
719/// Table containing nodes.
720
721#[derive(Debug, Clone, Serialize, Deserialize, Default)]
722#[serde(rename_all = "camelCase")]
723pub struct NodeTreeSnapshot {
724    /// Parent node index.
725    #[serde(skip_serializing_if = "Option::is_none")]
726    parentIndex: Option<Vec<i64>>,
727    /// 'Node''s nodeType.
728    #[serde(skip_serializing_if = "Option::is_none")]
729    nodeType: Option<Vec<i64>>,
730    /// Type of the shadow root the 'Node' is in. String values are equal to the 'ShadowRootType' enum.
731    #[serde(skip_serializing_if = "Option::is_none")]
732    shadowRootType: Option<RareStringData>,
733    /// 'Node''s nodeName.
734    #[serde(skip_serializing_if = "Option::is_none")]
735    nodeName: Option<Vec<StringIndex>>,
736    /// 'Node''s nodeValue.
737    #[serde(skip_serializing_if = "Option::is_none")]
738    nodeValue: Option<Vec<StringIndex>>,
739    /// 'Node''s id, corresponds to DOM.Node.backendNodeId.
740    #[serde(skip_serializing_if = "Option::is_none")]
741    backendNodeId: Option<Vec<crate::dom::BackendNodeId>>,
742    /// Attributes of an 'Element' node. Flatten name, value pairs.
743    #[serde(skip_serializing_if = "Option::is_none")]
744    attributes: Option<Vec<ArrayOfStrings>>,
745    /// Only set for textarea elements, contains the text value.
746    #[serde(skip_serializing_if = "Option::is_none")]
747    textValue: Option<RareStringData>,
748    /// Only set for input elements, contains the input's associated text value.
749    #[serde(skip_serializing_if = "Option::is_none")]
750    inputValue: Option<RareStringData>,
751    /// Only set for radio and checkbox input elements, indicates if the element has been checked
752    #[serde(skip_serializing_if = "Option::is_none")]
753    inputChecked: Option<RareBooleanData>,
754    /// Only set for option elements, indicates if the element has been selected
755    #[serde(skip_serializing_if = "Option::is_none")]
756    optionSelected: Option<RareBooleanData>,
757    /// The index of the document in the list of the snapshot documents.
758    #[serde(skip_serializing_if = "Option::is_none")]
759    contentDocumentIndex: Option<RareIntegerData>,
760    /// Type of a pseudo element node.
761    #[serde(skip_serializing_if = "Option::is_none")]
762    pseudoType: Option<RareStringData>,
763    /// Pseudo element identifier for this node. Only present if there is a
764    /// valid pseudoType.
765    #[serde(skip_serializing_if = "Option::is_none")]
766    pseudoIdentifier: Option<RareStringData>,
767    /// Whether this DOM node responds to mouse clicks. This includes nodes that have had click
768    /// event listeners attached via JavaScript as well as anchor tags that naturally navigate when
769    /// clicked.
770    #[serde(skip_serializing_if = "Option::is_none")]
771    isClickable: Option<RareBooleanData>,
772    /// The selected url for nodes with a srcset attribute.
773    #[serde(skip_serializing_if = "Option::is_none")]
774    currentSourceURL: Option<RareStringData>,
775    /// The url of the script (if any) that generates this node.
776    #[serde(skip_serializing_if = "Option::is_none")]
777    originURL: Option<RareStringData>,
778}
779
780impl NodeTreeSnapshot {
781    pub fn builder() -> NodeTreeSnapshotBuilder {
782        NodeTreeSnapshotBuilder {
783            parentIndex: None,
784            nodeType: None,
785            shadowRootType: None,
786            nodeName: None,
787            nodeValue: None,
788            backendNodeId: None,
789            attributes: None,
790            textValue: None,
791            inputValue: None,
792            inputChecked: None,
793            optionSelected: None,
794            contentDocumentIndex: None,
795            pseudoType: None,
796            pseudoIdentifier: None,
797            isClickable: None,
798            currentSourceURL: None,
799            originURL: None,
800        }
801    }
802    pub fn parentIndex(&self) -> Option<&[i64]> { self.parentIndex.as_deref() }
803    pub fn nodeType(&self) -> Option<&[i64]> { self.nodeType.as_deref() }
804    pub fn shadowRootType(&self) -> Option<&RareStringData> { self.shadowRootType.as_ref() }
805    pub fn nodeName(&self) -> Option<&[StringIndex]> { self.nodeName.as_deref() }
806    pub fn nodeValue(&self) -> Option<&[StringIndex]> { self.nodeValue.as_deref() }
807    pub fn backendNodeId(&self) -> Option<&[crate::dom::BackendNodeId]> { self.backendNodeId.as_deref() }
808    pub fn attributes(&self) -> Option<&[ArrayOfStrings]> { self.attributes.as_deref() }
809    pub fn textValue(&self) -> Option<&RareStringData> { self.textValue.as_ref() }
810    pub fn inputValue(&self) -> Option<&RareStringData> { self.inputValue.as_ref() }
811    pub fn inputChecked(&self) -> Option<&RareBooleanData> { self.inputChecked.as_ref() }
812    pub fn optionSelected(&self) -> Option<&RareBooleanData> { self.optionSelected.as_ref() }
813    pub fn contentDocumentIndex(&self) -> Option<&RareIntegerData> { self.contentDocumentIndex.as_ref() }
814    pub fn pseudoType(&self) -> Option<&RareStringData> { self.pseudoType.as_ref() }
815    pub fn pseudoIdentifier(&self) -> Option<&RareStringData> { self.pseudoIdentifier.as_ref() }
816    pub fn isClickable(&self) -> Option<&RareBooleanData> { self.isClickable.as_ref() }
817    pub fn currentSourceURL(&self) -> Option<&RareStringData> { self.currentSourceURL.as_ref() }
818    pub fn originURL(&self) -> Option<&RareStringData> { self.originURL.as_ref() }
819}
820
821#[derive(Default)]
822pub struct NodeTreeSnapshotBuilder {
823    parentIndex: Option<Vec<i64>>,
824    nodeType: Option<Vec<i64>>,
825    shadowRootType: Option<RareStringData>,
826    nodeName: Option<Vec<StringIndex>>,
827    nodeValue: Option<Vec<StringIndex>>,
828    backendNodeId: Option<Vec<crate::dom::BackendNodeId>>,
829    attributes: Option<Vec<ArrayOfStrings>>,
830    textValue: Option<RareStringData>,
831    inputValue: Option<RareStringData>,
832    inputChecked: Option<RareBooleanData>,
833    optionSelected: Option<RareBooleanData>,
834    contentDocumentIndex: Option<RareIntegerData>,
835    pseudoType: Option<RareStringData>,
836    pseudoIdentifier: Option<RareStringData>,
837    isClickable: Option<RareBooleanData>,
838    currentSourceURL: Option<RareStringData>,
839    originURL: Option<RareStringData>,
840}
841
842impl NodeTreeSnapshotBuilder {
843    /// Parent node index.
844    pub fn parentIndex(mut self, parentIndex: Vec<i64>) -> Self { self.parentIndex = Some(parentIndex); self }
845    /// 'Node''s nodeType.
846    pub fn nodeType(mut self, nodeType: Vec<i64>) -> Self { self.nodeType = Some(nodeType); self }
847    /// Type of the shadow root the 'Node' is in. String values are equal to the 'ShadowRootType' enum.
848    pub fn shadowRootType(mut self, shadowRootType: RareStringData) -> Self { self.shadowRootType = Some(shadowRootType); self }
849    /// 'Node''s nodeName.
850    pub fn nodeName(mut self, nodeName: Vec<StringIndex>) -> Self { self.nodeName = Some(nodeName); self }
851    /// 'Node''s nodeValue.
852    pub fn nodeValue(mut self, nodeValue: Vec<StringIndex>) -> Self { self.nodeValue = Some(nodeValue); self }
853    /// 'Node''s id, corresponds to DOM.Node.backendNodeId.
854    pub fn backendNodeId(mut self, backendNodeId: Vec<crate::dom::BackendNodeId>) -> Self { self.backendNodeId = Some(backendNodeId); self }
855    /// Attributes of an 'Element' node. Flatten name, value pairs.
856    pub fn attributes(mut self, attributes: Vec<ArrayOfStrings>) -> Self { self.attributes = Some(attributes); self }
857    /// Only set for textarea elements, contains the text value.
858    pub fn textValue(mut self, textValue: RareStringData) -> Self { self.textValue = Some(textValue); self }
859    /// Only set for input elements, contains the input's associated text value.
860    pub fn inputValue(mut self, inputValue: RareStringData) -> Self { self.inputValue = Some(inputValue); self }
861    /// Only set for radio and checkbox input elements, indicates if the element has been checked
862    pub fn inputChecked(mut self, inputChecked: RareBooleanData) -> Self { self.inputChecked = Some(inputChecked); self }
863    /// Only set for option elements, indicates if the element has been selected
864    pub fn optionSelected(mut self, optionSelected: RareBooleanData) -> Self { self.optionSelected = Some(optionSelected); self }
865    /// The index of the document in the list of the snapshot documents.
866    pub fn contentDocumentIndex(mut self, contentDocumentIndex: RareIntegerData) -> Self { self.contentDocumentIndex = Some(contentDocumentIndex); self }
867    /// Type of a pseudo element node.
868    pub fn pseudoType(mut self, pseudoType: RareStringData) -> Self { self.pseudoType = Some(pseudoType); self }
869    /// Pseudo element identifier for this node. Only present if there is a
870    /// valid pseudoType.
871    pub fn pseudoIdentifier(mut self, pseudoIdentifier: RareStringData) -> Self { self.pseudoIdentifier = Some(pseudoIdentifier); self }
872    /// Whether this DOM node responds to mouse clicks. This includes nodes that have had click
873    /// event listeners attached via JavaScript as well as anchor tags that naturally navigate when
874    /// clicked.
875    pub fn isClickable(mut self, isClickable: RareBooleanData) -> Self { self.isClickable = Some(isClickable); self }
876    /// The selected url for nodes with a srcset attribute.
877    pub fn currentSourceURL(mut self, currentSourceURL: RareStringData) -> Self { self.currentSourceURL = Some(currentSourceURL); self }
878    /// The url of the script (if any) that generates this node.
879    pub fn originURL(mut self, originURL: RareStringData) -> Self { self.originURL = Some(originURL); self }
880    pub fn build(self) -> NodeTreeSnapshot {
881        NodeTreeSnapshot {
882            parentIndex: self.parentIndex,
883            nodeType: self.nodeType,
884            shadowRootType: self.shadowRootType,
885            nodeName: self.nodeName,
886            nodeValue: self.nodeValue,
887            backendNodeId: self.backendNodeId,
888            attributes: self.attributes,
889            textValue: self.textValue,
890            inputValue: self.inputValue,
891            inputChecked: self.inputChecked,
892            optionSelected: self.optionSelected,
893            contentDocumentIndex: self.contentDocumentIndex,
894            pseudoType: self.pseudoType,
895            pseudoIdentifier: self.pseudoIdentifier,
896            isClickable: self.isClickable,
897            currentSourceURL: self.currentSourceURL,
898            originURL: self.originURL,
899        }
900    }
901}
902
903/// Table of details of an element in the DOM tree with a LayoutObject.
904
905#[derive(Debug, Clone, Serialize, Deserialize, Default)]
906#[serde(rename_all = "camelCase")]
907pub struct LayoutTreeSnapshot {
908    /// Index of the corresponding node in the 'NodeTreeSnapshot' array returned by 'captureSnapshot'.
909    nodeIndex: Vec<i64>,
910    /// Array of indexes specifying computed style strings, filtered according to the 'computedStyles' parameter passed to 'captureSnapshot'.
911    styles: Vec<ArrayOfStrings>,
912    /// The absolute position bounding box.
913    bounds: Vec<Rectangle>,
914    /// Contents of the LayoutText, if any.
915    text: Vec<StringIndex>,
916    /// Stacking context information.
917    stackingContexts: RareBooleanData,
918    /// Global paint order index, which is determined by the stacking order of the nodes. Nodes
919    /// that are painted together will have the same index. Only provided if includePaintOrder in
920    /// captureSnapshot was true.
921    #[serde(skip_serializing_if = "Option::is_none")]
922    paintOrders: Option<Vec<i64>>,
923    /// The offset rect of nodes. Only available when includeDOMRects is set to true
924    #[serde(skip_serializing_if = "Option::is_none")]
925    offsetRects: Option<Vec<Rectangle>>,
926    /// The scroll rect of nodes. Only available when includeDOMRects is set to true
927    #[serde(skip_serializing_if = "Option::is_none")]
928    scrollRects: Option<Vec<Rectangle>>,
929    /// The client rect of nodes. Only available when includeDOMRects is set to true
930    #[serde(skip_serializing_if = "Option::is_none")]
931    clientRects: Option<Vec<Rectangle>>,
932    /// The list of background colors that are blended with colors of overlapping elements.
933    #[serde(skip_serializing_if = "Option::is_none")]
934    blendedBackgroundColors: Option<Vec<StringIndex>>,
935    /// The list of computed text opacities.
936    #[serde(skip_serializing_if = "Option::is_none")]
937    textColorOpacities: Option<Vec<f64>>,
938}
939
940impl LayoutTreeSnapshot {
941    pub fn builder(nodeIndex: Vec<i64>, styles: Vec<ArrayOfStrings>, bounds: Vec<Rectangle>, text: Vec<StringIndex>, stackingContexts: RareBooleanData) -> LayoutTreeSnapshotBuilder {
942        LayoutTreeSnapshotBuilder {
943            nodeIndex: nodeIndex,
944            styles: styles,
945            bounds: bounds,
946            text: text,
947            stackingContexts: stackingContexts,
948            paintOrders: None,
949            offsetRects: None,
950            scrollRects: None,
951            clientRects: None,
952            blendedBackgroundColors: None,
953            textColorOpacities: None,
954        }
955    }
956    pub fn nodeIndex(&self) -> &[i64] { &self.nodeIndex }
957    pub fn styles(&self) -> &[ArrayOfStrings] { &self.styles }
958    pub fn bounds(&self) -> &[Rectangle] { &self.bounds }
959    pub fn text(&self) -> &[StringIndex] { &self.text }
960    pub fn stackingContexts(&self) -> &RareBooleanData { &self.stackingContexts }
961    pub fn paintOrders(&self) -> Option<&[i64]> { self.paintOrders.as_deref() }
962    pub fn offsetRects(&self) -> Option<&[Rectangle]> { self.offsetRects.as_deref() }
963    pub fn scrollRects(&self) -> Option<&[Rectangle]> { self.scrollRects.as_deref() }
964    pub fn clientRects(&self) -> Option<&[Rectangle]> { self.clientRects.as_deref() }
965    pub fn blendedBackgroundColors(&self) -> Option<&[StringIndex]> { self.blendedBackgroundColors.as_deref() }
966    pub fn textColorOpacities(&self) -> Option<&[f64]> { self.textColorOpacities.as_deref() }
967}
968
969
970pub struct LayoutTreeSnapshotBuilder {
971    nodeIndex: Vec<i64>,
972    styles: Vec<ArrayOfStrings>,
973    bounds: Vec<Rectangle>,
974    text: Vec<StringIndex>,
975    stackingContexts: RareBooleanData,
976    paintOrders: Option<Vec<i64>>,
977    offsetRects: Option<Vec<Rectangle>>,
978    scrollRects: Option<Vec<Rectangle>>,
979    clientRects: Option<Vec<Rectangle>>,
980    blendedBackgroundColors: Option<Vec<StringIndex>>,
981    textColorOpacities: Option<Vec<f64>>,
982}
983
984impl LayoutTreeSnapshotBuilder {
985    /// Global paint order index, which is determined by the stacking order of the nodes. Nodes
986    /// that are painted together will have the same index. Only provided if includePaintOrder in
987    /// captureSnapshot was true.
988    pub fn paintOrders(mut self, paintOrders: Vec<i64>) -> Self { self.paintOrders = Some(paintOrders); self }
989    /// The offset rect of nodes. Only available when includeDOMRects is set to true
990    pub fn offsetRects(mut self, offsetRects: Vec<Rectangle>) -> Self { self.offsetRects = Some(offsetRects); self }
991    /// The scroll rect of nodes. Only available when includeDOMRects is set to true
992    pub fn scrollRects(mut self, scrollRects: Vec<Rectangle>) -> Self { self.scrollRects = Some(scrollRects); self }
993    /// The client rect of nodes. Only available when includeDOMRects is set to true
994    pub fn clientRects(mut self, clientRects: Vec<Rectangle>) -> Self { self.clientRects = Some(clientRects); self }
995    /// The list of background colors that are blended with colors of overlapping elements.
996    pub fn blendedBackgroundColors(mut self, blendedBackgroundColors: Vec<StringIndex>) -> Self { self.blendedBackgroundColors = Some(blendedBackgroundColors); self }
997    /// The list of computed text opacities.
998    pub fn textColorOpacities(mut self, textColorOpacities: Vec<f64>) -> Self { self.textColorOpacities = Some(textColorOpacities); self }
999    pub fn build(self) -> LayoutTreeSnapshot {
1000        LayoutTreeSnapshot {
1001            nodeIndex: self.nodeIndex,
1002            styles: self.styles,
1003            bounds: self.bounds,
1004            text: self.text,
1005            stackingContexts: self.stackingContexts,
1006            paintOrders: self.paintOrders,
1007            offsetRects: self.offsetRects,
1008            scrollRects: self.scrollRects,
1009            clientRects: self.clientRects,
1010            blendedBackgroundColors: self.blendedBackgroundColors,
1011            textColorOpacities: self.textColorOpacities,
1012        }
1013    }
1014}
1015
1016/// Table of details of the post layout rendered text positions. The exact layout should not be regarded as
1017/// stable and may change between versions.
1018
1019#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1020#[serde(rename_all = "camelCase")]
1021pub struct TextBoxSnapshot {
1022    /// Index of the layout tree node that owns this box collection.
1023    layoutIndex: Vec<i64>,
1024    /// The absolute position bounding box.
1025    bounds: Vec<Rectangle>,
1026    /// The starting index in characters, for this post layout textbox substring. Characters that
1027    /// would be represented as a surrogate pair in UTF-16 have length 2.
1028    start: Vec<i64>,
1029    /// The number of characters in this post layout textbox substring. Characters that would be
1030    /// represented as a surrogate pair in UTF-16 have length 2.
1031    length: Vec<i64>,
1032}
1033
1034impl TextBoxSnapshot {
1035    pub fn builder(layoutIndex: Vec<i64>, bounds: Vec<Rectangle>, start: Vec<i64>, length: Vec<i64>) -> TextBoxSnapshotBuilder {
1036        TextBoxSnapshotBuilder {
1037            layoutIndex: layoutIndex,
1038            bounds: bounds,
1039            start: start,
1040            length: length,
1041        }
1042    }
1043    pub fn layoutIndex(&self) -> &[i64] { &self.layoutIndex }
1044    pub fn bounds(&self) -> &[Rectangle] { &self.bounds }
1045    pub fn start(&self) -> &[i64] { &self.start }
1046    pub fn length(&self) -> &[i64] { &self.length }
1047}
1048
1049
1050pub struct TextBoxSnapshotBuilder {
1051    layoutIndex: Vec<i64>,
1052    bounds: Vec<Rectangle>,
1053    start: Vec<i64>,
1054    length: Vec<i64>,
1055}
1056
1057impl TextBoxSnapshotBuilder {
1058    pub fn build(self) -> TextBoxSnapshot {
1059        TextBoxSnapshot {
1060            layoutIndex: self.layoutIndex,
1061            bounds: self.bounds,
1062            start: self.start,
1063            length: self.length,
1064        }
1065    }
1066}
1067
1068#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1069pub struct DisableParams {}
1070
1071impl DisableParams { pub const METHOD: &'static str = "DOMSnapshot.disable"; }
1072
1073impl<'a> crate::CdpCommand<'a> for DisableParams {
1074    const METHOD: &'static str = "DOMSnapshot.disable";
1075    type Response = crate::EmptyReturns;
1076}
1077
1078#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1079pub struct EnableParams {}
1080
1081impl EnableParams { pub const METHOD: &'static str = "DOMSnapshot.enable"; }
1082
1083impl<'a> crate::CdpCommand<'a> for EnableParams {
1084    const METHOD: &'static str = "DOMSnapshot.enable";
1085    type Response = crate::EmptyReturns;
1086}
1087
1088/// Returns a document snapshot, including the full DOM tree of the root node (including iframes,
1089/// template contents, and imported documents) in a flattened array, as well as layout and
1090/// white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
1091/// flattened.
1092
1093#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1094#[serde(rename_all = "camelCase")]
1095pub struct GetSnapshotParams<'a> {
1096    /// Whitelist of computed styles to return.
1097    computedStyleWhitelist: Vec<Cow<'a, str>>,
1098    /// Whether or not to retrieve details of DOM listeners (default false).
1099    #[serde(skip_serializing_if = "Option::is_none")]
1100    includeEventListeners: Option<bool>,
1101    /// Whether to determine and include the paint order index of LayoutTreeNodes (default false).
1102    #[serde(skip_serializing_if = "Option::is_none")]
1103    includePaintOrder: Option<bool>,
1104    /// Whether to include UA shadow tree in the snapshot (default false).
1105    #[serde(skip_serializing_if = "Option::is_none")]
1106    includeUserAgentShadowTree: Option<bool>,
1107}
1108
1109impl<'a> GetSnapshotParams<'a> {
1110    pub fn builder(computedStyleWhitelist: Vec<Cow<'a, str>>) -> GetSnapshotParamsBuilder<'a> {
1111        GetSnapshotParamsBuilder {
1112            computedStyleWhitelist: computedStyleWhitelist,
1113            includeEventListeners: None,
1114            includePaintOrder: None,
1115            includeUserAgentShadowTree: None,
1116        }
1117    }
1118    pub fn computedStyleWhitelist(&self) -> &[Cow<'a, str>] { &self.computedStyleWhitelist }
1119    pub fn includeEventListeners(&self) -> Option<bool> { self.includeEventListeners }
1120    pub fn includePaintOrder(&self) -> Option<bool> { self.includePaintOrder }
1121    pub fn includeUserAgentShadowTree(&self) -> Option<bool> { self.includeUserAgentShadowTree }
1122}
1123
1124
1125pub struct GetSnapshotParamsBuilder<'a> {
1126    computedStyleWhitelist: Vec<Cow<'a, str>>,
1127    includeEventListeners: Option<bool>,
1128    includePaintOrder: Option<bool>,
1129    includeUserAgentShadowTree: Option<bool>,
1130}
1131
1132impl<'a> GetSnapshotParamsBuilder<'a> {
1133    /// Whether or not to retrieve details of DOM listeners (default false).
1134    pub fn includeEventListeners(mut self, includeEventListeners: bool) -> Self { self.includeEventListeners = Some(includeEventListeners); self }
1135    /// Whether to determine and include the paint order index of LayoutTreeNodes (default false).
1136    pub fn includePaintOrder(mut self, includePaintOrder: bool) -> Self { self.includePaintOrder = Some(includePaintOrder); self }
1137    /// Whether to include UA shadow tree in the snapshot (default false).
1138    pub fn includeUserAgentShadowTree(mut self, includeUserAgentShadowTree: bool) -> Self { self.includeUserAgentShadowTree = Some(includeUserAgentShadowTree); self }
1139    pub fn build(self) -> GetSnapshotParams<'a> {
1140        GetSnapshotParams {
1141            computedStyleWhitelist: self.computedStyleWhitelist,
1142            includeEventListeners: self.includeEventListeners,
1143            includePaintOrder: self.includePaintOrder,
1144            includeUserAgentShadowTree: self.includeUserAgentShadowTree,
1145        }
1146    }
1147}
1148
1149/// Returns a document snapshot, including the full DOM tree of the root node (including iframes,
1150/// template contents, and imported documents) in a flattened array, as well as layout and
1151/// white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
1152/// flattened.
1153
1154#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1155#[serde(rename_all = "camelCase")]
1156pub struct GetSnapshotReturns<'a> {
1157    /// The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
1158    domNodes: Vec<DOMNode<'a>>,
1159    /// The nodes in the layout tree.
1160    layoutTreeNodes: Vec<LayoutTreeNode<'a>>,
1161    /// Whitelisted ComputedStyle properties for each node in the layout tree.
1162    computedStyles: Vec<ComputedStyle<'a>>,
1163}
1164
1165impl<'a> GetSnapshotReturns<'a> {
1166    pub fn builder(domNodes: Vec<DOMNode<'a>>, layoutTreeNodes: Vec<LayoutTreeNode<'a>>, computedStyles: Vec<ComputedStyle<'a>>) -> GetSnapshotReturnsBuilder<'a> {
1167        GetSnapshotReturnsBuilder {
1168            domNodes: domNodes,
1169            layoutTreeNodes: layoutTreeNodes,
1170            computedStyles: computedStyles,
1171        }
1172    }
1173    pub fn domNodes(&self) -> &[DOMNode<'a>] { &self.domNodes }
1174    pub fn layoutTreeNodes(&self) -> &[LayoutTreeNode<'a>] { &self.layoutTreeNodes }
1175    pub fn computedStyles(&self) -> &[ComputedStyle<'a>] { &self.computedStyles }
1176}
1177
1178
1179pub struct GetSnapshotReturnsBuilder<'a> {
1180    domNodes: Vec<DOMNode<'a>>,
1181    layoutTreeNodes: Vec<LayoutTreeNode<'a>>,
1182    computedStyles: Vec<ComputedStyle<'a>>,
1183}
1184
1185impl<'a> GetSnapshotReturnsBuilder<'a> {
1186    pub fn build(self) -> GetSnapshotReturns<'a> {
1187        GetSnapshotReturns {
1188            domNodes: self.domNodes,
1189            layoutTreeNodes: self.layoutTreeNodes,
1190            computedStyles: self.computedStyles,
1191        }
1192    }
1193}
1194
1195impl<'a> GetSnapshotParams<'a> { pub const METHOD: &'static str = "DOMSnapshot.getSnapshot"; }
1196
1197impl<'a> crate::CdpCommand<'a> for GetSnapshotParams<'a> {
1198    const METHOD: &'static str = "DOMSnapshot.getSnapshot";
1199    type Response = GetSnapshotReturns<'a>;
1200}
1201
1202/// Returns a document snapshot, including the full DOM tree of the root node (including iframes,
1203/// template contents, and imported documents) in a flattened array, as well as layout and
1204/// white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
1205/// flattened.
1206
1207#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1208#[serde(rename_all = "camelCase")]
1209pub struct CaptureSnapshotParams<'a> {
1210    /// Whitelist of computed styles to return.
1211    computedStyles: Vec<Cow<'a, str>>,
1212    /// Whether to include layout object paint orders into the snapshot.
1213    #[serde(skip_serializing_if = "Option::is_none")]
1214    includePaintOrder: Option<bool>,
1215    /// Whether to include DOM rectangles (offsetRects, clientRects, scrollRects) into the snapshot
1216    #[serde(skip_serializing_if = "Option::is_none")]
1217    includeDOMRects: Option<bool>,
1218    /// Whether to include blended background colors in the snapshot (default: false).
1219    /// Blended background color is achieved by blending background colors of all elements
1220    /// that overlap with the current element.
1221    #[serde(skip_serializing_if = "Option::is_none")]
1222    includeBlendedBackgroundColors: Option<bool>,
1223    /// Whether to include text color opacity in the snapshot (default: false).
1224    /// An element might have the opacity property set that affects the text color of the element.
1225    /// The final text color opacity is computed based on the opacity of all overlapping elements.
1226    #[serde(skip_serializing_if = "Option::is_none")]
1227    includeTextColorOpacities: Option<bool>,
1228}
1229
1230impl<'a> CaptureSnapshotParams<'a> {
1231    pub fn builder(computedStyles: Vec<Cow<'a, str>>) -> CaptureSnapshotParamsBuilder<'a> {
1232        CaptureSnapshotParamsBuilder {
1233            computedStyles: computedStyles,
1234            includePaintOrder: None,
1235            includeDOMRects: None,
1236            includeBlendedBackgroundColors: None,
1237            includeTextColorOpacities: None,
1238        }
1239    }
1240    pub fn computedStyles(&self) -> &[Cow<'a, str>] { &self.computedStyles }
1241    pub fn includePaintOrder(&self) -> Option<bool> { self.includePaintOrder }
1242    pub fn includeDOMRects(&self) -> Option<bool> { self.includeDOMRects }
1243    pub fn includeBlendedBackgroundColors(&self) -> Option<bool> { self.includeBlendedBackgroundColors }
1244    pub fn includeTextColorOpacities(&self) -> Option<bool> { self.includeTextColorOpacities }
1245}
1246
1247
1248pub struct CaptureSnapshotParamsBuilder<'a> {
1249    computedStyles: Vec<Cow<'a, str>>,
1250    includePaintOrder: Option<bool>,
1251    includeDOMRects: Option<bool>,
1252    includeBlendedBackgroundColors: Option<bool>,
1253    includeTextColorOpacities: Option<bool>,
1254}
1255
1256impl<'a> CaptureSnapshotParamsBuilder<'a> {
1257    /// Whether to include layout object paint orders into the snapshot.
1258    pub fn includePaintOrder(mut self, includePaintOrder: bool) -> Self { self.includePaintOrder = Some(includePaintOrder); self }
1259    /// Whether to include DOM rectangles (offsetRects, clientRects, scrollRects) into the snapshot
1260    pub fn includeDOMRects(mut self, includeDOMRects: bool) -> Self { self.includeDOMRects = Some(includeDOMRects); self }
1261    /// Whether to include blended background colors in the snapshot (default: false).
1262    /// Blended background color is achieved by blending background colors of all elements
1263    /// that overlap with the current element.
1264    pub fn includeBlendedBackgroundColors(mut self, includeBlendedBackgroundColors: bool) -> Self { self.includeBlendedBackgroundColors = Some(includeBlendedBackgroundColors); self }
1265    /// Whether to include text color opacity in the snapshot (default: false).
1266    /// An element might have the opacity property set that affects the text color of the element.
1267    /// The final text color opacity is computed based on the opacity of all overlapping elements.
1268    pub fn includeTextColorOpacities(mut self, includeTextColorOpacities: bool) -> Self { self.includeTextColorOpacities = Some(includeTextColorOpacities); self }
1269    pub fn build(self) -> CaptureSnapshotParams<'a> {
1270        CaptureSnapshotParams {
1271            computedStyles: self.computedStyles,
1272            includePaintOrder: self.includePaintOrder,
1273            includeDOMRects: self.includeDOMRects,
1274            includeBlendedBackgroundColors: self.includeBlendedBackgroundColors,
1275            includeTextColorOpacities: self.includeTextColorOpacities,
1276        }
1277    }
1278}
1279
1280/// Returns a document snapshot, including the full DOM tree of the root node (including iframes,
1281/// template contents, and imported documents) in a flattened array, as well as layout and
1282/// white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
1283/// flattened.
1284
1285#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1286#[serde(rename_all = "camelCase")]
1287pub struct CaptureSnapshotReturns<'a> {
1288    /// The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
1289    documents: Vec<DocumentSnapshot>,
1290    /// Shared string table that all string properties refer to with indexes.
1291    strings: Vec<Cow<'a, str>>,
1292}
1293
1294impl<'a> CaptureSnapshotReturns<'a> {
1295    pub fn builder(documents: Vec<DocumentSnapshot>, strings: Vec<Cow<'a, str>>) -> CaptureSnapshotReturnsBuilder<'a> {
1296        CaptureSnapshotReturnsBuilder {
1297            documents: documents,
1298            strings: strings,
1299        }
1300    }
1301    pub fn documents(&self) -> &[DocumentSnapshot] { &self.documents }
1302    pub fn strings(&self) -> &[Cow<'a, str>] { &self.strings }
1303}
1304
1305
1306pub struct CaptureSnapshotReturnsBuilder<'a> {
1307    documents: Vec<DocumentSnapshot>,
1308    strings: Vec<Cow<'a, str>>,
1309}
1310
1311impl<'a> CaptureSnapshotReturnsBuilder<'a> {
1312    pub fn build(self) -> CaptureSnapshotReturns<'a> {
1313        CaptureSnapshotReturns {
1314            documents: self.documents,
1315            strings: self.strings,
1316        }
1317    }
1318}
1319
1320impl<'a> CaptureSnapshotParams<'a> { pub const METHOD: &'static str = "DOMSnapshot.captureSnapshot"; }
1321
1322impl<'a> crate::CdpCommand<'a> for CaptureSnapshotParams<'a> {
1323    const METHOD: &'static str = "DOMSnapshot.captureSnapshot";
1324    type Response = CaptureSnapshotReturns<'a>;
1325}