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

Side by Side Diff: ui/file_manager/gallery/js/gallery.js

Issue 1142303007: Gallery: Replace buttons in top toolbar with paper-button and new icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix integration tests. Created 5 years, 6 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
OLDNEW
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
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');
89 this.topToolbar_ = queryRequiredElement(document, '#top-toolbar'); 88 this.topToolbar_ = queryRequiredElement(document, '#top-toolbar');
90 this.bottomToolbar_ = queryRequiredElement(document, '#bottom-toolbar'); 89 this.bottomToolbar_ = queryRequiredElement(document, '#bottom-toolbar');
91 90
92 this.filenameSpacer_ = queryRequiredElement(this.topToolbar_, 91 this.filenameSpacer_ = queryRequiredElement(this.topToolbar_,
93 '.filename-spacer'); 92 '.filename-spacer');
94 this.filenameEdit_ = util.createChild(this.filenameSpacer_, 93 this.filenameEdit_ = util.createChild(this.filenameSpacer_,
95 'namebox', 'input'); 94 'namebox', 'input');
96 95
97 this.filenameEdit_.setAttribute('type', 'text'); 96 this.filenameEdit_.setAttribute('type', 'text');
98 this.filenameEdit_.addEventListener('blur', 97 this.filenameEdit_.addEventListener('blur',
99 this.onFilenameEditBlur_.bind(this)); 98 this.onFilenameEditBlur_.bind(this));
100 99
101 this.filenameEdit_.addEventListener('focus', 100 this.filenameEdit_.addEventListener('focus',
102 this.onFilenameFocus_.bind(this)); 101 this.onFilenameFocus_.bind(this));
103 102
104 this.filenameEdit_.addEventListener('keydown', 103 this.filenameEdit_.addEventListener('keydown',
105 this.onFilenameEditKeydown_.bind(this)); 104 this.onFilenameEditKeydown_.bind(this));
106 105
107 var buttonSpacer = queryRequiredElement(this.topToolbar_, '.button-spacer'); 106 var buttonSpacer = queryRequiredElement(this.topToolbar_, '.button-spacer');
108 107
109 this.prompt_ = new ImageEditor.Prompt(this.container_, strf); 108 this.prompt_ = new ImageEditor.Prompt(this.container_, strf);
110 109
111 this.errorBanner_ = new ErrorBanner(this.container_); 110 this.errorBanner_ = new ErrorBanner(this.container_);
112 111
113 this.modeButton_ = queryRequiredElement(this.topToolbar_, 'button.mode'); 112 var slideModeButton = queryRequiredElement(
114 this.modeButton_.addEventListener('click', 113 this.topToolbar_, '.button.slide-mode');
115 this.toggleMode_.bind(this, undefined)); 114 slideModeButton.addEventListener(
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));
116 121
117 this.mosaicMode_ = new MosaicMode(content, 122 this.mosaicMode_ = new MosaicMode(content,
118 this.errorBanner_, 123 this.errorBanner_,
119 this.dataModel_, 124 this.dataModel_,
120 this.selectionModel_, 125 this.selectionModel_,
121 this.volumeManager_, 126 this.volumeManager_,
122 this.toggleMode_.bind(this, undefined)); 127 this.toggleMode_.bind(this, undefined));
123 128
124 this.slideMode_ = new SlideMode(this.container_, 129 this.slideMode_ = new SlideMode(this.container_,
125 content, 130 content,
126 this.topToolbar_, 131 this.topToolbar_,
127 this.bottomToolbar_, 132 this.bottomToolbar_,
128 this.prompt_, 133 this.prompt_,
129 this.errorBanner_, 134 this.errorBanner_,
130 this.dataModel_, 135 this.dataModel_,
131 this.selectionModel_, 136 this.selectionModel_,
132 this.metadataModel_, 137 this.metadataModel_,
133 this.thumbnailModel_, 138 this.thumbnailModel_,
134 this.context_, 139 this.context_,
135 this.volumeManager_, 140 this.volumeManager_,
136 this.toggleMode_.bind(this), 141 this.toggleMode_.bind(this),
137 str); 142 str);
138 143
139 this.slideMode_.addEventListener('image-displayed', function() { 144 this.slideMode_.addEventListener('image-displayed', function() {
140 cr.dispatchSimpleEvent(this, 'image-displayed'); 145 cr.dispatchSimpleEvent(this, 'image-displayed');
141 }.bind(this)); 146 }.bind(this));
142 147
143 this.deleteButton_ = this.initToolbarButton_('delete', 'GALLERY_DELETE'); 148 this.deleteButton_ = queryRequiredElement(this.topToolbar_, '.button.delete');
144 this.deleteButton_.addEventListener('click', this.delete_.bind(this)); 149 this.deleteButton_.addEventListener('click', this.delete_.bind(this));
145 150
146 this.shareButton_ = this.initToolbarButton_('share', 'GALLERY_SHARE'); 151 this.shareButton_ = queryRequiredElement(this.topToolbar_, '.button.share');
147 this.shareButton_.addEventListener( 152 this.shareButton_.addEventListener(
148 'click', this.onShareButtonClick_.bind(this)); 153 'click', this.onShareButtonClick_.bind(this));
149 154
150 this.dataModel_.addEventListener('splice', this.onSplice_.bind(this)); 155 this.dataModel_.addEventListener('splice', this.onSplice_.bind(this));
151 this.dataModel_.addEventListener('content', this.onContentChange_.bind(this)); 156 this.dataModel_.addEventListener('content', this.onContentChange_.bind(this));
152 157
153 this.selectionModel_.addEventListener('change', this.onSelection_.bind(this)); 158 this.selectionModel_.addEventListener('change', this.onSelection_.bind(this));
154 this.slideMode_.addEventListener('useraction', this.onUserAction_.bind(this)); 159 this.slideMode_.addEventListener('useraction', this.onUserAction_.bind(this));
155 160
156 this.shareDialog_ = new ShareDialog(this.container_); 161 this.shareDialog_ = new ShareDialog(this.container_);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 * Unloads the Gallery. 230 * Unloads the Gallery.
226 * @private 231 * @private
227 */ 232 */
228 Gallery.prototype.onPageHide_ = function() { 233 Gallery.prototype.onPageHide_ = function() {
229 this.volumeManager_.removeEventListener( 234 this.volumeManager_.removeEventListener(
230 'externally-unmounted', this.onExternallyUnmountedBound_); 235 'externally-unmounted', this.onExternallyUnmountedBound_);
231 this.volumeManager_.dispose(); 236 this.volumeManager_.dispose();
232 }; 237 };
233 238
234 /** 239 /**
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 /**
249 * Loads the content. 240 * Loads the content.
250 * 241 *
251 * @param {!Array<!Entry>} selectedEntries Array of selected entries. 242 * @param {!Array<!Entry>} selectedEntries Array of selected entries.
252 */ 243 */
253 Gallery.prototype.load = function(selectedEntries) { 244 Gallery.prototype.load = function(selectedEntries) {
254 GalleryUtil.createEntrySet(selectedEntries).then(function(allEntries) { 245 GalleryUtil.createEntrySet(selectedEntries).then(function(allEntries) {
255 this.loadInternal_(allEntries, selectedEntries); 246 this.loadInternal_(allEntries, selectedEntries);
256 }.bind(this)); 247 }.bind(this));
257 }; 248 };
258 249
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 */ 391 */
401 Gallery.prototype.onUserAction_ = function() { 392 Gallery.prototype.onUserAction_ = function() {
402 // Show the toolbar and hide it after the default timeout. 393 // Show the toolbar and hide it after the default timeout.
403 this.inactivityWatcher_.kick(); 394 this.inactivityWatcher_.kick();
404 }; 395 };
405 396
406 /** 397 /**
407 * Sets the current mode, update the UI. 398 * Sets the current mode, update the UI.
408 * @param {!(SlideMode|MosaicMode)} mode Current mode. 399 * @param {!(SlideMode|MosaicMode)} mode Current mode.
409 * @private 400 * @private
401 *
402 * TODO(yawano): Since this method is confusing with changeCurrentMode_. Rename
403 * or remove this method.
410 */ 404 */
411 Gallery.prototype.setCurrentMode_ = function(mode) { 405 Gallery.prototype.setCurrentMode_ = function(mode) {
412 if (mode !== this.slideMode_ && mode !== this.mosaicMode_) 406 if (mode !== this.slideMode_ && mode !== this.mosaicMode_)
413 console.error('Invalid Gallery mode'); 407 console.error('Invalid Gallery mode');
414 408
415 this.currentMode_ = mode; 409 this.currentMode_ = mode;
416 this.container_.setAttribute('mode', this.currentMode_.getName()); 410 this.container_.setAttribute('mode', this.currentMode_.getName());
417 this.updateSelectionAndState_(); 411 this.updateSelectionAndState_();
418 this.updateButtons_(); 412 };
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));
419 }; 487 };
420 488
421 /** 489 /**
422 * Mode toggle event handler. 490 * Mode toggle event handler.
423 * @param {function()=} opt_callback Callback. 491 * @param {function()=} opt_callback Callback.
424 * @param {Event=} opt_event Event that caused this call. 492 * @param {Event=} opt_event Event that caused this call.
425 * @private 493 * @private
426 */ 494 */
427 Gallery.prototype.toggleMode_ = function(opt_callback, opt_event) { 495 Gallery.prototype.toggleMode_ = function(opt_callback, opt_event) {
428 if (!this.modeButton_) 496 var targetMode = this.currentMode_ === this.slideMode_ ?
429 return; 497 this.mosaicMode_ : this.slideMode_;
430 498
431 if (this.changingMode_) // Do not re-enter while changing the mode. 499 this.changeCurrentMode_(targetMode, opt_event).then(function() {
432 return; 500 if (opt_callback)
433 501 opt_callback();
434 if (opt_event) 502 });
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 }
474 }; 503 };
475 504
476 /** 505 /**
477 * Deletes the selected items. 506 * Deletes the selected items.
478 * @private 507 * @private
479 */ 508 */
480 Gallery.prototype.delete_ = function() { 509 Gallery.prototype.delete_ = function() {
481 this.onUserAction_(); 510 this.onUserAction_();
482 511
483 // Clone the sorted selected indexes array. 512 // Clone the sorted selected indexes array.
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 this.slideMode_.updateThumbnails(); 841 this.slideMode_.updateThumbnails();
813 842
814 if (this.mosaicMode_) { 843 if (this.mosaicMode_) {
815 var mosaic = this.mosaicMode_.getMosaic(); 844 var mosaic = this.mosaicMode_.getMosaic();
816 if (mosaic.isInitialized()) 845 if (mosaic.isInitialized())
817 mosaic.reload(); 846 mosaic.reload();
818 } 847 }
819 }; 848 };
820 849
821 /** 850 /**
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 /**
835 * Enters the debug mode. 851 * Enters the debug mode.
836 */ 852 */
837 Gallery.prototype.debugMe = function() { 853 Gallery.prototype.debugMe = function() {
838 this.mosaicMode_.debugMe(); 854 this.mosaicMode_.debugMe();
839 }; 855 };
840 856
841 /** 857 /**
842 * Singleton gallery. 858 * Singleton gallery.
843 * @type {Gallery} 859 * @type {Gallery}
844 */ 860 */
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 initializePromise.then(reload); 908 initializePromise.then(reload);
893 909
894 /** 910 /**
895 * Enteres the debug mode. 911 * Enteres the debug mode.
896 */ 912 */
897 window.debugMe = function() { 913 window.debugMe = function() {
898 initializePromise.then(function() { 914 initializePromise.then(function() {
899 gallery.debugMe(); 915 gallery.debugMe();
900 }); 916 });
901 }; 917 };
OLDNEW
« no previous file with comments | « ui/file_manager/gallery/images/200/slideshow.png ('k') | ui/file_manager/gallery/js/slide_mode.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698