Bug 1407754 - exiting customize mode quickly after adding a toolbar item to toolbar properly adds it to the toolbar. r?jaws draft
authorErica Wright <ewright@mozilla.com>
Fri, 13 Oct 2017 09:27:48 -0400
changeset 680079 c9aabf6e3054f313208511209d81a0306aff8d65
parent 679509 98247fbf95c260786361e12ad924c4370885f686
child 735767 4bcf9faf6d95440374b8fed710d9ba9d8bfca07b
push id84401
push userbmo:ewright@mozilla.com
push dateFri, 13 Oct 2017 15:22:50 +0000
reviewersjaws
bugs1407754
milestone58.0a1
Bug 1407754 - exiting customize mode quickly after adding a toolbar item to toolbar properly adds it to the toolbar. r?jaws MozReview-Commit-ID: C7uvVVWoIeB
browser/components/customizableui/CustomizeMode.jsm
--- a/browser/components/customizableui/CustomizeMode.jsm
+++ b/browser/components/customizableui/CustomizeMode.jsm
@@ -582,30 +582,43 @@ CustomizeMode.prototype = {
 
   _promiseWidgetAnimationOut(aNode) {
     if (!gCosmeticAnimationsEnabled ||
         aNode.getAttribute("cui-anchorid") == "nav-bar-overflow-button" ||
         (aNode.tagName != "toolbaritem" && aNode.tagName != "toolbarbutton") ||
         (aNode.id == "downloads-button" && aNode.hidden)) {
       return null;
     }
+
     let animationNode;
     if (aNode.parentNode && aNode.parentNode.id.startsWith("wrapper-")) {
       animationNode = aNode.parentNode;
     } else {
       animationNode = aNode;
     }
     return new Promise(resolve => {
-      animationNode.classList.add("animate-out");
-      animationNode.addEventListener("animationend", function cleanupWidgetAnimationEnd(e) {
+      function cleanupCustomizationExit() {
+        resolveAnimationPromise();
+      }
+
+      function cleanupWidgetAnimationEnd(e) {
         if (e.animationName == "widget-animate-out" && e.target.id == animationNode.id) {
-          animationNode.removeEventListener("animationend", cleanupWidgetAnimationEnd);
-          resolve();
+          resolveAnimationPromise();
         }
-      });
+      }
+
+      function resolveAnimationPromise() {
+        animationNode.removeEventListener("animationend", cleanupWidgetAnimationEnd);
+        animationNode.removeEventListener("customizationending", cleanupCustomizationExit);
+        resolve();
+      }
+
+      animationNode.classList.add("animate-out");
+      animationNode.ownerGlobal.gNavToolbox.addEventListener("customizationending", cleanupCustomizationExit);
+      animationNode.addEventListener("animationend", cleanupWidgetAnimationEnd);
     });
   },
 
   async addToToolbar(aNode) {
     aNode = this._getCustomizableChildForNode(aNode);
     if (aNode.localName == "toolbarpaletteitem" && aNode.firstChild) {
       aNode = aNode.firstChild;
     }