| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | |
| 31 /** | 30 /** |
| 32 * @constructor | |
| 33 * @extends {WebInspector.PanelWithSidebar} | |
| 34 * @implements {WebInspector.TargetManager.Observer} | 31 * @implements {WebInspector.TargetManager.Observer} |
| 32 * @unrestricted |
| 35 */ | 33 */ |
| 36 WebInspector.LayersPanel = function() | 34 WebInspector.LayersPanel = class extends WebInspector.PanelWithSidebar { |
| 37 { | 35 constructor() { |
| 38 WebInspector.PanelWithSidebar.call(this, "layers", 225); | 36 super('layers', 225); |
| 39 | 37 |
| 40 /** @type {?WebInspector.LayerTreeModel} */ | 38 /** @type {?WebInspector.LayerTreeModel} */ |
| 41 this._model = null; | 39 this._model = null; |
| 42 | 40 |
| 43 WebInspector.targetManager.observeTargets(this); | 41 WebInspector.targetManager.observeTargets(this); |
| 44 this._layerViewHost = new WebInspector.LayerViewHost(); | 42 this._layerViewHost = new WebInspector.LayerViewHost(); |
| 45 this._layerTreeOutline = new WebInspector.LayerTreeOutline(this._layerViewHo
st); | 43 this._layerTreeOutline = new WebInspector.LayerTreeOutline(this._layerViewHo
st); |
| 46 this.panelSidebarElement().appendChild(this._layerTreeOutline.element); | 44 this.panelSidebarElement().appendChild(this._layerTreeOutline.element); |
| 47 this.setDefaultFocusedElement(this._layerTreeOutline.element); | 45 this.setDefaultFocusedElement(this._layerTreeOutline.element); |
| 48 | 46 |
| 49 this._rightSplitWidget = new WebInspector.SplitWidget(false, true, "layerDet
ailsSplitViewState"); | 47 this._rightSplitWidget = new WebInspector.SplitWidget(false, true, 'layerDet
ailsSplitViewState'); |
| 50 this.splitWidget().setMainWidget(this._rightSplitWidget); | 48 this.splitWidget().setMainWidget(this._rightSplitWidget); |
| 51 | 49 |
| 52 this._layers3DView = new WebInspector.Layers3DView(this._layerViewHost); | 50 this._layers3DView = new WebInspector.Layers3DView(this._layerViewHost); |
| 53 this._rightSplitWidget.setMainWidget(this._layers3DView); | 51 this._rightSplitWidget.setMainWidget(this._layers3DView); |
| 54 this._layers3DView.addEventListener(WebInspector.Layers3DView.Events.PaintPr
ofilerRequested, this._onPaintProfileRequested, this); | 52 this._layers3DView.addEventListener( |
| 53 WebInspector.Layers3DView.Events.PaintProfilerRequested, this._onPaintPr
ofileRequested, this); |
| 55 this._layers3DView.addEventListener(WebInspector.Layers3DView.Events.ScaleCh
anged, this._onScaleChanged, this); | 54 this._layers3DView.addEventListener(WebInspector.Layers3DView.Events.ScaleCh
anged, this._onScaleChanged, this); |
| 56 | 55 |
| 57 this._tabbedPane = new WebInspector.TabbedPane(); | 56 this._tabbedPane = new WebInspector.TabbedPane(); |
| 58 this._rightSplitWidget.setSidebarWidget(this._tabbedPane); | 57 this._rightSplitWidget.setSidebarWidget(this._tabbedPane); |
| 59 | 58 |
| 60 this._layerDetailsView = new WebInspector.LayerDetailsView(this._layerViewHo
st); | 59 this._layerDetailsView = new WebInspector.LayerDetailsView(this._layerViewHo
st); |
| 61 this._layerDetailsView.addEventListener(WebInspector.LayerDetailsView.Events
.PaintProfilerRequested, this._onPaintProfileRequested, this); | 60 this._layerDetailsView.addEventListener( |
| 62 this._tabbedPane.appendTab(WebInspector.LayersPanel.DetailsViewTabs.Details,
WebInspector.UIString("Details"), this._layerDetailsView); | 61 WebInspector.LayerDetailsView.Events.PaintProfilerRequested, this._onPai
ntProfileRequested, this); |
| 62 this._tabbedPane.appendTab( |
| 63 WebInspector.LayersPanel.DetailsViewTabs.Details, WebInspector.UIString(
'Details'), this._layerDetailsView); |
| 63 | 64 |
| 64 this._paintProfilerView = new WebInspector.LayerPaintProfilerView(this._show
Image.bind(this)); | 65 this._paintProfilerView = new WebInspector.LayerPaintProfilerView(this._show
Image.bind(this)); |
| 65 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabClosed,
this._onTabClosed, this); | 66 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabClosed,
this._onTabClosed, this); |
| 66 this._updateThrottler = new WebInspector.Throttler(100); | 67 this._updateThrottler = new WebInspector.Throttler(100); |
| 68 } |
| 69 |
| 70 /** |
| 71 * @override |
| 72 */ |
| 73 focus() { |
| 74 this._layerTreeOutline.focus(); |
| 75 } |
| 76 |
| 77 /** |
| 78 * @override |
| 79 */ |
| 80 wasShown() { |
| 81 super.wasShown(); |
| 82 if (this._model) |
| 83 this._model.enable(); |
| 84 this._layerTreeOutline.focus(); |
| 85 } |
| 86 |
| 87 /** |
| 88 * @override |
| 89 */ |
| 90 willHide() { |
| 91 if (this._model) |
| 92 this._model.disable(); |
| 93 super.willHide(); |
| 94 } |
| 95 |
| 96 /** |
| 97 * @override |
| 98 * @param {!WebInspector.Target} target |
| 99 */ |
| 100 targetAdded(target) { |
| 101 if (this._model) |
| 102 return; |
| 103 this._model = WebInspector.LayerTreeModel.fromTarget(target); |
| 104 if (!this._model) |
| 105 return; |
| 106 this._model.addEventListener(WebInspector.LayerTreeModel.Events.LayerTreeCha
nged, this._onLayerTreeUpdated, this); |
| 107 this._model.addEventListener(WebInspector.LayerTreeModel.Events.LayerPainted
, this._onLayerPainted, this); |
| 108 if (this.isShowing()) |
| 109 this._model.enable(); |
| 110 } |
| 111 |
| 112 /** |
| 113 * @override |
| 114 * @param {!WebInspector.Target} target |
| 115 */ |
| 116 targetRemoved(target) { |
| 117 if (!this._model || this._model.target() !== target) |
| 118 return; |
| 119 this._model.removeEventListener( |
| 120 WebInspector.LayerTreeModel.Events.LayerTreeChanged, this._onLayerTreeUp
dated, this); |
| 121 this._model.removeEventListener(WebInspector.LayerTreeModel.Events.LayerPain
ted, this._onLayerPainted, this); |
| 122 this._model.disable(); |
| 123 this._model = null; |
| 124 } |
| 125 |
| 126 _onLayerTreeUpdated() { |
| 127 this._updateThrottler.schedule(this._update.bind(this)); |
| 128 } |
| 129 |
| 130 /** |
| 131 * @return {!Promise<*>} |
| 132 */ |
| 133 _update() { |
| 134 if (this._model) |
| 135 this._layerViewHost.setLayerTree(this._model.layerTree()); |
| 136 return Promise.resolve(); |
| 137 } |
| 138 |
| 139 /** |
| 140 * @param {!WebInspector.Event} event |
| 141 */ |
| 142 _onLayerPainted(event) { |
| 143 if (!this._model) |
| 144 return; |
| 145 var layer = /** @type {!WebInspector.Layer} */ (event.data); |
| 146 if (this._layerViewHost.selection() && this._layerViewHost.selection().layer
() === layer) |
| 147 this._layerDetailsView.update(); |
| 148 this._layers3DView.updateLayerSnapshot(layer); |
| 149 } |
| 150 |
| 151 /** |
| 152 * @param {!WebInspector.Event} event |
| 153 */ |
| 154 _onPaintProfileRequested(event) { |
| 155 var selection = /** @type {!WebInspector.LayerView.Selection} */ (event.data
); |
| 156 this._layers3DView.snapshotForSelection(selection).then(snapshotWithRect =>
{ |
| 157 if (!snapshotWithRect) |
| 158 return; |
| 159 this._layerBeingProfiled = selection.layer(); |
| 160 this._tabbedPane.appendTab( |
| 161 WebInspector.LayersPanel.DetailsViewTabs.Profiler, WebInspector.UIStri
ng('Profiler'), this._paintProfilerView, |
| 162 undefined, true, true); |
| 163 this._tabbedPane.selectTab(WebInspector.LayersPanel.DetailsViewTabs.Profil
er); |
| 164 this._paintProfilerView.profile(snapshotWithRect.snapshot); |
| 165 }); |
| 166 } |
| 167 |
| 168 /** |
| 169 * @param {!WebInspector.Event} event |
| 170 */ |
| 171 _onTabClosed(event) { |
| 172 if (event.data.tabId !== WebInspector.LayersPanel.DetailsViewTabs.Profiler |
| !this._layerBeingProfiled) |
| 173 return; |
| 174 this._paintProfilerView.reset(); |
| 175 this._layers3DView.showImageForLayer(this._layerBeingProfiled, undefined); |
| 176 this._layerBeingProfiled = null; |
| 177 } |
| 178 |
| 179 /** |
| 180 * @param {string=} imageURL |
| 181 */ |
| 182 _showImage(imageURL) { |
| 183 this._layers3DView.showImageForLayer(this._layerBeingProfiled, imageURL); |
| 184 } |
| 185 |
| 186 /** |
| 187 * @param {!WebInspector.Event} event |
| 188 */ |
| 189 _onScaleChanged(event) { |
| 190 this._paintProfilerView.setScale(/** @type {number} */ (event.data)); |
| 191 } |
| 67 }; | 192 }; |
| 68 | 193 |
| 69 WebInspector.LayersPanel.DetailsViewTabs = { | 194 WebInspector.LayersPanel.DetailsViewTabs = { |
| 70 Details: "details", | 195 Details: 'details', |
| 71 Profiler: "profiler" | 196 Profiler: 'profiler' |
| 72 }; | 197 }; |
| 73 | |
| 74 WebInspector.LayersPanel.prototype = { | |
| 75 focus: function() | |
| 76 { | |
| 77 this._layerTreeOutline.focus(); | |
| 78 }, | |
| 79 | |
| 80 wasShown: function() | |
| 81 { | |
| 82 WebInspector.Panel.prototype.wasShown.call(this); | |
| 83 if (this._model) | |
| 84 this._model.enable(); | |
| 85 this._layerTreeOutline.focus(); | |
| 86 }, | |
| 87 | |
| 88 willHide: function() | |
| 89 { | |
| 90 if (this._model) | |
| 91 this._model.disable(); | |
| 92 WebInspector.Panel.prototype.willHide.call(this); | |
| 93 }, | |
| 94 | |
| 95 /** | |
| 96 * @override | |
| 97 * @param {!WebInspector.Target} target | |
| 98 */ | |
| 99 targetAdded: function(target) | |
| 100 { | |
| 101 if (this._model) | |
| 102 return; | |
| 103 this._model = WebInspector.LayerTreeModel.fromTarget(target); | |
| 104 if (!this._model) | |
| 105 return; | |
| 106 this._model.addEventListener(WebInspector.LayerTreeModel.Events.LayerTre
eChanged, this._onLayerTreeUpdated, this); | |
| 107 this._model.addEventListener(WebInspector.LayerTreeModel.Events.LayerPai
nted, this._onLayerPainted, this); | |
| 108 if (this.isShowing()) | |
| 109 this._model.enable(); | |
| 110 }, | |
| 111 | |
| 112 /** | |
| 113 * @override | |
| 114 * @param {!WebInspector.Target} target | |
| 115 */ | |
| 116 targetRemoved: function(target) | |
| 117 { | |
| 118 if (!this._model || this._model.target() !== target) | |
| 119 return; | |
| 120 this._model.removeEventListener(WebInspector.LayerTreeModel.Events.Layer
TreeChanged, this._onLayerTreeUpdated, this); | |
| 121 this._model.removeEventListener(WebInspector.LayerTreeModel.Events.Layer
Painted, this._onLayerPainted, this); | |
| 122 this._model.disable(); | |
| 123 this._model = null; | |
| 124 }, | |
| 125 | |
| 126 _onLayerTreeUpdated: function() | |
| 127 { | |
| 128 this._updateThrottler.schedule(this._update.bind(this)); | |
| 129 }, | |
| 130 | |
| 131 /** | |
| 132 * @return {!Promise<*>} | |
| 133 */ | |
| 134 _update: function() | |
| 135 { | |
| 136 if (this._model) | |
| 137 this._layerViewHost.setLayerTree(this._model.layerTree()); | |
| 138 return Promise.resolve(); | |
| 139 }, | |
| 140 | |
| 141 /** | |
| 142 * @param {!WebInspector.Event} event | |
| 143 */ | |
| 144 _onLayerPainted: function(event) | |
| 145 { | |
| 146 if (!this._model) | |
| 147 return; | |
| 148 var layer = /** @type {!WebInspector.Layer} */ (event.data); | |
| 149 if (this._layerViewHost.selection() && this._layerViewHost.selection().l
ayer() === layer) | |
| 150 this._layerDetailsView.update(); | |
| 151 this._layers3DView.updateLayerSnapshot(layer); | |
| 152 }, | |
| 153 | |
| 154 /** | |
| 155 * @param {!WebInspector.Event} event | |
| 156 */ | |
| 157 _onPaintProfileRequested: function(event) | |
| 158 { | |
| 159 var selection = /** @type {!WebInspector.LayerView.Selection} */ (event.
data); | |
| 160 this._layers3DView.snapshotForSelection(selection).then(snapshotWithRect
=> { | |
| 161 if (!snapshotWithRect) | |
| 162 return; | |
| 163 this._layerBeingProfiled = selection.layer(); | |
| 164 this._tabbedPane.appendTab(WebInspector.LayersPanel.DetailsViewTabs.
Profiler, WebInspector.UIString("Profiler"), this._paintProfilerView, undefined,
true, true); | |
| 165 this._tabbedPane.selectTab(WebInspector.LayersPanel.DetailsViewTabs.
Profiler); | |
| 166 this._paintProfilerView.profile(snapshotWithRect.snapshot); | |
| 167 }); | |
| 168 }, | |
| 169 | |
| 170 /** | |
| 171 * @param {!WebInspector.Event} event | |
| 172 */ | |
| 173 _onTabClosed: function(event) | |
| 174 { | |
| 175 if (event.data.tabId !== WebInspector.LayersPanel.DetailsViewTabs.Profil
er || !this._layerBeingProfiled) | |
| 176 return; | |
| 177 this._paintProfilerView.reset(); | |
| 178 this._layers3DView.showImageForLayer(this._layerBeingProfiled, undefined
); | |
| 179 this._layerBeingProfiled = null; | |
| 180 }, | |
| 181 | |
| 182 /** | |
| 183 * @param {string=} imageURL | |
| 184 */ | |
| 185 _showImage: function(imageURL) | |
| 186 { | |
| 187 this._layers3DView.showImageForLayer(this._layerBeingProfiled, imageURL)
; | |
| 188 }, | |
| 189 | |
| 190 /** | |
| 191 * @param {!WebInspector.Event} event | |
| 192 */ | |
| 193 _onScaleChanged: function(event) | |
| 194 { | |
| 195 this._paintProfilerView.setScale(/** @type {number} */(event.data)); | |
| 196 }, | |
| 197 | |
| 198 __proto__: WebInspector.PanelWithSidebar.prototype | |
| 199 }; | |
| OLD | NEW |