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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/network/NetworkTimelineColumn.js

Issue 2412013002: [Devtools] Added hover support for network timeline experiment (Closed)
Patch Set: Changes Created 4 years, 2 months 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.NetworkLogView} networkLogView 8 * @param {!WebInspector.NetworkLogView} networkLogView
9 * @param {!WebInspector.SortableDataGrid} dataGrid 9 * @param {!WebInspector.SortableDataGrid} dataGrid
10 */ 10 */
(...skipping 12 matching lines...) Expand all
23 this._rightPadding = 5; 23 this._rightPadding = 5;
24 24
25 this._dataGrid = dataGrid; 25 this._dataGrid = dataGrid;
26 this._networkLogView = networkLogView; 26 this._networkLogView = networkLogView;
27 27
28 this._vScrollElement = this.contentElement.createChild("div", "network-timel ine-v-scroll"); 28 this._vScrollElement = this.contentElement.createChild("div", "network-timel ine-v-scroll");
29 this._vScrollContent = this._vScrollElement.createChild("div"); 29 this._vScrollContent = this._vScrollElement.createChild("div");
30 this._vScrollElement.addEventListener("scroll", this._onScroll.bind(this), { passive: true }); 30 this._vScrollElement.addEventListener("scroll", this._onScroll.bind(this), { passive: true });
31 this._vScrollElement.addEventListener("mousewheel", this._onMouseWheel.bind( this), { passive: true }); 31 this._vScrollElement.addEventListener("mousewheel", this._onMouseWheel.bind( this), { passive: true });
32 this._canvas.addEventListener("mousewheel", this._onMouseWheel.bind(this), { passive: true }); 32 this._canvas.addEventListener("mousewheel", this._onMouseWheel.bind(this), { passive: true });
33 this._canvas.addEventListener("mousemove", this._onMouseMove.bind(this), tru e);
34 this._canvas.addEventListener("mouseleave", this.setHoveredRequest.bind(this , null), true);
33 35
34 this._dataGridScrollContainer = this._dataGrid.scrollContainer; 36 this._dataGridScrollContainer = this._dataGrid.scrollContainer;
35 this._dataGridScrollContainer.addEventListener("mousewheel", event => { 37 this._dataGridScrollContainer.addEventListener("mousewheel", event => {
36 event.consume(true); 38 event.consume(true);
37 this._onMouseWheel(event); 39 this._onMouseWheel(event);
38 }, true); 40 }, true);
39 41
40 // TODO(allada) When timeline canvas moves out of experiment move this to st ylesheet. 42 // TODO(allada) When timeline canvas moves out of experiment move this to st ylesheet.
41 this._dataGridScrollContainer.style.overflow = "hidden"; 43 this._dataGridScrollContainer.style.overflow = "hidden";
42 this._dataGrid.setScrollContainer(this._vScrollElement); 44 this._dataGrid.setScrollContainer(this._vScrollElement);
43 45
44 this._dataGrid.addEventListener(WebInspector.ViewportDataGrid.Events.Viewpor tCalculated, this._update.bind(this)); 46 this._dataGrid.addEventListener(WebInspector.ViewportDataGrid.Events.Viewpor tCalculated, this._update.bind(this));
45 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.PaddingChanged, this._updateHeight.bind(this)); 47 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.PaddingChanged, this._updateHeight.bind(this));
46 48
47 /** @type {!Array<!WebInspector.NetworkRequest>} */ 49 /** @type {!Array<!WebInspector.NetworkRequest>} */
48 this._requestData = []; 50 this._requestData = [];
51
52 /** @type {?WebInspector.NetworkRequest} */
53 this._hoveredRequest = null;
54
55 this._rowStripeColor = WebInspector.themeSupport.patchColor("#f5f5f5", WebIn spector.ThemeSupport.ColorUsage.Background);
56 this._rowHoverColor = WebInspector.themeSupport.patchColor("#ebf2fc", WebIns pector.ThemeSupport.ColorUsage.Background);
57 }
58
59 WebInspector.NetworkTimelineColumn.Events = {
60 RequestHovered: Symbol("RequestHovered")
49 } 61 }
50 62
51 WebInspector.NetworkTimelineColumn.prototype = { 63 WebInspector.NetworkTimelineColumn.prototype = {
52 wasShown: function() 64 wasShown: function()
53 { 65 {
54 this.scheduleUpdate(); 66 this.scheduleUpdate();
55 }, 67 },
56 68
57 scheduleRefreshData: function() 69 scheduleRefreshData: function()
58 { 70 {
59 this._needsRefreshData = true; 71 this._needsRefreshData = true;
60 }, 72 },
61 73
62 _refreshDataIfNeeded: function() 74 _refreshDataIfNeeded: function()
63 { 75 {
64 if (!this._needsRefreshData) 76 if (!this._needsRefreshData)
65 return; 77 return;
66 this._needsRefreshData = false; 78 this._needsRefreshData = false;
67 var currentNode = this._dataGrid.rootNode(); 79 var currentNode = this._dataGrid.rootNode();
68 this._requestData = []; 80 this._requestData = [];
69 while (currentNode = currentNode.traverseNextNode(true)) 81 while (currentNode = currentNode.traverseNextNode(true))
70 this._requestData.push(currentNode.request()); 82 this._requestData.push(currentNode.request());
71 }, 83 },
72 84
73 /** 85 /**
86 * @param {?WebInspector.NetworkRequest} request
87 */
88 setHoveredRequest: function(request)
89 {
90 this._hoveredRequest = request;
91 this.scheduleUpdate();
92 },
93
94 /**
95 * @param {!Event} event
96 */
97 _onMouseMove: function(event)
98 {
99 var request = this._getRequestFromPoint(event.offsetX, event.offsetY);
100 this.dispatchEventToListeners(WebInspector.NetworkTimelineColumn.Events. RequestHovered, request);
101 },
102
103 /**
74 * @param {!Event} event 104 * @param {!Event} event
75 */ 105 */
76 _onMouseWheel: function(event) 106 _onMouseWheel: function(event)
77 { 107 {
78 this._vScrollElement.scrollTop -= event.wheelDeltaY; 108 this._vScrollElement.scrollTop -= event.wheelDeltaY;
79 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ; 109 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ;
110 var request = this._getRequestFromPoint(event.offsetX, event.offsetY);
111 this.dispatchEventToListeners(WebInspector.NetworkTimelineColumn.Events. RequestHovered, request);
80 }, 112 },
81 113
82 /** 114 /**
83 * @param {!Event} event 115 * @param {!Event} event
84 */ 116 */
85 _onScroll: function(event) 117 _onScroll: function(event)
86 { 118 {
87 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ; 119 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ;
88 }, 120 },
89 121
122 /**
123 * @param {number} x
124 * @param {number} y
125 * @return {?WebInspector.NetworkRequest}
126 */
127 _getRequestFromPoint: function(x, y)
128 {
129 var rowHeight = this._networkLogView.rowHeight();
130 var scrollTop = this._vScrollElement.scrollTop;
131 return this._requestData[Math.floor((scrollTop + y - this._networkLogVie w.headerHeight()) / rowHeight)] || null;
132 },
133
90 scheduleUpdate: function() 134 scheduleUpdate: function()
91 { 135 {
92 if (this._updateRequestID) 136 if (this._updateRequestID)
93 return; 137 return;
94 this._updateRequestID = this.element.window().requestAnimationFrame(this ._update.bind(this)); 138 this._updateRequestID = this.element.window().requestAnimationFrame(this ._update.bind(this));
95 }, 139 },
96 140
97 _update: function() 141 _update: function()
98 { 142 {
99 this.element.window().cancelAnimationFrame(this._updateRequestID); 143 this.element.window().cancelAnimationFrame(this._updateRequestID);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 context.scale(window.devicePixelRatio, window.devicePixelRatio); 230 context.scale(window.devicePixelRatio, window.devicePixelRatio);
187 context.translate(0, this._networkLogView.headerHeight()); 231 context.translate(0, this._networkLogView.headerHeight());
188 context.rect(0, 0, this._offsetWidth, this._offsetHeight); 232 context.rect(0, 0, this._offsetWidth, this._offsetHeight);
189 context.clip(); 233 context.clip();
190 var rowHeight = this._networkLogView.rowHeight(); 234 var rowHeight = this._networkLogView.rowHeight();
191 var scrollTop = this._vScrollElement.scrollTop; 235 var scrollTop = this._vScrollElement.scrollTop;
192 var firstRequestIndex = Math.floor(scrollTop / rowHeight); 236 var firstRequestIndex = Math.floor(scrollTop / rowHeight);
193 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / rowHeight)); 237 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / rowHeight));
194 for (var i = firstRequestIndex; i < lastRequestIndex; i++) { 238 for (var i = firstRequestIndex; i < lastRequestIndex; i++) {
195 var rowOffset = rowHeight * i; 239 var rowOffset = rowHeight * i;
196 this._decorateRow(context, i, rowOffset - scrollTop, rowHeight);
197 var request = requests[i]; 240 var request = requests[i];
241 this._decorateRow(context, request, i, rowOffset - scrollTop, rowHei ght);
198 var ranges = WebInspector.RequestTimingView.calculateRequestTimeRang es(request, 0); 242 var ranges = WebInspector.RequestTimingView.calculateRequestTimeRang es(request, 0);
199 for (var range of ranges) { 243 for (var range of ranges) {
200 if (range.name === WebInspector.RequestTimeRangeNames.Total || 244 if (range.name === WebInspector.RequestTimeRangeNames.Total ||
201 range.name === WebInspector.RequestTimeRangeNames.Sending || 245 range.name === WebInspector.RequestTimeRangeNames.Sending ||
202 range.end - range.start === 0) 246 range.end - range.start === 0)
203 continue; 247 continue;
204 this._drawBar(context, range, rowOffset - scrollTop); 248 this._drawBar(context, range, rowOffset - scrollTop);
205 } 249 }
206 } 250 }
207 context.restore(); 251 context.restore();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 context.lineWidth = lineWidth; 308 context.lineWidth = lineWidth;
265 context.strokeStyle = borderColor; 309 context.strokeStyle = borderColor;
266 context.stroke(); 310 context.stroke();
267 } 311 }
268 context.fill(); 312 context.fill();
269 context.restore(); 313 context.restore();
270 }, 314 },
271 315
272 /** 316 /**
273 * @param {!CanvasRenderingContext2D} context 317 * @param {!CanvasRenderingContext2D} context
318 * @param {!WebInspector.NetworkRequest} request
274 * @param {number} rowNumber 319 * @param {number} rowNumber
275 * @param {number} y 320 * @param {number} y
276 * @param {number} rowHeight 321 * @param {number} rowHeight
277 */ 322 */
278 _decorateRow: function(context, rowNumber, y, rowHeight) 323 _decorateRow: function(context, request, rowNumber, y, rowHeight)
279 { 324 {
325 if (rowNumber % 2 === 1 && this._hoveredRequest !== request)
326 return;
280 context.save(); 327 context.save();
281 if (rowNumber % 2 === 1) 328 context.beginPath();
282 return; 329 var color = this._rowStripeColor;
330 if (this._hoveredRequest === request)
331 color = this._rowHoverColor;
283 332
284 context.beginPath(); 333 context.fillStyle = color;
285 context.fillStyle = WebInspector.themeSupport.patchColor("#f5f5f5", WebI nspector.ThemeSupport.ColorUsage.Background);
286 context.rect(0, y, this._offsetWidth, rowHeight); 334 context.rect(0, y, this._offsetWidth, rowHeight);
287 context.fill(); 335 context.fill();
288 context.restore(); 336 context.restore();
289 }, 337 },
290 338
291 __proto__: WebInspector.VBox.prototype 339 __proto__: WebInspector.VBox.prototype
292 } 340 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698