Bug 1381659 - Send a message from ContentSearch.jsm to blur the suggestions UI after a search instead of a beforeunload listener. r=florian draft
authorNihanth Subramanya <nhnt11@gmail.com>
Wed, 19 Jul 2017 02:37:40 +0530
changeset 610868 482c3b3bc51110f4571feb88ebd5cc877b4e0150
parent 610234 5e73b9798464c3f7106f0161dc9a49b234f42f9c
child 637975 7f0ad49eeefec0b66b7f4f9d1341bfbef2f2f7ff
push id69020
push usernhnt11@gmail.com
push dateTue, 18 Jul 2017 21:08:38 +0000
reviewersflorian
bugs1381659
milestone56.0a1
Bug 1381659 - Send a message from ContentSearch.jsm to blur the suggestions UI after a search instead of a beforeunload listener. r=florian MozReview-Commit-ID: HqTICEtuInW
browser/base/content/contentSearchUI.js
browser/modules/ContentSearch.jsm
--- a/browser/base/content/contentSearchUI.js
+++ b/browser/base/content/contentSearchUI.js
@@ -509,16 +509,21 @@ ContentSearchUIController.prototype = {
       this[methodName](event.detail.data);
     }
   },
 
   _onMsgFocusInput(event) {
     this.input.focus();
   },
 
+  _onMsgBlur(event) {
+    this.input.blur();
+    this._hideSuggestions();
+  },
+
   _onMsgSuggestions(suggestions) {
     // Ignore the suggestions if their search string or engine doesn't match
     // ours.  Due to the async nature of message passing, this can easily happen
     // when the user types quickly.
     if (this._stickyInputValue != suggestions.searchString ||
         this.defaultEngine.name != suggestions.engineName) {
       return;
     }
@@ -743,21 +748,16 @@ ContentSearchUIController.prototype = {
     // back to it if the blur was because the user clicked somewhere in the table.
     // onBlur uses the _mousedown flag to detect this.
     this._table.addEventListener("mousedown", () => { this._mousedown = true; });
     document.addEventListener("mouseup", () => { delete this._mousedown; });
 
     // Deselect the selected element on mouseout if it wasn't a suggestion.
     this._table.addEventListener("mouseout", this);
 
-    // If a search is loaded in the same tab, ensure the suggestions dropdown
-    // is hidden immediately when the page starts loading and not when it first
-    // appears, in order to provide timely feedback to the user.
-    window.addEventListener("beforeunload", () => { this._hideSuggestions(); });
-
     let headerRow = document.createElementNS(HTML_NS, "tr");
     let header = document.createElementNS(HTML_NS, "td");
     headerRow.setAttribute("class", "contentSearchHeaderRow");
     header.setAttribute("class", "contentSearchHeader");
     let iconImg = document.createElementNS(HTML_NS, "img");
     header.appendChild(iconImg);
     header.id = "contentSearchDefaultEngineHeader";
     headerRow.appendChild(header);
--- a/browser/modules/ContentSearch.jsm
+++ b/browser/modules/ContentSearch.jsm
@@ -231,16 +231,19 @@ this.ContentSearch = {
     let where = win.whereToOpenLink(data.originalEvent);
 
     // There is a chance that by the time we receive the search message, the user
     // has switched away from the tab that triggered the search. If, based on the
     // event, we need to load the search in the same tab that triggered it (i.e.
     // where === "current"), openUILinkIn will not work because that tab is no
     // longer the current one. For this case we manually load the URI.
     if (where === "current") {
+      // Since we're going to load the search in the same browser, blur the search
+      // UI to prevent further interaction before we start loading.
+      this._reply(msg, "Blur");
       browser.loadURIWithFlags(submission.uri.spec,
                                Ci.nsIWebNavigation.LOAD_FLAGS_NONE, null, null,
                                submission.postData);
     } else {
       let params = {
         postData: submission.postData,
         inBackground: Services.prefs.getBoolPref("browser.tabs.loadInBackground"),
       };