From 533a12d4930082a4162fdac2194d8d498b15b50b Mon Sep 17 00:00:00 2001 From: Blake Kaplan Date: Thu, 28 May 2015 09:55:46 -0700 Subject: [PATCH] Bug 1162329 - Fix the autocomplete popup opening with cached results. r=felipe The e10s autocomplete popup doesn't pop back up if nsAutoCompleteController.cpp decides to reuse its cached autocomplete result. We need to detect when this happens and open the popup in the parent. --- .../components/satchel/AutoCompleteE10S.jsm | 19 ++++++++++++++++++- toolkit/content/browser-child.js | 6 ++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/toolkit/components/satchel/AutoCompleteE10S.jsm b/toolkit/components/satchel/AutoCompleteE10S.jsm index c5491664ce6..5b3f7544ab0 100644 --- a/toolkit/components/satchel/AutoCompleteE10S.jsm +++ b/toolkit/components/satchel/AutoCompleteE10S.jsm @@ -82,10 +82,13 @@ this.AutoCompleteE10S = { getService(Ci.nsIMessageListenerManager); messageManager.addMessageListener("FormAutoComplete:SelectBy", this); messageManager.addMessageListener("FormAutoComplete:GetSelectedIndex", this); + messageManager.addMessageListener("FormAutoComplete:MaybeOpenPopup", this); messageManager.addMessageListener("FormAutoComplete:ClosePopup", this); }, _initPopup: function(browserWindow, rect, direction) { + this._popupCache = { browserWindow, rect, direction }; + this.browser = browserWindow.gBrowser.selectedBrowser; this.popup = this.browser.autoCompletePopup; this.popup.hidden = false; @@ -122,6 +125,7 @@ this.AutoCompleteE10S = { this.popup.closePopup(); } + this._resultCache = results; return resultsArray; }, @@ -192,6 +196,19 @@ this.AutoCompleteE10S = { case "FormAutoComplete:GetSelectedIndex": return this.popup.selectedIndex; + case "FormAutoComplete:MaybeOpenPopup": + if (AutoCompleteE10SView.treeData.length > 0 && + !this.popup.popupOpen) { + // This happens when one of the arrow keys is pressed after a search + // has already been completed. nsAutoCompleteController tries to + // re-use its own cache of the results without re-doing the search. + // Detect that and show the popup here. + this.showPopupWithResults(this._popupCache.browserWindow, + this._popupCache.rect, + this._resultCache); + } + break; + case "FormAutoComplete:ClosePopup": this.popup.closePopup(); break; @@ -202,7 +219,7 @@ this.AutoCompleteE10S = { this.browser.messageManager.sendAsyncMessage( "FormAutoComplete:HandleEnter", { selectedIndex: this.popup.selectedIndex, - IsPopupSelection: aIsPopupSelection } + isPopupSelection: aIsPopupSelection } ); }, diff --git a/toolkit/content/browser-child.js b/toolkit/content/browser-child.js index 6a37e928488..629788a58bc 100644 --- a/toolkit/content/browser-child.js +++ b/toolkit/content/browser-child.js @@ -551,6 +551,12 @@ let AutoCompletePopup = { }, openAutocompletePopup: function (input, element) { + if (!this._popupOpen) { + // The search itself normally opens the popup itself, but in some cases, + // nsAutoCompleteController tries to use cached results so notify our + // popup to reuse the last results. + sendAsyncMessage("FormAutoComplete:MaybeOpenPopup", {}); + } this._input = input; this._popupOpen = true; },