Bug 1309935 - Add ability to find within select dropdown when over 40 elements draft
authorTylerM <maklebus@msu.edu>
Thu, 13 Oct 2016 14:16:09 -0400
changeset 424930 8233ed556f112f788e5b80eca573c2ab803db5ef
parent 424929 11302ddd439eb615b911bbe67d16e014e736203d
child 533799 db99a13ca83e1586d268154c4827ac229fb2339b
push id32293
push userbmo:maklebus@msu.edu
push dateThu, 13 Oct 2016 20:34:31 +0000
bugs1309935
milestone52.0a1
Bug 1309935 - Add ability to find within select dropdown when over 40 elements Case insensitive inner search implemented for select options, with list navigation taking keyboard input until search field is focused. Pref added to enable search (dom.forms.selectSearch). r?jaws, mconley MozReview-Commit-ID: DouTpAjgtxz
layout/xul/nsXULPopupManager.cpp
modules/libpref/init/all.js
toolkit/modules/SelectParentHelper.jsm
--- a/layout/xul/nsXULPopupManager.cpp
+++ b/layout/xul/nsXULPopupManager.cpp
@@ -1985,16 +1985,17 @@ nsXULPopupManager::UpdateSearchListeners
 {
   nsIContent* content;
   nsCOMPtr<EventTarget> newTarget;
   nsMenuChainItem* item = GetTopVisibleMenu();
 
   if (item && item->PopupType() == ePopupTypeMenu) {
 	  // The search box is assumed to be the first child of the menupopup.
 	  content = item->Content()->GetFirstChild();
+	  // Check that content is in fact the search text field
 	  if (content->IsXULElement(nsGkAtoms::textbox)) {
 		  newTarget = content;
 	  }
   }
 
   if (mSearchListener != newTarget) {
     if (mSearchListener) {
       mSearchListener->RemoveEventListener(NS_LITERAL_STRING("blur"), this, true);
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5572,8 +5572,11 @@ pref("security.mixed_content.send_hsts_p
 // Don't change the order of evaluation of mixed-content and HSTS upgrades in
 // order to be most compatible with current standards
 pref("security.mixed_content.use_hsts", false);
 #else
 // Change the order of evaluation so HSTS upgrades happen before
 // mixed-content blocking
 pref("security.mixed_content.use_hsts", true);
 #endif
+
+// Enable search box in <select> dropdowns
+pref("dom.forms.selectSearch", true);
--- a/toolkit/modules/SelectParentHelper.jsm
+++ b/toolkit/modules/SelectParentHelper.jsm
@@ -212,19 +212,23 @@ function populateChildren(menulist, opti
       item.setAttribute("value", option.index);
 
       if (parentElement) {
         item.classList.add("contentSelectDropdown-ingroup")
       }
     }
   }
 
-  // Check if this is the first time iterating through the dropdown and if list is
-  //  long enough for a search element to be added.
-  if(addSearch && element.childElementCount > 40){
+  let prefs = Components.classes["@mozilla.org/preferences-service;1"]
+                       .getService(Components.interfaces.nsIPrefService).getBranch("dom.forms.");
+  let minimumElements = 40;
+
+  // Check if search pref is enabled, if this is the first time iterating through
+  //  the dropdown, and if the list is long enough for a search element to be added.
+  if(prefs.getBoolPref("selectSearch") && addSearch && element.childElementCount > minimumElements){
 
     // Add a search text field as the first element of the dropdown
     let searchbox = element.ownerDocument.createElement("textbox");
     searchbox.setAttribute("type", "search");
     searchbox.addEventListener("input", onSearchInput);
     element.insertBefore(searchbox, element.childNodes[0]);
   }