+ Added Math.tanh by way of utils
authorAza Raskin <aza@mozilla.com>
Wed, 28 Apr 2010 13:17:43 -0700
changeset 49831 b6436f2336f12ef01622f4cc0a11b501f9d69ed4
parent 49830 a23cfd4d924b33684edac4833243cc3445f0b216
child 49832 5a18a632ca355f9365876d0eb2b8715339152fc5
child 49833 5b3ef2044072ed06afeeeb56c552f2275bd260e8
push idunknown
push userunknown
push dateunknown
+ Added Math.tanh by way of utils + Added a minimum and maximum scale
browser/base/content/tabcandy/app/tabitems.js
browser/base/content/tabcandy/core/utils.js
--- a/browser/base/content/tabcandy/app/tabitems.js
+++ b/browser/base/content/tabcandy/app/tabitems.js
@@ -60,61 +60,57 @@ window.TabItem.prototype = $.extend(new 
   // ----------  
   setBounds: function(rect, immediately) {
     var $container = $(this.container);
     var $title = $('.tab-title', $container);
     var $thumb = $('.thumb', $container);
     var $close = $('.close', $container);
     var extra = this._getSizeExtra();
     var css = {};
+    
+    const minFontSize = 6;
+    const maxFontSize = 15;
 
     if(rect.left != this.bounds.left)
       css.left = rect.left;
       
     if(rect.top != this.bounds.top)
       css.top = rect.top;
       
     if(rect.width != this.bounds.width) {
       css.width = rect.width - extra.x;
       var scale = css.width / TabItems.tabWidth;
-      css.fontSize = TabItems.fontSize * scale;
-      if( css.fontSize < 10 ){
-        css.fontSize = 10;
-      }
+      
+      // The ease function ".5+.5*Math.tanh(2*x-2)" is a pretty
+      // little graph. It goes from near 0 at x=0 to near 1 at x=2
+      // smoothly and beautifully.
+      css.fontSize = minFontSize + (maxFontSize-minFontSize)*(.5+.5*Math.tanh(2*scale-2))
     }
 
     if(rect.height != this.bounds.height) {
       css.height = rect.height - extra.y; 
     }
       
     if($.isEmptyObject(css))
       return;
       
     this.bounds.copy(rect);
 
     if(immediately) {
       $container.css(css);
       
-/*
-      if(css.fontSize) {
-        if(css.fontSize < 8)
-          $title.hide();
-        else
-          $title.show();
-      }
-*/
     } else {
       TabMirror.pausePainting();
       $container.animate(css, {complete: function() {
         TabMirror.resumePainting();
       }}).dequeue();
     }
 
     if(css.fontSize) {
-      if(css.fontSize < 8)
+      if(css.fontSize < minFontSize)
         $title.fadeOut();
       else
         $title.fadeIn();
     }
 
     if(css.width) {
       if(css.width < 30) {
         $thumb.fadeOut();
--- a/browser/base/content/tabcandy/core/utils.js
+++ b/browser/base/content/tabcandy/core/utils.js
@@ -415,9 +415,14 @@ var Utils = {
   isJQuery: function(object) {
     // TODO: need more robust way 
     return (object && typeof(object.fadeIn) == 'function' ? true : false);
   }   
 };
 
 window.Utils = Utils;
 
+window.Math.tanh = function tanh(x){
+  var e = Math.exp(x);
+  return (e - 1/e) / (e + 1/e); 
+}
+
 })();