Skip to main content

browser_protocol/layertree/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3use std::borrow::Cow;
4
5/// Unique Layer identifier.
6
7pub type LayerId<'a> = Cow<'a, str>;
8
9/// Unique snapshot identifier.
10
11pub type SnapshotId<'a> = Cow<'a, str>;
12
13/// Rectangle where scrolling happens on the main thread.
14
15#[derive(Debug, Clone, Serialize, Deserialize, Default)]
16#[serde(rename_all = "camelCase")]
17pub struct ScrollRect<'a> {
18    /// Rectangle itself.
19    rect: crate::dom::Rect,
20    /// Reason for rectangle to force scrolling on the main thread
21    #[serde(rename = "type")]
22    type_: Cow<'a, str>,
23}
24
25impl<'a> ScrollRect<'a> {
26    /// Creates a builder for this type with the required parameters:
27    /// * `rect`: Rectangle itself.
28    /// * `type_`: Reason for rectangle to force scrolling on the main thread
29    pub fn builder(rect: crate::dom::Rect, type_: impl Into<Cow<'a, str>>) -> ScrollRectBuilder<'a> {
30        ScrollRectBuilder {
31            rect: rect,
32            type_: type_.into(),
33        }
34    }
35    /// Rectangle itself.
36    pub fn rect(&self) -> &crate::dom::Rect { &self.rect }
37    /// Reason for rectangle to force scrolling on the main thread
38    pub fn type_(&self) -> &str { self.type_.as_ref() }
39}
40
41
42pub struct ScrollRectBuilder<'a> {
43    rect: crate::dom::Rect,
44    type_: Cow<'a, str>,
45}
46
47impl<'a> ScrollRectBuilder<'a> {
48    pub fn build(self) -> ScrollRect<'a> {
49        ScrollRect {
50            rect: self.rect,
51            type_: self.type_,
52        }
53    }
54}
55
56/// Sticky position constraints.
57
58#[derive(Debug, Clone, Serialize, Deserialize, Default)]
59#[serde(rename_all = "camelCase")]
60pub struct StickyPositionConstraint<'a> {
61    /// Layout rectangle of the sticky element before being shifted
62    #[serde(rename = "stickyBoxRect")]
63    sticky_box_rect: crate::dom::Rect,
64    /// Layout rectangle of the containing block of the sticky element
65    #[serde(rename = "containingBlockRect")]
66    containing_block_rect: crate::dom::Rect,
67    /// The nearest sticky layer that shifts the sticky box
68    #[serde(skip_serializing_if = "Option::is_none", rename = "nearestLayerShiftingStickyBox")]
69    nearest_layer_shifting_sticky_box: Option<LayerId<'a>>,
70    /// The nearest sticky layer that shifts the containing block
71    #[serde(skip_serializing_if = "Option::is_none", rename = "nearestLayerShiftingContainingBlock")]
72    nearest_layer_shifting_containing_block: Option<LayerId<'a>>,
73}
74
75impl<'a> StickyPositionConstraint<'a> {
76    /// Creates a builder for this type with the required parameters:
77    /// * `sticky_box_rect`: Layout rectangle of the sticky element before being shifted
78    /// * `containing_block_rect`: Layout rectangle of the containing block of the sticky element
79    pub fn builder(sticky_box_rect: crate::dom::Rect, containing_block_rect: crate::dom::Rect) -> StickyPositionConstraintBuilder<'a> {
80        StickyPositionConstraintBuilder {
81            sticky_box_rect: sticky_box_rect,
82            containing_block_rect: containing_block_rect,
83            nearest_layer_shifting_sticky_box: None,
84            nearest_layer_shifting_containing_block: None,
85        }
86    }
87    /// Layout rectangle of the sticky element before being shifted
88    pub fn sticky_box_rect(&self) -> &crate::dom::Rect { &self.sticky_box_rect }
89    /// Layout rectangle of the containing block of the sticky element
90    pub fn containing_block_rect(&self) -> &crate::dom::Rect { &self.containing_block_rect }
91    /// The nearest sticky layer that shifts the sticky box
92    pub fn nearest_layer_shifting_sticky_box(&self) -> Option<&LayerId<'a>> { self.nearest_layer_shifting_sticky_box.as_ref() }
93    /// The nearest sticky layer that shifts the containing block
94    pub fn nearest_layer_shifting_containing_block(&self) -> Option<&LayerId<'a>> { self.nearest_layer_shifting_containing_block.as_ref() }
95}
96
97
98pub struct StickyPositionConstraintBuilder<'a> {
99    sticky_box_rect: crate::dom::Rect,
100    containing_block_rect: crate::dom::Rect,
101    nearest_layer_shifting_sticky_box: Option<LayerId<'a>>,
102    nearest_layer_shifting_containing_block: Option<LayerId<'a>>,
103}
104
105impl<'a> StickyPositionConstraintBuilder<'a> {
106    /// The nearest sticky layer that shifts the sticky box
107    pub fn nearest_layer_shifting_sticky_box(mut self, nearest_layer_shifting_sticky_box: impl Into<LayerId<'a>>) -> Self { self.nearest_layer_shifting_sticky_box = Some(nearest_layer_shifting_sticky_box.into()); self }
108    /// The nearest sticky layer that shifts the containing block
109    pub fn nearest_layer_shifting_containing_block(mut self, nearest_layer_shifting_containing_block: impl Into<LayerId<'a>>) -> Self { self.nearest_layer_shifting_containing_block = Some(nearest_layer_shifting_containing_block.into()); self }
110    pub fn build(self) -> StickyPositionConstraint<'a> {
111        StickyPositionConstraint {
112            sticky_box_rect: self.sticky_box_rect,
113            containing_block_rect: self.containing_block_rect,
114            nearest_layer_shifting_sticky_box: self.nearest_layer_shifting_sticky_box,
115            nearest_layer_shifting_containing_block: self.nearest_layer_shifting_containing_block,
116        }
117    }
118}
119
120/// Serialized fragment of layer picture along with its offset within the layer.
121
122#[derive(Debug, Clone, Serialize, Deserialize, Default)]
123#[serde(rename_all = "camelCase")]
124pub struct PictureTile<'a> {
125    /// Offset from owning layer left boundary
126    x: f64,
127    /// Offset from owning layer top boundary
128    y: f64,
129    /// Base64-encoded snapshot data. (Encoded as a base64 string when passed over JSON)
130    picture: Cow<'a, str>,
131}
132
133impl<'a> PictureTile<'a> {
134    /// Creates a builder for this type with the required parameters:
135    /// * `x`: Offset from owning layer left boundary
136    /// * `y`: Offset from owning layer top boundary
137    /// * `picture`: Base64-encoded snapshot data. (Encoded as a base64 string when passed over JSON)
138    pub fn builder(x: f64, y: f64, picture: impl Into<Cow<'a, str>>) -> PictureTileBuilder<'a> {
139        PictureTileBuilder {
140            x: x,
141            y: y,
142            picture: picture.into(),
143        }
144    }
145    /// Offset from owning layer left boundary
146    pub fn x(&self) -> f64 { self.x }
147    /// Offset from owning layer top boundary
148    pub fn y(&self) -> f64 { self.y }
149    /// Base64-encoded snapshot data. (Encoded as a base64 string when passed over JSON)
150    pub fn picture(&self) -> &str { self.picture.as_ref() }
151}
152
153
154pub struct PictureTileBuilder<'a> {
155    x: f64,
156    y: f64,
157    picture: Cow<'a, str>,
158}
159
160impl<'a> PictureTileBuilder<'a> {
161    pub fn build(self) -> PictureTile<'a> {
162        PictureTile {
163            x: self.x,
164            y: self.y,
165            picture: self.picture,
166        }
167    }
168}
169
170/// Information about a compositing layer.
171
172#[derive(Debug, Clone, Serialize, Deserialize, Default)]
173#[serde(rename_all = "camelCase")]
174pub struct Layer<'a> {
175    /// The unique id for this layer.
176    #[serde(rename = "layerId")]
177    layer_id: LayerId<'a>,
178    /// The id of parent (not present for root).
179    #[serde(skip_serializing_if = "Option::is_none", rename = "parentLayerId")]
180    parent_layer_id: Option<LayerId<'a>>,
181    /// The backend id for the node associated with this layer.
182    #[serde(skip_serializing_if = "Option::is_none", rename = "backendNodeId")]
183    backend_node_id: Option<crate::dom::BackendNodeId>,
184    /// Offset from parent layer, X coordinate.
185    #[serde(rename = "offsetX")]
186    offset_x: f64,
187    /// Offset from parent layer, Y coordinate.
188    #[serde(rename = "offsetY")]
189    offset_y: f64,
190    /// Layer width.
191    width: f64,
192    /// Layer height.
193    height: f64,
194    /// Transformation matrix for layer, default is identity matrix
195    #[serde(skip_serializing_if = "Option::is_none")]
196    transform: Option<Vec<f64>>,
197    /// Transform anchor point X, absent if no transform specified
198    #[serde(skip_serializing_if = "Option::is_none", rename = "anchorX")]
199    anchor_x: Option<f64>,
200    /// Transform anchor point Y, absent if no transform specified
201    #[serde(skip_serializing_if = "Option::is_none", rename = "anchorY")]
202    anchor_y: Option<f64>,
203    /// Transform anchor point Z, absent if no transform specified
204    #[serde(skip_serializing_if = "Option::is_none", rename = "anchorZ")]
205    anchor_z: Option<f64>,
206    /// Indicates how many time this layer has painted.
207    #[serde(rename = "paintCount")]
208    paint_count: u64,
209    /// Indicates whether this layer hosts any content, rather than being used for
210    /// transform/scrolling purposes only.
211    #[serde(rename = "drawsContent")]
212    draws_content: bool,
213    /// Set if layer is not visible.
214    #[serde(skip_serializing_if = "Option::is_none")]
215    invisible: Option<bool>,
216    /// Rectangles scrolling on main thread only.
217    #[serde(skip_serializing_if = "Option::is_none", rename = "scrollRects")]
218    scroll_rects: Option<Vec<ScrollRect<'a>>>,
219    /// Sticky position constraint information
220    #[serde(skip_serializing_if = "Option::is_none", rename = "stickyPositionConstraint")]
221    sticky_position_constraint: Option<StickyPositionConstraint<'a>>,
222}
223
224impl<'a> Layer<'a> {
225    /// Creates a builder for this type with the required parameters:
226    /// * `layer_id`: The unique id for this layer.
227    /// * `offset_x`: Offset from parent layer, X coordinate.
228    /// * `offset_y`: Offset from parent layer, Y coordinate.
229    /// * `width`: Layer width.
230    /// * `height`: Layer height.
231    /// * `paint_count`: Indicates how many time this layer has painted.
232    /// * `draws_content`: Indicates whether this layer hosts any content, rather than being used for transform/scrolling purposes only.
233    pub fn builder(layer_id: impl Into<LayerId<'a>>, offset_x: f64, offset_y: f64, width: f64, height: f64, paint_count: u64, draws_content: bool) -> LayerBuilder<'a> {
234        LayerBuilder {
235            layer_id: layer_id.into(),
236            parent_layer_id: None,
237            backend_node_id: None,
238            offset_x: offset_x,
239            offset_y: offset_y,
240            width: width,
241            height: height,
242            transform: None,
243            anchor_x: None,
244            anchor_y: None,
245            anchor_z: None,
246            paint_count: paint_count,
247            draws_content: draws_content,
248            invisible: None,
249            scroll_rects: None,
250            sticky_position_constraint: None,
251        }
252    }
253    /// The unique id for this layer.
254    pub fn layer_id(&self) -> &LayerId<'a> { &self.layer_id }
255    /// The id of parent (not present for root).
256    pub fn parent_layer_id(&self) -> Option<&LayerId<'a>> { self.parent_layer_id.as_ref() }
257    /// The backend id for the node associated with this layer.
258    pub fn backend_node_id(&self) -> Option<&crate::dom::BackendNodeId> { self.backend_node_id.as_ref() }
259    /// Offset from parent layer, X coordinate.
260    pub fn offset_x(&self) -> f64 { self.offset_x }
261    /// Offset from parent layer, Y coordinate.
262    pub fn offset_y(&self) -> f64 { self.offset_y }
263    /// Layer width.
264    pub fn width(&self) -> f64 { self.width }
265    /// Layer height.
266    pub fn height(&self) -> f64 { self.height }
267    /// Transformation matrix for layer, default is identity matrix
268    pub fn transform(&self) -> Option<&[f64]> { self.transform.as_deref() }
269    /// Transform anchor point X, absent if no transform specified
270    pub fn anchor_x(&self) -> Option<f64> { self.anchor_x }
271    /// Transform anchor point Y, absent if no transform specified
272    pub fn anchor_y(&self) -> Option<f64> { self.anchor_y }
273    /// Transform anchor point Z, absent if no transform specified
274    pub fn anchor_z(&self) -> Option<f64> { self.anchor_z }
275    /// Indicates how many time this layer has painted.
276    pub fn paint_count(&self) -> u64 { self.paint_count }
277    /// Indicates whether this layer hosts any content, rather than being used for
278    /// transform/scrolling purposes only.
279    pub fn draws_content(&self) -> bool { self.draws_content }
280    /// Set if layer is not visible.
281    pub fn invisible(&self) -> Option<bool> { self.invisible }
282    /// Rectangles scrolling on main thread only.
283    pub fn scroll_rects(&self) -> Option<&[ScrollRect<'a>]> { self.scroll_rects.as_deref() }
284    /// Sticky position constraint information
285    pub fn sticky_position_constraint(&self) -> Option<&StickyPositionConstraint<'a>> { self.sticky_position_constraint.as_ref() }
286}
287
288
289pub struct LayerBuilder<'a> {
290    layer_id: LayerId<'a>,
291    parent_layer_id: Option<LayerId<'a>>,
292    backend_node_id: Option<crate::dom::BackendNodeId>,
293    offset_x: f64,
294    offset_y: f64,
295    width: f64,
296    height: f64,
297    transform: Option<Vec<f64>>,
298    anchor_x: Option<f64>,
299    anchor_y: Option<f64>,
300    anchor_z: Option<f64>,
301    paint_count: u64,
302    draws_content: bool,
303    invisible: Option<bool>,
304    scroll_rects: Option<Vec<ScrollRect<'a>>>,
305    sticky_position_constraint: Option<StickyPositionConstraint<'a>>,
306}
307
308impl<'a> LayerBuilder<'a> {
309    /// The id of parent (not present for root).
310    pub fn parent_layer_id(mut self, parent_layer_id: impl Into<LayerId<'a>>) -> Self { self.parent_layer_id = Some(parent_layer_id.into()); self }
311    /// The backend id for the node associated with this layer.
312    pub fn backend_node_id(mut self, backend_node_id: crate::dom::BackendNodeId) -> Self { self.backend_node_id = Some(backend_node_id); self }
313    /// Transformation matrix for layer, default is identity matrix
314    pub fn transform(mut self, transform: Vec<f64>) -> Self { self.transform = Some(transform); self }
315    /// Transform anchor point X, absent if no transform specified
316    pub fn anchor_x(mut self, anchor_x: f64) -> Self { self.anchor_x = Some(anchor_x); self }
317    /// Transform anchor point Y, absent if no transform specified
318    pub fn anchor_y(mut self, anchor_y: f64) -> Self { self.anchor_y = Some(anchor_y); self }
319    /// Transform anchor point Z, absent if no transform specified
320    pub fn anchor_z(mut self, anchor_z: f64) -> Self { self.anchor_z = Some(anchor_z); self }
321    /// Set if layer is not visible.
322    pub fn invisible(mut self, invisible: bool) -> Self { self.invisible = Some(invisible); self }
323    /// Rectangles scrolling on main thread only.
324    pub fn scroll_rects(mut self, scroll_rects: Vec<ScrollRect<'a>>) -> Self { self.scroll_rects = Some(scroll_rects); self }
325    /// Sticky position constraint information
326    pub fn sticky_position_constraint(mut self, sticky_position_constraint: StickyPositionConstraint<'a>) -> Self { self.sticky_position_constraint = Some(sticky_position_constraint); self }
327    pub fn build(self) -> Layer<'a> {
328        Layer {
329            layer_id: self.layer_id,
330            parent_layer_id: self.parent_layer_id,
331            backend_node_id: self.backend_node_id,
332            offset_x: self.offset_x,
333            offset_y: self.offset_y,
334            width: self.width,
335            height: self.height,
336            transform: self.transform,
337            anchor_x: self.anchor_x,
338            anchor_y: self.anchor_y,
339            anchor_z: self.anchor_z,
340            paint_count: self.paint_count,
341            draws_content: self.draws_content,
342            invisible: self.invisible,
343            scroll_rects: self.scroll_rects,
344            sticky_position_constraint: self.sticky_position_constraint,
345        }
346    }
347}
348
349/// Array of timings, one per paint step.
350
351pub type PaintProfile = Vec<f64>;
352
353/// Provides the reasons why the given layer was composited.
354
355#[derive(Debug, Clone, Serialize, Deserialize, Default)]
356#[serde(rename_all = "camelCase")]
357pub struct CompositingReasonsParams<'a> {
358    /// The id of the layer for which we want to get the reasons it was composited.
359    #[serde(rename = "layerId")]
360    layer_id: LayerId<'a>,
361}
362
363impl<'a> CompositingReasonsParams<'a> {
364    /// Creates a builder for this type with the required parameters:
365    /// * `layer_id`: The id of the layer for which we want to get the reasons it was composited.
366    pub fn builder(layer_id: impl Into<LayerId<'a>>) -> CompositingReasonsParamsBuilder<'a> {
367        CompositingReasonsParamsBuilder {
368            layer_id: layer_id.into(),
369        }
370    }
371    /// The id of the layer for which we want to get the reasons it was composited.
372    pub fn layer_id(&self) -> &LayerId<'a> { &self.layer_id }
373}
374
375
376pub struct CompositingReasonsParamsBuilder<'a> {
377    layer_id: LayerId<'a>,
378}
379
380impl<'a> CompositingReasonsParamsBuilder<'a> {
381    pub fn build(self) -> CompositingReasonsParams<'a> {
382        CompositingReasonsParams {
383            layer_id: self.layer_id,
384        }
385    }
386}
387
388/// Provides the reasons why the given layer was composited.
389
390#[derive(Debug, Clone, Serialize, Deserialize, Default)]
391#[serde(rename_all = "camelCase")]
392pub struct CompositingReasonsReturns<'a> {
393    /// A list of strings specifying reasons for the given layer to become composited.
394    #[serde(rename = "compositingReasons")]
395    compositing_reasons: Vec<Cow<'a, str>>,
396    /// A list of strings specifying reason IDs for the given layer to become composited.
397    #[serde(rename = "compositingReasonIds")]
398    compositing_reason_ids: Vec<Cow<'a, str>>,
399}
400
401impl<'a> CompositingReasonsReturns<'a> {
402    /// Creates a builder for this type with the required parameters:
403    /// * `compositing_reasons`: A list of strings specifying reasons for the given layer to become composited.
404    /// * `compositing_reason_ids`: A list of strings specifying reason IDs for the given layer to become composited.
405    pub fn builder(compositing_reasons: Vec<Cow<'a, str>>, compositing_reason_ids: Vec<Cow<'a, str>>) -> CompositingReasonsReturnsBuilder<'a> {
406        CompositingReasonsReturnsBuilder {
407            compositing_reasons: compositing_reasons,
408            compositing_reason_ids: compositing_reason_ids,
409        }
410    }
411    /// A list of strings specifying reasons for the given layer to become composited.
412    pub fn compositing_reasons(&self) -> &[Cow<'a, str>] { &self.compositing_reasons }
413    /// A list of strings specifying reason IDs for the given layer to become composited.
414    pub fn compositing_reason_ids(&self) -> &[Cow<'a, str>] { &self.compositing_reason_ids }
415}
416
417
418pub struct CompositingReasonsReturnsBuilder<'a> {
419    compositing_reasons: Vec<Cow<'a, str>>,
420    compositing_reason_ids: Vec<Cow<'a, str>>,
421}
422
423impl<'a> CompositingReasonsReturnsBuilder<'a> {
424    pub fn build(self) -> CompositingReasonsReturns<'a> {
425        CompositingReasonsReturns {
426            compositing_reasons: self.compositing_reasons,
427            compositing_reason_ids: self.compositing_reason_ids,
428        }
429    }
430}
431
432impl<'a> CompositingReasonsParams<'a> { pub const METHOD: &'static str = "LayerTree.compositingReasons"; }
433
434impl<'a> crate::CdpCommand<'a> for CompositingReasonsParams<'a> {
435    const METHOD: &'static str = "LayerTree.compositingReasons";
436    type Response = CompositingReasonsReturns<'a>;
437}
438
439#[derive(Debug, Clone, Serialize, Deserialize, Default)]
440pub struct DisableParams {}
441
442impl DisableParams { pub const METHOD: &'static str = "LayerTree.disable"; }
443
444impl<'a> crate::CdpCommand<'a> for DisableParams {
445    const METHOD: &'static str = "LayerTree.disable";
446    type Response = crate::EmptyReturns;
447}
448
449#[derive(Debug, Clone, Serialize, Deserialize, Default)]
450pub struct EnableParams {}
451
452impl EnableParams { pub const METHOD: &'static str = "LayerTree.enable"; }
453
454impl<'a> crate::CdpCommand<'a> for EnableParams {
455    const METHOD: &'static str = "LayerTree.enable";
456    type Response = crate::EmptyReturns;
457}
458
459/// Returns the snapshot identifier.
460
461#[derive(Debug, Clone, Serialize, Deserialize, Default)]
462#[serde(rename_all = "camelCase")]
463pub struct LoadSnapshotParams<'a> {
464    /// An array of tiles composing the snapshot.
465    tiles: Vec<PictureTile<'a>>,
466}
467
468impl<'a> LoadSnapshotParams<'a> {
469    /// Creates a builder for this type with the required parameters:
470    /// * `tiles`: An array of tiles composing the snapshot.
471    pub fn builder(tiles: Vec<PictureTile<'a>>) -> LoadSnapshotParamsBuilder<'a> {
472        LoadSnapshotParamsBuilder {
473            tiles: tiles,
474        }
475    }
476    /// An array of tiles composing the snapshot.
477    pub fn tiles(&self) -> &[PictureTile<'a>] { &self.tiles }
478}
479
480
481pub struct LoadSnapshotParamsBuilder<'a> {
482    tiles: Vec<PictureTile<'a>>,
483}
484
485impl<'a> LoadSnapshotParamsBuilder<'a> {
486    pub fn build(self) -> LoadSnapshotParams<'a> {
487        LoadSnapshotParams {
488            tiles: self.tiles,
489        }
490    }
491}
492
493/// Returns the snapshot identifier.
494
495#[derive(Debug, Clone, Serialize, Deserialize, Default)]
496#[serde(rename_all = "camelCase")]
497pub struct LoadSnapshotReturns<'a> {
498    /// The id of the snapshot.
499    #[serde(rename = "snapshotId")]
500    snapshot_id: SnapshotId<'a>,
501}
502
503impl<'a> LoadSnapshotReturns<'a> {
504    /// Creates a builder for this type with the required parameters:
505    /// * `snapshot_id`: The id of the snapshot.
506    pub fn builder(snapshot_id: impl Into<SnapshotId<'a>>) -> LoadSnapshotReturnsBuilder<'a> {
507        LoadSnapshotReturnsBuilder {
508            snapshot_id: snapshot_id.into(),
509        }
510    }
511    /// The id of the snapshot.
512    pub fn snapshot_id(&self) -> &SnapshotId<'a> { &self.snapshot_id }
513}
514
515
516pub struct LoadSnapshotReturnsBuilder<'a> {
517    snapshot_id: SnapshotId<'a>,
518}
519
520impl<'a> LoadSnapshotReturnsBuilder<'a> {
521    pub fn build(self) -> LoadSnapshotReturns<'a> {
522        LoadSnapshotReturns {
523            snapshot_id: self.snapshot_id,
524        }
525    }
526}
527
528impl<'a> LoadSnapshotParams<'a> { pub const METHOD: &'static str = "LayerTree.loadSnapshot"; }
529
530impl<'a> crate::CdpCommand<'a> for LoadSnapshotParams<'a> {
531    const METHOD: &'static str = "LayerTree.loadSnapshot";
532    type Response = LoadSnapshotReturns<'a>;
533}
534
535/// Returns the layer snapshot identifier.
536
537#[derive(Debug, Clone, Serialize, Deserialize, Default)]
538#[serde(rename_all = "camelCase")]
539pub struct MakeSnapshotParams<'a> {
540    /// The id of the layer.
541    #[serde(rename = "layerId")]
542    layer_id: LayerId<'a>,
543}
544
545impl<'a> MakeSnapshotParams<'a> {
546    /// Creates a builder for this type with the required parameters:
547    /// * `layer_id`: The id of the layer.
548    pub fn builder(layer_id: impl Into<LayerId<'a>>) -> MakeSnapshotParamsBuilder<'a> {
549        MakeSnapshotParamsBuilder {
550            layer_id: layer_id.into(),
551        }
552    }
553    /// The id of the layer.
554    pub fn layer_id(&self) -> &LayerId<'a> { &self.layer_id }
555}
556
557
558pub struct MakeSnapshotParamsBuilder<'a> {
559    layer_id: LayerId<'a>,
560}
561
562impl<'a> MakeSnapshotParamsBuilder<'a> {
563    pub fn build(self) -> MakeSnapshotParams<'a> {
564        MakeSnapshotParams {
565            layer_id: self.layer_id,
566        }
567    }
568}
569
570/// Returns the layer snapshot identifier.
571
572#[derive(Debug, Clone, Serialize, Deserialize, Default)]
573#[serde(rename_all = "camelCase")]
574pub struct MakeSnapshotReturns<'a> {
575    /// The id of the layer snapshot.
576    #[serde(rename = "snapshotId")]
577    snapshot_id: SnapshotId<'a>,
578}
579
580impl<'a> MakeSnapshotReturns<'a> {
581    /// Creates a builder for this type with the required parameters:
582    /// * `snapshot_id`: The id of the layer snapshot.
583    pub fn builder(snapshot_id: impl Into<SnapshotId<'a>>) -> MakeSnapshotReturnsBuilder<'a> {
584        MakeSnapshotReturnsBuilder {
585            snapshot_id: snapshot_id.into(),
586        }
587    }
588    /// The id of the layer snapshot.
589    pub fn snapshot_id(&self) -> &SnapshotId<'a> { &self.snapshot_id }
590}
591
592
593pub struct MakeSnapshotReturnsBuilder<'a> {
594    snapshot_id: SnapshotId<'a>,
595}
596
597impl<'a> MakeSnapshotReturnsBuilder<'a> {
598    pub fn build(self) -> MakeSnapshotReturns<'a> {
599        MakeSnapshotReturns {
600            snapshot_id: self.snapshot_id,
601        }
602    }
603}
604
605impl<'a> MakeSnapshotParams<'a> { pub const METHOD: &'static str = "LayerTree.makeSnapshot"; }
606
607impl<'a> crate::CdpCommand<'a> for MakeSnapshotParams<'a> {
608    const METHOD: &'static str = "LayerTree.makeSnapshot";
609    type Response = MakeSnapshotReturns<'a>;
610}
611
612
613#[derive(Debug, Clone, Serialize, Deserialize, Default)]
614#[serde(rename_all = "camelCase")]
615pub struct ProfileSnapshotParams<'a> {
616    /// The id of the layer snapshot.
617    #[serde(rename = "snapshotId")]
618    snapshot_id: SnapshotId<'a>,
619    /// The maximum number of times to replay the snapshot (1, if not specified).
620    #[serde(skip_serializing_if = "Option::is_none", rename = "minRepeatCount")]
621    min_repeat_count: Option<u64>,
622    /// The minimum duration (in seconds) to replay the snapshot.
623    #[serde(skip_serializing_if = "Option::is_none", rename = "minDuration")]
624    min_duration: Option<f64>,
625    /// The clip rectangle to apply when replaying the snapshot.
626    #[serde(skip_serializing_if = "Option::is_none", rename = "clipRect")]
627    clip_rect: Option<crate::dom::Rect>,
628}
629
630impl<'a> ProfileSnapshotParams<'a> {
631    /// Creates a builder for this type with the required parameters:
632    /// * `snapshot_id`: The id of the layer snapshot.
633    pub fn builder(snapshot_id: impl Into<SnapshotId<'a>>) -> ProfileSnapshotParamsBuilder<'a> {
634        ProfileSnapshotParamsBuilder {
635            snapshot_id: snapshot_id.into(),
636            min_repeat_count: None,
637            min_duration: None,
638            clip_rect: None,
639        }
640    }
641    /// The id of the layer snapshot.
642    pub fn snapshot_id(&self) -> &SnapshotId<'a> { &self.snapshot_id }
643    /// The maximum number of times to replay the snapshot (1, if not specified).
644    pub fn min_repeat_count(&self) -> Option<u64> { self.min_repeat_count }
645    /// The minimum duration (in seconds) to replay the snapshot.
646    pub fn min_duration(&self) -> Option<f64> { self.min_duration }
647    /// The clip rectangle to apply when replaying the snapshot.
648    pub fn clip_rect(&self) -> Option<&crate::dom::Rect> { self.clip_rect.as_ref() }
649}
650
651
652pub struct ProfileSnapshotParamsBuilder<'a> {
653    snapshot_id: SnapshotId<'a>,
654    min_repeat_count: Option<u64>,
655    min_duration: Option<f64>,
656    clip_rect: Option<crate::dom::Rect>,
657}
658
659impl<'a> ProfileSnapshotParamsBuilder<'a> {
660    /// The maximum number of times to replay the snapshot (1, if not specified).
661    pub fn min_repeat_count(mut self, min_repeat_count: u64) -> Self { self.min_repeat_count = Some(min_repeat_count); self }
662    /// The minimum duration (in seconds) to replay the snapshot.
663    pub fn min_duration(mut self, min_duration: f64) -> Self { self.min_duration = Some(min_duration); self }
664    /// The clip rectangle to apply when replaying the snapshot.
665    pub fn clip_rect(mut self, clip_rect: crate::dom::Rect) -> Self { self.clip_rect = Some(clip_rect); self }
666    pub fn build(self) -> ProfileSnapshotParams<'a> {
667        ProfileSnapshotParams {
668            snapshot_id: self.snapshot_id,
669            min_repeat_count: self.min_repeat_count,
670            min_duration: self.min_duration,
671            clip_rect: self.clip_rect,
672        }
673    }
674}
675
676
677#[derive(Debug, Clone, Serialize, Deserialize, Default)]
678#[serde(rename_all = "camelCase")]
679pub struct ProfileSnapshotReturns {
680    /// The array of paint profiles, one per run.
681    timings: Vec<PaintProfile>,
682}
683
684impl ProfileSnapshotReturns {
685    /// Creates a builder for this type with the required parameters:
686    /// * `timings`: The array of paint profiles, one per run.
687    pub fn builder(timings: Vec<PaintProfile>) -> ProfileSnapshotReturnsBuilder {
688        ProfileSnapshotReturnsBuilder {
689            timings: timings,
690        }
691    }
692    /// The array of paint profiles, one per run.
693    pub fn timings(&self) -> &[PaintProfile] { &self.timings }
694}
695
696
697pub struct ProfileSnapshotReturnsBuilder {
698    timings: Vec<PaintProfile>,
699}
700
701impl ProfileSnapshotReturnsBuilder {
702    pub fn build(self) -> ProfileSnapshotReturns {
703        ProfileSnapshotReturns {
704            timings: self.timings,
705        }
706    }
707}
708
709impl<'a> ProfileSnapshotParams<'a> { pub const METHOD: &'static str = "LayerTree.profileSnapshot"; }
710
711impl<'a> crate::CdpCommand<'a> for ProfileSnapshotParams<'a> {
712    const METHOD: &'static str = "LayerTree.profileSnapshot";
713    type Response = ProfileSnapshotReturns;
714}
715
716/// Releases layer snapshot captured by the back-end.
717
718#[derive(Debug, Clone, Serialize, Deserialize, Default)]
719#[serde(rename_all = "camelCase")]
720pub struct ReleaseSnapshotParams<'a> {
721    /// The id of the layer snapshot.
722    #[serde(rename = "snapshotId")]
723    snapshot_id: SnapshotId<'a>,
724}
725
726impl<'a> ReleaseSnapshotParams<'a> {
727    /// Creates a builder for this type with the required parameters:
728    /// * `snapshot_id`: The id of the layer snapshot.
729    pub fn builder(snapshot_id: impl Into<SnapshotId<'a>>) -> ReleaseSnapshotParamsBuilder<'a> {
730        ReleaseSnapshotParamsBuilder {
731            snapshot_id: snapshot_id.into(),
732        }
733    }
734    /// The id of the layer snapshot.
735    pub fn snapshot_id(&self) -> &SnapshotId<'a> { &self.snapshot_id }
736}
737
738
739pub struct ReleaseSnapshotParamsBuilder<'a> {
740    snapshot_id: SnapshotId<'a>,
741}
742
743impl<'a> ReleaseSnapshotParamsBuilder<'a> {
744    pub fn build(self) -> ReleaseSnapshotParams<'a> {
745        ReleaseSnapshotParams {
746            snapshot_id: self.snapshot_id,
747        }
748    }
749}
750
751impl<'a> ReleaseSnapshotParams<'a> { pub const METHOD: &'static str = "LayerTree.releaseSnapshot"; }
752
753impl<'a> crate::CdpCommand<'a> for ReleaseSnapshotParams<'a> {
754    const METHOD: &'static str = "LayerTree.releaseSnapshot";
755    type Response = crate::EmptyReturns;
756}
757
758/// Replays the layer snapshot and returns the resulting bitmap.
759
760#[derive(Debug, Clone, Serialize, Deserialize, Default)]
761#[serde(rename_all = "camelCase")]
762pub struct ReplaySnapshotParams<'a> {
763    /// The id of the layer snapshot.
764    #[serde(rename = "snapshotId")]
765    snapshot_id: SnapshotId<'a>,
766    /// The first step to replay from (replay from the very start if not specified).
767    #[serde(skip_serializing_if = "Option::is_none", rename = "fromStep")]
768    from_step: Option<i64>,
769    /// The last step to replay to (replay till the end if not specified).
770    #[serde(skip_serializing_if = "Option::is_none", rename = "toStep")]
771    to_step: Option<i64>,
772    /// The scale to apply while replaying (defaults to 1).
773    #[serde(skip_serializing_if = "Option::is_none")]
774    scale: Option<f64>,
775}
776
777impl<'a> ReplaySnapshotParams<'a> {
778    /// Creates a builder for this type with the required parameters:
779    /// * `snapshot_id`: The id of the layer snapshot.
780    pub fn builder(snapshot_id: impl Into<SnapshotId<'a>>) -> ReplaySnapshotParamsBuilder<'a> {
781        ReplaySnapshotParamsBuilder {
782            snapshot_id: snapshot_id.into(),
783            from_step: None,
784            to_step: None,
785            scale: None,
786        }
787    }
788    /// The id of the layer snapshot.
789    pub fn snapshot_id(&self) -> &SnapshotId<'a> { &self.snapshot_id }
790    /// The first step to replay from (replay from the very start if not specified).
791    pub fn from_step(&self) -> Option<i64> { self.from_step }
792    /// The last step to replay to (replay till the end if not specified).
793    pub fn to_step(&self) -> Option<i64> { self.to_step }
794    /// The scale to apply while replaying (defaults to 1).
795    pub fn scale(&self) -> Option<f64> { self.scale }
796}
797
798
799pub struct ReplaySnapshotParamsBuilder<'a> {
800    snapshot_id: SnapshotId<'a>,
801    from_step: Option<i64>,
802    to_step: Option<i64>,
803    scale: Option<f64>,
804}
805
806impl<'a> ReplaySnapshotParamsBuilder<'a> {
807    /// The first step to replay from (replay from the very start if not specified).
808    pub fn from_step(mut self, from_step: i64) -> Self { self.from_step = Some(from_step); self }
809    /// The last step to replay to (replay till the end if not specified).
810    pub fn to_step(mut self, to_step: i64) -> Self { self.to_step = Some(to_step); self }
811    /// The scale to apply while replaying (defaults to 1).
812    pub fn scale(mut self, scale: f64) -> Self { self.scale = Some(scale); self }
813    pub fn build(self) -> ReplaySnapshotParams<'a> {
814        ReplaySnapshotParams {
815            snapshot_id: self.snapshot_id,
816            from_step: self.from_step,
817            to_step: self.to_step,
818            scale: self.scale,
819        }
820    }
821}
822
823/// Replays the layer snapshot and returns the resulting bitmap.
824
825#[derive(Debug, Clone, Serialize, Deserialize, Default)]
826#[serde(rename_all = "camelCase")]
827pub struct ReplaySnapshotReturns<'a> {
828    /// A data: URL for resulting image.
829    #[serde(rename = "dataURL")]
830    data_url: Cow<'a, str>,
831}
832
833impl<'a> ReplaySnapshotReturns<'a> {
834    /// Creates a builder for this type with the required parameters:
835    /// * `data_url`: A data: URL for resulting image.
836    pub fn builder(data_url: impl Into<Cow<'a, str>>) -> ReplaySnapshotReturnsBuilder<'a> {
837        ReplaySnapshotReturnsBuilder {
838            data_url: data_url.into(),
839        }
840    }
841    /// A data: URL for resulting image.
842    pub fn data_url(&self) -> &str { self.data_url.as_ref() }
843}
844
845
846pub struct ReplaySnapshotReturnsBuilder<'a> {
847    data_url: Cow<'a, str>,
848}
849
850impl<'a> ReplaySnapshotReturnsBuilder<'a> {
851    pub fn build(self) -> ReplaySnapshotReturns<'a> {
852        ReplaySnapshotReturns {
853            data_url: self.data_url,
854        }
855    }
856}
857
858impl<'a> ReplaySnapshotParams<'a> { pub const METHOD: &'static str = "LayerTree.replaySnapshot"; }
859
860impl<'a> crate::CdpCommand<'a> for ReplaySnapshotParams<'a> {
861    const METHOD: &'static str = "LayerTree.replaySnapshot";
862    type Response = ReplaySnapshotReturns<'a>;
863}
864
865/// Replays the layer snapshot and returns canvas log.
866
867#[derive(Debug, Clone, Serialize, Deserialize, Default)]
868#[serde(rename_all = "camelCase")]
869pub struct SnapshotCommandLogParams<'a> {
870    /// The id of the layer snapshot.
871    #[serde(rename = "snapshotId")]
872    snapshot_id: SnapshotId<'a>,
873}
874
875impl<'a> SnapshotCommandLogParams<'a> {
876    /// Creates a builder for this type with the required parameters:
877    /// * `snapshot_id`: The id of the layer snapshot.
878    pub fn builder(snapshot_id: impl Into<SnapshotId<'a>>) -> SnapshotCommandLogParamsBuilder<'a> {
879        SnapshotCommandLogParamsBuilder {
880            snapshot_id: snapshot_id.into(),
881        }
882    }
883    /// The id of the layer snapshot.
884    pub fn snapshot_id(&self) -> &SnapshotId<'a> { &self.snapshot_id }
885}
886
887
888pub struct SnapshotCommandLogParamsBuilder<'a> {
889    snapshot_id: SnapshotId<'a>,
890}
891
892impl<'a> SnapshotCommandLogParamsBuilder<'a> {
893    pub fn build(self) -> SnapshotCommandLogParams<'a> {
894        SnapshotCommandLogParams {
895            snapshot_id: self.snapshot_id,
896        }
897    }
898}
899
900/// Replays the layer snapshot and returns canvas log.
901
902#[derive(Debug, Clone, Serialize, Deserialize, Default)]
903#[serde(rename_all = "camelCase")]
904pub struct SnapshotCommandLogReturns {
905    /// The array of canvas function calls.
906    #[serde(rename = "commandLog")]
907    command_log: Vec<serde_json::Map<String, JsonValue>>,
908}
909
910impl SnapshotCommandLogReturns {
911    /// Creates a builder for this type with the required parameters:
912    /// * `command_log`: The array of canvas function calls.
913    pub fn builder(command_log: Vec<serde_json::Map<String, JsonValue>>) -> SnapshotCommandLogReturnsBuilder {
914        SnapshotCommandLogReturnsBuilder {
915            command_log: command_log,
916        }
917    }
918    /// The array of canvas function calls.
919    pub fn command_log(&self) -> &[serde_json::Map<String, JsonValue>] { &self.command_log }
920}
921
922
923pub struct SnapshotCommandLogReturnsBuilder {
924    command_log: Vec<serde_json::Map<String, JsonValue>>,
925}
926
927impl SnapshotCommandLogReturnsBuilder {
928    pub fn build(self) -> SnapshotCommandLogReturns {
929        SnapshotCommandLogReturns {
930            command_log: self.command_log,
931        }
932    }
933}
934
935impl<'a> SnapshotCommandLogParams<'a> { pub const METHOD: &'static str = "LayerTree.snapshotCommandLog"; }
936
937impl<'a> crate::CdpCommand<'a> for SnapshotCommandLogParams<'a> {
938    const METHOD: &'static str = "LayerTree.snapshotCommandLog";
939    type Response = SnapshotCommandLogReturns;
940}