| 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 "scrollDependentPosition": WebInspector.UIString("Composition due to associa
tion with an element with a \"position: fixed\" or \"position: sticky\" style.")
, | |
| 68 "overflowScrollingTouch": WebInspector.UIString("Composition due to associat
ion with an element with a \"overflow-scrolling: touch\" style."), | |
| 69 "blending": WebInspector.UIString("Composition due to association with an el
ement that has blend mode other than \"normal\"."), | |
| 70 "assumedOverlap": WebInspector.UIString("Composition due to association with
an element that may overlap other composited elements."), | |
| 71 "overlap": WebInspector.UIString("Composition due to association with an ele
ment overlapping other composited elements."), | |
| 72 "negativeZIndexChildren": WebInspector.UIString("Composition due to associat
ion with an element with descendants that have a negative z-index."), | |
| 73 "transformWithCompositedDescendants": WebInspector.UIString("Composition due
to association with an element with composited descendants."), | |
| 74 "opacityWithCompositedDescendants": WebInspector.UIString("Composition due t
o association with an element with opacity applied and composited descendants.")
, | |
| 75 "maskWithCompositedDescendants": WebInspector.UIString("Composition due to a
ssociation with a masked element and composited descendants."), | |
| 76 "reflectionWithCompositedDescendants": WebInspector.UIString("Composition du
e to association with an element with a reflection and composited descendants.")
, | |
| 77 "filterWithCompositedDescendants": WebInspector.UIString("Composition due to
association with an element with CSS filters applied and composited descendants
."), | |
| 78 "blendingWithCompositedDescendants": WebInspector.UIString("Composition due
to association with an element with CSS blending applied and composited descenda
nts."), | |
| 79 "clipsCompositingDescendants": WebInspector.UIString("Composition due to ass
ociation with an element clipping compositing descendants."), | |
| 80 "perspective": WebInspector.UIString("Composition due to association with an
element with perspective applied."), | |
| 81 "preserve3D": WebInspector.UIString("Composition due to association with an
element with a \"transform-style: preserve-3d\" style."), | |
| 82 "root": WebInspector.UIString("Root layer."), | |
| 83 "layerForClip": WebInspector.UIString("Layer for clip."), | |
| 84 "layerForScrollbar": WebInspector.UIString("Layer for scrollbar."), | |
| 85 "layerForScrollingContainer": WebInspector.UIString("Layer for scrolling con
tainer."), | |
| 86 "layerForForeground": WebInspector.UIString("Layer for foreground."), | |
| 87 "layerForBackground": WebInspector.UIString("Layer for background."), | |
| 88 "layerForMask": WebInspector.UIString("Layer for mask."), | |
| 89 "layerForVideoOverlay": WebInspector.UIString("Layer for video overlay."), | |
| 90 }; | |
| 91 | |
| 92 WebInspector.LayerDetailsView.prototype = { | |
| 93 /** | |
| 94 * @param {?WebInspector.LayerView.Selection} selection | |
| 95 * @override | |
| 96 */ | |
| 97 hoverObject: function(selection) { }, | |
| 98 | |
| 99 /** | |
| 100 * @param {?WebInspector.LayerView.Selection} selection | |
| 101 * @override | |
| 102 */ | |
| 103 selectObject: function(selection) | |
| 104 { | |
| 105 this._selection = selection; | |
| 106 if (this.isShowing()) | |
| 107 this.update(); | |
| 108 }, | |
| 109 | |
| 110 /** | |
| 111 * @param {?WebInspector.LayerTreeBase} layerTree | |
| 112 * @override | |
| 113 */ | |
| 114 setLayerTree: function(layerTree) { }, | |
| 115 | |
| 116 wasShown: function() | |
| 117 { | |
| 118 WebInspector.Widget.prototype.wasShown.call(this); | |
| 119 this.update(); | |
| 120 }, | |
| 121 | |
| 122 /** | |
| 123 * @param {number} index | |
| 124 * @param {!Event} event | |
| 125 */ | |
| 126 _onScrollRectClicked: function(index, event) | |
| 127 { | |
| 128 if (event.which !== 1) | |
| 129 return; | |
| 130 this._layerViewHost.selectObject(new WebInspector.LayerView.ScrollRectSe
lection(this._selection.layer(), index)); | |
| 131 }, | |
| 132 | |
| 133 _onPaintProfilerButtonClicked: function() | |
| 134 { | |
| 135 var traceEvent = this._selection.type() === WebInspector.LayerView.Selec
tion.Type.Tile ? /** @type {!WebInspector.LayerView.TileSelection} */ (this._sel
ection).traceEvent() : null; | |
| 136 this.dispatchEventToListeners(WebInspector.LayerDetailsView.Events.Paint
ProfilerRequested, traceEvent); | |
| 137 }, | |
| 138 | |
| 139 /** | |
| 140 * @param {!LayerTreeAgent.ScrollRect} scrollRect | |
| 141 * @param {number} index | |
| 142 */ | |
| 143 _createScrollRectElement: function(scrollRect, index) | |
| 144 { | |
| 145 if (index) | |
| 146 this._scrollRectsCell.createTextChild(", "); | |
| 147 var element = this._scrollRectsCell.createChild("span", "scroll-rect"); | |
| 148 if (this._selection.scrollRectIndex === index) | |
| 149 element.classList.add("active"); | |
| 150 element.textContent = WebInspector.LayerTreeModel.ScrollRectType[scrollR
ect.type].description + " (" + scrollRect.rect.x + ", " + scrollRect.rect.y + | |
| 151 ", " + scrollRect.rect.width + ", " + scrollRect.rect.height + ")"; | |
| 152 element.addEventListener("click", this._onScrollRectClicked.bind(this, i
ndex), false); | |
| 153 }, | |
| 154 | |
| 155 update: function() | |
| 156 { | |
| 157 var layer = this._selection && this._selection.layer(); | |
| 158 if (!layer) { | |
| 159 this._tableElement.remove(); | |
| 160 this._paintProfilerButton.remove(); | |
| 161 this._emptyWidget.show(this.element); | |
| 162 return; | |
| 163 } | |
| 164 this._emptyWidget.detach(); | |
| 165 this.element.appendChild(this._tableElement); | |
| 166 this.element.appendChild(this._paintProfilerButton); | |
| 167 this._sizeCell.textContent = WebInspector.UIString("%d × %d (at %d,%d)",
layer.width(), layer.height(), layer.offsetX(), layer.offsetY()); | |
| 168 this._paintCountCell.parentElement.classList.toggle("hidden", !layer.pai
ntCount()); | |
| 169 this._paintCountCell.textContent = layer.paintCount(); | |
| 170 this._memoryEstimateCell.textContent = Number.bytesToString(layer.gpuMem
oryUsage()); | |
| 171 layer.requestCompositingReasons(this._updateCompositingReasons.bind(this
)); | |
| 172 this._scrollRectsCell.removeChildren(); | |
| 173 layer.scrollRects().forEach(this._createScrollRectElement.bind(this)); | |
| 174 var traceEvent = this._selection.type() === WebInspector.LayerView.Selec
tion.Type.Tile ? /** @type {!WebInspector.LayerView.TileSelection} */ (this._sel
ection).traceEvent() : null; | |
| 175 this._paintProfilerButton.classList.toggle("hidden", !traceEvent); | |
| 176 }, | |
| 177 | |
| 178 _buildContent: function() | |
| 179 { | |
| 180 this._tableElement = this.element.createChild("table"); | |
| 181 this._tbodyElement = this._tableElement.createChild("tbody"); | |
| 182 this._sizeCell = this._createRow(WebInspector.UIString("Size")); | |
| 183 this._compositingReasonsCell = this._createRow(WebInspector.UIString("Co
mpositing Reasons")); | |
| 184 this._memoryEstimateCell = this._createRow(WebInspector.UIString("Memory
estimate")); | |
| 185 this._paintCountCell = this._createRow(WebInspector.UIString("Paint coun
t")); | |
| 186 this._scrollRectsCell = this._createRow(WebInspector.UIString("Slow scro
ll regions")); | |
| 187 this._paintProfilerButton = this.element.createChild("a", "hidden link")
; | |
| 188 this._paintProfilerButton.textContent = WebInspector.UIString("Paint Pro
filer"); | |
| 189 this._paintProfilerButton.addEventListener("click", this._onPaintProfile
rButtonClicked.bind(this)); | |
| 190 }, | |
| 191 | |
| 192 /** | |
| 193 * @param {string} title | |
| 194 */ | |
| 195 _createRow: function(title) | |
| 196 { | |
| 197 var tr = this._tbodyElement.createChild("tr"); | |
| 198 var titleCell = tr.createChild("td"); | |
| 199 titleCell.textContent = title; | |
| 200 return tr.createChild("td"); | |
| 201 }, | |
| 202 | |
| 203 /** | |
| 204 * @param {!Array.<string>} compositingReasons | |
| 205 */ | |
| 206 _updateCompositingReasons: function(compositingReasons) | |
| 207 { | |
| 208 if (!compositingReasons || !compositingReasons.length) { | |
| 209 this._compositingReasonsCell.textContent = "n/a"; | |
| 210 return; | |
| 211 } | |
| 212 this._compositingReasonsCell.removeChildren(); | |
| 213 var list = this._compositingReasonsCell.createChild("ul"); | |
| 214 for (var i = 0; i < compositingReasons.length; ++i) { | |
| 215 var text = WebInspector.LayerDetailsView.CompositingReasonDetail[com
positingReasons[i]] || compositingReasons[i]; | |
| 216 // If the text is more than one word but does not terminate with per
iod, add the period. | |
| 217 if (/\s.*[^.]$/.test(text)) | |
| 218 text += "."; | |
| 219 list.createChild("li").textContent = text; | |
| 220 } | |
| 221 }, | |
| 222 | |
| 223 __proto__: WebInspector.Widget.prototype | |
| 224 } | |
| OLD | NEW |