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)");
|
|
|
|
|
2008-08-30 17:43:35 -07:00
|
|
|
if (aStore) {
|
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;
|
|
|
|
}
|
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;
|
|
|
|
if (aTab.parentNode && !aTab.hasAttribute("busy"))
|
|
|
|
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);
|
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) {
|
2010-05-07 00:50:04 -07:00
|
|
|
if (this._selectedIndex == -1) {
|
|
|
|
// No virtual selectedIndex, focus must be in the panel already.
|
2009-07-20 21:25:59 -07:00
|
|
|
if (aForward)
|
|
|
|
document.commandDispatcher.advanceFocus();
|
|
|
|
else
|
|
|
|
document.commandDispatcher.rewindFocus();
|
|
|
|
} else {
|
2010-05-07 00:50:04 -07:00
|
|
|
// Focus isn't in the panel yet, so we maintain a virtual selectedIndex.
|
2009-07-20 21:25:59 -07:00
|
|
|
do {
|
|
|
|
this._selectedIndex += aForward ? 1 : -1;
|
|
|
|
if (this._selectedIndex < 0)
|
|
|
|
this._selectedIndex = this.previews.length - 1;
|
|
|
|
else if (this._selectedIndex >= this.previews.length)
|
|
|
|
this._selectedIndex = 0;
|
|
|
|
} while (this.selected.hidden);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
allTabs.close();
|
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) {
|
|
|
|
let index = gBrowser.selectedTab == tabs[0] ? 1 : 0;
|
|
|
|
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.
|
|
|
|
if (aTab == gBrowser.selectedTab && this.panel.state == "open") {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
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;
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All Tabs panel
|
|
|
|
*/
|
|
|
|
var allTabs = {
|
|
|
|
get panel () {
|
|
|
|
delete this.panel;
|
|
|
|
return this.panel = document.getElementById("allTabs-panel");
|
|
|
|
},
|
|
|
|
get filterField () {
|
|
|
|
delete this.filterField;
|
|
|
|
return this.filterField = document.getElementById("allTabs-filter");
|
|
|
|
},
|
|
|
|
get container () {
|
|
|
|
delete this.container;
|
|
|
|
return this.container = document.getElementById("allTabs-container");
|
|
|
|
},
|
|
|
|
get tabCloseButton () {
|
|
|
|
delete this.tabCloseButton;
|
|
|
|
return this.tabCloseButton = document.getElementById("allTabs-tab-close-button");
|
|
|
|
},
|
2011-07-07 23:46:50 -07:00
|
|
|
get toolbarButton() document.getElementById("alltabs-button"),
|
2009-12-28 07:44:20 -08:00
|
|
|
get previews () this.container.getElementsByClassName("allTabs-preview"),
|
2009-07-20 21:25:59 -07:00
|
|
|
get isOpen () this.panel.state == "open" || this.panel.state == "showing",
|
|
|
|
|
|
|
|
init: function allTabs_init() {
|
|
|
|
if (this._initiated)
|
|
|
|
return;
|
|
|
|
this._initiated = true;
|
2010-02-08 12:10:38 -08:00
|
|
|
|
2010-04-02 00:19:57 -07:00
|
|
|
tabPreviews.init();
|
|
|
|
|
2010-03-22 07:12:04 -07:00
|
|
|
Array.forEach(gBrowser.tabs, function (tab) {
|
2009-07-20 21:25:59 -07:00
|
|
|
this._addPreview(tab);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
gBrowser.tabContainer.addEventListener("TabOpen", this, false);
|
2009-12-12 11:31:21 -08:00
|
|
|
gBrowser.tabContainer.addEventListener("TabAttrModified", this, false);
|
2009-07-20 21:25:59 -07:00
|
|
|
gBrowser.tabContainer.addEventListener("TabMove", this, false);
|
|
|
|
gBrowser.tabContainer.addEventListener("TabClose", this, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
uninit: function allTabs_uninit() {
|
|
|
|
if (!this._initiated)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gBrowser.tabContainer.removeEventListener("TabOpen", this, false);
|
2009-12-12 11:31:21 -08:00
|
|
|
gBrowser.tabContainer.removeEventListener("TabAttrModified", this, false);
|
2009-07-20 21:25:59 -07:00
|
|
|
gBrowser.tabContainer.removeEventListener("TabMove", this, false);
|
|
|
|
gBrowser.tabContainer.removeEventListener("TabClose", this, false);
|
|
|
|
|
|
|
|
while (this.container.hasChildNodes())
|
|
|
|
this.container.removeChild(this.container.firstChild);
|
|
|
|
|
|
|
|
this._initiated = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
prefName: "browser.allTabs.previews",
|
|
|
|
readPref: function allTabs_readPref() {
|
2011-07-07 23:46:50 -07:00
|
|
|
var allTabsButton = this.toolbarButton;
|
2010-04-27 09:57:19 -07:00
|
|
|
if (!allTabsButton)
|
|
|
|
return;
|
2010-11-28 18:02:36 -08:00
|
|
|
|
|
|
|
if (gPrefService.getBoolPref(this.prefName)) {
|
|
|
|
allTabsButton.removeAttribute("type");
|
2009-07-20 21:25:59 -07:00
|
|
|
allTabsButton.setAttribute("command", "Browser:ShowAllTabs");
|
2010-11-28 18:02:36 -08:00
|
|
|
} else {
|
|
|
|
allTabsButton.setAttribute("type", "menu");
|
|
|
|
allTabsButton.removeAttribute("command");
|
2009-07-20 21:25:59 -07:00
|
|
|
allTabsButton.removeAttribute("oncommand");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
observe: function (aSubject, aTopic, aPrefName) {
|
|
|
|
this.readPref();
|
|
|
|
},
|
|
|
|
|
|
|
|
pick: function allTabs_pick(aPreview) {
|
|
|
|
if (!aPreview)
|
|
|
|
aPreview = this._firstVisiblePreview;
|
|
|
|
if (aPreview)
|
|
|
|
this.tabToSelect = aPreview._tab;
|
|
|
|
|
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
closeTab: function allTabs_closeTab(event) {
|
|
|
|
this.filterField.focus();
|
|
|
|
gBrowser.removeTab(event.currentTarget._targetPreview._tab);
|
|
|
|
},
|
|
|
|
|
|
|
|
filter: function allTabs_filter() {
|
|
|
|
if (this._currentFilter == this.filterField.value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._currentFilter = this.filterField.value;
|
|
|
|
|
|
|
|
var filter = this._currentFilter.split(/\s+/g);
|
|
|
|
this._visible = 0;
|
2009-12-28 07:44:20 -08:00
|
|
|
Array.forEach(this.previews, function (preview) {
|
2009-07-20 21:25:59 -07:00
|
|
|
var tab = preview._tab;
|
|
|
|
var matches = 0;
|
2010-07-29 16:39:57 -07:00
|
|
|
if (filter.length && !tab.hidden) {
|
2009-07-20 21:25:59 -07:00
|
|
|
let tabstring = tab.linkedBrowser.currentURI.spec;
|
|
|
|
try {
|
|
|
|
tabstring = decodeURI(tabstring);
|
|
|
|
} catch (e) {}
|
|
|
|
tabstring = tab.label + " " + tab.label.toLocaleLowerCase() + " " + tabstring;
|
|
|
|
for (let i = 0; i < filter.length; i++)
|
2012-09-08 13:56:04 -07:00
|
|
|
matches += tabstring.indexOf(filter[i]) > -1;
|
2009-07-20 21:25:59 -07:00
|
|
|
}
|
2010-07-29 16:39:57 -07:00
|
|
|
if (matches < filter.length || tab.hidden) {
|
2009-07-20 21:25:59 -07:00
|
|
|
preview.hidden = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._visible++;
|
|
|
|
this._updatePreview(preview);
|
|
|
|
preview.hidden = false;
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this._reflow();
|
|
|
|
},
|
|
|
|
|
|
|
|
open: function allTabs_open() {
|
2011-07-07 23:46:50 -07:00
|
|
|
var allTabsButton = this.toolbarButton;
|
|
|
|
if (allTabsButton &&
|
|
|
|
allTabsButton.getAttribute("type") == "menu") {
|
|
|
|
// Without setTimeout, the menupopup won't stay open when invoking
|
|
|
|
// "View > Show All Tabs" and the menu bar auto-hides.
|
|
|
|
setTimeout(function () {
|
|
|
|
allTabsButton.open = true;
|
|
|
|
}, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
this.init();
|
|
|
|
|
|
|
|
if (this.isOpen)
|
|
|
|
return;
|
|
|
|
|
2010-03-22 07:11:42 -07:00
|
|
|
this._maxPanelHeight = Math.max(gBrowser.clientHeight, screen.availHeight / 2);
|
|
|
|
this._maxPanelWidth = Math.max(gBrowser.clientWidth, screen.availWidth / 2);
|
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
this.filter();
|
|
|
|
|
|
|
|
tabPreviewPanelHelper.opening(this);
|
|
|
|
|
2010-03-22 07:11:42 -07:00
|
|
|
this.panel.popupBoxObject.setConsumeRollupEvent(Ci.nsIPopupBoxObject.ROLLUP_NO_CONSUME);
|
|
|
|
this.panel.openPopup(gBrowser, "overlap", 0, 0, false, true);
|
2009-07-20 21:25:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
close: function allTabs_close() {
|
|
|
|
this.panel.hidePopup();
|
|
|
|
},
|
|
|
|
|
|
|
|
setupGUI: function allTabs_setupGUI() {
|
|
|
|
this.filterField.focus();
|
2010-03-03 23:13:27 -08:00
|
|
|
this.filterField.placeholder = this.filterField.tooltipText;
|
2009-07-20 21:25:59 -07:00
|
|
|
|
|
|
|
this.panel.addEventListener("keypress", this, false);
|
|
|
|
this.panel.addEventListener("keypress", this, true);
|
|
|
|
this._browserCommandSet.addEventListener("command", this, false);
|
2010-03-22 07:11:42 -07:00
|
|
|
|
|
|
|
// When the panel is open, a second click on the all tabs button should
|
|
|
|
// close the panel but not re-open it.
|
|
|
|
document.getElementById("Browser:ShowAllTabs").setAttribute("disabled", "true");
|
2009-07-20 21:25:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
suspendGUI: function allTabs_suspendGUI() {
|
2010-03-03 23:13:27 -08:00
|
|
|
this.filterField.placeholder = "";
|
2009-07-20 21:25:59 -07:00
|
|
|
this.filterField.value = "";
|
|
|
|
this._currentFilter = null;
|
|
|
|
|
|
|
|
this._updateTabCloseButton();
|
|
|
|
|
|
|
|
this.panel.removeEventListener("keypress", this, false);
|
|
|
|
this.panel.removeEventListener("keypress", this, true);
|
|
|
|
this._browserCommandSet.removeEventListener("command", this, false);
|
2010-03-22 07:11:42 -07:00
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
document.getElementById("Browser:ShowAllTabs").removeAttribute("disabled");
|
|
|
|
}, 300);
|
2009-07-20 21:25:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function allTabs_handleEvent(event) {
|
2009-12-28 07:44:20 -08:00
|
|
|
if (/^Tab/.test(event.type)) {
|
|
|
|
var tab = event.target;
|
|
|
|
if (event.type != "TabOpen")
|
|
|
|
var preview = this._getPreview(tab);
|
|
|
|
}
|
2009-07-20 21:25:59 -07:00
|
|
|
switch (event.type) {
|
2009-12-12 11:31:21 -08:00
|
|
|
case "TabAttrModified":
|
2009-07-20 21:25:59 -07:00
|
|
|
// tab attribute modified (e.g. label, crop, busy, image)
|
2009-12-12 11:31:21 -08:00
|
|
|
if (!preview.hidden)
|
|
|
|
this._updatePreview(preview);
|
2009-07-20 21:25:59 -07:00
|
|
|
break;
|
|
|
|
case "TabOpen":
|
|
|
|
if (this.isOpen)
|
|
|
|
this.close();
|
2009-12-28 07:44:20 -08:00
|
|
|
this._addPreview(tab);
|
2008-07-15 09:11:00 -07:00
|
|
|
break;
|
2009-07-20 21:25:59 -07:00
|
|
|
case "TabMove":
|
2009-12-28 07:44:20 -08:00
|
|
|
let siblingPreview = tab.nextSibling &&
|
|
|
|
this._getPreview(tab.nextSibling);
|
|
|
|
if (siblingPreview)
|
|
|
|
siblingPreview.parentNode.insertBefore(preview, siblingPreview);
|
2009-07-20 21:25:59 -07:00
|
|
|
else
|
2009-12-28 07:44:20 -08:00
|
|
|
this.container.lastChild.appendChild(preview);
|
2010-01-22 00:44:16 -08:00
|
|
|
if (this.isOpen && !preview.hidden) {
|
2009-12-28 07:44:20 -08:00
|
|
|
this._reflow();
|
2010-01-22 00:44:16 -08:00
|
|
|
preview.focus();
|
|
|
|
}
|
2009-07-20 21:25:59 -07:00
|
|
|
break;
|
|
|
|
case "TabClose":
|
2009-12-28 07:44:20 -08:00
|
|
|
this._removePreview(preview);
|
2009-07-20 21:25:59 -07:00
|
|
|
break;
|
|
|
|
case "keypress":
|
|
|
|
this._onKeyPress(event);
|
2008-11-04 23:38:13 -08:00
|
|
|
break;
|
2009-07-20 21:25:59 -07:00
|
|
|
case "command":
|
|
|
|
if (event.target.id != "Browser:ShowAllTabs") {
|
|
|
|
// Close the panel when there's a browser command executing in the background.
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_visible: 0,
|
|
|
|
_currentFilter: null,
|
|
|
|
get _stack () {
|
|
|
|
delete this._stack;
|
|
|
|
return this._stack = document.getElementById("allTabs-stack");
|
|
|
|
},
|
2009-12-28 07:44:20 -08:00
|
|
|
get _browserCommandSet () {
|
|
|
|
delete this._browserCommandSet;
|
|
|
|
return this._browserCommandSet = document.getElementById("mainCommandSet");
|
|
|
|
},
|
2009-07-20 21:25:59 -07:00
|
|
|
get _previewLabelHeight () {
|
|
|
|
delete this._previewLabelHeight;
|
2009-12-28 07:44:20 -08:00
|
|
|
return this._previewLabelHeight = parseInt(getComputedStyle(this.previews[0], "").lineHeight);
|
2009-07-20 21:25:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
get _visiblePreviews ()
|
2009-12-28 07:44:20 -08:00
|
|
|
Array.filter(this.previews, function (preview) !preview.hidden),
|
2009-07-20 21:25:59 -07:00
|
|
|
|
|
|
|
get _firstVisiblePreview () {
|
|
|
|
if (this._visible == 0)
|
|
|
|
return null;
|
2009-12-28 07:44:20 -08:00
|
|
|
var previews = this.previews;
|
2009-07-20 21:25:59 -07:00
|
|
|
for (let i = 0; i < previews.length; i++) {
|
|
|
|
if (!previews[i].hidden)
|
|
|
|
return previews[i];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
_reflow: function allTabs_reflow() {
|
|
|
|
this._updateTabCloseButton();
|
|
|
|
|
2010-03-22 07:11:42 -07:00
|
|
|
const CONTAINER_MAX_WIDTH = this._maxPanelWidth * .95;
|
|
|
|
const CONTAINER_MAX_HEIGHT = this._maxPanelHeight - 35;
|
2009-07-20 21:25:59 -07:00
|
|
|
// the size of the whole preview relative to the thumbnail
|
|
|
|
const REL_PREVIEW_THUMBNAIL = 1.2;
|
2010-03-22 07:11:42 -07:00
|
|
|
const REL_PREVIEW_HEIGHT_WIDTH = tabPreviews.height / tabPreviews.width;
|
|
|
|
const PREVIEW_MAX_WIDTH = tabPreviews.width * REL_PREVIEW_THUMBNAIL;
|
2009-07-20 21:25:59 -07:00
|
|
|
|
|
|
|
var rows, previewHeight, previewWidth, outerHeight;
|
2010-03-22 07:11:42 -07:00
|
|
|
this._columns = Math.floor(CONTAINER_MAX_WIDTH / PREVIEW_MAX_WIDTH);
|
2009-07-20 21:25:59 -07:00
|
|
|
do {
|
|
|
|
rows = Math.ceil(this._visible / this._columns);
|
2010-03-22 07:11:42 -07:00
|
|
|
previewWidth = Math.min(PREVIEW_MAX_WIDTH,
|
|
|
|
Math.round(CONTAINER_MAX_WIDTH / this._columns));
|
|
|
|
previewHeight = Math.round(previewWidth * REL_PREVIEW_HEIGHT_WIDTH);
|
2009-07-20 21:25:59 -07:00
|
|
|
outerHeight = previewHeight + this._previewLabelHeight;
|
2010-03-22 07:11:42 -07:00
|
|
|
} while (rows * outerHeight > CONTAINER_MAX_HEIGHT && ++this._columns);
|
2009-07-20 21:25:59 -07:00
|
|
|
|
|
|
|
var outerWidth = previewWidth;
|
|
|
|
{
|
|
|
|
let innerWidth = Math.ceil(previewWidth / REL_PREVIEW_THUMBNAIL);
|
|
|
|
let innerHeight = Math.ceil(previewHeight / REL_PREVIEW_THUMBNAIL);
|
2009-07-26 00:53:04 -07:00
|
|
|
var canvasStyle = "max-width:" + innerWidth + "px;" +
|
2009-07-20 21:25:59 -07:00
|
|
|
"min-width:" + innerWidth + "px;" +
|
|
|
|
"max-height:" + innerHeight + "px;" +
|
|
|
|
"min-height:" + innerHeight + "px;";
|
|
|
|
}
|
|
|
|
|
2009-12-28 07:44:20 -08:00
|
|
|
var previews = Array.slice(this.previews);
|
|
|
|
|
|
|
|
while (this.container.hasChildNodes())
|
|
|
|
this.container.removeChild(this.container.firstChild);
|
2010-01-16 03:56:37 -08:00
|
|
|
for (let i = rows || 1; i > 0; i--)
|
2009-12-28 07:44:20 -08:00
|
|
|
this.container.appendChild(document.createElement("hbox"));
|
|
|
|
|
|
|
|
var row = this.container.firstChild;
|
2010-03-06 08:06:04 -08:00
|
|
|
var colCount = 0;
|
2009-12-28 07:44:20 -08:00
|
|
|
previews.forEach(function (preview) {
|
2010-03-06 08:06:04 -08:00
|
|
|
if (!preview.hidden &&
|
|
|
|
++colCount > this._columns) {
|
|
|
|
row = row.nextSibling;
|
|
|
|
colCount = 1;
|
|
|
|
}
|
2009-07-20 21:25:59 -07:00
|
|
|
preview.setAttribute("minwidth", outerWidth);
|
|
|
|
preview.setAttribute("height", outerHeight);
|
|
|
|
preview.setAttribute("canvasstyle", canvasStyle);
|
|
|
|
preview.removeAttribute("closebuttonhover");
|
2009-12-28 07:44:20 -08:00
|
|
|
row.appendChild(preview);
|
2009-07-20 21:25:59 -07:00
|
|
|
}, this);
|
|
|
|
|
2010-03-22 07:11:42 -07:00
|
|
|
this._stack.width = this._maxPanelWidth;
|
2009-07-20 21:25:59 -07:00
|
|
|
this.container.width = Math.ceil(outerWidth * Math.min(this._columns, this._visible));
|
2010-03-22 07:11:42 -07:00
|
|
|
this.container.left = Math.round((this._maxPanelWidth - this.container.width) / 2);
|
|
|
|
this.container.maxWidth = this._maxPanelWidth - this.container.left;
|
2009-07-20 21:25:59 -07:00
|
|
|
this.container.maxHeight = rows * outerHeight;
|
|
|
|
},
|
|
|
|
|
|
|
|
_addPreview: function allTabs_addPreview(aTab) {
|
|
|
|
var preview = document.createElement("button");
|
|
|
|
preview.className = "allTabs-preview";
|
|
|
|
preview._tab = aTab;
|
2009-12-28 07:44:20 -08:00
|
|
|
this.container.lastChild.appendChild(preview);
|
2009-07-20 21:25:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_removePreview: function allTabs_removePreview(aPreview) {
|
|
|
|
var updateUI = (this.isOpen && !aPreview.hidden);
|
|
|
|
aPreview._tab = null;
|
2009-12-28 07:44:20 -08:00
|
|
|
aPreview.parentNode.removeChild(aPreview);
|
2009-07-20 21:25:59 -07:00
|
|
|
if (updateUI) {
|
|
|
|
this._visible--;
|
|
|
|
this._reflow();
|
|
|
|
this.filterField.focus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreview: function allTabs_getPreview(aTab) {
|
2009-12-28 07:44:20 -08:00
|
|
|
var previews = this.previews;
|
2009-07-20 21:25:59 -07:00
|
|
|
for (let i = 0; i < previews.length; i++)
|
|
|
|
if (previews[i]._tab == aTab)
|
|
|
|
return previews[i];
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateTabCloseButton: function allTabs_updateTabCloseButton(event) {
|
|
|
|
if (event && event.target == this.tabCloseButton)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this.tabCloseButton._targetPreview) {
|
|
|
|
if (event && event.target == this.tabCloseButton._targetPreview)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.tabCloseButton._targetPreview.removeAttribute("closebuttonhover");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event &&
|
2009-12-28 07:44:20 -08:00
|
|
|
event.target.parentNode.parentNode == this.container &&
|
2009-07-20 21:25:59 -07:00
|
|
|
(event.target._tab.previousSibling || event.target._tab.nextSibling)) {
|
2010-03-22 07:11:42 -07:00
|
|
|
let canvas = event.target.firstChild.getBoundingClientRect();
|
2009-07-20 21:25:59 -07:00
|
|
|
let container = this.container.getBoundingClientRect();
|
|
|
|
let tabCloseButton = this.tabCloseButton.getBoundingClientRect();
|
|
|
|
let alignLeft = getComputedStyle(this.panel, "").direction == "rtl";
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
alignLeft = !alignLeft;
|
|
|
|
#endif
|
2010-03-22 07:11:42 -07:00
|
|
|
this.tabCloseButton.left = canvas.left -
|
2009-07-20 21:25:59 -07:00
|
|
|
container.left +
|
|
|
|
parseInt(this.container.left) +
|
|
|
|
(alignLeft ? 0 :
|
2010-03-22 07:11:42 -07:00
|
|
|
canvas.width - tabCloseButton.width);
|
|
|
|
this.tabCloseButton.top = canvas.top - container.top;
|
2009-07-20 21:25:59 -07:00
|
|
|
this.tabCloseButton._targetPreview = event.target;
|
|
|
|
this.tabCloseButton.style.visibility = "visible";
|
|
|
|
event.target.setAttribute("closebuttonhover", "true");
|
|
|
|
} else {
|
|
|
|
this.tabCloseButton.style.visibility = "hidden";
|
|
|
|
this.tabCloseButton.left = this.tabCloseButton.top = 0;
|
|
|
|
this.tabCloseButton._targetPreview = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_updatePreview: function allTabs_updatePreview(aPreview) {
|
|
|
|
aPreview.setAttribute("label", aPreview._tab.label);
|
|
|
|
aPreview.setAttribute("tooltiptext", aPreview._tab.label);
|
|
|
|
aPreview.setAttribute("crop", aPreview._tab.crop);
|
|
|
|
if (aPreview._tab.image)
|
|
|
|
aPreview.setAttribute("image", aPreview._tab.image);
|
|
|
|
else
|
|
|
|
aPreview.removeAttribute("image");
|
|
|
|
|
|
|
|
var thumbnail = tabPreviews.get(aPreview._tab);
|
|
|
|
if (aPreview.firstChild) {
|
|
|
|
if (aPreview.firstChild == thumbnail)
|
|
|
|
return;
|
|
|
|
aPreview.removeChild(aPreview.firstChild);
|
|
|
|
}
|
|
|
|
aPreview.appendChild(thumbnail);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onKeyPress: function allTabs_onKeyPress(event) {
|
|
|
|
if (event.eventPhase == event.CAPTURING_PHASE) {
|
|
|
|
this._onCapturingKeyPress(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.keyCode == event.DOM_VK_ESCAPE) {
|
|
|
|
this.close();
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.target == this.filterField) {
|
|
|
|
switch (event.keyCode) {
|
|
|
|
case event.DOM_VK_UP:
|
|
|
|
if (this._visible) {
|
|
|
|
let previews = this._visiblePreviews;
|
|
|
|
let columns = Math.min(previews.length, this._columns);
|
|
|
|
previews[Math.floor(previews.length / columns) * columns - 1].focus();
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case event.DOM_VK_DOWN:
|
|
|
|
if (this._visible) {
|
|
|
|
this._firstVisiblePreview.focus();
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onCapturingKeyPress: function allTabs_onCapturingKeyPress(event) {
|
|
|
|
switch (event.keyCode) {
|
|
|
|
case event.DOM_VK_UP:
|
|
|
|
case event.DOM_VK_DOWN:
|
|
|
|
if (event.target != this.filterField)
|
|
|
|
this._advanceFocusVertically(event);
|
2008-07-15 09:11:00 -07:00
|
|
|
break;
|
2009-07-20 21:25:59 -07:00
|
|
|
case event.DOM_VK_RETURN:
|
|
|
|
if (event.target == this.filterField) {
|
|
|
|
this.filter();
|
|
|
|
this.pick();
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2008-11-06 10:45:48 -08:00
|
|
|
}
|
2008-11-04 23:38:13 -08:00
|
|
|
break;
|
2008-07-15 09:11:00 -07:00
|
|
|
}
|
2009-07-20 21:25:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_advanceFocusVertically: function allTabs_advanceFocusVertically(event) {
|
|
|
|
var preview = document.activeElement;
|
2009-12-28 07:44:20 -08:00
|
|
|
if (!preview || preview.parentNode.parentNode != this.container)
|
2009-07-20 21:25:59 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
var up = (event.keyCode == event.DOM_VK_UP);
|
|
|
|
var previews = this._visiblePreviews;
|
|
|
|
|
|
|
|
if (up && preview == previews[0]) {
|
|
|
|
this.filterField.focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var i = previews.indexOf(preview);
|
|
|
|
var columns = Math.min(previews.length, this._columns);
|
|
|
|
var column = i % columns;
|
|
|
|
var row = Math.floor(i / columns);
|
|
|
|
|
|
|
|
function newIndex() row * columns + column;
|
|
|
|
function outOfBounds() newIndex() >= previews.length;
|
|
|
|
|
|
|
|
if (up) {
|
|
|
|
row--;
|
|
|
|
if (row < 0) {
|
|
|
|
let rows = Math.ceil(previews.length / columns);
|
|
|
|
row = rows - 1;
|
|
|
|
column--;
|
|
|
|
if (outOfBounds())
|
|
|
|
row--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
row++;
|
|
|
|
if (outOfBounds()) {
|
|
|
|
if (column == columns - 1) {
|
|
|
|
this.filterField.focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
row = 0;
|
|
|
|
column++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
previews[newIndex()].focus();
|
2008-07-15 09:11:00 -07:00
|
|
|
}
|
|
|
|
};
|