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

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

Issue 624563002: Files.app: Rename Rect used in Gallery with ImageRect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * The overlay displaying the image. 8 * The overlay displaying the image.
9 * 9 *
10 * @param {HTMLElement} container The container element. 10 * @param {HTMLElement} container The container element.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 /** 88 /**
89 * @override 89 * @override
90 */ 90 */
91 ImageView.prototype.draw = function() { 91 ImageView.prototype.draw = function() {
92 if (!this.contentCanvas_) // Do nothing if the image content is not set. 92 if (!this.contentCanvas_) // Do nothing if the image content is not set.
93 return; 93 return;
94 if (this.setupDeviceBuffer(this.screenImage_) || 94 if (this.setupDeviceBuffer(this.screenImage_) ||
95 this.displayedContentGeneration_ !== this.contentGeneration_) { 95 this.displayedContentGeneration_ !== this.contentGeneration_) {
96 this.displayedContentGeneration_ = this.contentGeneration_; 96 this.displayedContentGeneration_ = this.contentGeneration_;
97 ImageUtil.trace.resetTimer('paint'); 97 ImageUtil.trace.resetTimer('paint');
98 this.paintDeviceRect(this.contentCanvas_, new Rect(this.contentCanvas_)); 98 this.paintDeviceRect(
99 this.contentCanvas_, new ImageRect(this.contentCanvas_));
99 ImageUtil.trace.reportTimer('paint'); 100 ImageUtil.trace.reportTimer('paint');
100 } 101 }
101 }; 102 };
102 103
103 /** 104 /**
104 * Applies the viewport change that does not affect the screen cache size (zoom 105 * Applies the viewport change that does not affect the screen cache size (zoom
105 * change or offset change) with animation. 106 * change or offset change) with animation.
106 */ 107 */
107 ImageView.prototype.applyViewportChange = function() { 108 ImageView.prototype.applyViewportChange = function() {
108 if (this.screenImage_) { 109 if (this.screenImage_) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 ImageView.prototype.getContentRevision = function() { 152 ImageView.prototype.getContentRevision = function() {
152 return this.contentRevision_; 153 return this.contentRevision_;
153 }; 154 };
154 155
155 /** 156 /**
156 * Copies an image fragment from a full resolution canvas to a device resolution 157 * Copies an image fragment from a full resolution canvas to a device resolution
157 * canvas. 158 * canvas.
158 * 159 *
159 * @param {HTMLCanvasElement} canvas Canvas containing whole image. The canvas 160 * @param {HTMLCanvasElement} canvas Canvas containing whole image. The canvas
160 * may not be full resolution (scaled). 161 * may not be full resolution (scaled).
161 * @param {Rect} imageRect Rectangle region of the canvas to be rendered. 162 * @param {ImageRect} imageRect Rectangle region of the canvas to be rendered.
162 */ 163 */
163 ImageView.prototype.paintDeviceRect = function(canvas, imageRect) { 164 ImageView.prototype.paintDeviceRect = function(canvas, imageRect) {
164 // Map the rectangle in full resolution image to the rectangle in the device 165 // Map the rectangle in full resolution image to the rectangle in the device
165 // canvas. 166 // canvas.
166 var deviceBounds = this.viewport_.getDeviceBounds(); 167 var deviceBounds = this.viewport_.getDeviceBounds();
167 var scaleX = deviceBounds.width / canvas.width; 168 var scaleX = deviceBounds.width / canvas.width;
168 var scaleY = deviceBounds.height / canvas.height; 169 var scaleY = deviceBounds.height / canvas.height;
169 var deviceRect = new Rect( 170 var deviceRect = new ImageRect(
170 imageRect.left * scaleX, 171 imageRect.left * scaleX,
171 imageRect.top * scaleY, 172 imageRect.top * scaleY,
172 imageRect.width * scaleX, 173 imageRect.width * scaleX,
173 imageRect.height * scaleY); 174 imageRect.height * scaleY);
174 175
175 Rect.drawImage( 176 ImageRect.drawImage(
176 this.screenImage_.getContext('2d'), canvas, deviceRect, imageRect); 177 this.screenImage_.getContext('2d'), canvas, deviceRect, imageRect);
177 }; 178 };
178 179
179 /** 180 /**
180 * Creates an overlay canvas with properties similar to the screen canvas. 181 * Creates an overlay canvas with properties similar to the screen canvas.
181 * Useful for showing quick feedback when editing. 182 * Useful for showing quick feedback when editing.
182 * 183 *
183 * @return {HTMLCanvasElement} Overlay canvas. 184 * @return {HTMLCanvasElement} Overlay canvas.
184 */ 185 */
185 ImageView.prototype.createOverlayCanvas = function() { 186 ImageView.prototype.createOverlayCanvas = function() {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 if (item.contentImage) 398 if (item.contentImage)
398 return; 399 return;
399 this.prefetchLoader_.load(item, function(canvas) { 400 this.prefetchLoader_.load(item, function(canvas) {
400 if (canvas.width && canvas.height && !item.contentImage) 401 if (canvas.width && canvas.height && !item.contentImage)
401 item.contentImage = canvas; 402 item.contentImage = canvas;
402 }, delay); 403 }, delay);
403 }; 404 };
404 405
405 /** 406 /**
406 * Unloads content. 407 * Unloads content.
407 * @param {Rect} zoomToRect Target rectangle for zoom-out-effect. 408 * @param {ImageRect} zoomToRect Target rectangle for zoom-out-effect.
408 */ 409 */
409 ImageView.prototype.unload = function(zoomToRect) { 410 ImageView.prototype.unload = function(zoomToRect) {
410 if (this.unloadTimer_) { 411 if (this.unloadTimer_) {
411 clearTimeout(this.unloadTimer_); 412 clearTimeout(this.unloadTimer_);
412 this.unloadTimer_ = null; 413 this.unloadTimer_ = null;
413 } 414 }
414 if (zoomToRect && this.screenImage_) { 415 if (zoomToRect && this.screenImage_) {
415 var effect = this.createZoomEffect(zoomToRect); 416 var effect = this.createZoomEffect(zoomToRect);
416 this.setTransform_(this.screenImage_, this.viewport_, effect); 417 this.setTransform_(this.screenImage_, this.viewport_, effect);
417 this.screenImage_.setAttribute('fade', true); 418 this.screenImage_.setAttribute('fade', true);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 */ 494 */
494 ImageView.prototype.updateThumbnail_ = function(canvas) { 495 ImageView.prototype.updateThumbnail_ = function(canvas) {
495 ImageUtil.trace.resetTimer('thumb'); 496 ImageUtil.trace.resetTimer('thumb');
496 var pixelCount = 10000; 497 var pixelCount = 10000;
497 var downScale = 498 var downScale =
498 Math.max(1, Math.sqrt(canvas.width * canvas.height / pixelCount)); 499 Math.max(1, Math.sqrt(canvas.width * canvas.height / pixelCount));
499 500
500 this.thumbnailCanvas_ = canvas.ownerDocument.createElement('canvas'); 501 this.thumbnailCanvas_ = canvas.ownerDocument.createElement('canvas');
501 this.thumbnailCanvas_.width = Math.round(canvas.width / downScale); 502 this.thumbnailCanvas_.width = Math.round(canvas.width / downScale);
502 this.thumbnailCanvas_.height = Math.round(canvas.height / downScale); 503 this.thumbnailCanvas_.height = Math.round(canvas.height / downScale);
503 Rect.drawImage(this.thumbnailCanvas_.getContext('2d'), canvas); 504 ImageRect.drawImage(this.thumbnailCanvas_.getContext('2d'), canvas);
504 ImageUtil.trace.reportTimer('thumb'); 505 ImageUtil.trace.reportTimer('thumb');
505 }; 506 };
506 507
507 /** 508 /**
508 * Replaces the displayed image, possibly with slide-in animation. 509 * Replaces the displayed image, possibly with slide-in animation.
509 * 510 *
510 * @param {HTMLCanvasElement} content The image element. 511 * @param {HTMLCanvasElement} content The image element.
511 * @param {Object=} opt_effect Transition effect object. 512 * @param {Object=} opt_effect Transition effect object.
512 * @param {number=} opt_width Image width. 513 * @param {number=} opt_width Image width.
513 * @param {number=} opt_height Image height. 514 * @param {number=} opt_height Image height.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 if (!opt_effect) 567 if (!opt_effect)
567 opt_effect = new ImageView.Effect.None(); 568 opt_effect = new ImageView.Effect.None();
568 if (typeof opt_duration !== 'number') 569 if (typeof opt_duration !== 'number')
569 opt_duration = opt_effect.getDuration(); 570 opt_duration = opt_effect.getDuration();
570 element.style.webkitTransitionDuration = opt_duration + 'ms'; 571 element.style.webkitTransitionDuration = opt_duration + 'ms';
571 element.style.webkitTransitionTimingFunction = opt_effect.getTiming(); 572 element.style.webkitTransitionTimingFunction = opt_effect.getTiming();
572 element.style.webkitTransform = opt_effect.transform(element, viewport); 573 element.style.webkitTransform = opt_effect.transform(element, viewport);
573 }; 574 };
574 575
575 /** 576 /**
576 * @param {Rect} screenRect Target rectangle in screen coordinates. 577 * @param {ImageRect} screenRect Target rectangle in screen coordinates.
577 * @return {ImageView.Effect.Zoom} Zoom effect object. 578 * @return {ImageView.Effect.Zoom} Zoom effect object.
578 */ 579 */
579 ImageView.prototype.createZoomEffect = function(screenRect) { 580 ImageView.prototype.createZoomEffect = function(screenRect) {
580 return new ImageView.Effect.ZoomToScreen( 581 return new ImageView.Effect.ZoomToScreen(
581 screenRect, 582 screenRect,
582 ImageView.MODE_TRANSITION_DURATION); 583 ImageView.MODE_TRANSITION_DURATION);
583 }; 584 };
584 585
585 /** 586 /**
586 * Visualizes crop or rotate operation. Hide the old image instantly, animate 587 * Visualizes crop or rotate operation. Hide the old image instantly, animate
587 * the new image to visualize the operation. 588 * the new image to visualize the operation.
588 * 589 *
589 * @param {HTMLCanvasElement} canvas New content canvas. 590 * @param {HTMLCanvasElement} canvas New content canvas.
590 * @param {Rect} imageCropRect The crop rectangle in image coordinates. 591 * @param {ImageRect} imageCropRect The crop rectangle in image coordinates.
591 * Null for rotation operations. 592 * Null for rotation operations.
592 * @param {number} rotate90 Rotation angle in 90 degree increments. 593 * @param {number} rotate90 Rotation angle in 90 degree increments.
593 * @return {number} Animation duration. 594 * @return {number} Animation duration.
594 */ 595 */
595 ImageView.prototype.replaceAndAnimate = function( 596 ImageView.prototype.replaceAndAnimate = function(
596 canvas, imageCropRect, rotate90) { 597 canvas, imageCropRect, rotate90) {
597 var oldImageBounds = { 598 var oldImageBounds = {
598 width: this.viewport_.getImageBounds().width, 599 width: this.viewport_.getImageBounds().width,
599 height: this.viewport_.getImageBounds().height 600 height: this.viewport_.getImageBounds().height
600 }; 601 };
(...skipping 17 matching lines...) Expand all
618 0); 619 0);
619 620
620 return effect.getSafeInterval(); 621 return effect.getSafeInterval();
621 }; 622 };
622 623
623 /** 624 /**
624 * Visualizes "undo crop". Shrink the current image to the given crop rectangle 625 * Visualizes "undo crop". Shrink the current image to the given crop rectangle
625 * while fading in the new image. 626 * while fading in the new image.
626 * 627 *
627 * @param {HTMLCanvasElement} canvas New content canvas. 628 * @param {HTMLCanvasElement} canvas New content canvas.
628 * @param {Rect} imageCropRect The crop rectangle in image coordinates. 629 * @param {ImageRect} imageCropRect The crop rectangle in image coordinates.
629 * @return {number} Animation duration. 630 * @return {number} Animation duration.
630 */ 631 */
631 ImageView.prototype.animateAndReplace = function(canvas, imageCropRect) { 632 ImageView.prototype.animateAndReplace = function(canvas, imageCropRect) {
632 var oldScreenImage = this.screenImage_; 633 var oldScreenImage = this.screenImage_;
633 this.replaceContent_(canvas); 634 this.replaceContent_(canvas);
634 var newScreenImage = this.screenImage_; 635 var newScreenImage = this.screenImage_;
635 var setFade = ImageUtil.setAttribute.bind(null, newScreenImage, 'fade'); 636 var setFade = ImageUtil.setAttribute.bind(null, newScreenImage, 'fade');
636 setFade(true); 637 setFade(true);
637 oldScreenImage.parentNode.insertBefore(newScreenImage, oldScreenImage); 638 oldScreenImage.parentNode.insertBefore(newScreenImage, oldScreenImage);
638 var effect = new ImageView.Effect.Zoom( 639 var effect = new ImageView.Effect.Zoom(
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 return viewport.getShiftTransformation(this.shift_); 763 return viewport.getShiftTransformation(this.shift_);
763 }; 764 };
764 765
765 /** 766 /**
766 * Zoom effect. 767 * Zoom effect.
767 * 768 *
768 * Animates the original rectangle to the target rectangle. 769 * Animates the original rectangle to the target rectangle.
769 * 770 *
770 * @param {number} previousImageWidth Width of the full resolution image. 771 * @param {number} previousImageWidth Width of the full resolution image.
771 * @param {number} previousImageHeight Height of the full resolution image. 772 * @param {number} previousImageHeight Height of the full resolution image.
772 * @param {Rect} imageCropRect Crop rectangle in the full resolution image. 773 * @param {ImageRect} imageCropRect Crop rectangle in the full resolution image.
773 * @param {number=} opt_duration Duration of the effect. 774 * @param {number=} opt_duration Duration of the effect.
774 * @constructor 775 * @constructor
775 * @extends {ImageView.Effect} 776 * @extends {ImageView.Effect}
776 */ 777 */
777 ImageView.Effect.Zoom = function( 778 ImageView.Effect.Zoom = function(
778 previousImageWidth, previousImageHeight, imageCropRect, opt_duration) { 779 previousImageWidth, previousImageHeight, imageCropRect, opt_duration) {
779 ImageView.Effect.call(this, 780 ImageView.Effect.call(this,
780 opt_duration || ImageView.Effect.DEFAULT_DURATION, 'ease-out'); 781 opt_duration || ImageView.Effect.DEFAULT_DURATION, 'ease-out');
781 this.previousImageWidth_ = previousImageWidth; 782 this.previousImageWidth_ = previousImageWidth;
782 this.previousImageHeight_ = previousImageHeight; 783 this.previousImageHeight_ = previousImageHeight;
783 this.imageCropRect_ = imageCropRect; 784 this.imageCropRect_ = imageCropRect;
784 }; 785 };
785 786
786 ImageView.Effect.Zoom.prototype = { __proto__: ImageView.Effect.prototype }; 787 ImageView.Effect.Zoom.prototype = { __proto__: ImageView.Effect.prototype };
787 788
788 /** 789 /**
789 * @override 790 * @override
790 */ 791 */
791 ImageView.Effect.Zoom.prototype.transform = function(element, viewport) { 792 ImageView.Effect.Zoom.prototype.transform = function(element, viewport) {
792 return viewport.getInverseTransformForCroppedImage( 793 return viewport.getInverseTransformForCroppedImage(
793 this.previousImageWidth_, this.previousImageHeight_, this.imageCropRect_); 794 this.previousImageWidth_, this.previousImageHeight_, this.imageCropRect_);
794 }; 795 };
795 796
796 /** 797 /**
797 * Effect to zoom to a screen rectangle. 798 * Effect to zoom to a screen rectangle.
798 * 799 *
799 * @param {Rect} screenRect Rectangle in the application window's coordinate. 800 * @param {ImageRect} screenRect Rectangle in the application window's
801 * coordinate.
800 * @param {number=} opt_duration Duration of effect. 802 * @param {number=} opt_duration Duration of effect.
801 * @constructor 803 * @constructor
802 * @extends {ImageView.Effect} 804 * @extends {ImageView.Effect}
803 */ 805 */
804 ImageView.Effect.ZoomToScreen = function(screenRect, opt_duration) { 806 ImageView.Effect.ZoomToScreen = function(screenRect, opt_duration) {
805 ImageView.Effect.call(this, opt_duration); 807 ImageView.Effect.call(this, opt_duration);
806 this.screenRect_ = screenRect; 808 this.screenRect_ = screenRect;
807 }; 809 };
808 810
809 ImageView.Effect.ZoomToScreen.prototype = { 811 ImageView.Effect.ZoomToScreen.prototype = {
(...skipping 22 matching lines...) Expand all
832 }; 834 };
833 835
834 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype }; 836 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype };
835 837
836 /** 838 /**
837 * @override 839 * @override
838 */ 840 */
839 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) { 841 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) {
840 return viewport.getInverseTransformForRotatedImage(this.orientation_); 842 return viewport.getInverseTransformForRotatedImage(this.orientation_);
841 }; 843 };
OLDNEW
« no previous file with comments | « ui/file_manager/gallery/js/image_editor/image_util.js ('k') | ui/file_manager/gallery/js/image_editor/viewport.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698