Bug 608407 - GroupItems.getActiveOrphanTab should use UI.getActiveTabRef r=ian

This commit is contained in:
Raymond Lee 2011-04-04 10:27:50 +08:00
parent 48d2bcf2f6
commit f5d57e79a6
4 changed files with 33 additions and 65 deletions

View File

@ -708,17 +708,10 @@ GroupItem.prototype = Utils.extend(new Item(), new Subscribable(), {
let closestTabItem = UI.getClosestTab(closeCenter);
UI.setActiveTab(closestTabItem);
// set the active group or orphan tabitem.
if (closestTabItem) {
if (closestTabItem.parent) {
GroupItems.setActiveGroupItem(closestTabItem.parent);
} else {
GroupItems.setActiveOrphanTab(closestTabItem);
}
} else {
if (closestTabItem && closestTabItem.parent)
GroupItems.setActiveGroupItem(closestTabItem.parent);
else
GroupItems.setActiveGroupItem(null);
GroupItems.setActiveOrphanTab(null);
}
},
// ----------
@ -2256,7 +2249,7 @@ let GroupItems = {
return;
}
let orphanTabItem = this.getActiveOrphanTab();
let orphanTabItem = UI.getActiveOrphanTab();
if (!orphanTabItem) {
let targetGroupItem;
// find first visible non-app tab in the tabbar.
@ -2347,34 +2340,12 @@ let GroupItems = {
if (groupItem !== null) {
if (groupItem)
iQ(groupItem.container).addClass('activeGroupItem');
// if a groupItem is active, we surely are not in an orphaned tab.
this.setActiveOrphanTab(null);
}
this._activeGroupItem = groupItem;
this._save();
},
// ----------
// Function: getActiveOrphanTab
// Returns the active orphan tab, in cases when there is no active groupItem.
getActiveOrphanTab: function GroupItems_getActiveOrphanTab() {
return this._activeOrphanTab;
},
// ----------
// Function: setActiveOrphanTab
// In cases where an orphan tab (not in a groupItem) is active by itself,
// this function is called and the "active orphan tab" is set.
//
// Paramaters:
// groupItem - the active <TabItem> or <null>
setActiveOrphanTab: function GroupItems_setActiveOrphanTab(tabItem) {
if (tabItem !== null)
this.setActiveGroupItem(null);
this._activeOrphanTab = tabItem;
},
// ----------
// Function: _updateTabBar
// Hides and shows tabs in the tab bar based on the active groupItem or
@ -2382,14 +2353,18 @@ let GroupItems = {
_updateTabBar: function GroupItems__updateTabBar() {
if (!window.UI)
return; // called too soon
if (!this._activeGroupItem && !this._activeOrphanTab) {
Utils.assert(false, "There must be something to show in the tab bar!");
return;
let activeOrphanTab;
if (!this._activeGroupItem) {
activeOrphanTab = UI.getActiveOrphanTab();
if (!activeOrphanTab) {
Utils.assert(false, "There must be something to show in the tab bar!");
return;
}
}
let tabItems = this._activeGroupItem == null ?
[this._activeOrphanTab] : this._activeGroupItem._children;
[activeOrphanTab] : this._activeGroupItem._children;
gBrowser.showOnlyTheseTabs(tabItems.map(function(item) item.tab));
},
@ -2400,12 +2375,9 @@ let GroupItems = {
Utils.assertThrow(tabItem && tabItem.isATabItem, "tabItem must be a TabItem");
let groupItem = tabItem.parent;
if (groupItem) {
this.setActiveGroupItem(groupItem);
this.setActiveGroupItem(groupItem);
if (groupItem)
groupItem.setActiveTab(tabItem);
} else
this.setActiveOrphanTab(tabItem);
this._updateTabBar();
},
@ -2429,7 +2401,7 @@ let GroupItems = {
getNextGroupItemTab: function GroupItems_getNextGroupItemTab(reverse) {
var groupItems = Utils.copy(GroupItems.groupItems);
var activeGroupItem = GroupItems.getActiveGroupItem();
var activeOrphanTab = GroupItems.getActiveOrphanTab();
var activeOrphanTab = UI.getActiveOrphanTab();
var tabItem = null;
if (reverse)

View File

@ -643,11 +643,7 @@ TabItem.prototype = Utils.extend(new Item(), new Subscribable(), {
let $canvas = this.$canvas;
UI.setActiveTab(this);
if (this.parent) {
GroupItems.setActiveGroupItem(this.parent);
} else {
GroupItems.setActiveOrphanTab(this);
}
GroupItems.setActiveGroupItem(this.parent);
TabItems._update(this.tab, {force: true});
@ -713,8 +709,6 @@ TabItem.prototype = Utils.extend(new Item(), new Subscribable(), {
$tab.removeClass("front");
$canvas.css("-moz-transform", null);
GroupItems.setActiveOrphanTab(null);
if (typeof complete == "function")
complete();
};
@ -1093,8 +1087,8 @@ let TabItems = {
Utils.assertThrow(tab._tabViewTabItem, "should already be linked");
// note that it's ok to unlink an app tab; see .handleTabUnpin
if (tab._tabViewTabItem == GroupItems.getActiveOrphanTab())
GroupItems.setActiveOrphanTab(null);
if (tab._tabViewTabItem == UI.getActiveOrphanTab())
UI.setActiveTab(null);
this.unregister(tab._tabViewTabItem);
tab._tabViewTabItem._sendToSubscribers("close");

View File

@ -206,7 +206,7 @@ let UI = {
TabItems.tabWidth, TabItems.tabHeight);
newTab._tabViewTabItem.setBounds(box, true);
newTab._tabViewTabItem.pushAway(true);
GroupItems.setActiveOrphanTab(newTab._tabViewTabItem);
UI.setActiveTab(newTab._tabViewTabItem);
TabItems.creatingNewOrphanTab = false;
newTab._tabViewTabItem.zoomIn(true);
@ -356,9 +356,9 @@ let UI = {
GroupItems.setActiveGroupItem(groupItem);
},
// ----------
// Function: blurAll
// Blurs any currently focused element
//
blurAll: function UI_blurAll() {
iQ(":focus").each(function(element) {
element.blur();
@ -380,7 +380,6 @@ let UI = {
// ----------
// Function: getActiveTab
// Returns the currently active tab as a <TabItem>
//
getActiveTab: function UI_getActiveTab() {
return this._activeTab;
},
@ -415,6 +414,13 @@ let UI = {
}
},
// ----------
// Function: getActiveOrphanTab
// Returns the currently active orphan tab as a <TabItem>
getActiveOrphanTab: function UI_getActiveOrphanTab() {
return (this._activeTab && !this._activeTab.parent) ? this._activeTab : null;
},
// ----------
// Function: isTabViewVisible
// Returns true if the TabView UI is currently shown.
@ -476,7 +482,7 @@ let UI = {
// closed all other tabs. (If the user is looking at an orphan tab, then
// there is no active group for the purposes of this check.)
let activeGroupItem = null;
if (!GroupItems.getActiveOrphanTab()) {
if (!UI.getActiveOrphanTab()) {
activeGroupItem = GroupItems.getActiveGroupItem();
if (activeGroupItem && activeGroupItem.closeIfEmpty())
activeGroupItem = null;
@ -863,22 +869,18 @@ let UI = {
// No tabItem; must be an app tab. Base the tab bar on the current group.
// If no current group or orphan tab, figure it out based on what's
// already in the tab bar.
if (!GroupItems.getActiveGroupItem() && !GroupItems.getActiveOrphanTab()) {
if (!GroupItems.getActiveGroupItem() && !UI.getActiveOrphanTab()) {
for (let a = 0; a < gBrowser.tabs.length; a++) {
let theTab = gBrowser.tabs[a];
if (!theTab.pinned) {
let tabItem = theTab._tabViewTabItem;
if (tabItem.parent)
GroupItems.setActiveGroupItem(tabItem.parent);
else
GroupItems.setActiveOrphanTab(tabItem);
GroupItems.setActiveGroupItem(tabItem.parent);
break;
}
}
}
if (GroupItems.getActiveGroupItem() || GroupItems.getActiveOrphanTab())
if (GroupItems.getActiveGroupItem() || UI.getActiveOrphanTab())
GroupItems._updateTabBar();
}
},

View File

@ -62,7 +62,7 @@ function part1(win) {
let groupItems = contentWindow.GroupItems.groupItems;
is(groupItems.length, 1, "Only one group");
ok(!contentWindow.GroupItems.getActiveOrphanTab(), "There is no active orphan tab.");
ok(!contentWindow.UI.getActiveOrphanTab(), "There is no active orphan tab.");
ok(win.TabView.isVisible(), "Tab View is visible.");
win.gBrowser.tabContainer.addEventListener("TabSelect", function() {