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 // Setting the src of an img to an empty string can crash the browser, so we | 5 // Setting the src of an img to an empty string can crash the browser, so we |
6 // use an empty 1x1 gif instead. | 6 // use an empty 1x1 gif instead. |
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' | 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' |
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; | 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 2498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2509 var dirPath = this.directoryModel_.currentEntry.fullPath; | 2509 var dirPath = this.directoryModel_.currentEntry.fullPath; |
2510 | 2510 |
2511 // Push a temporary state which will be replaced every time an individual | 2511 // Push a temporary state which will be replaced every time an individual |
2512 // item is selected in the Gallery. | 2512 // item is selected in the Gallery. |
2513 this.updateLocation_(false /*push*/, dirPath); | 2513 this.updateLocation_(false /*push*/, dirPath); |
2514 | 2514 |
2515 galleryFrame.onload = function() { | 2515 galleryFrame.onload = function() { |
2516 self.document_.title = str('GALLERY'); | 2516 self.document_.title = str('GALLERY'); |
2517 galleryFrame.contentWindow.ImageUtil.metrics = metrics; | 2517 galleryFrame.contentWindow.ImageUtil.metrics = metrics; |
2518 galleryFrame.contentWindow.FileType = FileType; | 2518 galleryFrame.contentWindow.FileType = FileType; |
| 2519 galleryFrame.contentWindow.util = util; |
2519 | 2520 |
2520 galleryFrame.contentWindow.Gallery.open( | 2521 galleryFrame.contentWindow.Gallery.open( |
2521 self.directoryModel_.currentEntry, | 2522 self.directoryModel_.currentEntry, |
2522 urls, | 2523 urls, |
2523 selectedUrl, | 2524 selectedUrl, |
2524 function(name) { | 2525 function(name) { |
2525 self.updateLocation_(true /*replace*/, dirPath + '/' + name); | 2526 self.updateLocation_(true /*replace*/, dirPath + '/' + name); |
2526 }, | 2527 }, |
2527 function () { history.back(1) }, | 2528 function () { history.back(1) }, |
2528 self.metadataProvider_, | 2529 self.metadataProvider_, |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3352 | 3353 |
3353 FileManager.prototype.onRenameInputKeyDown_ = function(event) { | 3354 FileManager.prototype.onRenameInputKeyDown_ = function(event) { |
3354 if (!this.isRenamingInProgress()) | 3355 if (!this.isRenamingInProgress()) |
3355 return; | 3356 return; |
3356 | 3357 |
3357 // Do not move selection or lead item in list during rename. | 3358 // Do not move selection or lead item in list during rename. |
3358 if (event.keyIdentifier == 'Up' || event.keyIdentifier == 'Down') { | 3359 if (event.keyIdentifier == 'Up' || event.keyIdentifier == 'Down') { |
3359 event.stopPropagation(); | 3360 event.stopPropagation(); |
3360 } | 3361 } |
3361 | 3362 |
3362 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) | 3363 switch (util.getKeyModifiers(event) + event.keyCode) { |
3363 return; | 3364 case '27': // Escape |
3364 | |
3365 switch (event.keyCode) { | |
3366 case 27: // Escape | |
3367 this.cancelRename_(); | 3365 this.cancelRename_(); |
3368 event.preventDefault(); | 3366 event.preventDefault(); |
3369 break; | 3367 break; |
3370 | 3368 |
3371 case 13: // Enter | 3369 case '13': // Enter |
3372 this.commitRename_(); | 3370 this.commitRename_(); |
3373 event.preventDefault(); | 3371 event.preventDefault(); |
3374 break; | 3372 break; |
3375 } | 3373 } |
3376 }; | 3374 }; |
3377 | 3375 |
3378 FileManager.prototype.onRenameInputBlur_ = function(event) { | 3376 FileManager.prototype.onRenameInputBlur_ = function(event) { |
3379 if (this.isRenamingInProgress() && !this.renameInput_.validation_) | 3377 if (this.isRenamingInProgress() && !this.renameInput_.validation_) |
3380 this.cancelRename_(); | 3378 this.cancelRename_(); |
3381 }; | 3379 }; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3433 var parent = this.renameInput_.parentNode; | 3431 var parent = this.renameInput_.parentNode; |
3434 if (parent) { | 3432 if (parent) { |
3435 parent.removeAttribute('renaming'); | 3433 parent.removeAttribute('renaming'); |
3436 parent.removeChild(this.renameInput_); | 3434 parent.removeChild(this.renameInput_); |
3437 } | 3435 } |
3438 this.refocus(); | 3436 this.refocus(); |
3439 }; | 3437 }; |
3440 | 3438 |
3441 FileManager.prototype.onFilenameInputKeyUp_ = function(event) { | 3439 FileManager.prototype.onFilenameInputKeyUp_ = function(event) { |
3442 var enabled = this.updateOkButton_(); | 3440 var enabled = this.updateOkButton_(); |
3443 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) | 3441 if (enabled && |
3444 return; | 3442 (util.getKeyModifiers(event) + event.keyCode) == '13' /* Enter */) |
3445 if (enabled && event.keyCode == 13 /* Enter */) | |
3446 this.onOk_(); | 3443 this.onOk_(); |
3447 }; | 3444 }; |
3448 | 3445 |
3449 FileManager.prototype.onFilenameInputFocus_ = function(event) { | 3446 FileManager.prototype.onFilenameInputFocus_ = function(event) { |
3450 var input = this.filenameInput_; | 3447 var input = this.filenameInput_; |
3451 | 3448 |
3452 // On focus we want to select everything but the extension, but | 3449 // On focus we want to select everything but the extension, but |
3453 // Chrome will select-all after the focus event completes. We | 3450 // Chrome will select-all after the focus event completes. We |
3454 // schedule a timeout to alter the focus after that happens. | 3451 // schedule a timeout to alter the focus after that happens. |
3455 setTimeout(function() { | 3452 setTimeout(function() { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3556 | 3553 |
3557 /** | 3554 /** |
3558 * KeyDown event handler for the document. | 3555 * KeyDown event handler for the document. |
3559 */ | 3556 */ |
3560 FileManager.prototype.onKeyDown_ = function(event) { | 3557 FileManager.prototype.onKeyDown_ = function(event) { |
3561 if (event.srcElement === this.renameInput_) { | 3558 if (event.srcElement === this.renameInput_) { |
3562 // Ignore keydown handler in the rename input box. | 3559 // Ignore keydown handler in the rename input box. |
3563 return; | 3560 return; |
3564 } | 3561 } |
3565 | 3562 |
3566 if (event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) { | 3563 switch (util.getKeyModifiers(event) + event.keyCode) { |
3567 switch (event.keyCode) { | 3564 case 'Ctrl-190': // Ctrl-. => Toggle filter files. |
3568 case 190: // Ctrl-. => Toggle filter files. | 3565 var dm = this.directoryModel_; |
3569 var dm = this.directoryModel_; | 3566 dm.filterHidden = !dm.filterHidden; |
3570 dm.filterHidden = !dm.filterHidden; | 3567 event.preventDefault(); |
| 3568 return; |
| 3569 |
| 3570 case '27': // Escape => Cancel dialog. |
| 3571 if (this.copyManager_.getStatus().totalFiles != 0) { |
| 3572 // If there is a copy in progress, ESC will cancel it. |
3571 event.preventDefault(); | 3573 event.preventDefault(); |
| 3574 this.copyManager_.requestCancel(); |
3572 return; | 3575 return; |
3573 } | 3576 } |
3574 } | |
3575 | 3577 |
3576 if (!event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) { | 3578 if (this.butterTimer_) { |
3577 switch (event.keyCode) { | 3579 // Allow the user to manually dismiss timed butter messages. |
3578 case 27: // Escape => Cancel dialog. | 3580 event.preventDefault(); |
3579 if (this.copyManager_.getStatus().totalFiles != 0) { | 3581 this.hideButter(); |
3580 // If there is a copy in progress, ESC will cancel it. | 3582 return; |
3581 event.preventDefault(); | 3583 } |
3582 this.copyManager_.requestCancel(); | |
3583 return; | |
3584 } | |
3585 | 3584 |
3586 if (this.butterTimer_) { | 3585 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) { |
3587 // Allow the user to manually dismiss timed butter messages. | 3586 // If there is nothing else for ESC to do, then cancel the dialog. |
3588 event.preventDefault(); | 3587 event.preventDefault(); |
3589 this.hideButter(); | 3588 this.onCancel_(); |
3590 return; | 3589 } |
3591 } | 3590 break; |
3592 | |
3593 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) { | |
3594 // If there is nothing else for ESC to do, then cancel the dialog. | |
3595 event.preventDefault(); | |
3596 this.onCancel_(); | |
3597 } | |
3598 break; | |
3599 } | |
3600 } | 3591 } |
3601 }; | 3592 }; |
3602 | 3593 |
3603 /** | 3594 /** |
3604 * KeyDown event handler for the div.list-container element. | 3595 * KeyDown event handler for the div.list-container element. |
3605 */ | 3596 */ |
3606 FileManager.prototype.onListKeyDown_ = function(event) { | 3597 FileManager.prototype.onListKeyDown_ = function(event) { |
3607 if (event.srcElement.tagName == 'INPUT') { | 3598 if (event.srcElement.tagName == 'INPUT') { |
3608 // Ignore keydown handler in the rename input box. | 3599 // Ignore keydown handler in the rename input box. |
3609 return; | 3600 return; |
3610 } | 3601 } |
3611 | 3602 |
3612 var self = this; | 3603 var self = this; |
3613 function handleCommand(name) { | 3604 function handleCommand(name) { |
3614 self.updateCommands_(); | 3605 self.updateCommands_(); |
3615 if (self.commands_[name].disabled) | 3606 if (self.commands_[name].disabled) |
3616 return; | 3607 return; |
3617 event.preventDefault(); | 3608 event.preventDefault(); |
3618 event.stopPropagation(); | 3609 event.stopPropagation(); |
3619 self.commands_[name].execute(); | 3610 self.commands_[name].execute(); |
3620 } | 3611 } |
3621 | 3612 |
3622 if (event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) { | 3613 switch (util.getKeyModifiers(event) + event.keyCode) { |
3623 switch (event.keyCode) { | 3614 case 'Ctrl-32': // Ctrl-Space => New Folder. |
3624 case 32: // Ctrl-Space => New Folder. | 3615 handleCommand('newfolder'); |
3625 handleCommand('newfolder'); | 3616 break; |
3626 break; | |
3627 | 3617 |
3628 case 88: // Ctrl-X => Cut. | 3618 case 'Ctrl-88': // Ctrl-X => Cut. |
3629 handleCommand('cut'); | 3619 handleCommand('cut'); |
3630 break; | 3620 break; |
3631 | 3621 |
3632 case 67: // Ctrl-C => Copy. | 3622 case 'Ctrl-67': // Ctrl-C => Copy. |
3633 handleCommand('copy'); | 3623 handleCommand('copy'); |
3634 break; | 3624 break; |
3635 | 3625 |
3636 case 86: // Ctrl-V => Paste. | 3626 case 'Ctrl-86': // Ctrl-V => Paste. |
3637 handleCommand('paste'); | 3627 handleCommand('paste'); |
3638 break; | 3628 break; |
3639 | 3629 |
3640 case 69: // Ctrl-E => Rename. | 3630 case 'Ctrl-69': // Ctrl-E => Rename. |
3641 handleCommand('rename'); | 3631 handleCommand('rename'); |
3642 break; | 3632 break; |
3643 } | |
3644 } | |
3645 | 3633 |
3646 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) | 3634 case '8': // Backspace => Up one directory. |
3647 return; | |
3648 | |
3649 switch (event.keyCode) { | |
3650 case 8: // Backspace => Up one directory. | |
3651 event.preventDefault(); | 3635 event.preventDefault(); |
3652 var path = this.getCurrentDirectory(); | 3636 var path = this.getCurrentDirectory(); |
3653 if (path && !DirectoryModel.isRootPath(path)) { | 3637 if (path && !DirectoryModel.isRootPath(path)) { |
3654 var path = path.replace(/\/[^\/]+$/, ''); | 3638 var path = path.replace(/\/[^\/]+$/, ''); |
3655 this.directoryModel_.changeDirectory(path); | 3639 this.directoryModel_.changeDirectory(path); |
3656 } | 3640 } |
3657 break; | 3641 break; |
3658 | 3642 |
3659 case 13: // Enter => Change directory or perform default action. | 3643 case '13': // Enter => Change directory or perform default action. |
3660 if (this.selection.totalCount == 1 && | 3644 if (this.selection.totalCount == 1 && |
3661 this.selection.entries[0].isDirectory && | 3645 this.selection.entries[0].isDirectory && |
3662 this.dialogType_ != FileManager.SELECT_FOLDER) { | 3646 this.dialogType_ != FileManager.SELECT_FOLDER) { |
3663 event.preventDefault(); | 3647 event.preventDefault(); |
3664 this.onDirectoryAction(this.selection.entries[0]); | 3648 this.onDirectoryAction(this.selection.entries[0]); |
3665 } else if (this.dispatchSelectionAction_()) { | 3649 } else if (this.dispatchSelectionAction_()) { |
3666 event.preventDefault(); | 3650 event.preventDefault(); |
3667 } | 3651 } |
3668 break; | 3652 break; |
3669 | 3653 |
3670 case 46: // Delete. | 3654 case '46': // Delete. |
3671 handleCommand('delete'); | 3655 handleCommand('delete'); |
3672 break; | 3656 break; |
3673 } | 3657 } |
3674 }; | 3658 }; |
3675 | 3659 |
3676 /** | 3660 /** |
3677 * KeyPress event handler for the div.list-container element. | 3661 * KeyPress event handler for the div.list-container element. |
3678 */ | 3662 */ |
3679 FileManager.prototype.onListKeyPress_ = function(event) { | 3663 FileManager.prototype.onListKeyPress_ = function(event) { |
3680 if (event.srcElement.tagName == 'INPUT') { | 3664 if (event.srcElement.tagName == 'INPUT') { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3932 }); | 3916 }); |
3933 }, onError); | 3917 }, onError); |
3934 | 3918 |
3935 function onError(err) { | 3919 function onError(err) { |
3936 console.log('Error while checking free space: ' + err); | 3920 console.log('Error while checking free space: ' + err); |
3937 setTimeout(doCheck, 1000 * 60); | 3921 setTimeout(doCheck, 1000 * 60); |
3938 } | 3922 } |
3939 } | 3923 } |
3940 } | 3924 } |
3941 })(); | 3925 })(); |
OLD | NEW |