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 | 24 |
| 25 this._dataGrid = dataGrid; | 25 this._dataGrid = dataGrid; |
| 26 this._networkLogView = networkLogView; | 26 this._networkLogView = networkLogView; |
| 27 | 27 |
| 28 this._popoverAnchor = this.contentElement.createChild("div", "network-timeli ne-popover"); | |
|
lushnikov
2016/10/19 22:02:26
let's use AnchorBox - it's a more lightweight way
allada
2016/10/19 23:31:17
Done.
| |
| 29 this._popoverHelper = new WebInspector.PopoverHelper(this._popoverAnchor, th is._getPopoverAnchor.bind(this), this._showPopover.bind(this)); | |
| 30 | |
| 28 this._vScrollElement = this.contentElement.createChild("div", "network-timel ine-v-scroll"); | 31 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 }); | 32 this._vScrollElement.addEventListener("scroll", this._onScroll.bind(this), { passive: true }); |
| 31 this._vScrollElement.addEventListener("mousewheel", this._onMouseWheel.bind( this), { passive: true }); | 33 this._vScrollElement.addEventListener("mousewheel", this._onMouseWheel.bind( this), { passive: true }); |
| 32 this._canvas.addEventListener("mousewheel", this._onMouseWheel.bind(this), { passive: true }); | 34 this._vScrollContent = this._vScrollElement.createChild("div"); |
| 33 this._canvas.addEventListener("mousemove", this._onMouseMove.bind(this), tru e); | 35 |
| 34 this._canvas.addEventListener("mouseleave", this.setHoveredRequest.bind(this , null), true); | 36 this.element.addEventListener("mousewheel", this._onMouseWheel.bind(this), { passive: true }); |
| 37 this.element.addEventListener("mousemove", this._onMouseMove.bind(this), tru e); | |
| 38 this.element.addEventListener("mouseleave", this.setHoveredRequest.bind(this , null), true); | |
| 35 | 39 |
| 36 this._dataGridScrollContainer = this._dataGrid.scrollContainer; | 40 this._dataGridScrollContainer = this._dataGrid.scrollContainer; |
| 37 this._dataGridScrollContainer.addEventListener("mousewheel", event => { | 41 this._dataGridScrollContainer.addEventListener("mousewheel", event => { |
| 38 event.consume(true); | 42 event.consume(true); |
| 39 this._onMouseWheel(event); | 43 this._onMouseWheel(event); |
| 40 }, true); | 44 }, true); |
| 41 | 45 |
| 42 // TODO(allada) When timeline canvas moves out of experiment move this to st ylesheet. | 46 // TODO(allada) When timeline canvas moves out of experiment move this to st ylesheet. |
| 43 this._dataGridScrollContainer.style.overflow = "hidden"; | 47 this._dataGridScrollContainer.style.overflow = "hidden"; |
| 44 this._dataGrid.setScrollContainer(this._vScrollElement); | 48 this._dataGrid.setScrollContainer(this._vScrollElement); |
| 45 | 49 |
| 46 this._dataGrid.addEventListener(WebInspector.ViewportDataGrid.Events.Viewpor tCalculated, this._update.bind(this)); | 50 this._dataGrid.addEventListener(WebInspector.ViewportDataGrid.Events.Viewpor tCalculated, this._update.bind(this)); |
| 47 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.PaddingChanged, this._updateHeight.bind(this)); | 51 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.PaddingChanged, this._updateHeight.bind(this)); |
| 48 | 52 |
| 49 /** @type {!Array<!WebInspector.NetworkRequest>} */ | 53 /** @type {!Array<!WebInspector.NetworkRequest>} */ |
| 50 this._requestData = []; | 54 this._requestData = []; |
| 51 | 55 |
| 52 /** @type {?WebInspector.NetworkRequest} */ | 56 /** @type {?WebInspector.NetworkRequest} */ |
| 53 this._hoveredRequest = null; | 57 this._hoveredRequest = null; |
| 54 | 58 |
| 55 this._rowStripeColor = WebInspector.themeSupport.patchColor("#f5f5f5", WebIn spector.ThemeSupport.ColorUsage.Background); | 59 this._rowStripeColor = WebInspector.themeSupport.patchColor("#f5f5f5", WebIn spector.ThemeSupport.ColorUsage.Background); |
| 56 this._rowHoverColor = WebInspector.themeSupport.patchColor("#ebf2fc", WebIns pector.ThemeSupport.ColorUsage.Background); | 60 this._rowHoverColor = WebInspector.themeSupport.patchColor("#ebf2fc", WebIns pector.ThemeSupport.ColorUsage.Background); |
| 57 } | 61 } |
| 58 | 62 |
| 59 WebInspector.NetworkTimelineColumn.Events = { | 63 WebInspector.NetworkTimelineColumn.Events = { |
| 60 RequestHovered: Symbol("RequestHovered") | 64 RequestHovered: Symbol("RequestHovered") |
| 61 } | 65 } |
| 62 | 66 |
| 67 WebInspector.NetworkTimelineColumn._popoverShowDelay = 300; | |
|
lushnikov
2016/10/19 22:02:25
not used
allada
2016/10/19 23:31:17
Done.
| |
| 68 | |
| 63 WebInspector.NetworkTimelineColumn.prototype = { | 69 WebInspector.NetworkTimelineColumn.prototype = { |
| 70 willHide: function() | |
|
lushnikov
2016/10/19 22:02:25
nit: @override
allada
2016/10/19 23:31:17
Done.
| |
| 71 { | |
| 72 this._popoverHelper.hidePopover(); | |
| 73 }, | |
|
lushnikov
2016/10/19 22:02:25
nit: new line
allada
2016/10/19 23:31:17
Done.
| |
| 74 /** | |
| 75 * @param {!Element} element | |
| 76 * @param {!Event} event | |
| 77 * @return {!Element|!AnchorBox|undefined} | |
| 78 */ | |
| 79 _getPopoverAnchor: function(element, event) | |
| 80 { | |
| 81 if (!this._hoveredRequest) | |
| 82 return; | |
| 83 return this._popoverAnchor; | |
|
lushnikov
2016/10/19 22:02:26
shell we inline the _positionPopoverAnchor method
allada
2016/10/19 23:31:17
Acknowledged.
| |
| 84 }, | |
| 85 | |
| 86 /** | |
| 87 * @param {!Element} anchor | |
| 88 * @param {!WebInspector.Popover} popover | |
| 89 */ | |
| 90 _showPopover: function(anchor, popover) | |
| 91 { | |
| 92 if (!this._hoveredRequest) | |
| 93 return; | |
| 94 var content = WebInspector.RequestTimingView.createTimingTable(this._hov eredRequest, this._networkLogView.timeCalculator().minimumBoundary()); | |
| 95 popover.showForAnchor(content, anchor); | |
| 96 }, | |
| 97 | |
| 64 wasShown: function() | 98 wasShown: function() |
| 65 { | 99 { |
| 66 this.scheduleUpdate(); | 100 this.scheduleUpdate(); |
| 67 }, | 101 }, |
| 68 | 102 |
| 69 scheduleRefreshData: function() | 103 scheduleRefreshData: function() |
| 70 { | 104 { |
| 71 this._needsRefreshData = true; | 105 this._needsRefreshData = true; |
| 72 }, | 106 }, |
| 73 | 107 |
| 74 _refreshDataIfNeeded: function() | 108 _refreshDataIfNeeded: function() |
| 75 { | 109 { |
| 76 if (!this._needsRefreshData) | 110 if (!this._needsRefreshData) |
| 77 return; | 111 return; |
| 78 this._needsRefreshData = false; | 112 this._needsRefreshData = false; |
| 79 var currentNode = this._dataGrid.rootNode(); | 113 var currentNode = this._dataGrid.rootNode(); |
| 80 this._requestData = []; | 114 this._requestData = []; |
| 81 while (currentNode = currentNode.traverseNextNode(true)) | 115 while (currentNode = currentNode.traverseNextNode(true)) |
| 82 this._requestData.push(currentNode.request()); | 116 this._requestData.push(currentNode.request()); |
| 83 }, | 117 }, |
| 84 | 118 |
| 85 /** | 119 /** |
| 86 * @param {?WebInspector.NetworkRequest} request | 120 * @param {?WebInspector.NetworkRequest} request |
| 87 */ | 121 */ |
| 88 setHoveredRequest: function(request) | 122 setHoveredRequest: function(request) |
| 89 { | 123 { |
| 90 this._hoveredRequest = request; | 124 this._hoveredRequest = request; |
| 91 this.scheduleUpdate(); | 125 this.scheduleUpdate(); |
| 126 this._positionPopoverAnchor(); | |
| 92 }, | 127 }, |
| 93 | 128 |
| 94 /** | 129 /** |
| 95 * @param {!Event} event | 130 * @param {!Event} event |
| 96 */ | 131 */ |
| 97 _onMouseMove: function(event) | 132 _onMouseMove: function(event) |
| 98 { | 133 { |
| 99 var request = this._getRequestFromPoint(event.offsetX, event.offsetY); | 134 var request = this._getRequestFromPoint(event.offsetX, event.offsetY); |
| 100 this.dispatchEventToListeners(WebInspector.NetworkTimelineColumn.Events. RequestHovered, request); | 135 this.dispatchEventToListeners(WebInspector.NetworkTimelineColumn.Events. RequestHovered, request); |
| 101 }, | 136 }, |
| 102 | 137 |
| 103 /** | 138 /** |
| 104 * @param {!Event} event | 139 * @param {!Event} event |
| 105 */ | 140 */ |
| 106 _onMouseWheel: function(event) | 141 _onMouseWheel: function(event) |
| 107 { | 142 { |
| 108 this._vScrollElement.scrollTop -= event.wheelDeltaY; | 143 this._vScrollElement.scrollTop -= event.wheelDeltaY; |
| 109 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ; | 144 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ; |
| 145 this._popoverHelper.hidePopover(); | |
| 110 var request = this._getRequestFromPoint(event.offsetX, event.offsetY); | 146 var request = this._getRequestFromPoint(event.offsetX, event.offsetY); |
| 111 this.dispatchEventToListeners(WebInspector.NetworkTimelineColumn.Events. RequestHovered, request); | 147 this.dispatchEventToListeners(WebInspector.NetworkTimelineColumn.Events. RequestHovered, request); |
| 112 }, | 148 }, |
| 113 | 149 |
| 114 /** | 150 /** |
| 115 * @param {!Event} event | 151 * @param {!Event} event |
| 116 */ | 152 */ |
| 117 _onScroll: function(event) | 153 _onScroll: function(event) |
| 118 { | 154 { |
| 119 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ; | 155 this._dataGridScrollContainer.scrollTop = this._vScrollElement.scrollTop ; |
| 156 this._popoverHelper.hidePopover(); | |
| 157 }, | |
| 158 | |
| 159 _positionPopoverAnchor: function() | |
| 160 { | |
| 161 if (!this._hoveredRequest) | |
| 162 return; | |
| 163 var rowHeight = this._networkLogView.rowHeight(); | |
| 164 var range = WebInspector.RequestTimingView.calculateRequestTimeRanges(th is._hoveredRequest, 0).find(data => data.name === "total"); | |
| 165 var start = this._timeToPosition(range.start); | |
| 166 var end = this._timeToPosition(range.end); | |
| 167 | |
| 168 var rowIndex = this._requestData.findIndex(request => this._hoveredReque st === request); | |
| 169 var barHeight = this._getBarHeight(range.name); | |
| 170 | |
| 171 this._popoverAnchor.style.left = start + "px"; | |
| 172 this._popoverAnchor.style.width = (end - start) + "px" | |
| 173 this._popoverAnchor.style.height = barHeight + "px"; | |
| 174 this._popoverAnchor.style.top = this._networkLogView.headerHeight() + (r owHeight * rowIndex - this._vScrollElement.scrollTop) + ((rowHeight - barHeight) / 2) + "px"; | |
| 120 }, | 175 }, |
| 121 | 176 |
| 122 /** | 177 /** |
| 123 * @param {number} x | 178 * @param {number} x |
| 124 * @param {number} y | 179 * @param {number} y |
| 125 * @return {?WebInspector.NetworkRequest} | 180 * @return {?WebInspector.NetworkRequest} |
| 126 */ | 181 */ |
| 127 _getRequestFromPoint: function(x, y) | 182 _getRequestFromPoint: function(x, y) |
| 128 { | 183 { |
| 129 var rowHeight = this._networkLogView.rowHeight(); | 184 var rowHeight = this._networkLogView.rowHeight(); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 color = this._rowHoverColor; | 433 color = this._rowHoverColor; |
| 379 | 434 |
| 380 context.fillStyle = color; | 435 context.fillStyle = color; |
| 381 context.rect(0, y, this._offsetWidth, rowHeight); | 436 context.rect(0, y, this._offsetWidth, rowHeight); |
| 382 context.fill(); | 437 context.fill(); |
| 383 context.restore(); | 438 context.restore(); |
| 384 }, | 439 }, |
| 385 | 440 |
| 386 __proto__: WebInspector.VBox.prototype | 441 __proto__: WebInspector.VBox.prototype |
| 387 } | 442 } |
| OLD | NEW |