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

Side by Side Diff: ui/file_manager/gallery/js/image_editor/image_util.js

Issue 971173002: Gallery: Start to use new metadata model in Gallery. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test. Created 5 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // Namespace object for the utilities. 5 // Namespace object for the utilities.
6 var ImageUtil = {}; 6 var ImageUtil = {};
7 7
8 /** 8 /**
9 * Performance trace. 9 * Performance trace.
10 */ 10 */
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 }; 420 };
421 421
422 /** 422 /**
423 * ImageLoader loads an image from a given Entry into a canvas in two steps: 423 * ImageLoader loads an image from a given Entry into a canvas in two steps:
424 * 1. Loads the image into an HTMLImageElement. 424 * 1. Loads the image into an HTMLImageElement.
425 * 2. Copies pixels from HTMLImageElement to HTMLCanvasElement. This is done 425 * 2. Copies pixels from HTMLImageElement to HTMLCanvasElement. This is done
426 * stripe-by-stripe to avoid freezing up the UI. The transform is taken into 426 * stripe-by-stripe to avoid freezing up the UI. The transform is taken into
427 * account. 427 * account.
428 * 428 *
429 * @param {!HTMLDocument} document Owner document. 429 * @param {!HTMLDocument} document Owner document.
430 * @param {!MetadataModel} metadataModel
430 * @constructor 431 * @constructor
431 * @struct 432 * @struct
432 */ 433 */
433 ImageUtil.ImageLoader = function(document) { 434 ImageUtil.ImageLoader = function(document, metadataModel) {
434 this.document_ = document; 435 this.document_ = document;
436
437 /**
438 * @private {!MetadataModel}
439 * @const
440 */
441 this.metadataModel_ = metadataModel;
442
435 this.image_ = new Image(); 443 this.image_ = new Image();
436 this.generation_ = 0; 444 this.generation_ = 0;
437 445
438 /** 446 /**
439 * @type {number} 447 * @type {number}
440 * @private 448 * @private
441 */ 449 */
442 this.timeout_ = 0; 450 this.timeout_ = 0;
443 451
444 /** 452 /**
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 }; 511 };
504 onError = onError.bind(this); 512 onError = onError.bind(this);
505 513
506 var loadImage = function() { 514 var loadImage = function() {
507 ImageUtil.metrics.startInterval(ImageUtil.getMetricName('LoadTime')); 515 ImageUtil.metrics.startInterval(ImageUtil.getMetricName('LoadTime'));
508 this.timeout_ = null; 516 this.timeout_ = null;
509 517
510 this.image_.onload = function() { 518 this.image_.onload = function() {
511 this.image_.onerror = null; 519 this.image_.onerror = null;
512 this.image_.onload = null; 520 this.image_.onload = null;
513 item.getFetchedMedia().then(function(fetchedMediaMetadata) { 521 this.metadataModel_.get([entry], ['contentImageTransform']).then(
514 if (fetchedMediaMetadata.imageTransform) 522 function(metadataItems) {
515 onTransform(this.image_, fetchedMediaMetadata.imageTransform); 523 onTransform(this.image_, metadataItems[0].contentImageTransform);
516 else 524 }.bind(this));
517 onTransform(this.image_);
518 }.bind(this)).catch(function(error) {
519 console.error(error.stack || error);
520 });
521 }.bind(this); 525 }.bind(this);
522 526
523 // The error callback has an optional error argument, which in case of a 527 // The error callback has an optional error argument, which in case of a
524 // general error should not be specified 528 // general error should not be specified
525 this.image_.onerror = onError.bind(this, 'GALLERY_IMAGE_ERROR'); 529 this.image_.onerror = onError.bind(this, 'GALLERY_IMAGE_ERROR');
526 530
527 // Load the image directly. The query parameter is workaround for 531 // Load the image directly. The query parameter is workaround for
528 // crbug.com/379678, which force to update the contents of the image. 532 // crbug.com/379678, which force to update the contents of the image.
529 this.image_.src = entry.toURL() + '?nocache=' + Date.now(); 533 this.image_.src = entry.toURL() + '?nocache=' + Date.now();
530 }.bind(this); 534 }.bind(this);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 ImageUtil.getMetricName = function(name) { 725 ImageUtil.getMetricName = function(name) {
722 return 'PhotoEditor.' + name; 726 return 'PhotoEditor.' + name;
723 }; 727 };
724 728
725 /** 729 /**
726 * Used for metrics reporting, keep in sync with the histogram description. 730 * Used for metrics reporting, keep in sync with the histogram description.
727 * @type {Array.<string>} 731 * @type {Array.<string>}
728 * @const 732 * @const
729 */ 733 */
730 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; 734 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp'];
OLDNEW
« no previous file with comments | « ui/file_manager/gallery/js/gallery_item_unittest.js ('k') | ui/file_manager/gallery/js/image_editor/image_view.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698