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

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

Powered by Google App Engine
This is Rietveld 408576698