Bug 1559363 - Open-view-on-focus mode should only apply when the user explicitly focuses the address bar, not on autofocus. r=adw
authorDão Gottwald <dao@mozilla.com>
Wed, 19 Jun 2019 01:18:06 +0000
changeset 479197 b3c2e1416e88d0a364e789a8a83b222c969d62c4
parent 479196 a026827c657665ade9e7ffc6e03591093e49bbe4
child 479198 cdb8199134d6c4dd535cca3bbc03a604065f21f0
push id36173
push userrgurzau@mozilla.com
push dateWed, 19 Jun 2019 15:50:11 +0000
treeherdermozilla-central@10e3ed789e2b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1559363
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1559363 - Open-view-on-focus mode should only apply when the user explicitly focuses the address bar, not on autofocus. r=adw Differential Revision: https://phabricator.services.mozilla.com/D35280
browser/base/content/browser.js
browser/base/content/tabbrowser.js
browser/components/urlbar/UrlbarInput.jsm
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2423,16 +2423,19 @@ function focusAndSelectUrlBar(userInitia
   gURLBar.userInitiatedFocus = userInitiatedFocus;
   gURLBar.select();
   gURLBar.userInitiatedFocus = false;
 }
 
 function openLocation() {
   if (window.location.href == AppConstants.BROWSER_CHROME_URL) {
     focusAndSelectUrlBar(true);
+    if (gURLBar.openViewOnFocus && !gURLBar.view.isOpen) {
+      gURLBar.startQuery();
+    }
     return;
   }
 
   // If there's an open browser window, redirect the command there.
   let win = getTopWin();
   if (win) {
     win.focus();
     win.openLocation();
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -1172,19 +1172,17 @@ window._gBrowser = {
       }
     }
 
     // Focus the location bar if it was previously focused for that tab.
     // In full screen mode, only bother making the location bar visible
     // if the tab is a blank one.
     if (newBrowser._urlbarFocused && gURLBar) {
       // Explicitly close the popup if the URL bar retains focus
-      if (!gURLBar.openViewOnFocus) {
-        gURLBar.closePopup();
-      }
+      gURLBar.closePopup();
 
       // If the user happened to type into the URL bar for this browser
       // by the time we got here, focusing will cause the text to be
       // selected which could cause them to overwrite what they've
       // already typed in.
       if (gURLBar.focused && newBrowser.userTypedValue) {
         return;
       }
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -151,25 +151,35 @@ class UrlbarInput {
 
     // The event bufferer can be used to defer events that may affect users
     // muscle memory; for example quickly pressing DOWN+ENTER should end up
     // on a predictable result, regardless of the search status. The event
     // bufferer will invoke the handling code at the right time.
     this.eventBufferer = new UrlbarEventBufferer(this);
 
     this._inputFieldEvents = [
-      "blur", "focus", "input", "keydown", "keyup", "mouseover", "paste",
-      "scrollend", "select", "overflow", "underflow", "dragstart", "dragover",
-      "drop", "compositionstart", "compositionend",
+      "compositionstart", "compositionend",
+      "dragover", "dragstart", "drop",
+      "focus", "blur",
+      "input",
+      "keydown", "keyup",
+      "mousedown", "mouseover",
+      "overflow", "underflow",
+      "paste",
+      "scrollend",
+      "select",
     ];
     for (let name of this._inputFieldEvents) {
       this.inputField.addEventListener(name, this);
     }
 
+    // This is needed for the dropmarker. Once we remove that (i.e. make
+    // openViewOnFocus = true the default), this won't be needed anymore.
     this.addEventListener("mousedown", this);
+
     this.view.panel.addEventListener("popupshowing", this);
     this.view.panel.addEventListener("popuphidden", this);
 
     this._copyCutController = new CopyCutController(this);
     this.inputField.controllers.insertControllerAt(0, this._copyCutController);
 
     this._initPasteAndGo();
 
@@ -1285,40 +1295,40 @@ class UrlbarInput {
   _on_focus(event) {
     this._updateUrlTooltip();
     this.formatValue();
 
     // Hide popup notifications, to reduce visual noise.
     if (this.getAttribute("pageproxystate") != "valid") {
       this.window.UpdatePopupNotificationsVisibility();
     }
-
-    if (this.openViewOnFocus) {
-      this.startQuery();
-    }
   }
 
   _on_mouseover(event) {
     this._updateUrlTooltip();
   }
 
   _on_mousedown(event) {
-    if ((event.target == this.inputField ||
-         // Can be removed after bug 1513337:
-         event.originalTarget.classList.contains("anonymous-div")) &&
-        event.button == 0 &&
-        event.detail == 2 &&
-        UrlbarPrefs.get("doubleClickSelectsAll")) {
-      this.editor.selectAll();
-      event.preventDefault();
+    // We only care about left clicks here.
+    if (event.button != 0) {
       return;
     }
 
-    if (event.originalTarget.classList.contains("urlbar-history-dropmarker") &&
-        event.button == 0) {
+    if (event.currentTarget == this.inputField) {
+      if (event.detail == 2 &&
+          UrlbarPrefs.get("doubleClickSelectsAll")) {
+        this.editor.selectAll();
+        event.preventDefault();
+      } else if (this.openViewOnFocus && !this.view.isOpen) {
+        this.startQuery();
+      }
+      return;
+    }
+
+    if (event.originalTarget.classList.contains("urlbar-history-dropmarker")) {
       if (this.view.isOpen) {
         this.view.close();
       } else {
         this.startQuery();
       }
     }
   }
 
@@ -1455,19 +1465,16 @@ class UrlbarInput {
 
   _on_scrollend(event) {
     this._updateTextOverflow();
   }
 
   _on_TabSelect(event) {
     this._resetSearchState();
     this.controller.viewContextChanged();
-    if (this.focused && this.openViewOnFocus) {
-      this.startQuery();
-    }
   }
 
   _on_keydown(event) {
     // Due to event deferring, it's possible preventDefault() won't be invoked
     // soon enough to actually prevent some of the default behaviors, thus we
     // have to handle the event "twice". This first immediate call passes false
     // as second argument so that handleKeyNavigation will only simulate the
     // event handling, without actually executing actions.