display:inline on the tbody is causing the width of the iframe to be shrunk to the...
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / NetworkGridContentView.js
1 /*
2  * Copyright (C) 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.NetworkGridContentView = class NetworkGridContentView extends WebInspector.ContentView
27 {
28     constructor(representedObject, extraArguments)
29     {
30         console.assert(extraArguments);
31         console.assert(extraArguments.networkSidebarPanel instanceof WebInspector.NetworkSidebarPanel);
32
33         super(representedObject);
34
35         this._networkSidebarPanel = extraArguments.networkSidebarPanel;
36
37         this._contentTreeOutline = this._networkSidebarPanel.contentTreeOutline;
38         this._contentTreeOutline.addEventListener(WebInspector.TreeOutline.Event.SelectionDidChange, this._treeSelectionDidChange, this);
39
40         var columns = {domain: {}, type: {}, method: {}, scheme: {}, statusCode: {}, cached: {}, size: {}, transferSize: {}, requestSent: {}, latency: {}, duration: {}};
41
42         columns.domain.title = WebInspector.UIString("Domain");
43         columns.domain.width = "10%";
44
45         columns.type.title = WebInspector.UIString("Type");
46         columns.type.width = "8%";
47
48         columns.method.title = WebInspector.UIString("Method");
49         columns.method.width = "6%";
50
51         columns.scheme.title = WebInspector.UIString("Scheme");
52         columns.scheme.width = "6%";
53
54         columns.statusCode.title = WebInspector.UIString("Status");
55         columns.statusCode.width = "6%";
56
57         columns.cached.title = WebInspector.UIString("Cached");
58         columns.cached.width = "6%";
59
60         columns.size.title = WebInspector.UIString("Size");
61         columns.size.width = "8%";
62         columns.size.aligned = "right";
63
64         columns.transferSize.title = WebInspector.UIString("Transferred");
65         columns.transferSize.width = "8%";
66         columns.transferSize.aligned = "right";
67
68         columns.requestSent.title = WebInspector.UIString("Start Time");
69         columns.requestSent.width = "9%";
70         columns.requestSent.aligned = "right";
71
72         columns.latency.title = WebInspector.UIString("Latency");
73         columns.latency.width = "9%";
74         columns.latency.aligned = "right";
75
76         columns.duration.title = WebInspector.UIString("Duration");
77         columns.duration.width = "9%";
78         columns.duration.aligned = "right";
79
80         for (var column in columns)
81             columns[column].sortable = true;
82
83         this._dataGrid = new WebInspector.TimelineDataGrid(columns, this._contentTreeOutline);
84         this._dataGrid.addEventListener(WebInspector.DataGrid.Event.SelectedNodeChanged, this._dataGridNodeSelected, this);
85         this._dataGrid.sortColumnIdentifierSetting = new WebInspector.Setting("network-grid-content-view-sort", "requestSent");
86         this._dataGrid.sortOrderSetting = new WebInspector.Setting("network-grid-content-view-sort-order", WebInspector.DataGrid.SortOrder.Ascending);
87
88         this.element.classList.add("network-grid");
89         this.addSubview(this._dataGrid);
90
91         var networkTimeline = WebInspector.timelineManager.persistentNetworkTimeline;
92         networkTimeline.addEventListener(WebInspector.Timeline.Event.RecordAdded, this._networkTimelineRecordAdded, this);
93         networkTimeline.addEventListener(WebInspector.Timeline.Event.Reset, this._networkTimelineReset, this);
94
95         this._clearNetworkItemsNavigationItem = new WebInspector.ButtonNavigationItem("clear-network-items", WebInspector.UIString("Clear Network Items"), "Images/NavigationItemTrash.svg", 15, 15);
96         this._clearNetworkItemsNavigationItem.addEventListener(WebInspector.ButtonNavigationItem.Event.Clicked, this._clearNetworkItems, this);
97
98         this._pendingRecords = [];
99     }
100
101     // Public
102
103     get navigationSidebarTreeOutline()
104     {
105         return this._contentTreeOutline;
106     }
107
108     get selectionPathComponents()
109     {
110         if (!this._contentTreeOutline.selectedTreeElement || this._contentTreeOutline.selectedTreeElement.hidden)
111             return null;
112
113         var pathComponent = new WebInspector.GeneralTreeElementPathComponent(this._contentTreeOutline.selectedTreeElement);
114         pathComponent.addEventListener(WebInspector.HierarchicalPathComponent.Event.SiblingWasSelected, this._treeElementPathComponentSelected, this);
115         return [pathComponent];
116     }
117
118     get zeroTime()
119     {
120         return WebInspector.timelineManager.persistentNetworkTimeline.startTime;
121     }
122
123     get navigationItems()
124     {
125         return [this._clearNetworkItemsNavigationItem];
126     }
127
128     shown()
129     {
130         super.shown();
131
132         this._dataGrid.shown();
133     }
134
135     hidden()
136     {
137         this._dataGrid.hidden();
138
139         super.hidden();
140     }
141
142     closed()
143     {
144         this._dataGrid.closed();
145     }
146
147     reset()
148     {
149         this._contentTreeOutline.removeChildren();
150         this._dataGrid.reset();
151     }
152
153     // Protected
154
155     layout()
156     {
157         this._processPendingRecords();
158     }
159
160     // Private
161
162     _processPendingRecords()
163     {
164         if (!this._pendingRecords.length)
165             return;
166
167         for (var resourceTimelineRecord of this._pendingRecords) {
168             // Skip the record if it already exists in the tree.
169             var treeElement = this._contentTreeOutline.findTreeElement(resourceTimelineRecord.resource);
170             if (treeElement)
171                 continue;
172
173             treeElement = new WebInspector.ResourceTreeElement(resourceTimelineRecord.resource);
174             var dataGridNode = new WebInspector.ResourceTimelineDataGridNode(resourceTimelineRecord, false, this);
175
176             this._dataGrid.addRowInSortOrder(treeElement, dataGridNode);
177         }
178
179         this._pendingRecords = [];
180     }
181
182     _networkTimelineReset(event)
183     {
184         this.reset();
185     }
186
187     _networkTimelineRecordAdded(event)
188     {
189         var resourceTimelineRecord = event.data.record;
190         console.assert(resourceTimelineRecord instanceof WebInspector.ResourceTimelineRecord);
191
192         this._pendingRecords.push(resourceTimelineRecord);
193
194         this.needsLayout();
195     }
196
197     _treeElementPathComponentSelected(event)
198     {
199         var dataGridNode = this._dataGrid.dataGridNodeForTreeElement(event.data.pathComponent.generalTreeElement);
200         if (!dataGridNode)
201             return;
202         dataGridNode.revealAndSelect();
203     }
204
205     _treeSelectionDidChange(event)
206     {
207         this.dispatchEventToListeners(WebInspector.ContentView.Event.SelectionPathComponentsDidChange);
208
209         if (!this._networkSidebarPanel.canShowDifferentContentView())
210             return;
211
212         let treeElement = event.data.selectedElement;
213         if (treeElement instanceof WebInspector.ResourceTreeElement) {
214             WebInspector.showRepresentedObject(treeElement.representedObject);
215             return;
216         }
217
218         console.error("Unknown tree element", treeElement);
219     }
220
221     _dataGridNodeSelected(event)
222     {
223         this.dispatchEventToListeners(WebInspector.ContentView.Event.SelectionPathComponentsDidChange);
224     }
225
226     _clearNetworkItems(event) {
227         this.reset();
228     }
229 };