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 {!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"); | 14 this.registerRequiredCSS("network/networkTimelineColumn.css"); |
15 | 15 |
16 this._canvas = this.contentElement.createChild("canvas"); | 16 this._canvas = this.contentElement.createChild("canvas"); |
17 this._canvas.tabIndex = 1; | 17 this._canvas.tabIndex = 1; |
18 this.setDefaultFocusedElement(this._canvas); | 18 this.setDefaultFocusedElement(this._canvas); |
19 | 19 |
20 /** @const */ | 20 /** @const */ |
21 this._leftPadding = 5; | 21 this._leftPadding = 5; |
22 /** @const */ | 22 /** @const */ |
23 this._rightPadding = 5; | 23 this._rightPadding = 5; |
24 /** @const */ | |
25 this._fontSize = 10; | |
24 | 26 |
25 this._dataGrid = dataGrid; | 27 this._dataGrid = dataGrid; |
26 this._networkLogView = networkLogView; | 28 this._networkLogView = networkLogView; |
27 | 29 |
28 this._popoverAnchor = this.contentElement.createChild("div", "network-timeli ne-popover"); | 30 this._popoverAnchor = this.contentElement.createChild("div", "network-timeli ne-popover"); |
29 this._popoverHelper = new WebInspector.PopoverHelper(this._popoverAnchor, th is._getPopoverAnchor.bind(this), this._showPopover.bind(this)); | 31 this._popoverHelper = new WebInspector.PopoverHelper(this._popoverAnchor, th is._getPopoverAnchor.bind(this), this._showPopover.bind(this)); |
30 | 32 |
31 this._vScrollElement = this.contentElement.createChild("div", "network-timel ine-v-scroll"); | 33 this._vScrollElement = this.contentElement.createChild("div", "network-timel ine-v-scroll"); |
32 this._vScrollElement.addEventListener("scroll", this._onScroll.bind(this), { passive: true }); | 34 this._vScrollElement.addEventListener("scroll", this._onScroll.bind(this), { passive: true }); |
33 this._vScrollElement.addEventListener("mousewheel", this._onMouseWheel.bind( this), { passive: true }); | 35 this._vScrollElement.addEventListener("mousewheel", this._onMouseWheel.bind( this), { passive: true }); |
(...skipping 17 matching lines...) Expand all Loading... | |
51 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.PaddingChanged, this._updateHeight.bind(this)); | 53 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.PaddingChanged, this._updateHeight.bind(this)); |
52 | 54 |
53 /** @type {!Array<!WebInspector.NetworkRequest>} */ | 55 /** @type {!Array<!WebInspector.NetworkRequest>} */ |
54 this._requestData = []; | 56 this._requestData = []; |
55 | 57 |
56 /** @type {?WebInspector.NetworkRequest} */ | 58 /** @type {?WebInspector.NetworkRequest} */ |
57 this._hoveredRequest = null; | 59 this._hoveredRequest = null; |
58 | 60 |
59 this._rowStripeColor = WebInspector.themeSupport.patchColor("#f5f5f5", WebIn spector.ThemeSupport.ColorUsage.Background); | 61 this._rowStripeColor = WebInspector.themeSupport.patchColor("#f5f5f5", WebIn spector.ThemeSupport.ColorUsage.Background); |
60 this._rowHoverColor = WebInspector.themeSupport.patchColor("#ebf2fc", WebIns pector.ThemeSupport.ColorUsage.Background); | 62 this._rowHoverColor = WebInspector.themeSupport.patchColor("#ebf2fc", WebIns pector.ThemeSupport.ColorUsage.Background); |
63 | |
64 /** @type {!Map<!WebInspector.ResourceType, string>} */ | |
65 this._borderColorsForResourceTypeCache = new Map(); | |
66 /** @type {!Map<string, !CanvasGradient>} */ | |
67 this._colorsForResourceTypeCache = new Map(); | |
61 } | 68 } |
62 | 69 |
63 WebInspector.NetworkTimelineColumn.Events = { | 70 WebInspector.NetworkTimelineColumn.Events = { |
64 RequestHovered: Symbol("RequestHovered") | 71 RequestHovered: Symbol("RequestHovered") |
65 } | 72 } |
66 | 73 |
67 WebInspector.NetworkTimelineColumn._popoverShowDelay = 300; | 74 WebInspector.NetworkTimelineColumn._popoverShowDelay = 300; |
68 | 75 |
76 WebInspector.NetworkTimelineColumn._colorsForResourceType = { | |
77 document: "hsl(215, 100%, 80%)", | |
78 font: "hsl(8, 100%, 80%)", | |
79 media: "hsl(272, 64%, 80%)", | |
80 image: "hsl(272, 64%, 80%)", | |
81 script: "hsl(31, 100%, 80%)", | |
82 stylesheet: "hsl(90, 50%, 80%)", | |
83 texttrack: "hsl(8, 100%, 80%)", | |
84 websocket: "hsl(0, 0%, 95%)", | |
85 xhr: "hsl(53, 100%, 80%)", | |
86 other: "hsl(0, 0%, 95%)" | |
87 } | |
88 | |
69 WebInspector.NetworkTimelineColumn.prototype = { | 89 WebInspector.NetworkTimelineColumn.prototype = { |
70 willHide: function() | 90 willHide: function() |
71 { | 91 { |
72 this._popoverHelper.hidePopover(); | 92 this._popoverHelper.hidePopover(); |
73 }, | 93 }, |
74 /** | 94 /** |
75 * @param {!Element} element | 95 * @param {!Element} element |
76 * @param {!Event} event | 96 * @param {!Event} event |
77 * @return {!Element|!AnchorBox|undefined} | 97 * @return {!Element|!AnchorBox|undefined} |
78 */ | 98 */ |
79 _getPopoverAnchor: function(element, event) | 99 _getPopoverAnchor: function(element, event) |
80 { | 100 { |
81 if (!this._hoveredRequest) | 101 if (!this._hoveredRequest) |
82 return; | 102 return; |
83 return this._popoverAnchor; | 103 return this._popoverAnchor; |
84 }, | 104 }, |
85 | 105 |
86 /** | 106 /** |
87 * @param {!Element} anchor | 107 * @param {!Element} anchor |
88 * @param {!WebInspector.Popover} popover | 108 * @param {!WebInspector.Popover} popover |
89 */ | 109 */ |
90 _showPopover: function(anchor, popover) | 110 _showPopover: function(anchor, popover) |
91 { | 111 { |
92 if (!this._hoveredRequest) | 112 if (!this._hoveredRequest) |
93 return; | 113 return; |
94 var content = WebInspector.RequestTimingView.createTimingTable(this._hov eredRequest, this._networkLogView.timeCalculator().minimumBoundary()); | 114 var content = WebInspector.RequestTimingView.createTimingTable(this._hov eredRequest, this._networkLogView.calculator().minimumBoundary()); |
95 popover.showForAnchor(content, anchor); | 115 popover.showForAnchor(content, anchor); |
96 }, | 116 }, |
97 | 117 |
98 wasShown: function() | 118 wasShown: function() |
99 { | 119 { |
100 this.scheduleUpdate(); | 120 this.scheduleUpdate(); |
101 }, | 121 }, |
102 | 122 |
103 scheduleRefreshData: function() | 123 scheduleRefreshData: function() |
104 { | 124 { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 { | 174 { |
155 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ; | 175 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ; |
156 this._popoverHelper.hidePopover(); | 176 this._popoverHelper.hidePopover(); |
157 }, | 177 }, |
158 | 178 |
159 _positionPopoverAnchor: function() | 179 _positionPopoverAnchor: function() |
160 { | 180 { |
161 if (!this._hoveredRequest) | 181 if (!this._hoveredRequest) |
162 return; | 182 return; |
163 var rowHeight = this._networkLogView.rowHeight(); | 183 var rowHeight = this._networkLogView.rowHeight(); |
164 var range = WebInspector.RequestTimingView.calculateRequestTimeRanges(th is._hoveredRequest, 0).find(data => data.name === "total"); | 184 var percentages = this._networkLogView.calculator().computeBarGraphPerce ntages(this._hoveredRequest); |
165 var start = this._timeToPosition(range.start); | 185 var availableWidth = this._offsetWidth - this._leftPadding - this._right Padding; |
166 var end = this._timeToPosition(range.end); | 186 var start = (percentages.start / 100) * availableWidth + this._leftPaddi ng; |
187 var end = (percentages.end / 100) * availableWidth + this._leftPadding; | |
167 | 188 |
168 var rowIndex = this._requestData.findIndex(request => this._hoveredReque st === request); | 189 var rowIndex = this._requestData.findIndex(request => this._hoveredReque st === request); |
169 var barHeight = this._getBarHeight(range.name); | 190 var barHeight = this._getBarHeight(); |
170 | 191 |
171 this._popoverAnchor.style.left = start + "px"; | 192 this._popoverAnchor.style.left = start + "px"; |
172 this._popoverAnchor.style.width = (end - start) + "px" | 193 this._popoverAnchor.style.width = (end - start) + "px" |
173 this._popoverAnchor.style.height = barHeight + "px"; | 194 this._popoverAnchor.style.height = barHeight + "px"; |
174 this._popoverAnchor.style.top = this._networkLogView.headerHeight() + (r owHeight * rowIndex - this._vScrollElement.scrollTop) + ((rowHeight - barHeight) / 2) + "px"; | 195 this._popoverAnchor.style.top = this._networkLogView.headerHeight() + (r owHeight * rowIndex - this._vScrollElement.scrollTop) + ((rowHeight - barHeight) / 2) + "px"; |
175 }, | 196 }, |
176 | 197 |
177 /** | 198 /** |
178 * @param {number} x | 199 * @param {number} x |
179 * @param {number} y | 200 * @param {number} y |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 */ | 293 */ |
273 _timeToPosition: function(time) | 294 _timeToPosition: function(time) |
274 { | 295 { |
275 var availableWidth = this._offsetWidth - this._leftPadding - this._right Padding; | 296 var availableWidth = this._offsetWidth - this._leftPadding - this._right Padding; |
276 var timeToPixel = availableWidth / (this._endTime - this._startTime); | 297 var timeToPixel = availableWidth / (this._endTime - this._startTime); |
277 return Math.floor(this._leftPadding + (time - this._startTime) * timeToP ixel); | 298 return Math.floor(this._leftPadding + (time - this._startTime) * timeToP ixel); |
278 }, | 299 }, |
279 | 300 |
280 _draw: function() | 301 _draw: function() |
281 { | 302 { |
303 var useTimingBars = !WebInspector.moduleSetting("networkColorCodeResourc eTypes").get() && !this._networkLogView.calculator().startAtZero; | |
282 var requests = this._requestData; | 304 var requests = this._requestData; |
283 var context = this._canvas.getContext("2d"); | 305 var context = this._canvas.getContext("2d"); |
284 context.save(); | 306 context.save(); |
285 context.scale(window.devicePixelRatio, window.devicePixelRatio); | 307 context.scale(window.devicePixelRatio, window.devicePixelRatio); |
286 context.translate(0, this._networkLogView.headerHeight()); | 308 context.translate(0, this._networkLogView.headerHeight()); |
287 context.rect(0, 0, this._offsetWidth, this._offsetHeight); | 309 context.rect(0, 0, this._offsetWidth, this._offsetHeight); |
288 context.clip(); | 310 context.clip(); |
289 var rowHeight = this._networkLogView.rowHeight(); | 311 var rowHeight = this._networkLogView.rowHeight(); |
290 var scrollTop = this._vScrollElement.scrollTop; | 312 var scrollTop = this._vScrollElement.scrollTop; |
291 var firstRequestIndex = Math.floor(scrollTop / rowHeight); | 313 var firstRequestIndex = Math.floor(scrollTop / rowHeight); |
292 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / rowHeight)); | 314 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / rowHeight)); |
293 for (var i = firstRequestIndex; i < lastRequestIndex; i++) { | 315 for (var i = firstRequestIndex; i < lastRequestIndex; i++) { |
294 var rowOffset = rowHeight * i; | 316 var rowOffset = rowHeight * i; |
295 var request = requests[i]; | 317 var request = requests[i]; |
296 this._decorateRow(context, request, i, rowOffset - scrollTop, rowHei ght); | 318 this._decorateRow(context, request, i, rowOffset - scrollTop, rowHei ght); |
297 var ranges = WebInspector.RequestTimingView.calculateRequestTimeRang es(request, 0); | 319 if (useTimingBars) |
298 for (var range of ranges) { | 320 this._drawTimingBars(context, request, rowOffset - scrollTop); |
299 if (range.name === WebInspector.RequestTimeRangeNames.Total || | 321 else |
300 range.name === WebInspector.RequestTimeRangeNames.Sending || | 322 this._drawSimplifiedBars(context, request, rowOffset - scrollTop ); |
301 range.end - range.start === 0) | |
302 continue; | |
303 this._drawBar(context, range, rowOffset - scrollTop); | |
304 } | |
305 } | 323 } |
306 context.restore(); | 324 context.restore(); |
307 this._drawDividers(context); | 325 this._drawDividers(context); |
308 }, | 326 }, |
309 | 327 |
310 _drawDividers: function(context) | 328 _drawDividers: function(context) |
311 { | 329 { |
312 context.save(); | 330 context.save(); |
313 /** @const */ | 331 /** @const */ |
314 var minGridSlicePx = 64; // minimal distance between grid lines. | 332 var minGridSlicePx = 64; // minimal distance between grid lines. |
315 /** @const */ | |
316 var fontSize = 10; | |
317 | 333 |
318 var drawableWidth = this._offsetWidth - this._leftPadding - this._rightP adding; | 334 var drawableWidth = this._offsetWidth - this._leftPadding - this._rightP adding; |
319 var timelineDuration = this._timelineDuration(); | 335 var timelineDuration = this._timelineDuration(); |
320 var dividersCount = drawableWidth / minGridSlicePx; | 336 var dividersCount = drawableWidth / minGridSlicePx; |
321 var gridSliceTime = timelineDuration / dividersCount; | 337 var gridSliceTime = timelineDuration / dividersCount; |
322 var pixelsPerTime = drawableWidth / timelineDuration; | 338 var pixelsPerTime = drawableWidth / timelineDuration; |
323 | 339 |
324 // Align gridSliceTime to a nearest round value. | 340 // Align gridSliceTime to a nearest round value. |
325 // We allow spans that fit into the formula: span = (1|2|5)x10^n, | 341 // We allow spans that fit into the formula: span = (1|2|5)x10^n, |
326 // e.g.: ... .1 .2 .5 1 2 5 10 20 50 ... | 342 // e.g.: ... .1 .2 .5 1 2 5 10 20 50 ... |
327 // After a span has been chosen make grid lines at multiples of the span . | 343 // After a span has been chosen make grid lines at multiples of the span . |
328 | 344 |
329 var logGridSliceTime = Math.ceil(Math.log(gridSliceTime) / Math.LN10); | 345 var logGridSliceTime = Math.ceil(Math.log(gridSliceTime) / Math.LN10); |
330 gridSliceTime = Math.pow(10, logGridSliceTime); | 346 gridSliceTime = Math.pow(10, logGridSliceTime); |
331 if (gridSliceTime * pixelsPerTime >= 5 * minGridSlicePx) | 347 if (gridSliceTime * pixelsPerTime >= 5 * minGridSlicePx) |
332 gridSliceTime = gridSliceTime / 5; | 348 gridSliceTime = gridSliceTime / 5; |
333 if (gridSliceTime * pixelsPerTime >= 2 * minGridSlicePx) | 349 if (gridSliceTime * pixelsPerTime >= 2 * minGridSlicePx) |
334 gridSliceTime = gridSliceTime / 2; | 350 gridSliceTime = gridSliceTime / 2; |
335 | 351 |
336 context.lineWidth = 1; | 352 context.lineWidth = 1; |
337 context.strokeStyle = "rgba(0, 0, 0, .1)"; | 353 context.strokeStyle = "rgba(0, 0, 0, .1)"; |
338 context.font = fontSize + "px sans-serif"; | 354 context.font = this._fontSize + "px sans-serif"; |
339 context.fillStyle = "#444" | 355 context.fillStyle = "#444" |
340 gridSliceTime = gridSliceTime; | 356 gridSliceTime = gridSliceTime; |
341 for (var position = gridSliceTime * pixelsPerTime; position < drawableWi dth; position += gridSliceTime * pixelsPerTime) { | 357 for (var position = gridSliceTime * pixelsPerTime; position < drawableWi dth; position += gridSliceTime * pixelsPerTime) { |
342 // Added .5 because canvas drawing points are between pixels. | 358 // Added .5 because canvas drawing points are between pixels. |
343 var drawPosition = Math.floor(position) + this._leftPadding + .5; | 359 var drawPosition = Math.floor(position) + this._leftPadding + .5; |
344 context.beginPath(); | 360 context.beginPath(); |
345 context.moveTo(drawPosition, 0); | 361 context.moveTo(drawPosition, 0); |
346 context.lineTo(drawPosition, this._offsetHeight); | 362 context.lineTo(drawPosition, this._offsetHeight); |
347 context.stroke(); | 363 context.stroke(); |
348 if (position <= gridSliceTime * pixelsPerTime) | 364 if (position <= gridSliceTime * pixelsPerTime) |
349 continue; | 365 continue; |
350 var textData = Number.secondsToString(position / pixelsPerTime); | 366 var textData = Number.secondsToString(position / pixelsPerTime); |
351 context.fillText(textData, drawPosition - context.measureText(textDa ta).width - 2, Math.floor(this._networkLogView.headerHeight() - fontSize / 2)); | 367 context.fillText(textData, drawPosition - context.measureText(textDa ta).width - 2, Math.floor(this._networkLogView.headerHeight() - this._fontSize / 2)); |
352 } | 368 } |
353 context.restore(); | 369 context.restore(); |
354 }, | 370 }, |
355 | 371 |
356 /** | 372 /** |
357 * @return {number} | 373 * @return {number} |
358 */ | 374 */ |
359 _timelineDuration: function() | 375 _timelineDuration: function() |
360 { | 376 { |
361 return this._networkLogView.calculator().maximumBoundary() - this._netwo rkLogView.calculator().minimumBoundary(); | 377 return this._networkLogView.calculator().maximumBoundary() - this._netwo rkLogView.calculator().minimumBoundary(); |
362 }, | 378 }, |
363 | 379 |
364 /** | 380 /** |
365 * @param {!WebInspector.RequestTimeRangeNames} type | 381 * @param {!WebInspector.RequestTimeRangeNames=} type |
366 * @return {number} | 382 * @return {number} |
367 */ | 383 */ |
368 _getBarHeight: function(type) | 384 _getBarHeight: function(type) |
369 { | 385 { |
370 var types = WebInspector.RequestTimeRangeNames; | 386 var types = WebInspector.RequestTimeRangeNames; |
371 switch (type) { | 387 switch (type) { |
372 case types.Connecting: | 388 case types.Connecting: |
373 case types.SSL: | 389 case types.SSL: |
374 case types.DNS: | 390 case types.DNS: |
375 case types.Proxy: | 391 case types.Proxy: |
376 case types.Blocking: | 392 case types.Blocking: |
377 case types.Push: | 393 case types.Push: |
378 case types.Queueing: | 394 case types.Queueing: |
379 return 7; | 395 return 7; |
380 default: | 396 default: |
381 return 13; | 397 return 13; |
382 } | 398 } |
383 }, | 399 }, |
384 | 400 |
385 /** | 401 /** |
402 * @param {!WebInspector.NetworkRequest} request | |
403 * @return {string} | |
404 */ | |
405 _borderColorForResourceType: function(request) | |
406 { | |
407 var resourceType = request.resourceType(); | |
408 if (this._borderColorsForResourceTypeCache.has(resourceType)) | |
409 return this._borderColorsForResourceTypeCache.get(resourceType); | |
410 var colorsForResourceType = WebInspector.NetworkTimelineColumn._colorsFo rResourceType; | |
411 var color = colorsForResourceType[resourceType] || colorsForResourceType .Other; | |
412 var parsedColor = WebInspector.Color.parse(color); | |
413 var hsla = parsedColor.hsla(); | |
414 hsla[1] /= 2; | |
415 hsla[2] -= Math.min(hsla[2], 0.2); | |
416 var resultColor = /** @type {string} */ (parsedColor.asString(null)) | |
dgozman
2016/10/19 19:52:33
semicolon
| |
417 this._borderColorsForResourceTypeCache.set(resourceType, resultColor); | |
418 return resultColor; | |
419 }, | |
420 | |
421 /** | |
386 * @param {!CanvasRenderingContext2D} context | 422 * @param {!CanvasRenderingContext2D} context |
387 * @param {!WebInspector.RequestTimeRange} range | 423 * @param {!WebInspector.NetworkRequest} request |
424 * @return {string|!CanvasGradient} | |
425 */ | |
426 _colorForResourceType: function(context, request) | |
427 { | |
428 var colorsForResourceType = WebInspector.NetworkTimelineColumn._colorsFo rResourceType; | |
429 var resourceType = request.resourceType(); | |
430 var color = colorsForResourceType[resourceType] || colorsForResourceType .Other; | |
431 if (request.cached()) | |
432 return color; | |
433 | |
434 if (this._colorsForResourceTypeCache.has(color)) | |
435 return this._colorsForResourceTypeCache.get(color); | |
436 var parsedColor = WebInspector.Color.parse(color); | |
437 var hsla = parsedColor.hsla(); | |
438 hsla[1] -= Math.min(hsla[1], 0.28); | |
439 hsla[2] -= Math.min(hsla[2], 0.15); | |
440 var gradient = context.createLinearGradient(0, 0, 0, this._getBarHeight( )); | |
441 gradient.addColorStop(0, color); | |
442 gradient.addColorStop(1, /** @type {string} */ (parsedColor.asString(nul l))); | |
443 this._colorsForResourceTypeCache.set(color, gradient); | |
444 return gradient; | |
445 }, | |
446 | |
447 /** | |
448 * @param {!CanvasRenderingContext2D} context | |
449 * @param {!WebInspector.NetworkRequest} request | |
388 * @param {number} y | 450 * @param {number} y |
389 */ | 451 */ |
390 _drawBar: function(context, range, y) | 452 _drawSimplifiedBars: function(context, request, y) |
391 { | 453 { |
454 /** @const */ | |
455 var borderWidth = 1; | |
456 | |
392 context.save(); | 457 context.save(); |
458 var calculator = this._networkLogView.calculator(); | |
459 var percentages = calculator.computeBarGraphPercentages(request); | |
460 var drawWidth = this._offsetWidth - this._leftPadding - this._rightPaddi ng; | |
461 var borderOffset = borderWidth % 2 === 0 ? 0 : .5; | |
462 var start = this._leftPadding + Math.floor((percentages.start / 100) * d rawWidth) + borderOffset; | |
463 var mid = this._leftPadding + Math.floor((percentages.middle / 100) * dr awWidth) + borderOffset; | |
464 var end = this._leftPadding + Math.floor((percentages.end / 100) * drawW idth) + borderOffset; | |
465 var height = this._getBarHeight(); | |
466 y += Math.floor(this._networkLogView.rowHeight() / 2 - height / 2 + bord erWidth) - borderWidth / 2; | |
467 | |
468 context.translate(0, y); | |
469 context.fillStyle = this._colorForResourceType(context, request); | |
470 context.strokeStyle = this._borderColorForResourceType(request); | |
471 context.lineWidth = borderWidth; | |
472 | |
393 context.beginPath(); | 473 context.beginPath(); |
394 var lineWidth = 0; | 474 context.globalAlpha = .5; |
395 var color = this._colorForType(range.name); | 475 context.rect(start, 0, mid - start, height - borderWidth); |
396 var borderColor = color; | 476 context.fill(); |
397 if (range.name === WebInspector.RequestTimeRangeNames.Queueing) { | 477 context.stroke(); |
398 borderColor = "lightgrey"; | 478 |
399 lineWidth = 2; | 479 var barWidth = Math.max(2, end - mid); |
480 context.beginPath(); | |
481 context.globalAlpha = 1; | |
482 context.rect(mid, 0, barWidth, height - borderWidth); | |
483 context.fill(); | |
484 context.stroke(); | |
485 | |
486 if (request === this._hoveredRequest) { | |
487 var labels = calculator.computeBarGraphLabels(request); | |
488 this._drawSimplifiedBarDetails(context, labels.left, labels.right, s tart, mid, mid + barWidth + borderOffset) | |
400 } | 489 } |
401 if (range.name === WebInspector.RequestTimeRangeNames.Receiving) | 490 |
402 lineWidth = 2; | |
403 context.fillStyle = color; | |
404 var height = this._getBarHeight(range.name); | |
405 y += Math.floor(this._networkLogView.rowHeight() / 2 - height / 2) + lin eWidth / 2; | |
406 var start = this._timeToPosition(range.start); | |
407 var end = this._timeToPosition(range.end); | |
408 context.rect(start, y, end - start, height - lineWidth); | |
409 if (lineWidth) { | |
410 context.lineWidth = lineWidth; | |
411 context.strokeStyle = borderColor; | |
412 context.stroke(); | |
413 } | |
414 context.fill(); | |
415 context.restore(); | 491 context.restore(); |
416 }, | 492 }, |
417 | 493 |
494 /** | |
495 * @param {!CanvasRenderingContext2D} context | |
496 * @param {string} leftText | |
497 * @param {string} rightText | |
498 * @param {number} startX | |
499 * @param {number} midX | |
500 * @param {number} endX | |
501 */ | |
502 _drawSimplifiedBarDetails: function(context, leftText, rightText, startX, mi dX, endX) | |
503 { | |
504 /** @const */ | |
505 var barDotLineLength = 10; | |
506 | |
507 context.save(); | |
508 var height = this._getBarHeight(); | |
509 var leftLabelWidth = context.measureText(leftText).width; | |
510 var rightLabelWidth = context.measureText(rightText).width; | |
511 context.fillStyle = "#444"; | |
512 context.strokeStyle = "#444"; | |
513 if (leftLabelWidth < midX - startX) { | |
514 var midBarX = startX + (midX - startX) / 2 - leftLabelWidth / 2; | |
515 context.fillText(leftText, midBarX, this._fontSize); | |
516 } else if (barDotLineLength + leftLabelWidth + this._leftPadding < start X) { | |
517 context.beginPath(); | |
518 context.arc(startX, Math.floor(height / 2), 2, 0, 2 * Math.PI); | |
519 context.fill(); | |
520 context.fillText(leftText, startX - leftLabelWidth - barDotLineLengt h - 1, this._fontSize); | |
521 context.beginPath(); | |
522 context.lineWidth = 1; | |
523 context.moveTo(startX - barDotLineLength, Math.floor(height / 2)); | |
524 context.lineTo(startX, Math.floor(height / 2)); | |
525 context.stroke(); | |
526 } | |
527 | |
528 if (rightLabelWidth < endX - midX) { | |
529 var midBarX = midX + (endX - midX) / 2 - rightLabelWidth / 2; | |
530 context.fillText(rightText, midBarX, this._fontSize); | |
531 } else if (endX + barDotLineLength + rightLabelWidth < this._offsetWidth - this._leftPadding - this._rightPadding) { | |
532 context.beginPath(); | |
533 context.arc(endX, Math.floor(height / 2), 2, 0, 2 * Math.PI); | |
534 context.fill(); | |
535 context.fillText(rightText, endX + barDotLineLength + 1, this._fontS ize); | |
536 context.beginPath(); | |
537 context.lineWidth = 1; | |
538 context.moveTo(endX, Math.floor(height / 2)); | |
539 context.lineTo(endX + barDotLineLength, Math.floor(height / 2)); | |
540 context.stroke(); | |
541 } | |
542 context.restore(); | |
543 }, | |
544 | |
545 /** | |
546 * @param {!CanvasRenderingContext2D} context | |
547 * @param {!WebInspector.NetworkRequest} request | |
548 * @param {number} y | |
549 */ | |
550 _drawTimingBars: function(context, request, y) | |
551 { | |
552 context.save(); | |
553 var ranges = WebInspector.RequestTimingView.calculateRequestTimeRanges(r equest, 0); | |
554 for (var range of ranges) { | |
555 if (range.name === WebInspector.RequestTimeRangeNames.Total || | |
556 range.name === WebInspector.RequestTimeRangeNames.Sending || | |
557 range.end - range.start === 0) | |
558 continue; | |
559 context.beginPath(); | |
560 var lineWidth = 0; | |
561 var color = this._colorForType(range.name); | |
562 var borderColor = color; | |
563 if (range.name === WebInspector.RequestTimeRangeNames.Queueing) { | |
564 borderColor = "lightgrey"; | |
565 lineWidth = 2; | |
566 } | |
567 if (range.name === WebInspector.RequestTimeRangeNames.Receiving) | |
568 lineWidth = 2; | |
569 context.fillStyle = color; | |
570 var height = this._getBarHeight(range.name); | |
571 var middleBarY = y + Math.floor(this._networkLogView.rowHeight() / 2 - height / 2) + lineWidth / 2; | |
572 var start = this._timeToPosition(range.start); | |
573 var end = this._timeToPosition(range.end); | |
574 context.rect(start, middleBarY, end - start, height - lineWidth); | |
575 if (lineWidth) { | |
576 context.lineWidth = lineWidth; | |
577 context.strokeStyle = borderColor; | |
578 context.stroke(); | |
579 } | |
580 context.fill(); | |
581 } | |
582 context.restore(); | |
583 }, | |
584 | |
418 /** | 585 /** |
419 * @param {!CanvasRenderingContext2D} context | 586 * @param {!CanvasRenderingContext2D} context |
420 * @param {!WebInspector.NetworkRequest} request | 587 * @param {!WebInspector.NetworkRequest} request |
421 * @param {number} rowNumber | 588 * @param {number} rowNumber |
422 * @param {number} y | 589 * @param {number} y |
423 * @param {number} rowHeight | 590 * @param {number} rowHeight |
424 */ | 591 */ |
425 _decorateRow: function(context, request, rowNumber, y, rowHeight) | 592 _decorateRow: function(context, request, rowNumber, y, rowHeight) |
426 { | 593 { |
427 if (rowNumber % 2 === 1 && this._hoveredRequest !== request) | 594 if (rowNumber % 2 === 1 && this._hoveredRequest !== request) |
428 return; | 595 return; |
429 context.save(); | 596 context.save(); |
430 context.beginPath(); | 597 context.beginPath(); |
431 var color = this._rowStripeColor; | 598 var color = this._rowStripeColor; |
432 if (this._hoveredRequest === request) | 599 if (this._hoveredRequest === request) |
433 color = this._rowHoverColor; | 600 color = this._rowHoverColor; |
434 | 601 |
435 context.fillStyle = color; | 602 context.fillStyle = color; |
436 context.rect(0, y, this._offsetWidth, rowHeight); | 603 context.rect(0, y, this._offsetWidth, rowHeight); |
437 context.fill(); | 604 context.fill(); |
438 context.restore(); | 605 context.restore(); |
439 }, | 606 }, |
440 | 607 |
441 __proto__: WebInspector.VBox.prototype | 608 __proto__: WebInspector.VBox.prototype |
442 } | 609 } |
OLD | NEW |