Bug 1432716 - Group the "Show search suggestions ahead of browsing history in address bar results" checkbox with other search suggestion checkboxes. ui=shorlander r=adw a=lizzard
authorDão Gottwald <dao@mozilla.com>
Fri, 09 Feb 2018 10:44:28 +0100
changeset 454816 152720a4efe7421404020e2728a05bf5af543919
parent 454815 ab285921713c97914561c3834dc4c1a6c31383cf
child 454817 70cc9d6d659f726d328bfd6b529b28adccd62b5e
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, lizzard
bugs1432716
milestone59.0
Bug 1432716 - Group the "Show search suggestions ahead of browsing history in address bar results" checkbox with other search suggestion checkboxes. ui=shorlander r=adw a=lizzard MozReview-Commit-ID: CSuNpA0Yq0w
browser/components/preferences/in-content/search.js
browser/components/preferences/in-content/search.xul
browser/components/preferences/in-content/tests/browser_searchShowSuggestionsFirst.js
browser/themes/shared/incontentprefs/search.css
--- a/browser/components/preferences/in-content/search.js
+++ b/browser/components/preferences/in-content/search.js
@@ -54,73 +54,86 @@ var gSearchPane = {
     Services.obs.addObserver(this, "browser-search-engine-modified");
     window.addEventListener("unload", () => {
       Services.obs.removeObserver(this, "browser-search-engine-modified");
     });
 
     this._initAutocomplete();
 
     let suggestsPref = Preferences.get("browser.search.suggest.enabled");
-    suggestsPref.on("change", this.updateSuggestsCheckbox.bind(this));
-    this.updateSuggestsCheckbox();
-
+    let urlbarSuggestsPref = Preferences.get("browser.urlbar.suggest.searches");
+    let updateSuggestionCheckboxes = this._updateSuggestionCheckboxes.bind(this);
+    suggestsPref.on("change", updateSuggestionCheckboxes);
+    urlbarSuggestsPref.on("change", updateSuggestionCheckboxes);
     this._initShowSearchSuggestionsFirst();
+    this._updateSuggestionCheckboxes();
   },
 
   _initShowSearchSuggestionsFirst() {
-    let pref = Preferences.get("browser.urlbar.matchBuckets");
+    this._urlbarSuggestionsPosPref = Preferences.get("browser.urlbar.matchBuckets");
     let checkbox =
       document.getElementById("showSearchSuggestionsFirstCheckbox");
 
-    pref.on("change", () => {
-      this._syncFromShowSearchSuggestionsFirstPref(checkbox, pref);
+    this._urlbarSuggestionsPosPref.on("change", () => {
+      this._syncFromShowSearchSuggestionsFirstPref(checkbox);
     });
-    this._syncFromShowSearchSuggestionsFirstPref(checkbox, pref);
+    this._syncFromShowSearchSuggestionsFirstPref(checkbox);
 
     checkbox.addEventListener("command", () => {
-      this._syncToShowSearchSuggestionsFirstPref(checkbox.checked, pref);
+      this._syncToShowSearchSuggestionsFirstPref(checkbox.checked);
     });
   },
 
-  _syncFromShowSearchSuggestionsFirstPref(checkbox, pref) {
-    if (!pref.value) {
+  _syncFromShowSearchSuggestionsFirstPref(checkbox) {
+    if (!this._urlbarSuggestionsPosPref.value) {
       // The pref is cleared, meaning search suggestions are shown first.
       checkbox.checked = true;
       return;
     }
     // The pref has a value.  If the first bucket in the pref is search
     // suggestions, then check the checkbox.
-    let buckets = PlacesUtils.convertMatchBucketsStringToArray(pref.value);
+    let buckets = PlacesUtils.convertMatchBucketsStringToArray(this._urlbarSuggestionsPosPref.value);
     checkbox.checked = buckets[0] && buckets[0][0] == "suggestion";
   },
 
-  _syncToShowSearchSuggestionsFirstPref(checked, pref) {
+  _syncToShowSearchSuggestionsFirstPref(checked) {
     if (checked) {
       // Show search suggestions first, so clear the pref since that's the
       // default.
-      pref.reset();
+      this._urlbarSuggestionsPosPref.reset();
       return;
     }
     // Show history first.
-    pref.value = "general:5,suggestion:Infinity";
+    this._urlbarSuggestionsPosPref.value = "general:5,suggestion:Infinity";
   },
 
-  updateSuggestsCheckbox() {
+  _updateSuggestionCheckboxes() {
     let suggestsPref = Preferences.get("browser.search.suggest.enabled");
     let permanentPB =
       Services.prefs.getBoolPref("browser.privatebrowsing.autostart");
     let urlbarSuggests = document.getElementById("urlBarSuggestion");
+    let positionCheckbox =
+      document.getElementById("showSearchSuggestionsFirstCheckbox");
+
     urlbarSuggests.disabled = !suggestsPref.value || permanentPB;
 
     let urlbarSuggestsPref = Preferences.get("browser.urlbar.suggest.searches");
     urlbarSuggests.checked = urlbarSuggestsPref.value;
     if (urlbarSuggests.disabled) {
       urlbarSuggests.checked = false;
     }
 
+    if (urlbarSuggests.checked) {
+      positionCheckbox.disabled = false;
+      this._syncFromShowSearchSuggestionsFirstPref(positionCheckbox);
+    } else {
+      positionCheckbox.disabled = true;
+      positionCheckbox.checked = false;
+    }
+
     let permanentPBLabel =
       document.getElementById("urlBarSuggestionPermanentPBLabel");
     permanentPBLabel.hidden = urlbarSuggests.hidden || !permanentPB;
   },
 
   buildDefaultEngineDropDown() {
     // This is called each time something affects the list of engines.
     let list = document.getElementById("defaultEngine");
--- a/browser/components/preferences/in-content/search.xul
+++ b/browser/components/preferences/in-content/search.xul
@@ -13,18 +13,16 @@
     <groupbox id="searchbarGroup" data-category="paneSearch">
       <caption><label id="searchbarLabel">&searchBar.label;</label></caption>
       <radiogroup id="searchBarVisibleGroup" aria-labelledby="searchbarLabel" preference="browser.search.widget.inNavBar">
         <radio id="searchBarHiddenRadio" value="false" label="&searchBar.hidden.label;"/>
         <image class="searchBarImage searchBarHiddenImage" role="presentation"/>
         <radio id="searchBarShownRadio" value="true" label="&searchBar.shown.label;"/>
         <image class="searchBarImage searchBarShownImage" role="presentation"/>
       </radiogroup>
-      <checkbox id="showSearchSuggestionsFirstCheckbox"
-                label="&showSearchSuggestionsAboveHistory.label;"/>
     </groupbox>
 
     <!-- Default Search Engine -->
     <groupbox id="defaultEngineGroup" data-category="paneSearch">
       <caption><label>&defaultSearchEngine.label;</label></caption>
       <description>&chooseYourDefaultSearchEngine2.label;</description>
 
       <hbox id="browserDefaultSearchExtensionContent" align="center" hidden="true">
@@ -43,16 +41,18 @@
       <checkbox id="suggestionsInSearchFieldsCheckbox"
                 label="&provideSearchSuggestions.label;"
                 accesskey="&provideSearchSuggestions.accesskey;"
                 preference="browser.search.suggest.enabled"/>
       <vbox class="indent">
         <checkbox id="urlBarSuggestion" label="&showURLBarSuggestions2.label;"
                   accesskey="&showURLBarSuggestions2.accesskey;"
                   preference="browser.urlbar.suggest.searches"/>
+        <checkbox id="showSearchSuggestionsFirstCheckbox"
+                  label="&showSearchSuggestionsAboveHistory.label;"/>
         <hbox id="urlBarSuggestionPermanentPBLabel"
               align="center" class="indent">
           <label flex="1">&urlBarSuggestionsPermanentPB.label;</label>
         </hbox>
       </vbox>
     </groupbox>
 
     <groupbox id="oneClickSearchProvidersGroup" data-category="paneSearch">
--- a/browser/components/preferences/in-content/tests/browser_searchShowSuggestionsFirst.js
+++ b/browser/components/preferences/in-content/tests/browser_searchShowSuggestionsFirst.js
@@ -2,16 +2,18 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const PREF_NAME = "browser.urlbar.matchBuckets";
 const HISTORY_FIRST_PREF_VALUE = "general:5,suggestion:Infinity";
 const CHECKBOX_ID = "showSearchSuggestionsFirstCheckbox";
 
 // Open preferences with search suggestions shown first (the default).
 add_task(async function openWithSearchSuggestionsShownFirst() {
+  await SpecialPowers.pushPrefEnv({set: [["browser.urlbar.suggest.searches", true]]});
+
   // The pref should be cleared initially so that search suggestions are shown
   // first (the default).
   Assert.equal(Services.prefs.getCharPref(PREF_NAME, ""), "",
                "Pref should be cleared initially");
 
   // Open preferences.  The checkbox should be checked.
   await openPreferencesViaOpenPreferencesAPI("search", { leaveOpen: true });
   let doc = gBrowser.selectedBrowser.contentDocument;
--- a/browser/themes/shared/incontentprefs/search.css
+++ b/browser/themes/shared/incontentprefs/search.css
@@ -7,19 +7,18 @@
   width: 631px;
   margin-left: 33px;
 }
 
 .searchBarHiddenImage {
   list-style-image: url("chrome://browser/skin/preferences/in-content/no-search-bar.svg");
 }
 
-#searchBarShownRadio,
-#showSearchSuggestionsFirstCheckbox {
-  /* A little space to separate these from the elements above them. */
+#searchBarShownRadio {
+  /* Allow a little visual space to separate the radio from the image above it. */
   margin-top: 10px;
 }
 
 .searchBarShownImage  {
   list-style-image: url("chrome://browser/skin/preferences/in-content/search-bar.svg");
 }
 
 .searchBarImage:-moz-locale-dir(rtl) {