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
--- 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]);
}