| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 | 7 |
| 8 // Namespace object for the utilities. | 8 // Namespace object for the utilities. |
| 9 function ImageUtil() {} | 9 function ImageUtil() {} |
| 10 | 10 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 129 } |
| 130 | 130 |
| 131 case 0: | 131 case 0: |
| 132 this.left = 0; | 132 this.left = 0; |
| 133 this.top = 0; | 133 this.top = 0; |
| 134 this.width = 0; | 134 this.width = 0; |
| 135 this.height = 0; | 135 this.height = 0; |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 console.error('Invalid Rect constructor arguments:', | 138 console.error('Invalid Rect constructor arguments:', |
| 139 Array.apply(null, arguments)); | 139 Array.apply(null, arguments)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 Rect.prototype = { | 142 Rect.prototype = { |
| 143 /** | 143 /** |
| 144 * Obtains the x coordinate of right edge. The most right pixels in the | 144 * Obtains the x coordinate of right edge. The most right pixels in the |
| 145 * rectangle are (x = right - 1) and the pixels (x = right) are not included | 145 * rectangle are (x = right - 1) and the pixels (x = right) are not included |
| 146 * in the rectangle. | 146 * in the rectangle. |
| 147 * @return {number} | 147 * @return {number} |
| 148 */ | 148 */ |
| 149 get right() { | 149 get right() { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 this.document_ = document; | 433 this.document_ = document; |
| 434 this.image_ = new Image(); | 434 this.image_ = new Image(); |
| 435 this.generation_ = 0; | 435 this.generation_ = 0; |
| 436 }; | 436 }; |
| 437 | 437 |
| 438 /** | 438 /** |
| 439 * Loads an image. | 439 * Loads an image. |
| 440 * TODO(mtomasz): Simplify, or even get rid of this class and merge with the | 440 * TODO(mtomasz): Simplify, or even get rid of this class and merge with the |
| 441 * ThumbnaiLoader class. | 441 * ThumbnaiLoader class. |
| 442 * | 442 * |
| 443 * @param {FileEntry} entry Image entry to be loaded. | 443 * @param {Gallery.Item} item Item representing the image to be loaded. |
| 444 * @param {function(HTMLCanvasElement, string=)} callback Callback to be | 444 * @param {function(HTMLCanvasElement, string=)} callback Callback to be |
| 445 * called when loaded. The second optional argument is an error identifier. | 445 * called when loaded. The second optional argument is an error identifier. |
| 446 * @param {number=} opt_delay Load delay in milliseconds, useful to let the | 446 * @param {number=} opt_delay Load delay in milliseconds, useful to let the |
| 447 * animations play out before the computation heavy image loading starts. | 447 * animations play out before the computation heavy image loading starts. |
| 448 */ | 448 */ |
| 449 ImageUtil.ImageLoader.prototype.load = function(item, callback, opt_delay) { | 449 ImageUtil.ImageLoader.prototype.load = function(item, callback, opt_delay) { |
| 450 var entry = item.getEntry(); | 450 var entry = item.getEntry(); |
| 451 | 451 |
| 452 this.cancel(); | 452 this.cancel(); |
| 453 this.entry_ = entry; | 453 this.entry_ = entry; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 console.error(error.stack || error); | 486 console.error(error.stack || error); |
| 487 }); | 487 }); |
| 488 }.bind(this); | 488 }.bind(this); |
| 489 | 489 |
| 490 // The error callback has an optional error argument, which in case of a | 490 // The error callback has an optional error argument, which in case of a |
| 491 // general error should not be specified | 491 // general error should not be specified |
| 492 this.image_.onerror = onError.bind(this, 'GALLERY_IMAGE_ERROR'); | 492 this.image_.onerror = onError.bind(this, 'GALLERY_IMAGE_ERROR'); |
| 493 | 493 |
| 494 // Load the image directly. The query parameter is workaround for | 494 // Load the image directly. The query parameter is workaround for |
| 495 // crbug.com/379678, which force to update the contents of the image. | 495 // crbug.com/379678, which force to update the contents of the image. |
| 496 this.image_.src = entry.toURL() + "?nocache=" + Date.now(); | 496 this.image_.src = entry.toURL() + '?nocache=' + Date.now(); |
| 497 }.bind(this); | 497 }.bind(this); |
| 498 | 498 |
| 499 // Loads the image. If already loaded, then forces a reload. | 499 // Loads the image. If already loaded, then forces a reload. |
| 500 var startLoad = this.resetImage_.bind(this, function() { | 500 var startLoad = this.resetImage_.bind(this, function() { |
| 501 loadImage(); | 501 loadImage(); |
| 502 }.bind(this), onError); | 502 }.bind(this), onError); |
| 503 | 503 |
| 504 if (opt_delay) { | 504 if (opt_delay) { |
| 505 this.timeout_ = setTimeout(startLoad, opt_delay); | 505 this.timeout_ = setTimeout(startLoad, opt_delay); |
| 506 } else { | 506 } else { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 * @return {string} Full name. | 685 * @return {string} Full name. |
| 686 */ | 686 */ |
| 687 ImageUtil.getMetricName = function(name) { | 687 ImageUtil.getMetricName = function(name) { |
| 688 return 'PhotoEditor.' + name; | 688 return 'PhotoEditor.' + name; |
| 689 }; | 689 }; |
| 690 | 690 |
| 691 /** | 691 /** |
| 692 * Used for metrics reporting, keep in sync with the histogram description. | 692 * Used for metrics reporting, keep in sync with the histogram description. |
| 693 */ | 693 */ |
| 694 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; | 694 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; |
| OLD | NEW |