2008-07-15 09:11:00 -07:00
|
|
|
/*
|
|
|
|
#ifdef 0
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2008-07-15 09:11:00 -07:00
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tab previews utility, produces thumbnails
|
|
|
|
*/
|
|
|
|
var tabPreviews = {
|
2008-09-19 02:44:15 -07:00
|
|
|
aspectRatio: 0.5625, // 16:9
|
2012-09-06 05:41:46 -07:00
|
|
|
|
|
|
|
get width() {
|
|
|
|
delete this.width;
|
|
|
|
return this.width = Math.ceil(screen.availWidth / 5.75);
|
|
|
|
},
|
|
|
|
|
|
|
|
get height() {
|
|
|
|
delete this.height;
|
|
|
|
return this.height = Math.round(this.width * this.aspectRatio);
|
|
|
|
},
|
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
init: function tabPreviews_init() {
|
2010-04-02 00:19:57 -07:00
|
|
|
if (this._selectedTab)
|
|
|
|
return;
|
|
|
|
this._selectedTab = gBrowser.selectedTab;
|
|
|
|
|
2008-07-15 09:11:00 -07:00
|
|
|
gBrowser.tabContainer.addEventListener("TabSelect", this, false);
|
|
|
|
gBrowser.tabContainer.addEventListener("SSTabRestored", this, false);
|
|
|
|
},
|
2012-09-06 05:41:46 -07:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
get: function tabPreviews_get(aTab) {
|
2012-09-06 05:41:46 -07:00
|
|
|
let uri = aTab.linkedBrowser.currentURI.spec;
|
2010-04-02 00:19:57 -07:00
|
|
|
|
2008-08-30 17:43:35 -07:00
|
|
|
if (aTab.__thumbnail_lastURI &&
|
2012-09-06 05:41:46 -07:00
|
|
|
aTab.__thumbnail_lastURI != uri) {
|
2008-08-30 17:43:35 -07:00
|
|
|
aTab.__thumbnail = null;
|
|
|
|
aTab.__thumbnail_lastURI = null;
|
|
|
|
}
|
2012-09-06 05:41:46 -07:00
|
|
|
|
|
|
|
if (aTab.__thumbnail)
|
|
|
|
return aTab.__thumbnail;
|
|
|
|
|
|
|
|
if (aTab.getAttribute("pending") == "true") {
|
|
|
|
let img = new Image;
|
|
|
|
img.src = PageThumbs.getThumbnailURL(uri);
|
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.capture(aTab, !aTab.hasAttribute("busy"));
|
2008-07-15 09:11:00 -07:00
|
|
|
},
|
2010-04-02 00:19:57 -07:00
|
|
|
|
2012-09-06 05:41:46 -07:00
|
|
|
capture: function tabPreviews_capture(aTab, aStore) {
|
2008-07-15 09:11:00 -07:00
|
|
|
var thumbnail = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
|
|
|
|
thumbnail.mozOpaque = true;
|
|
|
|
thumbnail.height = this.height;
|
|
|
|
thumbnail.width = this.width;
|
2008-09-19 02:44:15 -07:00
|
|
|
|
2008-07-15 09:11:00 -07:00
|
|
|
var ctx = thumbnail.getContext("2d");
|
2008-09-19 02:44:15 -07:00
|
|
|
var win = aTab.linkedBrowser.contentWindow;
|
|
|
|
var snippetWidth = win.innerWidth * .6;
|
|
|
|
var scale = this.width / snippetWidth;
|
|
|
|
ctx.scale(scale, scale);
|
2008-07-15 09:11:00 -07:00
|
|
|
ctx.drawWindow(win, win.scrollX, win.scrollY,
|
2008-09-19 02:44:15 -07:00
|
|
|
snippetWidth, snippetWidth * this.aspectRatio, "rgb(255,255,255)");
|
|
|
|
|
2012-09-29 08:59:43 -07:00
|
|
|
if (aStore &&
|
|
|
|
aTab.linkedBrowser /* bug 795608: the tab may got removed while drawing the thumbnail */) {
|
2008-11-04 00:19:55 -08:00
|
|
|
aTab.__thumbnail = thumbnail;
|
2008-08-30 17:43:35 -07:00
|
|
|
aTab.__thumbnail_lastURI = aTab.linkedBrowser.currentURI.spec;
|
|
|
|
}
|
2012-09-29 08:59:43 -07:00
|
|
|
|
2008-11-04 00:19:55 -08:00
|
|
|
return thumbnail;
|
2008-07-15 09:11:00 -07:00
|
|
|
},
|
2012-09-06 05:41:46 -07:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
handleEvent: function tabPreviews_handleEvent(event) {
|
2008-07-15 09:11:00 -07:00
|
|
|
switch (event.type) {
|
|
|
|
case "TabSelect":
|
|
|
|
if (this._selectedTab &&
|
|
|
|
this._selectedTab.parentNode &&
|
|
|
|
!this._pendingUpdate) {
|
|
|
|
// Generate a thumbnail for the tab that was selected.
|
|
|
|
// The timeout keeps the UI snappy and prevents us from generating thumbnails
|
|
|
|
// for tabs that will be closed. During that timeout, don't generate other
|
|
|
|
// thumbnails in case multiple TabSelect events occur fast in succession.
|
|
|
|
this._pendingUpdate = true;
|
|
|
|
setTimeout(function (self, aTab) {
|
|
|
|
self._pendingUpdate = false;
|
2012-09-26 06:08:09 -07:00
|
|
|
if (aTab.parentNode &&
|
|
|
|
!aTab.hasAttribute("busy") &&
|
|
|
|
!aTab.hasAttribute("pending"))
|
2008-07-15 09:11:00 -07:00
|
|
|
self.capture(aTab, true);
|
|
|
|
}, 2000, this, this._selectedTab);
|
|
|
|
}
|
|
|
|
this._selectedTab = event.target;
|
|
|
|
break;
|
|
|
|
case "SSTabRestored":
|
|
|
|
this.capture(event.target, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
var tabPreviewPanelHelper = {
|
|
|
|
opening: function (host) {
|
|
|
|
host.panel.hidden = false;
|
|
|
|
|
|
|
|
var handler = this._generateHandler(host);
|
|
|
|
host.panel.addEventListener("popupshown", handler, false);
|
2009-07-27 09:55:31 -07:00
|
|
|
host.panel.addEventListener("popuphiding", handler, false);
|
2009-07-20 21:25:59 -07:00
|
|
|
|
|
|
|
host._prevFocus = document.commandDispatcher.focusedElement;
|
|
|
|
},
|
|
|
|
_generateHandler: function (host) {
|
|
|
|
var self = this;
|
|
|
|
return function (event) {
|
|
|
|
if (event.target == host.panel) {
|
|
|
|
host.panel.removeEventListener(event.type, arguments.callee, false);
|
|
|
|
self["_" + event.type](host);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
_popupshown: function (host) {
|
|
|
|
if ("setupGUI" in host)
|
|
|
|
host.setupGUI();
|
|
|
|
},
|
|
|
|
_popuphiding: function (host) {
|
|
|
|
if ("suspendGUI" in host)
|
|
|
|
host.suspendGUI();
|
|
|
|
|
|
|
|
if (host._prevFocus) {
|
|
|
|
Cc["@mozilla.org/focus-manager;1"]
|
|
|
|
.getService(Ci.nsIFocusManager)
|
|
|
|
.setFocus(host._prevFocus, Ci.nsIFocusManager.FLAG_NOSCROLL);
|
|
|
|
host._prevFocus = null;
|
|
|
|
} else
|
|
|
|
gBrowser.selectedBrowser.focus();
|
|
|
|
|
|
|
|
if (host.tabToSelect) {
|
|
|
|
gBrowser.selectedTab = host.tabToSelect;
|
|
|
|
host.tabToSelect = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-07-15 09:11:00 -07:00
|
|
|
/**
|
|
|
|
* Ctrl-Tab panel
|
|
|
|
*/
|
|
|
|
var ctrlTab = {
|
|
|
|
get panel () {
|
|
|
|
delete this.panel;
|
|
|
|
return this.panel = document.getElementById("ctrlTab-panel");
|
|
|
|
},
|
2009-07-20 21:25:59 -07:00
|
|
|
get showAllButton () {
|
|
|
|
delete this.showAllButton;
|
|
|
|
return this.showAllButton = document.getElementById("ctrlTab-showAll");
|
2008-07-15 09:11:00 -07:00
|
|
|
},
|
2009-07-20 21:25:59 -07:00
|
|
|
get previews () {
|
|
|
|
delete this.previews;
|
|
|
|
return this.previews = this.panel.getElementsByClassName("ctrlTab-preview");
|
2008-08-09 03:18:49 -07:00
|
|
|
},
|
2008-09-19 02:38:44 -07:00
|
|
|
get recentlyUsedLimit () {
|
|
|
|
delete this.recentlyUsedLimit;
|
|
|
|
return this.recentlyUsedLimit = gPrefService.getIntPref("browser.ctrlTab.recentlyUsedLimit");
|
|
|
|
},
|
2009-07-20 21:25:59 -07:00
|
|
|
get keys () {
|
|
|
|
var keys = {};
|
|
|
|
["close", "find", "selectAll"].forEach(function (key) {
|
|
|
|
keys[key] = document.getElementById("key_" + key)
|
|
|
|
.getAttribute("key")
|
|
|
|
.toLocaleLowerCase().charCodeAt(0);
|
|
|
|
});
|
|
|
|
delete this.keys;
|
|
|
|
return this.keys = keys;
|
|
|
|
},
|
|
|
|
_selectedIndex: 0,
|
|
|
|
get selected () this._selectedIndex < 0 ?
|
|
|
|
document.activeElement :
|
|
|
|
this.previews.item(this._selectedIndex),
|
|
|
|
get isOpen () this.panel.state == "open" || this.panel.state == "showing" || this._timer,
|
2008-11-04 23:38:13 -08:00
|
|
|
get tabCount () this.tabList.length,
|
2009-07-20 21:25:59 -07:00
|
|
|
get tabPreviewCount () Math.min(this.previews.length - 1, this.tabCount),
|
|
|
|
get canvasWidth () Math.min(tabPreviews.width,
|
|
|
|
Math.ceil(screen.availWidth * .85 / this.tabPreviewCount)),
|
|
|
|
get canvasHeight () Math.round(this.canvasWidth * tabPreviews.aspectRatio),
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2008-11-04 00:19:55 -08:00
|
|
|
get tabList () {
|
2008-11-04 23:38:13 -08:00
|
|
|
if (this._tabList)
|
|
|
|
return this._tabList;
|
|
|
|
|
2011-07-05 07:57:32 -07:00
|
|
|
// Using gBrowser.tabs instead of gBrowser.visibleTabs, as the latter
|
|
|
|
// exlcudes closing tabs, breaking the following loop in case the the
|
|
|
|
// selected tab is closing.
|
|
|
|
let list = Array.filter(gBrowser.tabs, function (tab) !tab.hidden);
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2010-07-29 16:39:57 -07:00
|
|
|
// Rotate the list until the selected tab is first
|
|
|
|
while (!list[0].selected)
|
2008-11-04 00:19:55 -08:00
|
|
|
list.push(list.shift());
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2011-07-05 07:57:32 -07:00
|
|
|
list = list.filter(function (tab) !tab.closing);
|
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
if (this.recentlyUsedLimit != 0) {
|
2012-08-25 14:18:43 -07:00
|
|
|
let recentlyUsedTabs = [];
|
|
|
|
for (let tab of this._recentlyUsedTabs) {
|
|
|
|
if (!tab.hidden && !tab.closing) {
|
|
|
|
recentlyUsedTabs.push(tab);
|
|
|
|
if (this.recentlyUsedLimit > 0 && recentlyUsedTabs.length >= this.recentlyUsedLimit)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:19:55 -08:00
|
|
|
for (let i = recentlyUsedTabs.length - 1; i >= 0; i--) {
|
|
|
|
list.splice(list.indexOf(recentlyUsedTabs[i]), 1);
|
|
|
|
list.unshift(recentlyUsedTabs[i]);
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 23:38:13 -08:00
|
|
|
|
|
|
|
return this._tabList = list;
|
2008-08-09 03:18:49 -07:00
|
|
|
},
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
init: function ctrlTab_init() {
|
|
|
|
if (!this._recentlyUsedTabs) {
|
2010-04-02 00:19:57 -07:00
|
|
|
tabPreviews.init();
|
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
this._recentlyUsedTabs = [gBrowser.selectedTab];
|
|
|
|
this._init(true);
|
|
|
|
}
|
|
|
|
},
|
2008-08-09 03:18:49 -07:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
uninit: function ctrlTab_uninit() {
|
|
|
|
this._recentlyUsedTabs = null;
|
|
|
|
this._init(false);
|
|
|
|
},
|
2008-07-15 09:11:00 -07:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
prefName: "browser.ctrlTab.previews",
|
|
|
|
readPref: function ctrlTab_readPref() {
|
|
|
|
var enable =
|
|
|
|
gPrefService.getBoolPref(this.prefName) &&
|
2008-11-04 23:38:13 -08:00
|
|
|
(!gPrefService.prefHasUserValue("browser.ctrlTab.disallowForScreenReaders") ||
|
|
|
|
!gPrefService.getBoolPref("browser.ctrlTab.disallowForScreenReaders"));
|
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
if (enable)
|
|
|
|
this.init();
|
|
|
|
else
|
|
|
|
this.uninit();
|
2008-11-04 23:38:13 -08:00
|
|
|
},
|
2009-07-20 21:25:59 -07:00
|
|
|
observe: function (aSubject, aTopic, aPrefName) {
|
|
|
|
this.readPref();
|
2008-07-15 09:11:00 -07:00
|
|
|
},
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
updatePreviews: function ctrlTab_updatePreviews() {
|
|
|
|
for (let i = 0; i < this.previews.length; i++)
|
|
|
|
this.updatePreview(this.previews[i], this.tabList[i]);
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
var showAllLabel = gNavigatorBundle.getString("ctrlTab.showAll.label");
|
|
|
|
this.showAllButton.label =
|
|
|
|
PluralForm.get(this.tabCount, showAllLabel).replace("#1", this.tabCount);
|
2013-02-11 04:48:32 -08:00
|
|
|
this.showAllButton.hidden = !allTabs.canOpen;
|
2008-11-04 00:19:55 -08:00
|
|
|
},
|
2009-07-20 21:25:59 -07:00
|
|
|
|
|
|
|
updatePreview: function ctrlTab_updatePreview(aPreview, aTab) {
|
|
|
|
if (aPreview == this.showAllButton)
|
|
|
|
return;
|
|
|
|
|
2009-12-12 11:31:21 -08:00
|
|
|
aPreview._tab = aTab;
|
2008-11-04 00:19:55 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
if (aPreview.firstChild)
|
|
|
|
aPreview.removeChild(aPreview.firstChild);
|
2008-11-04 00:19:55 -08:00
|
|
|
if (aTab) {
|
2009-07-20 21:25:59 -07:00
|
|
|
let canvasWidth = this.canvasWidth;
|
|
|
|
let canvasHeight = this.canvasHeight;
|
|
|
|
aPreview.appendChild(tabPreviews.get(aTab));
|
|
|
|
aPreview.setAttribute("label", aTab.label);
|
|
|
|
aPreview.setAttribute("tooltiptext", aTab.label);
|
|
|
|
aPreview.setAttribute("crop", aTab.crop);
|
|
|
|
aPreview.setAttribute("canvaswidth", canvasWidth);
|
|
|
|
aPreview.setAttribute("canvasstyle",
|
|
|
|
"max-width:" + canvasWidth + "px;" +
|
|
|
|
"min-width:" + canvasWidth + "px;" +
|
|
|
|
"max-height:" + canvasHeight + "px;" +
|
|
|
|
"min-height:" + canvasHeight + "px;");
|
|
|
|
if (aTab.image)
|
|
|
|
aPreview.setAttribute("image", aTab.image);
|
|
|
|
else
|
|
|
|
aPreview.removeAttribute("image");
|
|
|
|
aPreview.hidden = false;
|
2008-11-04 00:19:55 -08:00
|
|
|
} else {
|
2009-07-20 21:25:59 -07:00
|
|
|
aPreview.hidden = true;
|
|
|
|
aPreview.removeAttribute("label");
|
|
|
|
aPreview.removeAttribute("tooltiptext");
|
|
|
|
aPreview.removeAttribute("image");
|
2008-11-04 00:19:55 -08:00
|
|
|
}
|
2008-07-15 09:11:00 -07:00
|
|
|
},
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
advanceFocus: function ctrlTab_advanceFocus(aForward) {
|
2013-02-12 13:16:28 -08:00
|
|
|
let selectedIndex = Array.indexOf(this.previews, this.selected);
|
|
|
|
do {
|
|
|
|
selectedIndex += aForward ? 1 : -1;
|
|
|
|
if (selectedIndex < 0)
|
|
|
|
selectedIndex = this.previews.length - 1;
|
|
|
|
else if (selectedIndex >= this.previews.length)
|
|
|
|
selectedIndex = 0;
|
|
|
|
} while (this.previews[selectedIndex].hidden);
|
|
|
|
|
2010-05-07 00:50:04 -07:00
|
|
|
if (this._selectedIndex == -1) {
|
2013-02-12 13:16:28 -08:00
|
|
|
// Focus is already in the panel.
|
|
|
|
this.previews[selectedIndex].focus();
|
2009-07-20 21:25:59 -07:00
|
|
|
} else {
|
2013-02-12 13:16:28 -08:00
|
|
|
this._selectedIndex = selectedIndex;
|
2009-07-20 21:25:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this._timer) {
|
|
|
|
clearTimeout(this._timer);
|
|
|
|
this._timer = null;
|
|
|
|
this._openPanel();
|
2008-07-15 09:11:00 -07:00
|
|
|
}
|
|
|
|
},
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
_mouseOverFocus: function ctrlTab_mouseOverFocus(aPreview) {
|
|
|
|
if (this._trackMouseOver)
|
|
|
|
aPreview.focus();
|
|
|
|
},
|
2008-11-04 00:19:55 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
pick: function ctrlTab_pick(aPreview) {
|
|
|
|
if (!this.tabCount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var select = (aPreview || this.selected);
|
|
|
|
|
|
|
|
if (select == this.showAllButton)
|
|
|
|
this.showAllTabs();
|
|
|
|
else
|
|
|
|
this.close(select._tab);
|
2008-11-04 00:19:55 -08:00
|
|
|
},
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
showAllTabs: function ctrlTab_showAllTabs(aPreview) {
|
|
|
|
this.close();
|
|
|
|
document.getElementById("Browser:ShowAllTabs").doCommand();
|
2008-07-15 09:11:00 -07:00
|
|
|
},
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
remove: function ctrlTab_remove(aPreview) {
|
|
|
|
if (aPreview._tab)
|
|
|
|
gBrowser.removeTab(aPreview._tab);
|
2008-07-15 09:11:00 -07:00
|
|
|
},
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
attachTab: function ctrlTab_attachTab(aTab, aPos) {
|
2008-09-19 02:34:33 -07:00
|
|
|
if (aPos == 0)
|
2008-09-19 02:38:44 -07:00
|
|
|
this._recentlyUsedTabs.unshift(aTab);
|
2008-09-19 02:34:33 -07:00
|
|
|
else if (aPos)
|
2008-09-19 02:38:44 -07:00
|
|
|
this._recentlyUsedTabs.splice(aPos, 0, aTab);
|
2008-07-15 09:11:00 -07:00
|
|
|
else
|
2008-09-19 02:38:44 -07:00
|
|
|
this._recentlyUsedTabs.push(aTab);
|
2008-07-15 09:11:00 -07:00
|
|
|
},
|
2011-07-05 07:57:32 -07:00
|
|
|
detachTab: function ctrlTab_detachTab(aTab) {
|
|
|
|
var i = this._recentlyUsedTabs.indexOf(aTab);
|
2008-07-15 09:11:00 -07:00
|
|
|
if (i >= 0)
|
2011-07-05 07:57:32 -07:00
|
|
|
this._recentlyUsedTabs.splice(i, 1);
|
2008-07-15 09:11:00 -07:00
|
|
|
},
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
open: function ctrlTab_open() {
|
|
|
|
if (this.isOpen)
|
2008-11-04 23:38:13 -08:00
|
|
|
return;
|
2008-11-04 00:19:55 -08:00
|
|
|
|
2008-11-04 23:38:13 -08:00
|
|
|
document.addEventListener("keyup", this, true);
|
2009-07-20 21:25:59 -07:00
|
|
|
|
|
|
|
this.updatePreviews();
|
|
|
|
this._selectedIndex = 1;
|
|
|
|
|
|
|
|
// Add a slight delay before showing the UI, so that a quick
|
|
|
|
// "ctrl-tab" keypress just flips back to the MRU tab.
|
|
|
|
this._timer = setTimeout(function (self) {
|
|
|
|
self._timer = null;
|
|
|
|
self._openPanel();
|
2009-07-26 10:36:09 -07:00
|
|
|
}, 200, this);
|
2009-07-20 21:25:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_openPanel: function ctrlTab_openPanel() {
|
|
|
|
tabPreviewPanelHelper.opening(this);
|
|
|
|
|
|
|
|
this.panel.width = Math.min(screen.availWidth * .99,
|
|
|
|
this.canvasWidth * 1.25 * this.tabPreviewCount);
|
|
|
|
var estimateHeight = this.canvasHeight * 1.25 + 75;
|
2009-09-07 05:16:30 -07:00
|
|
|
this.panel.openPopupAtScreen(screen.availLeft + (screen.availWidth - this.panel.width) / 2,
|
|
|
|
screen.availTop + (screen.availHeight - estimateHeight) / 2,
|
|
|
|
false);
|
2008-07-15 09:11:00 -07:00
|
|
|
},
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
close: function ctrlTab_close(aTabToSelect) {
|
|
|
|
if (!this.isOpen)
|
|
|
|
return;
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
if (this._timer) {
|
|
|
|
clearTimeout(this._timer);
|
|
|
|
this._timer = null;
|
|
|
|
this.suspendGUI();
|
|
|
|
if (aTabToSelect)
|
|
|
|
gBrowser.selectedTab = aTabToSelect;
|
2008-11-04 23:38:13 -08:00
|
|
|
return;
|
2009-07-20 21:25:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
this.tabToSelect = aTabToSelect;
|
|
|
|
this.panel.hidePopup();
|
|
|
|
},
|
|
|
|
|
|
|
|
setupGUI: function ctrlTab_setupGUI() {
|
|
|
|
this.selected.focus();
|
|
|
|
this._selectedIndex = -1;
|
|
|
|
|
|
|
|
// Track mouse movement after a brief delay so that the item that happens
|
|
|
|
// to be under the mouse pointer initially won't be selected unintentionally.
|
|
|
|
this._trackMouseOver = false;
|
|
|
|
setTimeout(function (self) {
|
|
|
|
if (self.isOpen)
|
|
|
|
self._trackMouseOver = true;
|
|
|
|
}, 0, this);
|
|
|
|
},
|
|
|
|
|
|
|
|
suspendGUI: function ctrlTab_suspendGUI() {
|
|
|
|
document.removeEventListener("keyup", this, true);
|
|
|
|
|
|
|
|
Array.forEach(this.previews, function (preview) {
|
|
|
|
this.updatePreview(preview, null);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this._tabList = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
onKeyPress: function ctrlTab_onKeyPress(event) {
|
|
|
|
var isOpen = this.isOpen;
|
2008-11-04 23:38:13 -08:00
|
|
|
|
|
|
|
if (isOpen) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2008-07-15 09:11:00 -07:00
|
|
|
switch (event.keyCode) {
|
|
|
|
case event.DOM_VK_TAB:
|
2009-07-20 21:25:59 -07:00
|
|
|
if (event.ctrlKey && !event.altKey && !event.metaKey) {
|
2008-11-04 23:38:13 -08:00
|
|
|
if (isOpen) {
|
2009-07-20 21:25:59 -07:00
|
|
|
this.advanceFocus(!event.shiftKey);
|
|
|
|
} else if (!event.shiftKey) {
|
2008-11-04 23:38:13 -08:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2010-07-29 16:39:57 -07:00
|
|
|
let tabs = gBrowser.visibleTabs;
|
|
|
|
if (tabs.length > 2) {
|
2008-11-04 23:38:13 -08:00
|
|
|
this.open();
|
2010-07-29 16:39:57 -07:00
|
|
|
} else if (tabs.length == 2) {
|
2012-12-24 08:08:22 -08:00
|
|
|
let index = tabs[0].selected ? 1 : 0;
|
2010-07-29 16:39:57 -07:00
|
|
|
gBrowser.selectedTab = tabs[index];
|
2008-11-04 23:38:13 -08:00
|
|
|
}
|
|
|
|
}
|
2008-07-15 09:11:00 -07:00
|
|
|
}
|
|
|
|
break;
|
2008-08-11 02:06:42 -07:00
|
|
|
default:
|
2008-11-04 23:38:13 -08:00
|
|
|
if (isOpen && event.ctrlKey) {
|
2009-07-20 21:25:59 -07:00
|
|
|
if (event.keyCode == event.DOM_VK_DELETE) {
|
|
|
|
this.remove(this.selected);
|
|
|
|
break;
|
|
|
|
}
|
2008-11-04 23:38:13 -08:00
|
|
|
switch (event.charCode) {
|
2009-07-20 21:25:59 -07:00
|
|
|
case this.keys.close:
|
|
|
|
this.remove(this.selected);
|
2008-11-04 23:38:13 -08:00
|
|
|
break;
|
2009-07-20 21:25:59 -07:00
|
|
|
case this.keys.find:
|
|
|
|
case this.keys.selectAll:
|
|
|
|
this.showAllTabs();
|
2008-11-04 23:38:13 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-07-15 09:11:00 -07:00
|
|
|
}
|
|
|
|
},
|
2008-11-04 00:19:55 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
removeClosingTabFromUI: function ctrlTab_removeClosingTabFromUI(aTab) {
|
|
|
|
if (this.tabCount == 2) {
|
|
|
|
this.close();
|
|
|
|
return;
|
2008-08-09 03:18:49 -07:00
|
|
|
}
|
2008-11-04 23:38:13 -08:00
|
|
|
|
|
|
|
this._tabList = null;
|
2009-07-20 21:25:59 -07:00
|
|
|
this.updatePreviews();
|
|
|
|
|
|
|
|
if (this.selected.hidden)
|
|
|
|
this.advanceFocus(false);
|
|
|
|
if (this.selected == this.showAllButton)
|
|
|
|
this.advanceFocus(false);
|
|
|
|
|
|
|
|
// If the current tab is removed, another tab can steal our focus.
|
2012-12-24 08:08:22 -08:00
|
|
|
if (aTab.selected && this.panel.state == "open") {
|
2009-07-20 21:25:59 -07:00
|
|
|
setTimeout(function (selected) {
|
|
|
|
selected.focus();
|
|
|
|
}, 0, this.selected);
|
|
|
|
}
|
2008-11-04 00:19:55 -08:00
|
|
|
},
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
handleEvent: function ctrlTab_handleEvent(event) {
|
2008-07-15 09:11:00 -07:00
|
|
|
switch (event.type) {
|
2009-12-12 11:31:21 -08:00
|
|
|
case "TabAttrModified":
|
|
|
|
// tab attribute modified (e.g. label, crop, busy, image, selected)
|
2009-07-20 21:25:59 -07:00
|
|
|
for (let i = this.previews.length - 1; i >= 0; i--) {
|
|
|
|
if (this.previews[i]._tab && this.previews[i]._tab == event.target) {
|
|
|
|
this.updatePreview(this.previews[i], event.target);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-07-15 09:11:00 -07:00
|
|
|
break;
|
|
|
|
case "TabSelect":
|
2009-07-20 21:25:59 -07:00
|
|
|
this.detachTab(event.target);
|
|
|
|
this.attachTab(event.target, 0);
|
2008-07-15 09:11:00 -07:00
|
|
|
break;
|
|
|
|
case "TabOpen":
|
2008-09-19 02:34:33 -07:00
|
|
|
this.attachTab(event.target, 1);
|
2008-07-15 09:11:00 -07:00
|
|
|
break;
|
|
|
|
case "TabClose":
|
|
|
|
this.detachTab(event.target);
|
2008-11-04 00:19:55 -08:00
|
|
|
if (this.isOpen)
|
|
|
|
this.removeClosingTabFromUI(event.target);
|
2008-07-15 09:11:00 -07:00
|
|
|
break;
|
|
|
|
case "keypress":
|
2008-08-11 02:06:42 -07:00
|
|
|
this.onKeyPress(event);
|
2008-08-09 03:18:49 -07:00
|
|
|
break;
|
2008-07-15 09:11:00 -07:00
|
|
|
case "keyup":
|
2009-07-20 21:25:59 -07:00
|
|
|
if (event.keyCode == event.DOM_VK_CONTROL)
|
|
|
|
this.pick();
|
|
|
|
break;
|
2013-02-11 04:48:32 -08:00
|
|
|
case "popupshowing":
|
|
|
|
if (event.target.id == "menu_viewPopup")
|
|
|
|
document.getElementById("menu_showAllTabs").hidden = !allTabs.canOpen;
|
|
|
|
break;
|
2009-07-20 21:25:59 -07:00
|
|
|
}
|
|
|
|
},
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
_init: function ctrlTab__init(enable) {
|
|
|
|
var toggleEventListener = enable ? "addEventListener" : "removeEventListener";
|
|
|
|
|
|
|
|
var tabContainer = gBrowser.tabContainer;
|
|
|
|
tabContainer[toggleEventListener]("TabOpen", this, false);
|
2009-12-12 11:31:21 -08:00
|
|
|
tabContainer[toggleEventListener]("TabAttrModified", this, false);
|
2009-07-20 21:25:59 -07:00
|
|
|
tabContainer[toggleEventListener]("TabSelect", this, false);
|
|
|
|
tabContainer[toggleEventListener]("TabClose", this, false);
|
|
|
|
|
|
|
|
document[toggleEventListener]("keypress", this, false);
|
|
|
|
gBrowser.mTabBox.handleCtrlTab = !enable;
|
|
|
|
|
|
|
|
// If we're not running, hide the "Show All Tabs" menu item,
|
|
|
|
// as Shift+Ctrl+Tab will be handled by the tab bar.
|
|
|
|
document.getElementById("menu_showAllTabs").hidden = !enable;
|
2013-02-11 04:48:32 -08:00
|
|
|
document.getElementById("menu_viewPopup")[toggleEventListener]("popupshowing", this);
|
2010-11-28 18:02:36 -08:00
|
|
|
|
|
|
|
// Also disable the <key> to ensure Shift+Ctrl+Tab never triggers
|
|
|
|
// Show All Tabs.
|
|
|
|
var key_showAllTabs = document.getElementById("key_showAllTabs");
|
|
|
|
if (enable)
|
|
|
|
key_showAllTabs.removeAttribute("disabled");
|
|
|
|
else
|
|
|
|
key_showAllTabs.setAttribute("disabled", "true");
|
2009-07-20 21:25:59 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-02-11 04:48:32 -08:00
|
|
|
* All Tabs menu
|
2009-07-20 21:25:59 -07:00
|
|
|
*/
|
|
|
|
var allTabs = {
|
2011-07-07 23:46:50 -07:00
|
|
|
get toolbarButton() document.getElementById("alltabs-button"),
|
2013-02-11 04:48:32 -08:00
|
|
|
get canOpen() isElementVisible(this.toolbarButton),
|
2009-07-20 21:25:59 -07:00
|
|
|
|
|
|
|
open: function allTabs_open() {
|
2013-02-11 04:48:32 -08:00
|
|
|
if (this.canOpen) {
|
2011-07-07 23:46:50 -07:00
|
|
|
// Without setTimeout, the menupopup won't stay open when invoking
|
|
|
|
// "View > Show All Tabs" and the menu bar auto-hides.
|
|
|
|
setTimeout(function () {
|
2013-02-11 04:48:32 -08:00
|
|
|
allTabs.toolbarButton.open = true;
|
2011-07-07 23:46:50 -07:00
|
|
|
}, 0);
|
2009-07-20 21:25:59 -07:00
|
|
|
}
|
2008-07-15 09:11:00 -07:00
|
|
|
}
|
|
|
|
};
|