OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 5 |
6 // Namespace object for the utilities. | 6 // Namespace object for the utilities. |
7 function ImageUtil() {} | 7 function ImageUtil() {} |
8 | 8 |
9 /** | 9 /** |
10 * Performance trace. | 10 * Performance trace. |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 this.image_.onload = null; | 480 this.image_.onload = null; |
481 if (ImageUtil.ImageLoader.isTooLarge(this.image_)) { | 481 if (ImageUtil.ImageLoader.isTooLarge(this.image_)) { |
482 errorCallback('IMAGE_TOO_BIG_ERROR'); | 482 errorCallback('IMAGE_TOO_BIG_ERROR'); |
483 return; | 483 return; |
484 } | 484 } |
485 transformFetcher(url, onTransform.bind(this, e.target)); | 485 transformFetcher(url, onTransform.bind(this, e.target)); |
486 }.bind(this); | 486 }.bind(this); |
487 // errorCallback has an optional error argument, which in case of general | 487 // errorCallback has an optional error argument, which in case of general |
488 // error should not be specified | 488 // error should not be specified |
489 this.image_.onerror = errorCallback.bind(this, 'IMAGE_ERROR'); | 489 this.image_.onerror = errorCallback.bind(this, 'IMAGE_ERROR'); |
490 this.remoteLoader_ = util.loadImage(this.image_, url); | 490 this.taskId_ = util.loadImage(this.image_, url); |
491 }.bind(this); | 491 }.bind(this); |
492 if (opt_delay) { | 492 if (opt_delay) { |
493 this.timeout_ = setTimeout(startLoad, opt_delay); | 493 this.timeout_ = setTimeout(startLoad, opt_delay); |
494 } else { | 494 } else { |
495 startLoad(); | 495 startLoad(); |
496 } | 496 } |
497 }; | 497 }; |
498 | 498 |
499 /** | 499 /** |
500 * @return {boolean} True if an image is loading. | 500 * @return {boolean} True if an image is loading. |
(...skipping 25 matching lines...) Expand all Loading... |
526 this.callback_ = null; | 526 this.callback_ = null; |
527 if (this.timeout_) { | 527 if (this.timeout_) { |
528 clearTimeout(this.timeout_); | 528 clearTimeout(this.timeout_); |
529 this.timeout_ = null; | 529 this.timeout_ = null; |
530 } | 530 } |
531 if (this.image_) { | 531 if (this.image_) { |
532 this.image_.onload = function() {}; | 532 this.image_.onload = function() {}; |
533 this.image_.onerror = function() {}; | 533 this.image_.onerror = function() {}; |
534 this.image_.src = ''; | 534 this.image_.src = ''; |
535 } | 535 } |
536 if (this.remoteLoader_) { | 536 if (this.taskId_) |
537 this.remoteLoader_.cancel(); | 537 util.cancelLoadImage(this.taskId_); |
538 this.remoteLoader_ = null; | |
539 } | |
540 this.generation_++; // Silence the transform fetcher if it is in progress. | 538 this.generation_++; // Silence the transform fetcher if it is in progress. |
541 }; | 539 }; |
542 | 540 |
543 /** | 541 /** |
544 * @param {HTMLImageElement} image Image to be transformed. | 542 * @param {HTMLImageElement} image Image to be transformed. |
545 * @param {object} transform rransformation description to applay to the image. | 543 * @param {object} transform rransformation description to applay to the image. |
546 * @private | 544 * @private |
547 */ | 545 */ |
548 ImageUtil.ImageLoader.prototype.convertImage_ = function(image, transform) { | 546 ImageUtil.ImageLoader.prototype.convertImage_ = function(image, transform) { |
549 var canvas = this.document_.createElement('canvas'); | 547 var canvas = this.document_.createElement('canvas'); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 * @return {string} Full name. | 679 * @return {string} Full name. |
682 */ | 680 */ |
683 ImageUtil.getMetricName = function(name) { | 681 ImageUtil.getMetricName = function(name) { |
684 return 'PhotoEditor.' + name; | 682 return 'PhotoEditor.' + name; |
685 }; | 683 }; |
686 | 684 |
687 /** | 685 /** |
688 * Used for metrics reporting, keep in sync with the histogram description. | 686 * Used for metrics reporting, keep in sync with the histogram description. |
689 */ | 687 */ |
690 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; | 688 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; |
OLD | NEW |