Bug 1294531 - Use a className instead of an ID to alter the state of the search engine list to allow add-ons to add their own buttons to the page and choose the behavior that they want. r=Gijs
authorJared Wein <jwein@mozilla.com>
Sat, 13 Aug 2016 22:15:58 -0400
changeset 400814 4f30550d3edb5c60f07cea7259652722deccc094
parent 400813 90324e0a64e7840a046f9396ccb38c151133a605
child 400815 f2bc29797f09093a417e7eecf7ccd70ac53fcb7b
push id26289
push userbmo:npancholi@mozilla.com
push dateMon, 15 Aug 2016 22:10:02 +0000
reviewersGijs
bugs1294531
milestone51.0a1
Bug 1294531 - Use a className instead of an ID to alter the state of the search engine list to allow add-ons to add their own buttons to the page and choose the behavior that they want. r=Gijs MozReview-Commit-ID: 78VufTvjYVC
browser/components/preferences/in-content/search.js
browser/components/preferences/in-content/search.xul
--- a/browser/components/preferences/in-content/search.js
+++ b/browser/components/preferences/in-content/search.js
@@ -101,21 +101,26 @@ var gSearchPane = {
       if (e.name == currentEngine)
         list.selectedItem = item;
     });
   },
 
   handleEvent: function(aEvent) {
     switch (aEvent.type) {
       case "click":
-        if (aEvent.target.id != "engineChildren" && aEvent.target.id != "removeEngineButton") {
+        if (aEvent.target.id != "engineChildren" &&
+            !aEvent.target.classList.contains("searchEngineAction")) {
           let engineList = document.getElementById("engineList");
           // We don't want to toggle off selection while editing keyword
-          // so proceed only when the input field is hidden
-          if (engineList.inputField.hidden) {
+          // so proceed only when the input field is hidden.
+          // We need to check that engineList.view is defined here
+          // because the "click" event listener is on <window> and the
+          // view might have been destroyed if the pane has been navigated
+          // away from.
+          if (engineList.inputField.hidden && engineList.view) {
             let selection = engineList.view.selection;
             if (selection.count > 0) {
               selection.toggleSelect(selection.currentIndex);
             }
             engineList.blur();
           }
         }
         if (aEvent.target.id == "addEngines" && aEvent.button == 0) {
--- a/browser/components/preferences/in-content/search.xul
+++ b/browser/components/preferences/in-content/search.xul
@@ -75,16 +75,17 @@
 
       <hbox>
         <button id="restoreDefaultSearchEngines"
                 label="&restoreDefaultSearchEngines.label;"
                 accesskey="&restoreDefaultSearchEngines.accesskey;"
                 />
         <spacer flex="1"/>
         <button id="removeEngineButton"
+                class="searchEngineAction"
                 label="&removeEngine.label;"
                 accesskey="&removeEngine.accesskey;"
                 disabled="true"
                 />
       </hbox>
 
       <separator class="thin"/>