OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | |
5 /** @typedef {!{ | 4 /** @typedef {!{ |
6 rect: !DOMAgent.Rect, | 5 rect: !DOMAgent.Rect, |
7 snapshot: !WebInspector.PaintProfilerSnapshot | 6 snapshot: !WebInspector.PaintProfilerSnapshot |
8 }} | 7 }} |
9 */ | 8 */ |
10 WebInspector.SnapshotWithRect; | 9 WebInspector.SnapshotWithRect; |
11 | 10 |
12 /** | 11 /** |
13 * @interface | 12 * @interface |
14 */ | 13 */ |
15 WebInspector.Layer = function() | 14 WebInspector.Layer = function() {}; |
16 { | 15 |
| 16 WebInspector.Layer.prototype = { |
| 17 /** |
| 18 * @return {string} |
| 19 */ |
| 20 id: function() {}, |
| 21 |
| 22 /** |
| 23 * @return {?string} |
| 24 */ |
| 25 parentId: function() {}, |
| 26 |
| 27 /** |
| 28 * @return {?WebInspector.Layer} |
| 29 */ |
| 30 parent: function() {}, |
| 31 |
| 32 /** |
| 33 * @return {boolean} |
| 34 */ |
| 35 isRoot: function() {}, |
| 36 |
| 37 /** |
| 38 * @return {!Array.<!WebInspector.Layer>} |
| 39 */ |
| 40 children: function() {}, |
| 41 |
| 42 /** |
| 43 * @param {!WebInspector.Layer} child |
| 44 */ |
| 45 addChild: function(child) {}, |
| 46 |
| 47 /** |
| 48 * @return {?WebInspector.DOMNode} |
| 49 */ |
| 50 node: function() {}, |
| 51 |
| 52 /** |
| 53 * @return {?WebInspector.DOMNode} |
| 54 */ |
| 55 nodeForSelfOrAncestor: function() {}, |
| 56 |
| 57 /** |
| 58 * @return {number} |
| 59 */ |
| 60 offsetX: function() {}, |
| 61 |
| 62 /** |
| 63 * @return {number} |
| 64 */ |
| 65 offsetY: function() {}, |
| 66 |
| 67 /** |
| 68 * @return {number} |
| 69 */ |
| 70 width: function() {}, |
| 71 |
| 72 /** |
| 73 * @return {number} |
| 74 */ |
| 75 height: function() {}, |
| 76 |
| 77 /** |
| 78 * @return {?Array.<number>} |
| 79 */ |
| 80 transform: function() {}, |
| 81 |
| 82 /** |
| 83 * @return {!Array.<number>} |
| 84 */ |
| 85 quad: function() {}, |
| 86 |
| 87 /** |
| 88 * @return {!Array.<number>} |
| 89 */ |
| 90 anchorPoint: function() {}, |
| 91 |
| 92 /** |
| 93 * @return {boolean} |
| 94 */ |
| 95 invisible: function() {}, |
| 96 |
| 97 /** |
| 98 * @return {number} |
| 99 */ |
| 100 paintCount: function() {}, |
| 101 |
| 102 /** |
| 103 * @return {?DOMAgent.Rect} |
| 104 */ |
| 105 lastPaintRect: function() {}, |
| 106 |
| 107 /** |
| 108 * @return {!Array.<!LayerTreeAgent.ScrollRect>} |
| 109 */ |
| 110 scrollRects: function() {}, |
| 111 |
| 112 /** |
| 113 * @return {number} |
| 114 */ |
| 115 gpuMemoryUsage: function() {}, |
| 116 |
| 117 /** |
| 118 * @param {function(!Array.<string>)} callback |
| 119 */ |
| 120 requestCompositingReasons: function(callback) {}, |
| 121 |
| 122 /** |
| 123 * @return {boolean} |
| 124 */ |
| 125 drawsContent: function() {}, |
| 126 |
| 127 /** |
| 128 * @return {!Array<!Promise<?WebInspector.SnapshotWithRect>>} |
| 129 */ |
| 130 snapshots: function() {} |
17 }; | 131 }; |
18 | 132 |
19 WebInspector.Layer.prototype = { | 133 WebInspector.Layer.ScrollRectType = { |
20 /** | 134 NonFastScrollable: 'NonFastScrollable', |
21 * @return {string} | 135 TouchEventHandler: 'TouchEventHandler', |
22 */ | 136 WheelEventHandler: 'WheelEventHandler', |
23 id: function() { }, | 137 RepaintsOnScroll: 'RepaintsOnScroll' |
24 | |
25 /** | |
26 * @return {?string} | |
27 */ | |
28 parentId: function() { }, | |
29 | |
30 /** | |
31 * @return {?WebInspector.Layer} | |
32 */ | |
33 parent: function() { }, | |
34 | |
35 /** | |
36 * @return {boolean} | |
37 */ | |
38 isRoot: function() { }, | |
39 | |
40 /** | |
41 * @return {!Array.<!WebInspector.Layer>} | |
42 */ | |
43 children: function() { }, | |
44 | |
45 /** | |
46 * @param {!WebInspector.Layer} child | |
47 */ | |
48 addChild: function(child) { }, | |
49 | |
50 /** | |
51 * @return {?WebInspector.DOMNode} | |
52 */ | |
53 node: function() { }, | |
54 | |
55 /** | |
56 * @return {?WebInspector.DOMNode} | |
57 */ | |
58 nodeForSelfOrAncestor: function() { }, | |
59 | |
60 /** | |
61 * @return {number} | |
62 */ | |
63 offsetX: function() { }, | |
64 | |
65 /** | |
66 * @return {number} | |
67 */ | |
68 offsetY: function() { }, | |
69 | |
70 /** | |
71 * @return {number} | |
72 */ | |
73 width: function() { }, | |
74 | |
75 /** | |
76 * @return {number} | |
77 */ | |
78 height: function() { }, | |
79 | |
80 /** | |
81 * @return {?Array.<number>} | |
82 */ | |
83 transform: function() { }, | |
84 | |
85 /** | |
86 * @return {!Array.<number>} | |
87 */ | |
88 quad: function() { }, | |
89 | |
90 /** | |
91 * @return {!Array.<number>} | |
92 */ | |
93 anchorPoint: function() { }, | |
94 | |
95 /** | |
96 * @return {boolean} | |
97 */ | |
98 invisible: function() { }, | |
99 | |
100 /** | |
101 * @return {number} | |
102 */ | |
103 paintCount: function() { }, | |
104 | |
105 /** | |
106 * @return {?DOMAgent.Rect} | |
107 */ | |
108 lastPaintRect: function() { }, | |
109 | |
110 /** | |
111 * @return {!Array.<!LayerTreeAgent.ScrollRect>} | |
112 */ | |
113 scrollRects: function() { }, | |
114 | |
115 /** | |
116 * @return {number} | |
117 */ | |
118 gpuMemoryUsage: function() { }, | |
119 | |
120 /** | |
121 * @param {function(!Array.<string>)} callback | |
122 */ | |
123 requestCompositingReasons: function(callback) { }, | |
124 | |
125 /** | |
126 * @return {boolean} | |
127 */ | |
128 drawsContent: function() { }, | |
129 | |
130 /** | |
131 * @return {!Array<!Promise<?WebInspector.SnapshotWithRect>>} | |
132 */ | |
133 snapshots: function() { } | |
134 } | |
135 | |
136 WebInspector.Layer.ScrollRectType = { | |
137 NonFastScrollable: "NonFastScrollable", | |
138 TouchEventHandler: "TouchEventHandler", | |
139 WheelEventHandler: "WheelEventHandler", | |
140 RepaintsOnScroll: "RepaintsOnScroll" | |
141 }; | 138 }; |
142 | 139 |
143 /** | 140 /** |
144 * @constructor | 141 * @unrestricted |
145 * @param {?WebInspector.Target} target | 142 */ |
146 */ | 143 WebInspector.LayerTreeBase = class { |
147 WebInspector.LayerTreeBase = function(target) | 144 /** |
148 { | 145 * @param {?WebInspector.Target} target |
| 146 */ |
| 147 constructor(target) { |
149 this._target = target; | 148 this._target = target; |
150 this._domModel = target ? WebInspector.DOMModel.fromTarget(target) : null; | 149 this._domModel = target ? WebInspector.DOMModel.fromTarget(target) : null; |
151 this._layersById = {}; | 150 this._layersById = {}; |
152 this._root = null; | 151 this._root = null; |
153 this._contentRoot = null; | 152 this._contentRoot = null; |
154 /** @type Map<number, ?WebInspector.DOMNode> */ | 153 /** @type Map<number, ?WebInspector.DOMNode> */ |
155 this._backendNodeIdToNode = new Map(); | 154 this._backendNodeIdToNode = new Map(); |
156 }; | 155 } |
157 | 156 |
158 WebInspector.LayerTreeBase.prototype = { | 157 /** |
159 /** | 158 * @return {?WebInspector.Target} |
160 * @return {?WebInspector.Target} | 159 */ |
161 */ | 160 target() { |
162 target: function() | 161 return this._target; |
163 { | 162 } |
164 return this._target; | 163 |
165 }, | 164 /** |
| 165 * @return {?WebInspector.Layer} |
| 166 */ |
| 167 root() { |
| 168 return this._root; |
| 169 } |
| 170 |
| 171 /** |
| 172 * @param {?WebInspector.Layer} root |
| 173 * @protected |
| 174 */ |
| 175 setRoot(root) { |
| 176 this._root = root; |
| 177 } |
| 178 |
| 179 /** |
| 180 * @return {?WebInspector.Layer} |
| 181 */ |
| 182 contentRoot() { |
| 183 return this._contentRoot; |
| 184 } |
| 185 |
| 186 /** |
| 187 * @param {?WebInspector.Layer} contentRoot |
| 188 * @protected |
| 189 */ |
| 190 setContentRoot(contentRoot) { |
| 191 this._contentRoot = contentRoot; |
| 192 } |
| 193 |
| 194 /** |
| 195 * @param {function(!WebInspector.Layer)} callback |
| 196 * @param {?WebInspector.Layer=} root |
| 197 * @return {boolean} |
| 198 */ |
| 199 forEachLayer(callback, root) { |
| 200 if (!root) { |
| 201 root = this.root(); |
| 202 if (!root) |
| 203 return false; |
| 204 } |
| 205 return callback(root) || root.children().some(this.forEachLayer.bind(this, c
allback)); |
| 206 } |
| 207 |
| 208 /** |
| 209 * @param {string} id |
| 210 * @return {?WebInspector.Layer} |
| 211 */ |
| 212 layerById(id) { |
| 213 return this._layersById[id] || null; |
| 214 } |
| 215 |
| 216 /** |
| 217 * @param {!Set<number>} requestedNodeIds |
| 218 * @param {function()} callback |
| 219 */ |
| 220 _resolveBackendNodeIds(requestedNodeIds, callback) { |
| 221 if (!requestedNodeIds.size || !this._domModel) { |
| 222 callback(); |
| 223 return; |
| 224 } |
| 225 if (this._domModel) |
| 226 this._domModel.pushNodesByBackendIdsToFrontend(requestedNodeIds, populateB
ackendNodeMap.bind(this)); |
166 | 227 |
167 /** | 228 /** |
168 * @return {?WebInspector.Layer} | 229 * @this {WebInspector.LayerTreeBase} |
| 230 * @param {?Map<number, ?WebInspector.DOMNode>} nodesMap |
169 */ | 231 */ |
170 root: function() | 232 function populateBackendNodeMap(nodesMap) { |
171 { | 233 if (nodesMap) { |
172 return this._root; | 234 for (var nodeId of nodesMap.keysArray()) |
173 }, | 235 this._backendNodeIdToNode.set(nodeId, nodesMap.get(nodeId) || null); |
| 236 } |
| 237 callback(); |
| 238 } |
| 239 } |
174 | 240 |
175 /** | 241 /** |
176 * @param {?WebInspector.Layer} root | 242 * @param {!{width: number, height: number}} viewportSize |
177 * @protected | 243 */ |
178 */ | 244 setViewportSize(viewportSize) { |
179 setRoot: function(root) | 245 this._viewportSize = viewportSize; |
180 { | 246 } |
181 this._root = root; | |
182 }, | |
183 | 247 |
184 /** | 248 /** |
185 * @return {?WebInspector.Layer} | 249 * @return {!{width: number, height: number}|undefined} |
186 */ | 250 */ |
187 contentRoot: function() | 251 viewportSize() { |
188 { | 252 return this._viewportSize; |
189 return this._contentRoot; | 253 } |
190 }, | |
191 | 254 |
192 /** | 255 /** |
193 * @param {?WebInspector.Layer} contentRoot | 256 * @param {number} id |
194 * @protected | 257 * @return {?WebInspector.DOMNode} |
195 */ | 258 */ |
196 setContentRoot: function(contentRoot) | 259 _nodeForId(id) { |
197 { | 260 return this._domModel ? this._domModel.nodeForId(id) : null; |
198 this._contentRoot = contentRoot; | 261 } |
199 }, | |
200 | |
201 /** | |
202 * @param {function(!WebInspector.Layer)} callback | |
203 * @param {?WebInspector.Layer=} root | |
204 * @return {boolean} | |
205 */ | |
206 forEachLayer: function(callback, root) | |
207 { | |
208 if (!root) { | |
209 root = this.root(); | |
210 if (!root) | |
211 return false; | |
212 } | |
213 return callback(root) || root.children().some(this.forEachLayer.bind(thi
s, callback)); | |
214 }, | |
215 | |
216 /** | |
217 * @param {string} id | |
218 * @return {?WebInspector.Layer} | |
219 */ | |
220 layerById: function(id) | |
221 { | |
222 return this._layersById[id] || null; | |
223 }, | |
224 | |
225 /** | |
226 * @param {!Set<number>} requestedNodeIds | |
227 * @param {function()} callback | |
228 */ | |
229 _resolveBackendNodeIds: function(requestedNodeIds, callback) | |
230 { | |
231 if (!requestedNodeIds.size || !this._domModel) { | |
232 callback(); | |
233 return; | |
234 } | |
235 if (this._domModel) | |
236 this._domModel.pushNodesByBackendIdsToFrontend(requestedNodeIds, pop
ulateBackendNodeMap.bind(this)); | |
237 | |
238 /** | |
239 * @this {WebInspector.LayerTreeBase} | |
240 * @param {?Map<number, ?WebInspector.DOMNode>} nodesMap | |
241 */ | |
242 function populateBackendNodeMap(nodesMap) | |
243 { | |
244 if (nodesMap) { | |
245 for (var nodeId of nodesMap.keysArray()) | |
246 this._backendNodeIdToNode.set(nodeId, nodesMap.get(nodeId) |
| null); | |
247 } | |
248 callback(); | |
249 } | |
250 }, | |
251 | |
252 /** | |
253 * @param {!{width: number, height: number}} viewportSize | |
254 */ | |
255 setViewportSize: function(viewportSize) | |
256 { | |
257 this._viewportSize = viewportSize; | |
258 }, | |
259 | |
260 /** | |
261 * @return {!{width: number, height: number}|undefined} | |
262 */ | |
263 viewportSize: function() | |
264 { | |
265 return this._viewportSize; | |
266 }, | |
267 | |
268 /** | |
269 * @param {number} id | |
270 * @return {?WebInspector.DOMNode} | |
271 */ | |
272 _nodeForId: function(id) | |
273 { | |
274 return this._domModel ? this._domModel.nodeForId(id) : null; | |
275 } | |
276 }; | 262 }; |
OLD | NEW |