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 18 matching lines...) Expand all Loading... | |
29 */ | 29 */ |
30 | 30 |
31 /** | 31 /** |
32 * @constructor | 32 * @constructor |
33 * @extends {WebInspector.Object} | 33 * @extends {WebInspector.Object} |
34 */ | 34 */ |
35 WebInspector.LayerTreeModel = function() | 35 WebInspector.LayerTreeModel = function() |
36 { | 36 { |
37 WebInspector.Object.call(this); | 37 WebInspector.Object.call(this); |
38 this._layersById = {}; | 38 this._layersById = {}; |
39 this._scrollRectsByLayerId = {}; | |
39 // We fetch layer tree lazily and get paint events asynchronously, so keep t he last painted | 40 // We fetch layer tree lazily and get paint events asynchronously, so keep t he last painted |
40 // rect separate from layer so we can get it after refreshing the tree. | 41 // rect separate from layer so we can get it after refreshing the tree. |
41 this._lastPaintRectByLayerId = {}; | 42 this._lastPaintRectByLayerId = {}; |
42 InspectorBackend.registerLayerTreeDispatcher(new WebInspector.LayerTreeDispa tcher(this)); | 43 InspectorBackend.registerLayerTreeDispatcher(new WebInspector.LayerTreeDispa tcher(this)); |
43 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.Document Updated, this._onDocumentUpdated, this); | 44 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.Document Updated, this._onDocumentUpdated, this); |
44 } | 45 } |
45 | 46 |
46 WebInspector.LayerTreeModel.Events = { | 47 WebInspector.LayerTreeModel.Events = { |
47 LayerTreeChanged: "LayerTreeChanged", | 48 LayerTreeChanged: "LayerTreeChanged", |
48 LayerPainted: "LayerPainted", | 49 LayerPainted: "LayerPainted", |
49 } | 50 } |
50 | 51 |
52 /** | |
53 * @param {!LayerTreeAgent.ScrollRect} first | |
54 * @param {!LayerTreeAgent.ScrollRect} second | |
55 */ | |
56 WebInspector.LayerTreeModel._scrollRectsEqual = function(first, second) | |
57 { | |
58 return first.x === second.x && first.y === second.y && | |
59 first.width === second.width && first.height === second.height && | |
60 first.layerId === second.layerId && first.type === second.type; | |
61 } | |
62 | |
51 WebInspector.LayerTreeModel.prototype = { | 63 WebInspector.LayerTreeModel.prototype = { |
52 disable: function() | 64 disable: function() |
53 { | 65 { |
54 if (!this._enabled) | 66 if (!this._enabled) |
55 return; | 67 return; |
56 this._enabled = false; | 68 this._enabled = false; |
57 LayerTreeAgent.disable(); | 69 LayerTreeAgent.disable(); |
58 }, | 70 }, |
59 | 71 |
60 /** | 72 /** |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 /** | 125 /** |
114 * @param {string} id | 126 * @param {string} id |
115 * @return {?WebInspector.Layer} | 127 * @return {?WebInspector.Layer} |
116 */ | 128 */ |
117 layerById: function(id) | 129 layerById: function(id) |
118 { | 130 { |
119 return this._layersById[id] || null; | 131 return this._layersById[id] || null; |
120 }, | 132 }, |
121 | 133 |
122 /** | 134 /** |
123 * @param {!Array.<!LayerTreeAgent.Layer>} payload | 135 * @param {!Array.<!LayerTreeAgent.Layer>} layers |
124 */ | 136 */ |
125 _repopulate: function(payload) | 137 _repopulate: function(layers) |
126 { | 138 { |
127 var oldLayersById = this._layersById; | 139 var oldLayersById = this._layersById; |
128 this._layersById = {}; | 140 this._layersById = {}; |
129 for (var i = 0; i < payload.length; ++i) { | 141 for (var i = 0; i < layers.length; ++i) { |
130 var layerId = payload[i].layerId; | 142 var layerId = layers[i].layerId; |
131 var layer = oldLayersById[layerId]; | 143 var layer = oldLayersById[layerId]; |
132 if (layer) | 144 if (layer) |
133 layer._reset(payload[i]); | 145 layer._reset(layers[i]); |
134 else | 146 else |
135 layer = new WebInspector.Layer(payload[i]); | 147 layer = new WebInspector.Layer(layers[i]); |
136 this._layersById[layerId] = layer; | 148 this._layersById[layerId] = layer; |
137 var parentId = layer.parentId(); | 149 var parentId = layer.parentId(); |
138 if (!this._contentRoot && layer.nodeId()) | 150 if (!this._contentRoot && layer.nodeId()) |
139 this._contentRoot = layer; | 151 this._contentRoot = layer; |
140 var lastPaintRect = this._lastPaintRectByLayerId[layerId]; | 152 var lastPaintRect = this._lastPaintRectByLayerId[layerId]; |
141 if (lastPaintRect) | 153 if (lastPaintRect) |
142 layer._lastPaintRect = lastPaintRect; | 154 layer._lastPaintRect = lastPaintRect; |
143 if (parentId) { | 155 if (parentId) { |
144 var parent = this._layersById[parentId]; | 156 var parent = this._layersById[parentId]; |
145 if (!parent) | 157 if (!parent) |
146 console.assert(parent, "missing parent " + parentId + " for layer " + layerId); | 158 console.assert(parent, "missing parent " + parentId + " for layer " + layerId); |
147 parent.addChild(layer); | 159 parent.addChild(layer); |
148 } else { | 160 } else { |
149 if (this._root) | 161 if (this._root) |
150 console.assert(false, "Multiple root layers"); | 162 console.assert(false, "Multiple root layers"); |
151 this._root = layer; | 163 this._root = layer; |
152 } | 164 } |
153 } | 165 } |
154 this._lastPaintRectByLayerId = {}; | 166 this._lastPaintRectByLayerId = {}; |
155 }, | 167 }, |
156 | 168 |
157 /** | 169 /** |
158 * @param {!Array.<!LayerTreeAgent.Layer>=} payload | 170 * @param {!Array.<!LayerTreeAgent.ScrollRect>=} scrollRects |
159 */ | 171 */ |
160 _layerTreeChanged: function(payload) | 172 _updateScrollRects: function(scrollRects) |
173 { | |
174 var newScrollRectsByLayerId = {}; | |
175 var i, layerId; | |
176 for (i = 0; i < scrollRects.length; ++i) { | |
177 var scrollRect = scrollRects[i]; | |
178 var layer = this._layersById[scrollRect.layerId]; | |
179 // FIXME | |
caseq
2014/02/24 07:18:06
You can remove this once https://codereview.chromi
malch
2014/02/24 13:59:15
Done.
| |
180 if ((layer.width() !== 0 && layer.height() !== 0) && | |
181 (scrollRect.width > layer.width() || scrollRect.height > layer.h eight()) && | |
182 !layer.parent().parent()) | |
183 continue; | |
184 if (scrollRect.layerId in newScrollRectsByLayerId) | |
185 newScrollRectsByLayerId[scrollRect.layerId].push(scrollRect); | |
186 else | |
187 newScrollRectsByLayerId[scrollRect.layerId] = [scrollRect]; | |
188 } | |
189 for (layerId in this._scrollRectsByLayerId) { | |
190 if (!newScrollRectsByLayerId[layerId]) | |
191 delete this._scrollRectsByLayerId[layerId]; | |
192 } | |
193 for (layerId in newScrollRectsByLayerId) { | |
194 if (!this._scrollRectsByLayerId[layerId]) | |
195 this._scrollRectsByLayerId[layerId] = []; | |
196 var oldScrollRects = this._scrollRectsByLayerId[layerId]; | |
197 for (i = 0; i < newScrollRectsByLayerId[layerId].length; ++i) { | |
198 if (i >= oldScrollRects.length || | |
199 !WebInspector.LayerTreeModel._scrollRectsEqual(newScrollRect sByLayerId[layerId][i], oldScrollRects[i])) { | |
200 oldScrollRects[i] = newScrollRectsByLayerId[layerId][i]; | |
201 } | |
202 } | |
203 oldScrollRects.splice(newScrollRectsByLayerId[layerId].length); | |
204 } | |
205 }, | |
206 | |
207 /** | |
208 * @param {!Array.<!LayerTreeAgent.Layer>=} layers | |
209 * @param {!Array.<!LayerTreeAgent.ScrollRect>=} scrollRects | |
210 */ | |
211 _layerTreeChanged: function(layers, scrollRects) | |
161 { | 212 { |
162 this._root = null; | 213 this._root = null; |
163 this._contentRoot = null; | 214 this._contentRoot = null; |
164 // Payload will be null when not in the composited mode. | 215 // Payload will be null when not in the composited mode. |
165 if (payload) | 216 if (layers) |
166 this._repopulate(payload); | 217 this._repopulate(layers); |
218 if (scrollRects) | |
219 this._updateScrollRects(scrollRects); | |
167 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr eeChanged); | 220 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr eeChanged); |
168 }, | 221 }, |
169 | 222 |
170 /** | 223 /** |
171 * @param {!LayerTreeAgent.LayerId} layerId | 224 * @param {!LayerTreeAgent.LayerId} layerId |
172 * @param {!DOMAgent.Rect} clipRect | 225 * @param {!DOMAgent.Rect} clipRect |
173 */ | 226 */ |
174 _layerPainted: function(layerId, clipRect) | 227 _layerPainted: function(layerId, clipRect) |
175 { | 228 { |
176 var layer = this._layersById[layerId]; | 229 var layer = this._layersById[layerId]; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 * @implements {LayerTreeAgent.Dispatcher} | 448 * @implements {LayerTreeAgent.Dispatcher} |
396 * @param {!WebInspector.LayerTreeModel} layerTreeModel | 449 * @param {!WebInspector.LayerTreeModel} layerTreeModel |
397 */ | 450 */ |
398 WebInspector.LayerTreeDispatcher = function(layerTreeModel) | 451 WebInspector.LayerTreeDispatcher = function(layerTreeModel) |
399 { | 452 { |
400 this._layerTreeModel = layerTreeModel; | 453 this._layerTreeModel = layerTreeModel; |
401 } | 454 } |
402 | 455 |
403 WebInspector.LayerTreeDispatcher.prototype = { | 456 WebInspector.LayerTreeDispatcher.prototype = { |
404 /** | 457 /** |
405 * @param {!Array.<!LayerTreeAgent.Layer>=} payload | 458 * @param {!Array.<!LayerTreeAgent.Layer>=} layers |
459 * @param {!Array.<!LayerTreeAgent.ScrollRect>=} scrollRects | |
406 */ | 460 */ |
407 layerTreeDidChange: function(payload) | 461 layerTreeDidChange: function(layers, scrollRects) |
408 { | 462 { |
409 this._layerTreeModel._layerTreeChanged(payload); | 463 this._layerTreeModel._layerTreeChanged(layers, scrollRects); |
410 }, | 464 }, |
411 | 465 |
412 /** | 466 /** |
413 * @param {!LayerTreeAgent.LayerId} layerId | 467 * @param {!LayerTreeAgent.LayerId} layerId |
414 * @param {!DOMAgent.Rect} clipRect | 468 * @param {!DOMAgent.Rect} clipRect |
415 */ | 469 */ |
416 layerPainted: function(layerId, clipRect) | 470 layerPainted: function(layerId, clipRect) |
417 { | 471 { |
418 this._layerTreeModel._layerPainted(layerId, clipRect); | 472 this._layerTreeModel._layerPainted(layerId, clipRect); |
419 } | 473 } |
420 } | 474 } |
OLD | NEW |