Bug 1515044 - Port "hidden focus" code to UrlbarInput.jsm r=adw
authorRicky Rosario <rickyrosario@gmail.com>
Wed, 23 Jan 2019 16:28:04 +0000
changeset 455110 0e5aa503740c61f3d8ac2660428f01760bae199c
parent 455109 46b19ac773fa06edea4e04f9ee945852c0d9e867
child 455111 647e4cfc0eb44fb8abe57a2a4fa36c91edf3030a
push id35421
push useraciure@mozilla.com
push dateThu, 24 Jan 2019 03:42:51 +0000
treeherdermozilla-central@9aae2b5ef219 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1515044
milestone66.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 1515044 - Port "hidden focus" code to UrlbarInput.jsm r=adw MozReview-Commit-ID: GgYo2r9s5g4 Differential Revision: https://phabricator.services.mozilla.com/D17164
browser/base/content/urlbarBindings.xml
browser/components/about/AboutPrivateBrowsingHandler.jsm
browser/components/urlbar/UrlbarInput.jsm
browser/components/urlbar/tests/browser/browser.ini
browser/components/urlbar/tests/browser/browser_UrlbarInput_hiddenFocus.js
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -1709,17 +1709,17 @@ file, You can obtain one at http://mozil
       </method>
 
       <method name="removeHiddenFocus">
         <body><![CDATA[
           this.classList.remove("hidden-focus");
         ]]></body>
       </method>
 
-      <method name="hiddenFocus">
+      <method name="setHiddenFocus">
         <body><![CDATA[
           this.classList.add("hidden-focus");
           this.focus();
         ]]></body>
       </method>
     </implementation>
 
     <handlers>
--- a/browser/components/about/AboutPrivateBrowsingHandler.jsm
+++ b/browser/components/about/AboutPrivateBrowsingHandler.jsm
@@ -47,17 +47,17 @@ var AboutPrivateBrowsingHandler = {
         let searchAliases = Services.search.defaultEngine.wrappedJSObject.__internalAliases;
         if (searchAliases && searchAliases.length > 0) {
           searchAlias = `${searchAliases[0]} `;
         }
         let urlBar = aMessage.target.browser.ownerGlobal.gURLBar;
         let isFirstChange = true;
 
         if (!aMessage.data || !aMessage.data.text) {
-          urlBar.hiddenFocus();
+          urlBar.setHiddenFocus();
         } else {
           // Pass the provided text to the awesomebar. Prepend the @engine shortcut.
           urlBar.search(`${searchAlias}${aMessage.data.text}`);
           isFirstChange = false;
         }
 
         let checkFirstChange = () => {
           // Check if this is the first change since we hidden focused. If it is,
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -406,16 +406,33 @@ class UrlbarInput {
 
     this.inputField.value = char + " ";
 
     let event = this.document.createEvent("UIEvents");
     event.initUIEvent("input", true, false, this.window, 0);
     this.inputField.dispatchEvent(event);
   }
 
+  /**
+   * Focus without the focus styles.
+   * This is used by Activity Stream and about:privatebrowsing for search hand-off.
+   */
+  setHiddenFocus() {
+    this.textbox.classList.add("hidden-focus");
+    this.focus();
+  }
+
+  /**
+   * Remove the hidden focus styles.
+   * This is used by Activity Stream and about:privatebrowsing for search hand-off.
+   */
+  removeHiddenFocus() {
+    this.textbox.classList.remove("hidden-focus");
+  }
+
   // Getters and Setters below.
 
   get focused() {
     return this.textbox.getAttribute("focused") == "true";
   }
 
   get goButton() {
     return this.document.getAnonymousElementByAttribute(this.textbox, "anonid",
--- a/browser/components/urlbar/tests/browser/browser.ini
+++ b/browser/components/urlbar/tests/browser/browser.ini
@@ -51,16 +51,17 @@ run-if = e10s
 [browser_urlbarCopying.js]
 subsuite = clipboard
 support-files =
   authenticate.sjs
 [browser_urlbarEnter.js]
 [browser_urlbarFocusedCmdK.js]
 [browser_urlbarHashChangeProxyState.js]
 [browser_UrlbarInput_formatValue.js]
+[browser_UrlbarInput_hiddenFocus.js]
 [browser_UrlbarInput_overflow.js]
 [browser_UrlbarInput_tooltip.js]
 [browser_UrlbarInput_trimURLs.js]
 subsuite = clipboard
 [browser_UrlbarInput_unit.js]
 support-files = empty.xul
 [browser_UrlbarLoadRace.js]
 [browser_urlbarPlaceholder.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/urlbar/tests/browser/browser_UrlbarInput_hiddenFocus.js
@@ -0,0 +1,21 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+add_task(async function() {
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+
+  registerCleanupFunction(async function() {
+    BrowserTestUtils.removeTab(tab);
+    URLBarSetURI();
+  });
+
+  gURLBar.blur();
+  ok(!gURLBar.hasAttribute("focused") && !gURLBar.textbox.classList.contains("hidden-focus"),
+     "url bar is not focused or hidden");
+  gURLBar.setHiddenFocus();
+  ok(gURLBar.hasAttribute("focused") && gURLBar.textbox.classList.contains("hidden-focus"),
+    "url bar is focused and hidden");
+  gURLBar.removeHiddenFocus();
+  ok(gURLBar.hasAttribute("focused") && !gURLBar.textbox.classList.contains("hidden-focus"),
+    "url bar is focused and not hidden");
+});