+ Items now has a squishMode variable you can set to one of three possible ways to deal with items getting pushed off the screen: resize the whole set, squish only the ones getting pushed off, let them get pushed off but then have them push back on when there's room
authorIan Gilman <iangilman@gmail.com>
Tue, 20 Apr 2010 15:42:06 -0700
changeset 49814 cda9397c94671405cd214f65bf1d4513c46f1c30
parent 49813 bf82e65923f39a49927c68945fed0b18ed3bfaab
child 49815 fc0c5f55e3ac99ef8972a45671470760097f98d3
push idunknown
push userunknown
push dateunknown
+ Items now has a squishMode variable you can set to one of three possible ways to deal with items getting pushed off the screen: resize the whole set, squish only the ones getting pushed off, let them get pushed off but then have them push back on when there's room
browser/base/content/tabcandy/app/groups.js
browser/base/content/tabcandy/app/items.js
--- a/browser/base/content/tabcandy/app/groups.js
+++ b/browser/base/content/tabcandy/app/groups.js
@@ -31,16 +31,17 @@ function isEventOverElement(event, el){
 // A single group in the tab candy window. Descended from <Item>.
 // Note that it implements the <Subscribable> interface.
 window.Group = function(listOfEls, options) {
   if(typeof(options) == 'undefined')
     options = {};
 
   this._children = []; // an array of Items
   this.defaultSize = new Point(TabItems.tabWidth * 1.5, TabItems.tabHeight * 1.5);
+  this.locked = options.locked || false;
 
   var self = this;
 
   var rectToBe = options.bounds;
   if(!rectToBe) {
     var boundingBox = this._getBoundingBox(listOfEls);
     var padding = 30;
     rectToBe = new Rect(
@@ -579,18 +580,17 @@ window.Groups = {
     setTimeout(function() {
       // we do this in a timeout, as window.innerHeight hasn't adjusted for Firebug initially
       var pad = 5;
       var sw = window.innerWidth;
       var sh = window.innerHeight;
       var w = sw - (pad * 2);
       var h = TabItems.tabHeight;
       var box = new Rect(pad, sh - (h + pad), w, h);
-      self.newTabGroup = new Group([], {bounds: box, title: 'New Tabs'}); 
-      self.newTabGroup.locked = true;
+      self.newTabGroup = new Group([], {bounds: box, title: 'New Tabs', locked: true}); 
     }, 1000);
   },
 
   // ----------  
   register: function(group) {
     Utils.assert('only register once per group', $.inArray(group, this.groups) == -1);
     this.groups.push(group);
   },
--- a/browser/base/content/tabcandy/app/items.js
+++ b/browser/base/content/tabcandy/app/items.js
@@ -177,17 +177,17 @@ window.Item.prototype = {
       });
     };   
     
     while(itemsToPush.length)
       pushOne(itemsToPush.shift());         
 
     // ___ Squish!
     var pageBounds = Items.getPageBounds();
-    if(true) {
+    if(Items.squishMode == 'squish') {
       $.each(items, function(index, item) {
         var data = item.pushAwayData;
         if(data.generation == 0 || item.locked)
           return;
   
         function apply(item, posStep, posStep2, sizeStep) {
           var data = item.pushAwayData;
           if(data.generation == 0)
@@ -239,43 +239,76 @@ window.Item.prototype = {
           sizeStep.y = -posStep.y / data.generation;
           posStep.y += sizeStep.y;
           posStep2.y = sizeStep.y;
         }
   
         if(posStep.x || posStep.y || sizeStep.x || sizeStep.y) 
           apply(item, posStep, posStep2, sizeStep);
       });
+    } else if(Items.squishMode == 'all') {
+      var newPageBounds = null;
+      $.each(items, function(index, item) {
+        if(item.locked)
+          return;
+          
+        var data = item.pushAwayData;
+        var bounds = data.bounds;
+        newPageBounds = (newPageBounds ? newPageBounds.union(bounds) : new Rect(bounds));
+      });
+      
+      var wScale = pageBounds.width / newPageBounds.width;
+      var hScale = pageBounds.height / newPageBounds.height;
+      var scale = Math.min(hScale, wScale);
+      $.each(items, function(index, item) {
+        if(item.locked)
+          return;
+          
+        var data = item.pushAwayData;
+        var bounds = data.bounds;
+
+        bounds.left -= newPageBounds.left;
+        bounds.left *= scale;
+        bounds.width *= scale;
+
+        bounds.top -= newPageBounds.top;            
+        bounds.top *= scale;
+        bounds.height *= scale;
+      });
     }
 
     // ___ Unsquish
     $.each(items, function(index, item) {
+      if(item.locked)
+        return;
+        
       var data = item.pushAwayData;
       var bounds = data.bounds;
+      var newBounds = new Rect(bounds);
       if(bounds.width < TabItems.tabWidth) {
-        var available = new Rect(pageBounds);
-        var newBounds = new Rect(bounds);
         newBounds.left -= (TabItems.tabWidth - newBounds.width) / 2;
         newBounds.top -= (TabItems.tabHeight - newBounds.height) / 2;
         newBounds.width = TabItems.tabWidth;
         newBounds.height = TabItems.tabHeight;
+      }
         
-        var offset = new Point();
-        if(newBounds.left < pageBounds.left)
-          offset.x = pageBounds.left - newBounds.left;
-        else if(newBounds.right > pageBounds.right)
-          offset.x = pageBounds.right - newBounds.right;
+      var offset = new Point();
+      if(newBounds.left < pageBounds.left)
+        offset.x = pageBounds.left - newBounds.left;
+      else if(newBounds.right > pageBounds.right)
+        offset.x = pageBounds.right - newBounds.right;
 
-        if(newBounds.top < pageBounds.top)
-          offset.y = pageBounds.top - newBounds.top;
-        else if(newBounds.bottom > pageBounds.bottom)
-          offset.y = pageBounds.bottom - newBounds.bottom;
-          
-        newBounds.offset(offset);
+      if(newBounds.top < pageBounds.top)
+        offset.y = pageBounds.top - newBounds.top;
+      else if(newBounds.bottom > pageBounds.bottom)
+        offset.y = pageBounds.bottom - newBounds.bottom;
         
+      newBounds.offset(offset);
+
+      if(!bounds.equals(newBounds)) {        
         var blocked = false;
         $.each(items, function(index, item2) {
           if(item2 == item)
             return;
             
           var data2 = item2.pushAwayData;
           var bounds2 = data2.bounds;
           if(bounds2.intersects(newBounds)) {
@@ -315,16 +348,22 @@ window.Item.prototype = {
   }  
 };  
 
 // ##########
 // Class: Items
 // Keeps track of all Items. 
 window.Items = {
   // ----------
+  // Variable: squishMode
+  // How to deal when things go off the edge.
+  // Options include: all, squish, push
+  squishMode: 'squish', 
+  
+  // ----------
   // Function: init
   // Initialize the object
   init: function() {
   },
   
   // ----------  
   // Function: item
   // Given a DOM element representing an Item, returns the Item.