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