2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 importScript("LayerTree.js");
32 importScript("Layers3DView.js");
33 importScript("LayerDetailsView.js");
34 importScript("PaintProfilerView.js");
35 importScript("TransformController.js");
39 * @extends {WebInspector.PanelWithSidebarTree}
41 WebInspector.LayersPanel = function()
43 WebInspector.PanelWithSidebarTree.call(this, "layers", 225);
44 this.registerRequiredCSS("layersPanel.css");
46 this.sidebarElement().classList.add("outline-disclosure");
47 this.sidebarTree.element.classList.remove("sidebar-tree");
49 this._target = /** @type {!WebInspector.Target} */ (WebInspector.targetManager.activeTarget());
50 this._model = new WebInspector.LayerTreeModel(this._target);
51 this._model.addEventListener(WebInspector.LayerTreeModel.Events.LayerTreeChanged, this._onLayerTreeUpdated, this);
52 this._currentlySelectedLayer = null;
53 this._currentlyHoveredLayer = null;
55 this._layerTree = new WebInspector.LayerTree(this._model, this.sidebarTree);
56 this._layerTree.addEventListener(WebInspector.LayerTree.Events.LayerSelected, this._onObjectSelected, this);
57 this._layerTree.addEventListener(WebInspector.LayerTree.Events.LayerHovered, this._onObjectHovered, this);
59 this._rightSplitView = new WebInspector.SplitView(false, true, "layerDetailsSplitViewState");
60 this._rightSplitView.show(this.mainElement());
62 this._layers3DView = new WebInspector.Layers3DView(this._model);
63 this._layers3DView.show(this._rightSplitView.mainElement());
64 this._layers3DView.addEventListener(WebInspector.Layers3DView.Events.ObjectSelected, this._onObjectSelected, this);
65 this._layers3DView.addEventListener(WebInspector.Layers3DView.Events.ObjectHovered, this._onObjectHovered, this);
66 this._layers3DView.addEventListener(WebInspector.Layers3DView.Events.LayerSnapshotRequested, this._onSnapshotRequested, this);
67 this._layers3DView.registerShortcuts(this.registerShortcuts.bind(this));
69 this._tabbedPane = new WebInspector.TabbedPane();
70 this._tabbedPane.show(this._rightSplitView.sidebarElement());
72 this._layerDetailsView = new WebInspector.LayerDetailsView(this._model);
73 this._layerDetailsView.addEventListener(WebInspector.LayerDetailsView.Events.ObjectSelected, this._onObjectSelected, this);
74 this._tabbedPane.appendTab(WebInspector.LayersPanel.DetailsViewTabs.Details, WebInspector.UIString("Details"), this._layerDetailsView);
75 this._paintProfilerView = new WebInspector.PaintProfilerView(this._model, this._layers3DView);
76 this._tabbedPane.appendTab(WebInspector.LayersPanel.DetailsViewTabs.Profiler, WebInspector.UIString("Profiler"), this._paintProfilerView);
79 /** @typedef {{layer: !WebInspector.Layer, scrollRectIndex: number}|{layer: !WebInspector.Layer}} */
80 WebInspector.LayersPanel.ActiveObject;
82 WebInspector.LayersPanel.DetailsViewTabs = {
87 WebInspector.LayersPanel.prototype = {
90 WebInspector.Panel.prototype.wasShown.call(this);
91 this.sidebarTree.element.focus();
97 this._model.disable();
98 WebInspector.Panel.prototype.willHide.call(this);
102 * @param {!WebInspector.LayerTreeSnapshot} snapshot
104 _showSnapshot: function(snapshot)
106 this._model.setSnapshot(snapshot);
110 * @param {!WebInspector.TracingLayerSnapshot} snapshot
112 _showTracingSnapshot: function(snapshot)
114 this._model.setTracingSnapshot(snapshot);
117 _onLayerTreeUpdated: function()
119 if (this._currentlySelectedLayer && !this._model.layerById(this._currentlySelectedLayer.layer.id()))
120 this._selectObject(null);
121 if (this._currentlyHoveredLayer && !this._model.layerById(this._currentlyHoveredLayer.layer.id()))
122 this._hoverObject(null);
126 * @param {!WebInspector.Event} event
128 _onObjectSelected: function(event)
130 var activeObject = /** @type {!WebInspector.LayersPanel.ActiveObject} */ (event.data);
131 this._selectObject(activeObject);
135 * @param {!WebInspector.Event} event
137 _onObjectHovered: function(event)
139 var activeObject = /** @type {!WebInspector.LayersPanel.ActiveObject} */ (event.data);
140 this._hoverObject(activeObject);
144 * @param {!WebInspector.Event} event
146 _onSnapshotRequested: function(event)
148 var layer = /** @type {!WebInspector.Layer} */ (event.data);
149 this._tabbedPane.selectTab(WebInspector.LayersPanel.DetailsViewTabs.Profiler);
150 this._paintProfilerView.profile(layer);
154 * @param {?WebInspector.LayersPanel.ActiveObject} activeObject
156 _selectObject: function(activeObject)
158 var layer = activeObject && activeObject.layer;
159 if (this._currentlySelectedLayer === activeObject)
161 this._currentlySelectedLayer = activeObject;
162 var node = layer ? layer.nodeForSelfOrAncestor() : null;
164 node.highlightForTwoSeconds();
166 this._target.domModel.hideDOMNodeHighlight();
167 this._layerTree.selectLayer(layer);
168 this._layers3DView.selectObject(activeObject);
169 this._layerDetailsView.setObject(activeObject);
173 * @param {?WebInspector.LayersPanel.ActiveObject} activeObject
175 _hoverObject: function(activeObject)
177 var layer = activeObject && activeObject.layer;
178 if (this._currentlyHoveredLayer === activeObject)
180 this._currentlyHoveredLayer = activeObject;
181 var node = layer ? layer.nodeForSelfOrAncestor() : null;
185 this._target.domModel.hideDOMNodeHighlight();
186 this._layerTree.hoverLayer(layer);
187 this._layers3DView.hoverObject(activeObject);
190 __proto__: WebInspector.PanelWithSidebarTree.prototype
195 * @implements {WebInspector.Revealer}
197 WebInspector.LayersPanel.LayerTreeRevealer = function()
201 WebInspector.LayersPanel.LayerTreeRevealer.prototype = {
203 * @param {!Object} snapshotData
205 reveal: function(snapshotData)
207 if (snapshotData instanceof WebInspector.LayerTreeSnapshot)
208 /** @type {!WebInspector.LayersPanel} */ (WebInspector.inspectorView.showPanel("layers"))._showSnapshot(snapshotData);
209 else if (snapshotData instanceof WebInspector.TracingLayerSnapshot)
210 /** @type {!WebInspector.LayersPanel} */ (WebInspector.inspectorView.showPanel("layers"))._showTracingSnapshot(snapshotData);