Tab Kitがある時にスプリッタが二重に表示されてしまう問題に対処

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@6326 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2010-03-02 14:40:12 +00:00
parent 01f2263321
commit e94b5427c9
2 changed files with 88 additions and 64 deletions

View File

@ -166,11 +166,12 @@ TreeStyleTabBrowser.prototype = {
b.mStrip.addEventListener('dragend', this, false); b.mStrip.addEventListener('dragend', this, false);
b.mStrip.addEventListener('dragover', this, false); b.mStrip.addEventListener('dragover', this, false);
b.mStrip.addEventListener('dragdrop', this, false); b.mStrip.addEventListener('dragdrop', this, false);
b.mStrip.addEventListener('mousedown', this, true);
b.mStrip.addEventListener('mouseup', this, false);
b.mStrip.addEventListener('click', this, false);
b.mTabContainer.addEventListener('mouseover', this, true); b.mTabContainer.addEventListener('mouseover', this, true);
b.mTabContainer.addEventListener('mouseout', this, true); b.mTabContainer.addEventListener('mouseout', this, true);
b.mTabContainer.addEventListener('click', this, true);
b.mTabContainer.addEventListener('dblclick', this, true); b.mTabContainer.addEventListener('dblclick', this, true);
b.mTabContainer.addEventListener('mousedown', this, true);
b.mTabContainer.addEventListener('select', this, true); b.mTabContainer.addEventListener('select', this, true);
b.mTabContainer.addEventListener('scroll', this, true); b.mTabContainer.addEventListener('scroll', this, true);
b.mPanelContainer.addEventListener('dragexit', this, false); b.mPanelContainer.addEventListener('dragexit', this, false);
@ -1016,22 +1017,26 @@ TreeStyleTabBrowser.prototype = {
_ensureNewSplitter : function TSTBrowser__ensureNewSplitter() _ensureNewSplitter : function TSTBrowser__ensureNewSplitter()
{ {
var splitter = document.getAnonymousElementByAttribute(this.mTabBrowser, 'class', this.kSPLITTER); var splitter = document.getAnonymousElementByAttribute(this.mTabBrowser, 'class', this.kSPLITTER) ||
document.getAnonymousElementByAttribute(this.mTabBrowser, 'id', 'tabkit-splitter'); // Tab Kit
// We always have to re-create splitter, because its "collapse" // We always have to re-create splitter, because its "collapse"
// behavior becomes broken by repositioning of the tab bar. // behavior becomes broken by repositioning of the tab bar.
if (splitter) { if (splitter) {
splitter.parentNode.removeChild(splitter); let oldSplitter = splitter;
splitter.removeEventListener('mousedown', this, true); splitter = oldSplitter.cloneNode(true);
oldSplitter.parentNode.removeChild(oldSplitter);
}
else {
splitter = document.createElement('splitter');
splitter.setAttribute('state', 'open');
splitter.appendChild(document.createElement('grippy'));
} }
splitter = document.createElement('splitter'); var splitterClass = splitter.getAttribute('class') || '';
splitter.setAttribute('class', this.kSPLITTER); if (splitterClass.indexOf(this.kSPLITTER) < 0)
splitter.addEventListener('mousedown', this, true); splitterClass += (splitterClass ? ' ' : '' ) + this.kSPLITTER;
splitter.setAttribute('onclick', 'TreeStyleTabService.onTabbarResizerClick(event);'); splitter.setAttribute('class', splitterClass);
splitter.setAttribute('onmouseup', 'TreeStyleTabService.onTabbarResized(event);');
splitter.setAttribute('state', 'open');
splitter.appendChild(document.createElement('grippy'));
var ref = this.mTabBrowser.mPanelContainer; var ref = this.mTabBrowser.mPanelContainer;
ref.parentNode.insertBefore(splitter, ref); ref.parentNode.insertBefore(splitter, ref);
@ -1152,9 +1157,12 @@ TreeStyleTabBrowser.prototype = {
b.mStrip.removeEventListener('dragend', this, false); b.mStrip.removeEventListener('dragend', this, false);
b.mStrip.removeEventListener('dragover', this, false); b.mStrip.removeEventListener('dragover', this, false);
b.mStrip.removeEventListener('dragdrop', this, false); b.mStrip.removeEventListener('dragdrop', this, false);
b.mTabContainer.removeEventListener('click', this, true); b.mStrip.removeEventListener('mousedown', this, true);
b.mStrip.removeEventListener('mouseup', this, false);
b.mStrip.removeEventListener('click', this, false);
b.mTabContainer.removeEventListener('mouseover', this, true);
b.mTabContainer.removeEventListener('mouseout', this, true);
b.mTabContainer.removeEventListener('dblclick', this, true); b.mTabContainer.removeEventListener('dblclick', this, true);
b.mTabContainer.removeEventListener('mousedown', this, true);
b.mTabContainer.removeEventListener('select', this, true); b.mTabContainer.removeEventListener('select', this, true);
b.mTabContainer.removeEventListener('scroll', this, true); b.mTabContainer.removeEventListener('scroll', this, true);
b.mPanelContainer.removeEventListener('dragexit', this, false); b.mPanelContainer.removeEventListener('dragexit', this, false);
@ -1367,72 +1375,58 @@ TreeStyleTabBrowser.prototype = {
switch (aEvent.type) switch (aEvent.type)
{ {
case 'TabOpen': case 'TabOpen':
this.onTabAdded(aEvent); return this.onTabAdded(aEvent);
return;
case 'TabClose': case 'TabClose':
this.onTabRemoved(aEvent); return this.onTabRemoved(aEvent);
this.updateLastScrollPosition();
return;
case 'TabMove': case 'TabMove':
this.onTabMove(aEvent); return this.onTabMove(aEvent);
return;
case 'SSTabRestoring': case 'SSTabRestoring':
this.onTabRestoring(aEvent); return this.onTabRestoring(aEvent);
return;
case 'SSTabRestored': case 'SSTabRestored':
this.onTabRestored(aEvent); return this.onTabRestored(aEvent);
return;
case 'select': case 'select':
this.onTabSelect(aEvent); return this.onTabSelect(aEvent);
return;
case 'click': case 'click':
if (aEvent.target.ownerDocument == document) return this.onClick(aEvent);
this.onTabClick(aEvent);
return;
case 'dblclick': case 'dblclick':
this.onDblClick(aEvent); return this.onDblClick(aEvent);
return;
case 'mousedown': case 'mousedown':
this.onMouseDown(aEvent); return this.onMouseDown(aEvent);
return;
case 'mouseup':
return this.onMouseUp(aEvent);
case 'scroll': case 'scroll':
this.onScroll(aEvent); return this.onScroll(aEvent);
return;
case 'popupshowing': case 'popupshowing':
this.onPopupShowing(aEvent); return this.onPopupShowing(aEvent)
return;
case 'draggesture': case 'draggesture':
nsDragAndDrop.startDrag(aEvent, this.tabbarDNDObserver); return nsDragAndDrop.startDrag(aEvent, this.tabbarDNDObserver);
return;
case 'dragenter': case 'dragenter':
nsDragAndDrop.dragEnter(aEvent, this.tabbarDNDObserver); return nsDragAndDrop.dragEnter(aEvent, this.tabbarDNDObserver);
return;
case 'dragexit': case 'dragexit':
nsDragAndDrop.dragExit( return nsDragAndDrop.dragExit(
aEvent, aEvent,
aEvent.currentTarget == this.mTabBrowser.mStrip ? aEvent.currentTarget == this.mTabBrowser.mStrip ?
this.tabbarDNDObserver : this.tabbarDNDObserver :
this.panelDNDObserver this.panelDNDObserver
); );
return;
case 'dragend': case 'dragend':
this.tabbarDNDObserver.onDragEnd(aEvent); return this.tabbarDNDObserver.onDragEnd(aEvent);
return;
case 'dragover': case 'dragover':
case 'dragdrop': case 'dragdrop':
@ -1465,8 +1459,7 @@ TreeStyleTabBrowser.prototype = {
case 'overflow': case 'overflow':
case 'underflow': case 'underflow':
this.onTabbarOverflow(aEvent); return this.onTabbarOverflow(aEvent);
return;
case 'MultipleTabHandlerTabsClosing': case 'MultipleTabHandlerTabsClosing':
@ -1601,7 +1594,7 @@ TreeStyleTabBrowser.prototype = {
var collapsed = this.isCollapsed(tab); var collapsed = this.isCollapsed(tab);
if (collapsed) if (collapsed)
this.stopRendering(); this.stopRendering();
var subtreeCollapsed = this.isSubtreeCollapsed(tab); var subtreeCollapsed = this.isSubtreeCollapsed(tab);
if ( if (
@ -1790,6 +1783,8 @@ TreeStyleTabBrowser.prototype = {
b.selectedTab = nextFocusedTab; b.selectedTab = nextFocusedTab;
} }
this.updateLastScrollPosition();
if (collapsed) if (collapsed)
this.startRendering(); this.startRendering();
}, },
@ -2353,11 +2348,12 @@ TreeStyleTabBrowser.prototype = {
this.updateInvertedTabContentsOrder(); this.updateInvertedTabContentsOrder();
}, },
onTabClick : function TSTBrowser_onTabClick(aEvent) onTabClick : function TSTBrowser_onTabClick(aEvent, aTab)
{ {
aTab = aTab || this.getTabFromEvent(aEvent);
if (aEvent.button == 1) { if (aEvent.button == 1) {
let tab = this.getTabFromEvent(aEvent); if (!this.warnAboutClosingTabSubtreeOf(aTab)) {
if (tab && !this.warnAboutClosingTabSubtreeOf(tab)) {
aEvent.preventDefault(); aEvent.preventDefault();
aEvent.stopPropagation(); aEvent.stopPropagation();
} }
@ -2368,9 +2364,8 @@ TreeStyleTabBrowser.prototype = {
return; return;
if (this.isEventFiredOnTwisty(aEvent)) { if (this.isEventFiredOnTwisty(aEvent)) {
let tab = this.getTabFromEvent(aEvent); if (this.hasChildTabs(aTab) && this.canCollapseSubtree()) {
if (this.hasChildTabs(tab) && this.canCollapseSubtree()) { this.collapseExpandSubtree(aTab, aTab.getAttribute(this.kSUBTREE_COLLAPSED) != 'true');
this.collapseExpandSubtree(tab, tab.getAttribute(this.kSUBTREE_COLLAPSED) != 'true');
aEvent.preventDefault(); aEvent.preventDefault();
aEvent.stopPropagation(); aEvent.stopPropagation();
} }
@ -2378,20 +2373,12 @@ TreeStyleTabBrowser.prototype = {
} }
if (this.isEventFiredOnClosebox(aEvent)) { if (this.isEventFiredOnClosebox(aEvent)) {
let tab = this.getTabFromEvent(aEvent); if (!this.warnAboutClosingTabSubtreeOf(aTab)) {
if (!this.warnAboutClosingTabSubtreeOf(tab)) {
aEvent.preventDefault(); aEvent.preventDefault();
aEvent.stopPropagation(); aEvent.stopPropagation();
} }
return; return;
} }
// click on indented space on the tab bar
if (!this.getTabFromEvent(aEvent)) {
let tab = this.getTabFromTabbarEvent(aEvent);
if (tab) this.mTabBrowser.selectedTab = tab;
return;
}
}, },
getTabFromTabbarEvent : function TSTBrowser_getTabFromTabbarEvent(aEvent) getTabFromTabbarEvent : function TSTBrowser_getTabFromTabbarEvent(aEvent)
{ {
@ -2415,6 +2402,27 @@ TreeStyleTabBrowser.prototype = {
return tab; return tab;
}, },
onClick : function TSTBrowser_onClick(aEvent)
{
if (aEvent.target.ownerDocument != document)
return;
var tab = this.getTabFromEvent(aEvent);
var splitter = tab ? null : this.getSplitterFromEvent(aEvent) ;
if (tab) {
this.onTabClick(aEvent, tab);
}
else if (splitter) {
TreeStyleTabService.onTabbarResizerClick(aEvent);
}
else {
// click on indented space on the tab bar
tab = this.getTabFromTabbarEvent(aEvent);
if (tab) this.mTabBrowser.selectedTab = tab;
}
},
onDblClick : function TSTBrowser_onDblClick(aEvent) onDblClick : function TSTBrowser_onDblClick(aEvent)
{ {
var tab = this.getTabFromEvent(aEvent); var tab = this.getTabFromEvent(aEvent);
@ -2436,6 +2444,13 @@ TreeStyleTabBrowser.prototype = {
this.getTabFromEvent(aEvent).__treestyletab__preventSelect = true; this.getTabFromEvent(aEvent).__treestyletab__preventSelect = true;
}, },
onMouseUp : function TSTBrowser_onMouseUp(aEvent)
{
var splitter = this.getSplitterFromEvent(aEvent);
if (splitter)
TreeStyleTabService.onTabbarResized(aEvent);
},
onScroll : function TSTBrowser_onScroll(aEvent) onScroll : function TSTBrowser_onScroll(aEvent)
{ {
if (this.lastScrollX < 0 || this.lastScrollY < 0) return; if (this.lastScrollX < 0 || this.lastScrollY < 0) return;

View File

@ -673,6 +673,15 @@ var TreeStyleTabUtils = {
return this.getTabFromChild(aEvent.originalTarget || aEvent.target); return this.getTabFromChild(aEvent.originalTarget || aEvent.target);
}, },
getSplitterFromEvent : function TSTUtils_getSplitterFromEvent(aEvent)
{
return this.evaluateXPath(
'ancestor-or-self::xul:splitter[contains(concat(" ", normalize-space(@class), " "), " '+this.kSPLITTER+' ")]',
aEvent.originalTarget,
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
).singleNodeValue;
},
getTabFromFrame : function TSTUtils_getTabFromFrame(aFrame, aTabBrowser) getTabFromFrame : function TSTUtils_getTabFromFrame(aFrame, aTabBrowser)
{ {
var b = aTabBrowser || this.browser; var b = aTabBrowser || this.browser;