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

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

Issue 12677002: Adds animation on a hovered directory/volume when dragging files in Files.app (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 7 years, 9 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
« no previous file with comments | « chrome/browser/resources/file_manager/css/file_manager.css ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 5 /**
6 * Global (placed in the window object) variable name to hold internal 6 * Global (placed in the window object) variable name to hold internal
7 * file dragging information. Needed to show visual feedback while dragging 7 * file dragging information. Needed to show visual feedback while dragging
8 * since DataTransfer object is in protected state. Reachable from other 8 * since DataTransfer object is in protected state. Reachable from other
9 * file manager instances. 9 * file manager instances.
10 */ 10 */
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 }, 319 },
320 320
321 /** 321 /**
322 * @this {FileTransferController} 322 * @this {FileTransferController}
323 * @param {cr.ui.List} list Drop target list. 323 * @param {cr.ui.List} list Drop target list.
324 * @param {Event} event A dragend event of DOM. 324 * @param {Event} event A dragend event of DOM.
325 */ 325 */
326 onDragEnd_: function(list, event) { 326 onDragEnd_: function(list, event) {
327 var container = this.document_.querySelector('#drag-container'); 327 var container = this.document_.querySelector('#drag-container');
328 container.textContent = ''; 328 container.textContent = '';
329 this.setDropTarget_(null); 329 this.clearDropTarget_();
330 delete window[DRAG_AND_DROP_GLOBAL_DATA]; 330 delete window[DRAG_AND_DROP_GLOBAL_DATA];
331 }, 331 },
332 332
333 /** 333 /**
334 * @this {FileTransferController} 334 * @this {FileTransferController}
335 * @param {boolean} onlyIntoDirectories True if the drag is only into 335 * @param {boolean} onlyIntoDirectories True if the drag is only into
336 * directoris. 336 * directoris.
337 * @param {cr.ui.List} list Drop target list. 337 * @param {cr.ui.List} list Drop target list.
338 * @param {Event} event A dragover event of DOM. 338 * @param {Event} event A dragover event of DOM.
339 */ 339 */
(...skipping 16 matching lines...) Expand all
356 var item = list.getListItemAncestor(event.target); 356 var item = list.getListItemAncestor(event.target);
357 item = item && list.isItem(item) ? item : null; 357 item = item && list.isItem(item) ? item : null;
358 if (item == this.dropTarget_) 358 if (item == this.dropTarget_)
359 return; 359 return;
360 360
361 var entry = item && list.dataModel.item(item.listIndex); 361 var entry = item && list.dataModel.item(item.listIndex);
362 if (entry) { 362 if (entry) {
363 this.setDropTarget_(item, entry.isDirectory, event.dataTransfer, 363 this.setDropTarget_(item, entry.isDirectory, event.dataTransfer,
364 entry.fullPath); 364 entry.fullPath);
365 } else { 365 } else {
366 this.setDropTarget_(null); 366 this.clearDropTarget_();
367 } 367 }
368 }, 368 },
369 369
370 /** 370 /**
371 * @this {FileTransferController} 371 * @this {FileTransferController}
372 * @param {HTMLElement} breadcrumbsContainer Element which contains target 372 * @param {HTMLElement} breadcrumbsContainer Element which contains target
373 * breadcrumbs. 373 * breadcrumbs.
374 * @param {Event} event A dragenter event of DOM. 374 * @param {Event} event A dragenter event of DOM.
375 */ 375 */
376 onDragEnterBreadcrumbs_: function(breadcrumbsContainer, event) { 376 onDragEnterBreadcrumbs_: function(breadcrumbsContainer, event) {
(...skipping 12 matching lines...) Expand all
389 * @param {Event} event A dragleave event of DOM. 389 * @param {Event} event A dragleave event of DOM.
390 */ 390 */
391 onDragLeave_: function(list, event) { 391 onDragLeave_: function(list, event) {
392 // If mouse moves from one element to another the 'dragenter' 392 // If mouse moves from one element to another the 'dragenter'
393 // event for the new element comes before the 'dragleave' event for 393 // event for the new element comes before the 'dragleave' event for
394 // the old one. In this case event.target != this.lastEnteredTarget_ 394 // the old one. In this case event.target != this.lastEnteredTarget_
395 // and handler of the 'dragenter' event has already caried of 395 // and handler of the 'dragenter' event has already caried of
396 // drop target. So event.target == this.lastEnteredTarget_ 396 // drop target. So event.target == this.lastEnteredTarget_
397 // could only be if mouse goes out of listened element. 397 // could only be if mouse goes out of listened element.
398 if (event.target == this.lastEnteredTarget_) { 398 if (event.target == this.lastEnteredTarget_) {
399 this.setDropTarget_(null); 399 this.clearDropTarget_();
400 this.lastEnteredTarget_ = null; 400 this.lastEnteredTarget_ = null;
401 } 401 }
402 }, 402 },
403 403
404 /** 404 /**
405 * @this {FileTransferController} 405 * @this {FileTransferController}
406 * @param {boolean} onlyIntoDirectories True if the drag is only into 406 * @param {boolean} onlyIntoDirectories True if the drag is only into
407 * directories. 407 * directories.
408 * @param {Event} event A dragleave event of DOM. 408 * @param {Event} event A dragleave event of DOM.
409 */ 409 */
410 onDrop_: function(onlyIntoDirectories, event) { 410 onDrop_: function(onlyIntoDirectories, event) {
411 if (onlyIntoDirectories && !this.dropTarget_) 411 if (onlyIntoDirectories && !this.dropTarget_)
412 return; 412 return;
413 var destinationPath = this.destinationPath_ || 413 var destinationPath = this.destinationPath_ ||
414 this.directoryModel_.getCurrentDirPath(); 414 this.directoryModel_.getCurrentDirPath();
415 if (!this.canPasteOrDrop_(event.dataTransfer, destinationPath)) 415 if (!this.canPasteOrDrop_(event.dataTransfer, destinationPath))
416 return; 416 return;
417 event.preventDefault(); 417 event.preventDefault();
418 this.paste(event.dataTransfer, destinationPath, 418 this.paste(event.dataTransfer, destinationPath,
419 this.selectDropEffect_(event, destinationPath)); 419 this.selectDropEffect_(event, destinationPath));
420 this.setDropTarget_(null); 420 this.clearDropTarget_();
421 }, 421 },
422 422
423 /** 423 /**
424 * Sets the drop target.
424 * @this {FileTransferController} 425 * @this {FileTransferController}
426 * @param {Element} domElement Target of the drop.
427 * @param {boolean} isDirectory If the target is a directory.
428 * @param {DataTransfer} dataTransfer Data transfer object.
429 * @param {string} destinationPath Destination path.
425 */ 430 */
426 setDropTarget_: function(domElement, isDirectory, opt_dataTransfer, 431 setDropTarget_: function(domElement, isDirectory, dataTransfer,
427 opt_destinationPath) { 432 destinationPath) {
428 if (this.dropTarget_ == domElement) 433 if (this.dropTarget_ == domElement)
429 return; 434 return;
430 435
431 /** @type {string?} */ 436 /** @type {string?} */
432 this.destinationPath_ = null; 437 this.destinationPath_ = null;
433 if (domElement) { 438
434 if (isDirectory && 439 // Add accept class if the domElement can accept the drag.
435 this.canPasteOrDrop_(opt_dataTransfer, opt_destinationPath)) { 440 if (isDirectory &&
436 domElement.classList.add('accepts'); 441 this.canPasteOrDrop_(dataTransfer, destinationPath)) {
437 this.destinationPath_ = opt_destinationPath; 442 domElement.classList.add('accepts');
438 } 443 this.destinationPath_ = destinationPath;
439 } 444 }
440 if (this.dropTarget_ && this.dropTarget_.classList.contains('accepts')) { 445
441 var oldDropTarget = this.dropTarget_; 446 // Remove the old drag target.
442 var self = this; 447 this.clearDropTarget_();
443 setTimeout(function() { 448
444 if (oldDropTarget != self.dropTarget_) 449 // Set the new drop target.
445 oldDropTarget.classList.remove('accepts');
446 }, 0);
447 }
448 this.dropTarget_ = domElement; 450 this.dropTarget_ = domElement;
449 if (this.navigateTimer_ !== undefined) { 451
450 clearTimeout(this.navigateTimer_); 452 // Start timer changing the directory.
451 this.navigateTimer_ = undefined; 453 if (domElement && isDirectory && destinationPath &&
452 } 454 this.canPasteOrDrop_(dataTransfer, destinationPath)) {
453 if (domElement && isDirectory && opt_destinationPath) {
454 this.navigateTimer_ = setTimeout(function() { 455 this.navigateTimer_ = setTimeout(function() {
455 this.directoryModel_.changeDirectory(opt_destinationPath); 456 this.directoryModel_.changeDirectory(destinationPath);
456 }.bind(this), 2000); 457 }.bind(this), 2000);
457 } 458 }
458 }, 459 },
459 460
460 /** 461 /**
462 * Clears the drop target.
463 * @this {FileTransferController}
464 */
465 clearDropTarget_: function() {
466 if (this.dropTarget_ && this.dropTarget_.classList.contains('accepts'))
467 this.dropTarget_.classList.remove('accepts');
468 this.dropTarget_ = null;
469 if (this.navigateTimer_ !== undefined) {
470 clearTimeout(this.navigateTimer_);
471 this.navigateTimer_ = undefined;
472 }
473 },
474
475 /**
461 * @this {FileTransferController} 476 * @this {FileTransferController}
462 * @return {boolean} Returns false if {@code <input type="text">} element is 477 * @return {boolean} Returns false if {@code <input type="text">} element is
463 * currently active. Otherwise, returns true. 478 * currently active. Otherwise, returns true.
464 */ 479 */
465 isDocumentWideEvent_: function() { 480 isDocumentWideEvent_: function() {
466 return this.document_.activeElement.nodeName.toLowerCase() != 'input' || 481 return this.document_.activeElement.nodeName.toLowerCase() != 'input' ||
467 this.document_.activeElement.type.toLowerCase() != 'text'; 482 this.document_.activeElement.type.toLowerCase() != 'text';
468 }, 483 },
469 484
470 /** 485 /**
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 */ 537 */
523 onBeforeCut_: function(event) { 538 onBeforeCut_: function(event) {
524 if (!this.isDocumentWideEvent_()) 539 if (!this.isDocumentWideEvent_())
525 return; 540 return;
526 // queryCommandEnabled returns true if event.returnValue is false. 541 // queryCommandEnabled returns true if event.returnValue is false.
527 event.returnValue = !this.canCutOrDrag_(); 542 event.returnValue = !this.canCutOrDrag_();
528 }, 543 },
529 544
530 /** 545 /**
531 * @this {FileTransferController} 546 * @this {FileTransferController}
532 * @return {boolean} Returns true if some files are selected and all the file 547 * @return {boolean} Returns true if some files are selected and all the file
533 * on drive is available to be cut. Otherwise, returns false. 548 * on drive is available to be cut. Otherwise, returns false.
534 */ 549 */
535 canCutOrDrag_: function() { 550 canCutOrDrag_: function() {
536 return !this.readonly && this.canCopyOrDrag_(); 551 return !this.readonly && this.canCopyOrDrag_();
537 }, 552 },
538 553
539 /** 554 /**
540 * @this {FileTransferController} 555 * @this {FileTransferController}
541 */ 556 */
542 onPaste_: function(event) { 557 onPaste_: function(event) {
(...skipping 20 matching lines...) Expand all
563 */ 578 */
564 onBeforePaste_: function(event) { 579 onBeforePaste_: function(event) {
565 if (!this.isDocumentWideEvent_()) 580 if (!this.isDocumentWideEvent_())
566 return; 581 return;
567 // queryCommandEnabled returns true if event.returnValue is false. 582 // queryCommandEnabled returns true if event.returnValue is false.
568 event.returnValue = !this.canPasteOrDrop_(event.clipboardData); 583 event.returnValue = !this.canPasteOrDrop_(event.clipboardData);
569 }, 584 },
570 585
571 /** 586 /**
572 * @this {FileTransferController} 587 * @this {FileTransferController}
573 * @return {boolean} Returns true if {@code opt_destinationPath} is 588 * @param {DataTransfer} dataTransfer Data transfer object.
574 * available to be pasted to. Otherwise, returns false. 589 * @param {string=} opt_destinationPath Destination path.
590 * @return {boolean} Returns true if items stored in {@code dataTransfer} can
591 * be pasted to {@code opt_destinationPath}. Otherwise, returns false.
575 */ 592 */
576 canPasteOrDrop_: function(dataTransfer, opt_destinationPath) { 593 canPasteOrDrop_: function(dataTransfer, opt_destinationPath) {
577 var destinationPath = opt_destinationPath || 594 var destinationPath = opt_destinationPath ||
578 this.directoryModel_.getCurrentDirPath(); 595 this.directoryModel_.getCurrentDirPath();
579 if (this.directoryModel_.isPathReadOnly(destinationPath)) { 596 if (this.directoryModel_.isPathReadOnly(destinationPath)) {
580 return false; 597 return false;
581 } 598 }
582 if (this.directoryModel_.isSearching()) 599 if (this.directoryModel_.isSearching())
583 return false; 600 return false;
584 601
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 !event.ctrlKey) { 780 !event.ctrlKey) {
764 return 'move'; 781 return 'move';
765 } 782 }
766 if (event.dataTransfer.effectAllowed == 'copyMove' && 783 if (event.dataTransfer.effectAllowed == 'copyMove' &&
767 event.shiftKey) { 784 event.shiftKey) {
768 return 'move'; 785 return 'move';
769 } 786 }
770 return 'copy'; 787 return 'copy';
771 }, 788 },
772 }; 789 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/css/file_manager.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698