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

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

Issue 792733002: Add type annotations to gallery/js/image_editor/image_view.js. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 function ImageUtil() {} 6 function ImageUtil() {}
7 7
8 /** 8 /**
9 * Performance trace. 9 * Performance trace.
10 */ 10 */
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 this.top = 0; 130 this.top = 0;
131 this.width = 0; 131 this.width = 0;
132 this.height = 0; 132 this.height = 0;
133 return; 133 return;
134 } 134 }
135 console.error('Invalid ImageRect constructor arguments:', 135 console.error('Invalid ImageRect constructor arguments:',
136 Array.apply(null, arguments)); 136 Array.apply(null, arguments));
137 } 137 }
138 138
139 /** 139 /**
140 * Creates an image rect with a canvas.
141 * @param {!HTMLCanvasElement} canvas A canvas.
142 * @return {!ImageRect}
143 */
144 ImageRect.createFromCanvas = function(canvas) {
145 return new ImageRect(canvas);
146 };
147
148 /**
140 * Creates an image rect with a bound. 149 * Creates an image rect with a bound.
141 * @param {{left: number, top: number, right: number, bottom: number}} bound 150 * @param {{left: number, top: number, right: number, bottom: number}} bound
142 * A bound. 151 * A bound.
143 * @return {!ImageRect} 152 * @return {!ImageRect}
144 */ 153 */
145 ImageRect.createFromBounds = function(bound) { 154 ImageRect.createFromBounds = function(bound) {
146 return new ImageRect(bound); 155 return new ImageRect(bound);
147 }; 156 };
148 157
149 /** 158 /**
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return '(' + this.left + ',' + this.top + '):' + 317 return '(' + this.left + ',' + this.top + '):' +
309 '(' + (this.left + this.width) + ',' + (this.top + this.height) + ')'; 318 '(' + (this.left + this.width) + ',' + (this.top + this.height) + ')';
310 }; 319 };
311 /* 320 /*
312 * Useful shortcuts for drawing (static functions). 321 * Useful shortcuts for drawing (static functions).
313 */ 322 */
314 323
315 /** 324 /**
316 * Draw the image in context with appropriate scaling. 325 * Draw the image in context with appropriate scaling.
317 * @param {CanvasRenderingContext2D} context Context to draw. 326 * @param {CanvasRenderingContext2D} context Context to draw.
318 * @param {Image} image Image to draw. 327 * @param {!(HTMLCanvasElement|Image)} image Image to draw.
319 * @param {ImageRect=} opt_dstRect Rectangle in the canvas (whole canvas by 328 * @param {ImageRect=} opt_dstRect Rectangle in the canvas (whole canvas by
320 * default). 329 * default).
321 * @param {ImageRect=} opt_srcRect Rectangle in the image (whole image by 330 * @param {ImageRect=} opt_srcRect Rectangle in the image (whole image by
322 * default). 331 * default).
323 */ 332 */
324 ImageRect.drawImage = function(context, image, opt_dstRect, opt_srcRect) { 333 ImageRect.drawImage = function(context, image, opt_dstRect, opt_srcRect) {
325 opt_dstRect = opt_dstRect || new ImageRect(context.canvas); 334 opt_dstRect = opt_dstRect || new ImageRect(context.canvas);
326 opt_srcRect = opt_srcRect || new ImageRect(image); 335 opt_srcRect = opt_srcRect || new ImageRect(image);
327 if (opt_dstRect.isEmpty() || opt_srcRect.isEmpty()) 336 if (opt_dstRect.isEmpty() || opt_srcRect.isEmpty())
328 return; 337 return;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 this.image_ = new Image(); 474 this.image_ = new Image();
466 this.generation_ = 0; 475 this.generation_ = 0;
467 }; 476 };
468 477
469 /** 478 /**
470 * Loads an image. 479 * Loads an image.
471 * TODO(mtomasz): Simplify, or even get rid of this class and merge with the 480 * TODO(mtomasz): Simplify, or even get rid of this class and merge with the
472 * ThumbnaiLoader class. 481 * ThumbnaiLoader class.
473 * 482 *
474 * @param {Gallery.Item} item Item representing the image to be loaded. 483 * @param {Gallery.Item} item Item representing the image to be loaded.
475 * @param {function(HTMLCanvasElement, string=)} callback Callback to be 484 * @param {function(!HTMLCanvasElement, string=)} callback Callback to be
476 * called when loaded. The second optional argument is an error identifier. 485 * called when loaded. The second optional argument is an error identifier.
477 * @param {number=} opt_delay Load delay in milliseconds, useful to let the 486 * @param {number=} opt_delay Load delay in milliseconds, useful to let the
478 * animations play out before the computation heavy image loading starts. 487 * animations play out before the computation heavy image loading starts.
479 */ 488 */
480 ImageUtil.ImageLoader.prototype.load = function(item, callback, opt_delay) { 489 ImageUtil.ImageLoader.prototype.load = function(item, callback, opt_delay) {
481 var entry = item.getEntry(); 490 var entry = item.getEntry();
482 491
483 this.cancel(); 492 this.cancel();
484 this.entry_ = entry; 493 this.entry_ = entry;
485 this.callback_ = callback; 494 this.callback_ = callback;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 587
579 /** 588 /**
580 * @param {Entry} entry Image entry. 589 * @param {Entry} entry Image entry.
581 * @return {boolean} True if loader loads this image. 590 * @return {boolean} True if loader loads this image.
582 */ 591 */
583 ImageUtil.ImageLoader.prototype.isLoading = function(entry) { 592 ImageUtil.ImageLoader.prototype.isLoading = function(entry) {
584 return this.isBusy() && util.isSameEntry(this.entry_, entry); 593 return this.isBusy() && util.isSameEntry(this.entry_, entry);
585 }; 594 };
586 595
587 /** 596 /**
588 * @param {function(HTMLCanvasElement, string=)} callback To be called when the 597 * @param {function(!HTMLCanvasElement, string=)} callback To be called when the
589 * image loaded. 598 * image loaded.
590 */ 599 */
591 ImageUtil.ImageLoader.prototype.setCallback = function(callback) { 600 ImageUtil.ImageLoader.prototype.setCallback = function(callback) {
592 this.callback_ = callback; 601 this.callback_ = callback;
593 }; 602 };
594 603
595 /** 604 /**
596 * Stops loading image. 605 * Stops loading image.
597 */ 606 */
598 ImageUtil.ImageLoader.prototype.cancel = function() { 607 ImageUtil.ImageLoader.prototype.cancel = function() {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 * @return {string} Full name. 726 * @return {string} Full name.
718 */ 727 */
719 ImageUtil.getMetricName = function(name) { 728 ImageUtil.getMetricName = function(name) {
720 return 'PhotoEditor.' + name; 729 return 'PhotoEditor.' + name;
721 }; 730 };
722 731
723 /** 732 /**
724 * Used for metrics reporting, keep in sync with the histogram description. 733 * Used for metrics reporting, keep in sync with the histogram description.
725 */ 734 */
726 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; 735 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp'];
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698