Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/console/ConsoleView.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/console/ConsoleView.js b/third_party/WebKit/Source/devtools/front_end/console/ConsoleView.js |
| index 1c057b0091fc9b1669ae0b1d40af2b4dc885b432..e1f9bb56e37db169bcc00cfaf88232b290618196 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/console/ConsoleView.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/console/ConsoleView.js |
| @@ -136,6 +136,7 @@ WebInspector.ConsoleView = function() |
| this._prompt.renderAsBlock(); |
| var proxyElement = this._prompt.attach(this._promptElement); |
| proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this), false); |
| + proxyElement.addEventListener("input", this._promptInput.bind(this), false); |
| this._consoleHistorySetting = WebInspector.settings.createLocalSetting("consoleHistory", []); |
| var historyData = this._consoleHistorySetting.get(); |
| @@ -154,6 +155,11 @@ WebInspector.ConsoleView = function() |
| this._initConsoleMessages(); |
| WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this._executionContextChanged, this); |
| + |
| + this._messagesElement.addEventListener("mousedown", this._updateStickToBottomOnMouseDown.bind(this), false); |
| + this._messagesElement.addEventListener("mouseup", this._updateStickToBottomOnMouseUp.bind(this), false); |
| + this._messagesElement.addEventListener("mouseleave", this._updateStickToBottomOnMouseUp.bind(this), false); |
| + this._messagesElement.addEventListener("wheel", this._updateStickToBottomOnWheel.bind(this), false); |
| } |
| WebInspector.ConsoleView.persistedHistorySize = 300; |
| @@ -344,7 +350,7 @@ WebInspector.ConsoleView.prototype = { |
| restoreScrollPositions: function() |
| { |
| - if (this._viewport.scrolledToBottom()) |
| + if (this._viewport.stickToBottom()) |
| this._immediatelyScrollToBottom(); |
| else |
| WebInspector.Widget.prototype.restoreScrollPositions.call(this); |
| @@ -354,7 +360,7 @@ WebInspector.ConsoleView.prototype = { |
| { |
| this._scheduleViewportRefresh(); |
| this._hidePromptSuggestBox(); |
| - if (this._viewport.scrolledToBottom()) |
| + if (this._viewport.stickToBottom()) |
| this._immediatelyScrollToBottom(); |
| for (var i = 0; i < this._visibleViewMessages.length; ++i) |
| this._visibleViewMessages[i].onResize(); |
| @@ -374,6 +380,8 @@ WebInspector.ConsoleView.prototype = { |
| */ |
| function invalidateViewport() |
| { |
| + if (this._muteViewportUpdates) |
|
dgozman
2016/08/09 21:16:47
Let's do dirty flag here as well.
luoe
2016/08/10 01:03:07
Done.
|
| + return Promise.resolve(); |
| if (this._needsFullUpdate) { |
| this._updateMessageList(); |
| delete this._needsFullUpdate; |
| @@ -382,12 +390,17 @@ WebInspector.ConsoleView.prototype = { |
| } |
| return Promise.resolve(); |
| } |
| + if (this._muteViewportUpdates) { |
| + this._maybeDirtyWhileMuted = true; |
| + return; |
| + } |
| this._viewportThrottler.schedule(invalidateViewport.bind(this)); |
| }, |
| _immediatelyScrollToBottom: function() |
| { |
| // This will scroll viewport and trigger its refresh. |
| + this._viewport.setStickToBottom(true); |
| this._promptElement.scrollIntoView(true); |
| }, |
| @@ -744,7 +757,9 @@ WebInspector.ConsoleView.prototype = { |
| _promptKeyDown: function(event) |
| { |
| - if (isEnterKey(event)) { |
| + if (event.key === "PageUp") { |
| + this._updateStickToBottomOnWheel(); |
| + } else if (isEnterKey(event)) { |
| this._enterKeyPressed(event); |
| return; |
| } |
| @@ -995,6 +1010,61 @@ WebInspector.ConsoleView.prototype = { |
| highlightNode.scrollIntoViewIfNeeded(); |
| }, |
| + _updateStickToBottomOnMouseDown: function() |
| + { |
| + this._muteViewportUpdates = true; |
| + this._viewport.setStickToBottom(false); |
| + if (this._waitForScrollTimeout) { |
| + clearTimeout(this._waitForScrollTimeout); |
| + delete this._waitForScrollTimeout; |
| + } |
| + }, |
| + |
| + _updateStickToBottomOnMouseUp: function() |
| + { |
| + if (!this._muteViewportUpdates) |
| + return; |
| + |
| + // Delay querying isScrolledToBottom to give time for smooth scroll |
| + // events to arrive. The value for the longest timeout duration is |
| + // retrieved from crbug.com/575409. |
| + this._waitForScrollTimeout = setTimeout(updateViewportState.bind(this), 200); |
| + |
| + /** |
| + * @this {!WebInspector.ConsoleView} |
| + */ |
| + function updateViewportState() |
| + { |
| + this._muteViewportUpdates = false; |
|
dgozman
2016/08/09 21:16:47
Also do |delete this._waitForScrollTimeout|
luoe
2016/08/10 01:03:07
Done.
|
| + this._viewport.setStickToBottom(this._messagesElement.isScrolledToBottom()); |
| + if (this._maybeDirtyWhileMuted) { |
| + this._scheduleViewportRefresh(); |
|
dgozman
2016/08/09 21:16:47
Let's add a test which adds new messages while use
luoe
2016/08/10 01:03:07
Done.
|
| + delete this._maybeDirtyWhileMuted; |
| + } |
| + this._updateViewportStickinessForTest(); |
| + } |
| + }, |
| + |
| + _updateViewportStickinessForTest: function() |
| + { |
| + // This method is sniffed in tests. |
| + }, |
| + |
| + _updateStickToBottomOnWheel: function() |
| + { |
| + this._updateStickToBottomOnMouseDown(); |
| + this._updateStickToBottomOnMouseUp(); |
| + }, |
| + |
| + _promptInput: function(event) |
| + { |
| + // When the prompt is the only visible item, do not scroll to bottom. |
| + if (this.itemCount() === 0 || this._viewport.firstVisibleIndex() === this.itemCount()) |
| + this._viewport.setStickToBottom(false); |
|
dgozman
2016/08/09 21:16:47
I don't think we should set it false - just return
luoe
2016/08/10 01:03:07
Done.
|
| + else |
| + this._immediatelyScrollToBottom(); |
| + }, |
| + |
| __proto__: WebInspector.VBox.prototype |
| } |