OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * Global (placed in the window object) variable name to hold internal | 8 * Global (placed in the window object) variable name to hold internal |
9 * file dragging information. Needed to show visual feedback while dragging | 9 * file dragging information. Needed to show visual feedback while dragging |
10 * since DataTransfer object is in protected state. Reachable from other | 10 * since DataTransfer object is in protected state. Reachable from other |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 * @param {DirectoryTree} tree Its sub items will could be drop target. | 127 * @param {DirectoryTree} tree Its sub items will could be drop target. |
128 */ | 128 */ |
129 attachTreeDropTarget: function(tree) { | 129 attachTreeDropTarget: function(tree) { |
130 tree.addEventListener('dragover', this.onDragOver_.bind(this, true, tree)); | 130 tree.addEventListener('dragover', this.onDragOver_.bind(this, true, tree)); |
131 tree.addEventListener('dragenter', this.onDragEnterTree_.bind(this, tree)); | 131 tree.addEventListener('dragenter', this.onDragEnterTree_.bind(this, tree)); |
132 tree.addEventListener('dragleave', this.onDragLeave_.bind(this, tree)); | 132 tree.addEventListener('dragleave', this.onDragLeave_.bind(this, tree)); |
133 tree.addEventListener('drop', this.onDrop_.bind(this, true)); | 133 tree.addEventListener('drop', this.onDrop_.bind(this, true)); |
134 }, | 134 }, |
135 | 135 |
136 /** | 136 /** |
137 * @this {FileTransferController} | |
138 * @param {NavigationList} tree Its sub items will could be drop target. | |
139 */ | |
140 attachNavigationListDropTarget: function(list) { | |
141 list.addEventListener('dragover', | |
142 this.onDragOver_.bind(this, true /* onlyIntoDirectories */, list)); | |
143 list.addEventListener('dragenter', | |
144 this.onDragEnterVolumesList_.bind(this, list)); | |
145 list.addEventListener('dragleave', this.onDragLeave_.bind(this, list)); | |
146 list.addEventListener('drop', | |
147 this.onDrop_.bind(this, true /* onlyIntoDirectories */)); | |
148 }, | |
149 | |
150 /** | |
151 * Attach handlers of copy, cut and paste operations to the document. | 137 * Attach handlers of copy, cut and paste operations to the document. |
152 * | 138 * |
153 * @this {FileTransferController} | 139 * @this {FileTransferController} |
154 */ | 140 */ |
155 attachCopyPasteHandlers: function() { | 141 attachCopyPasteHandlers: function() { |
156 this.document_.addEventListener('beforecopy', | 142 this.document_.addEventListener('beforecopy', |
157 this.onBeforeCopy_.bind(this)); | 143 this.onBeforeCopy_.bind(this)); |
158 this.document_.addEventListener('copy', | 144 this.document_.addEventListener('copy', |
159 this.onCopy_.bind(this)); | 145 this.onCopy_.bind(this)); |
160 this.document_.addEventListener('beforecut', | 146 this.document_.addEventListener('beforecut', |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 var entry = item && item.entry; | 610 var entry = item && item.entry; |
625 if (entry) { | 611 if (entry) { |
626 this.setDropTarget_(item, event.dataTransfer, entry); | 612 this.setDropTarget_(item, event.dataTransfer, entry); |
627 } else { | 613 } else { |
628 this.clearDropTarget_(); | 614 this.clearDropTarget_(); |
629 } | 615 } |
630 }, | 616 }, |
631 | 617 |
632 /** | 618 /** |
633 * @this {FileTransferController} | 619 * @this {FileTransferController} |
634 * @param {NavigationList} list Drop target list. | |
635 * @param {Event} event A dragenter event of DOM. | |
636 */ | |
637 onDragEnterVolumesList_: function(list, event) { | |
638 event.preventDefault(); // Required to prevent the cursor flicker. | |
639 | |
640 this.lastEnteredTarget_ = event.target; | |
641 var item = list.getListItemAncestor(event.target); | |
642 item = item && list.isItem(item) ? item : null; | |
643 if (item === this.dropTarget_) | |
644 return; | |
645 | |
646 var modelItem = item && list.dataModel.item(item.listIndex); | |
647 if (modelItem && modelItem.isShortcut) { | |
648 this.setDropTarget_(item, event.dataTransfer, modelItem.entry); | |
649 return; | |
650 } | |
651 if (modelItem && modelItem.isVolume && modelItem.volumeInfo.displayRoot) { | |
652 this.setDropTarget_( | |
653 item, event.dataTransfer, modelItem.volumeInfo.displayRoot); | |
654 return; | |
655 } | |
656 | |
657 this.clearDropTarget_(); | |
658 }, | |
659 | |
660 /** | |
661 * @this {FileTransferController} | |
662 * @param {cr.ui.List} list Drop target list. | 620 * @param {cr.ui.List} list Drop target list. |
663 * @param {Event} event A dragleave event of DOM. | 621 * @param {Event} event A dragleave event of DOM. |
664 */ | 622 */ |
665 onDragLeave_: function(list, event) { | 623 onDragLeave_: function(list, event) { |
666 // If mouse moves from one element to another the 'dragenter' | 624 // If mouse moves from one element to another the 'dragenter' |
667 // event for the new element comes before the 'dragleave' event for | 625 // event for the new element comes before the 'dragleave' event for |
668 // the old one. In this case event.target !== this.lastEnteredTarget_ | 626 // the old one. In this case event.target !== this.lastEnteredTarget_ |
669 // and handler of the 'dragenter' event has already caried of | 627 // and handler of the 'dragenter' event has already caried of |
670 // drop target. So event.target === this.lastEnteredTarget_ | 628 // drop target. So event.target === this.lastEnteredTarget_ |
671 // could only be if mouse goes out of listened element. | 629 // could only be if mouse goes out of listened element. |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 !event.ctrlKey) { | 1060 !event.ctrlKey) { |
1103 return 'move'; | 1061 return 'move'; |
1104 } | 1062 } |
1105 if (event.shiftKey) { | 1063 if (event.shiftKey) { |
1106 return 'move'; | 1064 return 'move'; |
1107 } | 1065 } |
1108 } | 1066 } |
1109 return 'copy'; | 1067 return 'copy'; |
1110 }, | 1068 }, |
1111 }; | 1069 }; |
OLD | NEW |