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
|
/*
* Copyright (C) 2013 Google 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:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
* OWNER OR 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.
*/
/**
* @constructor
* @param {!WebInspector.LayerTreeModel} model
* @extends {WebInspector.View}
*/
WebInspector.LayerDetailsView = function(model)
{
WebInspector.View.call(this);
this.element.classList.add("fill");
this.element.classList.add("layer-details-view");
this._emptyView = new WebInspector.EmptyView(WebInspector.UIString("Select a layer to see its details"));
this._createTable();
this._model = model;
this._model.addEventListener(WebInspector.LayerTreeModel.Events.LayerTreeChanged, this._onLayerTreeUpdated, this);
this._model.addEventListener(WebInspector.LayerTreeModel.Events.LayerPainted, this._onLayerPainted, this);
}
/**
* @type {!Object.<string, string>}
*/
WebInspector.LayerDetailsView.CompositingReasonDetail = {
"transform3D": WebInspector.UIString("Composition due to association with an element with a CSS 3D transform."),
"video": WebInspector.UIString("Composition due to association with a <video> element."),
"canvas": WebInspector.UIString("Composition due to the element being a <canvas> element."),
"plugin": WebInspector.UIString("Composition due to association with a plugin."),
"iFrame": WebInspector.UIString("Composition due to association with an <iframe> element."),
"backfaceVisibilityHidden": WebInspector.UIString("Composition due to association with an element with a \"backface-visibility: hidden\" style."),
"animation": WebInspector.UIString("Composition due to association with an animated element."),
"filters": WebInspector.UIString("Composition due to association with an element with CSS filters applied."),
"positionFixed": WebInspector.UIString("Composition due to association with an element with a \"position: fixed\" style."),
"positionSticky": WebInspector.UIString("Composition due to association with an element with a \"position: sticky\" style."),
"overflowScrollingTouch": WebInspector.UIString("Composition due to association with an element with a \"overflow-scrolling: touch\" style."),
"blending": WebInspector.UIString("Composition due to association with an element that has blend mode other than \"normal\"."),
"assumedOverlap": WebInspector.UIString("Composition due to association with an element that may overlap other composited elements."),
"overlap": WebInspector.UIString("Composition due to association with an element overlapping other composited elements."),
"negativeZIndexChildren": WebInspector.UIString("Composition due to association with an element with descendants that have a negative z-index."),
"transformWithCompositedDescendants": WebInspector.UIString("Composition due to association with an element with composited descendants."),
"opacityWithCompositedDescendants": WebInspector.UIString("Composition due to association with an element with opacity applied and composited descendants."),
"maskWithCompositedDescendants": WebInspector.UIString("Composition due to association with a masked element and composited descendants."),
"reflectionWithCompositedDescendants": WebInspector.UIString("Composition due to association with an element with a reflection and composited descendants."),
"filterWithCompositedDescendants": WebInspector.UIString("Composition due to association with an element with CSS filters applied and composited descendants."),
"blendingWithCompositedDescendants": WebInspector.UIString("Composition due to association with an element with CSS blending applied and composited descendants."),
"clipsCompositingDescendants": WebInspector.UIString("Composition due to association with an element clipping compositing descendants."),
"perspective": WebInspector.UIString("Composition due to association with an element with perspective applied."),
"preserve3D": WebInspector.UIString("Composition due to association with an element with a \"transform-style: preserve-3d\" style."),
"root": WebInspector.UIString("Root layer."),
"layerForClip": WebInspector.UIString("Layer for clip."),
"layerForScrollbar": WebInspector.UIString("Layer for scrollbar."),
"layerForScrollingContainer": WebInspector.UIString("Layer for scrolling container."),
"layerForForeground": WebInspector.UIString("Layer for foreground."),
"layerForBackground": WebInspector.UIString("Layer for background."),
"layerForMask": WebInspector.UIString("Layer for mask."),
"layerForVideoOverlay": WebInspector.UIString("Layer for video overlay.")
};
WebInspector.LayerDetailsView.prototype = {
/**
* @param {?WebInspector.Layer} layer
*/
setLayer: function(layer)
{
this._layer = layer;
if (this.isShowing())
this._update();
},
wasShown: function()
{
WebInspector.View.prototype.wasShown.call(this);
this._update();
},
_onLayerTreeUpdated: function()
{
if (this.isShowing())
this._update();
},
/**
* @param {!WebInspector.Event} event
*/
_onLayerPainted: function(event)
{
var layer = /** @type {!WebInspector.Layer} */ (event.data);
if (this._layer === layer)
this._paintCountCell.textContent = layer.paintCount();
},
_update: function()
{
if (!this._layer) {
this._tableElement.remove();
this._emptyView.show(this.element);
return;
}
this._emptyView.detach();
this.element.appendChild(this._tableElement);
this._positionCell.textContent = WebInspector.UIString("%d,%d", this._layer.offsetX(), this._layer.offsetY());
this._sizeCell.textContent = WebInspector.UIString("%d × %d", this._layer.width(), this._layer.height());
this._paintCountCell.textContent = this._layer.paintCount();
const bytesPerPixel = 4;
this._memoryEstimateCell.textContent = Number.bytesToString(this._layer.invisible() ? 0 : this._layer.width() * this._layer.height() * bytesPerPixel);
this._layer.requestCompositingReasons(this._updateCompositingReasons.bind(this));
},
_createTable: function()
{
this._tableElement = this.element.createChild("table");
this._tbodyElement = this._tableElement.createChild("tbody");
this._positionCell = this._createRow(WebInspector.UIString("Position in parent:"));
this._sizeCell = this._createRow(WebInspector.UIString("Size:"));
this._compositingReasonsCell = this._createRow(WebInspector.UIString("Compositing Reasons:"));
this._memoryEstimateCell = this._createRow(WebInspector.UIString("Memory estimate:"));
this._paintCountCell = this._createRow(WebInspector.UIString("Paint count:"));
},
/**
* @param {string} title
*/
_createRow: function(title)
{
var tr = this._tbodyElement.createChild("tr");
var titleCell = tr.createChild("td");
titleCell.textContent = title;
return tr.createChild("td");
},
/**
* @param {!Array.<string>} compositingReasons
*/
_updateCompositingReasons: function(compositingReasons)
{
if (!compositingReasons || !compositingReasons.length) {
this._compositingReasonsCell.textContent = "n/a";
return;
}
var fragment = document.createDocumentFragment();
for (var i = 0; i < compositingReasons.length; ++i) {
if (i)
fragment.appendChild(document.createTextNode(","));
var span = document.createElement("span");
span.title = WebInspector.LayerDetailsView.CompositingReasonDetail[compositingReasons[i]] || "";
span.textContent = compositingReasons[i];
fragment.appendChild(span);
}
this._compositingReasonsCell.removeChildren();
this._compositingReasonsCell.appendChild(fragment);
},
__proto__: WebInspector.View.prototype
}
|