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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 util.addPageLoadHandler(function() { | 7 util.addPageLoadHandler(function() { |
8 if (!location.hash) | 8 if (!location.hash) |
9 return; | 9 return; |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... | |
28 * @param {boolean=} opt_exiting True if the app is exiting. | 28 * @param {boolean=} opt_exiting True if the app is exiting. |
29 */ | 29 */ |
30 function unload(opt_exiting) { Gallery.instance.onUnload(opt_exiting) } | 30 function unload(opt_exiting) { Gallery.instance.onUnload(opt_exiting) } |
31 | 31 |
32 /** | 32 /** |
33 * Gallery for viewing and editing image files. | 33 * Gallery for viewing and editing image files. |
34 * | 34 * |
35 * @param {Object} context Object containing the following: | 35 * @param {Object} context Object containing the following: |
36 * {function(string)} onNameChange Called every time a selected | 36 * {function(string)} onNameChange Called every time a selected |
37 * item name changes (on rename and on selection change). | 37 * item name changes (on rename and on selection change). |
38 * {function} onBack | |
yoshiki
2013/05/07 02:21:50
s/function/function(string)/
mtomasz
2013/05/07 03:52:02
Done.
| |
38 * {function} onClose | 39 * {function} onClose |
yoshiki
2013/05/07 02:21:50
s/function/function()/
mtomasz
2013/05/07 03:52:02
Done.
| |
40 * {function} onMaximize | |
yoshiki
2013/05/07 02:21:50
ditto
mtomasz
2013/05/07 03:52:02
Done.
| |
39 * {MetadataCache} metadataCache | 41 * {MetadataCache} metadataCache |
40 * {Array.<Object>} shareActions | 42 * {Array.<Object>} shareActions |
41 * {string} readonlyDirName Directory name for readonly warning or null. | 43 * {string} readonlyDirName Directory name for readonly warning or null. |
42 * {DirEntry} saveDirEntry Directory to save to. | 44 * {DirEntry} saveDirEntry Directory to save to. |
43 * {function(string)} displayStringFunction. | 45 * {function(string)} displayStringFunction. |
44 * @class | 46 * @class |
45 * @constructor | 47 * @constructor |
46 */ | 48 */ |
47 function Gallery(context) { | 49 function Gallery(context) { |
48 this.container_ = document.querySelector('.gallery'); | 50 this.container_ = document.querySelector('.gallery'); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 function() { | 103 function() { |
102 // Try to scan the parent directory. | 104 // Try to scan the parent directory. |
103 var pathParts = path.split('/'); | 105 var pathParts = path.split('/'); |
104 pathParts.pop(); | 106 pathParts.pop(); |
105 var parentPath = pathParts.join('/'); | 107 var parentPath = pathParts.join('/'); |
106 filesystem.root.getDirectory(parentPath, {create: false}, | 108 filesystem.root.getDirectory(parentPath, {create: false}, |
107 scanDirectory, open /* no data, just display an error */); | 109 scanDirectory, open /* no data, just display an error */); |
108 }); | 110 }); |
109 }); | 111 }); |
110 | 112 |
111 function scanDirectory(dirEntry) { | 113 var scanDirectory = function(dirEntry) { |
112 currentDir = dirEntry; | 114 currentDir = dirEntry; |
113 util.forEachDirEntry(currentDir, function(entry) { | 115 util.forEachDirEntry(currentDir, function(entry) { |
114 if (entry == null) { | 116 if (entry == null) { |
115 open(); | 117 open(); |
116 } else if (FileType.isImageOrVideo(entry)) { | 118 } else if (FileType.isImageOrVideo(entry)) { |
117 var url = entry.toURL(); | 119 var url = entry.toURL(); |
118 urls.push(url); | 120 urls.push(url); |
119 if (entry.fullPath == path) | 121 if (entry.fullPath == path) |
120 selectedUrls = [url]; | 122 selectedUrls = [url]; |
121 } | 123 } |
122 }); | 124 }); |
123 } | 125 }; |
124 | 126 |
125 function onClose() { | 127 var onBack = function() { |
yoshiki
2013/05/07 02:21:50
I should think that a 'selectedUrls' parameter is
mtomasz
2013/05/07 03:52:02
We get the selected path from the current location
| |
126 // Exiting to the Files app seems arbitrary. Consider closing the tab. | 128 // Exiting to the Files app seems arbitrary. Consider closing the tab. |
127 document.location = 'main.html?' + | 129 document.location = 'main.html?' + |
yoshiki
2013/05/07 02:21:50
Shouldn't we use 'main_new_ui.html' in new ui?
mtomasz
2013/05/07 03:52:02
This seem not to be used in Files.app V2. I've add
| |
128 JSON.stringify({defaultPath: document.location.hash.substr(1)}); | 130 JSON.stringify({defaultPath: document.location.hash.substr(1)}); |
129 } | 131 }; |
132 | |
133 var onClose = function() { | |
134 window.close(); | |
135 }; | |
136 | |
137 var onMaximize = function() { | |
138 var appWindow = chrome.app.window.current(); | |
139 if (appWindow.isMaximized()) | |
140 appWindow.restore(); | |
141 else | |
142 appWindow.maximize(); | |
143 }; | |
130 | 144 |
131 function open() { | 145 function open() { |
132 urls.sort(); | 146 urls.sort(); |
133 Gallery.getFileBrowserPrivate().getStrings(function(strings) { | 147 Gallery.getFileBrowserPrivate().getStrings(function(strings) { |
134 loadTimeData.data = strings; | 148 loadTimeData.data = strings; |
135 var context = { | 149 var context = { |
136 readonlyDirName: null, | 150 readonlyDirName: null, |
137 curDirEntry: currentDir, | 151 curDirEntry: currentDir, |
138 saveDirEntry: null, | 152 saveDirEntry: null, |
139 metadataCache: MetadataCache.createFull(), | 153 metadataCache: MetadataCache.createFull(), |
140 pageState: pageState, | 154 pageState: pageState, |
155 onBack: onBack, | |
141 onClose: onClose, | 156 onClose: onClose, |
157 onMaximize: onMaximize, | |
142 displayStringFunction: strf | 158 displayStringFunction: strf |
143 }; | 159 }; |
144 Gallery.open(context, urls, selectedUrls); | 160 Gallery.open(context, urls, selectedUrls); |
145 if (opt_callback) opt_callback(); | 161 if (opt_callback) opt_callback(); |
146 }); | 162 }); |
147 } | 163 } |
148 }; | 164 }; |
149 | 165 |
150 /** | 166 /** |
151 * Tools fade-out timeout im milliseconds. | 167 * Tools fade-out timeout im milliseconds. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 | 224 |
209 /** | 225 /** |
210 * Closes gallery when a volume containing the selected item is unmounted. | 226 * Closes gallery when a volume containing the selected item is unmounted. |
211 * @param {Event} event The unmount event. | 227 * @param {Event} event The unmount event. |
212 * @private | 228 * @private |
213 */ | 229 */ |
214 Gallery.prototype.onExternallyUnmounted_ = function(event) { | 230 Gallery.prototype.onExternallyUnmounted_ = function(event) { |
215 if (!this.selectedItemFilesystemPath_) | 231 if (!this.selectedItemFilesystemPath_) |
216 return; | 232 return; |
217 if (this.selectedItemFilesystemPath_.indexOf(event.mountPath) == 0) | 233 if (this.selectedItemFilesystemPath_.indexOf(event.mountPath) == 0) |
218 this.onClose_(); | 234 this.onBack_(); |
219 }; | 235 }; |
220 | 236 |
221 /** | 237 /** |
222 * Beforeunload handler. | 238 * Beforeunload handler. |
223 * @return {string?} User-visible message on null if it is OK to close. | 239 * @return {string?} User-visible message on null if it is OK to close. |
224 */ | 240 */ |
225 Gallery.prototype.onBeforeUnload = function() { | 241 Gallery.prototype.onBeforeUnload = function() { |
226 return this.slideMode_.onBeforeUnload(); | 242 return this.slideMode_.onBeforeUnload(); |
227 }; | 243 }; |
228 | 244 |
229 /** | 245 /** |
230 * Unload the Gallery. | 246 * Unload the Gallery. |
231 * @param {boolean} exiting True if the app is exiting. | 247 * @param {boolean} exiting True if the app is exiting. |
232 */ | 248 */ |
233 Gallery.prototype.onUnload = function(exiting) { | 249 Gallery.prototype.onUnload = function(exiting) { |
234 if (!this.context_.searchResults) { | 250 if (!this.context_.searchResults) { |
235 this.metadataCache_.removeObserver(this.thumbnailObserverId_); | 251 this.metadataCache_.removeObserver(this.thumbnailObserverId_); |
236 } | 252 } |
237 this.slideMode_.onUnload(exiting); | 253 this.slideMode_.onUnload(exiting); |
238 }; | 254 }; |
239 | 255 |
240 /** | 256 /** |
241 * Initializes DOM UI | 257 * Initializes DOM UI |
242 * @private | 258 * @private |
243 */ | 259 */ |
244 Gallery.prototype.initDom_ = function() { | 260 Gallery.prototype.initDom_ = function() { |
245 var content = util.createChild(this.container_, 'content'); | 261 var content = util.createChild(this.container_, 'content'); |
246 content.addEventListener('click', this.onContentClick_.bind(this)); | 262 content.addEventListener('click', this.onContentClick_.bind(this)); |
247 | 263 |
248 var closeButton = util.createChild(this.container_, 'close tool dimmable'); | |
249 util.createChild(closeButton); | |
250 closeButton.addEventListener('click', this.onClose_.bind(this)); | |
251 | |
252 this.header_ = util.createChild(this.container_, 'header tool dimmable'); | 264 this.header_ = util.createChild(this.container_, 'header tool dimmable'); |
253 this.toolbar_ = util.createChild(this.container_, 'toolbar tool dimmable'); | 265 this.toolbar_ = util.createChild(this.container_, 'toolbar tool dimmable'); |
254 | 266 |
267 var backButton = util.createChild(this.container_, | |
268 'back-button tool dimmable'); | |
269 util.createChild(backButton); | |
270 backButton.addEventListener('click', this.onBack_.bind(this)); | |
271 | |
272 if (util.platform.newUI()) { | |
273 var maximizeButton = util.createChild(this.header_, | |
274 'maximize-button tool dimmable', | |
275 'button'); | |
276 maximizeButton.addEventListener('click', this.onMaximize_.bind(this)); | |
277 | |
278 var closeButton = util.createChild(this.header_, | |
279 'close-button tool dimmable', | |
280 'button'); | |
281 closeButton.addEventListener('click', this.onClose_.bind(this)); | |
282 } | |
283 | |
255 this.filenameSpacer_ = util.createChild(this.toolbar_, 'filename-spacer'); | 284 this.filenameSpacer_ = util.createChild(this.toolbar_, 'filename-spacer'); |
256 | |
257 this.filenameEdit_ = util.createChild(this.filenameSpacer_, | 285 this.filenameEdit_ = util.createChild(this.filenameSpacer_, |
258 'namebox', 'input'); | 286 'namebox', 'input'); |
259 | 287 |
260 this.filenameEdit_.setAttribute('type', 'text'); | 288 this.filenameEdit_.setAttribute('type', 'text'); |
261 this.filenameEdit_.addEventListener('blur', | 289 this.filenameEdit_.addEventListener('blur', |
262 this.onFilenameEditBlur_.bind(this)); | 290 this.onFilenameEditBlur_.bind(this)); |
263 | 291 |
264 this.filenameEdit_.addEventListener('focus', | 292 this.filenameEdit_.addEventListener('focus', |
265 this.onFilenameFocus_.bind(this)); | 293 this.onFilenameFocus_.bind(this)); |
266 | 294 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 /* TODO: consider nice blow-up animation for the first image */ | 414 /* TODO: consider nice blow-up animation for the first image */ |
387 this.slideMode_.enter(null, function() { | 415 this.slideMode_.enter(null, function() { |
388 // Flash the toolbar briefly to show it is there. | 416 // Flash the toolbar briefly to show it is there. |
389 this.inactivityWatcher_.kick(Gallery.FIRST_FADE_TIMEOUT); | 417 this.inactivityWatcher_.kick(Gallery.FIRST_FADE_TIMEOUT); |
390 }.bind(this), | 418 }.bind(this), |
391 maybeLoadMosaic); | 419 maybeLoadMosaic); |
392 } | 420 } |
393 }; | 421 }; |
394 | 422 |
395 /** | 423 /** |
396 * Close the Gallery. | 424 * Close the Gallery and go to Files.app. |
397 * @private | 425 * @private |
398 */ | 426 */ |
399 Gallery.prototype.close_ = function() { | 427 Gallery.prototype.back_ = function() { |
400 if (util.isFullScreen()) { | 428 if (util.isFullScreen()) { |
401 util.toggleFullScreen(this.document_, | 429 util.toggleFullScreen(this.document_, |
402 false); // Leave the full screen mode. | 430 false); // Leave the full screen mode. |
403 } | 431 } |
404 this.context_.onClose(this.getSelectedUrls()); | 432 this.context_.onBack(this.getSelectedUrls()); |
405 }; | 433 }; |
406 | 434 |
407 /** | 435 /** |
408 * Handle user's 'Close' action (Escape or a click on the X icon). | 436 * Handle user's 'Back' action (Escape or a click on the X icon). |
437 * @private | |
438 */ | |
439 Gallery.prototype.onBack_ = function() { | |
440 this.executeWhenReady(this.back_.bind(this)); | |
441 }; | |
442 | |
443 /** | |
444 * Handle user's 'Close' action. | |
409 * @private | 445 * @private |
410 */ | 446 */ |
411 Gallery.prototype.onClose_ = function() { | 447 Gallery.prototype.onClose_ = function() { |
412 this.executeWhenReady(this.close_.bind(this)); | 448 this.executeWhenReady(this.context_.onClose); |
413 }; | 449 }; |
414 | 450 |
415 /** | 451 /** |
452 * Handle user's 'Maximize' action (Escape or a click on the X icon). | |
453 * @private | |
454 */ | |
455 Gallery.prototype.onMaximize_ = function() { | |
456 this.executeWhenReady(this.context_.onMaximize); | |
457 }; | |
458 | |
459 /** | |
416 * Execute a function when the editor is done with the modifications. | 460 * Execute a function when the editor is done with the modifications. |
417 * @param {function} callback Function to execute. | 461 * @param {function} callback Function to execute. |
418 */ | 462 */ |
419 Gallery.prototype.executeWhenReady = function(callback) { | 463 Gallery.prototype.executeWhenReady = function(callback) { |
420 this.currentMode_.executeWhenReady(callback); | 464 this.currentMode_.executeWhenReady(callback); |
421 }; | 465 }; |
422 | 466 |
423 /** | 467 /** |
424 * @return {Object} File browser private API. | 468 * @return {Object} File browser private API. |
425 */ | 469 */ |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 | 690 |
647 switch (util.getKeyModifiers(event) + event.keyIdentifier) { | 691 switch (util.getKeyModifiers(event) + event.keyIdentifier) { |
648 case 'U+0008': // Backspace. | 692 case 'U+0008': // Backspace. |
649 // The default handler would call history.back and close the Gallery. | 693 // The default handler would call history.back and close the Gallery. |
650 event.preventDefault(); | 694 event.preventDefault(); |
651 break; | 695 break; |
652 | 696 |
653 case 'U+001B': // Escape | 697 case 'U+001B': // Escape |
654 // Swallow Esc if it closed the Share menu, otherwise close the Gallery. | 698 // Swallow Esc if it closed the Share menu, otherwise close the Gallery. |
655 if (!wasSharing) | 699 if (!wasSharing) |
656 this.onClose_(); | 700 this.onBack_(); |
657 break; | 701 break; |
658 | 702 |
659 case 'U+004D': // 'm' switches between Slide and Mosaic mode. | 703 case 'U+004D': // 'm' switches between Slide and Mosaic mode. |
660 this.toggleMode_(null, event); | 704 this.toggleMode_(null, event); |
661 break; | 705 break; |
662 | 706 |
663 | 707 |
664 case 'U+0056': // 'v' | 708 case 'U+0056': // 'v' |
665 this.slideMode_.startSlideshow(SlideMode.SLIDESHOW_INTERVAL_FIRST, event); | 709 this.slideMode_.startSlideshow(SlideMode.SLIDESHOW_INTERVAL_FIRST, event); |
666 return; | 710 return; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 Gallery.prototype.updateThumbnails_ = function() { | 945 Gallery.prototype.updateThumbnails_ = function() { |
902 if (this.currentMode_ == this.slideMode_) | 946 if (this.currentMode_ == this.slideMode_) |
903 this.slideMode_.updateThumbnails(); | 947 this.slideMode_.updateThumbnails(); |
904 | 948 |
905 if (this.mosaicMode_) { | 949 if (this.mosaicMode_) { |
906 var mosaic = this.mosaicMode_.getMosaic(); | 950 var mosaic = this.mosaicMode_.getMosaic(); |
907 if (mosaic.isInitialized()) | 951 if (mosaic.isInitialized()) |
908 mosaic.reload(); | 952 mosaic.reload(); |
909 } | 953 } |
910 }; | 954 }; |
OLD | NEW |