From bff49321b02679167edb67b28a3e9ea50eec7a56 Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Fri, 21 Jan 2011 04:25:18 +0100 Subject: [PATCH] Bug 613541 - Panorama closes browser window when closing 'undo close group' r=ian a=blocking --- browser/base/content/tabview/groupitems.js | 22 + browser/base/content/tabview/ui.js | 20 +- browser/base/content/test/tabview/Makefile.in | 1 + .../test/tabview/browser_tabview_bug613541.js | 396 ++++++++++++++++++ 4 files changed, 431 insertions(+), 8 deletions(-) create mode 100644 browser/base/content/test/tabview/browser_tabview_bug613541.js diff --git a/browser/base/content/tabview/groupitems.js b/browser/base/content/tabview/groupitems.js index bd0a05b5c82f..58d249331dae 100644 --- a/browser/base/content/tabview/groupitems.js +++ b/browser/base/content/tabview/groupitems.js @@ -641,6 +641,20 @@ GroupItem.prototype = Utils.extend(new Item(), new Subscribable(), { this._cancelFadeAwayUndoButtonTimer(); + // When the last non-empty groupItem is closed and there are no orphan or + // pinned tabs then create a new group with a blank tab. + let remainingGroups = GroupItems.groupItems.filter(function (groupItem) { + return (groupItem != self && groupItem.getChildren().length); + }); + if (!gBrowser._numPinnedTabs && !GroupItems.getOrphanedTabs().length && + !remainingGroups.length) { + let emptyGroups = GroupItems.groupItems.filter(function (groupItem) { + return (groupItem != self && !groupItem.getChildren().length); + }); + let group = (emptyGroups.length ? emptyGroups[0] : GroupItems.newGroup()); + group.newTab(); + } + // when "TabClose" event is fired, the browser tab is about to close and our // item "close" event is fired. And then, the browser tab gets closed. // In other words, the group "close" event is fired before all browser @@ -1673,6 +1687,14 @@ let GroupItems = { this.groupItems = null; }, + // ---------- + // Function: newGroup + // Creates a new empty group. + newGroup: function () { + let bounds = new Rect(20, 20, 250, 200); + return new GroupItem([], {bounds: bounds, immediately: true}); + }, + // ---------- // Function: pauseArrange // Bypass arrange() calls and collect for resolution in diff --git a/browser/base/content/tabview/ui.js b/browser/base/content/tabview/ui.js index b183381b56f0..0d750c59ebfc 100644 --- a/browser/base/content/tabview/ui.js +++ b/browser/base/content/tabview/ui.js @@ -25,6 +25,7 @@ * Ehsan Akhgari * Raymond Lee * Sean Dunn + * Tim Taubert * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -1356,14 +1357,17 @@ let UI = { let unhiddenGroups = GroupItems.groupItems.filter(function(groupItem) { return (!groupItem.hidden && groupItem.getChildren().length > 0); }); - // no visible groups, no orphaned tabs and no apps tabs, open a new group - // with a blank tab - if (unhiddenGroups.length == 0 && GroupItems.getOrphanedTabs().length == 0 && - gBrowser._numPinnedTabs == 0) { - let box = new Rect(20, 20, 250, 200); - let groupItem = new GroupItem([], { bounds: box, immediately: true }); - groupItem.newTab(); - return; + // no pinned tabs, no visible groups and no orphaned tabs: open a new + // group. open a blank tab and return + if (!unhiddenGroups.length && !GroupItems.getOrphanedTabs().length) { + let emptyGroups = GroupItems.groupItems.filter(function (groupItem) { + return (!groupItem.hidden && !groupItem.getChildren().length); + }); + let group = (emptyGroups.length ? emptyGroups[0] : GroupItems.newGroup()); + if (!gBrowser._numPinnedTabs) { + group.newTab(); + return; + } } // If there's an active TabItem, zoom into it. If not (for instance when the diff --git a/browser/base/content/test/tabview/Makefile.in b/browser/base/content/test/tabview/Makefile.in index 1ecf79f65229..24ad20ea3bb8 100644 --- a/browser/base/content/test/tabview/Makefile.in +++ b/browser/base/content/test/tabview/Makefile.in @@ -80,6 +80,7 @@ _BROWSER_FILES = \ browser_tabview_bug608184.js \ browser_tabview_bug608158.js \ browser_tabview_bug610242.js \ + browser_tabview_bug613541.js \ browser_tabview_bug616729.js \ browser_tabview_bug616967.js \ browser_tabview_bug618828.js \ diff --git a/browser/base/content/test/tabview/browser_tabview_bug613541.js b/browser/base/content/test/tabview/browser_tabview_bug613541.js new file mode 100644 index 000000000000..3fbc71d2f149 --- /dev/null +++ b/browser/base/content/test/tabview/browser_tabview_bug613541.js @@ -0,0 +1,396 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is a test for bug 613541. + * + * The Initial Developer of the Original Code is + * Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Tim Taubert + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +function test() { + let cw; + let currentTest; + + let getGroupItem = function (index) { + return cw.GroupItems.groupItems[index]; + } + + let createGroupItem = function (numTabs) { + let bounds = new cw.Rect(20, 20, 200, 200); + let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true}); + cw.GroupItems.setActiveGroupItem(groupItem); + + for (let i=0; i