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

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

Issue 2400093002: [Devtools] New network timeline experiment Part 1 (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
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * @constructor
7 * @extends {WebInspector.VBox}
8 * @param {!WebInspector.NetworkLogView} networkLogView
9 * @param {!WebInspector.SortableDataGrid} dataGrid
10 */
11 WebInspector.NetworkTimelineColumn = function(networkLogView, dataGrid)
12 {
13 WebInspector.VBox.call(this, true);
14 this._canvas = this.contentElement.createChild("canvas");
15 this._canvas.tabIndex = 1;
16 this.setDefaultFocusedElement(this._canvas);
17
18 /** @const */
19 this._leftPadding = 5;
20 /** @const */
21 this._rightPadding = 5;
22
23 this._dataGrid = dataGrid;
24 this._networkLogView = networkLogView;
25 /** @type {!Array<!WebInspector.NetworkRequest>} */
26 this._requestData = [];
27 }
28
29 WebInspector.NetworkTimelineColumn.prototype = {
30 scheduleUpdate: function()
31 {
32 if (this._updateRequestID)
33 return;
34 this._updateRequestID = this.element.window().requestAnimationFrame(this ._update.bind(this));
35 },
36
37 _update: function()
38 {
39 this.element.window().cancelAnimationFrame(this._updateRequestID);
40 this._updateRequestID = null;
41 this._resetCanvas();
42 this._draw();
43 },
44
45 _resetCanvas: function()
46 {
47 var ratio = window.devicePixelRatio;
48 this._canvas.width = this._offsetWidth * ratio;
49 this._canvas.height = this._offsetHeight * ratio;
50 this._canvas.style.width = this._offsetWidth + "px";
51 this._canvas.style.height = this._offsetHeight + "px";
52 },
53
54 /**
55 * @override
56 */
57 onResize: function()
58 {
59 WebInspector.VBox.prototype.onResize.call(this);
60 this._offsetWidth = this.contentElement.offsetWidth;
61 this._offsetHeight = this.contentElement.offsetHeight;
62 this.scheduleUpdate();
63 },
64
65 /**
66 * @param {!WebInspector.RequestTimeRangeNames} type
67 * @return {string}
68 */
69 _colorForType: function(type)
70 {
71 var types = WebInspector.RequestTimeRangeNames;
72 switch (type) {
73 case types.Receiving:
74 case types.ReceivingPush:
75 return "#03A9F4";
76 case types.Waiting:
77 return "#00C853";
78 case types.Connecting:
79 return "#FF9800";
80 case types.SSL:
81 return "#9C27B0";
82 case types.DNS:
83 return "#009688";
84 case types.Proxy:
85 return "#A1887F";
86 case types.Blocking:
87 return "#AAAAAA";
88 case types.Push:
89 return "#8CDBff";
90 case types.Queueing:
91 return "white";
92 case types.ServiceWorker:
93 case types.ServiceWorkerPreparation:
94 default:
95 return "orange";
96 }
97 },
98
99 /**
100 * @return {number}
101 */
102 _scrollTop: function()
103 {
104 return this._dataGrid.scrollContainer.scrollTop;
105 },
106
107 /**
108 * @param {number} time
109 * @return {number}
110 */
111 _timeToPosition: function(time)
112 {
113 var availableWidth = this._offsetWidth - this._leftPadding - this._right Padding;
114 var timeToPixel = availableWidth / (this._endTime - this._startTime);
115 return Math.floor(this._leftPadding + (time - this._startTime) * timeToP ixel);
116 },
117
118 _draw: function()
119 {
120 var requests = this._requestData;
121 var context = this._canvas.getContext("2d");
122 context.save();
123 context.scale(window.devicePixelRatio, window.devicePixelRatio);
124 context.translate(0, this._networkLogView.headerHeight());
125 context.rect(0, 0, this._offsetWidth, this._offsetHeight);
126 context.clip();
127 this._startTime = this._networkLogView.calculator().minimumBoundary();
128 this._endTime = this._networkLogView.calculator().maximumBoundary();
129 var rowHeight = this._networkLogView.rowHeight();
130 var scrollTop = this._scrollTop();
131 for (var i = 0; i < requests.length; i++) {
132 var rowTop = rowHeight * i;
133 if (rowTop + rowHeight <= scrollTop)
alph 2016/10/08 01:35:09 you can do better to find the first visible row. :
allada 2016/10/08 02:06:34 Done.
134 continue;
135 var request = requests[i];
136 var ranges = WebInspector.RequestTimingView.calculateRequestTimeRang es(request, 0);
137 for (var range of ranges) {
138 if (range.name === WebInspector.RequestTimeRangeNames.Total ||
139 range.name === WebInspector.RequestTimeRangeNames.Sending ||
140 range.end - range.start === 0)
141 continue;
142 context.save();
alph 2016/10/08 01:35:09 nit: move save/restore into _drawBar
allada 2016/10/08 02:06:34 Done.
143 this._drawBar(context, range, rowTop - scrollTop);
144 context.restore();
145 }
146 }
147 context.restore();
148 },
149
150 _timelineDuration: function()
alph 2016/10/08 01:35:09 annotate
allada 2016/10/08 02:06:34 Done.
151 {
152 return this._networkLogView.calculator().maximumBoundary() - this._netwo rkLogView.calculator().minimumBoundary();
153 },
154
155 /**
156 * @param {!WebInspector.RequestTimeRangeNames} type
157 * @return {number}
158 */
159 _getBarHeight: function(type)
160 {
161 var types = WebInspector.RequestTimeRangeNames;
162 switch (type) {
163 case types.Connecting:
164 case types.SSL:
165 case types.DNS:
166 case types.Proxy:
167 case types.Blocking:
168 case types.Push:
169 case types.Queueing:
170 return 7;
171 default:
172 return 13;
173 }
174 },
175
176 /**
177 * @param {!CanvasRenderingContext2D} context
178 * @param {!WebInspector.RequestTimeRange} range
179 * @param {number} y
180 */
181 _drawBar: function(context, range, y)
182 {
183 context.beginPath();
184 var lineWidth = 0;
185 var color = this._colorForType(range.name);
186 var borderColor = color;
187 if (range.name === WebInspector.RequestTimeRangeNames.Queueing) {
188 borderColor = "lightgrey";
189 lineWidth = 2;
190 }
191 if (range.name === WebInspector.RequestTimeRangeNames.Receiving)
192 lineWidth = 2;
193 context.fillStyle = color;
194 var height = this._getBarHeight(range.name);
195 y += Math.floor(this._networkLogView.rowHeight() / 2 - height / 2) + lin eWidth / 2;
196 var start = this._timeToPosition(range.start);
197 var end = this._timeToPosition(range.end);
198 context.rect(start, y, end - start, height - lineWidth);
199 if (lineWidth) {
200 context.lineWidth = lineWidth;
201 context.strokeStyle = borderColor;
202 context.stroke();
203 }
204 context.fill();
205 },
206
207 __proto__: WebInspector.VBox.prototype
208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698