Bug 1520317 - If the preselected flag on the query context is set, then select the first result when results are added. r=dao
authorDrew Willcoxon <adw@mozilla.com>
Thu, 17 Jan 2019 17:13:51 +0000
changeset 514285 cc0ec99ff8b8e36e50f31c257ea9463354c71e83
parent 514284 c0db84bf3f57f80a4911b83ab6c13525786ad69e
child 514286 a9a828f85c918316db6f21cecff15d5f20275296
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1520317
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 1520317 - If the preselected flag on the query context is set, then select the first result when results are added. r=dao There's a `context.preselected` flag, so the view should probably respect that. Currently, `UrlbarProviderUnifiedComplete` sets the flag when it adds results. One other thing to note is that right now, when the popup opens, the view effectively assumes that `context.preselected` is true, and it selects the first result. But the selection doesn't actually appear because right after that, the query results are added, so the popup is cleared, and the selection isn't set again. Differential Revision: https://phabricator.services.mozilla.com/D16602
browser/components/urlbar/UrlbarView.jsm
--- a/browser/components/urlbar/UrlbarView.jsm
+++ b/browser/components/urlbar/UrlbarView.jsm
@@ -125,16 +125,22 @@ class UrlbarView {
   onQueryResults(queryContext) {
     // XXX For now, clear the results for each set received. We should really
     // be updating the existing list.
     this._rows.textContent = "";
     this._queryContext = queryContext;
     for (let resultIndex in queryContext.results) {
       this._addRow(resultIndex);
     }
+
+    if (queryContext.preselected) {
+      this._selected = this._rows.firstElementChild;
+      this._selected.toggleAttribute("selected", true);
+    }
+
     this._openPanel();
   }
 
   /**
    * Handles removing a result from the view when it is removed from the query,
    * and attempts to select the new result on the same row.
    *
    * This assumes that the result rows are in index order.
@@ -187,19 +193,16 @@ class UrlbarView {
 
     this._alignPanel();
 
     // TODO: Search one off buttons are a stub right now.
     //       We'll need to set them up properly.
     this.oneOffSearchButtons;
 
     this.panel.openPopup(this.input.textbox.closest("toolbar"), "after_end", 0, -1);
-
-    this._selected = this._rows.firstElementChild;
-    this._selected.toggleAttribute("selected", true);
   }
 
   _alignPanel() {
     // Make the panel span the width of the window.
     let documentRect =
       this._getBoundsWithoutFlushing(this.document.documentElement);
     let width = documentRect.right - documentRect.left;
     this.panel.setAttribute("width", width);