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 /** | 5 /** |
6 * The overlay displaying the image. | 6 * The overlay displaying the image. |
7 */ | 7 */ |
8 function ImageView(container, viewport, metadataProvider) { | 8 function ImageView(container, viewport, metadataProvider) { |
9 this.container_ = container; | 9 this.container_ = container; |
10 this.viewport_ = viewport; | 10 this.viewport_ = viewport; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 mainImageSlide = 0; | 262 mainImageSlide = 0; |
263 } else { | 263 } else { |
264 // Thumbnail image load failed, loading the main image immediately. | 264 // Thumbnail image load failed, loading the main image immediately. |
265 mainImageLoadDelay = 0; | 265 mainImageLoadDelay = 0; |
266 } | 266 } |
267 loadMainImage(loadType, mainImageSlide, source, | 267 loadMainImage(loadType, mainImageSlide, source, |
268 canvas.width != 0, mainImageLoadDelay); | 268 canvas.width != 0, mainImageLoadDelay); |
269 } | 269 } |
270 | 270 |
271 function loadMainImage(loadType, slide, contentURL, previewShown, delay) { | 271 function loadMainImage(loadType, slide, contentURL, previewShown, delay) { |
| 272 contentURL = metadata.cachedURL || contentURL; |
272 if (self.prefetchLoader_.isLoading(contentURL)) { | 273 if (self.prefetchLoader_.isLoading(contentURL)) { |
273 // The image we need is already being prefetched. Initiating another load | 274 // The image we need is already being prefetched. Initiating another load |
274 // would be a waste. Hijack the load instead by overriding the callback. | 275 // would be a waste. Hijack the load instead by overriding the callback. |
275 self.prefetchLoader_.setCallback( | 276 self.prefetchLoader_.setCallback( |
276 displayMainImage.bind(null, loadType, slide, previewShown)); | 277 displayMainImage.bind(null, loadType, slide, previewShown)); |
277 | 278 |
278 // Swap the loaders so that the self.isLoading works correctly. | 279 // Swap the loaders so that the self.isLoading works correctly. |
279 var temp = self.prefetchLoader_; | 280 var temp = self.prefetchLoader_; |
280 self.prefetchLoader_ = self.imageLoader_; | 281 self.prefetchLoader_ = self.imageLoader_; |
281 self.imageLoader_ = temp; | 282 self.imageLoader_ = temp; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 347 |
347 var cached = this.getReadyContent(id, source); | 348 var cached = this.getReadyContent(id, source); |
348 if (cached) { | 349 if (cached) { |
349 prefetchDone(cached); | 350 prefetchDone(cached); |
350 } else if (FileType.getMediaType(source) == 'image') { | 351 } else if (FileType.getMediaType(source) == 'image') { |
351 // Evict the LRU item before we allocate the new canvas to avoid unneeded | 352 // Evict the LRU item before we allocate the new canvas to avoid unneeded |
352 // strain on memory. | 353 // strain on memory. |
353 this.contentCache_.evictLRU(); | 354 this.contentCache_.evictLRU(); |
354 | 355 |
355 this.prefetchLoader_.load( | 356 this.prefetchLoader_.load( |
356 source, | 357 metadata.cachedURL || source, |
357 this.localImageTransformFetcher_, | 358 this.localImageTransformFetcher_, |
358 prefetchDone, | 359 prefetchDone, |
359 ImageView.ANIMATION_WAIT_INTERVAL); | 360 ImageView.ANIMATION_WAIT_INTERVAL); |
360 } | 361 } |
361 }; | 362 }; |
362 | 363 |
363 ImageView.prototype.replaceContent_ = function( | 364 ImageView.prototype.replaceContent_ = function( |
364 content, opt_reuseScreenCanvas, opt_width, opt_height, opt_preview) { | 365 content, opt_reuseScreenCanvas, opt_width, opt_height, opt_preview) { |
365 | 366 |
366 if (content.constructor.name == 'HTMLVideoElement') { | 367 if (content.constructor.name == 'HTMLVideoElement') { |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 if (this.order_.length > this.capacity_) | 571 if (this.order_.length > this.capacity_) |
571 throw new Error('Exceeded cache capacity'); | 572 throw new Error('Exceeded cache capacity'); |
572 }; | 573 }; |
573 | 574 |
574 ImageView.Cache.prototype.evictLRU = function() { | 575 ImageView.Cache.prototype.evictLRU = function() { |
575 if (this.order_.length == this.capacity_) { | 576 if (this.order_.length == this.capacity_) { |
576 var id = this.order_.shift(); | 577 var id = this.order_.shift(); |
577 delete this.map_[id]; | 578 delete this.map_[id]; |
578 } | 579 } |
579 }; | 580 }; |
OLD | NEW |