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
155/// Returns the snapshot identifier.
156
157#[derive(Debug, Clone, Serialize, Deserialize, Default)]
158#[serde(rename_all = "camelCase")]
159pub struct LoadSnapshotParams {
160    /// An array of tiles composing the snapshot.
161
162    pub tiles: Vec<PictureTile>,
163}
164
165/// Returns the snapshot identifier.
166
167#[derive(Debug, Clone, Serialize, Deserialize, Default)]
168#[serde(rename_all = "camelCase")]
169pub struct LoadSnapshotReturns {
170    /// The id of the snapshot.
171
172    pub snapshotId: SnapshotId,
173}
174
175/// Returns the layer snapshot identifier.
176
177#[derive(Debug, Clone, Serialize, Deserialize, Default)]
178#[serde(rename_all = "camelCase")]
179pub struct MakeSnapshotParams {
180    /// The id of the layer.
181
182    pub layerId: LayerId,
183}
184
185/// Returns the layer snapshot identifier.
186
187#[derive(Debug, Clone, Serialize, Deserialize, Default)]
188#[serde(rename_all = "camelCase")]
189pub struct MakeSnapshotReturns {
190    /// The id of the layer snapshot.
191
192    pub snapshotId: SnapshotId,
193}
194
195
196#[derive(Debug, Clone, Serialize, Deserialize, Default)]
197#[serde(rename_all = "camelCase")]
198pub struct ProfileSnapshotParams {
199    /// The id of the layer snapshot.
200
201    pub snapshotId: SnapshotId,
202    /// The maximum number of times to replay the snapshot (1, if not specified).
203
204    #[serde(skip_serializing_if = "Option::is_none")]
205    pub minRepeatCount: Option<u64>,
206    /// The minimum duration (in seconds) to replay the snapshot.
207
208    #[serde(skip_serializing_if = "Option::is_none")]
209    pub minDuration: Option<f64>,
210    /// The clip rectangle to apply when replaying the snapshot.
211
212    #[serde(skip_serializing_if = "Option::is_none")]
213    pub clipRect: Option<crate::dom::Rect>,
214}
215
216
217#[derive(Debug, Clone, Serialize, Deserialize, Default)]
218#[serde(rename_all = "camelCase")]
219pub struct ProfileSnapshotReturns {
220    /// The array of paint profiles, one per run.
221
222    pub timings: Vec<PaintProfile>,
223}
224
225/// Releases layer snapshot captured by the back-end.
226
227#[derive(Debug, Clone, Serialize, Deserialize, Default)]
228#[serde(rename_all = "camelCase")]
229pub struct ReleaseSnapshotParams {
230    /// The id of the layer snapshot.
231
232    pub snapshotId: SnapshotId,
233}
234
235/// Replays the layer snapshot and returns the resulting bitmap.
236
237#[derive(Debug, Clone, Serialize, Deserialize, Default)]
238#[serde(rename_all = "camelCase")]
239pub struct ReplaySnapshotParams {
240    /// The id of the layer snapshot.
241
242    pub snapshotId: SnapshotId,
243    /// The first step to replay from (replay from the very start if not specified).
244
245    #[serde(skip_serializing_if = "Option::is_none")]
246    pub fromStep: Option<i64>,
247    /// The last step to replay to (replay till the end if not specified).
248
249    #[serde(skip_serializing_if = "Option::is_none")]
250    pub toStep: Option<i64>,
251    /// The scale to apply while replaying (defaults to 1).
252
253    #[serde(skip_serializing_if = "Option::is_none")]
254    pub scale: Option<f64>,
255}
256
257/// Replays the layer snapshot and returns the resulting bitmap.
258
259#[derive(Debug, Clone, Serialize, Deserialize, Default)]
260#[serde(rename_all = "camelCase")]
261pub struct ReplaySnapshotReturns {
262    /// A data: URL for resulting image.
263
264    pub dataURL: String,
265}
266
267/// Replays the layer snapshot and returns canvas log.
268
269#[derive(Debug, Clone, Serialize, Deserialize, Default)]
270#[serde(rename_all = "camelCase")]
271pub struct SnapshotCommandLogParams {
272    /// The id of the layer snapshot.
273
274    pub snapshotId: SnapshotId,
275}
276
277/// Replays the layer snapshot and returns canvas log.
278
279#[derive(Debug, Clone, Serialize, Deserialize, Default)]
280#[serde(rename_all = "camelCase")]
281pub struct SnapshotCommandLogReturns {
282    /// The array of canvas function calls.
283
284    pub commandLog: Vec<serde_json::Map<String, JsonValue>>,
285}