Bug 1463708 - only reset previews when leaving the panel, r?johannh draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 19 Jun 2018 21:44:00 +0100
changeset 808727 b90787b7caa0931806c9c59bcc0af7eb994aabf4
parent 808726 681eb7dfa324dd50403c382888929ea8b8b11b00
push id113470
push userbmo:gijskruitbosch+bugs@gmail.com
push dateWed, 20 Jun 2018 13:26:45 +0000
reviewersjohannh
bugs1463708
milestone62.0a1
Bug 1463708 - only reset previews when leaving the panel, r?johannh MozReview-Commit-ID: 1KVseuWlEPU
browser/components/customizableui/CustomizeMode.jsm
--- a/browser/components/customizableui/CustomizeMode.jsm
+++ b/browser/components/customizableui/CustomizeMode.jsm
@@ -1373,17 +1373,16 @@ CustomizeMode.prototype = {
       tbb.setAttribute("aria-checked", isActive);
       tbb.setAttribute("role", "menuitemradio");
       if (isActive) {
         tbb.setAttribute("active", "true");
       }
       tbb.addEventListener("focus", previewTheme);
       tbb.addEventListener("mouseover", previewTheme);
       tbb.addEventListener("blur", resetPreview);
-      tbb.addEventListener("mouseout", resetPreview);
 
       return tbb;
     }
 
     let themes = [];
     let lwts = LightweightThemeManager.usedThemes;
     let currentLwt = LightweightThemeManager.currentTheme;
 
@@ -1414,16 +1413,33 @@ CustomizeMode.prototype = {
           button.theme.userDisabled = false;
         else
           LightweightThemeManager.currentTheme = button.theme;
         onThemeSelected(panel);
       });
       panel.insertBefore(button, recommendedLabel);
     }
 
+    function panelMouseOut(e) {
+      // mouseout events bubble, so we get mouseout events for the buttons
+      // in the panel. Here, we only care when the mouse actually leaves
+      // the panel. For some reason event.target might not be the panel
+      // even when the mouse *is* leaving the panel, so we check
+      // explicitOriginalTarget instead.
+      if (e.explicitOriginalTarget == panel) {
+        resetPreview();
+      }
+    }
+
+    panel.addEventListener("mouseout", panelMouseOut);
+    panel.addEventListener("popuphidden", () => {
+      panel.removeEventListener("mouseout", panelMouseOut);
+      resetPreview();
+    }, {once: true});
+
     let lwthemePrefs = Services.prefs.getBranch("lightweightThemes.");
     let recommendedThemes = lwthemePrefs.getStringPref("recommendedThemes");
     recommendedThemes = JSON.parse(recommendedThemes);
     let sb = Services.strings.createBundle("chrome://browser/locale/lightweightThemes.properties");
     for (let theme of recommendedThemes) {
       try {
         theme.name = sb.GetStringFromName("lightweightThemes." + theme.id + ".name");
         theme.description = sb.GetStringFromName("lightweightThemes." + theme.id + ".description");