Bug 680686 - Remove AllTabs.jsm until the all-windows feature gets properly implemented; r=dao

This commit is contained in:
Tim Taubert 2011-08-21 10:41:17 +02:00
Родитель 4e79012cc6
Коммит b1673c8818
7 изменённых файлов: 71 добавлений и 236 удалений

Просмотреть файл

@ -231,7 +231,7 @@ function GroupItem(listOfEls, options) {
.appendTo(appTabTrayContainer);
AllTabs.tabs.forEach(function(xulTab) {
if (xulTab.pinned && xulTab.ownerDocument.defaultView == gWindow)
if (xulTab.pinned)
self.addAppTab(xulTab, {dontAdjustTray: true});
});
@ -1926,13 +1926,13 @@ let GroupItems = {
let self = this;
// setup attr modified handler, and prepare for its uninit
function handleAttrModified(xulTab) {
self._handleAttrModified(xulTab);
function handleAttrModified(event) {
self._handleAttrModified(event.target);
}
// make sure any closed tabs are removed from the delay update list
function handleClose(xulTab) {
let idx = self._delayedModUpdates.indexOf(xulTab);
function handleClose(event) {
let idx = self._delayedModUpdates.indexOf(event.target);
if (idx != -1)
self._delayedModUpdates.splice(idx, 1);
}
@ -2040,7 +2040,7 @@ let GroupItems = {
// Function: _updateAppTabIcons
// Update images of any apptab icons that point to passed in xultab
_updateAppTabIcons: function GroupItems__updateAppTabIcons(xulTab) {
if (xulTab.ownerDocument.defaultView != gWindow || !xulTab.pinned)
if (!xulTab.pinned)
return;
let iconUrl = this.getAppTabFavIconUrl(xulTab);

Просмотреть файл

@ -1,183 +0,0 @@
/* ***** 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 TabView AllTabs.
*
* 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):
* Edward Lee <edilee@mozilla.com>
*
* 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 ***** */
"use strict";
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
let EXPORTED_SYMBOLS = ["AllTabs"];
let AllTabs = {
// ----------
// Function: toString
// Prints [AllTabs] for debug use
toString: function AllTabs_toString() {
return "[AllTabs]";
},
/**
* Get an array of all tabs from all tabbrowser windows.
*
* @usage let numAllTabs = AllTabs.tabs.length;
* AllTabs.tabs.forEach(handleAllTabs);
*/
get tabs() {
// Get tabs from each browser window and flatten them into one array
return Array.concat.apply(null, browserWindows.map(function(browserWindow) {
return Array.filter(browserWindow.gBrowser.tabs, function (tab) !tab.closing);
}));
},
/**
* Attach a callback for a given tab event.
*
* @param eventName
* Name of the corresponding Tab* Event; one of "attrModified",
* "close", "move", "open", "select", "pinned", "unpinned".
* @param callback
* Callback that gets called with the tab as the first argument and
* the event as the second argument.
* @usage AllTabs.register("change", function handleChange(tab, event) {});
*/
register: function register(eventName, callback) {
// Either add additional callbacks or create the first entry
let listeners = eventListeners[events[eventName]];
if (listeners)
listeners.push(callback);
else
eventListeners[events[eventName]] = [callback];
},
/**
* Remove a callback for a given tab event.
*
* @param eventName
* Name of the corresponding Tab* Event; one of "attrModified",
* "close", "move", "open", "select", "pinned", "unpinned".
* @param callback
* The callback given for the original AllTabs.register call.
* @usage AllTabs.unregister("close", handleClose);
*/
unregister: function unregister(eventName, callback) {
// Nothing to remove for this event
let listeners = eventListeners[events[eventName]];
if (!listeners)
return;
// Can only remove a callback if we have it
let index = listeners.indexOf(callback);
if (index == -1)
return;
listeners.splice(index, 1);
}
};
__defineGetter__("browserWindows", function browserWindows() {
let browserWindows = [];
let windows = Services.wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements())
browserWindows.push(windows.getNext());
return browserWindows;
});
let events = {
attrModified: "TabAttrModified",
close: "TabClose",
move: "TabMove",
open: "TabOpen",
select: "TabSelect",
pinned: "TabPinned",
unpinned: "TabUnpinned"
};
let eventListeners = {};
function registerBrowserWindow(browserWindow) {
for each (let event in events)
browserWindow.addEventListener(event, tabEventListener, true);
browserWindow.addEventListener("unload", unregisterBrowserWindow, false);
}
function unregisterBrowserWindow(unloadEvent) {
let browserWindow = unloadEvent.currentTarget;
for each (let event in events)
browserWindow.removeEventListener(event, tabEventListener, true);
browserWindow.removeEventListener("unload", unregisterBrowserWindow, false);
}
function tabEventListener(event) {
// Make sure we've gotten listeners before trying to call
let listeners = eventListeners[event.type];
if (!listeners)
return;
let tab = event.target;
// Make a copy of the listeners, so it can't change as we call back
listeners.slice().forEach(function (callback) {
try {
callback(tab, event);
}
// Don't let failing callbacks stop us but report the failure
catch (ex) {
Cu.reportError(ex);
}
});
}
function observer(subject, topic, data) {
switch (topic) {
case "domwindowopened":
subject.addEventListener("load", function onLoad() {
subject.removeEventListener("load", onLoad, false);
// Now that the window has loaded, only register on browser windows
let doc = subject.document.documentElement;
if (doc.getAttribute("windowtype") == "navigator:browser")
registerBrowserWindow(subject);
}, false);
break;
}
}
// Register listeners on all browser windows and future ones
browserWindows.forEach(registerBrowserWindow);
Services.obs.addObserver(observer, "domwindowopened", false);

Просмотреть файл

@ -79,9 +79,6 @@ let Storage = {
// ___ Tabs
AllTabs.tabs.forEach(function(tab) {
if (tab.ownerDocument.defaultView != gWindow)
return;
self.saveTab(tab, null);
});

Просмотреть файл

@ -746,27 +746,26 @@ let TabItems = {
this.tempCanvas.height = 112;
// When a tab is opened, create the TabItem
this._eventListeners["open"] = function(tab) {
if (tab.ownerDocument.defaultView != gWindow || tab.pinned)
return;
this._eventListeners.open = function (event) {
let tab = event.target;
if (!tab.pinned)
self.link(tab);
}
// When a tab's content is loaded, show the canvas and hide the cached data
// if necessary.
this._eventListeners["attrModified"] = function(tab) {
if (tab.ownerDocument.defaultView != gWindow || tab.pinned)
return;
this._eventListeners.attrModified = function (event) {
let tab = event.target;
if (!tab.pinned)
self.update(tab);
}
// When a tab is closed, unlink.
this._eventListeners["close"] = function(tab) {
if (tab.ownerDocument.defaultView != gWindow || tab.pinned)
return;
this._eventListeners.close = function (event) {
let tab = event.target;
// XXX bug #635975 - don't unlink the tab if the dom window is closing.
if (!UI.isDOMWindowClosing)
if (!tab.pinned && !UI.isDOMWindowClosing)
self.unlink(tab);
}
for (let name in this._eventListeners) {
@ -775,7 +774,7 @@ let TabItems = {
// For each tab, create the link.
AllTabs.tabs.forEach(function (tab) {
if (tab.ownerDocument.defaultView != gWindow || tab.pinned)
if (tab.pinned)
return;
self.link(tab, {immediately: true});

Просмотреть файл

@ -5,7 +5,6 @@ const Ci = Components.interfaces;
const Cu = Components.utils;
const Cr = Components.results;
Cu.import("resource:///modules/tabview/AllTabs.jsm");
Cu.import("resource:///modules/tabview/utils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
@ -44,6 +43,30 @@ var gTabViewDeck = gWindow.document.getElementById("tab-view-deck");
var gBrowserPanel = gWindow.document.getElementById("browser-panel");
var gTabViewFrame = gWindow.document.getElementById("tab-view");
let AllTabs = {
_events: {
attrModified: "TabAttrModified",
close: "TabClose",
move: "TabMove",
open: "TabOpen",
select: "TabSelect",
pinned: "TabPinned",
unpinned: "TabUnpinned"
},
get tabs() {
return Array.filter(gBrowser.tabs, function (tab) !tab.closing);
},
register: function AllTabs_register(eventName, callback) {
gBrowser.tabContainer.addEventListener(this._events[eventName], callback, false);
},
unregister: function AllTabs_unregister(eventName, callback) {
gBrowser.tabContainer.removeEventListener(this._events[eventName], callback, false);
}
};
# NB: Certain files need to evaluate before others
#include iq.js

Просмотреть файл

@ -703,9 +703,8 @@ let UI = {
});
// TabOpen
this._eventListeners.open = function(tab) {
if (tab.ownerDocument.defaultView != gWindow)
return;
this._eventListeners.open = function (event) {
let tab = event.target;
// if it's an app tab, add it to all the group items
if (tab.pinned)
@ -715,9 +714,8 @@ let UI = {
};
// TabClose
this._eventListeners.close = function(tab) {
if (tab.ownerDocument.defaultView != gWindow)
return;
this._eventListeners.close = function (event) {
let tab = event.target;
// if it's an app tab, remove it from all the group items
if (tab.pinned)
@ -773,9 +771,8 @@ let UI = {
};
// TabMove
this._eventListeners.move = function(tab) {
if (tab.ownerDocument.defaultView != gWindow)
return;
this._eventListeners.move = function (event) {
let tab = event.target;
if (GroupItems.groupItems.length > 0) {
if (tab.pinned) {
@ -790,26 +787,21 @@ let UI = {
};
// TabSelect
this._eventListeners.select = function(tab) {
if (tab.ownerDocument.defaultView != gWindow)
return;
self.onTabSelect(tab);
this._eventListeners.select = function (event) {
self.onTabSelect(event.target);
};
// TabPinned
this._eventListeners.pinned = function(tab) {
if (tab.ownerDocument.defaultView != gWindow)
return;
this._eventListeners.pinned = function (event) {
let tab = event.target;
TabItems.handleTabPin(tab);
GroupItems.addAppTab(tab);
};
// TabUnpinned
this._eventListeners.unpinned = function(tab) {
if (tab.ownerDocument.defaultView != gWindow)
return;
this._eventListeners.unpinned = function (event) {
let tab = event.target;
TabItems.handleTabUnpin(tab);
GroupItems.removeAppTab(tab);

Просмотреть файл

@ -1,15 +1,16 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource:///modules/tabview/AllTabs.jsm");
function test() {
waitForExplicitFinish();
let AllTabs;
let newTab = gBrowser.addTab();
// TabPinned
let pinned = function(tab) {
let pinned = function (event) {
let tab = event.target;
is(tab, newTab, "The tabs are the same after the tab is pinned");
ok(tab.pinned, "The tab gets pinned");
@ -17,7 +18,9 @@ function test() {
};
// TabUnpinned
let unpinned = function(tab) {
let unpinned = function (event) {
let tab = event.target;
AllTabs.unregister("pinned", pinned);
AllTabs.unregister("unpinned", unpinned);
@ -26,13 +29,17 @@ function test() {
// clean up and finish
gBrowser.removeTab(tab);
finish();
hideTabView(finish);
};
showTabView(function () {
AllTabs = TabView.getContentWindow().AllTabs;
AllTabs.register("pinned", pinned);
AllTabs.register("unpinned", unpinned);
ok(!newTab.pinned, "The tab is not pinned");
gBrowser.pinTab(newTab);
});
}