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 * Slide mode displays a single image and has a set of controls to navigate | 8 * Slide mode displays a single image and has a set of controls to navigate |
9 * between the images and to edit an image. | 9 * between the images and to edit an image. |
10 * | 10 * |
(...skipping 19 matching lines...) Expand all Loading... |
30 this.prompt_ = prompt; | 30 this.prompt_ = prompt; |
31 this.dataModel_ = dataModel; | 31 this.dataModel_ = dataModel; |
32 this.selectionModel_ = selectionModel; | 32 this.selectionModel_ = selectionModel; |
33 this.context_ = context; | 33 this.context_ = context; |
34 this.metadataCache_ = context.metadataCache; | 34 this.metadataCache_ = context.metadataCache; |
35 this.toggleMode_ = toggleMode; | 35 this.toggleMode_ = toggleMode; |
36 this.displayStringFunction_ = displayStringFunction; | 36 this.displayStringFunction_ = displayStringFunction; |
37 | 37 |
38 this.onSelectionBound_ = this.onSelection_.bind(this); | 38 this.onSelectionBound_ = this.onSelection_.bind(this); |
39 this.onSpliceBound_ = this.onSplice_.bind(this); | 39 this.onSpliceBound_ = this.onSplice_.bind(this); |
40 this.onContentBound_ = this.onContentChange_.bind(this); | |
41 | 40 |
42 // Unique numeric key, incremented per each load attempt used to discard | 41 // Unique numeric key, incremented per each load attempt used to discard |
43 // old attempts. This can happen especially when changing selection fast or | 42 // old attempts. This can happen especially when changing selection fast or |
44 // Internet connection is slow. | 43 // Internet connection is slow. |
45 this.currentUniqueKey_ = 0; | 44 this.currentUniqueKey_ = 0; |
46 | 45 |
47 this.initListeners_(); | 46 this.initListeners_(); |
48 this.initDom_(); | 47 this.initDom_(); |
49 } | 48 } |
50 | 49 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 SlideMode.prototype.enter = function( | 248 SlideMode.prototype.enter = function( |
250 zoomFromRect, displayCallback, loadCallback) { | 249 zoomFromRect, displayCallback, loadCallback) { |
251 this.sequenceDirection_ = 0; | 250 this.sequenceDirection_ = 0; |
252 this.sequenceLength_ = 0; | 251 this.sequenceLength_ = 0; |
253 | 252 |
254 var loadDone = function(loadType, delay) { | 253 var loadDone = function(loadType, delay) { |
255 this.active_ = true; | 254 this.active_ = true; |
256 | 255 |
257 this.selectionModel_.addEventListener('change', this.onSelectionBound_); | 256 this.selectionModel_.addEventListener('change', this.onSelectionBound_); |
258 this.dataModel_.addEventListener('splice', this.onSpliceBound_); | 257 this.dataModel_.addEventListener('splice', this.onSpliceBound_); |
259 this.dataModel_.addEventListener('content', this.onContentBound_); | |
260 | 258 |
261 ImageUtil.setAttribute(this.arrowBox_, 'active', this.getItemCount_() > 1); | 259 ImageUtil.setAttribute(this.arrowBox_, 'active', this.getItemCount_() > 1); |
262 this.ribbon_.enable(); | 260 this.ribbon_.enable(); |
263 | 261 |
264 // Wait 1000ms after the animation is done, then prefetch the next image. | 262 // Wait 1000ms after the animation is done, then prefetch the next image. |
265 this.requestPrefetch(1, delay + 1000); | 263 this.requestPrefetch(1, delay + 1000); |
266 | 264 |
267 if (loadCallback) loadCallback(); | 265 if (loadCallback) loadCallback(); |
268 }.bind(this); | 266 }.bind(this); |
269 | 267 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 }); | 305 }); |
308 }.bind(this)).then(function(delay) { | 306 }.bind(this)).then(function(delay) { |
309 // Turn the mode active. | 307 // Turn the mode active. |
310 this.active_ = true; | 308 this.active_ = true; |
311 ImageUtil.setAttribute(this.arrowBox_, 'active', this.getItemCount_() > 1); | 309 ImageUtil.setAttribute(this.arrowBox_, 'active', this.getItemCount_() > 1); |
312 this.ribbon_.enable(); | 310 this.ribbon_.enable(); |
313 | 311 |
314 // Register handlers. | 312 // Register handlers. |
315 this.selectionModel_.addEventListener('change', this.onSelectionBound_); | 313 this.selectionModel_.addEventListener('change', this.onSelectionBound_); |
316 this.dataModel_.addEventListener('splice', this.onSpliceBound_); | 314 this.dataModel_.addEventListener('splice', this.onSpliceBound_); |
317 this.dataModel_.addEventListener('content', this.onContentBound_); | |
318 this.touchHandlers_.enabled = true; | 315 this.touchHandlers_.enabled = true; |
319 | 316 |
320 // Wait 1000ms after the animation is done, then prefetch the next image. | 317 // Wait 1000ms after the animation is done, then prefetch the next image. |
321 this.requestPrefetch(1, delay + 1000); | 318 this.requestPrefetch(1, delay + 1000); |
322 | 319 |
323 // Call load callback. | 320 // Call load callback. |
324 if (loadCallback) | 321 if (loadCallback) |
325 loadCallback(); | 322 loadCallback(); |
326 }.bind(this)).catch(function(error) { | 323 }.bind(this)).catch(function(error) { |
327 console.error(error.stack, error); | 324 console.error(error.stack, error); |
328 }); | 325 }); |
329 }; | 326 }; |
330 | 327 |
331 /** | 328 /** |
332 * Leave the mode. | 329 * Leave the mode. |
333 * @param {Rect} zoomToRect Rectangle for zoom effect. | 330 * @param {Rect} zoomToRect Rectangle for zoom effect. |
334 * @param {function} callback Called when the image is committed and | 331 * @param {function} callback Called when the image is committed and |
335 * the zoom-out animation has started. | 332 * the zoom-out animation has started. |
336 */ | 333 */ |
337 SlideMode.prototype.leave = function(zoomToRect, callback) { | 334 SlideMode.prototype.leave = function(zoomToRect, callback) { |
338 var commitDone = function() { | 335 var commitDone = function() { |
339 this.stopEditing_(); | 336 this.stopEditing_(); |
340 this.stopSlideshow_(); | 337 this.stopSlideshow_(); |
341 ImageUtil.setAttribute(this.arrowBox_, 'active', false); | 338 ImageUtil.setAttribute(this.arrowBox_, 'active', false); |
342 this.selectionModel_.removeEventListener( | 339 this.selectionModel_.removeEventListener( |
343 'change', this.onSelectionBound_); | 340 'change', this.onSelectionBound_); |
344 this.dataModel_.removeEventListener('splice', this.onSpliceBound_); | 341 this.dataModel_.removeEventListener('splice', this.onSpliceBound_); |
345 this.dataModel_.removeEventListener('content', this.onContentBound_); | |
346 this.ribbon_.disable(); | 342 this.ribbon_.disable(); |
347 this.active_ = false; | 343 this.active_ = false; |
348 if (this.savedSelection_) | 344 if (this.savedSelection_) |
349 this.selectionModel_.selectedIndexes = this.savedSelection_; | 345 this.selectionModel_.selectedIndexes = this.savedSelection_; |
350 this.unloadImage_(zoomToRect); | 346 this.unloadImage_(zoomToRect); |
351 callback(); | 347 callback(); |
352 }.bind(this); | 348 }.bind(this); |
353 | 349 |
354 this.viewport_.resetView(); | 350 this.viewport_.resetView(); |
355 if (this.getItemCount_() === 0) { | 351 if (this.getItemCount_() === 0) { |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 ImageUtil.metrics.recordUserAction(ImageUtil.getMetricName('Edit')); | 985 ImageUtil.metrics.recordUserAction(ImageUtil.getMetricName('Edit')); |
990 | 986 |
991 callback(); | 987 callback(); |
992 cr.dispatchSimpleEvent(this, 'image-saved'); | 988 cr.dispatchSimpleEvent(this, 'image-saved'); |
993 }.bind(this)).catch(function(error) { | 989 }.bind(this)).catch(function(error) { |
994 console.error(error.stack || error); | 990 console.error(error.stack || error); |
995 }); | 991 }); |
996 }; | 992 }; |
997 | 993 |
998 /** | 994 /** |
999 * Update caches when the selected item has been renamed. | |
1000 * @param {Event} event Event. | |
1001 * @private | |
1002 */ | |
1003 SlideMode.prototype.onContentChange_ = function(event) { | |
1004 var newEntry = event.item.getEntry(); | |
1005 if (!util.isSameEntry(newEntry, event.oldEntry)) | |
1006 this.imageView_.changeEntry(newEntry); | |
1007 }; | |
1008 | |
1009 /** | |
1010 * Flash 'Saved' label briefly to indicate that the image has been saved. | 995 * Flash 'Saved' label briefly to indicate that the image has been saved. |
1011 * @private | 996 * @private |
1012 */ | 997 */ |
1013 SlideMode.prototype.flashSavedLabel_ = function() { | 998 SlideMode.prototype.flashSavedLabel_ = function() { |
1014 var setLabelHighlighted = | 999 var setLabelHighlighted = |
1015 ImageUtil.setAttribute.bind(null, this.savedLabel_, 'highlighted'); | 1000 ImageUtil.setAttribute.bind(null, this.savedLabel_, 'highlighted'); |
1016 setTimeout(setLabelHighlighted.bind(null, true), 0); | 1001 setTimeout(setLabelHighlighted.bind(null, true), 0); |
1017 setTimeout(setLabelHighlighted.bind(null, false), 300); | 1002 setTimeout(setLabelHighlighted.bind(null, false), 300); |
1018 }; | 1003 }; |
1019 | 1004 |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1551 else | 1536 else |
1552 viewport.setRotation(this.gestureStartRotation_); | 1537 viewport.setRotation(this.gestureStartRotation_); |
1553 this.slideMode_.applyViewportChange(); | 1538 this.slideMode_.applyViewportChange(); |
1554 break; | 1539 break; |
1555 } | 1540 } |
1556 | 1541 |
1557 // Update the last event. | 1542 // Update the last event. |
1558 this.lastEvent_ = event; | 1543 this.lastEvent_ = event; |
1559 this.lastZoom_ = viewport.getZoom(); | 1544 this.lastZoom_ = viewport.getZoom(); |
1560 }; | 1545 }; |
OLD | NEW |