Bug 941292 - Add search provider options flyout. r=sfoster
authorJim Mathies <jmathies@mozilla.com>
Wed, 04 Dec 2013 05:46:10 -0600
changeset 158803 d8c647479ec112ed7fa290ebf5e94ed98a5614d6
parent 158802 bf8935bf584724365aac0414b079375c2c83e4fd
child 158804 4b85621b0bbf43c655cb3a7801d3b726b48bfb5e
push id37085
push userryanvm@gmail.com
push dateWed, 04 Dec 2013 22:39:20 +0000
treeherdermozilla-inbound@1426ffa9caf2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfoster
bugs941292
milestone28.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 941292 - Add search provider options flyout. r=sfoster
browser/metro/base/content/browser.xul
browser/metro/base/content/flyoutpanels/FlyoutPanelsUI.js
browser/metro/base/content/flyoutpanels/SearchFlyoutPanel.js
browser/metro/base/content/flyoutpanels/SettingsCharm.js
browser/metro/base/jar.mn
browser/metro/locales/en-US/chrome/browser.properties
browser/metro/locales/en-US/chrome/searchPanel.dtd
browser/metro/locales/jar.mn
--- a/browser/metro/base/content/browser.xul
+++ b/browser/metro/base/content/browser.xul
@@ -16,16 +16,18 @@
 <!ENTITY % browserDTD SYSTEM "chrome://browser/locale/browser.dtd">
 %browserDTD;
 <!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd">
 %brandDTD;
 <!ENTITY % prefsDTD SYSTEM "chrome://browser/locale/preferences.dtd">
 %prefsDTD;
 <!ENTITY % aboutPanelDTD SYSTEM "chrome://browser/locale/aboutPanel.dtd">
 %aboutPanelDTD;
+<!ENTITY % searchPanelDTD SYSTEM "chrome://browser/locale/searchPanel.dtd">
+%searchPanelDTD;
 #ifdef MOZ_SERVICES_SYNC
 <!ENTITY % syncBrandDTD SYSTEM "chrome://browser/locale/syncBrand.dtd">
 %syncBrandDTD;
 <!ENTITY % syncDTD SYSTEM "chrome://browser/locale/sync.dtd">
 %syncDTD;
 #endif
 ]>
 
@@ -681,16 +683,20 @@ Desktop browser's sync prefs.
                    label="&doNotTrack.options.doTrack;" value="0"/>
             <radio id="prefs-dnt-nopref" class="flyoutpanel-hack"
                    label="&doNotTrack.options.default;" value="-1"/>
           </radiogroup>
         </setting>
         <label class="text-link" href="https://www.mozilla.org/dnt">&doNotTrack.learnMoreLink;</label>
       </settings>
     </flyoutpanel>
+    <flyoutpanel id="search-flyoutpanel" class="flyout-narrow" headertext="&searchFlyoutHeader.title;">
+      <settings id="search-options" label="&searchSetting.title;">
+      </settings>
+    </flyoutpanel>
 
     <!-- Chrome touch selection overlay -->
     <box class="selection-overlay-hidden" id="chrome-selection-overlay"/>
 
     <box onclick="event.stopPropagation();" id="context-container" class="menu-container" hidden="true">
       <vbox id="context-popup" class="menu-popup">
         <richlistbox id="context-commands" bindingType="contextmenu" flex="1">
           <!-- priority="low" items are hidden by default when a context is being displayed
--- a/browser/metro/base/content/flyoutpanels/FlyoutPanelsUI.js
+++ b/browser/metro/base/content/flyoutpanels/FlyoutPanelsUI.js
@@ -17,16 +17,17 @@ let FlyoutPanelsUI = {
     Cu.import("resource://gre/modules/Services.jsm");
 
     this._isInitialized = true;
     let scriptContexts = {};
     let scripts =
           [
             ['AboutFlyoutPanel', 'chrome://browser/content/flyoutpanels/AboutFlyoutPanel.js'],
             ['PrefsFlyoutPanel', 'chrome://browser/content/flyoutpanels/PrefsFlyoutPanel.js'],
+            ['SearchFlyoutPanel', 'chrome://browser/content/flyoutpanels/SearchFlyoutPanel.js'],
 #ifdef MOZ_SERVICES_SYNC
             ['SyncFlyoutPanel', 'chrome://browser/content/flyoutpanels/SyncFlyoutPanel.js'],
 #endif
           ];
 
     scripts.forEach(function (aScript) {
       let [name, script] = aScript;
       XPCOMUtils.defineLazyGetter(FlyoutPanelsUI, name, function() {
new file mode 100644
--- /dev/null
+++ b/browser/metro/base/content/flyoutpanels/SearchFlyoutPanel.js
@@ -0,0 +1,60 @@
+// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+
+let SearchFlyoutPanel = {
+  _isInitialized: false,
+  _hasShown: false,
+  init: function pv_init() {
+    if (this._isInitialized) {
+      Cu.reportError("Attempting to re-initialize PreferencesPanelView");
+      return;
+    }
+    this._topmostElement = document.getElementById("search-flyoutpanel");
+    this._isInitialized = true;
+  },
+
+  checked: function checked(aId) {
+    aId = aId.replace("search-", "");
+    Services.search.defaultEngine = this._engines[parseInt(aId)];
+    this.updateSearchEngines();
+  },
+
+  updateSearchEngines: function () {
+    // Clear the list
+    let setting = document.getElementById("search-options");
+    while(setting.hasChildNodes()) {
+      setting.removeChild(setting.firstChild);
+    }
+
+    // Build up the list and check the default
+    this._engines = Services.search.getVisibleEngines();
+    let defaultEngine = Services.search.defaultEngine;
+
+    this._engines.forEach(function (aEngine, aIndex) {
+      let radio = document.createElementNS(XUL_NS, "radio");
+      radio.setAttribute("id", "search-" + aIndex);
+      radio.setAttribute("label", aEngine.name);
+      radio.setAttribute("oncommand", "FlyoutPanelsUI.SearchFlyoutPanel.checked(this.id)");
+      if (defaultEngine == aEngine) {
+        radio.setAttribute("selected", true);
+      }
+      setting.appendChild(radio);
+    }.bind(this));
+  },
+
+  _show: function() {
+    if (!this._hasShown) {
+      this._hasShown = true;
+      this.updateSearchEngines();
+    }
+    this._topmostElement.show();
+  }
+};
--- a/browser/metro/base/content/flyoutpanels/SettingsCharm.js
+++ b/browser/metro/base/content/flyoutpanels/SettingsCharm.js
@@ -24,30 +24,39 @@ var SettingsCharm = {
   init: function SettingsCharm_init() {
     Services.obs.addObserver(this, "metro-settings-entry-selected", false);
 
     // Options
     this.addEntry({
         label: Strings.browser.GetStringFromName("optionsCharm"),
         onselected: function() FlyoutPanelsUI.show('PrefsFlyoutPanel')
     });
+
+    // Search providers
+    this.addEntry({
+        label: Strings.browser.GetStringFromName("searchCharm"),
+        onselected: function() FlyoutPanelsUI.show('SearchFlyoutPanel')
+    });
+
 /*
  * Temporarily disabled until we can have sync prefs together with the
  * Desktop browser's sync prefs.
     // Sync
     this.addEntry({
         label: Strings.brand.GetStringFromName("syncBrandShortName"),
         onselected: function() FlyoutPanelsUI.show('SyncFlyoutPanel')
     });
 */
+
     // About
     this.addEntry({
         label: Strings.browser.GetStringFromName("aboutCharm1"),
         onselected: function() FlyoutPanelsUI.show('AboutFlyoutPanel')
     });
+
     // Help
     this.addEntry({
         label: Strings.browser.GetStringFromName("helpOnlineCharm"),
         onselected: function() {
           let url = Services.urlFormatter.formatURLPref("app.support.baseURL");
           BrowserUI.addAndShowTab(url, Browser.selectedTab);
         }
     });
--- a/browser/metro/base/jar.mn
+++ b/browser/metro/base/jar.mn
@@ -29,16 +29,17 @@ chrome.jar:
   content/bindings/circularprogress.xml        (content/bindings/circularprogress.xml)
   content/bindings/notification.xml            (content/bindings/notification.xml)
   content/bindings/tabprompts.xml              (content/bindings/tabprompts.xml)
 
   content/flyoutpanels/SettingsCharm.js        (content/flyoutpanels/SettingsCharm.js)
 * content/flyoutpanels/FlyoutPanelsUI.js       (content/flyoutpanels/FlyoutPanelsUI.js)
 * content/flyoutpanels/AboutFlyoutPanel.js     (content/flyoutpanels/AboutFlyoutPanel.js)
   content/flyoutpanels/PrefsFlyoutPanel.js     (content/flyoutpanels/PrefsFlyoutPanel.js)
+  content/flyoutpanels/SearchFlyoutPanel.js    (content/flyoutpanels/SearchFlyoutPanel.js)
 #ifdef MOZ_SERVICES_SYNC
   content/flyoutpanels/SyncFlyoutPanel.js      (content/flyoutpanels/SyncFlyoutPanel.js)
 #endif
 
   content/helperui/AlertsHelper.js             (content/helperui/AlertsHelper.js)
   content/helperui/IndexedDB.js                (content/helperui/IndexedDB.js)
   content/helperui/MenuUI.js                   (content/helperui/MenuUI.js)
   content/helperui/OfflineApps.js              (content/helperui/OfflineApps.js)
--- a/browser/metro/locales/en-US/chrome/browser.properties
+++ b/browser/metro/locales/en-US/chrome/browser.properties
@@ -39,16 +39,17 @@ contextAppbar2.clear=Clear selection
 # Clear private data
 clearPrivateData.clearButton=Clear
 clearPrivateData.title=Clear Private Data
 clearPrivateData.message=Clear your private data?
 
 # Settings Charms
 aboutCharm1=About
 optionsCharm=Options
+searchCharm=Search
 helpOnlineCharm=Help (online)
 
 # General
 # LOCALIZATION NOTE (browserForSaveLocation): Title for the "Save..." file picker dialog
 browserForSaveLocation=Save Location
 # LOCALIZATION NOTE (browserForSaveLocation): Title for the "Open..." file picker dialog
 browserForOpenLocation=Open Location
 
new file mode 100644
--- /dev/null
+++ b/browser/metro/locales/en-US/chrome/searchPanel.dtd
@@ -0,0 +1,7 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+
+<!ENTITY searchFlyoutHeader.title  "Search">
+<!ENTITY searchSetting.title  "Default Search Provider">
--- a/browser/metro/locales/jar.mn
+++ b/browser/metro/locales/jar.mn
@@ -11,16 +11,17 @@
 % locale browser @AB_CD@ %locale/browser/
   locale/browser/aboutCertError.dtd       (%chrome/aboutCertError.dtd)
   locale/browser/browser.dtd              (%chrome/browser.dtd)
   locale/browser/browser.properties       (%chrome/browser.properties)
   locale/browser/region.properties        (%chrome/region.properties)
   locale/browser/config.dtd               (%chrome/config.dtd)
   locale/browser/preferences.dtd          (%chrome/preferences.dtd)
   locale/browser/aboutPanel.dtd           (%chrome/aboutPanel.dtd)
+  locale/browser/searchPanel.dtd          (%chrome/searchPanel.dtd)
   locale/browser/checkbox.dtd             (%chrome/checkbox.dtd)
   locale/browser/sync.dtd                 (%chrome/sync.dtd)
   locale/browser/sync.properties          (%chrome/sync.properties)
   locale/browser/passwordmgr.properties   (%chrome/passwordmgr.properties)
   locale/browser/phishing.dtd             (%chrome/phishing.dtd)
   locale/browser/crashprompt.properties   (%chrome/crashprompt.properties)
   locale/browser/aboutAddons.dtd          (%chrome/aboutAddons.dtd)