Allow to drop a tab to another more easily

This commit is contained in:
Piro / YUKI Hiroshi 2012-10-13 01:00:57 +09:00
parent cefa9b52fa
commit c66f32e4ab

View File

@ -147,9 +147,10 @@
' $&\n' + ' $&\n' +
'}, this);' '}, this);'
).replace( ).replace(
'let tabWidth = ', /(let tabWidth = [^;]+;)/,
'tabs = tabs.filter(function(tab) { return draggedTabs.indexOf(tab) < 0 });\n' + 'tabs = tabs.filter(function(tab) { return draggedTabs.indexOf(tab) < 0 });\n' +
'$&' '$1\n' +
'let tabCenterOffset = aCanDropOnSelf ? (tabWidth / 2) : 0 ;'
).replace( ).replace(
'let tabCenter = ', 'let tabCenter = ',
'draggedTabs.slice(1).forEach(function(tab) {\n' + 'draggedTabs.slice(1).forEach(function(tab) {\n' +
@ -157,19 +158,19 @@
'}, this);\n' + '}, this);\n' +
'$&' '$&'
).replace( ).replace(
/(let tabCenter = [^;]+)\/ 2;/, /(let tabCenter = )([^;]+)\/ 2;/,
'$1 / units/*2*/;\n' + // support drop on self '$1Math.round($2 / units/*2*/);\n' + // support drop on self
'let tabLeftCenter = tabCenter;\n' + 'let tabLeftCenter = tabCenter;\n' +
'let tabRightCenter = tabScreenX + translateX + tabsWidth - tabWidth / units;' 'let tabRightCenter = Math.round(tabScreenX + translateX + tabsWidth - tabWidth / units);'
).replace( ).replace(
'tabs[mid] == draggedTab', 'tabs[mid] == draggedTab',
'/* $& */ false' '/* $& */ false'
).replace( ).replace(
'(screenX > tabCenter)', '(screenX > tabCenter)',
'/* $& */ (screenX > tabRightCenter)' '/* $& */ (screenX + tabCenterOffset > tabRightCenter)'
).replace( ).replace(
'(screenX + boxObject[size] < tabCenter)', '(screenX + boxObject[size] < tabCenter)',
'/* $& */ (screenX + boxObject[size] < tabLeftCenter)' '/* $& */ (screenX + boxObject[size] - tabCenterOffset < tabLeftCenter)'
).replace( ).replace(
'-tabWidth : tabWidth', '-tabWidth : tabWidth',
'/* $& */ -tabsWidth : tabsWidth' '/* $& */ -tabsWidth : tabsWidth'
@ -178,7 +179,7 @@
'/* $& */ tabsWidth : -tabsWidth' '/* $& */ tabsWidth : -tabsWidth'
).replace( // add a new argument ).replace( // add a new argument
')', ')',
', aAcceptDropOnSelf)' ', aCanDropOnSelf)'
).replace( // insert initialization processes ).replace( // insert initialization processes
'{', '{',
'{\n' + '{\n' +
@ -187,8 +188,8 @@
' var size = isVertical ? "height" : "width" ;\n' + ' var size = isVertical ? "height" : "width" ;\n' +
' var scroll = isVertical ? "scrollY" : "scrollX" ;\n' + ' var scroll = isVertical ? "scrollY" : "scrollX" ;\n' +
' var translator = isVertical ? "translateY" : "translateX" ;\n' + ' var translator = isVertical ? "translateY" : "translateX" ;\n' +
' aAcceptDropOnSelf = aAcceptDropOnSelf || ("TreeStyleTabService" in window);\n' + ' aCanDropOnSelf = aCanDropOnSelf || ("TreeStyleTabService" in window);\n' +
' var units = aAcceptDropOnSelf ? 3 : 2 ;' ' var units = aCanDropOnSelf ? 3 : 2 ;'
) )
); );
@ -199,13 +200,13 @@
* date : 2012-10-09 * date : 2012-10-09
* source : http://mxr.mozilla.org/mozilla-central/source/browser/base/content/tabbrowser.xml * source : http://mxr.mozilla.org/mozilla-central/source/browser/base/content/tabbrowser.xml
*/ */
// function _animateTabMove(event, aAcceptDropOnSelf) { // function _animateTabMove(event, aCanDropOnSelf) {
// var isVertical = window['piro.sakura.ne.jp'].tabsDragUtils.isVertical(this); // var isVertical = window['piro.sakura.ne.jp'].tabsDragUtils.isVertical(this);
// var position = isVertical ? 'screenY' : 'screenX' ; // var position = isVertical ? 'screenY' : 'screenX' ;
// var size = isVertical ? 'height' : 'width' ; // var size = isVertical ? 'height' : 'width' ;
// var translator = isVertical ? "translateY" : "translateX" ; // var translator = isVertical ? "translateY" : "translateX" ;
// aAcceptDropOnSelf = aAcceptDropOnSelf || ("TreeStyleTabService" in window); // aCanDropOnSelf = aCanDropOnSelf || ("TreeStyleTabService" in window);
// var units = aAcceptDropOnSelf ? 3 : 2 ; // var units = aCanDropOnSelf ? 3 : 2 ;
// //
// let draggedTab = event.dataTransfer.mozGetDataAt(TAB_DROP_TYPE, 0); // let draggedTab = event.dataTransfer.mozGetDataAt(TAB_DROP_TYPE, 0);
// var draggedTabs = window['piro.sakura.ne.jp'].tabsDragUtils.getDraggedTabs(event); // var draggedTabs = window['piro.sakura.ne.jp'].tabsDragUtils.getDraggedTabs(event);
@ -243,6 +244,7 @@
// tabs.reverse(); // tabs.reverse();
// tabs = tabs.filter(function(tab) { return draggedTabs.indexOf(tab) < 0 }); // tabs = tabs.filter(function(tab) { return draggedTabs.indexOf(tab) < 0 });
// let tabWidth = draggedTab.getBoundingClientRect()[size]/*.width*/; // let tabWidth = draggedTab.getBoundingClientRect()[size]/*.width*/;
// let tabCenterOffset = aCanDropOnSelf ? (tabWidth / 2) : 0 ;
// //
// // Move the dragged tab based on the mouse position. // // Move the dragged tab based on the mouse position.
// //
@ -270,9 +272,9 @@
// draggedTabs.slice(1).forEach(function(tab) { // draggedTabs.slice(1).forEach(function(tab) {
// tab.style.transform = draggedTab.style.transform; // tab.style.transform = draggedTab.style.transform;
// }, this); // }, this);
// let tabCenter = tabScreenX + translateX + tabWidth / units/*2*/; // let tabCenter = Math.round(tabScreenX + translateX + tabWidth / units/*2*/);
// let tabLeftCenter = tabCenter; // let tabLeftCenter = tabCenter;
// let tabRightCenter = tabScreenX + translateX + tabsWidth - tabWidth / units; // let tabRightCenter = Math.round(tabScreenX + translateX + tabsWidth - tabWidth / units);
// let newIndex = -1; // let newIndex = -1;
// let oldIndex = "animDropIndex" in draggedTab._dragData ? // let oldIndex = "animDropIndex" in draggedTab._dragData ?
// draggedTab._dragData.animDropIndex : draggedTab._tPos; // draggedTab._dragData.animDropIndex : draggedTab._tPos;
@ -287,10 +289,10 @@
// let boxObject = tabs[mid].boxObject; // let boxObject = tabs[mid].boxObject;
// let screenX = boxObject[position]/*.screenX*/ + getTabShift(tabs[mid], oldIndex); // let screenX = boxObject[position]/*.screenX*/ + getTabShift(tabs[mid], oldIndex);
// // if (screenX > tabCenter) { // // if (screenX > tabCenter) {
// if (screenX > tabRightCenter) { // if (screenX + tabCenterOffset > tabRightCenter) {
// high = mid - 1; // high = mid - 1;
// // } else if (screenX + boxObject.width < tabCenter) { // // } else if (screenX + boxObject.width < tabCenter) {
// } else if (screenX + boxObject[size]/*.width*/ < tabLeftCenter) { // } else if (screenX + boxObject[size]/*.width*/ - tabCenterOffset < tabLeftCenter) {
// low = mid + 1; // low = mid + 1;
// } else { // } else {
// newIndex = tabs[mid]._tPos; // newIndex = tabs[mid]._tPos;