Bug 1522522 - Show "Switch to tab:" and "Extension:" labels in the qunatumbar input. r=Standard8
authorDão Gottwald <dao@mozilla.com>
Tue, 29 Jan 2019 14:58:43 +0000
changeset 455967 a1ff781d6669b5732a595cb878bf4434e6758b3d
parent 455966 d085f7afb20a6718b42e4735c269a1b81f2c0065
child 455968 9a8a9e60b2676ad6464d75d1627a2499e0092fd3
push id35465
push usershindli@mozilla.com
push dateWed, 30 Jan 2019 04:10:12 +0000
treeherdermozilla-central@9e919be867b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1522522
milestone67.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 1522522 - Show "Switch to tab:" and "Extension:" labels in the qunatumbar input. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D17919
browser/base/content/browser.css
browser/components/urlbar/UrlbarInput.jsm
--- a/browser/base/content/browser.css
+++ b/browser/base/content/browser.css
@@ -692,16 +692,17 @@ html|input.urlbar-input {
 }
 #PopupAutoCompleteRichResult[noactions] > richlistbox > richlistitem.overridable-action > .ac-action {
   display: none;
 }
 #PopupAutoCompleteRichResult[noactions] > richlistbox > richlistitem.overridable-action > .ac-type-icon {
   list-style-image: none;
 }
 
+#urlbar[noactions] > #urlbar-display-box,
 #urlbar:not([actiontype="switchtab"]):not([actiontype="extension"]) > #urlbar-display-box,
 #urlbar:not([actiontype="switchtab"]) > #urlbar-display-box > #switchtab,
 #urlbar:not([actiontype="extension"]) > #urlbar-display-box > #extension {
   display: none;
 }
 
 #PopupAutoComplete[firstresultstyle="insecureWarning"] {
   min-width: 200px;
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -105,16 +105,17 @@ class UrlbarInput {
     this.inputField.addEventListener("focus", this);
     this.inputField.addEventListener("input", this);
     this.inputField.addEventListener("mouseover", this);
     this.inputField.addEventListener("overflow", this);
     this.inputField.addEventListener("underflow", this);
     this.inputField.addEventListener("scrollend", this);
     this.inputField.addEventListener("select", this);
     this.inputField.addEventListener("keydown", this);
+    this.inputField.addEventListener("keyup", this);
     this.view.panel.addEventListener("popupshowing", this);
     this.view.panel.addEventListener("popuphidden", this);
 
     this.inputField.controllers.insertControllerAt(0, new CopyCutController(this));
     this._initPasteAndGo();
   }
 
   /**
@@ -306,17 +307,17 @@ class UrlbarInput {
       allowInheritPrincipal: false,
     };
 
     // TODO bug 1521702: Call _maybeCanonizeURL for autofilled results with the
     // typed string (not the autofilled one).
 
     switch (result.type) {
       case UrlbarUtils.RESULT_TYPE.TAB_SWITCH: {
-        if (this._overrideDefaultAction(event)) {
+        if (this.hasAttribute("noactions")) {
           where = "current";
           break;
         }
 
         this.handleRevert();
         let prevTab = this.window.gBrowser.selectedTab;
         let loadOpts = {
           adoptIntoActiveWindow: UrlbarPrefs.get("switchTabs.adoptIntoActiveWindow"),
@@ -380,16 +381,25 @@ class UrlbarInput {
         } catch (ex) {}
         if (uri) {
           val = this.window.losslessDecodeURI(uri);
         }
         break;
       }
     }
     this.value = val;
+
+    switch (result.type) {
+      case UrlbarUtils.RESULT_TYPE.TAB_SWITCH:
+        this.setAttribute("actiontype", "switchtab");
+        break;
+      case UrlbarUtils.RESULT_TYPE.OMNIBOX:
+        this.setAttribute("actiontype", "extension");
+        break;
+    }
   }
 
   /**
    * Starts a query based on the user input.
    *
    * @param {number} [options.lastKey]
    *   The last key the user entered (as a key code).
    */
@@ -500,16 +510,17 @@ class UrlbarInput {
       val = originalUrl.displaySpec;
     }
 
     val = this.trimValue(val);
 
     this.valueIsTyped = false;
     this.inputField.value = val;
     this.formatValue();
+    this.removeAttribute("actiontype");
 
     // Dispatch ValueChange event for accessibility.
     let event = this.document.createEvent("Events");
     event.initEvent("ValueChange", true, true);
     this.inputField.dispatchEvent(event);
 
     return val;
   }
@@ -611,24 +622,30 @@ class UrlbarInput {
       // the beginning or end (or both).
       let trimmedSegments = spec.split(trimmedSpec);
       selectedVal = trimmedSegments[0] + selectedVal;
     }
 
     return selectedVal;
   }
 
-  _overrideDefaultAction(event) {
-    return event.shiftKey ||
-           event.altKey ||
-           (AppConstants.platform == "macosx" ?
-              event.metaKey : event.ctrlKey);
+  _toggleNoActions(event) {
+    if (event.keyCode == KeyEvent.DOM_VK_SHIFT ||
+        event.keyCode == KeyEvent.DOM_VK_ALT ||
+        event.keyCode == (AppConstants.platform == "macosx" ?
+                            KeyEvent.DOM_VK_META :
+                            KeyEvent.DOM_VK_CONTROL)) {
+      if (event.type == "keydown") {
+        this.setAttribute("noactions", "true");
+      } else {
+        this.removeAttribute("noactions");
+      }
+    }
   }
 
-
   /**
    * Get the url to load for the search query and records in telemetry that it
    * is being loaded.
    *
    * @param {nsISearchEngine} engine
    *   The engine to generate the query for.
    * @param {Event} event
    *   The event that triggered this query.
@@ -897,16 +914,17 @@ class UrlbarInput {
     this._untrimmedValue = value;
     this.window.gBrowser.userTypedValue = value;
 
     if (value) {
       this.setAttribute("usertyping", "true");
     } else {
       this.removeAttribute("usertyping");
     }
+    this.removeAttribute("actiontype");
 
     // XXX Fill in lastKey, and add anything else we need.
     this.startQuery({
       lastKey: null,
     });
   }
 
   _on_select(event) {
@@ -958,16 +976,21 @@ class UrlbarInput {
   }
 
   _on_TabSelect(event) {
     this.controller.tabContextChanged();
   }
 
   _on_keydown(event) {
     this.controller.handleKeyNavigation(event);
+    this._toggleNoActions(event);
+  }
+
+  _on_keyup(event) {
+    this._toggleNoActions(event);
   }
 
   _on_popupshowing() {
     this.setAttribute("open", "true");
   }
 
   _on_popuphidden() {
     this.removeAttribute("open");