middle click on tab link should close the tab

This commit is contained in:
Piro / SHIMODA Hiroshi 2011-12-10 02:05:08 +09:00
parent 8ec27ba13c
commit 9259ecad17
2 changed files with 51 additions and 5 deletions

View File

@ -147,14 +147,47 @@ function getTabById(aId)
function onItemClick(aEvent) function onItemClick(aEvent)
{ {
var gBrowser = getOwnerTabBrowser();
if (!gBrowser)
return;
var tab = getTabById(aEvent.getData('id')); var tab = getTabById(aEvent.getData('id'));
if (tab) if (!tab)
return;
var button = aEvent.getData('button');
var altKey = aEvent.getData('altKey');
var ctrlKey = aEvent.getData('ctrlKey');
var metaKey = aEvent.getData('metaKey');
var shiftKey = aEvent.getData('shiftKey');
var isMiddleClick = (
(
button == 1 &&
!altKey &&
!ctrlKey &&
!metaKey &&
!shiftKey
) ||
(
button == 0 &&
!altKey &&
(ctrlKey || metaKey) &&
!shiftKey
)
);
if (isMiddleClick)
gBrowser.removeTab(tab);
else if (button != 2)
gBrowser.selectedTab = tab; gBrowser.selectedTab = tab;
} }
function updateTree() function updateTree()
{ {
if (window.closed)
return;
var tree = document.getElementById('tree'); var tree = document.getElementById('tree');
var range = document.createRange(); var range = document.createRange();
@ -162,13 +195,18 @@ function updateTree()
range.deleteContents(); range.deleteContents();
range.detach(); range.detach();
tree.appendChild(PseudoTreeBuilder.build(getOwnerTab())); var contents = PseudoTreeBuilder.build(getOwnerTab());
if (contents)
tree.appendChild(contents);
} }
function checkUpdateTreeNow() function checkUpdateTreeNow()
{ {
if (getOwnerTab().selected) if (getOwnerTab().selected)
window.setTimeout(onTabSelect, 0); window.setTimeout(function() {
if (!window.closed)
onTabSelect();
}, 0);
} }
var gShouldUpdate = false; var gShouldUpdate = false;

View File

@ -58,8 +58,11 @@ var PseudoTreeBuilder = {
var tree = this.createTabItem(aTab); var tree = this.createTabItem(aTab);
tree.querySelector("."+this.kTREEROW) var row = tree.querySelector("."+this.kTREEROW);
.className += " "+this.kROOTITEM; if (!row)
return;
row.className += " "+this.kROOTITEM;
tree.setAttribute('onclick', <![CDATA[ tree.setAttribute('onclick', <![CDATA[
var doc = event.target.ownerDocument; var doc = event.target.ownerDocument;
@ -74,6 +77,11 @@ var PseudoTreeBuilder = {
var customEvent = doc.createEvent('DataContainerEvent'); var customEvent = doc.createEvent('DataContainerEvent');
customEvent.initEvent(%EVENT_TYPE%, true, true); customEvent.initEvent(%EVENT_TYPE%, true, true);
customEvent.setData('id', label.getAttribute('tab-id')); customEvent.setData('id', label.getAttribute('tab-id'));
customEvent.setData('button', event.button);
customEvent.setData('altKey', event.altKey);
customEvent.setData('ctrlKey', event.ctrlKey);
customEvent.setData('metaKey', event.metaKey);
customEvent.setData('shiftKey', event.shiftKey);
event.target.dispatchEvent(customEvent); event.target.dispatchEvent(customEvent);
} }
]]>.toString().replace('%EVENT_TYPE%', this.kTAB_LINK_CLICK.quote())); ]]>.toString().replace('%EVENT_TYPE%', this.kTAB_LINK_CLICK.quote()));