| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 setCurrentlyDraggingTile(null); | 154 setCurrentlyDraggingTile(null); |
| 155 | 155 |
| 156 // tilePage will be null if we've already been removed. | 156 // tilePage will be null if we've already been removed. |
| 157 if (this.tilePage) | 157 if (this.tilePage) |
| 158 this.tilePage.positionTile_(this.index); | 158 this.tilePage.positionTile_(this.index); |
| 159 | 159 |
| 160 // Take an appropriate action with the drag clone. | 160 // Take an appropriate action with the drag clone. |
| 161 if (this.landedOnTrash) { | 161 if (this.landedOnTrash) { |
| 162 this.dragClone.classList.add('deleting'); | 162 this.dragClone.classList.add('deleting'); |
| 163 } else if (this.tilePage) { | 163 } else if (this.tilePage) { |
| 164 if (this.tilePage.selected) { | 164 if (this.tilePage.selected && e.dataTransfer.dropEffect != 'copy') { |
| 165 // The tile's contents may have moved following the respositioning; | 165 // The tile's contents may have moved following the respositioning; |
| 166 // adjust for that. | 166 // adjust for that. |
| 167 var contentDiffX = this.dragClone.firstChild.offsetLeft - | 167 var contentDiffX = this.dragClone.firstChild.offsetLeft - |
| 168 this.firstChild.offsetLeft; | 168 this.firstChild.offsetLeft; |
| 169 var contentDiffY = this.dragClone.firstChild.offsetTop - | 169 var contentDiffY = this.dragClone.firstChild.offsetTop - |
| 170 this.firstChild.offsetTop; | 170 this.firstChild.offsetTop; |
| 171 this.dragClone.style.left = (this.gridX + this.parentNode.offsetLeft - | 171 this.dragClone.style.left = (this.gridX + this.parentNode.offsetLeft - |
| 172 contentDiffX) + 'px'; | 172 contentDiffX) + 'px'; |
| 173 this.dragClone.style.top = | 173 this.dragClone.style.top = |
| 174 (this.gridY + this.parentNode.getBoundingClientRect().top - | 174 (this.gridY + this.parentNode.getBoundingClientRect().top - |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 }, | 896 }, |
| 897 | 897 |
| 898 /** | 898 /** |
| 899 * Performs all actions necessary when the user moves the cursor during | 899 * Performs all actions necessary when the user moves the cursor during |
| 900 * a drag over the tile page. | 900 * a drag over the tile page. |
| 901 * @param {Event} e A mouseover event for the drag over. | 901 * @param {Event} e A mouseover event for the drag over. |
| 902 */ | 902 */ |
| 903 doDragOver: function(e) { | 903 doDragOver: function(e) { |
| 904 e.preventDefault(); | 904 e.preventDefault(); |
| 905 | 905 |
| 906 if (currentlyDraggingTile) | 906 this.setDropEffect(e.dataTransfer); |
| 907 e.dataTransfer.dropEffect = 'move'; | |
| 908 else | |
| 909 e.dataTransfer.dropEffect = 'copy'; | |
| 910 | |
| 911 var newDragIndex = this.getWouldBeIndexForPoint_(e.pageX, e.pageY); | 907 var newDragIndex = this.getWouldBeIndexForPoint_(e.pageX, e.pageY); |
| 912 if (newDragIndex < 0 || newDragIndex >= this.tileElements_.length) | 908 if (newDragIndex < 0 || newDragIndex >= this.tileElements_.length) |
| 913 newDragIndex = this.dragItemIndex_; | 909 newDragIndex = this.dragItemIndex_; |
| 914 this.updateDropIndicator_(newDragIndex); | 910 this.updateDropIndicator_(newDragIndex); |
| 915 }, | 911 }, |
| 916 | 912 |
| 917 /** | 913 /** |
| 918 * Performs all actions necessary when the user completes a drop. | 914 * Performs all actions necessary when the user completes a drop. |
| 919 * @param {Event} e A mouseover event for the drag drop. | 915 * @param {Event} e A mouseover event for the drag drop. |
| 920 */ | 916 */ |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 assert(false); | 1019 assert(false); |
| 1024 }, | 1020 }, |
| 1025 | 1021 |
| 1026 /** | 1022 /** |
| 1027 * Called when a tile has been moved (via dragging). Override this to make | 1023 * Called when a tile has been moved (via dragging). Override this to make |
| 1028 * backend updates. | 1024 * backend updates. |
| 1029 * @param {Node} draggedTile The tile that was dropped. | 1025 * @param {Node} draggedTile The tile that was dropped. |
| 1030 */ | 1026 */ |
| 1031 tileMoved: function(draggedTile) { | 1027 tileMoved: function(draggedTile) { |
| 1032 }, | 1028 }, |
| 1029 |
| 1030 /** |
| 1031 * Sets the drop effect on |dataTransfer| to the desired value (e.g. |
| 1032 * 'copy'). |
| 1033 * @param {Object} dataTransfer The drag event dataTransfer object. |
| 1034 */ |
| 1035 setDropEffect: function(dataTransfer) { |
| 1036 assert(false); |
| 1037 }, |
| 1033 }; | 1038 }; |
| 1034 | 1039 |
| 1035 return { | 1040 return { |
| 1036 getCurrentlyDraggingTile: getCurrentlyDraggingTile, | 1041 getCurrentlyDraggingTile: getCurrentlyDraggingTile, |
| 1037 TilePage: TilePage, | 1042 TilePage: TilePage, |
| 1038 }; | 1043 }; |
| 1039 }); | 1044 }); |
| OLD | NEW |