| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 /** | |
| 32 * @constructor | |
| 33 * @param {!WebInspector.LayerViewHost} layerViewHost | |
| 34 * @extends {WebInspector.Widget} | |
| 35 * @implements {WebInspector.LayerView} | |
| 36 */ | |
| 37 WebInspector.LayerDetailsView = function(layerViewHost) | |
| 38 { | |
| 39 WebInspector.Widget.call(this); | |
| 40 this.element.classList.add("layer-details-view"); | |
| 41 this._layerViewHost = layerViewHost; | |
| 42 this._layerViewHost.registerView(this); | |
| 43 this._emptyWidget = new WebInspector.EmptyWidget(WebInspector.UIString("Sele
ct a layer to see its details")); | |
| 44 this._buildContent(); | |
| 45 } | |
| 46 | |
| 47 /** | |
| 48 * @enum {string} | |
| 49 */ | |
| 50 /** @enum {symbol} */ | |
| 51 WebInspector.LayerDetailsView.Events = { | |
| 52 PaintProfilerRequested: Symbol("PaintProfilerRequested") | |
| 53 } | |
| 54 | |
| 55 /** | |
| 56 * @type {!Object.<string, string>} | |
| 57 */ | |
| 58 WebInspector.LayerDetailsView.CompositingReasonDetail = { | |
| 59 "transform3D": WebInspector.UIString("Composition due to association with an
element with a CSS 3D transform."), | |
| 60 "video": WebInspector.UIString("Composition due to association with a <video
> element."), | |
| 61 "canvas": WebInspector.UIString("Composition due to the element being a <can
vas> element."), | |
| 62 "plugin": WebInspector.UIString("Composition due to association with a plugi
n."), | |
| 63 "iFrame": WebInspector.UIString("Composition due to association with an <ifr
ame> element."), | |
| 64 "backfaceVisibilityHidden": WebInspector.UIString("Composition due to associ
ation with an element with a \"backface-visibility: hidden\" style."), | |
| 65 "animation": WebInspector.UIString("Composition due to association with an a
nimated element."), | |
| 66 "filters": WebInspector.UIString("Composition due to association with an ele
ment with CSS filters applied."), | |
| 67 "positionFixed": WebInspector.UIString("Composition due to association with
an element with a \"position: fixed\" style."), | |
| 68 // FIXME: Can we remove this entry now that position: sticky has been remove
d? | |
| 69 "positionSticky": WebInspector.UIString("Composition due to association with
an element with a \"position: sticky\" style."), | |
| 70 "overflowScrollingTouch": WebInspector.UIString("Composition due to associat
ion with an element with a \"overflow-scrolling: touch\" style."), | |
| 71 "blending": WebInspector.UIString("Composition due to association with an el
ement that has blend mode other than \"normal\"."), | |
| 72 "assumedOverlap": WebInspector.UIString("Composition due to association with
an element that may overlap other composited elements."), | |
| 73 "overlap": WebInspector.UIString("Composition due to association with an ele
ment overlapping other composited elements."), | |
| 74 "negativeZIndexChildren": WebInspector.UIString("Composition due to associat
ion with an element with descendants that have a negative z-index."), | |
| 75 "transformWithCompositedDescendants": WebInspector.UIString("Composition due
to association with an element with composited descendants."), | |
| 76 "opacityWithCompositedDescendants": WebInspector.UIString("Composition due t
o association with an element with opacity applied and composited descendants.")
, | |
| 77 "maskWithCompositedDescendants": WebInspector.UIString("Composition due to a
ssociation with a masked element and composited descendants."), | |
| 78 "reflectionWithCompositedDescendants": WebInspector.UIString("Composition du
e to association with an element with a reflection and composited descendants.")
, | |
| 79 "filterWithCompositedDescendants": WebInspector.UIString("Composition due to
association with an element with CSS filters applied and composited descendants
."), | |
| 80 "blendingWithCompositedDescendants": WebInspector.UIString("Composition due
to association with an element with CSS blending applied and composited descenda
nts."), | |
| 81 "clipsCompositingDescendants": WebInspector.UIString("Composition due to ass
ociation with an element clipping compositing descendants."), | |
| 82 "perspective": WebInspector.UIString("Composition due to association with an
element with perspective applied."), | |
| 83 "preserve3D": WebInspector.UIString("Composition due to association with an
element with a \"transform-style: preserve-3d\" style."), | |
| 84 "root": WebInspector.UIString("Root layer."), | |
| 85 "layerForClip": WebInspector.UIString("Layer for clip."), | |
| 86 "layerForScrollbar": WebInspector.UIString("Layer for scrollbar."), | |
| 87 "layerForScrollingContainer": WebInspector.UIString("Layer for scrolling con
tainer."), | |
| 88 "layerForForeground": WebInspector.UIString("Layer for foreground."), | |
| 89 "layerForBackground": WebInspector.UIString("Layer for background."), | |
| 90 "layerForMask": WebInspector.UIString("Layer for mask."), | |
| 91 "layerForVideoOverlay": WebInspector.UIString("Layer for video overlay."), | |
| 92 }; | |
| 93 | |
| 94 WebInspector.LayerDetailsView.prototype = { | |
| 95 /** | |
| 96 * @param {?WebInspector.LayerView.Selection} selection | |
| 97 * @override | |
| 98 */ | |
| 99 hoverObject: function(selection) { }, | |
| 100 | |
| 101 /** | |
| 102 * @param {?WebInspector.LayerView.Selection} selection | |
| 103 * @override | |
| 104 */ | |
| 105 selectObject: function(selection) | |
| 106 { | |
| 107 this._selection = selection; | |
| 108 if (this.isShowing()) | |
| 109 this.update(); | |
| 110 }, | |
| 111 | |
| 112 /** | |
| 113 * @param {?WebInspector.LayerTreeBase} layerTree | |
| 114 * @override | |
| 115 */ | |
| 116 setLayerTree: function(layerTree) { }, | |
| 117 | |
| 118 wasShown: function() | |
| 119 { | |
| 120 WebInspector.Widget.prototype.wasShown.call(this); | |
| 121 this.update(); | |
| 122 }, | |
| 123 | |
| 124 /** | |
| 125 * @param {number} index | |
| 126 * @param {!Event} event | |
| 127 */ | |
| 128 _onScrollRectClicked: function(index, event) | |
| 129 { | |
| 130 if (event.which !== 1) | |
| 131 return; | |
| 132 this._layerViewHost.selectObject(new WebInspector.LayerView.ScrollRectSe
lection(this._selection.layer(), index)); | |
| 133 }, | |
| 134 | |
| 135 _onPaintProfilerButtonClicked: function() | |
| 136 { | |
| 137 var traceEvent = this._selection.type() === WebInspector.LayerView.Selec
tion.Type.Tile ? /** @type {!WebInspector.LayerView.TileSelection} */ (this._sel
ection).traceEvent() : null; | |
| 138 this.dispatchEventToListeners(WebInspector.LayerDetailsView.Events.Paint
ProfilerRequested, traceEvent); | |
| 139 }, | |
| 140 | |
| 141 /** | |
| 142 * @param {!LayerTreeAgent.ScrollRect} scrollRect | |
| 143 * @param {number} index | |
| 144 */ | |
| 145 _createScrollRectElement: function(scrollRect, index) | |
| 146 { | |
| 147 if (index) | |
| 148 this._scrollRectsCell.createTextChild(", "); | |
| 149 var element = this._scrollRectsCell.createChild("span", "scroll-rect"); | |
| 150 if (this._selection.scrollRectIndex === index) | |
| 151 element.classList.add("active"); | |
| 152 element.textContent = WebInspector.LayerTreeModel.ScrollRectType[scrollR
ect.type].description + " (" + scrollRect.rect.x + ", " + scrollRect.rect.y + | |
| 153 ", " + scrollRect.rect.width + ", " + scrollRect.rect.height + ")"; | |
| 154 element.addEventListener("click", this._onScrollRectClicked.bind(this, i
ndex), false); | |
| 155 }, | |
| 156 | |
| 157 update: function() | |
| 158 { | |
| 159 var layer = this._selection && this._selection.layer(); | |
| 160 if (!layer) { | |
| 161 this._tableElement.remove(); | |
| 162 this._paintProfilerButton.remove(); | |
| 163 this._emptyWidget.show(this.element); | |
| 164 return; | |
| 165 } | |
| 166 this._emptyWidget.detach(); | |
| 167 this.element.appendChild(this._tableElement); | |
| 168 this.element.appendChild(this._paintProfilerButton); | |
| 169 this._sizeCell.textContent = WebInspector.UIString("%d × %d (at %d,%d)",
layer.width(), layer.height(), layer.offsetX(), layer.offsetY()); | |
| 170 this._paintCountCell.parentElement.classList.toggle("hidden", !layer.pai
ntCount()); | |
| 171 this._paintCountCell.textContent = layer.paintCount(); | |
| 172 this._memoryEstimateCell.textContent = Number.bytesToString(layer.gpuMem
oryUsage()); | |
| 173 layer.requestCompositingReasons(this._updateCompositingReasons.bind(this
)); | |
| 174 this._scrollRectsCell.removeChildren(); | |
| 175 layer.scrollRects().forEach(this._createScrollRectElement.bind(this)); | |
| 176 var traceEvent = this._selection.type() === WebInspector.LayerView.Selec
tion.Type.Tile ? /** @type {!WebInspector.LayerView.TileSelection} */ (this._sel
ection).traceEvent() : null; | |
| 177 this._paintProfilerButton.classList.toggle("hidden", !traceEvent); | |
| 178 }, | |
| 179 | |
| 180 _buildContent: function() | |
| 181 { | |
| 182 this._tableElement = this.element.createChild("table"); | |
| 183 this._tbodyElement = this._tableElement.createChild("tbody"); | |
| 184 this._sizeCell = this._createRow(WebInspector.UIString("Size")); | |
| 185 this._compositingReasonsCell = this._createRow(WebInspector.UIString("Co
mpositing Reasons")); | |
| 186 this._memoryEstimateCell = this._createRow(WebInspector.UIString("Memory
estimate")); | |
| 187 this._paintCountCell = this._createRow(WebInspector.UIString("Paint coun
t")); | |
| 188 this._scrollRectsCell = this._createRow(WebInspector.UIString("Slow scro
ll regions")); | |
| 189 this._paintProfilerButton = this.element.createChild("a", "hidden link")
; | |
| 190 this._paintProfilerButton.textContent = WebInspector.UIString("Paint Pro
filer"); | |
| 191 this._paintProfilerButton.addEventListener("click", this._onPaintProfile
rButtonClicked.bind(this)); | |
| 192 }, | |
| 193 | |
| 194 /** | |
| 195 * @param {string} title | |
| 196 */ | |
| 197 _createRow: function(title) | |
| 198 { | |
| 199 var tr = this._tbodyElement.createChild("tr"); | |
| 200 var titleCell = tr.createChild("td"); | |
| 201 titleCell.textContent = title; | |
| 202 return tr.createChild("td"); | |
| 203 }, | |
| 204 | |
| 205 /** | |
| 206 * @param {!Array.<string>} compositingReasons | |
| 207 */ | |
| 208 _updateCompositingReasons: function(compositingReasons) | |
| 209 { | |
| 210 if (!compositingReasons || !compositingReasons.length) { | |
| 211 this._compositingReasonsCell.textContent = "n/a"; | |
| 212 return; | |
| 213 } | |
| 214 this._compositingReasonsCell.removeChildren(); | |
| 215 var list = this._compositingReasonsCell.createChild("ul"); | |
| 216 for (var i = 0; i < compositingReasons.length; ++i) { | |
| 217 var text = WebInspector.LayerDetailsView.CompositingReasonDetail[com
positingReasons[i]] || compositingReasons[i]; | |
| 218 // If the text is more than one word but does not terminate with per
iod, add the period. | |
| 219 if (/\s.*[^.]$/.test(text)) | |
| 220 text += "."; | |
| 221 list.createChild("li").textContent = text; | |
| 222 } | |
| 223 }, | |
| 224 | |
| 225 __proto__: WebInspector.Widget.prototype | |
| 226 } | |
| OLD | NEW |