Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: third_party/WebKit/Source/devtools/front_end/console/ConsoleView.js

Issue 2179123004: DevTools: fix stick to bottom in console viewport (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename forTest fn() Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 f41672c9b35a9187a1f414a30b8484b5c94d47c0..0bfa0cbf4f4aa2e55b6ecab2b9eb2e13e20f828f 100644
--- a/third_party/WebKit/Source/devtools/front_end/console/ConsoleView.js
+++ b/third_party/WebKit/Source/devtools/front_end/console/ConsoleView.js
@@ -154,6 +154,12 @@ 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("mousewheel", this._updateStickToBottomOnMouseWheel.bind(this), false);
+ this._messagesElement.addEventListener("mouseup", this._updateStickToBottomOnMouseUp.bind(this), false);
+ this._messagesElement.addEventListener("mouseleave", this._updateStickToBottomOnMouseUp.bind(this), false);
+ this._messagesElement.addEventListener("keydown", this._updateStickToBottomOnKeyDown.bind(this), true);
}
WebInspector.ConsoleView.persistedHistorySize = 300;
@@ -353,7 +359,7 @@ WebInspector.ConsoleView.prototype = {
restoreScrollPositions: function()
{
- if (this._viewport.scrolledToBottom())
+ if (this._viewport.stickToBottom())
this._immediatelyScrollToBottom();
else
WebInspector.Widget.prototype.restoreScrollPositions.call(this);
@@ -363,7 +369,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();
@@ -383,6 +389,8 @@ WebInspector.ConsoleView.prototype = {
*/
function invalidateViewport()
{
+ if (this._muteViewportUpdates)
+ return Promise.resolve();
if (this._needsFullUpdate) {
this._updateMessageList();
delete this._needsFullUpdate;
@@ -391,12 +399,15 @@ WebInspector.ConsoleView.prototype = {
}
return Promise.resolve();
}
+ if (this._muteViewportUpdates)
+ 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);
},
@@ -1003,6 +1014,67 @@ WebInspector.ConsoleView.prototype = {
highlightNode.scrollIntoViewIfNeeded();
},
+ _updateStickToBottomOnMouseDown: function()
+ {
+ this._muteViewportUpdates = true;
+ this._viewport.setStickToBottom(false);
+ this._wasScrolledToBottom = this._messagesElement.isScrolledToBottom();
+ },
+
+ _updateStickToBottomOnMouseUp: function()
+ {
+ if (!this._muteViewportUpdates)
+ return;
+
+ this._muteViewportUpdates = false;
+ if (this._wasScrolledToBottom) {
+ // Clicking the scrollbar may trigger events in the order:
+ // mousedown > mouseup > scroll. 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.
+ setTimeout(updateViewportState.bind(this), 200);
+ } else {
+ // In another case, when users drag the scroll thumb to the bottom,
+ // the viewport should stick. Checking whether the mouse is released
+ // at the bottom of the viewport is not verifiable after an async
+ // timeout, so we do it immediately.
+ updateViewportState.call(this);
+ }
+ delete this._wasScrolledToBottom;
+
+ /**
+ * @this {!WebInspector.ConsoleView}
+ */
+ function updateViewportState()
+ {
+ this._viewport.setStickToBottom(this._messagesElement.isScrolledToBottom());
+ this._scheduleViewportRefresh();
+ this._updateViewportStickinessForTest();
+ }
+ },
+
+ _updateViewportStickinessForTest: function()
+ {
+ // This method is sniffed in tests.
+ },
+
+ _updateStickToBottomOnMouseWheel: function()
+ {
+ this._updateStickToBottomOnMouseDown();
+ this._updateStickToBottomOnMouseUp();
+ },
+
+ _updateStickToBottomOnKeyDown: function(event)
dgozman 2016/08/03 21:19:01 Can we instead listen to prompt text changed or so
luoe 2016/08/04 23:13:01 Yeah, that would be better.
+ {
+ if (event.key === "Escape")
dgozman 2016/08/03 21:19:01 This still looks really hacky. What happens if I d
luoe 2016/08/04 23:13:01 You're right, I hadn't thought of that. Modified
+ return;
+
+ if (event.key === "PageUp" || event.key === "PageDown")
dgozman 2016/08/03 21:19:00 Ctrl+Home/End? Opt+Something on mac? There could b
luoe 2016/08/04 23:13:01 On Mac, Fn-Arrow keys map to PageUp/Down/Home/End.
+ this._updateStickToBottomOnMouseWheel();
+ else
+ this._viewport.setStickToBottom(true);
+ },
+
__proto__: WebInspector.VBox.prototype
}

Powered by Google App Engine
This is Rietveld 408576698