Bug 686487 - Ctrl+K should open a new global search tab if searchbox is not available. r=asuth
☠☠ backed out by f1214f53c1c3 ☠ ☠
authorThomas Düllmann <bugzilla2007@duellmann24.net>
Sat, 17 Dec 2016 22:03:17 +0200
changeset 28038 95da4e9ee8dc6cbf96b056b3e0e70ae90d0fff46
parent 28037 78522213bd3802ac01c80c0fa5c90a23a707505a
child 28039 4cc7e241a7d02dd1a662f37cd2b674a1566f2306
push id1966
push userclokep@gmail.com
push dateMon, 12 Jun 2017 16:57:35 +0000
treeherdercomm-beta@32d9b8d10da1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs686487
Bug 686487 - Ctrl+K should open a new global search tab if searchbox is not available. r=asuth Toolbar customization, hidden toolbars, but gloda enabled. (started by Wei Zhang, polished by aceman)
mail/base/content/mailWindowOverlay.js
mail/base/content/search.xml
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -3531,43 +3531,78 @@ function SendMDNResponse()
   gMessageNotificationBar.mdnGenerator.userAgreed();
 }
 
 function IgnoreMDNResponse()
 {
   gMessageNotificationBar.mdnGenerator.userDeclined();
 }
 
+/***
+ * Focus the gloda global search input box on current tab, or,
+ * if the search box is hidden, open a new gloda search tab
+ * and focus its search box.
+ */
 function QuickSearchFocus()
 {
+  if (!Services.prefs.getBoolPref("mailnews.database.global.indexer.enabled")) {
+    // If gloda is disabled, do nothing.
+    return;
+  }
+
   let tabmail = document.getElementById('tabmail');
+  if (!tabmail) {
+    // No tabmail element: This should never happen.
+    return;
+  }
 
   // If we're currently viewing a Gloda tab, drill down to find the
   // built-in search input, and select that.
-  if (tabmail
-      && tabmail.currentTabInfo.mode.name == "glodaFacet") {
+  if (tabmail.currentTabInfo.mode.name == "glodaFacet") {
     let searchInput = tabmail.currentTabInfo
                              .panel
                              .querySelector(".remote-gloda-search");
     if (searchInput)
       searchInput.select();
 
     return;
   }
 
-  if (tabmail && tabmail.currentTabInfo.mode.name == "chat") {
+  if (tabmail.currentTabInfo.mode.name == "chat") {
     let searchInput = document.getElementById("IMSearchInput");
     if (searchInput)
       searchInput.select();
     return;
   }
 
-  var quickSearchTextBox = document.getElementById('searchInput');
-  if (quickSearchTextBox)
-    quickSearchTextBox.select();
+  let newTab = true;
+  let globalSearchTextBox = document.getElementById("searchInput");
+  if (globalSearchTextBox) {
+    // Via toolbar customization, globalSearchTextBox can be in different places:
+    // Toolbars, tab bar, menu bar, etc. When the containing elements are hidden,
+    // the searchbox will also be hidden, so clientHeight and clientWidth of the
+    // searchbox or one of its parent will typically be zero and we can test for that.
+    // If globalSearchTextBox is hidden, use a new tab.
+    newTab = false;
+    let element = globalSearchTextBox;
+    while (element) {
+      if ((element.clientHeight == 0) || (element.clientWidth == 0))
+        newTab = true;
+      element = element.parentElement;
+    }
+  }
+
+  if (!newTab) {
+    // Focus and select global search box.
+    globalSearchTextBox.select();
+  } else {
+    // Open a new global search tab.
+    globalSearchTextBox.value = "";
+    globalSearchTextBox.doSearch(true);
+  }
 }
 
 /**
  * Opens a search window with the given folder, or the displayed one if none is
  * chosen.
  *
  * @param [aFolder] the folder to open the search window for, if different from
  *                  the displayed one
--- a/mail/base/content/search.xml
+++ b/mail/base/content/search.xml
@@ -212,21 +212,21 @@
           }
         } catch (e) {
           logException(e);
         }
         ]]></body>
       </method>
 
       <method name="doSearch">
+        <parameter name="aEmpty"/> <!-- run the search even with empty string -->
         <body><![CDATA[
           Components.utils.import("resource://gre/modules/Services.jsm");
-
           try {
-            if (this.value) {
+            if (this.value || aEmpty) {
               let tabmail = document.getElementById("tabmail");
               // If the current tab is a gloda search tab, reset the value
               //  to the initial search value.  Otherwise, clear it.  This
               //  is the value that 3is going to be saved with the current
               //  tab when we switch back to it next.
               let searchString = this.value;
 
               if (tabmail.currentTabInfo.mode.name == "glodaFacet") {