Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/timeline/TimelineTreeView.js

Issue 2444223002: [Devtools] Cleanup DataGrid's typecast and identifier naming (Closed)
Patch Set: changes Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends {WebInspector.VBox} 7 * @extends {WebInspector.VBox}
8 * @param {!WebInspector.TimelineModel} model 8 * @param {!WebInspector.TimelineModel} model
9 * @param {!Array<!WebInspector.TimelineModel.Filter>} filters 9 * @param {!Array<!WebInspector.TimelineModel.Filter>} filters
10 */ 10 */
11 WebInspector.TimelineTreeView = function(model, filters) 11 WebInspector.TimelineTreeView = function(model, filters)
12 { 12 {
13 WebInspector.VBox.call(this); 13 WebInspector.VBox.call(this);
14 this.element.classList.add("timeline-tree-view"); 14 this.element.classList.add("timeline-tree-view");
15 15
16 this._model = model; 16 this._model = model;
17 this._linkifier = new WebInspector.Linkifier(); 17 this._linkifier = new WebInspector.Linkifier();
18 18
19 this._filters = filters.slice(); 19 this._filters = filters.slice();
20 20
21 var columns = []; 21 var columns = /** @type {!Array<!WebInspector.DataGrid.ColumnDescriptor>} */ ([]);
22 this._populateColumns(columns); 22 this._populateColumns(columns);
23 23
24 var mainView = new WebInspector.VBox(); 24 var mainView = new WebInspector.VBox();
25 this._populateToolbar(mainView.element); 25 this._populateToolbar(mainView.element);
26 this._dataGrid = new WebInspector.SortableDataGrid(columns); 26 this._dataGrid = new WebInspector.SortableDataGrid(columns);
27 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SortingChanged, this._sortingChanged, this); 27 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SortingChanged, this._sortingChanged, this);
28 this._dataGrid.element.addEventListener("mousemove", this._onMouseMove.bind( this), true); 28 this._dataGrid.element.addEventListener("mousemove", this._onMouseMove.bind( this), true);
29 this._dataGrid.setResizeMethod(WebInspector.DataGrid.ResizeMethod.Last); 29 this._dataGrid.setResizeMethod(WebInspector.DataGrid.ResizeMethod.Last);
30 this._dataGrid.asWidget().show(mainView.element); 30 this._dataGrid.asWidget().show(mainView.element);
31 31
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 */ 160 */
161 _populateColumns: function(columns) 161 _populateColumns: function(columns)
162 { 162 {
163 columns.push({id: "self", title: WebInspector.UIString("Self Time"), wid th: "110px", fixedWidth: true, sortable: true}); 163 columns.push({id: "self", title: WebInspector.UIString("Self Time"), wid th: "110px", fixedWidth: true, sortable: true});
164 columns.push({id: "total", title: WebInspector.UIString("Total Time"), w idth: "110px", fixedWidth: true, sortable: true}); 164 columns.push({id: "total", title: WebInspector.UIString("Total Time"), w idth: "110px", fixedWidth: true, sortable: true});
165 columns.push({id: "activity", title: WebInspector.UIString("Activity"), disclosure: true, sortable: true}); 165 columns.push({id: "activity", title: WebInspector.UIString("Activity"), disclosure: true, sortable: true});
166 }, 166 },
167 167
168 _sortingChanged: function() 168 _sortingChanged: function()
169 { 169 {
170 var columnIdentifier = this._dataGrid.sortColumnIdentifier(); 170 var columnId = this._dataGrid.sortColumnId();
171 if (!columnIdentifier) 171 if (!columnId)
172 return; 172 return;
173 var sortFunction; 173 var sortFunction;
174 switch (columnIdentifier) { 174 switch (columnId) {
175 case "startTime": 175 case "startTime":
176 sortFunction = compareStartTime; 176 sortFunction = compareStartTime;
177 break; 177 break;
178 case "self": 178 case "self":
179 sortFunction = compareNumericField.bind(null, "selfTime"); 179 sortFunction = compareNumericField.bind(null, "selfTime");
180 break; 180 break;
181 case "total": 181 case "total":
182 sortFunction = compareNumericField.bind(null, "totalTime"); 182 sortFunction = compareNumericField.bind(null, "totalTime");
183 break; 183 break;
184 case "activity": 184 case "activity":
185 sortFunction = compareName; 185 sortFunction = compareName;
186 break; 186 break;
187 default: 187 default:
188 console.assert(false, "Unknown sort field: " + columnIdentifier); 188 console.assert(false, "Unknown sort field: " + columnId);
189 return; 189 return;
190 } 190 }
191 this._dataGrid.sortNodes(sortFunction, !this._dataGrid.isSortOrderAscend ing()); 191 this._dataGrid.sortNodes(sortFunction, !this._dataGrid.isSortOrderAscend ing());
192 192
193 /** 193 /**
194 * @param {string} field 194 * @param {string} field
195 * @param {!WebInspector.DataGridNode} a 195 * @param {!WebInspector.DataGridNode} a
196 * @param {!WebInspector.DataGridNode} b 196 * @param {!WebInspector.DataGridNode} b
197 * @return {number} 197 * @return {number}
198 */ 198 */
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 this._treeView = treeView; 309 this._treeView = treeView;
310 this._grandTotalTime = grandTotalTime; 310 this._grandTotalTime = grandTotalTime;
311 this._maxSelfTime = maxSelfTime; 311 this._maxSelfTime = maxSelfTime;
312 this._maxTotalTime = maxTotalTime; 312 this._maxTotalTime = maxTotalTime;
313 WebInspector.SortableDataGridNode.call(this, null, false); 313 WebInspector.SortableDataGridNode.call(this, null, false);
314 }; 314 };
315 315
316 WebInspector.TimelineTreeView.GridNode.prototype = { 316 WebInspector.TimelineTreeView.GridNode.prototype = {
317 /** 317 /**
318 * @override 318 * @override
319 * @param {string} columnIdentifier 319 * @param {string} columnId
320 * @return {!Element} 320 * @return {!Element}
321 */ 321 */
322 createCell: function(columnIdentifier) 322 createCell: function(columnId)
323 { 323 {
324 if (columnIdentifier === "activity") 324 if (columnId === "activity")
325 return this._createNameCell(columnIdentifier); 325 return this._createNameCell(columnId);
326 return this._createValueCell(columnIdentifier) || WebInspector.DataGridN ode.prototype.createCell.call(this, columnIdentifier); 326 return this._createValueCell(columnId) || WebInspector.DataGridNode.prot otype.createCell.call(this, columnId);
327 }, 327 },
328 328
329 /** 329 /**
330 * @param {string} columnIdentifier 330 * @param {string} columnId
331 * @return {!Element} 331 * @return {!Element}
332 */ 332 */
333 _createNameCell: function(columnIdentifier) 333 _createNameCell: function(columnId)
334 { 334 {
335 var cell = this.createTD(columnIdentifier); 335 var cell = this.createTD(columnId);
336 var container = cell.createChild("div", "name-container"); 336 var container = cell.createChild("div", "name-container");
337 var icon = container.createChild("div", "activity-icon"); 337 var icon = container.createChild("div", "activity-icon");
338 var name = container.createChild("div", "activity-name"); 338 var name = container.createChild("div", "activity-name");
339 var event = this._profileNode.event; 339 var event = this._profileNode.event;
340 if (this._profileNode.isGroupNode()) { 340 if (this._profileNode.isGroupNode()) {
341 var treeView = /** @type {!WebInspector.AggregatedTimelineTreeView} */ (this._treeView); 341 var treeView = /** @type {!WebInspector.AggregatedTimelineTreeView} */ (this._treeView);
342 var info = treeView._displayInfoForGroupNode(this._profileNode); 342 var info = treeView._displayInfoForGroupNode(this._profileNode);
343 name.textContent = info.name; 343 name.textContent = info.name;
344 icon.style.backgroundColor = info.color; 344 icon.style.backgroundColor = info.color;
345 } else if (event) { 345 } else if (event) {
346 var data = event.args["data"]; 346 var data = event.args["data"];
347 var deoptReason = data && data["deoptReason"]; 347 var deoptReason = data && data["deoptReason"];
348 if (deoptReason) 348 if (deoptReason)
349 container.createChild("div", "activity-warning").title = WebInsp ector.UIString("Not optimized: %s", deoptReason); 349 container.createChild("div", "activity-warning").title = WebInsp ector.UIString("Not optimized: %s", deoptReason);
350 name.textContent = event.name === WebInspector.TimelineModel.RecordT ype.JSFrame 350 name.textContent = event.name === WebInspector.TimelineModel.RecordT ype.JSFrame
351 ? WebInspector.beautifyFunctionName(event.args["data"]["function Name"]) 351 ? WebInspector.beautifyFunctionName(event.args["data"]["function Name"])
352 : WebInspector.TimelineUIUtils.eventTitle(event); 352 : WebInspector.TimelineUIUtils.eventTitle(event);
353 var link = this._treeView._linkifyLocation(event); 353 var link = this._treeView._linkifyLocation(event);
354 if (link) 354 if (link)
355 container.createChild("div", "activity-link").appendChild(link); 355 container.createChild("div", "activity-link").appendChild(link);
356 icon.style.backgroundColor = WebInspector.TimelineUIUtils.eventColor (event); 356 icon.style.backgroundColor = WebInspector.TimelineUIUtils.eventColor (event);
357 } 357 }
358 return cell; 358 return cell;
359 }, 359 },
360 360
361 /** 361 /**
362 * @param {string} columnIdentifier 362 * @param {string} columnId
363 * @return {?Element} 363 * @return {?Element}
364 */ 364 */
365 _createValueCell: function(columnIdentifier) 365 _createValueCell: function(columnId)
366 { 366 {
367 if (columnIdentifier !== "self" && columnIdentifier !== "total" && colum nIdentifier !== "startTime") 367 if (columnId !== "self" && columnId !== "total" && columnId !== "startTi me")
368 return null; 368 return null;
369 369
370 var showPercents = false; 370 var showPercents = false;
371 var value; 371 var value;
372 var maxTime; 372 var maxTime;
373 switch (columnIdentifier) { 373 switch (columnId) {
374 case "startTime": 374 case "startTime":
375 value = this._profileNode.event.startTime - this._treeView._model.mi nimumRecordTime(); 375 value = this._profileNode.event.startTime - this._treeView._model.mi nimumRecordTime();
376 break; 376 break;
377 case "self": 377 case "self":
378 value = this._profileNode.selfTime; 378 value = this._profileNode.selfTime;
379 maxTime = this._maxSelfTime; 379 maxTime = this._maxSelfTime;
380 showPercents = true; 380 showPercents = true;
381 break; 381 break;
382 case "total": 382 case "total":
383 value = this._profileNode.totalTime; 383 value = this._profileNode.totalTime;
384 maxTime = this._maxTotalTime; 384 maxTime = this._maxTotalTime;
385 showPercents = true; 385 showPercents = true;
386 break; 386 break;
387 default: 387 default:
388 return null; 388 return null;
389 } 389 }
390 var cell = this.createTD(columnIdentifier); 390 var cell = this.createTD(columnId);
391 cell.className = "numeric-column"; 391 cell.className = "numeric-column";
392 var textDiv = cell.createChild("div"); 392 var textDiv = cell.createChild("div");
393 textDiv.createChild("span").textContent = WebInspector.UIString("%.1f\u2 009ms", value); 393 textDiv.createChild("span").textContent = WebInspector.UIString("%.1f\u2 009ms", value);
394 394
395 if (showPercents && this._treeView._exposePercentages()) 395 if (showPercents && this._treeView._exposePercentages())
396 textDiv.createChild("span", "percent-column").textContent = WebInspe ctor.UIString("%.1f\u2009%%", value / this._grandTotalTime * 100); 396 textDiv.createChild("span", "percent-column").textContent = WebInspe ctor.UIString("%.1f\u2009%%", value / this._grandTotalTime * 100);
397 if (maxTime) { 397 if (maxTime) {
398 textDiv.classList.add("background-percent-bar"); 398 textDiv.classList.add("background-percent-bar");
399 cell.createChild("div", "background-bar-container").createChild("div ", "background-bar").style.width = (value * 100 / maxTime).toFixed(1) + "%"; 399 cell.createChild("div", "background-bar-container").createChild("div ", "background-bar").style.width = (value * 100 / maxTime).toFixed(1) + "%";
400 } 400 }
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 /** 828 /**
829 * @constructor 829 * @constructor
830 * @extends {WebInspector.VBox} 830 * @extends {WebInspector.VBox}
831 */ 831 */
832 WebInspector.TimelineStackView = function(treeView) 832 WebInspector.TimelineStackView = function(treeView)
833 { 833 {
834 WebInspector.VBox.call(this); 834 WebInspector.VBox.call(this);
835 var header = this.element.createChild("div", "timeline-stack-view-header"); 835 var header = this.element.createChild("div", "timeline-stack-view-header");
836 header.textContent = WebInspector.UIString("Heaviest stack"); 836 header.textContent = WebInspector.UIString("Heaviest stack");
837 this._treeView = treeView; 837 this._treeView = treeView;
838 var columns = [ 838 var columns = /** @type {!Array<!WebInspector.DataGrid.ColumnDescriptor>} */ ([
839 {id: "total", title: WebInspector.UIString("Total Time"), fixedWidth: tr ue, width: "110px"}, 839 {id: "total", title: WebInspector.UIString("Total Time"), fixedWidth: tr ue, width: "110px"},
840 {id: "activity", title: WebInspector.UIString("Activity")} 840 {id: "activity", title: WebInspector.UIString("Activity")}
841 ]; 841 ]);
842 this._dataGrid = new WebInspector.ViewportDataGrid(columns); 842 this._dataGrid = new WebInspector.ViewportDataGrid(columns);
843 this._dataGrid.setResizeMethod(WebInspector.DataGrid.ResizeMethod.Last); 843 this._dataGrid.setResizeMethod(WebInspector.DataGrid.ResizeMethod.Last);
844 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SelectedNode, t his._onSelectionChanged, this); 844 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SelectedNode, t his._onSelectionChanged, this);
845 this._dataGrid.asWidget().show(this.element); 845 this._dataGrid.asWidget().show(this.element);
846 }; 846 };
847 847
848 /** @enum {symbol} */ 848 /** @enum {symbol} */
849 WebInspector.TimelineStackView.Events = { 849 WebInspector.TimelineStackView.Events = {
850 SelectionChanged: Symbol("SelectionChanged") 850 SelectionChanged: Symbol("SelectionChanged")
851 }; 851 };
(...skipping 27 matching lines...) Expand all
879 return selectedNode && /** @type {!WebInspector.TimelineTreeView.GridNod e} */ (selectedNode)._profileNode; 879 return selectedNode && /** @type {!WebInspector.TimelineTreeView.GridNod e} */ (selectedNode)._profileNode;
880 }, 880 },
881 881
882 _onSelectionChanged: function() 882 _onSelectionChanged: function()
883 { 883 {
884 this.dispatchEventToListeners(WebInspector.TimelineStackView.Events.Sele ctionChanged); 884 this.dispatchEventToListeners(WebInspector.TimelineStackView.Events.Sele ctionChanged);
885 }, 885 },
886 886
887 __proto__: WebInspector.VBox.prototype 887 __proto__: WebInspector.VBox.prototype
888 }; 888 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698