Update library

This commit is contained in:
YUKI Hiroshi 2016-09-06 18:10:38 +09:00
parent d57cbdad49
commit 8d59f83188

View File

@ -13,12 +13,9 @@
original:
http://github.com/piroor/fxaddonlib-tabs-drag-utils
depends on:
https://github.com/clear-code/js-extended-immutable
*/
(function() {
const currentRevision = 40;
const currentRevision = 41;
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
@ -37,9 +34,6 @@
const Ci = Components.interfaces;
const TAB_DROP_TYPE = 'application/x-moz-tabbrowser-tab';
// fix path to extended-immutable.js
var { ExtendedImmutable } = Components.utils.import('resource://treestyletab-modules/lib/extended-immutable.js', {});
var tabsDragUtils = {
revision : currentRevision,
@ -149,28 +143,51 @@
if (typeof aObserver._getDropEffectForTabDrag === 'function' &&
!aObserver.__tabsDragUtils__getDropEffectForTabDrag) {
aObserver.__tabsDragUtils__getDropEffectForTabDrag = aObserver._getDropEffectForTabDrag;
aObserver._getDropEffectForTabDrag = function(aEvent, ...aArgs) {
if (!window["piro.sakura.ne.jp"].tabsDragUtils.isTabsDragging(aEvent))
return aEvent;
aObserver.__tabsDragUtils_original__getDropEffectForTabDrag = aObserver._getDropEffectForTabDrag;
aObserver._getDropEffectForTabDrag = function(event) {
/**
* Original:
* base version: Nightly 51.0a1
* date : 2016-09-04
* source : https://dxr.mozilla.org/mozilla-central/rev/1789229965bfc5e7b08dfcf1c054c366abe1267a/browser/base/content/tabbrowser.xml#5545
*/
//=====================================================================
var dt = event.dataTransfer;
// Disallow dropping multiple items
// if (dt.mozItemCount > 1)
if (dt.mozItemCount > 1 && !window['piro.sakura.ne.jp'].tabsDragUtils.isTabsDragging(event))
return "none";
var fakeItemCount = 1;
var fakeDataTransfer = new ExtendedImmutable(aEvent.dataTransfer, {
get mozItemCount() {
if (fakeItemCount) {
fakeItemCount = null;
return fakeItemCount;
}
return aEvent.dataTransfer.mozItemCount;
}
});
var fakeEvent = new ExtendedImmutable(aEvent, {
get dataTransfer() {
return fakeDataTransfer;
}
});
return aObserver.__tabsDragUtils__getDropEffectForTabDrag(fakeEvent, ...aArgs);
var types = dt.mozTypesAt(0);
// tabs are always added as the first type
if (types[0] == TAB_DROP_TYPE) {
let sourceNode = dt.mozGetDataAt(TAB_DROP_TYPE, 0);
if (sourceNode instanceof XULElement &&
sourceNode.localName == "tab" &&
sourceNode.ownerDocument.defaultView instanceof ChromeWindow &&
sourceNode.ownerDocument.documentElement.getAttribute("windowtype") == "navigator:browser" &&
sourceNode.ownerDocument.defaultView.gBrowser.tabContainer == sourceNode.parentNode) {
// Do not allow transfering a private tab to a non-private window
// and vice versa.
if (PrivateBrowsingUtils.isWindowPrivate(window) !=
PrivateBrowsingUtils.isWindowPrivate(sourceNode.ownerDocument.defaultView))
return "none";
if (window.gMultiProcessBrowser !=
sourceNode.ownerDocument.defaultView.gMultiProcessBrowser)
return "none";
return dt.dropEffect == "copy" ? "copy" : "move";
}
}
if (browserDragAndDrop.canDropLink(event)) {
return "link";
}
return "none";
//=====================================================================
};
aObserver.__TabsDragUtils_updated__getDropEffectForTabDrag = aObserver._getDropEffectForTabDrag;
}
if ('_animateTabMove' in aObserver &&
@ -308,8 +325,6 @@ TDUContext.utils.updateDropIndex(newIndex, TDUContext);
// Shift background tabs to leave a gap where the dragged tab
// would currently be dropped.
tabWidth = TDUContext.tabsSize;
for (let tab of tabs) {
if (tab != draggedTab) {
let shift = getTabShift(tab, newIndex);
@ -320,9 +335,11 @@ tabWidth = TDUContext.tabsSize;
function getTabShift(tab, dropIndex) {
if (tab._tPos < draggedTab._tPos && tab._tPos >= dropIndex)
return rtl ? -tabWidth : tabWidth;
return rtl ? -TDUContext.tabsSize : TDUContext.tabsSize;
// return rtl ? -tabWidth : tabWidth;
if (tab._tPos > draggedTab._tPos && tab._tPos < dropIndex)
return rtl ? tabWidth : -tabWidth;
return rtl ? TDUContext.tabsSize : -TDUContext.tabsSize;
// return rtl ? tabWidth : -tabWidth;
return 0;
}