2008-07-15 09:11:00 -07:00
|
|
|
/*
|
|
|
|
#ifdef 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 Tab Previews.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2008
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Dão Gottwald <dao@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 *****
|
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tab previews utility, produces thumbnails
|
|
|
|
*/
|
|
|
|
var tabPreviews = {
|
2008-09-19 02:44:15 -07:00
|
|
|
aspectRatio: 0.5625, // 16:9
|
2009-07-20 21:25:59 -07:00
|
|
|
init: function tabPreviews_init() {
|
|
|
|
this.width = Math.ceil(screen.availWidth / 5.75);
|
2008-07-15 09:11:00 -07:00
|
|
|
this.height = Math.round(this.width * this.aspectRatio);
|
|
|
|
|
|
|
|
gBrowser.tabContainer.addEventListener("TabSelect", this, false);
|
|
|
|
gBrowser.tabContainer.addEventListener("SSTabRestored", this, false);
|
|
|
|
},
|
2009-07-20 21:25:59 -07:00
|
|
|
uninit: function tabPreviews_uninit() {
|
2008-07-15 09:11:00 -07:00
|
|
|
gBrowser.tabContainer.removeEventListener("TabSelect", this, false);
|
|
|
|
gBrowser.tabContainer.removeEventListener("SSTabRestored", this, false);
|
|
|
|
this._selectedTab = null;
|
|
|
|
},
|
2009-07-20 21:25:59 -07:00
|
|
|
get: function tabPreviews_get(aTab) {
|
2008-08-30 17:43:35 -07:00
|
|
|
if (aTab.__thumbnail_lastURI &&
|
|
|
|
aTab.__thumbnail_lastURI != aTab.linkedBrowser.currentURI.spec) {
|
|
|
|
aTab.__thumbnail = null;
|
|
|
|
aTab.__thumbnail_lastURI = null;
|
|
|
|
}
|
2008-07-15 09:11:00 -07:00
|
|
|
return aTab.__thumbnail || this.capture(aTab, !aTab.hasAttribute("busy"));
|
|
|
|
},
|
2009-07-20 21:25:59 -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
|
|
|
},
|
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);
|
|
|
|
host.panel.addEventListener("popuphidden", 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;
|
|
|
|
}
|
2009-07-27 09:55:31 -07:00
|
|
|
},
|
|
|
|
_popuphidden: function (host) {
|
|
|
|
// Destroy the widget in order to prevent outdated content
|
|
|
|
// when re-opening the panel.
|
|
|
|
host.panel.hidden = true;
|
2009-07-20 21:25:59 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
|
2008-11-04 00:19:55 -08:00
|
|
|
var list = Array.slice(gBrowser.mTabs);
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2008-11-04 00:19:55 -08:00
|
|
|
if (this._closing)
|
|
|
|
this.detachTab(this._closing, list);
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2008-11-04 00:19:55 -08:00
|
|
|
for (let i = 0; i < gBrowser.tabContainer.selectedIndex; i++)
|
|
|
|
list.push(list.shift());
|
2008-11-04 23:38:13 -08:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
if (this.recentlyUsedLimit != 0) {
|
2008-11-04 00:19:55 -08:00
|
|
|
let recentlyUsedTabs = this._recentlyUsedTabs;
|
|
|
|
if (this.recentlyUsedLimit > 0)
|
|
|
|
recentlyUsedTabs = this._recentlyUsedTabs.slice(0, this.recentlyUsedLimit);
|
|
|
|
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) {
|
|
|
|
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) {
|
|
|
|
if (this.panel.state == "open") {
|
|
|
|
if (aForward)
|
|
|
|
document.commandDispatcher.advanceFocus();
|
|
|
|
else
|
|
|
|
document.commandDispatcher.rewindFocus();
|
|
|
|
} else {
|
|
|
|
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
|
|
|
},
|
2009-07-20 21:25:59 -07:00
|
|
|
detachTab: function ctrlTab_detachTab(aTab, aTabs) {
|
2008-11-04 00:19:55 -08:00
|
|
|
var tabs = aTabs || this._recentlyUsedTabs;
|
|
|
|
var i = tabs.indexOf(aTab);
|
2008-07-15 09:11:00 -07:00
|
|
|
if (i >= 0)
|
2008-11-04 00:19:55 -08:00
|
|
|
tabs.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();
|
|
|
|
if (gBrowser.mTabs.length > 2) {
|
|
|
|
this.open();
|
|
|
|
} else if (gBrowser.mTabs.length == 2) {
|
|
|
|
gBrowser.selectedTab = gBrowser.selectedTab.nextSibling ||
|
|
|
|
gBrowser.selectedTab.previousSibling;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2008-11-04 00:19:55 -08:00
|
|
|
this._closing = aTab;
|
2008-11-04 23:38:13 -08:00
|
|
|
this._tabList = null;
|
2009-07-20 21:25:59 -07:00
|
|
|
this.updatePreviews();
|
2008-11-04 00:19:55 -08:00
|
|
|
this._closing = null;
|
2009-07-20 21:25:59 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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");
|
|
|
|
},
|
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
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
Array.forEach(gBrowser.mTabs, function (tab) {
|
|
|
|
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() {
|
|
|
|
var allTabsButton = document.getAnonymousElementByAttribute(
|
|
|
|
gBrowser.tabContainer, "anonid", "alltabs-button");
|
|
|
|
if (gPrefService.getBoolPref(this.prefName)) {
|
|
|
|
allTabsButton.removeAttribute("type");
|
|
|
|
allTabsButton.setAttribute("command", "Browser:ShowAllTabs");
|
|
|
|
} else {
|
|
|
|
allTabsButton.setAttribute("type", "menu");
|
|
|
|
allTabsButton.removeAttribute("command");
|
|
|
|
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;
|
|
|
|
if (filter.length) {
|
|
|
|
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++)
|
|
|
|
matches += tabstring.indexOf(filter[i]) > -1;
|
|
|
|
}
|
|
|
|
if (matches < filter.length) {
|
|
|
|
preview.hidden = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._visible++;
|
|
|
|
this._updatePreview(preview);
|
|
|
|
preview.hidden = false;
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this._reflow();
|
|
|
|
},
|
|
|
|
|
|
|
|
open: function allTabs_open() {
|
|
|
|
this.init();
|
|
|
|
|
|
|
|
if (this.isOpen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.filter();
|
|
|
|
|
|
|
|
tabPreviewPanelHelper.opening(this);
|
|
|
|
|
|
|
|
this.panel.popupBoxObject.setConsumeRollupEvent(Ci.nsIPopupBoxObject.ROLLUP_CONSUME);
|
|
|
|
var estimateHeight = (this._maxHeight + parseInt(this.container.maxHeight) + 50) / 2;
|
2009-09-07 05:16:30 -07:00
|
|
|
this.panel.openPopupAtScreen(screen.availLeft + (screen.availWidth - this._maxWidth) / 2,
|
|
|
|
screen.availTop + (screen.availHeight - estimateHeight) / 2,
|
|
|
|
false);
|
2009-07-20 21:25:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
close: function allTabs_close() {
|
|
|
|
this.panel.hidePopup();
|
|
|
|
},
|
|
|
|
|
|
|
|
setupGUI: function allTabs_setupGUI() {
|
|
|
|
this.filterField.focus();
|
|
|
|
this.filterField.setAttribute("emptytext", this.filterField.tooltipText);
|
|
|
|
|
|
|
|
this.panel.addEventListener("keypress", this, false);
|
|
|
|
this.panel.addEventListener("keypress", this, true);
|
|
|
|
this._browserCommandSet.addEventListener("command", this, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
suspendGUI: function allTabs_suspendGUI() {
|
|
|
|
this.filterField.removeAttribute("emptytext");
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
|
|
|
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 _maxWidth () screen.availWidth * .9,
|
|
|
|
get _maxHeight () screen.availHeight * .75,
|
|
|
|
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();
|
|
|
|
|
|
|
|
// the size of the whole preview relative to the thumbnail
|
|
|
|
const REL_PREVIEW_THUMBNAIL = 1.2;
|
|
|
|
|
|
|
|
var maxHeight = this._maxHeight;
|
|
|
|
var maxWidth = this._maxWidth;
|
|
|
|
var rel = tabPreviews.height / tabPreviews.width;
|
|
|
|
var rows, previewHeight, previewWidth, outerHeight;
|
|
|
|
var previewMaxWidth = tabPreviews.width * REL_PREVIEW_THUMBNAIL;
|
|
|
|
this._columns = Math.floor(maxWidth / previewMaxWidth);
|
|
|
|
do {
|
|
|
|
rows = Math.ceil(this._visible / this._columns);
|
|
|
|
previewWidth = Math.min(previewMaxWidth, Math.round(maxWidth / this._columns));
|
|
|
|
previewHeight = Math.round(previewWidth * rel);
|
|
|
|
outerHeight = previewHeight + this._previewLabelHeight;
|
|
|
|
} while (rows * outerHeight > maxHeight && ++this._columns);
|
|
|
|
|
|
|
|
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;
|
|
|
|
var i = 0;
|
|
|
|
previews.forEach(function (preview) {
|
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);
|
|
|
|
if (!preview.hidden)
|
|
|
|
row = this.container.childNodes[Math.floor(++i / this._columns)];
|
2009-07-20 21:25:59 -07:00
|
|
|
}, this);
|
|
|
|
|
|
|
|
this._stack.width = maxWidth;
|
|
|
|
this.container.width = Math.ceil(outerWidth * Math.min(this._columns, this._visible));
|
|
|
|
this.container.left = Math.round((maxWidth - this.container.width) / 2);
|
|
|
|
this.container.maxWidth = maxWidth - this.container.left;
|
|
|
|
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)) {
|
|
|
|
let preview = event.target.getBoundingClientRect();
|
|
|
|
let container = this.container.getBoundingClientRect();
|
|
|
|
let tabCloseButton = this.tabCloseButton.getBoundingClientRect();
|
|
|
|
let alignLeft = getComputedStyle(this.panel, "").direction == "rtl";
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
alignLeft = !alignLeft;
|
|
|
|
#endif
|
|
|
|
this.tabCloseButton.left = preview.left -
|
|
|
|
container.left +
|
|
|
|
parseInt(this.container.left) +
|
|
|
|
(alignLeft ? 0 :
|
|
|
|
preview.width - tabCloseButton.width);
|
|
|
|
this.tabCloseButton.top = preview.top - container.top;
|
|
|
|
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
|
|
|
}
|
|
|
|
};
|