Skip to main content

cdp_driver/protocol/
layer_tree.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! The `LayerTree` domain.
5//!
6//! Types, command parameters and event payloads for the `LayerTree`
7//! domain. The method-name constants for the same domain are in
8//! [`crate::methods`].
9//!
10//! This domain is experimental and may change without notice.
11
12use serde::{Deserialize, Serialize};
13
14/// Unique Layer identifier.
15pub type LayerId = String;
16
17/// Unique snapshot identifier.
18pub type SnapshotId = String;
19
20/// Rectangle where scrolling happens on the main thread.
21#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
22pub struct ScrollRect {
23    /// Rectangle itself.
24    pub rect: crate::protocol::dom::Rect,
25    /// Reason for rectangle to force scrolling on the main thread
26    pub r#type: ScrollRectType,
27}
28
29/// The values `type` accepts on `ScrollRect`.
30#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
31pub enum ScrollRectType {
32    /// `RepaintsOnScroll`
33    RepaintsOnScroll,
34    /// `TouchEventHandler`
35    TouchEventHandler,
36    /// `WheelEventHandler`
37    WheelEventHandler,
38    /// A value this vendored schema does not list. Chrome adds values ahead of
39    /// the published protocol, so an unrecognised one is kept as it arrived
40    /// rather than failing the payload it came in.
41    #[serde(untagged)]
42    Unrecognized(String),
43}
44
45/// Sticky position constraints.
46#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
47pub struct StickyPositionConstraint {
48    /// Layout rectangle of the sticky element before being shifted
49    #[serde(rename = "stickyBoxRect")]
50    pub sticky_box_rect: crate::protocol::dom::Rect,
51    /// Layout rectangle of the containing block of the sticky element
52    #[serde(rename = "containingBlockRect")]
53    pub containing_block_rect: crate::protocol::dom::Rect,
54    /// The nearest sticky layer that shifts the sticky box
55    #[serde(
56        rename = "nearestLayerShiftingStickyBox",
57        default,
58        skip_serializing_if = "Option::is_none"
59    )]
60    pub nearest_layer_shifting_sticky_box: Option<LayerId>,
61    /// The nearest sticky layer that shifts the containing block
62    #[serde(
63        rename = "nearestLayerShiftingContainingBlock",
64        default,
65        skip_serializing_if = "Option::is_none"
66    )]
67    pub nearest_layer_shifting_containing_block: Option<LayerId>,
68}
69
70/// Serialized fragment of layer picture along with its offset within the
71/// layer.
72#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
73pub struct PictureTile {
74    /// Offset from owning layer left boundary
75    pub x: f64,
76    /// Offset from owning layer top boundary
77    pub y: f64,
78    /// Base64-encoded snapshot data. (Encoded as a base64 string when passed over
79    /// JSON)
80    pub picture: String,
81}
82
83/// Information about a compositing layer.
84#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
85pub struct Layer {
86    /// The unique id for this layer.
87    #[serde(rename = "layerId")]
88    pub layer_id: LayerId,
89    /// The id of parent (not present for root).
90    #[serde(
91        rename = "parentLayerId",
92        default,
93        skip_serializing_if = "Option::is_none"
94    )]
95    pub parent_layer_id: Option<LayerId>,
96    /// The backend id for the node associated with this layer.
97    #[serde(
98        rename = "backendNodeId",
99        default,
100        skip_serializing_if = "Option::is_none"
101    )]
102    pub backend_node_id: Option<crate::protocol::dom::BackendNodeId>,
103    /// Offset from parent layer, X coordinate.
104    #[serde(rename = "offsetX")]
105    pub offset_x: f64,
106    /// Offset from parent layer, Y coordinate.
107    #[serde(rename = "offsetY")]
108    pub offset_y: f64,
109    /// Layer width.
110    pub width: f64,
111    /// Layer height.
112    pub height: f64,
113    /// Transformation matrix for layer, default is identity matrix
114    #[serde(default, skip_serializing_if = "Option::is_none")]
115    pub transform: Option<Vec<f64>>,
116    /// Transform anchor point X, absent if no transform specified
117    #[serde(rename = "anchorX", default, skip_serializing_if = "Option::is_none")]
118    pub anchor_x: Option<f64>,
119    /// Transform anchor point Y, absent if no transform specified
120    #[serde(rename = "anchorY", default, skip_serializing_if = "Option::is_none")]
121    pub anchor_y: Option<f64>,
122    /// Transform anchor point Z, absent if no transform specified
123    #[serde(rename = "anchorZ", default, skip_serializing_if = "Option::is_none")]
124    pub anchor_z: Option<f64>,
125    /// Indicates how many time this layer has painted.
126    #[serde(rename = "paintCount")]
127    pub paint_count: i64,
128    /// Indicates whether this layer hosts any content, rather than being used for
129    /// transform/scrolling purposes only.
130    #[serde(rename = "drawsContent")]
131    pub draws_content: bool,
132    /// Set if layer is not visible.
133    #[serde(default, skip_serializing_if = "Option::is_none")]
134    pub invisible: Option<bool>,
135    /// Rectangles scrolling on main thread only.
136    #[serde(
137        rename = "scrollRects",
138        default,
139        skip_serializing_if = "Option::is_none"
140    )]
141    pub scroll_rects: Option<Vec<ScrollRect>>,
142    /// Sticky position constraint information
143    #[serde(
144        rename = "stickyPositionConstraint",
145        default,
146        skip_serializing_if = "Option::is_none"
147    )]
148    pub sticky_position_constraint: Option<StickyPositionConstraint>,
149}
150
151/// Array of timings, one per paint step.
152pub type PaintProfile = Vec<f64>;
153
154/// Provides the reasons why the given layer was composited.
155///
156/// Parameters of `LayerTree.compositingReasons`.
157#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
158pub struct CompositingReasonsParams {
159    /// The id of the layer for which we want to get the reasons it was
160    /// composited.
161    #[serde(rename = "layerId")]
162    pub layer_id: LayerId,
163}
164
165/// What `LayerTree.compositingReasons` answers with.
166#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
167pub struct CompositingReasonsReturns {
168    /// A list of strings specifying reasons for the given layer to become
169    /// composited.
170    #[serde(rename = "compositingReasons")]
171    pub compositing_reasons: Vec<String>,
172    /// A list of strings specifying reason IDs for the given layer to become
173    /// composited.
174    #[serde(rename = "compositingReasonIds")]
175    pub compositing_reason_ids: Vec<String>,
176}
177
178impl crate::typed::Command for CompositingReasonsParams {
179    const METHOD: &'static str = "LayerTree.compositingReasons";
180    type Returns = CompositingReasonsReturns;
181}
182
183/// Disables compositing tree inspection.
184///
185/// Parameters of `LayerTree.disable`.
186#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
187pub struct DisableParams {}
188
189impl crate::typed::Command for DisableParams {
190    const METHOD: &'static str = "LayerTree.disable";
191    type Returns = crate::typed::NoReturns;
192}
193
194/// Enables compositing tree inspection.
195///
196/// Parameters of `LayerTree.enable`.
197#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
198pub struct EnableParams {}
199
200impl crate::typed::Command for EnableParams {
201    const METHOD: &'static str = "LayerTree.enable";
202    type Returns = crate::typed::NoReturns;
203}
204
205/// Returns the snapshot identifier.
206///
207/// Parameters of `LayerTree.loadSnapshot`.
208#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
209pub struct LoadSnapshotParams {
210    /// An array of tiles composing the snapshot.
211    pub tiles: Vec<PictureTile>,
212}
213
214/// What `LayerTree.loadSnapshot` answers with.
215#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
216pub struct LoadSnapshotReturns {
217    /// The id of the snapshot.
218    #[serde(rename = "snapshotId")]
219    pub snapshot_id: SnapshotId,
220}
221
222impl crate::typed::Command for LoadSnapshotParams {
223    const METHOD: &'static str = "LayerTree.loadSnapshot";
224    type Returns = LoadSnapshotReturns;
225}
226
227/// Returns the layer snapshot identifier.
228///
229/// Parameters of `LayerTree.makeSnapshot`.
230#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
231pub struct MakeSnapshotParams {
232    /// The id of the layer.
233    #[serde(rename = "layerId")]
234    pub layer_id: LayerId,
235}
236
237/// What `LayerTree.makeSnapshot` answers with.
238#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
239pub struct MakeSnapshotReturns {
240    /// The id of the layer snapshot.
241    #[serde(rename = "snapshotId")]
242    pub snapshot_id: SnapshotId,
243}
244
245impl crate::typed::Command for MakeSnapshotParams {
246    const METHOD: &'static str = "LayerTree.makeSnapshot";
247    type Returns = MakeSnapshotReturns;
248}
249
250/// Parameters of `LayerTree.profileSnapshot`.
251#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
252pub struct ProfileSnapshotParams {
253    /// The id of the layer snapshot.
254    #[serde(rename = "snapshotId")]
255    pub snapshot_id: SnapshotId,
256    /// The maximum number of times to replay the snapshot (1, if not specified).
257    #[serde(
258        rename = "minRepeatCount",
259        default,
260        skip_serializing_if = "Option::is_none"
261    )]
262    pub min_repeat_count: Option<i64>,
263    /// The minimum duration (in seconds) to replay the snapshot.
264    #[serde(
265        rename = "minDuration",
266        default,
267        skip_serializing_if = "Option::is_none"
268    )]
269    pub min_duration: Option<f64>,
270    /// The clip rectangle to apply when replaying the snapshot.
271    #[serde(rename = "clipRect", default, skip_serializing_if = "Option::is_none")]
272    pub clip_rect: Option<crate::protocol::dom::Rect>,
273}
274
275/// What `LayerTree.profileSnapshot` answers with.
276#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
277pub struct ProfileSnapshotReturns {
278    /// The array of paint profiles, one per run.
279    pub timings: Vec<PaintProfile>,
280}
281
282impl crate::typed::Command for ProfileSnapshotParams {
283    const METHOD: &'static str = "LayerTree.profileSnapshot";
284    type Returns = ProfileSnapshotReturns;
285}
286
287/// Releases layer snapshot captured by the back-end.
288///
289/// Parameters of `LayerTree.releaseSnapshot`.
290#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
291pub struct ReleaseSnapshotParams {
292    /// The id of the layer snapshot.
293    #[serde(rename = "snapshotId")]
294    pub snapshot_id: SnapshotId,
295}
296
297impl crate::typed::Command for ReleaseSnapshotParams {
298    const METHOD: &'static str = "LayerTree.releaseSnapshot";
299    type Returns = crate::typed::NoReturns;
300}
301
302/// Replays the layer snapshot and returns the resulting bitmap.
303///
304/// Parameters of `LayerTree.replaySnapshot`.
305#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
306pub struct ReplaySnapshotParams {
307    /// The id of the layer snapshot.
308    #[serde(rename = "snapshotId")]
309    pub snapshot_id: SnapshotId,
310    /// The first step to replay from (replay from the very start if not
311    /// specified).
312    #[serde(rename = "fromStep", default, skip_serializing_if = "Option::is_none")]
313    pub from_step: Option<i64>,
314    /// The last step to replay to (replay till the end if not specified).
315    #[serde(rename = "toStep", default, skip_serializing_if = "Option::is_none")]
316    pub to_step: Option<i64>,
317    /// The scale to apply while replaying (defaults to 1).
318    #[serde(default, skip_serializing_if = "Option::is_none")]
319    pub scale: Option<f64>,
320}
321
322/// What `LayerTree.replaySnapshot` answers with.
323#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
324pub struct ReplaySnapshotReturns {
325    /// A data: URL for resulting image.
326    #[serde(rename = "dataURL")]
327    pub data_url: String,
328}
329
330impl crate::typed::Command for ReplaySnapshotParams {
331    const METHOD: &'static str = "LayerTree.replaySnapshot";
332    type Returns = ReplaySnapshotReturns;
333}
334
335/// Replays the layer snapshot and returns canvas log.
336///
337/// Parameters of `LayerTree.snapshotCommandLog`.
338#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
339pub struct SnapshotCommandLogParams {
340    /// The id of the layer snapshot.
341    #[serde(rename = "snapshotId")]
342    pub snapshot_id: SnapshotId,
343}
344
345/// What `LayerTree.snapshotCommandLog` answers with.
346#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
347pub struct SnapshotCommandLogReturns {
348    /// The array of canvas function calls.
349    #[serde(rename = "commandLog")]
350    pub command_log: Vec<serde_json::Value>,
351}
352
353impl crate::typed::Command for SnapshotCommandLogParams {
354    const METHOD: &'static str = "LayerTree.snapshotCommandLog";
355    type Returns = SnapshotCommandLogReturns;
356}
357
358/// Payload of the `LayerTree.layerPainted` event.
359#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
360pub struct LayerPaintedEvent {
361    /// The id of the painted layer.
362    #[serde(rename = "layerId")]
363    pub layer_id: LayerId,
364    /// Clip rectangle.
365    pub clip: crate::protocol::dom::Rect,
366}
367
368impl crate::typed::Event for LayerPaintedEvent {
369    const METHOD: &'static str = "LayerTree.layerPainted";
370}
371
372/// Payload of the `LayerTree.layerTreeDidChange` event.
373#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
374pub struct LayerTreeDidChangeEvent {
375    /// Layer tree, absent if not in the compositing mode.
376    #[serde(default, skip_serializing_if = "Option::is_none")]
377    pub layers: Option<Vec<Layer>>,
378}
379
380impl crate::typed::Event for LayerTreeDidChangeEvent {
381    const METHOD: &'static str = "LayerTree.layerTreeDidChange";
382}