2011-02-27 17:36:36 -08:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
2010-10-18 02:53:58 -07:00
|
|
|
|
2011-02-17 12:37:32 -08:00
|
|
|
function createEmptyGroupItem(contentWindow, width, height, padding, animate) {
|
2010-10-18 02:53:58 -07:00
|
|
|
let pageBounds = contentWindow.Items.getPageBounds();
|
|
|
|
pageBounds.inset(padding, padding);
|
|
|
|
|
|
|
|
let box = new contentWindow.Rect(pageBounds);
|
|
|
|
box.width = width;
|
|
|
|
box.height = height;
|
2011-02-17 12:37:32 -08:00
|
|
|
|
2011-02-14 09:21:37 -08:00
|
|
|
let emptyGroupItem =
|
2011-02-17 12:37:32 -08:00
|
|
|
new contentWindow.GroupItem([], { bounds: box, immediately: !animate });
|
2010-10-18 02:53:58 -07:00
|
|
|
|
|
|
|
return emptyGroupItem;
|
|
|
|
}
|
2011-01-12 17:08:22 -08:00
|
|
|
|
2011-02-14 09:21:37 -08:00
|
|
|
// ----------
|
|
|
|
function createGroupItemWithTabs(win, width, height, padding, urls, animate) {
|
|
|
|
let contentWindow = win.TabView.getContentWindow();
|
|
|
|
let groupItemCount = contentWindow.GroupItems.groupItems.length;
|
|
|
|
// create empty group item
|
|
|
|
let groupItem = createEmptyGroupItem(contentWindow, width, height, padding, animate);
|
|
|
|
ok(groupItem.isEmpty(), "This group is empty");
|
|
|
|
is(contentWindow.GroupItems.groupItems.length, ++groupItemCount,
|
|
|
|
"The number of groups is increased by 1");
|
|
|
|
// add blank items
|
2011-04-22 13:05:11 -07:00
|
|
|
contentWindow.UI.setActive(groupItem);
|
2011-02-14 09:21:37 -08:00
|
|
|
let t = 0;
|
|
|
|
urls.forEach( function(url) {
|
|
|
|
let newItem = win.gBrowser.loadOneTab(url)._tabViewTabItem;
|
|
|
|
ok(newItem.container, "Created element "+t+":"+newItem.container);
|
|
|
|
++t;
|
|
|
|
});
|
|
|
|
return groupItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function createGroupItemWithBlankTabs(win, width, height, padding, numNewTabs, animate) {
|
|
|
|
let urls = [];
|
|
|
|
while(numNewTabs--)
|
|
|
|
urls.push("about:blank");
|
|
|
|
return createGroupItemWithTabs(win, width, height, padding, urls, animate);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function closeGroupItem(groupItem, callback) {
|
|
|
|
groupItem.addSubscriber(groupItem, "groupHidden", function() {
|
|
|
|
groupItem.removeSubscriber(groupItem, "groupHidden");
|
|
|
|
groupItem.addSubscriber(groupItem, "close", function() {
|
|
|
|
groupItem.removeSubscriber(groupItem, "close");
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
groupItem.closeHidden();
|
|
|
|
});
|
|
|
|
groupItem.closeAll();
|
|
|
|
}
|
|
|
|
|
2011-01-12 17:08:22 -08:00
|
|
|
// ----------
|
2011-01-13 10:22:47 -08:00
|
|
|
function afterAllTabItemsUpdated(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
let tabItems = win.document.getElementById("tab-view").contentWindow.TabItems;
|
|
|
|
|
|
|
|
for (let a = 0; a < win.gBrowser.tabs.length; a++) {
|
|
|
|
let tabItem = win.gBrowser.tabs[a]._tabViewTabItem;
|
|
|
|
if (tabItem)
|
|
|
|
tabItems._update(win.gBrowser.tabs[a]);
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------
|
2011-03-03 18:51:27 -08:00
|
|
|
function newWindowWithTabView(shownCallback, loadCallback, width, height) {
|
|
|
|
let winWidth = width || 800;
|
|
|
|
let winHeight = height || 800;
|
|
|
|
let win = window.openDialog(getBrowserURL(), "_blank",
|
|
|
|
"chrome,all,dialog=no,height=" + winHeight +
|
|
|
|
",width=" + winWidth);
|
2011-01-13 10:22:47 -08:00
|
|
|
let onLoad = function() {
|
|
|
|
win.removeEventListener("load", onLoad, false);
|
2011-03-03 18:51:27 -08:00
|
|
|
if (typeof loadCallback == "function")
|
|
|
|
loadCallback(win);
|
|
|
|
|
2011-01-13 10:22:47 -08:00
|
|
|
let onShown = function() {
|
|
|
|
win.removeEventListener("tabviewshown", onShown, false);
|
2011-03-03 18:51:27 -08:00
|
|
|
shownCallback(win);
|
2011-01-13 10:22:47 -08:00
|
|
|
};
|
|
|
|
win.addEventListener("tabviewshown", onShown, false);
|
|
|
|
win.TabView.toggle();
|
|
|
|
}
|
|
|
|
win.addEventListener("load", onLoad, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function afterAllTabsLoaded(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
2011-01-12 17:08:22 -08:00
|
|
|
let stillToLoad = 0;
|
|
|
|
|
|
|
|
function onLoad() {
|
|
|
|
this.removeEventListener("load", onLoad, true);
|
|
|
|
stillToLoad--;
|
|
|
|
if (!stillToLoad)
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
|
2011-01-13 10:22:47 -08:00
|
|
|
for (let a = 0; a < win.gBrowser.tabs.length; a++) {
|
|
|
|
let browser = win.gBrowser.tabs[a].linkedBrowser;
|
2011-04-07 12:55:49 -07:00
|
|
|
if (browser.contentDocument.readyState != "complete" ||
|
|
|
|
browser.webProgress.isLoadingDocument) {
|
2011-01-12 17:08:22 -08:00
|
|
|
stillToLoad++;
|
|
|
|
browser.addEventListener("load", onLoad, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stillToLoad)
|
|
|
|
callback();
|
|
|
|
}
|
2011-01-18 04:32:03 -08:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
function showTabView(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
if (win.TabView.isVisible()) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
whenTabViewIsShown(callback, win);
|
|
|
|
win.TabView.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function hideTabView(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
if (!win.TabView.isVisible()) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
whenTabViewIsHidden(callback, win);
|
|
|
|
win.TabView.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function whenTabViewIsHidden(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
if (!win.TabView.isVisible()) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
win.addEventListener('tabviewhidden', function () {
|
|
|
|
win.removeEventListener('tabviewhidden', arguments.callee, false);
|
|
|
|
callback();
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function whenTabViewIsShown(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
if (win.TabView.isVisible()) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
win.addEventListener('tabviewshown', function () {
|
|
|
|
win.removeEventListener('tabviewshown', arguments.callee, false);
|
|
|
|
callback();
|
|
|
|
}, false);
|
|
|
|
}
|
2011-02-22 12:32:16 -08:00
|
|
|
|
2011-03-28 19:51:26 -07:00
|
|
|
// ----------
|
|
|
|
function showSearch(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
let contentWindow = win.document.getElementById("tab-view").contentWindow;
|
|
|
|
if (contentWindow.isSearchEnabled()) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
whenSearchIsEnabled(callback, win);
|
|
|
|
contentWindow.performSearch();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function hideSearch(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
let contentWindow = win.document.getElementById("tab-view").contentWindow;
|
|
|
|
if (!contentWindow.isSearchEnabled()) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
whenSearchIsDisabled(callback, win);
|
|
|
|
contentWindow.hideSearch();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function whenSearchIsEnabled(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
let contentWindow = win.document.getElementById("tab-view").contentWindow;
|
|
|
|
if (contentWindow.isSearchEnabled()) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
contentWindow.addEventListener("tabviewsearchenabled", function () {
|
|
|
|
contentWindow.removeEventListener("tabviewsearchenabled", arguments.callee, false);
|
|
|
|
callback();
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function whenSearchIsDisabled(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
let contentWindow = win.document.getElementById("tab-view").contentWindow;
|
|
|
|
if (!contentWindow.isSearchEnabled()) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
contentWindow.addEventListener("tabviewsearchdisabled", function () {
|
|
|
|
contentWindow.removeEventListener("tabviewsearchdisabled", arguments.callee, false);
|
|
|
|
callback();
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-22 12:32:16 -08:00
|
|
|
// ----------
|
|
|
|
function hideGroupItem(groupItem, callback) {
|
|
|
|
if (groupItem.hidden) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
groupItem.addSubscriber(groupItem, "groupHidden", function () {
|
|
|
|
groupItem.removeSubscriber(groupItem, "groupHidden");
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
groupItem.closeAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function unhideGroupItem(groupItem, callback) {
|
|
|
|
if (!groupItem.hidden) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
groupItem.addSubscriber(groupItem, "groupShown", function () {
|
|
|
|
groupItem.removeSubscriber(groupItem, "groupShown");
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
groupItem._unhide();
|
|
|
|
}
|
2011-05-17 14:31:41 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
function whenWindowLoaded(win, callback) {
|
|
|
|
win.addEventListener("load", function onLoad() {
|
|
|
|
win.removeEventListener("load", onLoad, false);
|
|
|
|
executeSoon(callback);
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function whenWindowStateReady(win, callback) {
|
|
|
|
win.addEventListener("SSWindowStateReady", function onReady() {
|
|
|
|
win.removeEventListener("SSWindowStateReady", onReady, false);
|
|
|
|
executeSoon(callback);
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function newWindowWithState(state, callback) {
|
|
|
|
let opts = "chrome,all,dialog=no,height=800,width=800";
|
|
|
|
let win = window.openDialog(getBrowserURL(), "_blank", opts);
|
|
|
|
|
|
|
|
whenWindowLoaded(win, function () {
|
|
|
|
ss.setWindowState(win, JSON.stringify(state), true);
|
|
|
|
});
|
|
|
|
|
|
|
|
whenWindowStateReady(win, function () {
|
|
|
|
afterAllTabsLoaded(function () callback(win), win);
|
|
|
|
});
|
|
|
|
}
|