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

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

Issue 2154893002: DevTools: remove isTrusted check and isUserGesture from ViewportControl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DevTools: fix stick to bottom in console viewport Created 4 years, 5 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..4ab0e4925529b14af9d05a8efb9f37181a1aa122 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,60 @@ WebInspector.ConsoleView.prototype = {
highlightNode.scrollIntoViewIfNeeded();
},
+ _updateStickToBottomOnMouseDown: function()
+ {
+ this._muteViewportUpdates = true;
+ this._viewport.setStickToBottom(false);
+ this._wasScrolledToBottom = this._viewport.element.isScrolledToBottom();
+ },
+
+ _updateStickToBottomOnMouseUp: function()
+ {
+ this._muteViewportUpdates = false;
+ if (this._wasScrolledToBottom) {
+ // When stuck to the bottom, clicking the gray area above the scroll
+ // thumb should scroll upwards and stop sticking. Smooth scroll
+ // events triggered by the click need to finish before querying
+ // isScrolledToBottom. The timeout value used is the longest smooth
+ // scroll duration, a value 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._viewport.element.isScrolledToBottom());
+ this._scheduleViewportRefresh();
+ }
+ },
+
+ _updateStickToBottomOnMouseWheel: function()
+ {
+ this._updateStickToBottomOnMouseDown();
+ this._updateStickToBottomOnMouseUp();
+ },
+
+ _updateStickToBottomOnKeyDown: function(event)
+ {
+ var isPageUpDown = event.keyCode === WebInspector.KeyboardShortcut.Keys.PageDown.code || event.keyCode === WebInspector.KeyboardShortcut.Keys.PageUp.code;
+ var isEsc = event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code;
+ if (isEsc)
+ return;
+ if (isPageUpDown)
+ this._updateStickToBottomOnMouseWheel();
+ else
+ this._viewport.setStickToBottom(true);
+ },
+
__proto__: WebInspector.VBox.prototype
}

Powered by Google App Engine
This is Rietveld 408576698