Skip to main content

browser_protocol/layertree/
mod.rs

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