| 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 /** | 5 /** |
| 6 * Overrided metadata worker's path. | 6 * Overrided metadata worker's path. |
| 7 * @type {string} | 7 * @type {string} |
| 8 */ | 8 */ |
| 9 ContentMetadataProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; | 9 ContentMetadataProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; |
| 10 | 10 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // ----------------------------------------------------------------- | 78 // ----------------------------------------------------------------- |
| 79 // Initializes the UI. | 79 // Initializes the UI. |
| 80 | 80 |
| 81 // Initialize the dialog label. | 81 // Initialize the dialog label. |
| 82 cr.ui.dialogs.BaseDialog.OK_LABEL = str('GALLERY_OK_LABEL'); | 82 cr.ui.dialogs.BaseDialog.OK_LABEL = str('GALLERY_OK_LABEL'); |
| 83 cr.ui.dialogs.BaseDialog.CANCEL_LABEL = str('GALLERY_CANCEL_LABEL'); | 83 cr.ui.dialogs.BaseDialog.CANCEL_LABEL = str('GALLERY_CANCEL_LABEL'); |
| 84 | 84 |
| 85 var content = queryRequiredElement(document, '#content'); | 85 var content = queryRequiredElement(document, '#content'); |
| 86 content.addEventListener('click', this.onContentClick_.bind(this)); | 86 content.addEventListener('click', this.onContentClick_.bind(this)); |
| 87 | 87 |
| 88 this.header_ = queryRequiredElement(document, '#header'); |
| 88 this.topToolbar_ = queryRequiredElement(document, '#top-toolbar'); | 89 this.topToolbar_ = queryRequiredElement(document, '#top-toolbar'); |
| 89 this.bottomToolbar_ = queryRequiredElement(document, '#bottom-toolbar'); | 90 this.bottomToolbar_ = queryRequiredElement(document, '#bottom-toolbar'); |
| 90 | 91 |
| 91 this.filenameSpacer_ = queryRequiredElement(this.topToolbar_, | 92 this.filenameSpacer_ = queryRequiredElement(this.topToolbar_, |
| 92 '.filename-spacer'); | 93 '.filename-spacer'); |
| 93 this.filenameEdit_ = util.createChild(this.filenameSpacer_, | 94 this.filenameEdit_ = util.createChild(this.filenameSpacer_, |
| 94 'namebox', 'input'); | 95 'namebox', 'input'); |
| 95 | 96 |
| 96 this.filenameEdit_.setAttribute('type', 'text'); | 97 this.filenameEdit_.setAttribute('type', 'text'); |
| 97 this.filenameEdit_.addEventListener('blur', | 98 this.filenameEdit_.addEventListener('blur', |
| 98 this.onFilenameEditBlur_.bind(this)); | 99 this.onFilenameEditBlur_.bind(this)); |
| 99 | 100 |
| 100 this.filenameEdit_.addEventListener('focus', | 101 this.filenameEdit_.addEventListener('focus', |
| 101 this.onFilenameFocus_.bind(this)); | 102 this.onFilenameFocus_.bind(this)); |
| 102 | 103 |
| 103 this.filenameEdit_.addEventListener('keydown', | 104 this.filenameEdit_.addEventListener('keydown', |
| 104 this.onFilenameEditKeydown_.bind(this)); | 105 this.onFilenameEditKeydown_.bind(this)); |
| 105 | 106 |
| 106 var buttonSpacer = queryRequiredElement(this.topToolbar_, '.button-spacer'); | 107 var buttonSpacer = queryRequiredElement(this.topToolbar_, '.button-spacer'); |
| 107 | 108 |
| 108 this.prompt_ = new ImageEditor.Prompt(this.container_, strf); | 109 this.prompt_ = new ImageEditor.Prompt(this.container_, strf); |
| 109 | 110 |
| 110 this.errorBanner_ = new ErrorBanner(this.container_); | 111 this.errorBanner_ = new ErrorBanner(this.container_); |
| 111 | 112 |
| 112 var slideModeButton = queryRequiredElement( | 113 this.modeButton_ = queryRequiredElement(this.topToolbar_, 'button.mode'); |
| 113 this.topToolbar_, '.button.slide-mode'); | 114 this.modeButton_.addEventListener('click', |
| 114 slideModeButton.addEventListener( | 115 this.toggleMode_.bind(this, undefined)); |
| 115 'click', this.onSlideModeButtonClicked_.bind(this)); | |
| 116 | |
| 117 var mosaicModeButton = queryRequiredElement( | |
| 118 this.topToolbar_, '.button.mosaic-mode'); | |
| 119 mosaicModeButton.addEventListener( | |
| 120 'click', this.onMosaicModeButtonClicked_.bind(this)); | |
| 121 | 116 |
| 122 this.mosaicMode_ = new MosaicMode(content, | 117 this.mosaicMode_ = new MosaicMode(content, |
| 123 this.errorBanner_, | 118 this.errorBanner_, |
| 124 this.dataModel_, | 119 this.dataModel_, |
| 125 this.selectionModel_, | 120 this.selectionModel_, |
| 126 this.volumeManager_, | 121 this.volumeManager_, |
| 127 this.toggleMode_.bind(this, undefined)); | 122 this.toggleMode_.bind(this, undefined)); |
| 128 | 123 |
| 129 this.slideMode_ = new SlideMode(this.container_, | 124 this.slideMode_ = new SlideMode(this.container_, |
| 130 content, | 125 content, |
| 131 this.topToolbar_, | 126 this.topToolbar_, |
| 132 this.bottomToolbar_, | 127 this.bottomToolbar_, |
| 133 this.prompt_, | 128 this.prompt_, |
| 134 this.errorBanner_, | 129 this.errorBanner_, |
| 135 this.dataModel_, | 130 this.dataModel_, |
| 136 this.selectionModel_, | 131 this.selectionModel_, |
| 137 this.metadataModel_, | 132 this.metadataModel_, |
| 138 this.thumbnailModel_, | 133 this.thumbnailModel_, |
| 139 this.context_, | 134 this.context_, |
| 140 this.volumeManager_, | 135 this.volumeManager_, |
| 141 this.toggleMode_.bind(this), | 136 this.toggleMode_.bind(this), |
| 142 str); | 137 str); |
| 143 | 138 |
| 144 this.slideMode_.addEventListener('image-displayed', function() { | 139 this.slideMode_.addEventListener('image-displayed', function() { |
| 145 cr.dispatchSimpleEvent(this, 'image-displayed'); | 140 cr.dispatchSimpleEvent(this, 'image-displayed'); |
| 146 }.bind(this)); | 141 }.bind(this)); |
| 147 | 142 |
| 148 this.deleteButton_ = queryRequiredElement(this.topToolbar_, '.button.delete'); | 143 this.deleteButton_ = this.initToolbarButton_('delete', 'GALLERY_DELETE'); |
| 149 this.deleteButton_.addEventListener('click', this.delete_.bind(this)); | 144 this.deleteButton_.addEventListener('click', this.delete_.bind(this)); |
| 150 | 145 |
| 151 this.shareButton_ = queryRequiredElement(this.topToolbar_, '.button.share'); | 146 this.shareButton_ = this.initToolbarButton_('share', 'GALLERY_SHARE'); |
| 152 this.shareButton_.addEventListener( | 147 this.shareButton_.addEventListener( |
| 153 'click', this.onShareButtonClick_.bind(this)); | 148 'click', this.onShareButtonClick_.bind(this)); |
| 154 | 149 |
| 155 this.dataModel_.addEventListener('splice', this.onSplice_.bind(this)); | 150 this.dataModel_.addEventListener('splice', this.onSplice_.bind(this)); |
| 156 this.dataModel_.addEventListener('content', this.onContentChange_.bind(this)); | 151 this.dataModel_.addEventListener('content', this.onContentChange_.bind(this)); |
| 157 | 152 |
| 158 this.selectionModel_.addEventListener('change', this.onSelection_.bind(this)); | 153 this.selectionModel_.addEventListener('change', this.onSelection_.bind(this)); |
| 159 this.slideMode_.addEventListener('useraction', this.onUserAction_.bind(this)); | 154 this.slideMode_.addEventListener('useraction', this.onUserAction_.bind(this)); |
| 160 | 155 |
| 161 this.shareDialog_ = new ShareDialog(this.container_); | 156 this.shareDialog_ = new ShareDialog(this.container_); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 * Unloads the Gallery. | 225 * Unloads the Gallery. |
| 231 * @private | 226 * @private |
| 232 */ | 227 */ |
| 233 Gallery.prototype.onPageHide_ = function() { | 228 Gallery.prototype.onPageHide_ = function() { |
| 234 this.volumeManager_.removeEventListener( | 229 this.volumeManager_.removeEventListener( |
| 235 'externally-unmounted', this.onExternallyUnmountedBound_); | 230 'externally-unmounted', this.onExternallyUnmountedBound_); |
| 236 this.volumeManager_.dispose(); | 231 this.volumeManager_.dispose(); |
| 237 }; | 232 }; |
| 238 | 233 |
| 239 /** | 234 /** |
| 235 * Initializes a toolbar button. |
| 236 * |
| 237 * @param {string} className Class to add. |
| 238 * @param {string} title Button title. |
| 239 * @return {!HTMLElement} Newly created button. |
| 240 * @private |
| 241 */ |
| 242 Gallery.prototype.initToolbarButton_ = function(className, title) { |
| 243 var button = queryRequiredElement(this.topToolbar_, 'button.' + className); |
| 244 button.title = str(title); |
| 245 return button; |
| 246 }; |
| 247 |
| 248 /** |
| 240 * Loads the content. | 249 * Loads the content. |
| 241 * | 250 * |
| 242 * @param {!Array<!Entry>} selectedEntries Array of selected entries. | 251 * @param {!Array<!Entry>} selectedEntries Array of selected entries. |
| 243 */ | 252 */ |
| 244 Gallery.prototype.load = function(selectedEntries) { | 253 Gallery.prototype.load = function(selectedEntries) { |
| 245 GalleryUtil.createEntrySet(selectedEntries).then(function(allEntries) { | 254 GalleryUtil.createEntrySet(selectedEntries).then(function(allEntries) { |
| 246 this.loadInternal_(allEntries, selectedEntries); | 255 this.loadInternal_(allEntries, selectedEntries); |
| 247 }.bind(this)); | 256 }.bind(this)); |
| 248 }; | 257 }; |
| 249 | 258 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 */ | 400 */ |
| 392 Gallery.prototype.onUserAction_ = function() { | 401 Gallery.prototype.onUserAction_ = function() { |
| 393 // Show the toolbar and hide it after the default timeout. | 402 // Show the toolbar and hide it after the default timeout. |
| 394 this.inactivityWatcher_.kick(); | 403 this.inactivityWatcher_.kick(); |
| 395 }; | 404 }; |
| 396 | 405 |
| 397 /** | 406 /** |
| 398 * Sets the current mode, update the UI. | 407 * Sets the current mode, update the UI. |
| 399 * @param {!(SlideMode|MosaicMode)} mode Current mode. | 408 * @param {!(SlideMode|MosaicMode)} mode Current mode. |
| 400 * @private | 409 * @private |
| 401 * | |
| 402 * TODO(yawano): Since this method is confusing with changeCurrentMode_. Rename | |
| 403 * or remove this method. | |
| 404 */ | 410 */ |
| 405 Gallery.prototype.setCurrentMode_ = function(mode) { | 411 Gallery.prototype.setCurrentMode_ = function(mode) { |
| 406 if (mode !== this.slideMode_ && mode !== this.mosaicMode_) | 412 if (mode !== this.slideMode_ && mode !== this.mosaicMode_) |
| 407 console.error('Invalid Gallery mode'); | 413 console.error('Invalid Gallery mode'); |
| 408 | 414 |
| 409 this.currentMode_ = mode; | 415 this.currentMode_ = mode; |
| 410 this.container_.setAttribute('mode', this.currentMode_.getName()); | 416 this.container_.setAttribute('mode', this.currentMode_.getName()); |
| 411 this.updateSelectionAndState_(); | 417 this.updateSelectionAndState_(); |
| 412 }; | 418 this.updateButtons_(); |
| 413 | |
| 414 /** | |
| 415 * Handles click event of SlideModeButton. | |
| 416 * @param {!Event} event An event. | |
| 417 * @private | |
| 418 */ | |
| 419 Gallery.prototype.onSlideModeButtonClicked_ = function(event) { | |
| 420 this.changeCurrentMode_(this.slideMode_, event); | |
| 421 }; | |
| 422 | |
| 423 /** | |
| 424 * Handles click event of MosaicModeButton. | |
| 425 * @param {!Event} event An event. | |
| 426 * @private | |
| 427 */ | |
| 428 Gallery.prototype.onMosaicModeButtonClicked_ = function(event) { | |
| 429 this.changeCurrentMode_(this.mosaicMode_, event); | |
| 430 }; | |
| 431 | |
| 432 /** | |
| 433 * Change current mode. | |
| 434 * @param {!(SlideMode|MosaicMode)} mode Target mode. | |
| 435 * @param {Event=} opt_event Event that caused this call. | |
| 436 * @private | |
| 437 */ | |
| 438 Gallery.prototype.changeCurrentMode_ = function(mode, opt_event) { | |
| 439 return new Promise(function(fulfill, reject) { | |
| 440 // Do not re-enter while changing the mode. | |
| 441 if (this.currentMode_ === mode || this.changingMode_) { | |
| 442 fulfill(); | |
| 443 return; | |
| 444 } | |
| 445 | |
| 446 if (opt_event) | |
| 447 this.onUserAction_(); | |
| 448 | |
| 449 this.changingMode_ = true; | |
| 450 | |
| 451 var onModeChanged = function() { | |
| 452 this.changingMode_ = false; | |
| 453 fulfill(); | |
| 454 }.bind(this); | |
| 455 | |
| 456 var tileIndex = Math.max(0, this.selectionModel_.selectedIndex); | |
| 457 | |
| 458 var mosaic = this.mosaicMode_.getMosaic(); | |
| 459 var tileRect = mosaic.getTileRect(tileIndex); | |
| 460 | |
| 461 if (mode === this.mosaicMode_) { | |
| 462 this.setCurrentMode_(this.mosaicMode_); | |
| 463 mosaic.transform( | |
| 464 tileRect, this.slideMode_.getSelectedImageRect(), true /* instant */); | |
| 465 this.slideMode_.leave( | |
| 466 tileRect, | |
| 467 function() { | |
| 468 // Animate back to normal position. | |
| 469 mosaic.transform(null, null); | |
| 470 mosaic.show(); | |
| 471 onModeChanged(); | |
| 472 }.bind(this)); | |
| 473 this.bottomToolbar_.hidden = true; | |
| 474 } else { | |
| 475 this.setCurrentMode_(this.slideMode_); | |
| 476 this.slideMode_.enter( | |
| 477 tileRect, | |
| 478 function() { | |
| 479 // Animate to zoomed position. | |
| 480 mosaic.transform(tileRect, this.slideMode_.getSelectedImageRect()); | |
| 481 mosaic.hide(); | |
| 482 }.bind(this), | |
| 483 onModeChanged); | |
| 484 this.bottomToolbar_.hidden = false; | |
| 485 } | |
| 486 }.bind(this)); | |
| 487 }; | 419 }; |
| 488 | 420 |
| 489 /** | 421 /** |
| 490 * Mode toggle event handler. | 422 * Mode toggle event handler. |
| 491 * @param {function()=} opt_callback Callback. | 423 * @param {function()=} opt_callback Callback. |
| 492 * @param {Event=} opt_event Event that caused this call. | 424 * @param {Event=} opt_event Event that caused this call. |
| 493 * @private | 425 * @private |
| 494 */ | 426 */ |
| 495 Gallery.prototype.toggleMode_ = function(opt_callback, opt_event) { | 427 Gallery.prototype.toggleMode_ = function(opt_callback, opt_event) { |
| 496 var targetMode = this.currentMode_ === this.slideMode_ ? | 428 if (!this.modeButton_) |
| 497 this.mosaicMode_ : this.slideMode_; | 429 return; |
| 498 | 430 |
| 499 this.changeCurrentMode_(targetMode, opt_event).then(function() { | 431 if (this.changingMode_) // Do not re-enter while changing the mode. |
| 500 if (opt_callback) | 432 return; |
| 501 opt_callback(); | 433 |
| 502 }); | 434 if (opt_event) |
| 435 this.onUserAction_(); |
| 436 |
| 437 this.changingMode_ = true; |
| 438 |
| 439 var onModeChanged = function() { |
| 440 this.changingMode_ = false; |
| 441 if (opt_callback) opt_callback(); |
| 442 }.bind(this); |
| 443 |
| 444 var tileIndex = Math.max(0, this.selectionModel_.selectedIndex); |
| 445 |
| 446 var mosaic = this.mosaicMode_.getMosaic(); |
| 447 var tileRect = mosaic.getTileRect(tileIndex); |
| 448 |
| 449 if (this.currentMode_ === this.slideMode_) { |
| 450 this.setCurrentMode_(this.mosaicMode_); |
| 451 mosaic.transform( |
| 452 tileRect, this.slideMode_.getSelectedImageRect(), true /* instant */); |
| 453 this.slideMode_.leave( |
| 454 tileRect, |
| 455 function() { |
| 456 // Animate back to normal position. |
| 457 mosaic.transform(null, null); |
| 458 mosaic.show(); |
| 459 onModeChanged(); |
| 460 }.bind(this)); |
| 461 this.bottomToolbar_.hidden = true; |
| 462 } else { |
| 463 this.setCurrentMode_(this.slideMode_); |
| 464 this.slideMode_.enter( |
| 465 tileRect, |
| 466 function() { |
| 467 // Animate to zoomed position. |
| 468 mosaic.transform(tileRect, this.slideMode_.getSelectedImageRect()); |
| 469 mosaic.hide(); |
| 470 }.bind(this), |
| 471 onModeChanged); |
| 472 this.bottomToolbar_.hidden = false; |
| 473 } |
| 503 }; | 474 }; |
| 504 | 475 |
| 505 /** | 476 /** |
| 506 * Deletes the selected items. | 477 * Deletes the selected items. |
| 507 * @private | 478 * @private |
| 508 */ | 479 */ |
| 509 Gallery.prototype.delete_ = function() { | 480 Gallery.prototype.delete_ = function() { |
| 510 this.onUserAction_(); | 481 this.onUserAction_(); |
| 511 | 482 |
| 512 // Clone the sorted selected indexes array. | 483 // Clone the sorted selected indexes array. |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 this.slideMode_.updateThumbnails(); | 812 this.slideMode_.updateThumbnails(); |
| 842 | 813 |
| 843 if (this.mosaicMode_) { | 814 if (this.mosaicMode_) { |
| 844 var mosaic = this.mosaicMode_.getMosaic(); | 815 var mosaic = this.mosaicMode_.getMosaic(); |
| 845 if (mosaic.isInitialized()) | 816 if (mosaic.isInitialized()) |
| 846 mosaic.reload(); | 817 mosaic.reload(); |
| 847 } | 818 } |
| 848 }; | 819 }; |
| 849 | 820 |
| 850 /** | 821 /** |
| 822 * Updates buttons. |
| 823 * @private |
| 824 */ |
| 825 Gallery.prototype.updateButtons_ = function() { |
| 826 if (this.modeButton_) { |
| 827 var oppositeMode = |
| 828 this.currentMode_ === this.slideMode_ ? this.mosaicMode_ : |
| 829 this.slideMode_; |
| 830 this.modeButton_.title = str(oppositeMode.getTitle()); |
| 831 } |
| 832 }; |
| 833 |
| 834 /** |
| 851 * Enters the debug mode. | 835 * Enters the debug mode. |
| 852 */ | 836 */ |
| 853 Gallery.prototype.debugMe = function() { | 837 Gallery.prototype.debugMe = function() { |
| 854 this.mosaicMode_.debugMe(); | 838 this.mosaicMode_.debugMe(); |
| 855 }; | 839 }; |
| 856 | 840 |
| 857 /** | 841 /** |
| 858 * Singleton gallery. | 842 * Singleton gallery. |
| 859 * @type {Gallery} | 843 * @type {Gallery} |
| 860 */ | 844 */ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 initializePromise.then(reload); | 892 initializePromise.then(reload); |
| 909 | 893 |
| 910 /** | 894 /** |
| 911 * Enteres the debug mode. | 895 * Enteres the debug mode. |
| 912 */ | 896 */ |
| 913 window.debugMe = function() { | 897 window.debugMe = function() { |
| 914 initializePromise.then(function() { | 898 initializePromise.then(function() { |
| 915 gallery.debugMe(); | 899 gallery.debugMe(); |
| 916 }); | 900 }); |
| 917 }; | 901 }; |
| OLD | NEW |