Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / layers / LayersPanel.js
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 importScript("LayerTree.js");
32 importScript("Layers3DView.js");
33 importScript("LayerDetailsView.js");
34 importScript("PaintProfilerView.js");
35 importScript("TransformController.js");
36
37 /**
38  * @constructor
39  * @extends {WebInspector.PanelWithSidebarTree}
40  */
41 WebInspector.LayersPanel = function()
42 {
43     WebInspector.PanelWithSidebarTree.call(this, "layers", 225);
44     this.registerRequiredCSS("layersPanel.css");
45
46     this.sidebarElement().classList.add("outline-disclosure");
47     this.sidebarTree.element.classList.remove("sidebar-tree");
48
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;
54
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);
58
59     this._rightSplitView = new WebInspector.SplitView(false, true, "layerDetailsSplitViewState");
60     this._rightSplitView.show(this.mainElement());
61
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));
68
69     this._tabbedPane = new WebInspector.TabbedPane();
70     this._tabbedPane.show(this._rightSplitView.sidebarElement());
71
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);
77 }
78
79 /** @typedef {{layer: !WebInspector.Layer, scrollRectIndex: number}|{layer: !WebInspector.Layer}} */
80 WebInspector.LayersPanel.ActiveObject;
81
82 WebInspector.LayersPanel.DetailsViewTabs = {
83     Details: "details",
84     Profiler: "profiler"
85 };
86
87 WebInspector.LayersPanel.prototype = {
88     wasShown: function()
89     {
90         WebInspector.Panel.prototype.wasShown.call(this);
91         this.sidebarTree.element.focus();
92         this._model.enable();
93     },
94
95     willHide: function()
96     {
97         this._model.disable();
98         WebInspector.Panel.prototype.willHide.call(this);
99     },
100
101     /**
102      * @param {!WebInspector.LayerTreeSnapshot} snapshot
103      */
104     _showSnapshot: function(snapshot)
105     {
106         this._model.setSnapshot(snapshot);
107     },
108
109     /**
110      * @param {!WebInspector.TracingLayerSnapshot} snapshot
111      */
112     _showTracingSnapshot: function(snapshot)
113     {
114         this._model.setTracingSnapshot(snapshot);
115     },
116
117     _onLayerTreeUpdated: function()
118     {
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);
123     },
124
125     /**
126      * @param {!WebInspector.Event} event
127      */
128     _onObjectSelected: function(event)
129     {
130         var activeObject = /** @type {!WebInspector.LayersPanel.ActiveObject} */ (event.data);
131         this._selectObject(activeObject);
132     },
133
134     /**
135      * @param {!WebInspector.Event} event
136      */
137     _onObjectHovered: function(event)
138     {
139         var activeObject = /** @type {!WebInspector.LayersPanel.ActiveObject} */ (event.data);
140         this._hoverObject(activeObject);
141     },
142
143     /**
144      * @param {!WebInspector.Event} event
145      */
146     _onSnapshotRequested: function(event)
147     {
148         var layer = /** @type {!WebInspector.Layer} */ (event.data);
149         this._tabbedPane.selectTab(WebInspector.LayersPanel.DetailsViewTabs.Profiler);
150         this._paintProfilerView.profile(layer);
151     },
152
153     /**
154      * @param {?WebInspector.LayersPanel.ActiveObject} activeObject
155      */
156     _selectObject: function(activeObject)
157     {
158         var layer = activeObject && activeObject.layer;
159         if (this._currentlySelectedLayer === activeObject)
160             return;
161         this._currentlySelectedLayer = activeObject;
162         var node = layer ? layer.nodeForSelfOrAncestor() : null;
163         if (node)
164             node.highlightForTwoSeconds();
165         else
166             this._target.domModel.hideDOMNodeHighlight();
167         this._layerTree.selectLayer(layer);
168         this._layers3DView.selectObject(activeObject);
169         this._layerDetailsView.setObject(activeObject);
170     },
171
172     /**
173      * @param {?WebInspector.LayersPanel.ActiveObject} activeObject
174      */
175     _hoverObject: function(activeObject)
176     {
177         var layer = activeObject && activeObject.layer;
178         if (this._currentlyHoveredLayer === activeObject)
179             return;
180         this._currentlyHoveredLayer = activeObject;
181         var node = layer ? layer.nodeForSelfOrAncestor() : null;
182         if (node)
183             node.highlight();
184         else
185             this._target.domModel.hideDOMNodeHighlight();
186         this._layerTree.hoverLayer(layer);
187         this._layers3DView.hoverObject(activeObject);
188     },
189
190     __proto__: WebInspector.PanelWithSidebarTree.prototype
191 }
192
193 /**
194  * @constructor
195  * @implements {WebInspector.Revealer}
196  */
197 WebInspector.LayersPanel.LayerTreeRevealer = function()
198 {
199 }
200
201 WebInspector.LayersPanel.LayerTreeRevealer.prototype = {
202     /**
203      * @param {!Object} snapshotData
204      */
205     reveal: function(snapshotData)
206     {
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);
211     }
212 }