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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/file_manager/js/file_selection.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * PreviewPanel UI class. 8 * PreviewPanel UI class.
9 * @param {HTMLElement} element DOM Element of preview panel. 9 * @param {HTMLElement} element DOM Element of preview panel.
10 * @param {PreviewPanel.VisibilityType} visibilityType Initial value of the 10 * @param {PreviewPanel.VisibilityType} visibilityType Initial value of the
11 * visibility type. 11 * visibility type.
12 * @param {string} currentPath Initial value of the current path. 12 * @param {string} currentPath Initial value of the current path.
13 * @param {MetadataCache} metadataCache Metadata cache.
13 * @constructor 14 * @constructor
14 * @extends {cr.EventTarget} 15 * @extends {cr.EventTarget}
15 */ 16 */
16 var PreviewPanel = function(element, visibilityType, currentPath) { 17 var PreviewPanel = function(element,
18 visibilityType,
19 currentPath,
20 metadataCache) {
17 /** 21 /**
18 * The cached height of preview panel. 22 * The cached height of preview panel.
19 * @type {number} 23 * @type {number}
20 * @private 24 * @private
21 */ 25 */
22 this.height_ = 0; 26 this.height_ = 0;
23 27
24 /** 28 /**
25 * Visiblity type of the preview panel. 29 * Visiblity type of the preview panel.
26 * @type {PreviewPanel.VisiblityType} 30 * @type {PreviewPanel.VisiblityType}
27 * @private 31 * @private
28 */ 32 */
29 this.visibilityType_ = visibilityType; 33 this.visibilityType_ = visibilityType;
30 34
31 /** 35 /**
32 * Current path to be desplayed. 36 * Current path to be desplayed.
33 * @type {string} 37 * @type {string}
34 * @private 38 * @private
35 */ 39 */
36 this.currentPath_ = currentPath || '/'; 40 this.currentPath_ = currentPath || '/';
37 41
38 /** 42 /**
39 * Dom element of the preview panel. 43 * Dom element of the preview panel.
40 * @type {HTMLElement} 44 * @type {HTMLElement}
41 * @private 45 * @private
42 */ 46 */
43 this.element_ = element; 47 this.element_ = element;
44 48
45 /** 49 /**
46 * @type {HTMLElement} 50 * @type {PreviewPanel.Thumbnails}
47 * @private
48 */ 51 */
49 this.thumbnailElement_ = element.querySelector('.preview-thumbnails'); 52 this.thumbnails = new PreviewPanel.Thumbnails(
53 element.querySelector('.preview-thumbnails'), metadataCache);
50 54
51 /** 55 /**
52 * @type {HTMLElement} 56 * @type {HTMLElement}
53 * @private 57 * @private
54 */ 58 */
55 this.summaryElement_ = element.querySelector('.preview-summary'); 59 this.summaryElement_ = element.querySelector('.preview-summary');
56 60
57 /** 61 /**
58 * @type {PreviewPanel.CalculatingSizeLabel} 62 * @type {PreviewPanel.CalculatingSizeLabel}
59 * @private 63 * @private
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 * @private 326 * @private
323 */ 327 */
324 PreviewPanel.CalculatingSizeLabel.prototype.onStep_ = function() { 328 PreviewPanel.CalculatingSizeLabel.prototype.onStep_ = function() {
325 var text = str('CALCULATING_SIZE'); 329 var text = str('CALCULATING_SIZE');
326 for (var i = 0; i < ~~(this.count_ / 2) % 4; i++) { 330 for (var i = 0; i < ~~(this.count_ / 2) % 4; i++) {
327 text += '.'; 331 text += '.';
328 } 332 }
329 this.element_.textContent = text; 333 this.element_.textContent = text;
330 this.count_++; 334 this.count_++;
331 }; 335 };
336
337 /**
338 * Thumbnails on the preview panel.
339 * @param {HTMLElement} element DOM Element of thumbnail container.
340 * @param {MetadataCache} metadataCache MetadataCache.
yoshiki 2013/09/10 02:36:28 @constructor
hirono 2013/09/10 02:44:18 Done.
341 */
342 PreviewPanel.Thumbnails = function(element, metadataCache) {
343 this.element_ = element;
344 this.metadataCache_ = metadataCache;
345 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.
346 };
347
348 /**
349 * Maximium number of thumbnails.
350 * @const {number}
351 */
352 PreviewPanel.Thumbnails.MAX_THUMBNAIL_COUNT = 4;
353
354 /**
355 * Edge length of the thumbnail square.
356 * @const {number}
357 */
358 PreviewPanel.Thumbnails.THUMBNAIL_SIZE = 35;
359
360 /**
361 * Longer edge length of zoomed thumbnail rectangle.
362 * @const {number}
363 */
364 PreviewPanel.Thumbnails.ZOOMED_THUMBNAIL_SIZE = 200;
365
366 PreviewPanel.Thumbnails.prototype = {
367 /**
368 * Sets entries to be displayed in the view.
369 * @param {Array.<Entry>} value Entries.
370 */
371 set selection(value) {
372 this.sequence_++;
373 this.loadThumbnails_(value);
374 }
375 };
376
377 /**
378 * Loads thumbnail images.
379 * @param {FileSelection} selection Selection containing entries that are
380 * sources of images.
381 * @private
382 */
383 PreviewPanel.Thumbnails.prototype.loadThumbnails_ = function(selection) {
384 var entries = selection.entries;
385 this.element_.classList.remove('has-zoom');
386 this.element_.innerText = '';
387 var clickHandler = selection.tasks &&
388 selection.tasks.executeDefault.bind(selection.tasks);
389 var length = Math.min(entries.length,
390 PreviewPanel.Thumbnails.MAX_THUMBNAIL_COUNT);
391 for (var i = 0; i < length; i++) {
392 // Create a box.
393 var box = this.element_.ownerDocument.createElement('div');
394 box.style.zIndex = PreviewPanel.Thumbnails.MAX_THUMBNAIL_COUNT + 1 - i;
395
396 // Load the image.
397 FileGrid.decorateThumbnailBox(box,
398 entries[i],
399 this.metadataCache_,
400 ThumbnailLoader.FillMode.FILL,
401 FileGrid.ThumbnailQuality.LOW,
402 i == 0 && length == 1 &&
403 this.setZoomedImage_.bind(this));
404
405 // Register the click handler.
406 if (clickHandler)
407 box.addEventListener('click', clickHandler);
408
409 // Append
410 this.element_.appendChild(box);
411 }
412 };
413
414 /**
415 * Create the zoomed version of image and set it to the DOM element to show the
416 * zoomed image.
417 *
418 * @param {Image} image Image to be source of the zoomed image.
419 * @param {transform} transform Transoformation to be applied to the image.
420 * @private
421 */
422 PreviewPanel.Thumbnails.prototype.setZoomedImage_ =
423 function(image, transform) {
424 if (!image)
425 return;
426 var width = image.width || 0;
427 var height = image.height || 0;
428 if (width == 0 ||
429 height == 0 ||
430 (width < PreviewPanel.Thumbnails.THUMBNAIL_SIZE * 2 &&
431 height < PreviewPanel.Thumbnails.THUMBNAIL_SIZE * 2))
432 return;
433
434 var scale = Math.min(1,
435 PreviewPanel.Thumbnails.ZOOMED_THUMBNAIL_SIZE /
436 Math.max(width, height));
437 var imageWidth = ~~(width * scale);
438 var imageHeight = ~~(height * scale);
439 var zoomedImage = this.element_.ownerDocument.createElement('img');
440
441 if (scale < 0.3) {
442 // Scaling large images kills animation. Downscale it in advance.
443 // Canvas scales images with liner interpolation. Make a larger
444 // image (but small enough to not kill animation) and let IMAGE
445 // scale it smoothly.
446 var INTERMEDIATE_SCALE = 3;
447 var canvas = this.element_.ownerDocument.createElement('canvas');
448 canvas.width = imageWidth * INTERMEDIATE_SCALE;
449 canvas.height = imageHeight * INTERMEDIATE_SCALE;
450 var ctx = canvas.getContext('2d');
451 ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
452 // Using bigger than default compression reduces image size by
453 // several times. Quality degradation compensated by greater resolution.
454 zoomedImage.src = canvas.toDataURL('image/jpeg', 0.6);
455 } else {
456 zoomedImage.src = image.src;
457 }
458
459 var boxWidth = Math.max(PreviewPanel.Thumbnails.THUMBNAIL_SIZE, imageWidth);
460 var boxHeight = Math.max(PreviewPanel.Thumbnails.THUMBNAIL_SIZE, imageHeight);
461 if (transform && transform.rotate90 % 2 == 1) {
462 var t = boxWidth;
463 boxWidth = boxHeight;
464 boxHeight = t;
465 }
466
467 util.applyTransform(zoomedImage, transform);
468
469 var zoomedBox = this.element_.ownerDocument.createElement('div');
470 zoomedBox.className = 'popup';
471 zoomedBox.style.width = boxWidth + 'px';
472 zoomedBox.style.height = boxHeight + 'px';
473 zoomedBox.appendChild(zoomedImage);
474
475 this.element_.appendChild(zoomedBox);
476 this.element_.classList.add('has-zoom');
477 return;
478 };
OLDNEW
« 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