Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: Source/devtools/front_end/LayerTreeModel.js

Issue 166273018: Added showing slow scroll rectangles in Layers panel. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: More fixes. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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) &&
caseq 2014/02/20 11:14:24 No need for parenthesis here.
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
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
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 for (i = 0; i < newScrollRectsByLayerId[layerId].length; ++i) {
197 if (i >= this._scrollRectsByLayerId[layerId].length ||
198 !WebInspector.LayerTreeModel._scrollRectsEqual(newScrollRect sByLayerId[layerId][i], this._scrollRectsByLayerId[layerId][i]))
199 this._scrollRectsByLayerId[layerId][i] = newScrollRectsByLay erId[layerId][i];
caseq 2014/02/20 11:14:24 style: this line needs to go into a { block } beca
200 }
201 this._scrollRectsByLayerId[layerId].splice(newScrollRectsByLayerId[l ayerId].length);
202 }
203 },
204
205 /**
206 * @param {!Array.<!LayerTreeAgent.Layer>=} layers
207 * @param {!Array.<!LayerTreeAgent.ScrollRect>=} scrollRects
208 */
209 _layerTreeChanged: function(layers, scrollRects)
161 { 210 {
162 this._root = null; 211 this._root = null;
163 this._contentRoot = null; 212 this._contentRoot = null;
164 // Payload will be null when not in the composited mode. 213 // Payload will be null when not in the composited mode.
165 if (payload) 214 if (layers)
166 this._repopulate(payload); 215 this._repopulate(layers);
216 if (scrollRects)
217 this._updateScrollRects(scrollRects);
167 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr eeChanged); 218 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr eeChanged);
168 }, 219 },
169 220
170 /** 221 /**
171 * @param {!LayerTreeAgent.LayerId} layerId 222 * @param {!LayerTreeAgent.LayerId} layerId
172 * @param {!DOMAgent.Rect} clipRect 223 * @param {!DOMAgent.Rect} clipRect
173 */ 224 */
174 _layerPainted: function(layerId, clipRect) 225 _layerPainted: function(layerId, clipRect)
175 { 226 {
176 var layer = this._layersById[layerId]; 227 var layer = this._layersById[layerId];
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 * @implements {LayerTreeAgent.Dispatcher} 446 * @implements {LayerTreeAgent.Dispatcher}
396 * @param {!WebInspector.LayerTreeModel} layerTreeModel 447 * @param {!WebInspector.LayerTreeModel} layerTreeModel
397 */ 448 */
398 WebInspector.LayerTreeDispatcher = function(layerTreeModel) 449 WebInspector.LayerTreeDispatcher = function(layerTreeModel)
399 { 450 {
400 this._layerTreeModel = layerTreeModel; 451 this._layerTreeModel = layerTreeModel;
401 } 452 }
402 453
403 WebInspector.LayerTreeDispatcher.prototype = { 454 WebInspector.LayerTreeDispatcher.prototype = {
404 /** 455 /**
405 * @param {!Array.<!LayerTreeAgent.Layer>=} payload 456 * @param {!Array.<!LayerTreeAgent.Layer>=} layers
457 * @param {!Array.<!LayerTreeAgent.ScrollRect>=} scrollRects
406 */ 458 */
407 layerTreeDidChange: function(payload) 459 layerTreeDidChange: function(layers, scrollRects)
408 { 460 {
409 this._layerTreeModel._layerTreeChanged(payload); 461 this._layerTreeModel._layerTreeChanged(layers, scrollRects);
410 }, 462 },
411 463
412 /** 464 /**
413 * @param {!LayerTreeAgent.LayerId} layerId 465 * @param {!LayerTreeAgent.LayerId} layerId
414 * @param {!DOMAgent.Rect} clipRect 466 * @param {!DOMAgent.Rect} clipRect
415 */ 467 */
416 layerPainted: function(layerId, clipRect) 468 layerPainted: function(layerId, clipRect)
417 { 469 {
418 this._layerTreeModel._layerPainted(layerId, clipRect); 470 this._layerTreeModel._layerPainted(layerId, clipRect);
419 } 471 }
420 } 472 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698