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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/timeline/LayerViewHost.js

Issue 2358253002: DevTools: extract a component for layer viewer (Closed)
Patch Set: renamed the banner Created 4 years, 2 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
(Empty)
1 /*
2 * Copyright 2015 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 /**
8 * @interface
9 */
10 WebInspector.LayerView = function()
11 {
12 }
13
14 WebInspector.LayerView.prototype = {
15 /**
16 * @param {?WebInspector.LayerView.Selection} selection
17 */
18 hoverObject: function(selection) { },
19
20 /**
21 * @param {?WebInspector.LayerView.Selection} selection
22 */
23 selectObject: function(selection) { },
24
25 /**
26 * @param {?WebInspector.LayerTreeBase} layerTree
27 */
28 setLayerTree: function(layerTree) { }
29 }
30
31
32 /**
33 * @constructor
34 * @param {!WebInspector.LayerView.Selection.Type} type
35 * @param {!WebInspector.Layer} layer
36 */
37 WebInspector.LayerView.Selection = function(type, layer)
38 {
39 this._type = type;
40 this._layer = layer;
41 }
42
43 /**
44 * @enum {string}
45 */
46 WebInspector.LayerView.Selection.Type = {
47 Layer: "Layer",
48 ScrollRect: "ScrollRect",
49 Tile: "Tile",
50 }
51
52 /**
53 * @param {?WebInspector.LayerView.Selection} a
54 * @param {?WebInspector.LayerView.Selection} b
55 * @return {boolean}
56 */
57 WebInspector.LayerView.Selection.isEqual = function(a, b)
58 {
59 return a && b ? a._isEqual(b) : a === b;
60 }
61
62 WebInspector.LayerView.Selection.prototype = {
63 /**
64 * @return {!WebInspector.LayerView.Selection.Type}
65 */
66 type: function()
67 {
68 return this._type;
69 },
70
71 /**
72 * @return {!WebInspector.Layer}
73 */
74 layer: function()
75 {
76 return this._layer;
77 },
78
79 /**
80 * @param {!WebInspector.LayerView.Selection} other
81 * @return {boolean}
82 */
83 _isEqual: function(other)
84 {
85 return false;
86 }
87 }
88
89 /**
90 * @constructor
91 * @extends {WebInspector.LayerView.Selection}
92 * @param {!WebInspector.Layer} layer
93 */
94 WebInspector.LayerView.LayerSelection = function(layer)
95 {
96 console.assert(layer, "LayerSelection with empty layer");
97 WebInspector.LayerView.Selection.call(this, WebInspector.LayerView.Selection .Type.Layer, layer);
98 }
99
100 WebInspector.LayerView.LayerSelection.prototype = {
101 /**
102 * @override
103 * @param {!WebInspector.LayerView.Selection} other
104 * @return {boolean}
105 */
106 _isEqual: function(other)
107 {
108 return other._type === WebInspector.LayerView.Selection.Type.Layer && ot her.layer().id() === this.layer().id();
109 },
110
111 __proto__: WebInspector.LayerView.Selection.prototype
112 }
113
114 /**
115 * @constructor
116 * @extends {WebInspector.LayerView.Selection}
117 * @param {!WebInspector.Layer} layer
118 * @param {number} scrollRectIndex
119 */
120 WebInspector.LayerView.ScrollRectSelection = function(layer, scrollRectIndex)
121 {
122 WebInspector.LayerView.Selection.call(this, WebInspector.LayerView.Selection .Type.ScrollRect, layer);
123 this.scrollRectIndex = scrollRectIndex;
124 }
125
126 WebInspector.LayerView.ScrollRectSelection.prototype = {
127 /**
128 * @override
129 * @param {!WebInspector.LayerView.Selection} other
130 * @return {boolean}
131 */
132 _isEqual: function(other)
133 {
134 return other._type === WebInspector.LayerView.Selection.Type.ScrollRect &&
135 this.layer().id() === other.layer().id() && this.scrollRectIndex === other.scrollRectIndex;
136 },
137
138 __proto__: WebInspector.LayerView.Selection.prototype
139 }
140
141 /**
142 * @constructor
143 * @extends {WebInspector.LayerView.Selection}
144 * @param {!WebInspector.Layer} layer
145 * @param {!WebInspector.TracingModel.Event} traceEvent
146 */
147 WebInspector.LayerView.TileSelection = function(layer, traceEvent)
148 {
149 WebInspector.LayerView.Selection.call(this, WebInspector.LayerView.Selection .Type.Tile, layer);
150 this._traceEvent = traceEvent;
151 }
152
153 WebInspector.LayerView.TileSelection.prototype = {
154 /**
155 * @override
156 * @param {!WebInspector.LayerView.Selection} other
157 * @return {boolean}
158 */
159 _isEqual: function(other)
160 {
161 return other._type === WebInspector.LayerView.Selection.Type.Tile
162 && this.layer().id() === other.layer().id() && this.traceEvent === o ther.traceEvent;
163 },
164
165 /**
166 * @return {!WebInspector.TracingModel.Event}
167 */
168 traceEvent: function()
169 {
170 return this._traceEvent;
171 },
172
173 __proto__: WebInspector.LayerView.Selection.prototype
174 }
175
176 /**
177 * @constructor
178 */
179 WebInspector.LayerViewHost = function()
180 {
181 /** @type {!Array.<!WebInspector.LayerView>} */
182 this._views = [];
183 this._selectedObject = null;
184 this._hoveredObject = null;
185 this._showInternalLayersSetting = WebInspector.settings.createSetting("layer sShowInternalLayers", false);
186 }
187
188 WebInspector.LayerViewHost.prototype = {
189 /**
190 * @param {!WebInspector.LayerView} layerView
191 */
192 registerView: function(layerView)
193 {
194 this._views.push(layerView);
195 },
196
197 /**
198 * @param {?WebInspector.LayerTreeBase} layerTree
199 */
200 setLayerTree: function(layerTree)
201 {
202 this._target = layerTree.target();
203 var selectedLayer = this._selectedObject && this._selectedObject.layer() ;
204 if (selectedLayer && (!layerTree || !layerTree.layerById(selectedLayer.i d())))
205 this.selectObject(null);
206 var hoveredLayer = this._hoveredObject && this._hoveredObject.layer();
207 if (hoveredLayer && (!layerTree || !layerTree.layerById(hoveredLayer.id( ))))
208 this.hoverObject(null);
209 for (var view of this._views)
210 view.setLayerTree(layerTree);
211 },
212
213 /**
214 * @param {?WebInspector.LayerView.Selection} selection
215 */
216 hoverObject: function(selection)
217 {
218 if (WebInspector.LayerView.Selection.isEqual(this._hoveredObject, select ion))
219 return;
220 this._hoveredObject = selection;
221 var layer = selection && selection.layer();
222 this._toggleNodeHighlight(layer ? layer.nodeForSelfOrAncestor() : null);
223 for (var view of this._views)
224 view.hoverObject(selection);
225 },
226
227 /**
228 * @param {?WebInspector.LayerView.Selection} selection
229 */
230 selectObject: function(selection)
231 {
232 if (WebInspector.LayerView.Selection.isEqual(this._selectedObject, selec tion))
233 return;
234 this._selectedObject = selection;
235 for (var view of this._views)
236 view.selectObject(selection);
237 },
238
239 /**
240 * @return {?WebInspector.LayerView.Selection}
241 */
242 selection: function()
243 {
244 return this._selectedObject;
245 },
246
247 /**
248 * @param {!WebInspector.ContextMenu} contextMenu
249 * @param {?WebInspector.LayerView.Selection} selection
250 */
251 showContextMenu: function(contextMenu, selection)
252 {
253 contextMenu.appendCheckboxItem(WebInspector.UIString("Show internal laye rs"), this._toggleShowInternalLayers.bind(this), this._showInternalLayersSetting .get());
254 var node = selection && selection.layer() && selection.layer().nodeForSe lfOrAncestor();
255 if (node)
256 contextMenu.appendApplicableItems(node);
257 contextMenu.show();
258 },
259
260 /**
261 * @return {!WebInspector.Setting}
262 */
263 showInternalLayersSetting: function()
264 {
265 return this._showInternalLayersSetting;
266 },
267
268 _toggleShowInternalLayers: function()
269 {
270 this._showInternalLayersSetting.set(!this._showInternalLayersSetting.get ());
271 },
272
273 /**
274 * @param {?WebInspector.DOMNode} node
275 */
276 _toggleNodeHighlight: function(node)
277 {
278 if (node) {
279 node.highlightForTwoSeconds();
280 return;
281 }
282 WebInspector.DOMModel.hideDOMNodeHighlight();
283 }
284 }
285
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698