Web Inspector: remove the remaining TimelineSidebarPanel references
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / ScriptDetailsTimelineView.js
1 /*
2  * Copyright (C) 2014, 2015 Apple 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
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 WebInspector.ScriptDetailsTimelineView = class ScriptDetailsTimelineView extends WebInspector.TimelineView
27 {
28     constructor(timeline, extraArguments)
29     {
30         super(timeline, extraArguments);
31
32         console.assert(timeline.type === WebInspector.TimelineRecord.Type.Script);
33
34         let columns = {name: {}, location: {}, callCount: {}, startTime: {}, totalTime: {}, selfTime: {}, averageTime: {}};
35
36         columns.name.title = WebInspector.UIString("Name");
37         columns.name.width = "10%";
38         columns.name.icon = true;
39         columns.name.disclosure = true;
40
41         columns.location.title = WebInspector.UIString("Location");
42         columns.location.icon = true;
43         columns.location.width = "15%";
44
45         let isSamplingProfiler = !!window.ScriptProfilerAgent;
46         if (isSamplingProfiler)
47             columns.callCount.title = WebInspector.UIString("Samples");
48         else {
49             // COMPATIBILITY(iOS 9): ScriptProfilerAgent did not exist yet, we had call counts, not samples.
50             columns.callCount.title = WebInspector.UIString("Calls");
51         }
52         columns.callCount.width = "5%";
53         columns.callCount.aligned = "right";
54
55         columns.startTime.title = WebInspector.UIString("Start Time");
56         columns.startTime.width = "10%";
57         columns.startTime.aligned = "right";
58
59         columns.totalTime.title = WebInspector.UIString("Total Time");
60         columns.totalTime.width = "10%";
61         columns.totalTime.aligned = "right";
62
63         columns.selfTime.title = WebInspector.UIString("Self Time");
64         columns.selfTime.width = "10%";
65         columns.selfTime.aligned = "right";
66
67         columns.averageTime.title = WebInspector.UIString("Average Time");
68         columns.averageTime.width = "10%";
69         columns.averageTime.aligned = "right";
70
71         for (var column in columns)
72             columns[column].sortable = true;
73
74         this._dataGrid = new WebInspector.ScriptTimelineDataGrid(null, columns, this);
75         this._dataGrid.addEventListener(WebInspector.TimelineDataGrid.Event.FiltersDidChange, this._dataGridFiltersDidChange, this);
76         this._dataGrid.addEventListener(WebInspector.DataGrid.Event.SelectedNodeChanged, this._dataGridNodeSelected, this);
77         this._dataGrid.sortColumnIdentifierSetting = new WebInspector.Setting("script-timeline-view-sort", "startTime");
78         this._dataGrid.sortOrderSetting = new WebInspector.Setting("script-timeline-view-sort-order", WebInspector.DataGrid.SortOrder.Ascending);
79
80         this.element.classList.add("script");
81         this.addSubview(this._dataGrid);
82
83         timeline.addEventListener(WebInspector.Timeline.Event.RecordAdded, this._scriptTimelineRecordAdded, this);
84         timeline.addEventListener(WebInspector.Timeline.Event.Refreshed, this._scriptTimelineRecordRefreshed, this);
85
86         this._pendingRecords = [];
87     }
88
89     // Public
90
91     shown()
92     {
93         super.shown();
94
95         this._dataGrid.shown();
96     }
97
98     hidden()
99     {
100         this._dataGrid.hidden();
101
102         super.hidden();
103     }
104
105     closed()
106     {
107         console.assert(this.representedObject instanceof WebInspector.Timeline);
108         this.representedObject.removeEventListener(null, null, this);
109
110         this._dataGrid.closed();
111     }
112
113     get selectionPathComponents()
114     {
115         var dataGridNode = this._dataGrid.selectedNode;
116         if (!dataGridNode)
117             return null;
118
119         var pathComponents = [];
120
121         while (dataGridNode && !dataGridNode.root) {
122             console.assert(dataGridNode instanceof WebInspector.TimelineDataGridNode);
123             if (dataGridNode.hidden)
124                 return null;
125
126             let representedObject = null;
127             if (dataGridNode instanceof WebInspector.ProfileNodeDataGridNode)
128                 representedObject = dataGridNode.profileNode;
129
130             let pathComponent = new WebInspector.TimelineDataGridNodePathComponent(dataGridNode);
131             pathComponent.addEventListener(WebInspector.HierarchicalPathComponent.Event.SiblingWasSelected, this.dataGridNodePathComponentSelected, this);
132             pathComponents.unshift(pathComponent);
133             dataGridNode = dataGridNode.parent;
134         }
135
136         return pathComponents;
137     }
138
139     reset()
140     {
141         super.reset();
142
143         this._dataGrid.reset();
144
145         this._pendingRecords = [];
146     }
147
148     // Protected
149
150     dataGridNodePathComponentSelected(event)
151     {
152         let dataGridNode = event.data.pathComponent.timelineDataGridNode;
153         console.assert(dataGridNode.dataGrid === this._dataGrid);
154
155         dataGridNode.revealAndSelect();
156     }
157
158     layout()
159     {
160         if (this.startTime !== this._oldStartTime || this.endTime !== this._oldEndTime) {
161             let dataGridNode = this._dataGrid.children[0];
162             while (dataGridNode) {
163                 dataGridNode.updateRangeTimes(this.startTime, this.endTime);
164                 if (dataGridNode.revealed)
165                     dataGridNode.refreshIfNeeded();
166                 dataGridNode = dataGridNode.traverseNextNode(false, null, true);
167             }
168
169             this._oldStartTime = this.startTime;
170             this._oldEndTime = this.endTime;
171         }
172
173         this._processPendingRecords();
174     }
175
176     // Private
177
178     _processPendingRecords()
179     {
180         if (WebInspector.timelineManager.scriptProfilerIsTracking())
181             return;
182
183         if (!this._pendingRecords.length)
184             return;
185
186         let zeroTime = this.zeroTime;
187         let startTime = this.startTime;
188         let endTime = this.endTime;
189
190         for (let scriptTimelineRecord of this._pendingRecords) {
191             let rootNodes = [];
192             if (scriptTimelineRecord.profile) {
193                 // FIXME: Support using the bottom-up tree once it is implemented.
194                 rootNodes = scriptTimelineRecord.profile.topDownRootNodes;
195             }
196
197             let dataGridNode = new WebInspector.ScriptTimelineDataGridNode(scriptTimelineRecord, zeroTime);
198             this._dataGrid.addRowInSortOrder(null, dataGridNode);
199
200             for (let profileNode of rootNodes) {
201                 let profileNodeDataGridNode = new WebInspector.ProfileNodeDataGridNode(profileNode, zeroTime, startTime, endTime);
202                 this._dataGrid.addRowInSortOrder(null, profileNodeDataGridNode, dataGridNode);
203             }
204         }
205
206         this._pendingRecords = [];
207     }
208
209     _scriptTimelineRecordAdded(event)
210     {
211         var scriptTimelineRecord = event.data.record;
212         console.assert(scriptTimelineRecord instanceof WebInspector.ScriptTimelineRecord);
213
214         this._pendingRecords.push(scriptTimelineRecord);
215
216         this.needsLayout();
217     }
218
219     _scriptTimelineRecordRefreshed(event)
220     {
221         this.needsLayout();
222     }
223
224     _dataGridFiltersDidChange(event)
225     {
226         // FIXME: <https://webkit.org/b/154924> Web Inspector: hook up grid row filtering in the new Timelines UI
227     }
228
229     _dataGridNodeSelected(event)
230     {
231         this.dispatchEventToListeners(WebInspector.ContentView.Event.SelectionPathComponentsDidChange);
232     }
233 };