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

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

Issue 2409313003: [Devtools] Canvas network timeline experiment establishes scrolling (Closed)
Patch Set: Merge branch 'master' into NETWORK_TIMELINE_4_SCROLL 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 */
11 WebInspector.NetworkTimelineColumn = function(networkLogView, dataGrid) 11 WebInspector.NetworkTimelineColumn = function(networkLogView, dataGrid)
12 { 12 {
13 WebInspector.VBox.call(this, true); 13 WebInspector.VBox.call(this, true);
14 this.registerRequiredCSS("network/networkTimelineColumn.css");
15
14 this._canvas = this.contentElement.createChild("canvas"); 16 this._canvas = this.contentElement.createChild("canvas");
15 this._canvas.tabIndex = 1; 17 this._canvas.tabIndex = 1;
16 this.setDefaultFocusedElement(this._canvas); 18 this.setDefaultFocusedElement(this._canvas);
17 19
18 /** @const */ 20 /** @const */
19 this._leftPadding = 5; 21 this._leftPadding = 5;
20 /** @const */ 22 /** @const */
21 this._rightPadding = 5; 23 this._rightPadding = 5;
22 24
23 this._dataGrid = dataGrid; 25 this._dataGrid = dataGrid;
24 this._networkLogView = networkLogView; 26 this._networkLogView = networkLogView;
27
28 this._vScrollElement = this.contentElement.createChild("div", "network-timel ine-v-scroll");
29 this._vScrollContent = this._vScrollElement.createChild("div");
30 this._vScrollElement.addEventListener("scroll", this._onScroll.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 });
33
34 this._dataGridScrollContainer = this._dataGrid.scrollContainer;
35 this._dataGridScrollContainer.addEventListener("mousewheel", event => {
36 event.consume(true);
37 this._onMouseWheel(event);
38 }, true);
39
40 // TODO(allada) When timeline canvas moves out of experiment move this to st ylesheet.
41 this._dataGridScrollContainer.style.overflow = "hidden";
42 this._dataGrid.setScrollContainer(this._vScrollElement);
43
44 this._dataGrid.addEventListener(WebInspector.ViewportDataGrid.Events.Viewpor tCalculated, this._update.bind(this));
45 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.PaddingChanged, this._updateHeight.bind(this));
46
25 /** @type {!Array<!WebInspector.NetworkRequest>} */ 47 /** @type {!Array<!WebInspector.NetworkRequest>} */
26 this._requestData = []; 48 this._requestData = [];
27 } 49 }
28 50
29 WebInspector.NetworkTimelineColumn.prototype = { 51 WebInspector.NetworkTimelineColumn.prototype = {
30 wasShown: function() 52 wasShown: function()
31 { 53 {
32 this.scheduleUpdate(); 54 this.scheduleUpdate();
33 }, 55 },
34 56
35 scheduleRefreshData: function() 57 scheduleRefreshData: function()
36 { 58 {
37 this._needsRefreshData = true; 59 this._needsRefreshData = true;
38 }, 60 },
39 61
40 _refreshDataIfNeeded: function() 62 _refreshDataIfNeeded: function()
41 { 63 {
42 if (!this._needsRefreshData) 64 if (!this._needsRefreshData)
43 return; 65 return;
44 this._needsRefreshData = false; 66 this._needsRefreshData = false;
45 var currentNode = this._dataGrid.rootNode(); 67 var currentNode = this._dataGrid.rootNode();
46 this._requestData = []; 68 this._requestData = [];
47 while (currentNode = currentNode.traverseNextNode(true)) 69 while (currentNode = currentNode.traverseNextNode(true))
48 this._requestData.push(currentNode.request()); 70 this._requestData.push(currentNode.request());
49 this._update(); 71 },
72
73 /**
74 * @param {!Event} event
75 */
76 _onMouseWheel: function(event)
77 {
78 this._vScrollElement.scrollTop -= event.wheelDeltaY;
79 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ;
80 },
81
82 /**
83 * @param {!Event} event
84 */
85 _onScroll: function(event)
86 {
87 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ;
50 }, 88 },
51 89
52 scheduleUpdate: function() 90 scheduleUpdate: function()
53 { 91 {
54 if (this._updateRequestID) 92 if (this._updateRequestID)
55 return; 93 return;
56 this._updateRequestID = this.element.window().requestAnimationFrame(this ._update.bind(this)); 94 this._updateRequestID = this.element.window().requestAnimationFrame(this ._update.bind(this));
57 }, 95 },
58 96
59 _update: function() 97 _update: function()
60 { 98 {
61 this.element.window().cancelAnimationFrame(this._updateRequestID); 99 this.element.window().cancelAnimationFrame(this._updateRequestID);
62 this._updateRequestID = null; 100 this._updateRequestID = null;
63 101
64 this._refreshDataIfNeeded(); 102 this._refreshDataIfNeeded();
65 103
66 this._startTime = this._networkLogView.calculator().minimumBoundary(); 104 this._startTime = this._networkLogView.calculator().minimumBoundary();
67 this._endTime = this._networkLogView.calculator().maximumBoundary(); 105 this._endTime = this._networkLogView.calculator().maximumBoundary();
68 this._resetCanvas(); 106 this._resetCanvas();
69 this._draw(); 107 this._draw();
70 }, 108 },
71 109
110 _updateHeight: function()
111 {
112 var totalHeight = this._dataGridScrollContainer.scrollHeight;
113 this._vScrollContent.style.height = totalHeight + "px";
114 },
115
72 _resetCanvas: function() 116 _resetCanvas: function()
73 { 117 {
74 var ratio = window.devicePixelRatio; 118 var ratio = window.devicePixelRatio;
75 this._canvas.width = this._offsetWidth * ratio; 119 this._canvas.width = this._offsetWidth * ratio;
76 this._canvas.height = this._offsetHeight * ratio; 120 this._canvas.height = this._offsetHeight * ratio;
77 this._canvas.style.width = this._offsetWidth + "px"; 121 this._canvas.style.width = this._offsetWidth + "px";
78 this._canvas.style.height = this._offsetHeight + "px"; 122 this._canvas.style.height = this._offsetHeight + "px";
79 }, 123 },
80 124
81 /** 125 /**
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 case types.Queueing: 161 case types.Queueing:
118 return "white"; 162 return "white";
119 case types.ServiceWorker: 163 case types.ServiceWorker:
120 case types.ServiceWorkerPreparation: 164 case types.ServiceWorkerPreparation:
121 default: 165 default:
122 return "orange"; 166 return "orange";
123 } 167 }
124 }, 168 },
125 169
126 /** 170 /**
127 * @return {number}
128 */
129 _scrollTop: function()
130 {
131 return this._dataGrid.scrollContainer.scrollTop;
132 },
133
134 /**
135 * @param {number} time 171 * @param {number} time
136 * @return {number} 172 * @return {number}
137 */ 173 */
138 _timeToPosition: function(time) 174 _timeToPosition: function(time)
139 { 175 {
140 var availableWidth = this._offsetWidth - this._leftPadding - this._right Padding; 176 var availableWidth = this._offsetWidth - this._leftPadding - this._right Padding;
141 var timeToPixel = availableWidth / (this._endTime - this._startTime); 177 var timeToPixel = availableWidth / (this._endTime - this._startTime);
142 return Math.floor(this._leftPadding + (time - this._startTime) * timeToP ixel); 178 return Math.floor(this._leftPadding + (time - this._startTime) * timeToP ixel);
143 }, 179 },
144 180
145 _draw: function() 181 _draw: function()
146 { 182 {
147 var requests = this._requestData; 183 var requests = this._requestData;
148 var context = this._canvas.getContext("2d"); 184 var context = this._canvas.getContext("2d");
149 context.save(); 185 context.save();
150 context.scale(window.devicePixelRatio, window.devicePixelRatio); 186 context.scale(window.devicePixelRatio, window.devicePixelRatio);
151 context.translate(0, this._networkLogView.headerHeight()); 187 context.translate(0, this._networkLogView.headerHeight());
152 context.rect(0, 0, this._offsetWidth, this._offsetHeight); 188 context.rect(0, 0, this._offsetWidth, this._offsetHeight);
153 context.clip(); 189 context.clip();
154 var rowHeight = this._networkLogView.rowHeight(); 190 var rowHeight = this._networkLogView.rowHeight();
155 var scrollTop = this._scrollTop(); 191 var scrollTop = this._vScrollElement.scrollTop;
156 var firstRequestIndex = Math.floor(scrollTop / rowHeight); 192 var firstRequestIndex = Math.floor(scrollTop / rowHeight);
157 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / rowHeight)); 193 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / rowHeight));
158 for (var i = firstRequestIndex; i < lastRequestIndex; i++) { 194 for (var i = firstRequestIndex; i < lastRequestIndex; i++) {
159 var rowOffset = rowHeight * i; 195 var rowOffset = rowHeight * i;
160 var rowNumber = i - firstRequestIndex; 196 this._decorateRow(context, i, rowOffset - scrollTop, rowHeight);
161 this._decorateRow(context, rowNumber, rowOffset - scrollTop, rowHeig ht);
162 var request = requests[i]; 197 var request = requests[i];
163 var ranges = WebInspector.RequestTimingView.calculateRequestTimeRang es(request, 0); 198 var ranges = WebInspector.RequestTimingView.calculateRequestTimeRang es(request, 0);
164 for (var range of ranges) { 199 for (var range of ranges) {
165 if (range.name === WebInspector.RequestTimeRangeNames.Total || 200 if (range.name === WebInspector.RequestTimeRangeNames.Total ||
166 range.name === WebInspector.RequestTimeRangeNames.Sending || 201 range.name === WebInspector.RequestTimeRangeNames.Sending ||
167 range.end - range.start === 0) 202 range.end - range.start === 0)
168 continue; 203 continue;
169 this._drawBar(context, range, rowOffset - scrollTop); 204 this._drawBar(context, range, rowOffset - scrollTop);
170 } 205 }
171 } 206 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 283
249 context.beginPath(); 284 context.beginPath();
250 context.fillStyle = WebInspector.themeSupport.patchColor("#f5f5f5", WebI nspector.ThemeSupport.ColorUsage.Background); 285 context.fillStyle = WebInspector.themeSupport.patchColor("#f5f5f5", WebI nspector.ThemeSupport.ColorUsage.Background);
251 context.rect(0, y, this._offsetWidth, rowHeight); 286 context.rect(0, y, this._offsetWidth, rowHeight);
252 context.fill(); 287 context.fill();
253 context.restore(); 288 context.restore();
254 }, 289 },
255 290
256 __proto__: WebInspector.VBox.prototype 291 __proto__: WebInspector.VBox.prototype
257 } 292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698