Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: chrome/browser/resources/file_manager/js/file_transfer_controller.js

Issue 10226001: Dropping files into the root list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 var MAX_DRAG_THUMBAIL_COUNT = 4; 5 var MAX_DRAG_THUMBAIL_COUNT = 4;
6 6
7 /** 7 /**
8 * TODO(olege): Fix style warnings. 8 * TODO(olege): Fix style warnings.
9 */ 9 */
10 function FileTransferController(fileList, 10 function FileTransferController(fileList,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 attachDragSource: function(list) { 44 attachDragSource: function(list) {
45 list.style.webkitUserDrag = 'element'; 45 list.style.webkitUserDrag = 'element';
46 list.addEventListener('dragstart', this.onDragStart_.bind(this, list)); 46 list.addEventListener('dragstart', this.onDragStart_.bind(this, list));
47 list.addEventListener('dragend', this.onDragEnd_.bind(this, list)); 47 list.addEventListener('dragend', this.onDragEnd_.bind(this, list));
48 list.addEventListener('drag', this.onDrag_.bind(this, list)); 48 list.addEventListener('drag', this.onDrag_.bind(this, list));
49 }, 49 },
50 50
51 /** 51 /**
52 * @param {cr.ui.List} list List itself and its directory items will could 52 * @param {cr.ui.List} list List itself and its directory items will could
53 * be drop target. 53 * be drop target.
54 * @param {boolean=} opt_onlyIntoDirectories If true only directory list
55 * items could be drop targets. Otherwise any other place of the list
56 * accetps files (putting it into the current directory).
54 */ 57 */
55 attachDropTarget: function(list) { 58 attachDropTarget: function(list, opt_onlyIntoDirectories) {
56 list.addEventListener('dragover', this.onDragOver_.bind(this, list)); 59 list.addEventListener('dragover', this.onDragOver_.bind(this, list));
57 list.addEventListener('dragenter', this.onDragEnter_.bind(this, list)); 60 list.addEventListener('dragenter', this.onDragEnter_.bind(this, list));
58 list.addEventListener('dragleave', this.onDragLeave_.bind(this, list)); 61 list.addEventListener('dragleave', this.onDragLeave_.bind(this, list));
59 list.addEventListener('drop', this.onDrop_.bind(this, list)); 62 list.addEventListener('drop', this.onDrop_.bind(this, list,
63 !!opt_onlyIntoDirectories));
60 }, 64 },
61 65
62 /** 66 /**
63 * Attach handlers of copy, cut and paste operations to the document. 67 * Attach handlers of copy, cut and paste operations to the document.
64 * @param {HTMLDocument} doc Command dispatcher. 68 * @param {HTMLDocument} doc Command dispatcher.
65 */ 69 */
66 attachCopyPasteHandlers: function(doc) { 70 attachCopyPasteHandlers: function(doc) {
67 this.document_ = doc; 71 this.document_ = doc;
68 doc.addEventListener('beforecopy', this.onBeforeCopy_.bind(this)); 72 doc.addEventListener('beforecopy', this.onBeforeCopy_.bind(this));
69 doc.addEventListener('copy', this.onCopy_.bind(this)); 73 doc.addEventListener('copy', this.onCopy_.bind(this));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 189
186 this.setDropTarget_(item && list.isItem(item) ? item : null, 190 this.setDropTarget_(item && list.isItem(item) ? item : null,
187 event.dataTransfer); 191 event.dataTransfer);
188 }, 192 },
189 193
190 onDragLeave_: function(event) { 194 onDragLeave_: function(event) {
191 if (this.dragEnterCount_-- == 0) 195 if (this.dragEnterCount_-- == 0)
192 this.setDropTarget_(null); 196 this.setDropTarget_(null);
193 }, 197 },
194 198
195 onDrop_: function(list, event) { 199 onDrop_: function(list, onlyIntoDirectories, event) {
196 console.log('drop: ', event.dataTransfer.dropEffect); 200 console.log('drop: ', event.dataTransfer.dropEffect);
197 var item = list.getListItemAncestor(event.target); 201 var item = list.getListItemAncestor(event.target);
198 var dropTarget = item && list.isItem(item) ? 202 var dropTarget = item && list.isItem(item) ?
199 this.fileList_.item(item.listIndex) : null; 203 list.dataModel.item(item.listIndex) : null;
200 if (dropTarget && !dropTarget.isDirectory) 204 if (dropTarget && !dropTarget.isDirectory)
201 dropTarget = null; 205 dropTarget = null;
206 if (onlyIntoDirectories && !dropTarget)
207 return;
202 if (!this.canPasteOrDrop_(event.dataTransfer, dropTarget)) 208 if (!this.canPasteOrDrop_(event.dataTransfer, dropTarget))
203 return; 209 return;
204 event.preventDefault(); 210 event.preventDefault();
205 this.paste(event.dataTransfer, dropTarget); 211 this.paste(event.dataTransfer, dropTarget);
206 if (this.dropTarget_) { 212 if (this.dropTarget_) {
207 var target = this.dropTarget_; 213 var target = this.dropTarget_;
208 this.setDropTarget_(null); 214 this.setDropTarget_(null);
209 } 215 }
210 }, 216 },
211 217
212 setDropTarget_: function(listItem, opt_dataTransfer) { 218 setDropTarget_: function(listItem, opt_dataTransfer) {
213 if (this.dropTarget_ == listItem) 219 if (this.dropTarget_ == listItem)
214 return; 220 return;
215 221
216 if (listItem) { 222 if (listItem) {
217 var entry = this.fileList_.item(listItem.listIndex); 223 var list = listItem.parentElement;
224 var entry = list.dataModel.item(listItem.listIndex);
218 if (entry.isDirectory && 225 if (entry.isDirectory &&
219 (!opt_dataTransfer || 226 (!opt_dataTransfer ||
220 this.canPasteOrDrop_(opt_dataTransfer, entry))) { 227 this.canPasteOrDrop_(opt_dataTransfer, entry))) {
221 listItem.classList.add('accepts'); 228 listItem.classList.add('accepts');
222 } 229 }
223 } else { 230 } else {
224 this.dragEnterCount_ = 0; 231 this.dragEnterCount_ = 0;
225 } 232 }
226 if (this.dropTarget_ && this.dropTarget_.classList.contains('accepts')) { 233 if (this.dropTarget_ && this.dropTarget_.classList.contains('accepts')) {
227 var oldDropTarget = this.dropTarget_; 234 var oldDropTarget = this.dropTarget_;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 }, 308 },
302 309
303 onBeforePaste_: function(event) { 310 onBeforePaste_: function(event) {
304 if (!this.isDocumentWideEvent_(event)) 311 if (!this.isDocumentWideEvent_(event))
305 return; 312 return;
306 // queryCommandEnabled returns true if event.returnValue is false. 313 // queryCommandEnabled returns true if event.returnValue is false.
307 event.returnValue = !this.canPasteOrDrop_(event.clipboardData); 314 event.returnValue = !this.canPasteOrDrop_(event.clipboardData);
308 }, 315 },
309 316
310 canPasteOrDrop_: function(dataTransfer, opt_entry) { 317 canPasteOrDrop_: function(dataTransfer, opt_entry) {
311 if (this.readonly) 318 if (!opt_entry && this.readonly)
312 return false; // assure destination entry is in the current directory. 319 return false; // assure destination entry is in the current directory.
320 if (opt_entry && this.directoryModel_.isPathReadOnly(opt_entry.fullPath))
321 return false;
313 322
314 if (!dataTransfer.types || dataTransfer.types.indexOf('fs/tag') == -1) 323 if (!dataTransfer.types || dataTransfer.types.indexOf('fs/tag') == -1)
315 return false; // Unsupported type of content. 324 return false; // Unsupported type of content.
316 if (dataTransfer.getData('fs/tag') == '') { 325 if (dataTransfer.getData('fs/tag') == '') {
317 // Data protected. Other checks are not possible but it makes sense to 326 // Data protected. Other checks are not possible but it makes sense to
318 // let the user try. 327 // let the user try.
319 return true; 328 return true;
320 } 329 }
321 330
322 var directories = dataTransfer.getData('fs/directories').split('\n'). 331 var directories = dataTransfer.getData('fs/directories').split('\n').
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 * @type {Array.<Entry>} 409 * @type {Array.<Entry>}
401 */ 410 */
402 get selectedEntries_() { 411 get selectedEntries_() {
403 var list = this.fileList_; 412 var list = this.fileList_;
404 return this.fileListSelection_.selectedIndexes.map(function(index) { 413 return this.fileListSelection_.selectedIndexes.map(function(index) {
405 return list.item(index); 414 return list.item(index);
406 }); 415 });
407 } 416 }
408 }; 417 };
409 418
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698