| 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 * The overlay displaying the image. | 6 * The overlay displaying the image. |
| 7 * | 7 * |
| 8 * @param {!HTMLElement} container The container element. | 8 * @param {!HTMLElement} container The container element. |
| 9 * @param {!Viewport} viewport The viewport. | 9 * @param {!Viewport} viewport The viewport. |
| 10 * @param {!MetadataModel} metadataModel | 10 * @param {!MetadataModel} metadataModel |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 * @param {!ImageView.Effect} effect | 145 * @param {!ImageView.Effect} effect |
| 146 * @return {ImageView.LoadTarget} Load target. | 146 * @return {ImageView.LoadTarget} Load target. |
| 147 */ | 147 */ |
| 148 ImageView.getLoadTarget = function(item, effect) { | 148 ImageView.getLoadTarget = function(item, effect) { |
| 149 if (item.contentImage) | 149 if (item.contentImage) |
| 150 return ImageView.LoadTarget.CACHED_MAIN_IMAGE; | 150 return ImageView.LoadTarget.CACHED_MAIN_IMAGE; |
| 151 if (item.screenImage) | 151 if (item.screenImage) |
| 152 return ImageView.LoadTarget.CACHED_THUMBNAIL; | 152 return ImageView.LoadTarget.CACHED_THUMBNAIL; |
| 153 | 153 |
| 154 // Only show thumbnails if there is no effect or the effect is Slide. | 154 // Only show thumbnails if there is no effect or the effect is Slide. |
| 155 var metadata = item.getMetadata(); | |
| 156 var thumbnailLoader = new ThumbnailLoader( | 155 var thumbnailLoader = new ThumbnailLoader( |
| 157 item.getEntry(), ThumbnailLoader.LoaderType.CANVAS, item.getMetadata()); | 156 item.getEntry(), |
| 157 ThumbnailLoader.LoaderType.CANVAS, |
| 158 item.getThumbnailMetadataItem()); |
| 158 if ((effect instanceof ImageView.Effect.None || | 159 if ((effect instanceof ImageView.Effect.None || |
| 159 effect instanceof ImageView.Effect.Slide) && | 160 effect instanceof ImageView.Effect.Slide) && |
| 160 thumbnailLoader.getLoadTarget() !== | 161 thumbnailLoader.getLoadTarget() !== |
| 161 ThumbnailLoader.LoadTarget.FILE_ENTRY) { | 162 ThumbnailLoader.LoadTarget.FILE_ENTRY) { |
| 162 return ImageView.LoadTarget.THUMBNAIL; | 163 return ImageView.LoadTarget.THUMBNAIL; |
| 163 } | 164 } |
| 164 | 165 |
| 165 return ImageView.LoadTarget.MAIN_IMAGE; | 166 return ImageView.LoadTarget.MAIN_IMAGE; |
| 166 }; | 167 }; |
| 167 | 168 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 * @param {!Gallery.Item} item Gallery item to be loaded. | 344 * @param {!Gallery.Item} item Gallery item to be loaded. |
| 344 * @param {!ImageView.Effect} effect Transition effect object. | 345 * @param {!ImageView.Effect} effect Transition effect object. |
| 345 * @param {function()} displayCallback Called when the image is displayed | 346 * @param {function()} displayCallback Called when the image is displayed |
| 346 * (possibly as a preview). | 347 * (possibly as a preview). |
| 347 * @param {function(!ImageView.LoadType, number, *=)} loadCallback Called when | 348 * @param {function(!ImageView.LoadType, number, *=)} loadCallback Called when |
| 348 * the image is fully loaded. The first parameter is the load type. | 349 * the image is fully loaded. The first parameter is the load type. |
| 349 */ | 350 */ |
| 350 ImageView.prototype.load = | 351 ImageView.prototype.load = |
| 351 function(item, effect, displayCallback, loadCallback) { | 352 function(item, effect, displayCallback, loadCallback) { |
| 352 var entry = item.getEntry(); | 353 var entry = item.getEntry(); |
| 353 var metadata = item.getMetadata() || {}; | |
| 354 | 354 |
| 355 if (!(effect instanceof ImageView.Effect.None)) { | 355 if (!(effect instanceof ImageView.Effect.None)) { |
| 356 // Skip effects when reloading repeatedly very quickly. | 356 // Skip effects when reloading repeatedly very quickly. |
| 357 var time = Date.now(); | 357 var time = Date.now(); |
| 358 if (this.lastLoadTime_ && | 358 if (this.lastLoadTime_ && |
| 359 (time - this.lastLoadTime_) < ImageView.FAST_SCROLL_INTERVAL) { | 359 (time - this.lastLoadTime_) < ImageView.FAST_SCROLL_INTERVAL) { |
| 360 effect = new ImageView.Effect.None(); | 360 effect = new ImageView.Effect.None(); |
| 361 } | 361 } |
| 362 this.lastLoadTime_ = time; | 362 this.lastLoadTime_ = time; |
| 363 } | 363 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 382 displayThumbnail(ImageView.LoadType.CACHED_SCREEN, item.screenImage); | 382 displayThumbnail(ImageView.LoadType.CACHED_SCREEN, item.screenImage); |
| 383 // As far as the user can tell the image is loaded. We still need to load | 383 // As far as the user can tell the image is loaded. We still need to load |
| 384 // the full res image to make editing possible, but we can report now. | 384 // the full res image to make editing possible, but we can report now. |
| 385 ImageUtil.metrics.recordInterval(ImageUtil.getMetricName('DisplayTime')); | 385 ImageUtil.metrics.recordInterval(ImageUtil.getMetricName('DisplayTime')); |
| 386 break; | 386 break; |
| 387 | 387 |
| 388 case ImageView.LoadTarget.THUMBNAIL: | 388 case ImageView.LoadTarget.THUMBNAIL: |
| 389 var thumbnailLoader = new ThumbnailLoader( | 389 var thumbnailLoader = new ThumbnailLoader( |
| 390 entry, | 390 entry, |
| 391 ThumbnailLoader.LoaderType.CANVAS, | 391 ThumbnailLoader.LoaderType.CANVAS, |
| 392 metadata); | 392 item.getThumbnailMetadataItem()); |
| 393 thumbnailLoader.loadDetachedImage(function(success) { | 393 thumbnailLoader.loadDetachedImage(function(success) { |
| 394 displayThumbnail( | 394 displayThumbnail( |
| 395 ImageView.LoadType.IMAGE_FILE, | 395 ImageView.LoadType.IMAGE_FILE, |
| 396 success ? thumbnailLoader.getImage() : null); | 396 success ? thumbnailLoader.getImage() : null); |
| 397 }); | 397 }); |
| 398 break; | 398 break; |
| 399 | 399 |
| 400 case ImageView.LoadTarget.MAIN_IMAGE: | 400 case ImageView.LoadTarget.MAIN_IMAGE: |
| 401 loadMainImage( | 401 loadMainImage( |
| 402 ImageView.LoadType.IMAGE_FILE, | 402 ImageView.LoadType.IMAGE_FILE, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 } | 478 } |
| 479 | 479 |
| 480 if (loadType !== ImageView.LoadType.ERROR && | 480 if (loadType !== ImageView.LoadType.ERROR && |
| 481 loadType !== ImageView.LoadType.CACHED_SCREEN) { | 481 loadType !== ImageView.LoadType.CACHED_SCREEN) { |
| 482 ImageUtil.metrics.recordInterval(ImageUtil.getMetricName('DisplayTime')); | 482 ImageUtil.metrics.recordInterval(ImageUtil.getMetricName('DisplayTime')); |
| 483 } | 483 } |
| 484 ImageUtil.metrics.recordEnum(ImageUtil.getMetricName('LoadMode'), | 484 ImageUtil.metrics.recordEnum(ImageUtil.getMetricName('LoadMode'), |
| 485 loadType, Object.keys(ImageView.LoadType).length); | 485 loadType, Object.keys(ImageView.LoadType).length); |
| 486 | 486 |
| 487 if (loadType === ImageView.LoadType.ERROR && | 487 if (loadType === ImageView.LoadType.ERROR && |
| 488 !navigator.onLine && !metadata.external.present) { | 488 !navigator.onLine && !item.getMetadataItem().present) { |
| 489 loadType = ImageView.LoadType.OFFLINE; | 489 loadType = ImageView.LoadType.OFFLINE; |
| 490 } | 490 } |
| 491 if (loadCallback) loadCallback(loadType, animationDuration, opt_error); | 491 if (loadCallback) loadCallback(loadType, animationDuration, opt_error); |
| 492 } | 492 } |
| 493 }; | 493 }; |
| 494 | 494 |
| 495 /** | 495 /** |
| 496 * Prefetches an image. | 496 * Prefetches an image. |
| 497 * @param {!Gallery.Item} item The image item. | 497 * @param {!Gallery.Item} item The image item. |
| 498 * @param {number=} opt_delay Image load delay in ms. | 498 * @param {number=} opt_delay Image load delay in ms. |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 }; | 967 }; |
| 968 | 968 |
| 969 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype }; | 969 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype }; |
| 970 | 970 |
| 971 /** | 971 /** |
| 972 * @override | 972 * @override |
| 973 */ | 973 */ |
| 974 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) { | 974 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) { |
| 975 return viewport.getInverseTransformForRotatedImage(this.orientation_); | 975 return viewport.getInverseTransformForRotatedImage(this.orientation_); |
| 976 }; | 976 }; |
| OLD | NEW |