Bug 595235 Make search suggestions work with new search sidebar r= Neil.
authorPhilip Chee <philip.chee@gmail.com>
Sat, 01 Jun 2013 02:29:18 +0800
changeset 12536 8919c64f2bb26c5829d40ed77a1ff261a330c39a
parent 12535 800dca20e0a25e96b7a55192281f023c0e4d4d5b
child 12537 1bc26fe506964e72dd0c46eacdb87e3fc429bf06
push id9218
push userphilip.chee@gmail.com
push dateFri, 31 May 2013 18:45:03 +0000
treeherdercomm-central@1bc26fe50696 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs595235
Bug 595235 Make search suggestions work with new search sidebar r= Neil. Original patch by Robert Kaiser <kairo@kairo.at>
suite/common/search/search-panel.js
suite/common/search/search-panel.xul
suite/installer/package-manifest.in
suite/themes/classic/communicator/search/search.css
suite/themes/modern/communicator/search/search.css
--- a/suite/common/search/search-panel.js
+++ b/suite/common/search/search-panel.js
@@ -1,24 +1,29 @@
 /* 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/. */
 
 Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/FormHistory.jsm");
 
 const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 const SEARCH_ENGINE_TOPIC = "browser-search-engine-modified";
-var menulist, textbox;
+var isPB, menulist, textbox;
 
 function Startup() {
   menulist = document.getElementById("sidebar-search-engines");
   textbox = document.getElementById("sidebar-search-text");
+  isPB = top.gPrivate;
+  if (isPB)
+    textbox.searchParam += "|private";
 
   LoadEngineList();
-  Services.obs.addObserver(engineObserver, SEARCH_ENGINE_TOPIC, false);
+  Services.obs.addObserver(engineObserver, SEARCH_ENGINE_TOPIC, true);
 }
 
 function LoadEngineList() {
   // Make sure the popup is empty.
   menulist.removeAllItems();
 
   var engines = Services.search.getVisibleEngines();
   for (let i = 0; i < engines.length; i++) {
@@ -28,35 +33,48 @@ function LoadEngineList() {
     if (engines[i].iconURI)
       menuitem.setAttribute("image", engines[i].iconURI.spec);
     menulist.menupopup.appendChild(menuitem);
     menuitem.engine = engines[i];
   }
   menulist.value = Services.search.currentEngine.name;
 }
 
-function Shutdown() {
-  Services.obs.removeObserver(engineObserver, SEARCH_ENGINE_TOPIC, false);
-}
-
 function SelectEngine() {
   if (menulist.selectedItem)
     Services.search.currentEngine = menulist.selectedItem.engine;
 }
 
 function doSearch() {
   var textValue = textbox.value;
 
+  // Save the current value in the form history (shared with the search bar)
+  // except when in Private Browsing mode.
+
+  if (textValue && !isPB) {
+    FormHistory.update({
+      op: "bump",
+      fieldname: "searchbar-history",
+      value: textValue
+    }, {
+      handleError: function(aError) {
+        Components.utils.reportError("Saving search to form history failed: " + aError.message);
+      }
+    });
+  }
+
   var where = Services.prefs.getBoolPref("browser.search.openintab") ? "tab" : "current";
-
   var submission = Services.search.currentEngine.getSubmission(textValue);
   openUILinkIn(submission.uri.spec, where, null, submission.postData);
 }
 
 var engineObserver = {
+  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIObserver,
+                                         Components.interfaces.nsISupportsWeakReference]),
+
   observe: function(aEngine, aTopic, aVerb) {
     if (aTopic == SEARCH_ENGINE_TOPIC) {
       if (aVerb == "engine-current")
         return;
       // Right now, always just rebuild the list after any modification.
       LoadEngineList();
     }
   }
--- a/suite/common/search/search-panel.xul
+++ b/suite/common/search/search-panel.xul
@@ -5,28 +5,34 @@
 
 <?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://communicator/skin/search/search.css" type="text/css"?>
 
 <!DOCTYPE page SYSTEM "chrome://communicator/locale/search/search-panel.dtd" >
 <page id="searchPanel"
       xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
       onload="Startup();"
-      onunload="Shutdown();"
       elementtofocus="sidebar-search-text">
 
   <script type="application/javascript" src="chrome://communicator/content/search/search-panel.js"/>
   <script type="application/javascript" src="chrome://communicator/content/utilityOverlay.js"/>
 
     <menulist id="sidebar-search-engines"
               oncommand="SelectEngine(this);"/>
 
     <hbox align="center">
-      <textbox id="sidebar-search-text" flex="1"
-               onkeypress="if (event.keyCode == event.DOM_VK_RETURN) doSearch();"
-               placeholder="&search.placeholder;"/>
+      <textbox id="sidebar-search-text" flex="1" class="padded"
+               ontextentered="doSearch();"
+               placeholder="&search.placeholder;"
+               type="autocomplete"
+               autocompletesearch="search-autocomplete"
+               autocompletesearchparam="searchbar-history"
+               timeout="250"
+               maxrows="10"
+               completeselectedindex="true"
+               tabscrolling="true"/>
       <button id="searchButton" label="&search.button.label;"
               oncommand="doSearch();"/>
     </hbox>
     <button id="managerButton"
             label="&search.engineManager.label;"
             oncommand="window.top.OpenSearchEngineManager();"/>
 </page>
--- a/suite/installer/package-manifest.in
+++ b/suite/installer/package-manifest.in
@@ -391,16 +391,17 @@
 @BINPATH@/components/nsDefaultCLH.manifest
 @BINPATH@/components/nsDOMIdentity.js
 #ifdef MOZ_GTK2
 @BINPATH@/components/nsFilePicker.js
 @BINPATH@/components/nsFilePicker.manifest
 #endif
 @BINPATH@/components/nsFormAutoComplete.js
 @BINPATH@/components/nsFormHistory.js
+@BINPATH@/components/FormHistoryStartup.js
 @BINPATH@/components/nsHandlerService.js
 @BINPATH@/components/nsHandlerService.manifest
 @BINPATH@/components/nsHelperAppDlg.js
 @BINPATH@/components/nsHelperAppDlg.manifest
 @BINPATH@/components/nsIDService.js
 @BINPATH@/components/nsINIProcessor.js
 @BINPATH@/components/nsINIProcessor.manifest
 @BINPATH@/components/nsInputListAutoComplete.js
--- a/suite/themes/classic/communicator/search/search.css
+++ b/suite/themes/classic/communicator/search/search.css
@@ -2,8 +2,12 @@
  * 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/. */
 
 /* ===== search.css =====================================================
    == Styles specific to the Search sidebar panel.
    ====================================================================== */
 
 @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
+
+.autocomplete-treebody::-moz-tree-cell(suggesthint) {
+  border-top: 1px solid GrayText;
+}
--- a/suite/themes/modern/communicator/search/search.css
+++ b/suite/themes/modern/communicator/search/search.css
@@ -2,8 +2,12 @@
  * 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/. */
 
 /* ===== search.css =====================================================
    == Styles specific to the Search sidebar panel.
    ====================================================================== */
 
 @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
+
+.autocomplete-treebody::-moz-tree-cell(suggesthint) {
+  border-top: 1px solid #999999;
+}