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