ドラッグ&ドロップの処理を別ファイルに分離
git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5054 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
parent
74d88e1acc
commit
f573c43345
@ -14,12 +14,19 @@
|
||||
<script src="res/autoScroll.js" type="application/x-javascript; version=1.7"/>
|
||||
<script src="res/animationManager.js" type="application/x-javascript; version=1.7"/>
|
||||
<script src="res/extensions.js" type="application/x-javascript; version=1.7"/>
|
||||
|
||||
<script src="treestyletab.js" type="application/x-javascript; version=1.7"/>
|
||||
<script src="treestyletabbrowser.js" type="application/x-javascript; version=1.7"/>
|
||||
<script src="treestyletabbrowser_tabbarDNDObserver.js" type="application/x-javascript; version=1.7"/>
|
||||
<script src="treestyletabbrowser_tabpanelDNDObserver.js" type="application/x-javascript; version=1.7"/>
|
||||
|
||||
<script src="preloadImages.js" type="application/x-javascript; version=1.7"/>
|
||||
|
||||
<script src="bookmarksOverlay.js" type="application/x-javascript; version=1.7"/>
|
||||
<script src="bookmarksOverlayEditable.js" type="application/x-javascript; version=1.7"/>
|
||||
|
||||
<script src="hacks.js" type="application/x-javascript; version=1.7"/>
|
||||
|
||||
<script type="application/x-javascript; version=1.7"><![CDATA[
|
||||
// preload images
|
||||
TreeStyleTabService.observe(
|
||||
|
@ -2347,242 +2347,19 @@ TreeStyleTabBrowser.prototype = {
|
||||
},
|
||||
|
||||
/* drag and drop */
|
||||
autoExpandTimer : null,
|
||||
autoExpandTarget : null,
|
||||
autoExpandedTabs : [],
|
||||
|
||||
// tabbar
|
||||
get tabbarDNDObserver()
|
||||
get tabbarDNDObserver()
|
||||
{
|
||||
if (!this._tabbarDNDObserver)
|
||||
this._tabbarDNDObserver = {
|
||||
mOwner : this,
|
||||
|
||||
onDragStart : function(aEvent, aTransferData, aDragAction)
|
||||
{
|
||||
if (!this.canDragTabbar(aEvent))
|
||||
return false;
|
||||
|
||||
var sv = this.mOwner;
|
||||
aTransferData.data = new TransferData();
|
||||
aTransferData.data.addDataForFlavour(
|
||||
sv.kDRAG_TYPE_TABBAR,
|
||||
aEvent.shiftKey ?
|
||||
sv.kTABBAR_MOVE_FORCE :
|
||||
sv.kTABBAR_MOVE_NORMAL
|
||||
);
|
||||
sv.mTabBrowser.setAttribute(sv.kDROP_POSITION, sv.kDROP_POSITION_UNKNOWN);
|
||||
|
||||
aEvent.stopPropagation();
|
||||
return true;
|
||||
delete this.tabbarDNDObserver;
|
||||
return (this.tabbarDNDObserver = new TreeStyleTabBrowserTabbarDNDObserver(this));
|
||||
},
|
||||
|
||||
canDragTabbar : function(aEvent)
|
||||
get panelDNDObserver()
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
var tab = sv.getTabFromEvent(aEvent);
|
||||
var tabbar = sv.getTabbarFromEvent(aEvent);
|
||||
return (
|
||||
(tab ? aEvent.shiftKey : tabbar ) &&
|
||||
(
|
||||
aEvent.shiftKey ||
|
||||
sv.mTabBrowser.getAttribute(sv.kFIXED) != 'true'
|
||||
)
|
||||
);
|
||||
delete this.panelDNDObserver;
|
||||
return (this.panelDNDObserver = new TreeStyleTabBrowserTabpanelDNDObserver(this));
|
||||
},
|
||||
|
||||
onDragEnter : function(aEvent, aDragSession)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
var tab = aEvent.target;
|
||||
if (tab.localName != 'tab' ||
|
||||
!sv.getTreePref('autoExpand.enabled'))
|
||||
return;
|
||||
|
||||
var now = (new Date()).getTime();
|
||||
|
||||
window.clearTimeout(sv.autoExpandTimer);
|
||||
if (aEvent.target == aDragSession.sourceNode) return;
|
||||
sv.autoExpandTimer = window.setTimeout(
|
||||
function(aTarget) {
|
||||
let tab = sv.getTabById(aTarget);
|
||||
if (tab &&
|
||||
tab.getAttribute(sv.kSUBTREE_COLLAPSED) == 'true' &&
|
||||
tab.getAttribute(sv.kDROP_POSITION) == 'self') {
|
||||
if (sv.getTreePref('autoExpand.intelligently')) {
|
||||
sv.collapseExpandTreesIntelligentlyFor(tab);
|
||||
}
|
||||
else {
|
||||
sv.autoExpandedTabs.push(aTarget);
|
||||
sv.collapseExpandSubtree(tab, false);
|
||||
}
|
||||
}
|
||||
},
|
||||
sv.getTreePref('autoExpand.delay'),
|
||||
tab.getAttribute(sv.kID)
|
||||
);
|
||||
|
||||
tab = null;
|
||||
now = null;
|
||||
},
|
||||
|
||||
onDragExit : function(aEvent, aDragSession)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
var now = (new Date()).getTime();
|
||||
|
||||
window.clearTimeout(sv.autoExpandTimer);
|
||||
sv.autoExpandTimer = null;
|
||||
},
|
||||
|
||||
onDragEnd : function(aEvent)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
window.setTimeout(function() {
|
||||
sv.mTabBrowser.removeAttribute(sv.kDROP_POSITION);
|
||||
}, 10);
|
||||
aEvent.stopPropagation();
|
||||
},
|
||||
|
||||
onDragOver : function(aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
},
|
||||
|
||||
onDrop : function(aEvent, aXferData, aDragSession)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
if (!sv.autoExpandedTabs.length) return;
|
||||
if (sv.getTreePref('autoExpand.collapseFinally')) {
|
||||
sv.autoExpandedTabs.forEach(function(aTarget) {
|
||||
this.collapseExpandSubtree(this.getTabById(aTarget), true, true);
|
||||
}, sv);
|
||||
}
|
||||
sv.autoExpandedTabs = [];
|
||||
},
|
||||
|
||||
canDrop : function(aEvent, aDragSession)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
var tooltip = sv.mTabBrowser.mStrip.firstChild;
|
||||
if (tooltip &&
|
||||
tooltip.localName == 'tooltip' &&
|
||||
tooltip.popupBoxObject.popupState != 'closed')
|
||||
tooltip.hidePopup();
|
||||
|
||||
var dropAction = sv.getDropAction(aEvent, aDragSession);
|
||||
if ('dataTransfer' in aEvent) {
|
||||
var dt = aEvent.dataTransfer;
|
||||
if (dropAction.action & this.kACTION_NEWTAB) {
|
||||
dt.effectAllowed = dt.dropEffect = (
|
||||
!dropAction.source ? 'link' :
|
||||
sv.isAccelKeyPressed(aEvent) ? 'copy' :
|
||||
'move'
|
||||
);
|
||||
}
|
||||
}
|
||||
return dropAction.canDrop;
|
||||
},
|
||||
|
||||
getSupportedFlavours : function()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour('application/x-moz-tabbrowser-tab');
|
||||
flavourSet.appendFlavour('text/x-moz-url');
|
||||
flavourSet.appendFlavour('text/unicode');
|
||||
flavourSet.appendFlavour('text/plain');
|
||||
flavourSet.appendFlavour('application/x-moz-file', 'nsIFile');
|
||||
return flavourSet;
|
||||
}
|
||||
|
||||
};
|
||||
return this._tabbarDNDObserver;
|
||||
},
|
||||
|
||||
// content area
|
||||
get panelDNDObserver()
|
||||
{
|
||||
if (!this._panelDNDObserver)
|
||||
this._panelDNDObserver = {
|
||||
mOwner : this,
|
||||
|
||||
onDragExit : function(aEvent, aDragSession)
|
||||
{
|
||||
if (!this.canDrop(aEvent, aDragSession)) return;
|
||||
var sv = this.mOwner;
|
||||
sv.mTabBrowser.setAttribute(sv.kDROP_POSITION, sv.kDROP_POSITION_UNKNOWN);
|
||||
},
|
||||
|
||||
onDragOver : function(aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
if (!this.canDrop(aEvent, aDragSession)) return;
|
||||
var sv = this.mOwner;
|
||||
var position = this.getDropPosition(aEvent);
|
||||
if (position != 'center' &&
|
||||
position != sv.mTabBrowser.getAttribute(sv.kTABBAR_POSITION))
|
||||
sv.mTabBrowser.setAttribute(sv.kDROP_POSITION, position);
|
||||
},
|
||||
|
||||
onDrop : function(aEvent, aXferData, aDragSession)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
var position = this.getDropPosition(aEvent);
|
||||
if (position != 'center' &&
|
||||
position != sv.mTabBrowser.getAttribute(sv.kTABBAR_POSITION)) {
|
||||
if (sv.getTreePref('tabbar.fixed.autoCancelOnDrop') &&
|
||||
aXferData.data != sv.kTABBAR_MOVE_FORCE) {
|
||||
let orient = (position == 'left' || position == 'right') ? 'vertical' : 'horizontal' ;
|
||||
sv.setTreePref('tabbar.fixed.'+orient, false);
|
||||
}
|
||||
sv.changeTabbarPosition(position);
|
||||
}
|
||||
|
||||
aEvent.stopPropagation();
|
||||
},
|
||||
|
||||
getDropPosition : function(aEvent)
|
||||
{
|
||||
var box = this.mOwner.mTabBrowser.boxObject;
|
||||
var W = box.width;
|
||||
var H = box.height;
|
||||
var X = box.screenX;
|
||||
var Y = box.screenY;
|
||||
var x = aEvent.screenX - X;
|
||||
var y = aEvent.screenY - Y;
|
||||
|
||||
if (x > (W * 0.33) &&
|
||||
x < (W * 0.66) &&
|
||||
y > (H * 0.33) &&
|
||||
y < (H * 0.66))
|
||||
return 'center';
|
||||
|
||||
var isTL = x <= W - (y * W / H);
|
||||
var isBL = x <= y * W / H;
|
||||
return (isTL && isBL) ? 'left' :
|
||||
(isTL && !isBL) ? 'top' :
|
||||
(!isTL && isBL) ? 'bottom' :
|
||||
'right' ;
|
||||
},
|
||||
|
||||
canDrop : function(aEvent, aDragSession)
|
||||
{
|
||||
return (
|
||||
aDragSession &&
|
||||
aDragSession.isDataFlavorSupported(this.mOwner.kDRAG_TYPE_TABBAR) &&
|
||||
aDragSession.sourceNode
|
||||
) ? true : false ;
|
||||
},
|
||||
|
||||
getSupportedFlavours : function()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour(this.mOwner.kDRAG_TYPE_TABBAR);
|
||||
return flavourSet;
|
||||
}
|
||||
|
||||
};
|
||||
return this._panelDNDObserver;
|
||||
},
|
||||
|
||||
getCurrentDragSession : function()
|
||||
{
|
||||
return Components
|
||||
|
147
content/treestyletab/treestyletabbrowser_tabbarDNDObserver.js
Normal file
147
content/treestyletab/treestyletabbrowser_tabbarDNDObserver.js
Normal file
@ -0,0 +1,147 @@
|
||||
function TreeStyleTabBrowserTabbarDNDObserver(aOwner)
|
||||
{
|
||||
this.mOwner = aOwner;
|
||||
this.mAutoExpandTimer = null;
|
||||
this.mAutoExpandedTabs = [],
|
||||
}
|
||||
|
||||
TreeStyleTabBrowserTabbarDNDObserver.prototype = {
|
||||
|
||||
onDragStart : function(aEvent, aTransferData, aDragAction)
|
||||
{
|
||||
if (!this.canDragTabbar(aEvent))
|
||||
return false;
|
||||
|
||||
var sv = this.mOwner;
|
||||
aTransferData.data = new TransferData();
|
||||
aTransferData.data.addDataForFlavour(
|
||||
sv.kDRAG_TYPE_TABBAR,
|
||||
aEvent.shiftKey ?
|
||||
sv.kTABBAR_MOVE_FORCE :
|
||||
sv.kTABBAR_MOVE_NORMAL
|
||||
);
|
||||
sv.mTabBrowser.setAttribute(sv.kDROP_POSITION, sv.kDROP_POSITION_UNKNOWN);
|
||||
|
||||
aEvent.stopPropagation();
|
||||
return true;
|
||||
},
|
||||
|
||||
canDragTabbar : function(aEvent)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
var tab = sv.getTabFromEvent(aEvent);
|
||||
var tabbar = sv.getTabbarFromEvent(aEvent);
|
||||
return (
|
||||
(tab ? aEvent.shiftKey : tabbar ) &&
|
||||
(
|
||||
aEvent.shiftKey ||
|
||||
sv.mTabBrowser.getAttribute(sv.kFIXED) != 'true'
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
onDragEnter : function(aEvent, aDragSession)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
var tab = aEvent.target;
|
||||
if (tab.localName != 'tab' ||
|
||||
!sv.getTreePref('autoExpand.enabled'))
|
||||
return;
|
||||
|
||||
var now = (new Date()).getTime();
|
||||
|
||||
window.clearTimeout(this.mAutoExpandTimer);
|
||||
if (aEvent.target == aDragSession.sourceNode) return;
|
||||
this.mAutoExpandTimer = window.setTimeout(
|
||||
function(aTarget) {
|
||||
let tab = sv.getTabById(aTarget);
|
||||
if (tab &&
|
||||
tab.getAttribute(sv.kSUBTREE_COLLAPSED) == 'true' &&
|
||||
tab.getAttribute(sv.kDROP_POSITION) == 'self') {
|
||||
if (sv.getTreePref('autoExpand.intelligently')) {
|
||||
sv.collapseExpandTreesIntelligentlyFor(tab);
|
||||
}
|
||||
else {
|
||||
this.mAutoExpandedTabs.push(aTarget);
|
||||
sv.collapseExpandSubtree(tab, false);
|
||||
}
|
||||
}
|
||||
},
|
||||
sv.getTreePref('autoExpand.delay'),
|
||||
tab.getAttribute(sv.kID)
|
||||
);
|
||||
|
||||
tab = null;
|
||||
now = null;
|
||||
},
|
||||
|
||||
onDragExit : function(aEvent, aDragSession)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
var now = (new Date()).getTime();
|
||||
|
||||
window.clearTimeout(this.mAutoExpandTimer);
|
||||
this.mAutoExpandTimer = null;
|
||||
},
|
||||
|
||||
onDragEnd : function(aEvent)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
window.setTimeout(function() {
|
||||
sv.mTabBrowser.removeAttribute(sv.kDROP_POSITION);
|
||||
}, 10);
|
||||
aEvent.stopPropagation();
|
||||
},
|
||||
|
||||
onDragOver : function(aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
},
|
||||
|
||||
onDrop : function(aEvent, aXferData, aDragSession)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
if (!this.mAutoExpandedTabs.length) return;
|
||||
if (sv.getTreePref('autoExpand.collapseFinally')) {
|
||||
this.mAutoExpandedTabs.forEach(function(aTarget) {
|
||||
this.collapseExpandSubtree(this.getTabById(aTarget), true, true);
|
||||
}, sv);
|
||||
}
|
||||
this.mAutoExpandedTabs = [];
|
||||
},
|
||||
|
||||
canDrop : function(aEvent, aDragSession)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
var tooltip = sv.mTabBrowser.mStrip.firstChild;
|
||||
if (tooltip &&
|
||||
tooltip.localName == 'tooltip' &&
|
||||
tooltip.popupBoxObject.popupState != 'closed')
|
||||
tooltip.hidePopup();
|
||||
|
||||
var dropAction = sv.getDropAction(aEvent, aDragSession);
|
||||
if ('dataTransfer' in aEvent) {
|
||||
var dt = aEvent.dataTransfer;
|
||||
if (dropAction.action & this.kACTION_NEWTAB) {
|
||||
dt.effectAllowed = dt.dropEffect = (
|
||||
!dropAction.source ? 'link' :
|
||||
sv.isAccelKeyPressed(aEvent) ? 'copy' :
|
||||
'move'
|
||||
);
|
||||
}
|
||||
}
|
||||
return dropAction.canDrop;
|
||||
},
|
||||
|
||||
getSupportedFlavours : function()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour('application/x-moz-tabbrowser-tab');
|
||||
flavourSet.appendFlavour('text/x-moz-url');
|
||||
flavourSet.appendFlavour('text/unicode');
|
||||
flavourSet.appendFlavour('text/plain');
|
||||
flavourSet.appendFlavour('application/x-moz-file', 'nsIFile');
|
||||
return flavourSet;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -0,0 +1,83 @@
|
||||
function TreeStyleTabBrowserTabpanelDNDObserver(aOwner)
|
||||
{
|
||||
this.mOwner = aOwner;
|
||||
}
|
||||
|
||||
TreeStyleTabBrowserTabpanelDNDObserver.prototype = {
|
||||
|
||||
onDragExit : function(aEvent, aDragSession)
|
||||
{
|
||||
if (!this.canDrop(aEvent, aDragSession)) return;
|
||||
var sv = this.mOwner;
|
||||
sv.mTabBrowser.setAttribute(sv.kDROP_POSITION, sv.kDROP_POSITION_UNKNOWN);
|
||||
},
|
||||
|
||||
onDragOver : function(aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
if (!this.canDrop(aEvent, aDragSession)) return;
|
||||
var sv = this.mOwner;
|
||||
var position = this.getDropPosition(aEvent);
|
||||
if (position != 'center' &&
|
||||
position != sv.mTabBrowser.getAttribute(sv.kTABBAR_POSITION))
|
||||
sv.mTabBrowser.setAttribute(sv.kDROP_POSITION, position);
|
||||
},
|
||||
|
||||
onDrop : function(aEvent, aXferData, aDragSession)
|
||||
{
|
||||
var sv = this.mOwner;
|
||||
var position = this.getDropPosition(aEvent);
|
||||
if (position != 'center' &&
|
||||
position != sv.mTabBrowser.getAttribute(sv.kTABBAR_POSITION)) {
|
||||
if (sv.getTreePref('tabbar.fixed.autoCancelOnDrop') &&
|
||||
aXferData.data != sv.kTABBAR_MOVE_FORCE) {
|
||||
let orient = (position == 'left' || position == 'right') ? 'vertical' : 'horizontal' ;
|
||||
sv.setTreePref('tabbar.fixed.'+orient, false);
|
||||
}
|
||||
sv.changeTabbarPosition(position);
|
||||
}
|
||||
|
||||
aEvent.stopPropagation();
|
||||
},
|
||||
|
||||
getDropPosition : function(aEvent)
|
||||
{
|
||||
var box = this.mOwner.mTabBrowser.boxObject;
|
||||
var W = box.width;
|
||||
var H = box.height;
|
||||
var X = box.screenX;
|
||||
var Y = box.screenY;
|
||||
var x = aEvent.screenX - X;
|
||||
var y = aEvent.screenY - Y;
|
||||
|
||||
if (x > (W * 0.33) &&
|
||||
x < (W * 0.66) &&
|
||||
y > (H * 0.33) &&
|
||||
y < (H * 0.66))
|
||||
return 'center';
|
||||
|
||||
var isTL = x <= W - (y * W / H);
|
||||
var isBL = x <= y * W / H;
|
||||
return (isTL && isBL) ? 'left' :
|
||||
(isTL && !isBL) ? 'top' :
|
||||
(!isTL && isBL) ? 'bottom' :
|
||||
'right' ;
|
||||
},
|
||||
|
||||
canDrop : function(aEvent, aDragSession)
|
||||
{
|
||||
return (
|
||||
aDragSession &&
|
||||
aDragSession.isDataFlavorSupported(this.mOwner.kDRAG_TYPE_TABBAR) &&
|
||||
aDragSession.sourceNode
|
||||
) ? true : false ;
|
||||
},
|
||||
|
||||
getSupportedFlavours : function()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour(this.mOwner.kDRAG_TYPE_TABBAR);
|
||||
return flavourSet;
|
||||
}
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user