OLD | NEW |
---|---|
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 {number} rowHeight | 8 * @param {number} rowHeight |
9 * @param {!WebInspector.NetworkTimeCalculator} calculator | 9 * @param {!WebInspector.NetworkTimeCalculator} calculator |
10 */ | 10 */ |
(...skipping 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 /** @type {!Array<!WebInspector.NetworkRequest>} */ | 36 /** @type {!Array<!WebInspector.NetworkRequest>} */ |
37 this._requestData = []; | 37 this._requestData = []; |
38 | 38 |
39 /** @type {?WebInspector.NetworkRequest} */ | 39 /** @type {?WebInspector.NetworkRequest} */ |
40 this._hoveredRequest = null; | 40 this._hoveredRequest = null; |
41 | 41 |
42 /** @type {?WebInspector.NetworkRequest} */ | 42 /** @type {?WebInspector.NetworkRequest} */ |
43 this._navigationRequest = null; | 43 this._navigationRequest = null; |
44 | 44 |
45 /** @type {!Map<string, !Array<number>>} */ | |
46 this._eventDividers = new Map(); | |
47 | |
45 var colorUsage = WebInspector.ThemeSupport.ColorUsage; | 48 var colorUsage = WebInspector.ThemeSupport.ColorUsage; |
46 this._rowNavigationRequestColor = WebInspector.themeSupport.patchColor("#def ", colorUsage.Background); | 49 this._rowNavigationRequestColor = WebInspector.themeSupport.patchColor("#def ", colorUsage.Background); |
47 this._rowStripeColor = WebInspector.themeSupport.patchColor("#f5f5f5", color Usage.Background); | 50 this._rowStripeColor = WebInspector.themeSupport.patchColor("#f5f5f5", color Usage.Background); |
48 this._rowHoverColor = WebInspector.themeSupport.patchColor("#ebf2fc", /** @t ype {!WebInspector.ThemeSupport.ColorUsage} */ (colorUsage.Background | colorUsa ge.Selection)); | 51 this._rowHoverColor = WebInspector.themeSupport.patchColor("#ebf2fc", /** @t ype {!WebInspector.ThemeSupport.ColorUsage} */ (colorUsage.Background | colorUsa ge.Selection)); |
49 | 52 |
50 /** @type {!Map<!WebInspector.ResourceType, string>} */ | 53 /** @type {!Map<!WebInspector.ResourceType, string>} */ |
51 this._borderColorsForResourceTypeCache = new Map(); | 54 this._borderColorsForResourceTypeCache = new Map(); |
52 /** @type {!Map<string, !CanvasGradient>} */ | 55 /** @type {!Map<string, !CanvasGradient>} */ |
53 this._colorsForResourceTypeCache = new Map(); | 56 this._colorsForResourceTypeCache = new Map(); |
54 }; | 57 }; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 | 184 |
182 scheduleDraw: function() | 185 scheduleDraw: function() |
183 { | 186 { |
184 if (this._updateRequestID) | 187 if (this._updateRequestID) |
185 return; | 188 return; |
186 this._updateRequestID = this.element.window().requestAnimationFrame(() = > this.update()); | 189 this._updateRequestID = this.element.window().requestAnimationFrame(() = > this.update()); |
187 }, | 190 }, |
188 | 191 |
189 /** | 192 /** |
190 * @param {number=} scrollTop | 193 * @param {number=} scrollTop |
194 * @param {!Map<string, !Array<number>>=} eventDividers | |
191 * @param {!{requests: !Array<!WebInspector.NetworkRequest>, navigationReque st: ?WebInspector.NetworkRequest}=} requestData | 195 * @param {!{requests: !Array<!WebInspector.NetworkRequest>, navigationReque st: ?WebInspector.NetworkRequest}=} requestData |
192 */ | 196 */ |
193 update: function(scrollTop, requestData) | 197 update: function(scrollTop, eventDividers, requestData) |
194 { | 198 { |
195 if (scrollTop !== undefined) | 199 if (scrollTop !== undefined) |
196 this._scrollTop = scrollTop; | 200 this._scrollTop = scrollTop; |
197 if (requestData) { | 201 if (requestData) { |
198 this._requestData = requestData.requests; | 202 this._requestData = requestData.requests; |
199 this._navigationRequest = requestData.navigationRequest; | 203 this._navigationRequest = requestData.navigationRequest; |
200 this._calculateCanvasSize(); | 204 this._calculateCanvasSize(); |
201 } | 205 } |
206 if (eventDividers !== undefined) | |
207 this._eventDividers = eventDividers; | |
202 this.element.window().cancelAnimationFrame(this._updateRequestID); | 208 this.element.window().cancelAnimationFrame(this._updateRequestID); |
203 this._updateRequestID = null; | 209 this._updateRequestID = null; |
204 | 210 |
205 this._startTime = this._calculator.minimumBoundary(); | 211 this._startTime = this._calculator.minimumBoundary(); |
206 this._endTime = this._calculator.maximumBoundary(); | 212 this._endTime = this._calculator.maximumBoundary(); |
207 this._resetCanvas(); | 213 this._resetCanvas(); |
208 this._draw(); | 214 this._draw(); |
209 }, | 215 }, |
210 | 216 |
211 _resetCanvas: function() | 217 _resetCanvas: function() |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / this._rowHeight)); | 298 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / this._rowHeight)); |
293 for (var i = firstRequestIndex; i < lastRequestIndex; i++) { | 299 for (var i = firstRequestIndex; i < lastRequestIndex; i++) { |
294 var rowOffset = this._rowHeight * i; | 300 var rowOffset = this._rowHeight * i; |
295 var request = requests[i]; | 301 var request = requests[i]; |
296 this._decorateRow(context, request, i, rowOffset - this._scrollTop); | 302 this._decorateRow(context, request, i, rowOffset - this._scrollTop); |
297 if (useTimingBars) | 303 if (useTimingBars) |
298 this._drawTimingBars(context, request, rowOffset - this._scrollT op); | 304 this._drawTimingBars(context, request, rowOffset - this._scrollT op); |
299 else | 305 else |
300 this._drawSimplifiedBars(context, request, rowOffset - this._scr ollTop); | 306 this._drawSimplifiedBars(context, request, rowOffset - this._scr ollTop); |
301 } | 307 } |
308 this._drawEventDividers(context); | |
302 context.restore(); | 309 context.restore(); |
310 // This is outside of the save/restore above because it must draw in hea der. | |
303 this._drawDividers(context); | 311 this._drawDividers(context); |
304 }, | 312 }, |
305 | 313 |
314 /** | |
315 * @param {!CanvasRenderingContext2D} context | |
316 */ | |
317 _drawEventDividers: function(context) | |
318 { | |
319 context.save(); | |
320 context.lineWidth = 1; | |
321 for (var color of this._eventDividers.keys()) { | |
322 context.strokeStyle = color; | |
323 for (var time of this._eventDividers.get(color)) { | |
324 context.beginPath(); | |
325 var x = this._timeToPosition(time); | |
326 context.moveTo(x, 0); | |
327 context.lineTo(x, this._offsetHeight); | |
328 } | |
329 context.stroke(); | |
330 } | |
331 context.restore(); | |
332 }, | |
333 | |
334 /** | |
335 * @param {!CanvasRenderingContext2D} context | |
336 */ | |
306 _drawDividers: function(context) | 337 _drawDividers: function(context) |
307 { | 338 { |
308 context.save(); | 339 context.save(); |
309 /** @const */ | 340 /** @const */ |
310 var minGridSlicePx = 64; // minimal distance between grid lines. | 341 var minGridSlicePx = 64; // minimal distance between grid lines. |
311 | 342 |
312 var drawableWidth = this._offsetWidth - this._leftPadding; | 343 var drawableWidth = this._offsetWidth - this._leftPadding; |
313 var timelineDuration = this._timelineDuration(); | 344 var timelineDuration = this._timelineDuration(); |
314 var dividersCount = drawableWidth / minGridSlicePx; | 345 var dividersCount = drawableWidth / minGridSlicePx; |
315 var gridSliceTime = timelineDuration / dividersCount; | 346 var gridSliceTime = timelineDuration / dividersCount; |
316 var pixelsPerTime = drawableWidth / timelineDuration; | 347 var pixelsPerTime = drawableWidth / timelineDuration; |
317 | 348 |
318 // Align gridSliceTime to a nearest round value. | 349 // Align gridSliceTime to a nearest round value. |
319 // We allow spans that fit into the formula: span = (1|2|5)x10^n, | 350 // We allow spans that fit into the formula: span = (1|2|5)x10^n, |
320 // e.g.: ... .1 .2 .5 1 2 5 10 20 50 ... | 351 // e.g.: ... .1 .2 .5 1 2 5 10 20 50 ... |
321 // After a span has been chosen make grid lines at multiples of the span . | 352 // After a span has been chosen make grid lines at multiples of the span . |
322 | 353 |
323 var logGridSliceTime = Math.ceil(Math.log(gridSliceTime) / Math.LN10); | 354 var logGridSliceTime = Math.ceil(Math.log(gridSliceTime) / Math.LN10); |
324 gridSliceTime = Math.pow(10, logGridSliceTime); | 355 gridSliceTime = Math.pow(10, logGridSliceTime); |
325 if (gridSliceTime * pixelsPerTime >= 5 * minGridSlicePx) | 356 if (gridSliceTime * pixelsPerTime >= 5 * minGridSlicePx) |
326 gridSliceTime = gridSliceTime / 5; | 357 gridSliceTime = gridSliceTime / 5; |
327 if (gridSliceTime * pixelsPerTime >= 2 * minGridSlicePx) | 358 if (gridSliceTime * pixelsPerTime >= 2 * minGridSlicePx) |
328 gridSliceTime = gridSliceTime / 2; | 359 gridSliceTime = gridSliceTime / 2; |
329 | 360 |
361 context.scale(window.devicePixelRatio, window.devicePixelRatio); | |
dgozman
2016/10/28 18:35:38
Do this scaling just once at the top of draw.
allada
2016/10/28 21:09:07
Done.
| |
330 context.lineWidth = 1; | 362 context.lineWidth = 1; |
331 context.strokeStyle = "rgba(0, 0, 0, .1)"; | 363 context.strokeStyle = "rgba(0, 0, 0, .1)"; |
332 context.font = this._fontSize + "px sans-serif"; | 364 context.font = this._fontSize + "px sans-serif"; |
333 context.fillStyle = "#444"; | 365 context.fillStyle = "#444"; |
334 gridSliceTime = gridSliceTime; | 366 gridSliceTime = gridSliceTime; |
335 for (var position = gridSliceTime * pixelsPerTime; position < drawableWi dth; position += gridSliceTime * pixelsPerTime) { | 367 for (var position = gridSliceTime * pixelsPerTime; position < drawableWi dth; position += gridSliceTime * pixelsPerTime) { |
336 // Added .5 because canvas drawing points are between pixels. | 368 // Added .5 because canvas drawing points are between pixels. |
337 var drawPosition = Math.floor(position) + this._leftPadding + .5; | 369 var drawPosition = Math.floor(position) + this._leftPadding + .5; |
338 context.beginPath(); | 370 context.beginPath(); |
339 context.moveTo(drawPosition, 0); | 371 context.moveTo(drawPosition, 0); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 color = this._rowNavigationRequestColor; | 610 color = this._rowNavigationRequestColor; |
579 | 611 |
580 context.fillStyle = color; | 612 context.fillStyle = color; |
581 context.rect(0, y, this._offsetWidth, this._rowHeight); | 613 context.rect(0, y, this._offsetWidth, this._rowHeight); |
582 context.fill(); | 614 context.fill(); |
583 context.restore(); | 615 context.restore(); |
584 }, | 616 }, |
585 | 617 |
586 __proto__: WebInspector.VBox.prototype | 618 __proto__: WebInspector.VBox.prototype |
587 }; | 619 }; |
OLD | NEW |