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

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
42 this._startTime = this._networkLogView.calculator().minimumBoundary();
43 this._endTime = this._networkLogView.calculator().maximumBoundary();
44 this._resetCanvas();
45 this._draw();
46 },
47
48 _resetCanvas: function()
49 {
50 var ratio = window.devicePixelRatio;
51 this._canvas.width = this._offsetWidth * ratio;
52 this._canvas.height = this._offsetHeight * ratio;
53 this._canvas.style.width = this._offsetWidth + "px";
54 this._canvas.style.height = this._offsetHeight + "px";
55 },
56
57 /**
58 * @override
59 */
60 onResize: function()
61 {
62 WebInspector.VBox.prototype.onResize.call(this);
63 this._offsetWidth = this.contentElement.offsetWidth;
64 this._offsetHeight = this.contentElement.offsetHeight;
65 this.scheduleUpdate();
66 },
67
68 /**
69 * @param {!WebInspector.RequestTimeRangeNames} type
70 * @return {string}
71 */
72 _colorForType: function(type)
73 {
74 var types = WebInspector.RequestTimeRangeNames;
75 switch (type) {
76 case types.Receiving:
77 case types.ReceivingPush:
78 return "#03A9F4";
79 case types.Waiting:
80 return "#00C853";
81 case types.Connecting:
82 return "#FF9800";
83 case types.SSL:
84 return "#9C27B0";
85 case types.DNS:
86 return "#009688";
87 case types.Proxy:
88 return "#A1887F";
89 case types.Blocking:
90 return "#AAAAAA";
91 case types.Push:
92 return "#8CDBff";
93 case types.Queueing:
94 return "white";
95 case types.ServiceWorker:
96 case types.ServiceWorkerPreparation:
97 default:
98 return "orange";
99 }
100 },
101
102 /**
103 * @return {number}
104 */
105 _scrollTop: function()
106 {
107 return this._dataGrid.scrollContainer.scrollTop;
108 },
109
110 /**
111 * @param {number} time
112 * @return {number}
113 */
114 _timeToPosition: function(time)
115 {
116 var availableWidth = this._offsetWidth - this._leftPadding - this._right Padding;
117 var timeToPixel = availableWidth / (this._endTime - this._startTime);
118 return Math.floor(this._leftPadding + (time - this._startTime) * timeToP ixel);
119 },
120
121 _draw: function()
122 {
123 var requests = this._requestData;
124 var context = this._canvas.getContext("2d");
125 context.save();
126 context.scale(window.devicePixelRatio, window.devicePixelRatio);
127 context.translate(0, this._networkLogView.headerHeight());
128 context.rect(0, 0, this._offsetWidth, this._offsetHeight);
129 context.clip();
130 var rowHeight = this._networkLogView.rowHeight();
131 var scrollTop = this._scrollTop();
132 var firstRequestIndex = Math.floor(scrollTop / rowHeight);
133 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / rowHeight));
134 for (var i = firstRequestIndex; i < lastRequestIndex; i++) {
135 var rowOffset = rowHeight * i;
136 var request = requests[i];
137 var ranges = WebInspector.RequestTimingView.calculateRequestTimeRang es(request, 0);
138 for (var range of ranges) {
139 if (range.name === WebInspector.RequestTimeRangeNames.Total ||
140 range.name === WebInspector.RequestTimeRangeNames.Sending ||
141 range.end - range.start === 0)
142 continue;
143 this._drawBar(context, range, rowOffset - scrollTop);
144 }
145 }
146 context.restore();
147 },
148
149 /**
150 * @return {number}
151 */
152 _timelineDuration: function()
153 {
154 return this._networkLogView.calculator().maximumBoundary() - this._netwo rkLogView.calculator().minimumBoundary();
155 },
156
157 /**
158 * @param {!WebInspector.RequestTimeRangeNames} type
159 * @return {number}
160 */
161 _getBarHeight: function(type)
162 {
163 var types = WebInspector.RequestTimeRangeNames;
164 switch (type) {
165 case types.Connecting:
166 case types.SSL:
167 case types.DNS:
168 case types.Proxy:
169 case types.Blocking:
170 case types.Push:
171 case types.Queueing:
172 return 7;
173 default:
174 return 13;
175 }
176 },
177
178 /**
179 * @param {!CanvasRenderingContext2D} context
180 * @param {!WebInspector.RequestTimeRange} range
181 * @param {number} y
182 */
183 _drawBar: function(context, range, y)
184 {
185 context.save();
186 context.beginPath();
187 var lineWidth = 0;
188 var color = this._colorForType(range.name);
189 var borderColor = color;
190 if (range.name === WebInspector.RequestTimeRangeNames.Queueing) {
191 borderColor = "lightgrey";
192 lineWidth = 2;
193 }
194 if (range.name === WebInspector.RequestTimeRangeNames.Receiving)
195 lineWidth = 2;
196 context.fillStyle = color;
197 var height = this._getBarHeight(range.name);
198 y += Math.floor(this._networkLogView.rowHeight() / 2 - height / 2) + lin eWidth / 2;
199 var start = this._timeToPosition(range.start);
200 var end = this._timeToPosition(range.end);
201 context.rect(start, y, end - start, height - lineWidth);
202 if (lineWidth) {
203 context.lineWidth = lineWidth;
204 context.strokeStyle = borderColor;
205 context.stroke();
206 }
207 context.fill();
208 context.restore();
209 },
210
211 __proto__: WebInspector.VBox.prototype
212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698