From b2a90224d625d39f58ef0e68a130264bbd7de505 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sat, 13 Oct 2012 02:09:34 +0900 Subject: [PATCH] Calculate drop position based on visual positions of tabs --- modules/tabbarDNDObserver.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/modules/tabbarDNDObserver.js b/modules/tabbarDNDObserver.js index d45bd560..47f22972 100644 --- a/modules/tabbarDNDObserver.js +++ b/modules/tabbarDNDObserver.js @@ -263,6 +263,31 @@ catch(e) { event : aEvent }; + /** + * Even if a dragover tab is moved by CSS "transform", + * the event is fired based on its original position. + * Following tabs can be transformed, and we'll see far + * tab (visually it is far but logically it is below the + * pointer!) as the drop target. + * "animDropIndex" is calculated based on their visual + * positions, and we can use it to calculate the drop target + * which is visually below the pointer. + */ + let draggedTab = aEvent.dataTransfer && aEvent.dataTransfer.mozGetDataAt(TAB_DROP_TYPE, 0); + if (draggedTab && draggedTab._dragData && 'animDropIndex' in draggedTab._dragData) { + let newIndex = draggedTab._dragData.animDropIndex; + /** + * Preceding tabs won't be transformed. We have to + * handle only following tabs. + */ + if (newIndex > draggedTab._tPos) { + newIndex--; + let tabs = sv.getAllTabs(b); + if (newIndex < tabs.length) + tab = tabs[newIndex]; + } + } + var isTabMoveFromOtherWindow = aSourceTab && aSourceTab.ownerDocument != d; var isNewTabAction = !aSourceTab || aSourceTab.ownerDocument != d; @@ -839,7 +864,8 @@ try{ sv.autoScroll.processAutoScroll(aEvent); - var dragOverTab = sv.getTabFromEvent(aEvent) || sv.getTabFromTabbarEvent(aEvent) || aEvent.target; + let draggedTab = aEvent.dataTransfer && aEvent.dataTransfer.mozGetDataAt(TAB_DROP_TYPE, 0); + let dragOverTab = sv.getTabFromEvent(aEvent) || sv.getTabFromTabbarEvent(aEvent) || aEvent.target; b.ownerDocument.defaultView['piro.sakura.ne.jp'].tabsDragUtils .processTabsDragging(aEvent, !dragOverTab || !dragOverTab.pinned); @@ -897,7 +923,6 @@ try{ let dropPosition = info.position == sv.kDROP_BEFORE ? 'before' : info.position == sv.kDROP_AFTER ? 'after' : 'self'; - let draggedTab = aEvent.dataTransfer && aEvent.dataTransfer.mozGetDataAt(TAB_DROP_TYPE, 0); if (indicatorTab != draggedTab && indicatorTab.getAttribute(sv.kDROP_POSITION) != dropPosition) { this.clearDropPosition();