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

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: 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._onMouseHover.bind(this), tr ue);
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.Updated , this._update.bind(this)); 46 this._dataGrid.addEventListener(WebInspector.ViewportDataGrid.Events.Updated , 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;
49 } 54 }
50 55
51 WebInspector.NetworkTimelineColumn.prototype = { 56 WebInspector.NetworkTimelineColumn.prototype = {
52 wasShown: function() 57 wasShown: function()
53 { 58 {
54 this.scheduleUpdate(); 59 this.scheduleUpdate();
55 }, 60 },
56 61
57 scheduleRefreshData: function() 62 scheduleRefreshData: function()
58 { 63 {
59 this._needsRefreshData = true; 64 this._needsRefreshData = true;
60 }, 65 },
61 66
62 _refreshDataIfNeeded: function() 67 _refreshDataIfNeeded: function()
63 { 68 {
64 if (!this._needsRefreshData) 69 if (!this._needsRefreshData)
65 return; 70 return;
66 this._needsRefreshData = false; 71 this._needsRefreshData = false;
67 var currentNode = this._dataGrid.rootNode(); 72 var currentNode = this._dataGrid.rootNode();
68 this._requestData = []; 73 this._requestData = [];
69 while (currentNode = currentNode.traverseNextNode(true)) 74 while (currentNode = currentNode.traverseNextNode(true))
70 this._requestData.push(currentNode.request()); 75 this._requestData.push(currentNode.request());
71 }, 76 },
72 77
78 /**
79 * @param {?WebInspector.NetworkRequest} request
80 */
81 setHoveredRequest: function(request)
82 {
83 this._hoveredRequest = request;
84 this.scheduleUpdate();
85 },
86
87 _onMouseHover: function(event)
dgozman 2016/10/12 17:31:32 JSDoc....
allada 2016/10/12 19:15:29 Done.
88 {
89 var request = this._requestFromPoint(event.offsetX, event.offsetY);
90 this._networkLogView.setHoveredRequest(request);
91 },
92
73 _onMouseWheel: function(event) 93 _onMouseWheel: function(event)
74 { 94 {
75 this._vScrollElement.scrollTop -= event.wheelDeltaY; 95 this._vScrollElement.scrollTop -= event.wheelDeltaY;
76 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ; 96 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ;
97 var request = this._requestFromPoint(event.offsetX, event.offsetY);
98 this._networkLogView.setHoveredRequest(request);
77 }, 99 },
78 100
79 _onScroll: function(event) 101 _onScroll: function(event)
80 { 102 {
81 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ; 103 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ;
82 }, 104 },
83 105
106 /**
107 * @param {number} x
108 * @param {number} y
109 * @return {?WebInspector.NetworkRequest}
110 */
111 _requestFromPoint: function(x, y)
112 {
113 var rowHeight = this._networkLogView.rowHeight();
114 var scrollTop = this._vScrollElement.scrollTop;
115 return this._requestData[Math.floor((scrollTop + y - this._networkLogVie w.headerHeight()) / rowHeight)] || null;
116 },
117
84 scheduleUpdate: function() 118 scheduleUpdate: function()
85 { 119 {
86 if (this._updateRequestID) 120 if (this._updateRequestID)
87 return; 121 return;
88 this._updateRequestID = this.element.window().requestAnimationFrame(this ._update.bind(this)); 122 this._updateRequestID = this.element.window().requestAnimationFrame(this ._update.bind(this));
89 }, 123 },
90 124
91 _update: function() 125 _update: function()
92 { 126 {
93 this.element.window().cancelAnimationFrame(this._updateRequestID); 127 this.element.window().cancelAnimationFrame(this._updateRequestID);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 context.scale(window.devicePixelRatio, window.devicePixelRatio); 214 context.scale(window.devicePixelRatio, window.devicePixelRatio);
181 context.translate(0, this._networkLogView.headerHeight()); 215 context.translate(0, this._networkLogView.headerHeight());
182 context.rect(0, 0, this._offsetWidth, this._offsetHeight); 216 context.rect(0, 0, this._offsetWidth, this._offsetHeight);
183 context.clip(); 217 context.clip();
184 var rowHeight = this._networkLogView.rowHeight(); 218 var rowHeight = this._networkLogView.rowHeight();
185 var scrollTop = this._vScrollElement.scrollTop; 219 var scrollTop = this._vScrollElement.scrollTop;
186 var firstRequestIndex = Math.floor(scrollTop / rowHeight); 220 var firstRequestIndex = Math.floor(scrollTop / rowHeight);
187 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / rowHeight)); 221 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / rowHeight));
188 for (var i = firstRequestIndex; i < lastRequestIndex; i++) { 222 for (var i = firstRequestIndex; i < lastRequestIndex; i++) {
189 var rowOffset = rowHeight * i; 223 var rowOffset = rowHeight * i;
190 this._decorateRow(context, i, rowOffset - scrollTop, rowHeight);
191 var request = requests[i]; 224 var request = requests[i];
225 this._decorateRow(context, request, i, rowOffset - scrollTop, rowHei ght);
192 var ranges = WebInspector.RequestTimingView.calculateRequestTimeRang es(request, 0); 226 var ranges = WebInspector.RequestTimingView.calculateRequestTimeRang es(request, 0);
193 for (var range of ranges) { 227 for (var range of ranges) {
194 if (range.name === WebInspector.RequestTimeRangeNames.Total || 228 if (range.name === WebInspector.RequestTimeRangeNames.Total ||
195 range.name === WebInspector.RequestTimeRangeNames.Sending || 229 range.name === WebInspector.RequestTimeRangeNames.Sending ||
196 range.end - range.start === 0) 230 range.end - range.start === 0)
197 continue; 231 continue;
198 this._drawBar(context, range, rowOffset - scrollTop); 232 this._drawBar(context, range, rowOffset - scrollTop);
199 } 233 }
200 } 234 }
201 context.restore(); 235 context.restore();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 context.lineWidth = lineWidth; 292 context.lineWidth = lineWidth;
259 context.strokeStyle = borderColor; 293 context.strokeStyle = borderColor;
260 context.stroke(); 294 context.stroke();
261 } 295 }
262 context.fill(); 296 context.fill();
263 context.restore(); 297 context.restore();
264 }, 298 },
265 299
266 /** 300 /**
267 * @param {!CanvasRenderingContext2D} context 301 * @param {!CanvasRenderingContext2D} context
302 * @param {!WebInspector.NetworkRequest} request
268 * @param {number} rowNumber 303 * @param {number} rowNumber
269 * @param {number} y 304 * @param {number} y
270 * @param {number} rowHeight 305 * @param {number} rowHeight
271 */ 306 */
272 _decorateRow: function(context, rowNumber, y, rowHeight) 307 _decorateRow: function(context, request, rowNumber, y, rowHeight)
273 { 308 {
309 if (rowNumber % 2 === 1 && this._hoveredRequest !== request)
310 return;
274 context.save(); 311 context.save();
275 if (rowNumber % 2 === 1) 312 context.beginPath();
276 return; 313 var color = WebInspector.themeSupport.patchColor("#f5f5f5", WebInspector .ThemeSupport.ColorUsage.Background);
dgozman 2016/10/12 17:31:32 We should save these colors to variables to only p
allada 2016/10/12 19:15:29 Done.
314 if (this._hoveredRequest === request)
315 color = WebInspector.themeSupport.patchColor("#ebf2fc", WebInspector .ThemeSupport.ColorUsage.Background);
277 316
278 context.beginPath(); 317 context.fillStyle = color;
279 context.fillStyle = WebInspector.themeSupport.patchColor("#f5f5f5", WebI nspector.ThemeSupport.ColorUsage.Background);
280 context.rect(0, y, this._offsetWidth, rowHeight); 318 context.rect(0, y, this._offsetWidth, rowHeight);
281 context.fill(); 319 context.fill();
282 context.restore(); 320 context.restore();
283 }, 321 },
284 322
285 __proto__: WebInspector.VBox.prototype 323 __proto__: WebInspector.VBox.prototype
286 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698