Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2544)

Unified Diff: chrome/browser/resources/file_manager/js/media/media_util.js

Issue 12316118: Enabled Mosaic view on each volume. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/file_manager/js/media/media_util.js
diff --git a/chrome/browser/resources/file_manager/js/media/media_util.js b/chrome/browser/resources/file_manager/js/media/media_util.js
index 2d105007d7baf423fbb954fe5a2aefaedfa77772..5332e112b3aef7d840112b77b22112cfae3a1173 100644
--- a/chrome/browser/resources/file_manager/js/media/media_util.js
+++ b/chrome/browser/resources/file_manager/js/media/media_util.js
@@ -12,9 +12,14 @@
* default: IMAGE.
* @param {Object=} opt_metadata Metadata object.
* @param {string=} opt_mediaType Media type.
+ * @param {ThumbnailLoader.UseEmbedded=} opt_useEmbedded If to use embedded
+ * jpeg thumbnail if available. Default: USE_EMBEDDED.
* @constructor
*/
-function ThumbnailLoader(url, opt_loaderType, opt_metadata, opt_mediaType) {
+function ThumbnailLoader(
+ url, opt_loaderType, opt_metadata, opt_mediaType, opt_useEmbedded) {
+ opt_useEmbedded = opt_useEmbedded || ThumbnailLoader.UseEmbedded.USE_EMBEDDED;
+
this.mediaType_ = opt_mediaType || FileType.getMediaType(url);
this.loaderType_ = opt_loaderType || ThumbnailLoader.LoaderType.IMAGE;
@@ -35,7 +40,8 @@ function ThumbnailLoader(url, opt_loaderType, opt_metadata, opt_mediaType) {
}
}
- if (opt_metadata.thumbnail && opt_metadata.thumbnail.url) {
+ if (opt_metadata.thumbnail && opt_metadata.thumbnail.url &&
+ opt_useEmbedded == ThumbnailLoader.UseEmbedded.USE_EMBEDDED) {
this.thumbnailUrl_ = opt_metadata.thumbnail.url;
this.transform_ = opt_metadata.thumbnail.transform;
} else if (FileType.isImage(url)) {
@@ -85,6 +91,16 @@ ThumbnailLoader.LoaderType = {
};
/**
+ * Whether to use the embedded thumbnail, or not. The embedded thumbnail may
+ * be small.
+ * @enum
yoshiki 2013/02/26 08:21:44 @enum {number} The @enum tag must be followed by
mtomasz 2013/02/26 08:39:20 We have to fix it in lots of places. Separate cl?
yoshiki 2013/02/26 08:50:27 Thanks. We need to fix the others as well in separ
mtomasz 2013/02/27 00:55:31 Done.
+ */
+ThumbnailLoader.UseEmbedded = {
+ USE_EMBEDDED: 0,
+ NO_EMBEDDED: 1
+};
+
+/**
* Maximum thumbnail's width when generating from the full resolution image.
* @const
* @type {number}
@@ -122,6 +138,7 @@ ThumbnailLoader.prototype.load = function(box, fillMode, opt_optimizationMode,
return;
}
+ this.cancel();
this.canvasUpToDate_ = false;
this.image_ = new Image();
this.image_.onload = function() {
@@ -150,7 +167,7 @@ ThumbnailLoader.prototype.load = function(box, fillMode, opt_optimizationMode,
// TODO(mtomasz): Smarter calculation of the requested size.
var wasAttached = box.ownerDocument.contains(box);
- var taskId = util.loadImage(
+ this.taskId_ = util.loadImage(
this.image_,
this.thumbnailUrl_,
{ maxWidth: ThumbnailLoader.THUMBNAIL_MAX_WIDTH,
@@ -166,11 +183,22 @@ ThumbnailLoader.prototype.load = function(box, fillMode, opt_optimizationMode,
return true;
});
- if (!taskId)
+ if (!this.taskId_)
this.image_.classList.add('cached');
};
/**
+ * Cancels loading the current image.
+ */
+ThumbnailLoader.prototype.cancel = function() {
+ if (this.taskId_) {
+ this.image_.onload = function() {};
+ this.image_.onerror = function() {};
+ util.cancelLoadImage(this.taskId_);
+ }
+};
+
+/**
* @return {boolean} True if a valid image is loaded.
*/
ThumbnailLoader.prototype.hasValidImage = function() {
@@ -211,20 +239,21 @@ ThumbnailLoader.prototype.loadDetachedImage = function(callback) {
return;
}
+ this.cancel();
this.canvasUpToDate_ = false;
this.image_ = new Image();
this.image_.onload = callback.bind(null, true);
this.image_.onerror = callback.bind(null, false);
// TODO(mtomasz): Smarter calculation of the requested size.
- var taskId = util.loadImage(
+ this.taskId_ = util.loadImage(
this.image_,
this.thumbnailUrl_,
{ maxWidth: ThumbnailLoader.THUMBNAIL_MAX_WIDTH,
maxHeight: ThumbnailLoader.THUMBNAIL_MAX_HEIGHT,
cache: true });
- if (!taskId)
+ if (!this.taskId_)
this.image_.classList.add('cached');
};
@@ -263,7 +292,7 @@ ThumbnailLoader.prototype.attachImage = function(container, fillMode) {
util.applyTransform(container, this.transform_);
ThumbnailLoader.centerImage_(
container, attachableMedia, fillMode, this.isRotated_());
- if (this.image_.parentNode != container) {
+ if (attachableMedia.parentNode != container) {
container.textContent = '';
container.appendChild(attachableMedia);
}

Powered by Google App Engine
This is Rietveld 408576698