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 draft
authorJared Wein <jwein@mozilla.com>
Sat, 13 Aug 2016 22:15:58 -0400
changeset 400478 9adf8f91b82193c1acd731e8ef1abce620cee3c7
parent 400477 e135af145a2eb0fb6b8a5f9a35cf21655e19ad7c
child 528213 b963d63acd3554cf2472578d294dba7f4ac3d4e0
push id26158
push userjwein@mozilla.com
push dateSun, 14 Aug 2016 02:16:57 +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"/>