Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 | 147 |
| 148 this._updateFilterStatus(); | 148 this._updateFilterStatus(); |
| 149 WebInspector.moduleSetting("consoleTimestampsEnabled").addChangeListener(thi s._consoleTimestampsSettingChanged, this); | 149 WebInspector.moduleSetting("consoleTimestampsEnabled").addChangeListener(thi s._consoleTimestampsSettingChanged, this); |
| 150 | 150 |
| 151 this._registerWithMessageSink(); | 151 this._registerWithMessageSink(); |
| 152 WebInspector.targetManager.observeTargets(this); | 152 WebInspector.targetManager.observeTargets(this); |
| 153 | 153 |
| 154 this._initConsoleMessages(); | 154 this._initConsoleMessages(); |
| 155 | 155 |
| 156 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this._executionContextChanged, this); | 156 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this._executionContextChanged, this); |
| 157 | |
| 158 this._messagesElement.addEventListener("mousedown", this._updateStickToBotto mOnMouseDown.bind(this), false); | |
| 159 this._messagesElement.addEventListener("mousewheel", this._updateStickToBott omOnMouseWheel.bind(this), false); | |
| 160 this._messagesElement.addEventListener("mouseup", this._updateStickToBottomO nMouseUp.bind(this), false); | |
| 161 this._messagesElement.addEventListener("mouseleave", this._updateStickToBott omOnMouseUp.bind(this), false); | |
| 162 this._messagesElement.addEventListener("keydown", this._updateStickToBottomO nKeyDown.bind(this), true); | |
| 157 } | 163 } |
| 158 | 164 |
| 159 WebInspector.ConsoleView.persistedHistorySize = 300; | 165 WebInspector.ConsoleView.persistedHistorySize = 300; |
| 160 | 166 |
| 161 WebInspector.ConsoleView.prototype = { | 167 WebInspector.ConsoleView.prototype = { |
| 162 /** | 168 /** |
| 163 * @return {!WebInspector.SearchableView} | 169 * @return {!WebInspector.SearchableView} |
| 164 */ | 170 */ |
| 165 searchableView: function() | 171 searchableView: function() |
| 166 { | 172 { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 if (this._promptElement === WebInspector.currentFocusElement()) | 352 if (this._promptElement === WebInspector.currentFocusElement()) |
| 347 return; | 353 return; |
| 348 // Set caret position before setting focus in order to avoid scrolling | 354 // Set caret position before setting focus in order to avoid scrolling |
| 349 // by focus(). | 355 // by focus(). |
| 350 this._prompt.moveCaretToEndOfPrompt(); | 356 this._prompt.moveCaretToEndOfPrompt(); |
| 351 WebInspector.setCurrentFocusElement(this._promptElement); | 357 WebInspector.setCurrentFocusElement(this._promptElement); |
| 352 }, | 358 }, |
| 353 | 359 |
| 354 restoreScrollPositions: function() | 360 restoreScrollPositions: function() |
| 355 { | 361 { |
| 356 if (this._viewport.scrolledToBottom()) | 362 if (this._viewport.stickToBottom()) |
| 357 this._immediatelyScrollToBottom(); | 363 this._immediatelyScrollToBottom(); |
| 358 else | 364 else |
| 359 WebInspector.Widget.prototype.restoreScrollPositions.call(this); | 365 WebInspector.Widget.prototype.restoreScrollPositions.call(this); |
| 360 }, | 366 }, |
| 361 | 367 |
| 362 onResize: function() | 368 onResize: function() |
| 363 { | 369 { |
| 364 this._scheduleViewportRefresh(); | 370 this._scheduleViewportRefresh(); |
| 365 this._hidePromptSuggestBox(); | 371 this._hidePromptSuggestBox(); |
| 366 if (this._viewport.scrolledToBottom()) | 372 if (this._viewport.stickToBottom()) |
| 367 this._immediatelyScrollToBottom(); | 373 this._immediatelyScrollToBottom(); |
| 368 for (var i = 0; i < this._visibleViewMessages.length; ++i) | 374 for (var i = 0; i < this._visibleViewMessages.length; ++i) |
| 369 this._visibleViewMessages[i].onResize(); | 375 this._visibleViewMessages[i].onResize(); |
| 370 }, | 376 }, |
| 371 | 377 |
| 372 _hidePromptSuggestBox: function() | 378 _hidePromptSuggestBox: function() |
| 373 { | 379 { |
| 374 this._prompt.hideSuggestBox(); | 380 this._prompt.hideSuggestBox(); |
| 375 this._prompt.clearAutoComplete(true); | 381 this._prompt.clearAutoComplete(true); |
| 376 }, | 382 }, |
| 377 | 383 |
| 378 _scheduleViewportRefresh: function() | 384 _scheduleViewportRefresh: function() |
| 379 { | 385 { |
| 380 /** | 386 /** |
| 381 * @this {WebInspector.ConsoleView} | 387 * @this {WebInspector.ConsoleView} |
| 382 * @return {!Promise.<undefined>} | 388 * @return {!Promise.<undefined>} |
| 383 */ | 389 */ |
| 384 function invalidateViewport() | 390 function invalidateViewport() |
| 385 { | 391 { |
| 392 if (this._muteViewportUpdates) | |
| 393 return Promise.resolve(); | |
| 386 if (this._needsFullUpdate) { | 394 if (this._needsFullUpdate) { |
| 387 this._updateMessageList(); | 395 this._updateMessageList(); |
| 388 delete this._needsFullUpdate; | 396 delete this._needsFullUpdate; |
| 389 } else { | 397 } else { |
| 390 this._viewport.invalidate(); | 398 this._viewport.invalidate(); |
| 391 } | 399 } |
| 392 return Promise.resolve(); | 400 return Promise.resolve(); |
| 393 } | 401 } |
| 402 if (this._muteViewportUpdates) | |
| 403 return; | |
| 394 this._viewportThrottler.schedule(invalidateViewport.bind(this)); | 404 this._viewportThrottler.schedule(invalidateViewport.bind(this)); |
| 395 }, | 405 }, |
| 396 | 406 |
| 397 _immediatelyScrollToBottom: function() | 407 _immediatelyScrollToBottom: function() |
| 398 { | 408 { |
| 399 // This will scroll viewport and trigger its refresh. | 409 // This will scroll viewport and trigger its refresh. |
| 410 this._viewport.setStickToBottom(true); | |
| 400 this._promptElement.scrollIntoView(true); | 411 this._promptElement.scrollIntoView(true); |
| 401 }, | 412 }, |
| 402 | 413 |
| 403 _updateFilterStatus: function() | 414 _updateFilterStatus: function() |
| 404 { | 415 { |
| 405 this._filterStatusTextElement.textContent = WebInspector.UIString(this._ hiddenByFilterCount === 1 ? "%d message is hidden by filters." : "%d messages ar e hidden by filters.", this._hiddenByFilterCount); | 416 this._filterStatusTextElement.textContent = WebInspector.UIString(this._ hiddenByFilterCount === 1 ? "%d message is hidden by filters." : "%d messages ar e hidden by filters.", this._hiddenByFilterCount); |
| 406 this._filterStatusMessageElement.style.display = this._hiddenByFilterCou nt ? "" : "none"; | 417 this._filterStatusMessageElement.style.display = this._hiddenByFilterCou nt ? "" : "none"; |
| 407 }, | 418 }, |
| 408 | 419 |
| 409 /** | 420 /** |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 this._currentMatchRangeIndex = index; | 1007 this._currentMatchRangeIndex = index; |
| 997 this._searchableView.updateCurrentMatchIndex(index); | 1008 this._searchableView.updateCurrentMatchIndex(index); |
| 998 matchRange = this._regexMatchRanges[index]; | 1009 matchRange = this._regexMatchRanges[index]; |
| 999 var message = this._visibleViewMessages[matchRange.messageIndex]; | 1010 var message = this._visibleViewMessages[matchRange.messageIndex]; |
| 1000 var highlightNode = message.searchHighlightNode(matchRange.matchIndex); | 1011 var highlightNode = message.searchHighlightNode(matchRange.matchIndex); |
| 1001 highlightNode.classList.add(WebInspector.highlightedCurrentSearchResultC lassName); | 1012 highlightNode.classList.add(WebInspector.highlightedCurrentSearchResultC lassName); |
| 1002 this._viewport.scrollItemIntoView(matchRange.messageIndex); | 1013 this._viewport.scrollItemIntoView(matchRange.messageIndex); |
| 1003 highlightNode.scrollIntoViewIfNeeded(); | 1014 highlightNode.scrollIntoViewIfNeeded(); |
| 1004 }, | 1015 }, |
| 1005 | 1016 |
| 1017 _updateStickToBottomOnMouseDown: function() | |
| 1018 { | |
| 1019 this._muteViewportUpdates = true; | |
| 1020 this._viewport.setStickToBottom(false); | |
| 1021 this._wasScrolledToBottom = this._messagesElement.isScrolledToBottom(); | |
| 1022 }, | |
| 1023 | |
| 1024 _updateStickToBottomOnMouseUp: function() | |
| 1025 { | |
| 1026 if (!this._muteViewportUpdates) | |
| 1027 return; | |
| 1028 | |
| 1029 this._muteViewportUpdates = false; | |
| 1030 if (this._wasScrolledToBottom) { | |
| 1031 // Clicking the scrollbar may trigger events in the order: | |
| 1032 // mousedown > mouseup > scroll. Delay querying isScrolledToBottom | |
| 1033 // to give time for smooth scroll events to arrive. The value for | |
| 1034 // the longest timeout duration is retrieved from crbug.com/575409. | |
| 1035 setTimeout(updateViewportState.bind(this), 200); | |
| 1036 } else { | |
| 1037 // In another case, when users drag the scroll thumb to the bottom, | |
| 1038 // the viewport should stick. Checking whether the mouse is released | |
| 1039 // at the bottom of the viewport is not verifiable after an async | |
| 1040 // timeout, so we do it immediately. | |
| 1041 updateViewportState.call(this); | |
| 1042 } | |
| 1043 delete this._wasScrolledToBottom; | |
| 1044 | |
| 1045 /** | |
| 1046 * @this {!WebInspector.ConsoleView} | |
| 1047 */ | |
| 1048 function updateViewportState() | |
| 1049 { | |
| 1050 this._viewport.setStickToBottom(this._messagesElement.isScrolledToBo ttom()); | |
| 1051 this._scheduleViewportRefresh(); | |
| 1052 this._updateViewportForTest(); | |
| 1053 } | |
| 1054 }, | |
| 1055 | |
| 1056 _updateViewportForTest: function() | |
|
lushnikov
2016/08/02 19:37:25
_updateViewportStickinessForTest
luoe
2016/08/03 17:16:23
Done.
| |
| 1057 { | |
| 1058 // This method is sniffed in tests. | |
| 1059 }, | |
| 1060 | |
| 1061 _updateStickToBottomOnMouseWheel: function() | |
| 1062 { | |
| 1063 this._updateStickToBottomOnMouseDown(); | |
| 1064 this._updateStickToBottomOnMouseUp(); | |
| 1065 }, | |
| 1066 | |
| 1067 _updateStickToBottomOnKeyDown: function(event) | |
| 1068 { | |
| 1069 if (event.key === "Escape") | |
| 1070 return; | |
| 1071 | |
| 1072 if (event.key === "PageUp" || event.key === "PageDown") | |
| 1073 this._updateStickToBottomOnMouseWheel(); | |
| 1074 else | |
| 1075 this._viewport.setStickToBottom(true); | |
| 1076 }, | |
| 1077 | |
| 1006 __proto__: WebInspector.VBox.prototype | 1078 __proto__: WebInspector.VBox.prototype |
| 1007 } | 1079 } |
| 1008 | 1080 |
| 1009 /** | 1081 /** |
| 1010 * @constructor | 1082 * @constructor |
| 1011 * @extends {WebInspector.Object} | 1083 * @extends {WebInspector.Object} |
| 1012 * @param {!WebInspector.ConsoleView} view | 1084 * @param {!WebInspector.ConsoleView} view |
| 1013 */ | 1085 */ |
| 1014 WebInspector.ConsoleViewFilter = function(view) | 1086 WebInspector.ConsoleViewFilter = function(view) |
| 1015 { | 1087 { |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1338 return true; | 1410 return true; |
| 1339 } | 1411 } |
| 1340 return false; | 1412 return false; |
| 1341 } | 1413 } |
| 1342 } | 1414 } |
| 1343 | 1415 |
| 1344 /** | 1416 /** |
| 1345 * @typedef {{messageIndex: number, matchIndex: number}} | 1417 * @typedef {{messageIndex: number, matchIndex: number}} |
| 1346 */ | 1418 */ |
| 1347 WebInspector.ConsoleView.RegexMatchRange; | 1419 WebInspector.ConsoleView.RegexMatchRange; |
| OLD | NEW |