Backout changeset 7fbc721aa455 (bug 634672) because it breaks the Mac mochitest-browser-chrome tests
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 31 Mar 2011 12:00:08 -0400
changeset 64516 841d44530d2fb5fea37fdd33a0a4ac44e8f21bc0
parent 64515 4c7d52ed5ccd786d362f756809a64e9ce67bc6d5
child 64517 e38b294f02c5a6254ac33c919b65fa0798325cb3
push idunknown
push userunknown
push dateunknown
bugs634672
milestone2.2a1pre
backs out7fbc721aa455a5926f30614a94fdaa401064fb77
Backout changeset 7fbc721aa455 (bug 634672) because it breaks the Mac mochitest-browser-chrome tests
browser/base/content/tabview/groupitems.js
browser/base/content/tabview/items.js
browser/base/content/tabview/tabitems.js
browser/base/content/test/tabview/Makefile.in
browser/base/content/test/tabview/browser_tabview_bug624953.js
browser/base/content/test/tabview/browser_tabview_bug625666.js
browser/base/content/test/tabview/browser_tabview_bug634672.js
browser/base/content/test/tabview/browser_tabview_expander.js
--- a/browser/base/content/tabview/groupitems.js
+++ b/browser/base/content/tabview/groupitems.js
@@ -1246,18 +1246,18 @@ GroupItem.prototype = Utils.extend(new I
       return false;
 
     var bb = this.getContentBounds();
     var options = {
       return: 'widthAndColumns',
       count: count || this._children.length,
       hideTitle: false
     };
-    let arrObj = Items.arrange(this._children, bb, options);
-
+    let arrObj = Items.arrange(null, bb, options);
+ 
     let shouldStack = arrObj.childWidth < TabItems.minTabWidth * 1.35;
     this._columns = shouldStack ? null : arrObj.columns;
 
     return shouldStack;
   },
 
   // ----------
   // Function: _freezeItemSize
--- a/browser/base/content/tabview/items.js
+++ b/browser/base/content/tabview/items.js
@@ -938,16 +938,17 @@ let Items = {
   //
   // Possible "options" properties:
   //   animate - whether to animate; default: true.
   //   z - the z index to set all the items; default: don't change z.
   //   return - if set to 'widthAndColumns', it'll return an object with the
   //     width of children and the columns.
   //   count - overrides the item count for layout purposes;
   //     default: the actual item count
+  //   padding - pixels between each item
   //   columns - (int) a preset number of columns to use
   //   dropPos - a <Point> which should have a one-tab space left open, used
   //             when a tab is dragged over.
   //
   // Returns:
   //   By default, an object with three properties: `rects`, the list of <Rect>s,
   //   `dropIndex`, the index which a dragged tab should have if dropped
   //   (null if no `dropPos` was specified), and the number of columns (`columns`).
--- a/browser/base/content/tabview/tabitems.js
+++ b/browser/base/content/tabview/tabitems.js
@@ -226,16 +226,26 @@ TabItem.prototype = Utils.extend(new Ite
   forceCanvasSize: function TabItem_forceCanvasSize(w, h) {
     this.canvasSizeForced = true;
     this.$canvas[0].width = w;
     this.$canvas[0].height = h;
     this.tabCanvas.paint();
   },
 
   // ----------
+  // Function: _getFontSizeFromWidth
+  // Private method that returns the fontsize to use given the tab's width
+  _getFontSizeFromWidth: function TabItem__getFontSizeFromWidth(width) {
+    let widthRange = new Range(0,TabItems.tabWidth);
+    let proportion = widthRange.proportion(width-TabItems.tabItemPadding.x, true);
+    // proportion is in [0,1]
+    return TabItems.fontSizeRange.scale(proportion);
+  },
+
+  // ----------
   // Function: unforceCanvasSize
   // Stops holding the thumbnail resolution; allows it to shift to the
   // size of thumbnail on screen. Note that this call does not nest, unlike
   // <TabItems.resumePainting>; if you call forceCanvasSize multiple
   // times, you just need a single unforce to clear them all.
   unforceCanvasSize: function TabItem_unforceCanvasSize() {
     this.canvasSizeForced = false;
   },
@@ -426,24 +436,26 @@ TabItem.prototype = Utils.extend(new Ite
     if (rect.left != this.bounds.left || options.force)
       css.left = rect.left;
 
     if (rect.top != this.bounds.top || options.force)
       css.top = rect.top;
 
     if (rect.width != this.bounds.width || options.force) {
       css.width = rect.width - TabItems.tabItemPadding.x;
-      css.fontSize = TabItems.getFontSizeFromWidth(rect.width);
+      css.fontSize = this._getFontSizeFromWidth(rect.width);
       css.fontSize += 'px';
     }
 
     if (rect.height != this.bounds.height || options.force) {
-      css.height = rect.height - TabItems.tabItemPadding.y;
       if (!this.isStacked)
-        css.height -= TabItems.fontSizeRange.max;
+          css.height = rect.height - TabItems.tabItemPadding.y -
+                       TabItems.fontSizeRange.max;
+      else
+        css.height = rect.height - TabItems.tabItemPadding.y;
     }
 
     if (Utils.isEmptyObject(css))
       return;
 
     this.bounds.copy(rect);
 
     // If this is a brand new tab don't animate it in from
@@ -1271,69 +1283,67 @@ let TabItems = {
     var sane = true;
     if (!Utils.isRect(data.bounds)) {
       Utils.log('TabItems.storageSanity: bad bounds', data.bounds);
       sane = false;
     }
 
     return sane;
   },
-
-  // ----------
-  // Function: getFontSizeFromWidth
-  // Private method that returns the fontsize to use given the tab's width
-  getFontSizeFromWidth: function TabItem_getFontSizeFromWidth(width) {
-    let widthRange = new Range(0, TabItems.tabWidth);
-    let proportion = widthRange.proportion(width - TabItems.tabItemPadding.x, true);
-    // proportion is in [0,1]
-    return TabItems.fontSizeRange.scale(proportion);
-  },
-
+  
   // ----------
   // Function: _getWidthForHeight
   // Private method that returns the tabitem width given a height.
-  _getWidthForHeight: function TabItems__getWidthForHeight(height) {
-    return height * TabItems.invTabAspect;
+  // Set options.hideTitle=true to measure without a title.
+  // Default is to measure with a title.
+  _getWidthForHeight: function TabItems__getWidthForHeight(height, options) {    
+    let titleSize = (options !== undefined && options.hideTitle === true) ? 
+      0 : TabItems.fontSizeRange.max;
+    return Math.max(0, Math.max(TabItems.minTabHeight, height - titleSize)) * 
+      TabItems.invTabAspect;
   },
 
   // ----------
   // Function: _getHeightForWidth
   // Private method that returns the tabitem height given a width.
-  _getHeightForWidth: function TabItems__getHeightForWidth(width) {
-    return width * TabItems.tabAspect;
+  // Set options.hideTitle=false to measure without a title.
+  // Default is to measure with a title.
+  _getHeightForWidth: function TabItems__getHeightForWidth(width, options) {
+    let titleSize = (options !== undefined && options.hideTitle === true) ? 
+      0 : TabItems.fontSizeRange.max;
+    return Math.max(0, Math.max(TabItems.minTabWidth,width)) *
+      TabItems.tabAspect + titleSize;
   },
-
+  
   // ----------
   // Function: calcValidSize
   // Pass in a desired size, and receive a size based on proper title
   // size and aspect ratio.
   calcValidSize: function TabItems_calcValidSize(size, options) {
     Utils.assert(Utils.isPoint(size), 'input is a Point');
-
-    let width = Math.max(TabItems.minTabWidth, size.x);
-    let showTitle = !options || !options.hideTitle;
-    let titleSize = showTitle ? TabItems.fontSizeRange.max : 0;
-    let height = Math.max(TabItems.minTabHeight, size.y - titleSize);
-    let retSize = new Point(width, height);
+    let retSize = new Point(0,0);
+    if (size.x==-1) {
+      retSize.x = this._getWidthForHeight(size.y, options);
+      retSize.y = size.y;
+    } else if (size.y==-1) {
+      retSize.x = size.x;
+      retSize.y = this._getHeightForWidth(size.x, options);
+    } else {
+      let fitHeight = this._getHeightForWidth(size.x, options);
+      let fitWidth = this._getWidthForHeight(size.y, options);
 
-    if (size.x > -1)
-      retSize.y = this._getHeightForWidth(width);
-    if (size.y > -1)
-      retSize.x = this._getWidthForHeight(height);
-
-    if (size.x > -1 && size.y > -1) {
-      if (retSize.x < size.x)
-        retSize.y = this._getHeightForWidth(retSize.x);
-      else
-        retSize.x = this._getWidthForHeight(retSize.y);
+      // Go with the smallest final dimension.
+      if (fitWidth < size.x) {
+        retSize.x = fitWidth;
+        retSize.y = size.y;
+      } else {
+        retSize.x = size.x;
+        retSize.y = fitHeight;
+      }
     }
-
-    if (showTitle)
-      retSize.y += titleSize;
-
     return retSize;
   }
 };
 
 // ##########
 // Class: TabPriorityQueue
 // Container that returns tab items in a priority order
 // Current implementation assigns tab to either a high priority
--- a/browser/base/content/test/tabview/Makefile.in
+++ b/browser/base/content/test/tabview/Makefile.in
@@ -100,17 +100,16 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug623768.js \
                  browser_tabview_bug624265.js \
                  browser_tabview_bug624931.js \
                  browser_tabview_bug624727.js \
                  browser_tabview_bug624847.js \
                  browser_tabview_bug624953.js \
                  browser_tabview_bug625269.js \
                  browser_tabview_bug625424.js \
-                 browser_tabview_bug625666.js \
                  browser_tabview_bug626368.js \
                  browser_tabview_bug626525.js \
                  browser_tabview_bug626791.js \
                  browser_tabview_bug627288.js \
                  browser_tabview_bug627736.js \
                  browser_tabview_bug628165.js \
                  browser_tabview_bug628270.js \
                  browser_tabview_bug629189.js \
@@ -118,17 +117,16 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug630102.js \
                  browser_tabview_bug630157.js \
                  browser_tabview_bug631662.js \
                  browser_tabview_bug631752.js \
                  browser_tabview_bug633788.js \
                  browser_tabview_bug634077.js \
                  browser_tabview_bug634085.js \
                  browser_tabview_bug634158.js \
-                 browser_tabview_bug634672.js \
                  browser_tabview_bug635696.js \
                  browser_tabview_dragdrop.js \
                  browser_tabview_exit_button.js \
                  browser_tabview_expander.js \
                  browser_tabview_firstrun_pref.js \
                  browser_tabview_group.js \
                  browser_tabview_launch.js \
                  browser_tabview_multiwindow_search.js \
--- a/browser/base/content/test/tabview/browser_tabview_bug624953.js
+++ b/browser/base/content/test/tabview/browser_tabview_bug624953.js
@@ -1,23 +1,39 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 function test() {
   waitForExplicitFinish();
 
+  let finishTest = function (groupItem) {
+    groupItem.addSubscriber(groupItem, 'groupHidden', function () {
+      groupItem.removeSubscriber(groupItem, 'groupHidden');
+      groupItem.closeHidden();
+      hideTabView(finish);
+    });
+
+    groupItem.closeAll();
+  }
+
   showTabView(function () {
     let cw = TabView.getContentWindow();
 
-    let groupItem = createGroupItemWithBlankTabs(window, 200, 240, 20, 4)
-    ok(!groupItem.isStacked(), 'groupItem is not stacked');
+    let bounds = new cw.Rect(20, 20, 150, 200);
+    let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true});
+    cw.GroupItems.setActiveGroupItem(groupItem);
+
+    for (let i=0; i<4; i++)
+      gBrowser.loadOneTab('about:blank', {inBackground: true});
+
+    ok(!groupItem._isStacked, 'groupItem is not stacked');
     cw.GroupItems.pauseArrange();
 
-    groupItem.setSize(100, 100, true);
+    groupItem.setSize(150, 150);
     groupItem.setUserSize();
-    ok(!groupItem.isStacked(), 'groupItem is still not stacked');
+    ok(!groupItem._isStacked, 'groupItem is still not stacked');
 
     cw.GroupItems.resumeArrange();
-    ok(groupItem.isStacked(), 'groupItem is now stacked');
+    ok(groupItem._isStacked, 'groupItem is now stacked');
 
-    closeGroupItem(groupItem, finish);
+    finishTest(groupItem);
   });
 }
deleted file mode 100644
--- a/browser/base/content/test/tabview/browser_tabview_bug625666.js
+++ /dev/null
@@ -1,49 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
-function test() {
-  let cw;
-
-  let getTabItemAspect = function (tabItem) {
-    let bounds = cw.iQ('.thumb', tabItem.container).bounds();
-    let padding = cw.TabItems.tabItemPadding;
-    return (bounds.height + padding.y) / (bounds.width + padding.x);
-  }
-
-  let getAspectRange = function () {
-    let aspect = cw.TabItems.tabAspect;
-    let variance = aspect / 100 * 1.5;
-    return new cw.Range(aspect - variance, aspect + variance);
-  }
-
-  waitForExplicitFinish();
-
-  newWindowWithTabView(function (win) {
-    registerCleanupFunction(function () win.close());
-    cw = win.TabView.getContentWindow();
-
-    // prepare orphan tab
-    let tabItem = win.gBrowser.tabs[0]._tabViewTabItem;
-    tabItem.parent.remove(tabItem, {immediately: true});
-    tabItem.setBounds(new cw.Rect(20, 20, 200, 165), true);
-
-    let bounds = tabItem.getBounds();
-
-    // prepare group item
-    let box = new cw.Rect(20, 300, 400, 200);
-    let groupItem = new cw.GroupItem([], {bounds: box, immediately: true});
-
-    groupItem.setBounds(new cw.Rect(20, 100, 400, 200));
-    groupItem.pushAway(true);
-
-    let newBounds = tabItem.getBounds();
-    ok(newBounds.width < bounds.width, "The new width of item is smaller than the old one.");
-    ok(newBounds.height < bounds.height, "The new height of item is smaller than the old one.");
-
-    let aspectRange = getAspectRange();
-    let aspect = getTabItemAspect(tabItem);
-    ok(aspectRange.contains(aspect), "orphaned tabItem's aspect is correct");
-
-    finish();
-  });
-}
deleted file mode 100644
--- a/browser/base/content/test/tabview/browser_tabview_bug634672.js
+++ /dev/null
@@ -1,52 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
-function test() {
-  let cw;
-  let win;
-
-  waitForExplicitFinish();
-
-  newWindowWithTabView(function (tvwin) {
-    win = tvwin;
-    cw = win.TabView.getContentWindow();
-
-    registerCleanupFunction(function () {
-      if (win && !win.closed)
-        win.close();
-    });
-
-    // fill the group item with some tabs
-    for (let i = 0; i < 5; i++)
-      win.gBrowser.loadOneTab("about:blank");
-
-    let groupItem = cw.GroupItems.groupItems[0];
-    groupItem.setSize(400, 400, true);
-    let range = new cw.Range(1, 400);
-
-    // determine the groupItem's largest possible stacked size
-    while (range.extent > 1) {
-      let pivot = Math.floor(range.extent / 2);
-      groupItem.setSize(range.min + pivot, range.min + pivot, true);
-
-      if (groupItem.isStacked())
-        range.min += pivot;
-      else
-        range.max -= pivot;
-    }
-
-    // stack the group
-    groupItem.setSize(range.min, range.min, true);
-    ok(groupItem.isStacked(), "groupItem is stacked");
-
-    // one step back to un-stack the groupItem
-    groupItem.setSize(range.max, range.max, true);
-    ok(!groupItem.isStacked(), "groupItem is no longer stacked");
-
-    // check that close buttons are visible
-    let tabItem = groupItem.getChild(0);
-    isnot(tabItem.$close.css("display"), "none", "close button is visible");
-
-    finish();
-  });
-}
--- a/browser/base/content/test/tabview/browser_tabview_expander.js
+++ b/browser/base/content/test/tabview/browser_tabview_expander.js
@@ -12,17 +12,17 @@ function onTabViewWindowLoaded(win) {
 
   let contentWindow = win.document.getElementById("tab-view").contentWindow;
   let [originalTab] = win.gBrowser.visibleTabs;
   let currentGroup = contentWindow.GroupItems.getActiveGroupItem();
   
   // let's create a group small enough to get stacked
   let group = new contentWindow.GroupItem([], {
     immediately: true,
-    bounds: {left: 20, top: 300, width: 400, height: 400}
+    bounds: {left: 20, top: 300, width: 300, height: 300}
   });
 
   let expander = contentWindow.iQ(group.container).find(".stackExpander");
   ok("length" in expander && expander.length == 1, "The group has an expander.");
 
   // procreate!
   contentWindow.GroupItems.setActiveGroupItem(group);
   for (var i=0; i<7; i++) {