From 8d59f831884d9c3eb823bd80c56b783fec15dd63 Mon Sep 17 00:00:00 2001 From: YUKI Hiroshi Date: Tue, 6 Sep 2016 18:10:38 +0900 Subject: [PATCH] Update library --- content/treestyletab/res/tabsDragUtils.js | 79 ++++++++++++++--------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/content/treestyletab/res/tabsDragUtils.js b/content/treestyletab/res/tabsDragUtils.js index 45bcc7df..b785bcda 100644 --- a/content/treestyletab/res/tabsDragUtils.js +++ b/content/treestyletab/res/tabsDragUtils.js @@ -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; }