| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('ntp4', function() { | 5 cr.define('ntp4', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 // We can't pass the currently dragging tile via dataTransfer because of | 8 // We can't pass the currently dragging tile via dataTransfer because of |
| 9 // http://crbug.com/31037 | 9 // http://crbug.com/31037 |
| 10 var currentlyDraggingTile = null; | 10 var currentlyDraggingTile = null; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 setCurrentlyDraggingTile(null); | 152 setCurrentlyDraggingTile(null); |
| 153 | 153 |
| 154 // tilePage will be null if we've already been removed. | 154 // tilePage will be null if we've already been removed. |
| 155 if (this.tilePage) | 155 if (this.tilePage) |
| 156 this.tilePage.positionTile_(this.index); | 156 this.tilePage.positionTile_(this.index); |
| 157 | 157 |
| 158 // Take an appropriate action with the drag clone. | 158 // Take an appropriate action with the drag clone. |
| 159 if (this.landedOnTrash) { | 159 if (this.landedOnTrash) { |
| 160 this.dragClone.classList.add('deleting'); | 160 this.dragClone.classList.add('deleting'); |
| 161 } else if (this.tilePage) { | 161 } else if (this.tilePage) { |
| 162 if (this.tilePage.selected) { | 162 if (this.tilePage.selected && e.dataTransfer.dropEffect != 'copy') { |
| 163 // The tile's contents may have moved following the respositioning; | 163 // The tile's contents may have moved following the respositioning; |
| 164 // adjust for that. | 164 // adjust for that. |
| 165 var contentDiffX = this.dragClone.firstChild.offsetLeft - | 165 var contentDiffX = this.dragClone.firstChild.offsetLeft - |
| 166 this.firstChild.offsetLeft; | 166 this.firstChild.offsetLeft; |
| 167 var contentDiffY = this.dragClone.firstChild.offsetTop - | 167 var contentDiffY = this.dragClone.firstChild.offsetTop - |
| 168 this.firstChild.offsetTop; | 168 this.firstChild.offsetTop; |
| 169 this.dragClone.style.left = (this.gridX + this.parentNode.offsetLeft - | 169 this.dragClone.style.left = (this.gridX + this.parentNode.offsetLeft - |
| 170 contentDiffX) + 'px'; | 170 contentDiffX) + 'px'; |
| 171 this.dragClone.style.top = | 171 this.dragClone.style.top = |
| 172 (this.gridY + this.parentNode.getBoundingClientRect().top - | 172 (this.gridY + this.parentNode.getBoundingClientRect().top - |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 | 872 |
| 873 /** | 873 /** |
| 874 * Performs all actions necessary when the user moves the cursor during | 874 * Performs all actions necessary when the user moves the cursor during |
| 875 * a drag over the tile page. | 875 * a drag over the tile page. |
| 876 * @param {Event} e A mouseover event for the drag over. | 876 * @param {Event} e A mouseover event for the drag over. |
| 877 * @private | 877 * @private |
| 878 */ | 878 */ |
| 879 doDragOver: function(e) { | 879 doDragOver: function(e) { |
| 880 e.preventDefault(); | 880 e.preventDefault(); |
| 881 | 881 |
| 882 if (currentlyDraggingTile) | 882 this.setDropEffect(e.dataTransfer); |
| 883 e.dataTransfer.dropEffect = 'move'; | |
| 884 else | |
| 885 e.dataTransfer.dropEffect = 'copy'; | |
| 886 | |
| 887 var newDragIndex = this.getWouldBeIndexForPoint_(e.pageX, e.pageY); | 883 var newDragIndex = this.getWouldBeIndexForPoint_(e.pageX, e.pageY); |
| 888 if (newDragIndex < 0 || newDragIndex >= this.tileElements_.length) | 884 if (newDragIndex < 0 || newDragIndex >= this.tileElements_.length) |
| 889 newDragIndex = this.dragItemIndex_; | 885 newDragIndex = this.dragItemIndex_; |
| 890 this.updateDropIndicator_(newDragIndex); | 886 this.updateDropIndicator_(newDragIndex); |
| 891 }, | 887 }, |
| 892 | 888 |
| 893 /** | 889 /** |
| 894 * Performs all actions necessary when the user completes a drop. | 890 * Performs all actions necessary when the user completes a drop. |
| 895 * @param {Event} e A mouseover event for the drag drop. | 891 * @param {Event} e A mouseover event for the drag drop. |
| 896 * @private | 892 * @private |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 assert(false); | 995 assert(false); |
| 1000 }, | 996 }, |
| 1001 | 997 |
| 1002 /** | 998 /** |
| 1003 * Called when a tile has been moved (via dragging). Override this to make | 999 * Called when a tile has been moved (via dragging). Override this to make |
| 1004 * backend updates. | 1000 * backend updates. |
| 1005 * @param {Node} draggedTile The tile that was dropped. | 1001 * @param {Node} draggedTile The tile that was dropped. |
| 1006 */ | 1002 */ |
| 1007 tileMoved: function(draggedTile) { | 1003 tileMoved: function(draggedTile) { |
| 1008 }, | 1004 }, |
| 1005 |
| 1006 /** |
| 1007 * Sets the drop effect on |dataTransfer| to the desired value (e.g. |
| 1008 * 'copy'). |
| 1009 * @param {Object} dataTransfer The drag event dataTransfer object. |
| 1010 */ |
| 1011 setDropEffect: function(dataTransfer) { |
| 1012 assert(false); |
| 1013 }, |
| 1009 }; | 1014 }; |
| 1010 | 1015 |
| 1011 return { | 1016 return { |
| 1012 getCurrentlyDraggingTile: getCurrentlyDraggingTile, | 1017 getCurrentlyDraggingTile: getCurrentlyDraggingTile, |
| 1013 TilePage: TilePage, | 1018 TilePage: TilePage, |
| 1014 }; | 1019 }; |
| 1015 }); | 1020 }); |
| OLD | NEW |