Bug 745525 - Use handleEvent in PopupNotifications r=dolske
authorOHZEKI Tetsuharu <saneyuki.s.snyk@gmail.com>
Sun, 15 Apr 2012 19:21:25 -0400
changeset 95038 9a2f5f6016160523630a565df941b0e61173f10a
parent 95037 b69c5c0bb7274ebf6f722873a6f5e2eb64ed3a7b
child 95039 1b19214a0a50c271c1f20429a14a5ec863024ba3
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs745525
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 745525 - Use handleEvent in PopupNotifications r=dolske
toolkit/content/PopupNotifications.jsm
--- a/toolkit/content/PopupNotifications.jsm
+++ b/toolkit/content/PopupNotifications.jsm
@@ -119,51 +119,41 @@ function PopupNotifications(tabbrowser, 
   if (iconBox && !(iconBox instanceof Ci.nsIDOMXULElement))
     throw "Invalid iconBox";
   if (!(panel instanceof Ci.nsIDOMXULElement))
     throw "Invalid panel";
 
   this.window = tabbrowser.ownerDocument.defaultView;
   this.panel = panel;
   this.tabbrowser = tabbrowser;
-
-  this._onIconBoxCommand = this._onIconBoxCommand.bind(this);
   this.iconBox = iconBox;
 
-  this.panel.addEventListener("popuphidden", this._onPopupHidden.bind(this), true);
+  this.panel.addEventListener("popuphidden", this, true);
 
-  let self = this;
-  function updateFromListeners() {
-    // setTimeout(..., 0) needed, otherwise openPopup from "activate" event
-    // handler results in the popup being hidden again for some reason...
-    self.window.setTimeout(function () {
-      self._update();
-    }, 0);
-  }
-  this.window.addEventListener("activate", updateFromListeners, true);
-  this.tabbrowser.tabContainer.addEventListener("TabSelect", updateFromListeners, true);
+  this.window.addEventListener("activate", this, true);
+  this.tabbrowser.tabContainer.addEventListener("TabSelect", this, true);
 }
 
 PopupNotifications.prototype = {
 
   window: null,
   panel: null,
   tabbrowser: null,
 
   _iconBox: null,
   set iconBox(iconBox) {
     // Remove the listeners on the old iconBox, if needed
     if (this._iconBox) {
-      this._iconBox.removeEventListener("click", this._onIconBoxCommand, false);
-      this._iconBox.removeEventListener("keypress", this._onIconBoxCommand, false);
+      this._iconBox.removeEventListener("click", this, false);
+      this._iconBox.removeEventListener("keypress", this, false);
     }
     this._iconBox = iconBox;
     if (iconBox) {
-      iconBox.addEventListener("click", this._onIconBoxCommand, false);
-      iconBox.addEventListener("keypress", this._onIconBoxCommand, false);
+      iconBox.addEventListener("click", this, false);
+      iconBox.addEventListener("keypress", this, false);
     }
   },
   get iconBox() {
     return this._iconBox;
   },
 
   /**
    * Retrieve a Notification object associated with the browser/ID pair.
@@ -349,16 +339,37 @@ PopupNotifications.prototype = {
     let isCurrent = this._currentNotifications.indexOf(notification) != -1;
     this._remove(notification);
 
     // update the panel, if needed
     if (isCurrent)
       this._update();
   },
 
+  handleEvent: function (aEvent) {
+    switch (aEvent.type) {
+      case "popuphidden":
+        this._onPopupHidden(aEvent);
+        break;
+      case "activate":
+      case "TabSelect":
+        let self = this;
+        // setTimeout(..., 0) needed, otherwise openPopup from "activate" event
+        // handler results in the popup being hidden again for some reason...
+        this.window.setTimeout(function () {
+          self._update();
+        }, 0);
+        break;
+      case "click":
+      case "keypress":
+        this._onIconBoxCommand(aEvent);
+        break;
+    }
+  },
+
 ////////////////////////////////////////////////////////////////////////////////
 // Utility methods
 ////////////////////////////////////////////////////////////////////////////////
 
   _ignoreDismissal: null,
   _currentAnchorElement: null,
 
   /**