| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * Called from the main frame when unloading. | 8 * Called from the main frame when unloading. |
| 9 * @param {boolean=} opt_exiting True if the app is exiting. | 9 * @param {boolean=} opt_exiting True if the app is exiting. |
| 10 */ | 10 */ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * Gallery for viewing and editing image files. | 21 * Gallery for viewing and editing image files. |
| 22 * | 22 * |
| 23 * @param {!VolumeManager} volumeManager The VolumeManager instance of the | 23 * @param {!VolumeManager} volumeManager The VolumeManager instance of the |
| 24 * system. | 24 * system. |
| 25 * @class | 25 * @class |
| 26 * @constructor | 26 * @constructor |
| 27 */ | 27 */ |
| 28 function Gallery(volumeManager) { | 28 function Gallery(volumeManager) { |
| 29 this.context_ = { | 29 this.context_ = { |
| 30 appWindow: chrome.app.window.current(), | 30 appWindow: chrome.app.window.current(), |
| 31 onBack: function() {}, | |
| 32 onClose: function() { close(); }, | 31 onClose: function() { close(); }, |
| 33 onMaximize: function() { | 32 onMaximize: function() { |
| 34 var appWindow = chrome.app.window.current(); | 33 var appWindow = chrome.app.window.current(); |
| 35 if (appWindow.isMaximized()) | 34 if (appWindow.isMaximized()) |
| 36 appWindow.restore(); | 35 appWindow.restore(); |
| 37 else | 36 else |
| 38 appWindow.maximize(); | 37 appWindow.maximize(); |
| 39 }, | 38 }, |
| 40 onMinimize: function() { chrome.app.window.current().minimize(); }, | 39 onMinimize: function() { chrome.app.window.current().minimize(); }, |
| 41 onAppRegionChanged: function() {}, | 40 onAppRegionChanged: function() {}, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 * Closes gallery when a volume containing the selected item is unmounted. | 122 * Closes gallery when a volume containing the selected item is unmounted. |
| 124 * @param {!Event} event The unmount event. | 123 * @param {!Event} event The unmount event. |
| 125 * @private | 124 * @private |
| 126 */ | 125 */ |
| 127 Gallery.prototype.onExternallyUnmounted_ = function(event) { | 126 Gallery.prototype.onExternallyUnmounted_ = function(event) { |
| 128 if (!this.selectedEntry_) | 127 if (!this.selectedEntry_) |
| 129 return; | 128 return; |
| 130 | 129 |
| 131 if (this.volumeManager_.getVolumeInfo(this.selectedEntry_) === | 130 if (this.volumeManager_.getVolumeInfo(this.selectedEntry_) === |
| 132 event.volumeInfo) { | 131 event.volumeInfo) { |
| 133 this.onBack_(); | 132 close(); |
| 134 } | 133 } |
| 135 }; | 134 }; |
| 136 | 135 |
| 137 /** | 136 /** |
| 138 * Unloads the Gallery. | 137 * Unloads the Gallery. |
| 139 * @param {boolean} exiting True if the app is exiting. | 138 * @param {boolean} exiting True if the app is exiting. |
| 140 */ | 139 */ |
| 141 Gallery.prototype.onUnload = function(exiting) { | 140 Gallery.prototype.onUnload = function(exiting) { |
| 142 if (this.metadataCacheObserverId_ !== null) | 141 if (this.metadataCacheObserverId_ !== null) |
| 143 this.metadataCache_.removeObserver(this.metadataCacheObserverId_); | 142 this.metadataCache_.removeObserver(this.metadataCacheObserverId_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 154 // Initialize the dialog label. | 153 // Initialize the dialog label. |
| 155 cr.ui.dialogs.BaseDialog.OK_LABEL = str('GALLERY_OK_LABEL'); | 154 cr.ui.dialogs.BaseDialog.OK_LABEL = str('GALLERY_OK_LABEL'); |
| 156 cr.ui.dialogs.BaseDialog.CANCEL_LABEL = str('GALLERY_CANCEL_LABEL'); | 155 cr.ui.dialogs.BaseDialog.CANCEL_LABEL = str('GALLERY_CANCEL_LABEL'); |
| 157 | 156 |
| 158 var content = util.createChild(this.container_, 'content'); | 157 var content = util.createChild(this.container_, 'content'); |
| 159 content.addEventListener('click', this.onContentClick_.bind(this)); | 158 content.addEventListener('click', this.onContentClick_.bind(this)); |
| 160 | 159 |
| 161 this.header_ = util.createChild(this.container_, 'header tool dimmable'); | 160 this.header_ = util.createChild(this.container_, 'header tool dimmable'); |
| 162 this.toolbar_ = util.createChild(this.container_, 'toolbar tool dimmable'); | 161 this.toolbar_ = util.createChild(this.container_, 'toolbar tool dimmable'); |
| 163 | 162 |
| 164 var backButton = util.createChild(this.container_, | |
| 165 'back-button tool dimmable'); | |
| 166 util.createChild(backButton); | |
| 167 backButton.addEventListener('click', this.onBack_.bind(this)); | |
| 168 | |
| 169 var preventDefault = function(event) { event.preventDefault(); }; | 163 var preventDefault = function(event) { event.preventDefault(); }; |
| 170 | 164 |
| 171 var minimizeButton = util.createChild(this.header_, | 165 var minimizeButton = util.createChild(this.header_, |
| 172 'minimize-button tool dimmable', | 166 'minimize-button tool dimmable', |
| 173 'button'); | 167 'button'); |
| 174 minimizeButton.tabIndex = -1; | 168 minimizeButton.tabIndex = -1; |
| 175 minimizeButton.addEventListener('click', this.onMinimize_.bind(this)); | 169 minimizeButton.addEventListener('click', this.onMinimize_.bind(this)); |
| 176 minimizeButton.addEventListener('mousedown', preventDefault); | 170 minimizeButton.addEventListener('mousedown', preventDefault); |
| 177 | 171 |
| 178 var maximizeButton = util.createChild(this.header_, | 172 var maximizeButton = util.createChild(this.header_, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 /* TODO: consider nice blow-up animation for the first image */ | 323 /* TODO: consider nice blow-up animation for the first image */ |
| 330 this.slideMode_.enter(null, function() { | 324 this.slideMode_.enter(null, function() { |
| 331 // Flash the toolbar briefly to show it is there. | 325 // Flash the toolbar briefly to show it is there. |
| 332 this.inactivityWatcher_.kick(Gallery.FIRST_FADE_TIMEOUT); | 326 this.inactivityWatcher_.kick(Gallery.FIRST_FADE_TIMEOUT); |
| 333 }.bind(this), | 327 }.bind(this), |
| 334 maybeLoadMosaic); | 328 maybeLoadMosaic); |
| 335 } | 329 } |
| 336 }; | 330 }; |
| 337 | 331 |
| 338 /** | 332 /** |
| 339 * Closes the Gallery and go to Files.app. | |
| 340 * @private | |
| 341 */ | |
| 342 Gallery.prototype.back_ = function() { | |
| 343 if (util.isFullScreen(this.context_.appWindow)) { | |
| 344 util.toggleFullScreen(this.context_.appWindow, | |
| 345 false); // Leave the full screen mode. | |
| 346 } | |
| 347 this.context_.onBack(this.getSelectedEntries()); | |
| 348 }; | |
| 349 | |
| 350 /** | |
| 351 * Handles user's 'Back' action (Escape or a click on the X icon). | |
| 352 * @private | |
| 353 */ | |
| 354 Gallery.prototype.onBack_ = function() { | |
| 355 this.executeWhenReady(this.back_.bind(this)); | |
| 356 }; | |
| 357 | |
| 358 /** | |
| 359 * Handles user's 'Close' action. | 333 * Handles user's 'Close' action. |
| 360 * @private | 334 * @private |
| 361 */ | 335 */ |
| 362 Gallery.prototype.onClose_ = function() { | 336 Gallery.prototype.onClose_ = function() { |
| 363 this.executeWhenReady(this.context_.onClose); | 337 this.executeWhenReady(this.context_.onClose); |
| 364 }; | 338 }; |
| 365 | 339 |
| 366 /** | 340 /** |
| 367 * Handles user's 'Maximize' action (Escape or a click on the X icon). | 341 * Handles user's 'Maximize' action (Escape or a click on the X icon). |
| 368 * @private | 342 * @private |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 | 579 |
| 606 if (this.currentMode_.onKeyDown(event)) | 580 if (this.currentMode_.onKeyDown(event)) |
| 607 return; | 581 return; |
| 608 | 582 |
| 609 switch (util.getKeyModifiers(event) + event.keyIdentifier) { | 583 switch (util.getKeyModifiers(event) + event.keyIdentifier) { |
| 610 case 'U+0008': // Backspace. | 584 case 'U+0008': // Backspace. |
| 611 // The default handler would call history.back and close the Gallery. | 585 // The default handler would call history.back and close the Gallery. |
| 612 event.preventDefault(); | 586 event.preventDefault(); |
| 613 break; | 587 break; |
| 614 | 588 |
| 615 case 'U+001B': // Escape | |
| 616 // Swallow Esc if it closed the Share menu, otherwise close the Gallery. | |
| 617 if (!wasSharing) | |
| 618 this.onBack_(); | |
| 619 break; | |
| 620 | |
| 621 case 'U+004D': // 'm' switches between Slide and Mosaic mode. | 589 case 'U+004D': // 'm' switches between Slide and Mosaic mode. |
| 622 this.toggleMode_(null, event); | 590 this.toggleMode_(null, event); |
| 623 break; | 591 break; |
| 624 | 592 |
| 625 case 'U+0056': // 'v' | 593 case 'U+0056': // 'v' |
| 626 this.slideMode_.startSlideshow(SlideMode.SLIDESHOW_INTERVAL_FIRST, event); | 594 this.slideMode_.startSlideshow(SlideMode.SLIDESHOW_INTERVAL_FIRST, event); |
| 627 break; | 595 break; |
| 628 | 596 |
| 629 case 'U+007F': // Delete | 597 case 'U+007F': // Delete |
| 630 case 'Shift-U+0033': // Shift+'3' (Delete key might be missing). | 598 case 'Shift-U+0033': // Shift+'3' (Delete key might be missing). |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 ]).then(function(args) { | 861 ]).then(function(args) { |
| 894 var backgroundComponents = args[0]; | 862 var backgroundComponents = args[0]; |
| 895 var entries = args[1]; | 863 var entries = args[1]; |
| 896 window.loadTimeData.data = backgroundComponents.stringData; | 864 window.loadTimeData.data = backgroundComponents.stringData; |
| 897 var gallery = new Gallery(backgroundComponents.volumeManager); | 865 var gallery = new Gallery(backgroundComponents.volumeManager); |
| 898 gallery.load(entries.allEntries, entries.selectedEntries); | 866 gallery.load(entries.allEntries, entries.selectedEntries); |
| 899 }).catch(function(error) { | 867 }).catch(function(error) { |
| 900 console.error(error.stack || error); | 868 console.error(error.stack || error); |
| 901 }); | 869 }); |
| 902 }); | 870 }); |
| OLD | NEW |