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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 /** @type {!Array.<!WebInspector.ConsoleViewMessage>} */ | 129 /** @type {!Array.<!WebInspector.ConsoleViewMessage>} */ |
| 130 this._consoleMessages = []; | 130 this._consoleMessages = []; |
| 131 this._viewMessageSymbol = Symbol("viewMessage"); | 131 this._viewMessageSymbol = Symbol("viewMessage"); |
| 132 | 132 |
| 133 this._prompt = new WebInspector.TextPromptWithHistory(WebInspector.Execution ContextSelector.completionsForTextPromptInCurrentContext); | 133 this._prompt = new WebInspector.TextPromptWithHistory(WebInspector.Execution ContextSelector.completionsForTextPromptInCurrentContext); |
| 134 this._prompt.setSuggestBoxEnabled(true); | 134 this._prompt.setSuggestBoxEnabled(true); |
| 135 this._prompt.setAutocompletionTimeout(0); | 135 this._prompt.setAutocompletionTimeout(0); |
| 136 this._prompt.renderAsBlock(); | 136 this._prompt.renderAsBlock(); |
| 137 var proxyElement = this._prompt.attach(this._promptElement); | 137 var proxyElement = this._prompt.attach(this._promptElement); |
| 138 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this), fal se); | 138 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this), fal se); |
| 139 proxyElement.addEventListener("input", this._promptInput.bind(this), false); | |
| 139 | 140 |
| 140 this._consoleHistorySetting = WebInspector.settings.createLocalSetting("cons oleHistory", []); | 141 this._consoleHistorySetting = WebInspector.settings.createLocalSetting("cons oleHistory", []); |
| 141 var historyData = this._consoleHistorySetting.get(); | 142 var historyData = this._consoleHistorySetting.get(); |
| 142 this._prompt.setHistoryData(historyData); | 143 this._prompt.setHistoryData(historyData); |
| 143 | 144 |
| 144 this._consoleHistoryAutocompleteSetting = WebInspector.moduleSetting("consol eHistoryAutocomplete"); | 145 this._consoleHistoryAutocompleteSetting = WebInspector.moduleSetting("consol eHistoryAutocomplete"); |
| 145 this._consoleHistoryAutocompleteSetting.addChangeListener(this._consoleHisto ryAutocompleteChanged, this); | 146 this._consoleHistoryAutocompleteSetting.addChangeListener(this._consoleHisto ryAutocompleteChanged, this); |
| 146 this._consoleHistoryAutocompleteChanged(); | 147 this._consoleHistoryAutocompleteChanged(); |
| 147 | 148 |
| 148 this._updateFilterStatus(); | 149 this._updateFilterStatus(); |
| 149 WebInspector.moduleSetting("consoleTimestampsEnabled").addChangeListener(thi s._consoleTimestampsSettingChanged, this); | 150 WebInspector.moduleSetting("consoleTimestampsEnabled").addChangeListener(thi s._consoleTimestampsSettingChanged, this); |
| 150 | 151 |
| 151 this._registerWithMessageSink(); | 152 this._registerWithMessageSink(); |
| 152 WebInspector.targetManager.observeTargets(this); | 153 WebInspector.targetManager.observeTargets(this); |
| 153 | 154 |
| 154 this._initConsoleMessages(); | 155 this._initConsoleMessages(); |
| 155 | 156 |
| 156 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this._executionContextChanged, this); | 157 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this._executionContextChanged, this); |
| 158 | |
| 159 this._messagesElement.addEventListener("mousedown", this._updateStickToBotto mOnMouseDown.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("wheel", this._updateStickToBottomOnW heel.bind(this), false); | |
| 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Enter), WebInspecto r.UIString("Execute command")); | 757 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Enter), WebInspecto r.UIString("Execute command")); |
| 747 }, | 758 }, |
| 748 | 759 |
| 749 _clearPromptBackwards: function() | 760 _clearPromptBackwards: function() |
| 750 { | 761 { |
| 751 this._prompt.setText(""); | 762 this._prompt.setText(""); |
| 752 }, | 763 }, |
| 753 | 764 |
| 754 _promptKeyDown: function(event) | 765 _promptKeyDown: function(event) |
| 755 { | 766 { |
| 756 if (isEnterKey(event)) { | 767 if (event.key === "PageUp") { |
|
dgozman
2016/08/05 21:08:25
Let's move this back to keydown on element.
luoe
2016/08/05 23:05:57
On a closer look, I think this actually can stay.
| |
| 768 this._updateStickToBottomOnWheel(); | |
| 769 } else if (isEnterKey(event)) { | |
| 757 this._enterKeyPressed(event); | 770 this._enterKeyPressed(event); |
| 758 return; | 771 return; |
| 759 } | 772 } |
| 760 | 773 |
| 761 var shortcut = WebInspector.KeyboardShortcut.makeKeyFromEvent(event); | 774 var shortcut = WebInspector.KeyboardShortcut.makeKeyFromEvent(event); |
| 762 var handler = this._shortcuts[shortcut]; | 775 var handler = this._shortcuts[shortcut]; |
| 763 if (handler) { | 776 if (handler) { |
| 764 handler(); | 777 handler(); |
| 765 event.preventDefault(); | 778 event.preventDefault(); |
| 766 } | 779 } |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 997 this._currentMatchRangeIndex = index; | 1010 this._currentMatchRangeIndex = index; |
| 998 this._searchableView.updateCurrentMatchIndex(index); | 1011 this._searchableView.updateCurrentMatchIndex(index); |
| 999 matchRange = this._regexMatchRanges[index]; | 1012 matchRange = this._regexMatchRanges[index]; |
| 1000 var message = this._visibleViewMessages[matchRange.messageIndex]; | 1013 var message = this._visibleViewMessages[matchRange.messageIndex]; |
| 1001 var highlightNode = message.searchHighlightNode(matchRange.matchIndex); | 1014 var highlightNode = message.searchHighlightNode(matchRange.matchIndex); |
| 1002 highlightNode.classList.add(WebInspector.highlightedCurrentSearchResultC lassName); | 1015 highlightNode.classList.add(WebInspector.highlightedCurrentSearchResultC lassName); |
| 1003 this._viewport.scrollItemIntoView(matchRange.messageIndex); | 1016 this._viewport.scrollItemIntoView(matchRange.messageIndex); |
| 1004 highlightNode.scrollIntoViewIfNeeded(); | 1017 highlightNode.scrollIntoViewIfNeeded(); |
| 1005 }, | 1018 }, |
| 1006 | 1019 |
| 1020 _updateStickToBottomOnMouseDown: function() | |
| 1021 { | |
| 1022 this._muteViewportUpdates = true; | |
| 1023 this._viewport.setStickToBottom(false); | |
| 1024 }, | |
| 1025 | |
| 1026 _updateStickToBottomOnMouseUp: function() | |
| 1027 { | |
| 1028 if (!this._muteViewportUpdates) | |
| 1029 return; | |
| 1030 | |
| 1031 // Delay querying isScrolledToBottom to give time for smooth scroll | |
| 1032 // events to arrive. The value for the longest timeout duration is | |
| 1033 // retrieved from crbug.com/575409. | |
| 1034 setTimeout(updateViewportState.bind(this), 200); | |
|
dgozman
2016/08/05 21:08:25
Let's cancel previous one if any.
luoe
2016/08/05 23:05:57
Done.
| |
| 1035 | |
| 1036 /** | |
| 1037 * @this {!WebInspector.ConsoleView} | |
| 1038 */ | |
| 1039 function updateViewportState() | |
| 1040 { | |
| 1041 this._muteViewportUpdates = false; | |
|
dgozman
2016/08/05 21:08:25
We should schedule update here.
luoe
2016/08/05 23:05:57
We should. Doing so introduces an unfortunate slo
| |
| 1042 this._viewport.setStickToBottom(this._messagesElement.isScrolledToBo ttom()); | |
| 1043 this._updateViewportStickinessForTest(); | |
| 1044 } | |
| 1045 }, | |
| 1046 | |
| 1047 _updateViewportStickinessForTest: function() | |
| 1048 { | |
| 1049 // This method is sniffed in tests. | |
| 1050 }, | |
| 1051 | |
| 1052 _updateStickToBottomOnWheel: function() | |
| 1053 { | |
| 1054 this._updateStickToBottomOnMouseDown(); | |
| 1055 this._updateStickToBottomOnMouseUp(); | |
| 1056 }, | |
| 1057 | |
| 1058 _promptInput: function(event) | |
| 1059 { | |
| 1060 this._viewport.setStickToBottom(true); | |
|
dgozman
2016/08/05 21:08:25
Let's use _immediatelyScrollToBottom.
luoe
2016/08/05 23:05:57
Done.
| |
| 1061 }, | |
| 1062 | |
| 1007 __proto__: WebInspector.VBox.prototype | 1063 __proto__: WebInspector.VBox.prototype |
| 1008 } | 1064 } |
| 1009 | 1065 |
| 1010 /** | 1066 /** |
| 1011 * @constructor | 1067 * @constructor |
| 1012 * @extends {WebInspector.Object} | 1068 * @extends {WebInspector.Object} |
| 1013 * @param {!WebInspector.ConsoleView} view | 1069 * @param {!WebInspector.ConsoleView} view |
| 1014 */ | 1070 */ |
| 1015 WebInspector.ConsoleViewFilter = function(view) | 1071 WebInspector.ConsoleViewFilter = function(view) |
| 1016 { | 1072 { |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1339 return true; | 1395 return true; |
| 1340 } | 1396 } |
| 1341 return false; | 1397 return false; |
| 1342 } | 1398 } |
| 1343 } | 1399 } |
| 1344 | 1400 |
| 1345 /** | 1401 /** |
| 1346 * @typedef {{messageIndex: number, matchIndex: number}} | 1402 * @typedef {{messageIndex: number, matchIndex: number}} |
| 1347 */ | 1403 */ |
| 1348 WebInspector.ConsoleView.RegexMatchRange; | 1404 WebInspector.ConsoleView.RegexMatchRange; |
| OLD | NEW |