+ Subscribable (in utils.js) no longer has a separate onClose path
authorIan Gilman <ian@iangilman.com>
Wed, 14 Jul 2010 16:59:37 -0700
changeset 50124 be39a7c32f89bcff08fb09df4f843433defac222
parent 50123 cbeaeeaa042fb776d8c7b49d33c68e1614c66d6c
child 50125 d632c190b125baaf9f642414bb3bc545dcf1357c
push id15039
push useredward.lee@engineering.uiuc.edu
push dateThu, 12 Aug 2010 19:47:36 +0000
treeherdermozilla-central@5da28c582cc7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone2.0b2pre
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
+ Subscribable (in utils.js) no longer has a separate onClose path + My recent addition of a "content" div broke dragging to make a new group; fixed
browser/base/content/tabcandy/app/groups.js
browser/base/content/tabcandy/app/infoitems.js
browser/base/content/tabcandy/app/tabitems.js
browser/base/content/tabcandy/app/ui.js
browser/base/content/tabcandy/core/mirror.js
browser/base/content/tabcandy/core/utils.js
browser/base/content/tabcandy/tabcandy.html
--- a/browser/base/content/tabcandy/app/groups.js
+++ b/browser/base/content/tabcandy/app/groups.js
@@ -329,16 +329,29 @@ window.Group = function(listOfEls, optio
 
 // ----------
 window.Group.prototype = iQ.extend(new Item(), new Subscribable(), {
   // ----------
   // Variable: defaultName
   // The prompt text for the title field.
   defaultName: "name this group...",
 
+  // ----------
+  // Accepts a callback that will be called when this item closes. 
+  // The referenceObject is used to facilitate removal if necessary. 
+  addOnClose: function(referenceObject, callback) {
+    this.addSubscriber(referenceObject, "close", callback);      
+  },
+
+  // ----------
+  // Removes the close event callback associated with referenceObject.
+  removeOnClose: function(referenceObject) {
+    this.removeSubscriber(referenceObject, "close");      
+  },
+  
   // -----------
   // Function: setActiveTab
   // Sets the active <TabItem> for this group
   setActiveTab: function(tab){
     Utils.assert('tab must be a TabItem', tab && tab.isATabItem);
     this._activeTab = tab;
   },
 
@@ -565,17 +578,17 @@ window.Group.prototype = iQ.extend(new I
     }
   },
     
   // ----------
   // Function: close
   // Closes the group, removing (but not closing) all of its children.
   close: function() {
     this.removeAll();
-    this._sendOnClose();
+    this._sendToSubscribers("close");
     Groups.unregister(this);
     this.removeTrenches();
     iQ(this.container).fadeOut(function() {
       iQ(this).remove();
       Items.unsquish();
     });
 
     Storage.deleteGroup(Utils.getCurrentWindow(), this.id);
--- a/browser/base/content/tabcandy/app/infoitems.js
+++ b/browser/base/content/tabcandy/app/infoitems.js
@@ -116,16 +116,29 @@ window.InfoItem = function(bounds, optio
     this.save();
   } catch(e){
     Utils.log(e);
   }
 };
 
 // ----------
 window.InfoItem.prototype = iQ.extend(new Item(), new Subscribable(), {
+  // ----------
+  // Accepts a callback that will be called when this item closes. 
+  // The referenceObject is used to facilitate removal if necessary. 
+  addOnClose: function(referenceObject, callback) {
+    this.addSubscriber(referenceObject, "close", callback);      
+  },
+
+  // ----------
+  // Removes the close event callback associated with referenceObject.
+  removeOnClose: function(referenceObject) {
+    this.removeSubscriber(referenceObject, "close");      
+  },
+  
   // ----------  
   // Function: getStorageData
   // Returns all of the info worth storing about this item.
   getStorageData: function() {
     var data = null;
     
     try {
       data = {
@@ -225,17 +238,17 @@ window.InfoItem.prototype = iQ.extend(ne
     }
   },
     
   // ----------
   // Function: close
   // Closes the item. 
   close: function() {
     try {
-      this._sendOnClose();
+      this._sendToSubscribers("close");
       this.removeTrenches();
       iQ(this.container).fadeOut(function() {
         iQ(this).remove();
         Items.unsquish();
       });
   
   /*     Storage.deleteGroup(Utils.getCurrentWindow(), this.id); */
     } catch(e) {
--- a/browser/base/content/tabcandy/app/tabitems.js
+++ b/browser/base/content/tabcandy/app/tabitems.js
@@ -158,17 +158,17 @@ window.TabItem = function(container, tab
   this.reconnected = false;
   this._hasBeenDrawn = false;
   this.tab = tab;
   this.setResizable(true);
 
   this._updateDebugBounds();
   
   TabItems.register(this);
-  this.tab.mirror.addOnClose(this, function(who, info) {
+  this.tab.mirror.addSubscriber(this, "close", function(who, info) {
     TabItems.unregister(self);
     self.removeTrenches();
   });   
      
   this.tab.mirror.addSubscriber(this, 'urlChanged', function(who, info) {
     if (!self.reconnected && (info.oldURL == 'about:blank' || !info.oldURL)) 
       TabItems.reconnect(self);
 
@@ -375,23 +375,28 @@ window.TabItem.prototype = iQ.extend(new
   },
   
   // ----------
   removeClass: function(className) {
     iQ(this.container).removeClass(className);
   },
   
   // ----------
+  // Function: addOnClose
+  // Accepts a callback that will be called when this item closes. 
+  // The referenceObject is used to facilitate removal if necessary. 
   addOnClose: function(referenceObject, callback) {
-    this.tab.mirror.addOnClose(referenceObject, callback);      
+    this.tab.mirror.addSubscriber(referenceObject, "close", callback);      
   },
 
   // ----------
+  // Function: removeOnClose
+  // Removes the close event callback associated with referenceObject.
   removeOnClose: function(referenceObject) {
-    this.tab.mirror.removeOnClose(referenceObject);      
+    this.tab.mirror.removeSubscriber(referenceObject, "close");      
   },
   
   // ----------  
   setResizable: function(value){
     var $resizer = iQ('.expander', this.container);
 
     this.resizeOptions.minWidth = TabItems.minTabWidth;
     this.resizeOptions.minHeight = TabItems.minTabWidth * (TabItems.tabHeight / TabItems.tabWidth);
--- a/browser/base/content/tabcandy/app/ui.js
+++ b/browser/base/content/tabcandy/app/ui.js
@@ -285,17 +285,17 @@ window.Page = {
     var self = this;
         
     // When you click on the background/empty part of TabCandy,
     // we create a new group.
     let tabCandyContentDoc =
       Utils.getCurrentWindow().document.getElementById("tab-candy").
         contentDocument;
     iQ(tabCandyContentDoc).mousedown(function(e){
-      if ( e.originalTarget.id == "bg" )
+      if ( e.originalTarget.id == "content" )
         Page.createGroupOnDrag(e)
     });
 
     this.setupKeyHandlers();
 
     Tabs.onClose(function(){
       if (self.isTabCandyVisible()) {
         // just closed the selected tab in the tab candy interface.
--- a/browser/base/content/tabcandy/core/mirror.js
+++ b/browser/base/content/tabcandy/core/mirror.js
@@ -347,17 +347,17 @@ TabMirror.prototype = {
     // Add the tab to the page
     this._createEl(tab);
     return true;
   },
   
   unlink: function(tab){
     var mirror = tab.mirror;
     if (mirror) {
-      mirror._sendOnClose();
+      mirror._sendToSubscribers("close");
       var tabCanvas = mirror.tabCanvas;
       if (tabCanvas)
         tabCanvas.detach();
       
       iQ(mirror.el).remove();
       
       tab.mirror = null;
     }
--- a/browser/base/content/tabcandy/core/utils.js
+++ b/browser/base/content/tabcandy/core/utils.js
@@ -358,21 +358,18 @@ window.Range.prototype = {
       this.contains(value) :
       ( value.min <= this.max && this.min <= value.max );
   },
 };
 
 // ##########
 // Class: Subscribable
 // A mix-in for allowing objects to collect subscribers for custom events. 
-// Currently supports only onClose. 
-// TODO generalize for any number of events
 window.Subscribable = function() {
   this.subscribers = {};
-  this.onCloseSubscribers = null;
 };
 
 window.Subscribable.prototype = {
   // ----------
   // Function: addSubscriber
   // The given callback will be called when the Subscribable fires the given event.
   // The refObject is used to facilitate removal if necessary. 
   addSubscriber: function(refObject, eventName, callback) {
@@ -414,64 +411,16 @@ window.Subscribable.prototype = {
     if (!this.subscribers[eventName])
       return;
       
     var self = this;
     var subsCopy = iQ.merge([], this.subscribers[eventName]);
     subsCopy.forEach(function(object) { 
       object.callback(self, eventInfo);
     });
-  },
-  
-  // ----------
-  // Function: addOnClose
-  // The given callback will be called when the Subscribable fires its onClose.
-  // The referenceElement is used to facilitate removal if necessary. 
-  addOnClose: function(referenceElement, callback) {
-    if (!this.onCloseSubscribers)
-      this.onCloseSubscribers = [];
-      
-    var existing = this.onCloseSubscribers.filter(function(element) {
-      return element.referenceElement == referenceElement;
-    });
-    
-    if (existing.length) {
-      Utils.assert('should only ever be one', existing.length == 1);
-      existing[0].callback = callback;
-    } else {  
-      this.onCloseSubscribers.push({
-        referenceElement: referenceElement, 
-        callback: callback
-      });
-    }
-  },
-  
-  // ----------
-  // Function: removeOnClose
-  // Removes the callback associated with referenceElement for onClose notification. 
-  removeOnClose: function(referenceElement) {
-    if (!this.onCloseSubscribers)
-      return;
-      
-    this.onCloseSubscribers = this.onCloseSubscribers.filter(function(element) {
-      return element.referenceElement != referenceElement;
-    });
-  },
-  
-  // ----------
-  // Function: _sendOnClose
-  // Internal routine. Used by the Subscribable to fire onClose events.
-  _sendOnClose: function() {
-    if (!this.onCloseSubscribers)
-      return;
-      
-    var self = this;
-    this.onCloseSubscribers.forEach(function(object) {
-      object.callback(self);
-    });
   }
 };
 
 // ##########
 // Class: Utils
 // Singelton with common utility functions.
 var Utils = {
   _isMac : null,
--- a/browser/base/content/tabcandy/tabcandy.html
+++ b/browser/base/content/tabcandy/tabcandy.html
@@ -8,15 +8,15 @@
   <link rel="stylesheet" href="tabcandy.css" type="text/css"/>
   <link rel="stylesheet" href="chrome://browser/skin/tabcandy/platform.css" type="text/css"/>
 </head>
 
 <body style="background-color: transparent !important;-moz-appearance: none !important;" transparent="true">
   <div id="content">
     <div id="feedback" class="bottomButton">give feedback</div>  
     <div id="reset" class="bottomButton">reset</div>
+    <div id="bg" />
   </div>
-  <div id="bg" />
   
   <script type="text/javascript;version=1.8" src="tabcandy.js"></script>
   
 </body>
 </html>