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

Unified Diff: chrome/browser/resources/file_manager/js/ui/preview_panel.js

Issue 23676006: Files.app: Let the thumbnail images in the preview panels managed by PreviewPanel class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address the comments. Created 7 years, 3 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
« no previous file with comments | « chrome/browser/resources/file_manager/js/file_selection.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/file_manager/js/ui/preview_panel.js
diff --git a/chrome/browser/resources/file_manager/js/ui/preview_panel.js b/chrome/browser/resources/file_manager/js/ui/preview_panel.js
index ea5c3c065240ece6ca8cab7955665657d4be544d..b6c350a72738e0ff195b3311b12ab130d68e9fe1 100644
--- a/chrome/browser/resources/file_manager/js/ui/preview_panel.js
+++ b/chrome/browser/resources/file_manager/js/ui/preview_panel.js
@@ -10,10 +10,14 @@
* @param {PreviewPanel.VisibilityType} visibilityType Initial value of the
* visibility type.
* @param {string} currentPath Initial value of the current path.
+ * @param {MetadataCache} metadataCache Metadata cache.
* @constructor
* @extends {cr.EventTarget}
*/
-var PreviewPanel = function(element, visibilityType, currentPath) {
+var PreviewPanel = function(element,
+ visibilityType,
+ currentPath,
+ metadataCache) {
/**
* The cached height of preview panel.
* @type {number}
@@ -43,10 +47,10 @@ var PreviewPanel = function(element, visibilityType, currentPath) {
this.element_ = element;
/**
- * @type {HTMLElement}
- * @private
+ * @type {PreviewPanel.Thumbnails}
*/
- this.thumbnailElement_ = element.querySelector('.preview-thumbnails');
+ this.thumbnails = new PreviewPanel.Thumbnails(
+ element.querySelector('.preview-thumbnails'), metadataCache);
/**
* @type {HTMLElement}
@@ -329,3 +333,146 @@ PreviewPanel.CalculatingSizeLabel.prototype.onStep_ = function() {
this.element_.textContent = text;
this.count_++;
};
+
+/**
+ * Thumbnails on the preview panel.
+ * @param {HTMLElement} element DOM Element of thumbnail container.
+ * @param {MetadataCache} metadataCache MetadataCache.
yoshiki 2013/09/10 02:36:28 @constructor
hirono 2013/09/10 02:44:18 Done.
+ */
+PreviewPanel.Thumbnails = function(element, metadataCache) {
+ this.element_ = element;
+ this.metadataCache_ = metadataCache;
+ this.sequence_ = 0;
yoshiki 2013/09/10 02:36:28 Sorry for after lgtm, but could you add Object.sea
hirono 2013/09/10 02:44:18 Done.
+};
+
+/**
+ * Maximium number of thumbnails.
+ * @const {number}
+ */
+PreviewPanel.Thumbnails.MAX_THUMBNAIL_COUNT = 4;
+
+/**
+ * Edge length of the thumbnail square.
+ * @const {number}
+ */
+PreviewPanel.Thumbnails.THUMBNAIL_SIZE = 35;
+
+/**
+ * Longer edge length of zoomed thumbnail rectangle.
+ * @const {number}
+ */
+PreviewPanel.Thumbnails.ZOOMED_THUMBNAIL_SIZE = 200;
+
+PreviewPanel.Thumbnails.prototype = {
+ /**
+ * Sets entries to be displayed in the view.
+ * @param {Array.<Entry>} value Entries.
+ */
+ set selection(value) {
+ this.sequence_++;
+ this.loadThumbnails_(value);
+ }
+};
+
+/**
+ * Loads thumbnail images.
+ * @param {FileSelection} selection Selection containing entries that are
+ * sources of images.
+ * @private
+ */
+PreviewPanel.Thumbnails.prototype.loadThumbnails_ = function(selection) {
+ var entries = selection.entries;
+ this.element_.classList.remove('has-zoom');
+ this.element_.innerText = '';
+ var clickHandler = selection.tasks &&
+ selection.tasks.executeDefault.bind(selection.tasks);
+ var length = Math.min(entries.length,
+ PreviewPanel.Thumbnails.MAX_THUMBNAIL_COUNT);
+ for (var i = 0; i < length; i++) {
+ // Create a box.
+ var box = this.element_.ownerDocument.createElement('div');
+ box.style.zIndex = PreviewPanel.Thumbnails.MAX_THUMBNAIL_COUNT + 1 - i;
+
+ // Load the image.
+ FileGrid.decorateThumbnailBox(box,
+ entries[i],
+ this.metadataCache_,
+ ThumbnailLoader.FillMode.FILL,
+ FileGrid.ThumbnailQuality.LOW,
+ i == 0 && length == 1 &&
+ this.setZoomedImage_.bind(this));
+
+ // Register the click handler.
+ if (clickHandler)
+ box.addEventListener('click', clickHandler);
+
+ // Append
+ this.element_.appendChild(box);
+ }
+};
+
+/**
+ * Create the zoomed version of image and set it to the DOM element to show the
+ * zoomed image.
+ *
+ * @param {Image} image Image to be source of the zoomed image.
+ * @param {transform} transform Transoformation to be applied to the image.
+ * @private
+ */
+PreviewPanel.Thumbnails.prototype.setZoomedImage_ =
+ function(image, transform) {
+ if (!image)
+ return;
+ var width = image.width || 0;
+ var height = image.height || 0;
+ if (width == 0 ||
+ height == 0 ||
+ (width < PreviewPanel.Thumbnails.THUMBNAIL_SIZE * 2 &&
+ height < PreviewPanel.Thumbnails.THUMBNAIL_SIZE * 2))
+ return;
+
+ var scale = Math.min(1,
+ PreviewPanel.Thumbnails.ZOOMED_THUMBNAIL_SIZE /
+ Math.max(width, height));
+ var imageWidth = ~~(width * scale);
+ var imageHeight = ~~(height * scale);
+ var zoomedImage = this.element_.ownerDocument.createElement('img');
+
+ if (scale < 0.3) {
+ // Scaling large images kills animation. Downscale it in advance.
+ // Canvas scales images with liner interpolation. Make a larger
+ // image (but small enough to not kill animation) and let IMAGE
+ // scale it smoothly.
+ var INTERMEDIATE_SCALE = 3;
+ var canvas = this.element_.ownerDocument.createElement('canvas');
+ canvas.width = imageWidth * INTERMEDIATE_SCALE;
+ canvas.height = imageHeight * INTERMEDIATE_SCALE;
+ var ctx = canvas.getContext('2d');
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
+ // Using bigger than default compression reduces image size by
+ // several times. Quality degradation compensated by greater resolution.
+ zoomedImage.src = canvas.toDataURL('image/jpeg', 0.6);
+ } else {
+ zoomedImage.src = image.src;
+ }
+
+ var boxWidth = Math.max(PreviewPanel.Thumbnails.THUMBNAIL_SIZE, imageWidth);
+ var boxHeight = Math.max(PreviewPanel.Thumbnails.THUMBNAIL_SIZE, imageHeight);
+ if (transform && transform.rotate90 % 2 == 1) {
+ var t = boxWidth;
+ boxWidth = boxHeight;
+ boxHeight = t;
+ }
+
+ util.applyTransform(zoomedImage, transform);
+
+ var zoomedBox = this.element_.ownerDocument.createElement('div');
+ zoomedBox.className = 'popup';
+ zoomedBox.style.width = boxWidth + 'px';
+ zoomedBox.style.height = boxHeight + 'px';
+ zoomedBox.appendChild(zoomedImage);
+
+ this.element_.appendChild(zoomedBox);
+ this.element_.classList.add('has-zoom');
+ return;
+};
« no previous file with comments | « chrome/browser/resources/file_manager/js/file_selection.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698