OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 30 matching lines...) Expand all Loading... | |
41 this._lastPaintRectByLayerId = {}; | 41 this._lastPaintRectByLayerId = {}; |
42 InspectorBackend.registerLayerTreeDispatcher(new WebInspector.LayerTreeDispa tcher(this)); | 42 InspectorBackend.registerLayerTreeDispatcher(new WebInspector.LayerTreeDispa tcher(this)); |
43 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.Document Updated, this._onDocumentUpdated, this); | 43 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.Document Updated, this._onDocumentUpdated, this); |
44 } | 44 } |
45 | 45 |
46 WebInspector.LayerTreeModel.Events = { | 46 WebInspector.LayerTreeModel.Events = { |
47 LayerTreeChanged: "LayerTreeChanged", | 47 LayerTreeChanged: "LayerTreeChanged", |
48 LayerPainted: "LayerPainted", | 48 LayerPainted: "LayerPainted", |
49 } | 49 } |
50 | 50 |
51 /** | |
52 * @param {!LayerTreeAgent.ScrollRect} first | |
53 * @param {!LayerTreeAgent.ScrollRect} second | |
54 */ | |
55 WebInspector.LayerTreeModel._scrollRectsAreEqual = function(first, second) | |
56 { | |
57 return first.rect.x === second.rect.x && first.rect.y === second.rect.y && | |
58 first.rect.width === second.rect.width && first.rect.height === second.r ect.height && | |
59 first.type === second.type; | |
60 } | |
61 | |
51 WebInspector.LayerTreeModel.prototype = { | 62 WebInspector.LayerTreeModel.prototype = { |
52 disable: function() | 63 disable: function() |
53 { | 64 { |
54 if (!this._enabled) | 65 if (!this._enabled) |
55 return; | 66 return; |
56 this._enabled = false; | 67 this._enabled = false; |
57 LayerTreeAgent.disable(); | 68 LayerTreeAgent.disable(); |
58 }, | 69 }, |
59 | 70 |
60 /** | 71 /** |
(...skipping 29 matching lines...) Expand all Loading... | |
90 /** | 101 /** |
91 * @return {?WebInspector.Layer} | 102 * @return {?WebInspector.Layer} |
92 */ | 103 */ |
93 contentRoot: function() | 104 contentRoot: function() |
94 { | 105 { |
95 return this._contentRoot; | 106 return this._contentRoot; |
96 }, | 107 }, |
97 | 108 |
98 /** | 109 /** |
99 * @param {function(!WebInspector.Layer)} callback | 110 * @param {function(!WebInspector.Layer)} callback |
100 * @param {?WebInspector.Layer} root | 111 * @param {?WebInspector.Layer=} root |
101 * @return {boolean} | 112 * @return {boolean} |
102 */ | 113 */ |
103 forEachLayer: function(callback, root) | 114 forEachLayer: function(callback, root) |
104 { | 115 { |
105 if (!root) { | 116 if (!root) { |
106 root = this.root(); | 117 root = this.root(); |
107 if (!root) | 118 if (!root) |
108 return false; | 119 return false; |
109 } | 120 } |
110 return callback(root) || root.children().some(this.forEachLayer.bind(thi s, callback)); | 121 return callback(root) || root.children().some(this.forEachLayer.bind(thi s, callback)); |
111 }, | 122 }, |
112 | 123 |
113 /** | 124 /** |
114 * @param {string} id | 125 * @param {string} id |
115 * @return {?WebInspector.Layer} | 126 * @return {?WebInspector.Layer} |
116 */ | 127 */ |
117 layerById: function(id) | 128 layerById: function(id) |
118 { | 129 { |
119 return this._layersById[id] || null; | 130 return this._layersById[id] || null; |
120 }, | 131 }, |
121 | 132 |
122 /** | 133 /** |
123 * @param {!Array.<!LayerTreeAgent.Layer>} payload | 134 * @param {!Array.<!LayerTreeAgent.Layer>} layers |
124 */ | 135 */ |
125 _repopulate: function(payload) | 136 _repopulate: function(layers) |
126 { | 137 { |
127 var oldLayersById = this._layersById; | 138 var oldLayersById = this._layersById; |
128 this._layersById = {}; | 139 this._layersById = {}; |
129 for (var i = 0; i < payload.length; ++i) { | 140 for (var i = 0; i < layers.length; ++i) { |
130 var layerId = payload[i].layerId; | 141 var layerId = layers[i].layerId; |
131 var layer = oldLayersById[layerId]; | 142 var layer = oldLayersById[layerId]; |
132 if (layer) | 143 if (layer) |
133 layer._reset(payload[i]); | 144 layer._reset(layers[i]); |
134 else | 145 else |
135 layer = new WebInspector.Layer(payload[i]); | 146 layer = new WebInspector.Layer(layers[i]); |
136 this._layersById[layerId] = layer; | 147 this._layersById[layerId] = layer; |
137 var parentId = layer.parentId(); | 148 var parentId = layer.parentId(); |
138 if (!this._contentRoot && layer.nodeId()) | 149 if (!this._contentRoot && layer.nodeId()) |
139 this._contentRoot = layer; | 150 this._contentRoot = layer; |
140 var lastPaintRect = this._lastPaintRectByLayerId[layerId]; | 151 var lastPaintRect = this._lastPaintRectByLayerId[layerId]; |
141 if (lastPaintRect) | 152 if (lastPaintRect) |
142 layer._lastPaintRect = lastPaintRect; | 153 layer._lastPaintRect = lastPaintRect; |
143 if (parentId) { | 154 if (parentId) { |
144 var parent = this._layersById[parentId]; | 155 var parent = this._layersById[parentId]; |
145 if (!parent) | 156 if (!parent) |
146 console.assert(parent, "missing parent " + parentId + " for layer " + layerId); | 157 console.assert(parent, "missing parent " + parentId + " for layer " + layerId); |
147 parent.addChild(layer); | 158 parent.addChild(layer); |
148 } else { | 159 } else { |
149 if (this._root) | 160 if (this._root) |
150 console.assert(false, "Multiple root layers"); | 161 console.assert(false, "Multiple root layers"); |
151 this._root = layer; | 162 this._root = layer; |
152 } | 163 } |
164 layer._updateScrollRects(); | |
153 } | 165 } |
154 this._lastPaintRectByLayerId = {}; | 166 this._lastPaintRectByLayerId = {}; |
155 }, | 167 }, |
156 | 168 |
157 /** | 169 /** |
158 * @param {!Array.<!LayerTreeAgent.Layer>=} payload | 170 * @param {!Array.<!LayerTreeAgent.Layer>=} layers |
159 */ | 171 */ |
160 _layerTreeChanged: function(payload) | 172 _layerTreeChanged: function(layers) |
161 { | 173 { |
162 this._root = null; | 174 this._root = null; |
163 this._contentRoot = null; | 175 this._contentRoot = null; |
164 // Payload will be null when not in the composited mode. | 176 // Payload will be null when not in the composited mode. |
165 if (payload) | 177 if (layers) |
166 this._repopulate(payload); | 178 this._repopulate(layers); |
167 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr eeChanged); | 179 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr eeChanged); |
168 }, | 180 }, |
169 | 181 |
170 /** | 182 /** |
171 * @param {!LayerTreeAgent.LayerId} layerId | 183 * @param {!LayerTreeAgent.LayerId} layerId |
172 * @param {!DOMAgent.Rect} clipRect | 184 * @param {!DOMAgent.Rect} clipRect |
173 */ | 185 */ |
174 _layerPainted: function(layerId, clipRect) | 186 _layerPainted: function(layerId, clipRect) |
175 { | 187 { |
176 var layer = this._layersById[layerId]; | 188 var layer = this._layersById[layerId]; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 | 355 |
344 /** | 356 /** |
345 * @return {?DOMAgent.Rect} | 357 * @return {?DOMAgent.Rect} |
346 */ | 358 */ |
347 lastPaintRect: function() | 359 lastPaintRect: function() |
348 { | 360 { |
349 return this._lastPaintRect; | 361 return this._lastPaintRect; |
350 }, | 362 }, |
351 | 363 |
352 /** | 364 /** |
365 * @return {!Array.<!LayerTreeAgent.ScrollRect>} | |
366 */ | |
367 scrollRects: function() | |
368 { | |
369 return this._scrollRects; | |
370 }, | |
371 | |
372 /** | |
353 * @param {function(!Array.<string>)} callback | 373 * @param {function(!Array.<string>)} callback |
354 */ | 374 */ |
355 requestCompositingReasons: function(callback) | 375 requestCompositingReasons: function(callback) |
356 { | 376 { |
357 var wrappedCallback = InspectorBackend.wrapClientCallback(callback, "Lay erTreeAgent.reasonsForCompositingLayer(): ", undefined, []); | 377 var wrappedCallback = InspectorBackend.wrapClientCallback(callback, "Lay erTreeAgent.reasonsForCompositingLayer(): ", undefined, []); |
358 LayerTreeAgent.compositingReasons(this.id(), wrappedCallback); | 378 LayerTreeAgent.compositingReasons(this.id(), wrappedCallback); |
359 }, | 379 }, |
360 | 380 |
361 /** | 381 /** |
362 * @param {function(!WebInspector.PaintProfilerSnapshot=)} callback | 382 * @param {function(!WebInspector.PaintProfilerSnapshot=)} callback |
(...skipping 17 matching lines...) Expand all Loading... | |
380 /** | 400 /** |
381 * @param {!LayerTreeAgent.Layer} layerPayload | 401 * @param {!LayerTreeAgent.Layer} layerPayload |
382 */ | 402 */ |
383 _reset: function(layerPayload) | 403 _reset: function(layerPayload) |
384 { | 404 { |
385 this._children = []; | 405 this._children = []; |
386 this._parent = null; | 406 this._parent = null; |
387 this._paintCount = 0; | 407 this._paintCount = 0; |
388 this._layerPayload = layerPayload; | 408 this._layerPayload = layerPayload; |
389 this._image = null; | 409 this._image = null; |
410 }, | |
411 | |
412 _updateScrollRects: function() | |
413 { | |
414 if (!this._scrollRects) | |
415 this._scrollRects = []; | |
caseq
2014/02/27 13:46:55
We could have this set unconditionally in _reset()
malch
2014/02/27 14:58:59
Done.
| |
416 if (!this._layerPayload.scrollRects) | |
417 this._layerPayload.scrollRects = []; | |
caseq
2014/02/27 13:46:55
Why is this necessary? Touching the original paylo
malch
2014/02/27 14:58:59
Done.
| |
418 | |
419 var newRects = this._layerPayload.scrollRects; | |
caseq
2014/02/27 13:46:55
hint: var newRects = this._layerPayload.scrollRect
malch
2014/02/27 14:58:59
Done.
| |
420 for (var i = 0; i < newRects.length; ++i) { | |
421 if (i >= this._scrollRects.length || | |
422 !WebInspector.LayerTreeModel._scrollRectsAreEqual(newRects[i], t his._scrollRects[i])) { | |
423 this._scrollRects[i] = newRects[i]; | |
424 } | |
425 } | |
426 this._scrollRects.splice(newRects.length); | |
390 } | 427 } |
391 } | 428 } |
392 | 429 |
393 /** | 430 /** |
394 * @constructor | 431 * @constructor |
395 * @implements {LayerTreeAgent.Dispatcher} | 432 * @implements {LayerTreeAgent.Dispatcher} |
396 * @param {!WebInspector.LayerTreeModel} layerTreeModel | 433 * @param {!WebInspector.LayerTreeModel} layerTreeModel |
397 */ | 434 */ |
398 WebInspector.LayerTreeDispatcher = function(layerTreeModel) | 435 WebInspector.LayerTreeDispatcher = function(layerTreeModel) |
399 { | 436 { |
400 this._layerTreeModel = layerTreeModel; | 437 this._layerTreeModel = layerTreeModel; |
401 } | 438 } |
402 | 439 |
403 WebInspector.LayerTreeDispatcher.prototype = { | 440 WebInspector.LayerTreeDispatcher.prototype = { |
404 /** | 441 /** |
405 * @param {!Array.<!LayerTreeAgent.Layer>=} payload | 442 * @param {!Array.<!LayerTreeAgent.Layer>=} layers |
406 */ | 443 */ |
407 layerTreeDidChange: function(payload) | 444 layerTreeDidChange: function(layers) |
408 { | 445 { |
409 this._layerTreeModel._layerTreeChanged(payload); | 446 this._layerTreeModel._layerTreeChanged(layers); |
410 }, | 447 }, |
411 | 448 |
412 /** | 449 /** |
413 * @param {!LayerTreeAgent.LayerId} layerId | 450 * @param {!LayerTreeAgent.LayerId} layerId |
414 * @param {!DOMAgent.Rect} clipRect | 451 * @param {!DOMAgent.Rect} clipRect |
415 */ | 452 */ |
416 layerPainted: function(layerId, clipRect) | 453 layerPainted: function(layerId, clipRect) |
417 { | 454 { |
418 this._layerTreeModel._layerPainted(layerId, clipRect); | 455 this._layerTreeModel._layerPainted(layerId, clipRect); |
419 } | 456 } |
420 } | 457 } |
OLD | NEW |