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"); | |
| 15 | |
| 14 this._canvas = this.contentElement.createChild("canvas"); | 16 this._canvas = this.contentElement.createChild("canvas"); |
| 15 this._canvas.tabIndex = 1; | 17 this._canvas.tabIndex = 1; |
| 16 this.setDefaultFocusedElement(this._canvas); | 18 this.setDefaultFocusedElement(this._canvas); |
| 17 | 19 |
| 18 /** @const */ | 20 /** @const */ |
| 19 this._leftPadding = 5; | 21 this._leftPadding = 5; |
| 20 /** @const */ | 22 /** @const */ |
| 21 this._rightPadding = 5; | 23 this._rightPadding = 5; |
| 22 | 24 |
| 23 this._dataGrid = dataGrid; | 25 this._dataGrid = dataGrid; |
| 24 this._networkLogView = networkLogView; | 26 this._networkLogView = networkLogView; |
| 27 | |
| 28 this._vScrollElement = this.contentElement.createChild("div", "network-timel ine-v-scroll"); | |
| 29 this._vScrollContent = this._vScrollElement.createChild("div"); | |
| 30 this._vScrollElement.addEventListener("scroll", this._onScroll.bind(this), { passive: true }); | |
| 31 this._vScrollElement.addEventListener("mousewheel", this._onMouseWheel.bind( this), { passive: true }); | |
| 32 this._canvas.addEventListener("mousewheel", this._onMouseWheel.bind(this), { passive: true }); | |
| 33 | |
| 34 this._dataGridScrollContainer = this._dataGrid.scrollContainer; | |
| 35 this._dataGridScrollContainer.addEventListener("mousewheel", event => { | |
| 36 event.consume(true); | |
| 37 this._onMouseWheel(event); | |
| 38 }, true); | |
| 39 | |
| 40 // TODO(allada) When timeline canvas moves out of experiment move this to st ylesheet. | |
| 41 this._dataGridScrollContainer.style.overflow = "hidden"; | |
| 42 this._dataGrid.setScrollContainer(this._vScrollElement); | |
| 43 | |
| 44 this._dataGrid.addEventListener(WebInspector.ViewportDataGrid.Events.Updated , this._update.bind(this)); | |
| 45 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.PaddingChanged, this._updateHeight.bind(this)); | |
| 46 | |
| 25 /** @type {!Array<!WebInspector.NetworkRequest>} */ | 47 /** @type {!Array<!WebInspector.NetworkRequest>} */ |
| 26 this._requestData = []; | 48 this._requestData = []; |
| 27 } | 49 } |
| 28 | 50 |
| 29 WebInspector.NetworkTimelineColumn.prototype = { | 51 WebInspector.NetworkTimelineColumn.prototype = { |
| 30 wasShown: function() | 52 wasShown: function() |
| 31 { | 53 { |
| 32 this.scheduleUpdate(); | 54 this.scheduleUpdate(); |
| 33 }, | 55 }, |
| 34 | 56 |
| 35 scheduleRefreshData: function() | 57 scheduleRefreshData: function() |
| 36 { | 58 { |
| 37 this._needsRefreshData = true; | 59 this._needsRefreshData = true; |
| 38 }, | 60 }, |
| 39 | 61 |
| 40 _refreshDataIfNeeded: function() | 62 _refreshDataIfNeeded: function() |
| 41 { | 63 { |
| 42 if (!this._needsRefreshData) | 64 if (!this._needsRefreshData) |
| 43 return; | 65 return; |
| 44 this._needsRefreshData = false; | 66 this._needsRefreshData = false; |
| 45 var currentNode = this._dataGrid.rootNode(); | 67 var currentNode = this._dataGrid.rootNode(); |
| 46 this._requestData = []; | 68 this._requestData = []; |
| 47 while (currentNode = currentNode.traverseNextNode(true)) | 69 while (currentNode = currentNode.traverseNextNode(true)) |
| 48 this._requestData.push(currentNode.request()); | 70 this._requestData.push(currentNode.request()); |
| 49 this._update(); | 71 }, |
| 72 | |
| 73 _onMouseWheel: function(event) | |
|
dgozman
2016/10/11 21:53:39
Annotate please.
allada
2016/10/12 00:33:09
Done.
| |
| 74 { | |
| 75 this._vScrollElement.scrollTop -= event.wheelDeltaY; | |
|
dgozman
2016/10/11 21:53:39
Won't this cause _onScroll itself?
allada
2016/10/12 00:33:09
Yes, I can remove this part:
"this._dataGridScroll
| |
| 76 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ; | |
| 77 }, | |
| 78 | |
| 79 _onScroll: function(event) | |
|
dgozman
2016/10/11 21:53:39
Annotate please.
allada
2016/10/12 00:33:08
Done.
| |
| 80 { | |
| 81 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ; | |
| 50 }, | 82 }, |
| 51 | 83 |
| 52 scheduleUpdate: function() | 84 scheduleUpdate: function() |
| 53 { | 85 { |
| 54 if (this._updateRequestID) | 86 if (this._updateRequestID) |
| 55 return; | 87 return; |
| 56 this._updateRequestID = this.element.window().requestAnimationFrame(this ._update.bind(this)); | 88 this._updateRequestID = this.element.window().requestAnimationFrame(this ._update.bind(this)); |
| 57 }, | 89 }, |
| 58 | 90 |
| 59 _update: function() | 91 _update: function() |
| 60 { | 92 { |
| 61 this.element.window().cancelAnimationFrame(this._updateRequestID); | 93 this.element.window().cancelAnimationFrame(this._updateRequestID); |
| 62 this._updateRequestID = null; | 94 this._updateRequestID = null; |
| 63 | 95 |
| 64 this._refreshDataIfNeeded(); | 96 this._refreshDataIfNeeded(); |
| 65 | 97 |
| 66 this._startTime = this._networkLogView.calculator().minimumBoundary(); | 98 this._startTime = this._networkLogView.calculator().minimumBoundary(); |
| 67 this._endTime = this._networkLogView.calculator().maximumBoundary(); | 99 this._endTime = this._networkLogView.calculator().maximumBoundary(); |
| 68 this._resetCanvas(); | 100 this._resetCanvas(); |
| 69 this._draw(); | 101 this._draw(); |
| 70 }, | 102 }, |
| 71 | 103 |
| 104 _updateHeight: function() | |
| 105 { | |
| 106 var totalHeight = this._dataGridScrollContainer.scrollHeight; | |
| 107 this._vScrollContent.style.height = totalHeight + "px"; | |
| 108 }, | |
| 109 | |
| 72 _resetCanvas: function() | 110 _resetCanvas: function() |
| 73 { | 111 { |
| 74 var ratio = window.devicePixelRatio; | 112 var ratio = window.devicePixelRatio; |
| 75 this._canvas.width = this._offsetWidth * ratio; | 113 this._canvas.width = this._offsetWidth * ratio; |
| 76 this._canvas.height = this._offsetHeight * ratio; | 114 this._canvas.height = this._offsetHeight * ratio; |
| 77 this._canvas.style.width = this._offsetWidth + "px"; | 115 this._canvas.style.width = this._offsetWidth + "px"; |
| 78 this._canvas.style.height = this._offsetHeight + "px"; | 116 this._canvas.style.height = this._offsetHeight + "px"; |
| 79 }, | 117 }, |
| 80 | 118 |
| 81 /** | 119 /** |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 case types.Queueing: | 155 case types.Queueing: |
| 118 return "white"; | 156 return "white"; |
| 119 case types.ServiceWorker: | 157 case types.ServiceWorker: |
| 120 case types.ServiceWorkerPreparation: | 158 case types.ServiceWorkerPreparation: |
| 121 default: | 159 default: |
| 122 return "orange"; | 160 return "orange"; |
| 123 } | 161 } |
| 124 }, | 162 }, |
| 125 | 163 |
| 126 /** | 164 /** |
| 127 * @return {number} | |
| 128 */ | |
| 129 _scrollTop: function() | |
| 130 { | |
| 131 return this._dataGrid.scrollContainer.scrollTop; | |
| 132 }, | |
| 133 | |
| 134 /** | |
| 135 * @param {number} time | 165 * @param {number} time |
| 136 * @return {number} | 166 * @return {number} |
| 137 */ | 167 */ |
| 138 _timeToPosition: function(time) | 168 _timeToPosition: function(time) |
| 139 { | 169 { |
| 140 var availableWidth = this._offsetWidth - this._leftPadding - this._right Padding; | 170 var availableWidth = this._offsetWidth - this._leftPadding - this._right Padding; |
| 141 var timeToPixel = availableWidth / (this._endTime - this._startTime); | 171 var timeToPixel = availableWidth / (this._endTime - this._startTime); |
| 142 return Math.floor(this._leftPadding + (time - this._startTime) * timeToP ixel); | 172 return Math.floor(this._leftPadding + (time - this._startTime) * timeToP ixel); |
| 143 }, | 173 }, |
| 144 | 174 |
| 145 _draw: function() | 175 _draw: function() |
| 146 { | 176 { |
| 147 var requests = this._requestData; | 177 var requests = this._requestData; |
| 148 var context = this._canvas.getContext("2d"); | 178 var context = this._canvas.getContext("2d"); |
| 149 context.save(); | 179 context.save(); |
| 150 context.scale(window.devicePixelRatio, window.devicePixelRatio); | 180 context.scale(window.devicePixelRatio, window.devicePixelRatio); |
| 151 context.translate(0, this._networkLogView.headerHeight()); | 181 context.translate(0, this._networkLogView.headerHeight()); |
| 152 context.rect(0, 0, this._offsetWidth, this._offsetHeight); | 182 context.rect(0, 0, this._offsetWidth, this._offsetHeight); |
| 153 context.clip(); | 183 context.clip(); |
| 154 var rowHeight = this._networkLogView.rowHeight(); | 184 var rowHeight = this._networkLogView.rowHeight(); |
| 155 var scrollTop = this._scrollTop(); | 185 var scrollTop = this._vScrollElement.scrollTop; |
| 156 var firstRequestIndex = Math.floor(scrollTop / rowHeight); | 186 var firstRequestIndex = Math.floor(scrollTop / rowHeight); |
| 157 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / rowHeight)); | 187 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / rowHeight)); |
| 158 for (var i = firstRequestIndex; i < lastRequestIndex; i++) { | 188 for (var i = firstRequestIndex; i < lastRequestIndex; i++) { |
| 159 var rowOffset = rowHeight * i; | 189 var rowOffset = rowHeight * i; |
| 160 var rowNumber = i - firstRequestIndex; | 190 this._decorateRow(context, i, rowOffset - scrollTop, rowHeight); |
| 161 this._decorateRow(context, rowNumber, rowOffset - scrollTop, rowHeig ht); | |
| 162 var request = requests[i]; | 191 var request = requests[i]; |
| 163 var ranges = WebInspector.RequestTimingView.calculateRequestTimeRang es(request, 0); | 192 var ranges = WebInspector.RequestTimingView.calculateRequestTimeRang es(request, 0); |
| 164 for (var range of ranges) { | 193 for (var range of ranges) { |
| 165 if (range.name === WebInspector.RequestTimeRangeNames.Total || | 194 if (range.name === WebInspector.RequestTimeRangeNames.Total || |
| 166 range.name === WebInspector.RequestTimeRangeNames.Sending || | 195 range.name === WebInspector.RequestTimeRangeNames.Sending || |
| 167 range.end - range.start === 0) | 196 range.end - range.start === 0) |
| 168 continue; | 197 continue; |
| 169 this._drawBar(context, range, rowOffset - scrollTop); | 198 this._drawBar(context, range, rowOffset - scrollTop); |
| 170 } | 199 } |
| 171 } | 200 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 | 277 |
| 249 context.beginPath(); | 278 context.beginPath(); |
| 250 context.fillStyle = WebInspector.themeSupport.patchColor("#f5f5f5", WebI nspector.ThemeSupport.ColorUsage.Background); | 279 context.fillStyle = WebInspector.themeSupport.patchColor("#f5f5f5", WebI nspector.ThemeSupport.ColorUsage.Background); |
| 251 context.rect(0, y, this._offsetWidth, rowHeight); | 280 context.rect(0, y, this._offsetWidth, rowHeight); |
| 252 context.fill(); | 281 context.fill(); |
| 253 context.restore(); | 282 context.restore(); |
| 254 }, | 283 }, |
| 255 | 284 |
| 256 __proto__: WebInspector.VBox.prototype | 285 __proto__: WebInspector.VBox.prototype |
| 257 } | 286 } |
| OLD | NEW |