| 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 */ | 8 */ |
| 9 WebInspector.ChartViewport = function() | 9 WebInspector.ChartViewport = function() |
| 10 { | 10 { |
| 11 WebInspector.VBox.call(this, true); | 11 WebInspector.VBox.call(this, true); |
| 12 | 12 |
| 13 this.contentElement.addEventListener("mousewheel", this._onMouseWheel.bind(t
his), false); | 13 this.contentElement.addEventListener("mousewheel", this._onMouseWheel.bind(t
his), false); |
| 14 this.contentElement.addEventListener("keydown", this._handleZoomPanKeys.bind
(this), false); | 14 this.contentElement.addEventListener("keydown", this._handleZoomPanKeys.bind
(this), false); |
| 15 | 15 |
| 16 WebInspector.installInertialDragHandle(this.contentElement, this._startDragg
ing.bind(this), this._dragging.bind(this), this._endDragging.bind(this), "-webki
t-grabbing", null); | 16 this.viewportElement = this.contentElement.createChild("div", "fill"); |
| 17 WebInspector.installDragHandle(this.contentElement, this._startRangeSelectio
n.bind(this), this._rangeSelectionDragging.bind(this), this._endRangeSelection.b
ind(this), "text", null); | 17 WebInspector.installInertialDragHandle(this.viewportElement, this._startDrag
ging.bind(this), this._dragging.bind(this), this._endDragging.bind(this), "-webk
it-grabbing", null); |
| 18 WebInspector.installDragHandle(this.viewportElement, this._startRangeSelecti
on.bind(this), this._rangeSelectionDragging.bind(this), this._endRangeSelection.
bind(this), "text", null); |
| 18 | 19 |
| 19 /** @private */ | |
| 20 this._vScrollElement = this.contentElement.createChild("div", "flame-chart-v
-scroll"); | 20 this._vScrollElement = this.contentElement.createChild("div", "flame-chart-v
-scroll"); |
| 21 this._vScrollContent = this._vScrollElement.createChild("div"); | 21 this._vScrollContent = this._vScrollElement.createChild("div"); |
| 22 this._vScrollElement.addEventListener("scroll", this._onScroll.bind(this), f
alse); | 22 this._vScrollElement.addEventListener("scroll", this._onScroll.bind(this), f
alse); |
| 23 | 23 |
| 24 /** @private */ | |
| 25 this._selectionOverlay = this.contentElement.createChild("div", "flame-chart
-selection-overlay hidden"); | 24 this._selectionOverlay = this.contentElement.createChild("div", "flame-chart
-selection-overlay hidden"); |
| 26 /** @private */ | |
| 27 this._selectedTimeSpanLabel = this._selectionOverlay.createChild("div", "tim
e-span"); | 25 this._selectedTimeSpanLabel = this._selectionOverlay.createChild("div", "tim
e-span"); |
| 28 | 26 |
| 29 this.reset(); | 27 this.reset(); |
| 30 } | 28 } |
| 31 | 29 |
| 32 WebInspector.ChartViewport.prototype = { | 30 WebInspector.ChartViewport.prototype = { |
| 33 /** | 31 /** |
| 34 * @return {boolean} | 32 * @return {boolean} |
| 35 */ | 33 */ |
| 36 isDragging: function() | 34 isDragging: function() |
| 37 { | 35 { |
| 38 return this._isDragging; | 36 return this._isDragging; |
| 39 }, | 37 }, |
| 40 | 38 |
| 41 /** | 39 /** |
| 42 * @override | 40 * @override |
| 43 * @return {!Array<!Element>} | 41 * @return {!Array<!Element>} |
| 44 */ | 42 */ |
| 45 elementsToRestoreScrollPositionsFor: function() | 43 elementsToRestoreScrollPositionsFor: function() |
| 46 { | 44 { |
| 47 return [this._vScrollElement]; | 45 return [this._vScrollElement]; |
| 48 }, | 46 }, |
| 49 | 47 |
| 50 /** | 48 /** |
| 51 * @private | 49 * @private |
| 52 */ | 50 */ |
| 53 _updateScrollBar: function() | 51 _updateScrollBar: function() |
| 54 { | 52 { |
| 55 var showScroll = this._totalHeight > this._offsetHeight; | 53 var showScroll = this._totalHeight > this._offsetHeight; |
| 56 if (this._vScrollElement.classList.contains("hidden") === showScroll) { | 54 if (this._vScrollElement.classList.contains("hidden") !== showScroll) |
| 57 this._vScrollElement.classList.toggle("hidden", !showScroll); | 55 return; |
| 58 this._updateContentElementSize(); | 56 this._vScrollElement.classList.toggle("hidden", !showScroll); |
| 59 } | 57 this._updateContentElementSize(); |
| 60 }, | 58 }, |
| 61 | 59 |
| 62 /** | 60 /** |
| 63 * @override | 61 * @override |
| 64 */ | 62 */ |
| 65 onResize: function() | 63 onResize: function() |
| 66 { | 64 { |
| 67 this._updateScrollBar(); | 65 this._updateScrollBar(); |
| 68 this._updateContentElementSize(); | 66 this._updateContentElementSize(); |
| 69 this.scheduleUpdate(); | 67 this.scheduleUpdate(); |
| 70 }, | 68 }, |
| 71 | 69 |
| 72 reset: function() | 70 reset: function() |
| 73 { | 71 { |
| 74 this._vScrollElement.scrollTop = 0; | 72 this._vScrollElement.scrollTop = 0; |
| 75 /** @private */ | |
| 76 this._scrollTop = 0; | 73 this._scrollTop = 0; |
| 77 /** @private */ | |
| 78 this._rangeSelectionStart = 0; | 74 this._rangeSelectionStart = 0; |
| 79 /** @private */ | |
| 80 this._rangeSelectionEnd = 0; | 75 this._rangeSelectionEnd = 0; |
| 81 /** @private */ | |
| 82 this._scrollTop = 0; | |
| 83 /** @private */ | |
| 84 this._isDragging = false; | 76 this._isDragging = false; |
| 85 /** @private */ | |
| 86 this._dragStartPointX = 0; | 77 this._dragStartPointX = 0; |
| 87 /** @private */ | |
| 88 this._dragStartPointY = 0; | 78 this._dragStartPointY = 0; |
| 89 /** @private */ | |
| 90 this._dragStartScrollTop = 0; | 79 this._dragStartScrollTop = 0; |
| 91 /** @private */ | |
| 92 this._timeWindowLeft = 0; | 80 this._timeWindowLeft = 0; |
| 93 /** @private */ | |
| 94 this._timeWindowRight = 0; | 81 this._timeWindowRight = 0; |
| 95 /** @private */ | |
| 96 this._offsetWidth = 0; | 82 this._offsetWidth = 0; |
| 97 /** @private */ | |
| 98 this._offsetHeight = 0; | 83 this._offsetHeight = 0; |
| 99 /** @private */ | |
| 100 this._totalHeight = 0; | 84 this._totalHeight = 0; |
| 101 /** @private */ | |
| 102 this._pendingAnimationTimeLeft = 0; | 85 this._pendingAnimationTimeLeft = 0; |
| 103 /** @private */ | |
| 104 this._pendingAnimationTimeRight = 0; | 86 this._pendingAnimationTimeRight = 0; |
| 105 }, | 87 }, |
| 106 | 88 |
| 107 /** | 89 /** |
| 108 * @private | 90 * @private |
| 109 */ | 91 */ |
| 110 _updateContentElementSize: function() | 92 _updateContentElementSize: function() |
| 111 { | 93 { |
| 112 var offsetWidth = this._vScrollElement.offsetLeft; | 94 var offsetWidth = this._vScrollElement.offsetLeft; |
| 113 if (!offsetWidth) | 95 if (!offsetWidth) |
| 114 offsetWidth = this.contentElement.offsetWidth; | 96 offsetWidth = this.contentElement.offsetWidth; |
| 115 this._offsetWidth = offsetWidth; | 97 this._offsetWidth = offsetWidth; |
| 116 this._offsetHeight = this.contentElement.offsetHeight; | 98 this._offsetHeight = this.contentElement.offsetHeight; |
| 117 }, | 99 }, |
| 118 | 100 |
| 119 setContentHeight: function(totalHeight) | 101 setContentHeight: function(totalHeight) |
| 120 { | 102 { |
| 121 this._totalHeight = totalHeight; | 103 this._totalHeight = totalHeight; |
| 122 this._vScrollContent.style.height = totalHeight + "px"; | 104 this._vScrollContent.style.height = totalHeight + "px"; |
| 105 this._updateScrollBar(); |
| 123 if (this._scrollTop + this._offsetHeight <= totalHeight) | 106 if (this._scrollTop + this._offsetHeight <= totalHeight) |
| 124 return; | 107 return; |
| 125 this._scrollTop = Math.max(0, totalHeight - this._offsetHeight); | 108 this._scrollTop = Math.max(0, totalHeight - this._offsetHeight); |
| 126 this._vScrollElement.scrollTop = this._scrollTop; | 109 this._vScrollElement.scrollTop = this._scrollTop; |
| 127 }, | 110 }, |
| 128 | 111 |
| 129 /** | 112 /** |
| 130 * @param {number} offset | 113 * @param {number} offset |
| 131 * @param {number=} height | 114 * @param {number=} height |
| 132 */ | 115 */ |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 { | 168 { |
| 186 if (event.shiftKey) | 169 if (event.shiftKey) |
| 187 return false; | 170 return false; |
| 188 if (this._windowRight === Infinity) | 171 if (this._windowRight === Infinity) |
| 189 return false; | 172 return false; |
| 190 this._isDragging = true; | 173 this._isDragging = true; |
| 191 this._initMaxDragOffset(event); | 174 this._initMaxDragOffset(event); |
| 192 this._dragStartPointX = x; | 175 this._dragStartPointX = x; |
| 193 this._dragStartPointY = y; | 176 this._dragStartPointY = y; |
| 194 this._dragStartScrollTop = this._vScrollElement.scrollTop; | 177 this._dragStartScrollTop = this._vScrollElement.scrollTop; |
| 195 this.contentElement.style.cursor = ""; | 178 this.viewportElement.style.cursor = ""; |
| 196 this.hideHighlight(); | 179 this.hideHighlight(); |
| 197 return true; | 180 return true; |
| 198 }, | 181 }, |
| 199 | 182 |
| 200 /** | 183 /** |
| 201 * @param {number} x | 184 * @param {number} x |
| 202 * @param {number} y | 185 * @param {number} y |
| 203 * @private | 186 * @private |
| 204 */ | 187 */ |
| 205 _dragging: function(x, y) | 188 _dragging: function(x, y) |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 { | 413 { |
| 431 delete this._cancelWindowTimesAnimation; | 414 delete this._cancelWindowTimesAnimation; |
| 432 this._updateHighlight(); | 415 this._updateHighlight(); |
| 433 }, | 416 }, |
| 434 | 417 |
| 435 /** | 418 /** |
| 436 * @private | 419 * @private |
| 437 */ | 420 */ |
| 438 _cancelAnimation: function() | 421 _cancelAnimation: function() |
| 439 { | 422 { |
| 440 if (this._cancelWindowTimesAnimation) { | 423 if (!this._cancelWindowTimesAnimation) |
| 441 this._timeWindowLeft = this._pendingAnimationTimeLeft; | 424 return; |
| 442 this._timeWindowRight = this._pendingAnimationTimeRight; | 425 this._timeWindowLeft = this._pendingAnimationTimeLeft; |
| 443 this._cancelWindowTimesAnimation(); | 426 this._timeWindowRight = this._pendingAnimationTimeRight; |
| 444 delete this._cancelWindowTimesAnimation; | 427 this._cancelWindowTimesAnimation(); |
| 445 } | 428 delete this._cancelWindowTimesAnimation; |
| 446 }, | 429 }, |
| 447 | 430 |
| 448 scheduleUpdate: function() | 431 scheduleUpdate: function() |
| 449 { | 432 { |
| 450 if (this._updateTimerId || this._cancelWindowTimesAnimation) | 433 if (this._updateTimerId || this._cancelWindowTimesAnimation) |
| 451 return; | 434 return; |
| 452 this._updateTimerId = this.element.window().requestAnimationFrame(() =>
{ | 435 this._updateTimerId = this.element.window().requestAnimationFrame(() =>
{ |
| 453 this._updateTimerId = 0; | 436 this._updateTimerId = 0; |
| 454 this.update(); | 437 this.update(); |
| 455 }); | 438 }); |
| 456 }, | 439 }, |
| 457 | 440 |
| 458 update: function() {}, | 441 update: function() {}, |
| 459 | 442 |
| 460 /** | 443 /** |
| 461 * @param {number} startTime | 444 * @param {number} startTime |
| 462 * @param {number} endTime | 445 * @param {number} endTime |
| 463 */ | 446 */ |
| 464 setWindowTimes: function(startTime, endTime) | 447 setWindowTimes: function(startTime, endTime) |
| 465 { | 448 { |
| 449 this.hideRangeSelection(); |
| 466 if (this._muteAnimation || this._timeWindowLeft === 0 || this._timeWindo
wRight === Infinity || (startTime === 0 && endTime === Infinity) || (startTime =
== Infinity && endTime === Infinity)) { | 450 if (this._muteAnimation || this._timeWindowLeft === 0 || this._timeWindo
wRight === Infinity || (startTime === 0 && endTime === Infinity) || (startTime =
== Infinity && endTime === Infinity)) { |
| 467 // Initial setup. | 451 // Initial setup. |
| 468 this._timeWindowLeft = startTime; | 452 this._timeWindowLeft = startTime; |
| 469 this._timeWindowRight = endTime; | 453 this._timeWindowRight = endTime; |
| 470 this.scheduleUpdate(); | 454 this.scheduleUpdate(); |
| 471 return; | 455 return; |
| 472 } | 456 } |
| 473 this._cancelAnimation(); | 457 this._cancelAnimation(); |
| 474 this._cancelWindowTimesAnimation = WebInspector.animateFunction(this.ele
ment.window(), this._animateWindowTimes.bind(this), | 458 this._cancelWindowTimesAnimation = WebInspector.animateFunction(this.ele
ment.window(), this._animateWindowTimes.bind(this), |
| 475 [{from: this._timeWindowLeft, to: startTime}, {from: this._timeWindo
wRight, to: endTime}], 5, | 459 [{from: this._timeWindowLeft, to: startTime}, {from: this._timeWindo
wRight, to: endTime}], 5, |
| 476 this._animationCompleted.bind(this)); | 460 this._animationCompleted.bind(this)); |
| 477 this._pendingAnimationTimeLeft = startTime; | 461 this._pendingAnimationTimeLeft = startTime; |
| 478 this._pendingAnimationTimeRight = endTime; | 462 this._pendingAnimationTimeRight = endTime; |
| 479 }, | 463 }, |
| 480 | 464 |
| 481 __proto__: WebInspector.VBox.prototype | 465 __proto__: WebInspector.VBox.prototype |
| 482 } | 466 } |
| OLD | NEW |