Bug 1527946 - QuantumBar: Update the input value when cycling through results until no result is selected. r=Standard8
authorDão Gottwald <dao@mozilla.com>
Sat, 09 Mar 2019 12:15:26 +0000
changeset 521253 34a3d6b4f10f37b10428063096cad6af7c023e1a
parent 521252 ed23415c6ea00edd214b5281e89b5ffa5876d18a
child 521261 30385b68bea1a7f52c109b28a67f0ea611d88534
child 521262 070e1065af52d1a8ea91a7939a4c6e9263228156
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1527946
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 1527946 - QuantumBar: Update the input value when cycling through results until no result is selected. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D22551
browser/components/urlbar/UrlbarInput.jsm
browser/components/urlbar/UrlbarView.jsm
browser/components/urlbar/tests/browser/browser_urlbarOneOffs.js
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -437,50 +437,60 @@ class UrlbarInput {
 
     if (!url) {
       throw new Error(`Invalid url for result ${JSON.stringify(result)}`);
     }
     this._loadURL(url, where, openParams);
   }
 
   /**
-   * Called by the view when moving through results with the keyboard.
+   * Called by the view when moving through results with the keyboard, and when
+   * picking a result.
    *
-   * @param {UrlbarResult} result The result that was selected.
+   * @param {UrlbarResult} [result]
+   *   The result that was selected or picked, null if no result was selected.
    * @param {Event} [event] The event that picked the result.
    * @returns {boolean}
    *   Whether the value has been canonized
    */
-  setValueFromResult(result, event = null) {
-    // For autofilled results, the value that should be canonized is not the
-    // autofilled value but the value that the user typed.
-    let canonizedUrl = this._maybeCanonizeURL(event, result.autofill ?
-                         this._lastSearchString : this.textValue);
-    if (canonizedUrl) {
-      this.value = canonizedUrl;
+  setValueFromResult(result = null, event = null) {
+    let canonizedUrl;
+
+    if (!result) {
+      this.value = this._lastSearchString;
     } else {
-      this.value = this._getValueFromResult(result);
-      if (result.autofill) {
-        this.selectionStart = result.autofill.selectionStart;
-        this.selectionEnd = result.autofill.selectionEnd;
+      // For autofilled results, the value that should be canonized is not the
+      // autofilled value but the value that the user typed.
+      canonizedUrl = this._maybeCanonizeURL(event, result.autofill ?
+                       this._lastSearchString : this.textValue);
+      if (canonizedUrl) {
+        this.value = canonizedUrl;
+      } else {
+        this.value = this._getValueFromResult(result);
+        if (result.autofill) {
+          this.selectionStart = result.autofill.selectionStart;
+          this.selectionEnd = result.autofill.selectionEnd;
+        }
       }
     }
     this._resultForCurrentValue = result;
 
     // Also update userTypedValue. See bug 287996.
     this.window.gBrowser.userTypedValue = this.value;
 
     // The value setter clobbers the actiontype attribute, so update this after that.
-    switch (result.type) {
-      case UrlbarUtils.RESULT_TYPE.TAB_SWITCH:
-        this.setAttribute("actiontype", "switchtab");
-        break;
-      case UrlbarUtils.RESULT_TYPE.OMNIBOX:
-        this.setAttribute("actiontype", "extension");
-        break;
+    if (result) {
+      switch (result.type) {
+        case UrlbarUtils.RESULT_TYPE.TAB_SWITCH:
+          this.setAttribute("actiontype", "switchtab");
+          break;
+        case UrlbarUtils.RESULT_TYPE.OMNIBOX:
+          this.setAttribute("actiontype", "extension");
+          break;
+      }
     }
 
     return !!canonizedUrl;
   }
 
   /**
    * Starts a query based on the user input.
    *
--- a/browser/components/urlbar/UrlbarView.jsm
+++ b/browser/components/urlbar/UrlbarView.jsm
@@ -491,34 +491,32 @@ class UrlbarView {
 
     return item;
   }
 
   _selectItem(item, updateInput = true) {
     if (this._selected) {
       this._selected.toggleAttribute("selected", false);
       this._selected.toggleAttribute("aria-selected", false);
-      this._selected = null;
-    }
-
-    if (!item) {
-      this._rows.removeAttribute("aria-activedescendant");
-      return;
     }
     this._selected = item;
-    item.toggleAttribute("selected", true);
-    item.toggleAttribute("aria-selected", true);
-    this._rows.setAttribute("aria-activedescendant", item.id);
+    if (item) {
+      item.toggleAttribute("selected", true);
+      item.toggleAttribute("aria-selected", true);
+      this._rows.setAttribute("aria-activedescendant", item.id);
+    } else {
+      this._rows.removeAttribute("aria-activedescendant");
+    }
 
-    if (!updateInput) {
-      return;
-    }
-    let resultIndex = item.getAttribute("resultIndex");
-    let result = this._queryContext.results[resultIndex];
-    if (result) {
+    if (updateInput) {
+      let result = null;
+      if (item) {
+        let resultIndex = item.getAttribute("resultIndex");
+        result = this._queryContext.results[resultIndex];
+      }
       this.input.setValueFromResult(result);
     }
   }
 
   /**
    * Adds text content to a node, placing substrings that should be highlighted
    * inside <em> nodes.
    *
--- a/browser/components/urlbar/tests/browser/browser_urlbarOneOffs.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarOneOffs.js
@@ -276,20 +276,16 @@ add_task(async function hiddenWhenUsingS
 });
 
 
 function assertState(result, oneOff, textValue = undefined) {
   Assert.equal(UrlbarTestUtils.getSelectedIndex(window), result,
     "Expected result should be selected");
   Assert.equal(oneOffSearchButtons.selectedButtonIndex,
     oneOff, "Expected one-off should be selected");
-  // TODO Bug 1527946: Fix textValue differences for QuantumBar
-  if (UrlbarPrefs.get("quantumbar")) {
-    return;
-  }
   if (textValue !== undefined) {
     Assert.equal(gURLBar.textValue, textValue, "Expected textValue");
   }
 }
 
 function hidePopup() {
   return UrlbarTestUtils.promisePopupClose(window, () => {
     EventUtils.synthesizeKey("KEY_Escape");