Chromium Code Reviews| Index: chrome/browser/resources/file_manager/foreground/js/image_editor/image_view.js |
| diff --git a/chrome/browser/resources/file_manager/foreground/js/image_editor/image_view.js b/chrome/browser/resources/file_manager/foreground/js/image_editor/image_view.js |
| index 7c3bd5621ef0a46e9b028502f0e44419499f30b5..ed9066af468a9fa7632f93ed8210eb288fd8c820 100644 |
| --- a/chrome/browser/resources/file_manager/foreground/js/image_editor/image_view.js |
| +++ b/chrome/browser/resources/file_manager/foreground/js/image_editor/image_view.js |
| @@ -46,8 +46,8 @@ function ImageView(container, viewport, metadataCache) { |
| */ |
| this.screenImage_ = null; |
| - this.localImageTransformFetcher_ = function(url, callback) { |
| - metadataCache.get(url, 'fetchedMedia', function(fetchedMedia) { |
| + this.localImageTransformFetcher_ = function(entry, callback) { |
| + metadataCache.get(entry, 'fetchedMedia', function(fetchedMedia) { |
| callback(fetchedMedia.imageTransform); |
| }); |
| }; |
| @@ -102,13 +102,13 @@ ImageView.LOAD_TYPE_TOTAL = 6; |
| ImageView.prototype = {__proto__: ImageBuffer.Overlay.prototype}; |
| /** |
| - * Draw below overlays with the default zIndex. |
| + * Draws below overlays with the default zIndex. |
| * @return {number} Z-index. |
| */ |
| ImageView.prototype.getZIndex = function() { return -1 }; |
| /** |
| - * Draw the image on screen. |
| + * Draws the image on screen. |
| */ |
| ImageView.prototype.draw = function() { |
| if (!this.contentCanvas_) // Do nothing if the image content is not set. |
| @@ -174,7 +174,7 @@ ImageView.prototype.getCacheGeneration = function() { |
| }; |
| /** |
| - * Invalidate the caches to force redrawing the screen canvas. |
| + * Invalidates the caches to force redrawing the screen canvas. |
| */ |
| ImageView.prototype.invalidateCaches = function() { |
| this.contentGeneration_++; |
| @@ -210,7 +210,7 @@ ImageView.prototype.getContentRevision = function() { |
| }; |
| /** |
| - * Copy an image fragment from a full resolution canvas to a device resolution |
| + * Copies an image fragment from a full resolution canvas to a device resolution |
| * canvas. |
| * |
| * @param {Rect} deviceRect Rectangle in the device coordinates. |
| @@ -234,7 +234,7 @@ ImageView.prototype.paintDeviceRect = function(deviceRect, canvas, imageRect) { |
| }; |
| /** |
| - * Create an overlay canvas with properties similar to the screen canvas. |
| + * Creates an overlay canvas with properties similar to the screen canvas. |
| * Useful for showing quick feedback when editing. |
| * |
| * @return {HTMLCanvasElement} Overlay canvas. |
| @@ -284,19 +284,19 @@ ImageView.prototype.isLoading = function() { |
| }; |
| /** |
| - * Cancel the current image loading operation. The callbacks will be ignored. |
| + * Cancels the current image loading operation. The callbacks will be ignored. |
| */ |
| ImageView.prototype.cancelLoad = function() { |
| this.imageLoader_.cancel(); |
| }; |
| /** |
| - * Load and display a new image. |
| + * Loads and display a new image. |
| * |
| * Loads the thumbnail first, then replaces it with the main image. |
| * Takes into account the image orientation encoded in the metadata. |
| * |
| - * @param {string} url Image url. |
| + * @param {FileEntry} entry Image entry. |
| * @param {Object} metadata Metadata. |
| * @param {Object} effect Transition effect object. |
| * @param {function(number} displayCallback Called when the image is displayed |
| @@ -304,7 +304,7 @@ ImageView.prototype.cancelLoad = function() { |
| * @param {function(number} loadCallback Called when the image is fully loaded. |
| * The parameter is the load type. |
| */ |
| -ImageView.prototype.load = function(url, metadata, effect, |
| +ImageView.prototype.load = function(entry, metadata, effect, |
| displayCallback, loadCallback) { |
| if (effect) { |
| // Skip effects when reloading repeatedly very quickly. |
| @@ -322,10 +322,10 @@ ImageView.prototype.load = function(url, metadata, effect, |
| var self = this; |
| - this.contentID_ = url; |
| + this.contentEntry_ = entry; |
| this.contentRevision_ = -1; |
| - var loadingVideo = FileType.getMediaType(url) == 'video'; |
| + var loadingVideo = FileType.getMediaType(entry) == 'video'; |
|
hirono
2013/12/10 03:36:53
=== is preferred.
|
| if (loadingVideo) { |
| var video = this.document_.createElement('video'); |
| var videoPreview = !!(metadata.thumbnail && metadata.thumbnail.url); |
| @@ -356,7 +356,7 @@ ImageView.prototype.load = function(url, metadata, effect, |
| video.addEventListener('loadedmetadata', onVideoLoadSuccess); |
| video.addEventListener('error', onVideoLoadError); |
| - video.src = url; |
| + video.src = entry.toURL(); |
| video.load(); |
| return; |
| } |
| @@ -365,12 +365,12 @@ ImageView.prototype.load = function(url, metadata, effect, |
| // evicted later by the prefetched image. |
| this.contentCache_.evictLRU(); |
| - var cached = this.contentCache_.getItem(this.contentID_); |
| + var cached = this.contentCache_.getItem(this.contentEntry_); |
| if (cached) { |
| displayMainImage(ImageView.LOAD_TYPE_CACHED_FULL, |
| false /* no preview */, cached); |
| } else { |
| - var cachedScreen = this.screenCache_.getItem(this.contentID_); |
| + var cachedScreen = this.screenCache_.getItem(this.contentEntry_); |
| var imageWidth = metadata.media && metadata.media.width || |
| metadata.drive && metadata.drive.imageWidth; |
| var imageHeight = metadata.media && metadata.media.height || |
| @@ -396,7 +396,7 @@ ImageView.prototype.load = function(url, metadata, effect, |
| success ? thumbnailLoader.getImage() : null); |
| }); |
| } else { |
| - loadMainImage(ImageView.LOAD_TYPE_IMAGE_FILE, url, |
| + loadMainImage(ImageView.LOAD_TYPE_IMAGE_FILE, entry, |
| false /* no preview*/, 0 /* delay */); |
| } |
| } |
| @@ -411,12 +411,12 @@ ImageView.prototype.load = function(url, metadata, effect, |
| true /* preview */); |
| if (displayCallback) displayCallback(); |
| } |
| - loadMainImage(loadType, url, !!canvas, |
| + loadMainImage(loadType, entry, !!canvas, |
| (effect && canvas) ? effect.getSafeInterval() : 0); |
| } |
| - function loadMainImage(loadType, contentURL, previewShown, delay) { |
| - if (self.prefetchLoader_.isLoading(contentURL)) { |
| + function loadMainImage(loadType, contentEntry, previewShown, delay) { |
| + if (self.prefetchLoader_.isLoading(contentEntry)) { |
| // The image we need is already being prefetched. Initiating another load |
| // would be a waste. Hijack the load instead by overriding the callback. |
| self.prefetchLoader_.setCallback( |
| @@ -431,7 +431,7 @@ ImageView.prototype.load = function(url, metadata, effect, |
| self.prefetchLoader_.cancel(); // The prefetch was doing something useless. |
| self.imageLoader_.load( |
| - contentURL, |
| + contentEntry, |
| self.localImageTransformFetcher_, |
| displayMainImage.bind(null, loadType, previewShown), |
| delay); |
| @@ -473,28 +473,27 @@ ImageView.prototype.load = function(url, metadata, effect, |
| }; |
| /** |
| - * Prefetch an image. |
| - * |
| - * @param {string} url The image url. |
| + * Prefetches an image. |
| + * @param {FileEntry} entry The image entry. |
| * @param {number} delay Image load delay in ms. |
| */ |
| -ImageView.prototype.prefetch = function(url, delay) { |
| +ImageView.prototype.prefetch = function(entry, delay) { |
| var self = this; |
| function prefetchDone(canvas) { |
| if (canvas.width) |
| - self.contentCache_.putItem(url, canvas); |
| + self.contentCache_.putItem(entry, canvas); |
| } |
| - var cached = this.contentCache_.getItem(url); |
| + var cached = this.contentCache_.getItem(entry); |
| if (cached) { |
| prefetchDone(cached); |
| - } else if (FileType.getMediaType(url) == 'image') { |
| + } else if (FileType.getMediaType(entry) === 'image') { |
| // Evict the LRU item before we allocate the new canvas to avoid unneeded |
| // strain on memory. |
| this.contentCache_.evictLRU(); |
| this.prefetchLoader_.load( |
| - url, |
| + entry, |
| this.localImageTransformFetcher_, |
| prefetchDone, |
| delay); |
| @@ -502,19 +501,17 @@ ImageView.prototype.prefetch = function(url, delay) { |
| }; |
| /** |
| - * Rename the current image. |
| - * |
| - * @param {string} newUrl The new image url. |
| + * Renames the current image. |
| + * @param {FileEntry} newEntry The new image Entry. |
| */ |
| -ImageView.prototype.changeUrl = function(newUrl) { |
| - this.contentCache_.renameItem(this.contentID_, newUrl); |
| - this.screenCache_.renameItem(this.contentID_, newUrl); |
| - this.contentID_ = newUrl; |
| +ImageView.prototype.changeEntry = function(newEntry) { |
| + this.contentCache_.renameItem(this.contentEntry_, newEntry); |
| + this.screenCache_.renameItem(this.contentEntry_, newEntry); |
| + this.contentEntry_ = newEntry; |
| }; |
| /** |
| - * Unload content. |
| - * |
| + * Unloads content. |
| * @param {Rect} zoomToRect Target rectangle for zoom-out-effect. |
| */ |
| ImageView.prototype.unload = function(zoomToRect) { |
| @@ -540,7 +537,6 @@ ImageView.prototype.unload = function(zoomToRect) { |
| }; |
| /** |
| - * |
| * @param {HTMLCanvasElement|HTMLVideoElement} content The image element. |
| * @param {number=} opt_width Image width. |
| * @param {number=} opt_height Image height. |
| @@ -585,8 +581,8 @@ ImageView.prototype.replaceContent_ = function( |
| this.container_.appendChild(this.contentCanvas_); |
| this.contentCanvas_.classList.add('fullres'); |
| - this.contentCache_.putItem(this.contentID_, this.contentCanvas_, true); |
| - this.screenCache_.putItem(this.contentID_, this.screenImage_); |
| + this.contentCache_.putItem(this.contentEntry_, this.contentCanvas_, true); |
| + this.screenCache_.putItem(this.contentEntry_, this.screenImage_); |
| // TODO(kaznacheev): It is better to pass screenImage_ as it is usually |
| // much smaller than contentCanvas_ and still contains the entire image. |
| @@ -605,7 +601,7 @@ ImageView.prototype.replaceContent_ = function( |
| }; |
| /** |
| - * Add a listener for content changes. |
| + * Adds a listener for content changes. |
| * @param {function} callback Callback. |
| */ |
| ImageView.prototype.addContentCallback = function(callback) { |
| @@ -613,7 +609,7 @@ ImageView.prototype.addContentCallback = function(callback) { |
| }; |
| /** |
| - * Update the cached thumbnail image. |
| + * Updates the cached thumbnail image. |
| * |
| * @param {HTMLCanvasElement} canvas The source canvas. |
| * @private |
| @@ -632,7 +628,7 @@ ImageView.prototype.updateThumbnail_ = function(canvas) { |
| }; |
| /** |
| - * Replace the displayed image, possibly with slide-in animation. |
| + * Replaces the displayed image, possibly with slide-in animation. |
| * |
| * @param {HTMLCanvasElement|HTMLVideoElement} content The image element. |
| * @param {Object=} opt_effect Transition effect object. |
| @@ -701,7 +697,7 @@ ImageView.prototype.createZoomEffect = function(screenRect) { |
| }; |
| /** |
| - * Visualize crop or rotate operation. Hide the old image instantly, animate |
| + * Visualizes crop or rotate operation. Hide the old image instantly, animate |
| * the new image to visualize the operation. |
| * |
| * @param {HTMLCanvasElement} canvas New content canvas. |
| @@ -743,7 +739,7 @@ ImageView.prototype.replaceAndAnimate = function( |
| }; |
| /** |
| - * Visualize "undo crop". Shrink the current image to the given crop rectangle |
| + * Visualizes "undo crop". Shrink the current image to the given crop rectangle |
| * while fading in the new image. |
| * |
| * @param {HTMLCanvasElement} canvas New content canvas. |
| @@ -782,7 +778,6 @@ ImageView.prototype.animateAndReplace = function(canvas, imageCropRect) { |
| /** |
| * Generic cache with a limited capacity and LRU eviction. |
| - * |
| * @param {number} capacity Maximum number of cached item. |
| * @constructor |
| */ |
| @@ -793,71 +788,73 @@ ImageView.Cache = function(capacity) { |
| }; |
| /** |
| - * Fetch the item from the cache. |
| - * |
| - * @param {string} id The item ID. |
| + * Fetches the item from the cache. |
| + * @param {FileEntry} entry The entry. |
| * @return {Object} The cached item. |
| */ |
| -ImageView.Cache.prototype.getItem = function(id) { return this.map_[id] }; |
| +ImageView.Cache.prototype.getItem = function(entry) { |
| + return this.map_[entry.toURL()]; |
| +}; |
| /** |
| - * Put the item into the cache. |
| - * @param {string} id The item ID. |
| + * Puts the item into the cache. |
| + * |
| + * @param {FileEntry} entry The entry. |
| * @param {Object} item The item object. |
| * @param {boolean=} opt_keepLRU True if the LRU order should not be modified. |
| */ |
| -ImageView.Cache.prototype.putItem = function(id, item, opt_keepLRU) { |
| - var pos = this.order_.indexOf(id); |
| +ImageView.Cache.prototype.putItem = function(entry, item, opt_keepLRU) { |
| + var pos = this.order_.indexOf(entry.toURL()); |
| - if ((pos >= 0) != (id in this.map_)) |
| + if ((pos >= 0) != (entry.toURL() in this.map_)) |
|
hirono
2013/12/10 03:36:53
!== is preferred
mtomasz
2013/12/10 05:07:01
Done.
|
| throw new Error('Inconsistent cache state'); |
| - if (id in this.map_) { |
| + if (entry.toURL() in this.map_) { |
| if (!opt_keepLRU) { |
| // Move to the end (most recently used). |
| this.order_.splice(pos, 1); |
| - this.order_.push(id); |
| + this.order_.push(entry.toURL()); |
| } |
| } else { |
| this.evictLRU(); |
| - this.order_.push(id); |
| + this.order_.push(entry.toURL()); |
| } |
| - if ((pos >= 0) && (item != this.map_[id])) |
| - this.deleteItem_(this.map_[id]); |
| - this.map_[id] = item; |
| + if ((pos >= 0) && (item != this.map_[entry.toURL()])) |
| + this.deleteItem_(this.map_[entry.toURL()]); |
| + this.map_[entry.toURL()] = item; |
| if (this.order_.length > this.capacity_) |
| throw new Error('Exceeded cache capacity'); |
| }; |
| /** |
| - * Evict the least recently used items. |
| + * Evicts the least recently used items. |
| */ |
| ImageView.Cache.prototype.evictLRU = function() { |
| if (this.order_.length == this.capacity_) { |
|
hirono
2013/12/10 03:36:53
=== is preferred
mtomasz
2013/12/10 05:07:01
Done.
|
| - var id = this.order_.shift(); |
| - this.deleteItem_(this.map_[id]); |
| - delete this.map_[id]; |
| + var url = this.order_.shift(); |
| + this.deleteItem_(this.map_[url]); |
| + delete this.map_[url]; |
| } |
| }; |
| /** |
| - * Change the id of an entry. |
| - * @param {string} oldId The old ID. |
| - * @param {string} newId The new ID. |
| + * Changes the Entry. |
| + * @param {FileEntry} oldEntry The old Entry. |
| + * @param {FileEntry} newEntry The new Entry. |
| */ |
| -ImageView.Cache.prototype.renameItem = function(oldId, newId) { |
| - if (oldId == newId) |
| +ImageView.Cache.prototype.renameItem = function(oldEntry, newEntry) { |
| + if (oldEntry.toURL() == newEntry.toURL()) |
|
hirono
2013/12/10 03:36:53
Please use util.isSameEntry.
mtomasz
2013/12/10 05:07:01
Done.
|
| return; // No need to rename. |
| - var pos = this.order_.indexOf(oldId); |
| + var pos = this.order_.indexOf(oldEntry.toURL()); |
| if (pos < 0) |
| return; // Not cached. |
| - this.order_[pos] = newId; |
| - this.map_[newId] = this.map_[oldId]; |
| - delete this.map_[oldId]; |
| + this.order_[pos] = newEntry.toURL(); |
| + this.map_[newEntry.toURL()] = this.map_[oldEntry.toURL()]; |
| + delete this.map_[oldEntry.toURL()]; |
| }; |
| /** |