Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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], ['contentThumbnailTransform']).then( |
|
yawano
2015/03/03 04:14:50
Isn't this contentImageTransform instead of conten
hirono
2015/03/04 05:07:04
Good catch. Done.
| |
| 514 if (fetchedMediaMetadata.imageTransform) | 522 function(metadataItems) { |
| 515 onTransform(this.image_, fetchedMediaMetadata.imageTransform); | 523 onTransform( |
| 516 else | 524 this.image_, metadataItems[0].contentThumbnailTransform); |
| 517 onTransform(this.image_); | 525 }.bind(this)); |
| 518 }.bind(this)).catch(function(error) { | |
| 519 console.error(error.stack || error); | |
| 520 }); | |
| 521 }.bind(this); | 526 }.bind(this); |
| 522 | 527 |
| 523 // The error callback has an optional error argument, which in case of a | 528 // The error callback has an optional error argument, which in case of a |
| 524 // general error should not be specified | 529 // general error should not be specified |
| 525 this.image_.onerror = onError.bind(this, 'GALLERY_IMAGE_ERROR'); | 530 this.image_.onerror = onError.bind(this, 'GALLERY_IMAGE_ERROR'); |
| 526 | 531 |
| 527 // Load the image directly. The query parameter is workaround for | 532 // Load the image directly. The query parameter is workaround for |
| 528 // crbug.com/379678, which force to update the contents of the image. | 533 // crbug.com/379678, which force to update the contents of the image. |
| 529 this.image_.src = entry.toURL() + '?nocache=' + Date.now(); | 534 this.image_.src = entry.toURL() + '?nocache=' + Date.now(); |
| 530 }.bind(this); | 535 }.bind(this); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 ImageUtil.getMetricName = function(name) { | 726 ImageUtil.getMetricName = function(name) { |
| 722 return 'PhotoEditor.' + name; | 727 return 'PhotoEditor.' + name; |
| 723 }; | 728 }; |
| 724 | 729 |
| 725 /** | 730 /** |
| 726 * Used for metrics reporting, keep in sync with the histogram description. | 731 * Used for metrics reporting, keep in sync with the histogram description. |
| 727 * @type {Array.<string>} | 732 * @type {Array.<string>} |
| 728 * @const | 733 * @const |
| 729 */ | 734 */ |
| 730 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; | 735 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; |
| OLD | NEW |