1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
/*
* Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
WebInspector.LayerTreeDetailsSidebarPanel = class LayerTreeDetailsSidebarPanel extends WebInspector.DOMDetailsSidebarPanel
{
constructor()
{
super("layer-tree", WebInspector.UIString("Layers"), WebInspector.UIString("Layer"));
this._dataGridNodesByLayerId = new Map;
this.element.classList.add("layer-tree");
WebInspector.showShadowDOMSetting.addEventListener(WebInspector.Setting.Event.Changed, this._showShadowDOMSettingChanged, this);
window.addEventListener("resize", this._windowResized.bind(this));
this._buildLayerInfoSection();
this._buildDataGridSection();
this._buildBottomBar();
}
// DetailsSidebarPanel Overrides.
shown()
{
WebInspector.layerTreeManager.addEventListener(WebInspector.LayerTreeManager.Event.LayerTreeDidChange, this._layerTreeDidChange, this);
console.assert(this.parentSidebar);
this.needsRefresh();
super.shown();
}
hidden()
{
WebInspector.layerTreeManager.removeEventListener(WebInspector.LayerTreeManager.Event.LayerTreeDidChange, this._layerTreeDidChange, this);
super.hidden();
}
refresh()
{
if (!this.domNode)
return;
WebInspector.layerTreeManager.layersForNode(this.domNode, function(layerForNode, childLayers) {
this._unfilteredChildLayers = childLayers;
this._updateDisplayWithLayers(layerForNode, childLayers);
}.bind(this));
}
// DOMDetailsSidebarPanel Overrides
supportsDOMNode(nodeToInspect)
{
return WebInspector.layerTreeManager.supported && nodeToInspect.nodeType() === Node.ELEMENT_NODE;
}
// Private
_layerTreeDidChange(event)
{
this.needsRefresh();
}
_showShadowDOMSettingChanged(event)
{
if (this.selected)
this._updateDisplayWithLayers(this._layerForNode, this._unfilteredChildLayers);
}
_windowResized(event)
{
if (this._popover && this._popover.visible)
this._updatePopoverForSelectedNode();
}
_buildLayerInfoSection()
{
var rows = this._layerInfoRows = {};
var rowsArray = [];
rowsArray.push(rows["Width"] = new WebInspector.DetailsSectionSimpleRow(WebInspector.UIString("Width")));
rowsArray.push(rows["Height"] = new WebInspector.DetailsSectionSimpleRow(WebInspector.UIString("Height")));
rowsArray.push(rows["Paints"] = new WebInspector.DetailsSectionSimpleRow(WebInspector.UIString("Paints")));
rowsArray.push(rows["Memory"] = new WebInspector.DetailsSectionSimpleRow(WebInspector.UIString("Memory")));
this._layerInfoGroup = new WebInspector.DetailsSectionGroup(rowsArray);
var emptyRow = new WebInspector.DetailsSectionRow(WebInspector.UIString("No Layer Available"));
emptyRow.showEmptyMessage();
this._noLayerInformationGroup = new WebInspector.DetailsSectionGroup([emptyRow]);
this._layerInfoSection = new WebInspector.DetailsSection("layer-info", WebInspector.UIString("Layer Info"), [this._noLayerInformationGroup]);
this.contentView.element.appendChild(this._layerInfoSection.element);
}
_buildDataGridSection()
{
var columns = {name: {}, paintCount: {}, memory: {}};
columns.name.title = WebInspector.UIString("Node");
columns.name.sortable = false;
columns.paintCount.title = WebInspector.UIString("Paints");
columns.paintCount.sortable = true;
columns.paintCount.aligned = "right";
columns.paintCount.width = "50px";
columns.memory.title = WebInspector.UIString("Memory");
columns.memory.sortable = true;
columns.memory.aligned = "right";
columns.memory.width = "70px";
this._dataGrid = new WebInspector.DataGrid(columns);
this._dataGrid.addEventListener(WebInspector.DataGrid.Event.SortChanged, this._sortDataGrid, this);
this._dataGrid.addEventListener(WebInspector.DataGrid.Event.SelectedNodeChanged, this._selectedDataGridNodeChanged, this);
this.sortColumnIdentifierSetting = new WebInspector.Setting("layer-tree-details-sidebar-panel-sort", "memory");
this.sortOrderSetting = new WebInspector.Setting("layer-tree-details-sidebar-panel-sort-order", WebInspector.DataGrid.SortOrder.Descending);
var element = this._dataGrid.element;
element.classList.add("inline");
element.addEventListener("focus", this._dataGridGainedFocus.bind(this), false);
element.addEventListener("blur", this._dataGridLostFocus.bind(this), false);
element.addEventListener("click", this._dataGridWasClicked.bind(this), false);
this._childLayersRow = new WebInspector.DetailsSectionDataGridRow(null, WebInspector.UIString("No Child Layers"));
var group = new WebInspector.DetailsSectionGroup([this._childLayersRow]);
var section = new WebInspector.DetailsSection("layer-children", WebInspector.UIString("Child Layers"), [group], null, true);
this.contentView.element.appendChild(section.element);
}
_buildBottomBar()
{
var bottomBar = this.element.appendChild(document.createElement("div"));
bottomBar.className = "bottom-bar";
this._layersCountLabel = bottomBar.appendChild(document.createElement("div"));
this._layersCountLabel.className = "layers-count-label";
this._layersMemoryLabel = bottomBar.appendChild(document.createElement("div"));
this._layersMemoryLabel.className = "layers-memory-label";
}
_sortDataGrid()
{
var sortColumnIdentifier = this._dataGrid.sortColumnIdentifier;
function comparator(a, b)
{
var item1 = a.layer[sortColumnIdentifier] || 0;
var item2 = b.layer[sortColumnIdentifier] || 0;
return item1 - item2;
}
this._dataGrid.sortNodes(comparator);
this._updatePopoverForSelectedNode();
}
_selectedDataGridNodeChanged()
{
if (this._dataGrid.selectedNode) {
this._highlightSelectedNode();
this._showPopoverForSelectedNode();
} else {
WebInspector.domTreeManager.hideDOMNodeHighlight();
this._hidePopover();
}
}
_dataGridGainedFocus(event)
{
this._highlightSelectedNode();
this._showPopoverForSelectedNode();
}
_dataGridLostFocus(event)
{
WebInspector.domTreeManager.hideDOMNodeHighlight();
this._hidePopover();
}
_dataGridWasClicked(event)
{
if (this._dataGrid.selectedNode && event.target.parentNode.classList.contains("filler"))
this._dataGrid.selectedNode.deselect();
}
_highlightSelectedNode()
{
var dataGridNode = this._dataGrid.selectedNode;
if (!dataGridNode)
return;
var layer = dataGridNode.layer;
if (layer.isGeneratedContent || layer.isReflection || layer.isAnonymous)
WebInspector.domTreeManager.highlightRect(layer.bounds, true);
else
WebInspector.domTreeManager.highlightDOMNode(layer.nodeId);
}
_updateDisplayWithLayers(layerForNode, childLayers)
{
if (!WebInspector.showShadowDOMSetting.value) {
childLayers = childLayers.filter(function(layer) {
return !layer.isInShadowTree;
});
}
this._updateLayerInfoSection(layerForNode);
this._updateDataGrid(layerForNode, childLayers);
this._updateMetrics(layerForNode, childLayers);
this._layerForNode = layerForNode;
this._childLayers = childLayers;
}
_updateLayerInfoSection(layer)
{
this._layerInfoSection.groups = layer ? [this._layerInfoGroup] : [this._noLayerInformationGroup];
if (!layer)
return;
this._layerInfoRows["Memory"].value = Number.bytesToString(layer.memory);
this._layerInfoRows["Width"].value = layer.compositedBounds.width + "px";
this._layerInfoRows["Height"].value = layer.compositedBounds.height + "px";
this._layerInfoRows["Paints"].value = layer.paintCount + "";
}
_updateDataGrid(layerForNode, childLayers)
{
let dataGrid = this._dataGrid;
let mutations = WebInspector.layerTreeManager.layerTreeMutations(this._childLayers, childLayers);
mutations.removals.forEach(function(layer) {
let node = this._dataGridNodesByLayerId.get(layer.layerId);
if (node) {
dataGrid.removeChild(node);
this._dataGridNodesByLayerId.delete(layer.layerId);
}
}, this);
mutations.additions.forEach(function(layer) {
let node = this._dataGridNodeForLayer(layer);
if (node)
dataGrid.appendChild(node);
}, this);
mutations.preserved.forEach(function(layer) {
let node = this._dataGridNodesByLayerId.get(layer.layerId);
if (node)
node.layer = layer;
}, this);
this._sortDataGrid();
this._childLayersRow.dataGrid = !isEmptyObject(childLayers) ? this._dataGrid : null;
}
_dataGridNodeForLayer(layer)
{
let node = new WebInspector.LayerTreeDataGridNode(layer);
this._dataGridNodesByLayerId.set(layer.layerId, node);
return node;
}
_updateMetrics(layerForNode, childLayers)
{
var layerCount = 0;
var totalMemory = 0;
if (layerForNode) {
layerCount++;
totalMemory += layerForNode.memory || 0;
}
childLayers.forEach(function(layer) {
layerCount++;
totalMemory += layer.memory || 0;
});
this._layersCountLabel.textContent = WebInspector.UIString("Layer Count: %d").format(layerCount);
this._layersMemoryLabel.textContent = WebInspector.UIString("Memory: %s").format(Number.bytesToString(totalMemory));
}
_showPopoverForSelectedNode()
{
var dataGridNode = this._dataGrid.selectedNode;
if (!dataGridNode)
return;
this._contentForPopover(dataGridNode.layer, function(content) {
if (dataGridNode === this._dataGrid.selectedNode)
this._updatePopoverForSelectedNode(content);
}.bind(this));
}
_updatePopoverForSelectedNode(content)
{
var dataGridNode = this._dataGrid.selectedNode;
if (!dataGridNode)
return;
var popover = this._popover;
if (!popover)
popover = this._popover = new WebInspector.Popover;
var targetFrame = WebInspector.Rect.rectFromClientRect(dataGridNode.element.getBoundingClientRect());
if (content)
popover.content = content;
popover.present(targetFrame.pad(2), [WebInspector.RectEdge.MIN_X]);
}
_hidePopover()
{
if (this._popover)
this._popover.dismiss();
}
_contentForPopover(layer, callback)
{
var content = document.createElement("div");
content.className = "layer-tree-popover";
content.appendChild(document.createElement("p")).textContent = WebInspector.UIString("Reasons for compositing:");
var list = content.appendChild(document.createElement("ul"));
WebInspector.layerTreeManager.reasonsForCompositingLayer(layer, function(compositingReasons) {
if (isEmptyObject(compositingReasons)) {
callback(content);
return;
}
this._populateListOfCompositingReasons(list, compositingReasons);
callback(content);
}.bind(this));
return content;
}
_populateListOfCompositingReasons(list, compositingReasons)
{
function addReason(reason)
{
list.appendChild(document.createElement("li")).textContent = reason;
}
if (compositingReasons.transform3D)
addReason(WebInspector.UIString("Element has a 3D transform"));
if (compositingReasons.video)
addReason(WebInspector.UIString("Element is <video>"));
if (compositingReasons.canvas)
addReason(WebInspector.UIString("Element is <canvas>"));
if (compositingReasons.plugin)
addReason(WebInspector.UIString("Element is a plug-in"));
if (compositingReasons.iFrame)
addReason(WebInspector.UIString("Element is <iframe>"));
if (compositingReasons.backfaceVisibilityHidden)
addReason(WebInspector.UIString("Element has “backface-visibility: hidden” style"));
if (compositingReasons.clipsCompositingDescendants)
addReason(WebInspector.UIString("Element clips compositing descendants"));
if (compositingReasons.animation)
addReason(WebInspector.UIString("Element is animated"));
if (compositingReasons.filters)
addReason(WebInspector.UIString("Element has CSS filters applied"));
if (compositingReasons.positionFixed)
addReason(WebInspector.UIString("Element has “position: fixed” style"));
if (compositingReasons.positionSticky)
addReason(WebInspector.UIString("Element has “position: sticky” style"));
if (compositingReasons.overflowScrollingTouch)
addReason(WebInspector.UIString("Element has “-webkit-overflow-scrolling: touch” style"));
if (compositingReasons.stacking)
addReason(WebInspector.UIString("Element establishes a stacking context"));
if (compositingReasons.overlap)
addReason(WebInspector.UIString("Element overlaps other compositing element"));
if (compositingReasons.negativeZIndexChildren)
addReason(WebInspector.UIString("Element has children with a negative z-index"));
if (compositingReasons.transformWithCompositedDescendants)
addReason(WebInspector.UIString("Element has a 2D transform and composited descendants"));
if (compositingReasons.opacityWithCompositedDescendants)
addReason(WebInspector.UIString("Element has opacity applied and composited descendants"));
if (compositingReasons.maskWithCompositedDescendants)
addReason(WebInspector.UIString("Element is masked and composited descendants"));
if (compositingReasons.reflectionWithCompositedDescendants)
addReason(WebInspector.UIString("Element has a reflection and composited descendants"));
if (compositingReasons.filterWithCompositedDescendants)
addReason(WebInspector.UIString("Element has CSS filters applied and composited descendants"));
if (compositingReasons.blendingWithCompositedDescendants)
addReason(WebInspector.UIString("Element has CSS blending applied and composited descendants"));
if (compositingReasons.isolatesCompositedBlendingDescendants)
addReason(WebInspector.UIString("Element is a stacking context and has composited descendants with CSS blending applied"));
if (compositingReasons.perspective)
addReason(WebInspector.UIString("Element has perspective applied"));
if (compositingReasons.preserve3D)
addReason(WebInspector.UIString("Element has “transform-style: preserve-3d” style"));
if (compositingReasons.willChange)
addReason(WebInspector.UIString("Element has “will-change” style with includes opacity, transform, transform-style, perspective, filter or backdrop-filter"));
if (compositingReasons.root)
addReason(WebInspector.UIString("Element is the root element"));
if (compositingReasons.blending)
addReason(WebInspector.UIString("Element has “blend-mode” style"));
}
};
|