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

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

Issue 402863002: Specify canvas size by using CSS width/height. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/file_manager/gallery/js/image_editor/viewport.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 * @override 94 * @override
95 */ 95 */
96 ImageView.prototype.getZIndex = function() { return -1; }; 96 ImageView.prototype.getZIndex = function() { return -1; };
97 97
98 /** 98 /**
99 * @override 99 * @override
100 */ 100 */
101 ImageView.prototype.draw = function() { 101 ImageView.prototype.draw = function() {
102 if (!this.contentCanvas_) // Do nothing if the image content is not set. 102 if (!this.contentCanvas_) // Do nothing if the image content is not set.
103 return; 103 return;
104 104 if (this.setupDeviceBuffer(this.screenImage_) ||
105 var forceRepaint = false;
106 var deviceBounds = this.viewport_.getDeviceBounds();
107 if (deviceBounds.width != this.screenImage_.width ||
108 deviceBounds.height != this.screenImage_.height) {
109 this.setupDeviceBuffer(this.screenImage_);
110 forceRepaint = true;
111 }
112
113 if (forceRepaint ||
114 this.displayedContentGeneration_ !== this.contentGeneration_) { 105 this.displayedContentGeneration_ !== this.contentGeneration_) {
115 this.displayedContentGeneration_ = this.contentGeneration_; 106 this.displayedContentGeneration_ = this.contentGeneration_;
116 ImageUtil.trace.resetTimer('paint'); 107 ImageUtil.trace.resetTimer('paint');
117 this.paintDeviceRect(this.contentCanvas_, new Rect(this.contentCanvas_)); 108 this.paintDeviceRect(this.contentCanvas_, new Rect(this.contentCanvas_));
118 ImageUtil.trace.reportTimer('paint'); 109 ImageUtil.trace.reportTimer('paint');
119 } 110 }
120 }; 111 };
121 112
122 /** 113 /**
123 * Applies the viewport change that does not affect the screen cache size (zoom 114 * Applies the viewport change that does not affect the screen cache size (zoom
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 }; 199 };
209 200
210 /** 201 /**
211 * Sets up the canvas as a buffer in the device resolution. 202 * Sets up the canvas as a buffer in the device resolution.
212 * 203 *
213 * @param {HTMLCanvasElement} canvas The buffer canvas. 204 * @param {HTMLCanvasElement} canvas The buffer canvas.
214 */ 205 */
215 ImageView.prototype.setupDeviceBuffer = function(canvas) { 206 ImageView.prototype.setupDeviceBuffer = function(canvas) {
216 // Set the canvas position and size in device pixels. 207 // Set the canvas position and size in device pixels.
217 var deviceRect = this.viewport_.getDeviceBounds(); 208 var deviceRect = this.viewport_.getDeviceBounds();
218 if (canvas.width !== deviceRect.width) 209 var needRepaint = false;
210 if (canvas.width !== deviceRect.width) {
219 canvas.width = deviceRect.width; 211 canvas.width = deviceRect.width;
220 if (canvas.height !== deviceRect.height) 212 needRepaint = true;
213 }
214 if (canvas.height !== deviceRect.height) {
221 canvas.height = deviceRect.height; 215 canvas.height = deviceRect.height;
216 needRepaint = true;
217 }
222 218
223 // Center the image. 219 // Center the image.
224 var imageBoudns = this.viewport_.getImageElementBoundsOnScreen(); 220 var imageBoudns = this.viewport_.getImageElementBoundsOnScreen();
fukino 2014/07/22 05:32:18 nit: imageBounds?
hirono 2014/07/22 06:51:28 Yes, renamed.
225 canvas.style.left = imageBoudns.left + 'px'; 221 canvas.style.left = imageBoudns.left + 'px';
226 canvas.style.top = imageBoudns.top + 'px'; 222 canvas.style.top = imageBoudns.top + 'px';
223 canvas.style.width = imageBoudns.width + 'px';
224 canvas.style.height = imageBoudns.height + 'px';
227 225
228 // Scale the canvas down to screen pixels.
229 this.setTransform(canvas); 226 this.setTransform(canvas);
227
228 return needRepaint;
fukino 2014/07/22 05:32:18 nit: Please write a comment for return value.
hirono 2014/07/22 06:51:28 Done.
230 }; 229 };
231 230
232 /** 231 /**
233 * @return {ImageData} A new ImageData object with a copy of the content. 232 * @return {ImageData} A new ImageData object with a copy of the content.
234 */ 233 */
235 ImageView.prototype.copyScreenImageData = function() { 234 ImageView.prototype.copyScreenImageData = function() {
236 return this.screenImage_.getContext('2d').getImageData( 235 return this.screenImage_.getContext('2d').getImageData(
237 0, 0, this.screenImage_.width, this.screenImage_.height); 236 0, 0, this.screenImage_.width, this.screenImage_.height);
238 }; 237 };
239 238
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 * Obtains the CSS transformation string of the effect. 819 * Obtains the CSS transformation string of the effect.
821 * @param {DOMCanvas} element Canvas element to be applied the transforamtion. 820 * @param {DOMCanvas} element Canvas element to be applied the transforamtion.
822 * @param {Viewport} viewport Current viewport. 821 * @param {Viewport} viewport Current viewport.
823 * @return CSS transformation description. 822 * @return CSS transformation description.
824 */ 823 */
825 ImageView.Effect.prototype.transform = function(element, viewport) { 824 ImageView.Effect.prototype.transform = function(element, viewport) {
826 throw new Error('Not implemented.'); 825 throw new Error('Not implemented.');
827 }; 826 };
828 827
829 /** 828 /**
830 * Default effect. It is not a no-op as it needs to adjust a canvas scale 829 * Default effect.
831 * for devicePixelRatio.
832 * 830 *
833 * @constructor 831 * @constructor
834 * @extends {ImageView.Effect} 832 * @extends {ImageView.Effect}
835 */ 833 */
836 ImageView.Effect.None = function() { 834 ImageView.Effect.None = function() {
837 ImageView.Effect.call(this, 0, 'easy-out'); 835 ImageView.Effect.call(this, 0, 'easy-out');
838 }; 836 };
839 837
840 /** 838 /**
841 * Inherits from ImageView.Effect. 839 * Inherits from ImageView.Effect.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 /** 879 /**
882 * @override 880 * @override
883 */ 881 */
884 ImageView.Effect.Slide.prototype.transform = function(element, viewport) { 882 ImageView.Effect.Slide.prototype.transform = function(element, viewport) {
885 return viewport.getShiftTransformation(this.shift_); 883 return viewport.getShiftTransformation(this.shift_);
886 }; 884 };
887 885
888 /** 886 /**
889 * Zoom effect. 887 * Zoom effect.
890 * 888 *
891 * Animates the original rectangle to the target rectangle. Both parameters 889 * Animates the original rectangle to the target rectangle.
892 * should be given in device coordinates (accounting for devicePixelRatio).
893 * 890 *
894 * @param {number} previousImageWidth Width of the full resolution image. 891 * @param {number} previousImageWidth Width of the full resolution image.
895 * @param {number} previousImageHeight Hieght of the full resolution image. 892 * @param {number} previousImageHeight Hieght of the full resolution image.
896 * @param {Rect} imageCropRect Crop rectangle in the full resolution image. 893 * @param {Rect} imageCropRect Crop rectangle in the full resolution image.
897 * @param {number=} opt_duration Duration of the effect. 894 * @param {number=} opt_duration Duration of the effect.
898 * @constructor 895 * @constructor
899 * @extends {ImageView.Effect} 896 * @extends {ImageView.Effect}
900 */ 897 */
901 ImageView.Effect.Zoom = function( 898 ImageView.Effect.Zoom = function(
902 previousImageWidth, previousImageHeight, imageCropRect, opt_duration) { 899 previousImageWidth, previousImageHeight, imageCropRect, opt_duration) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 }; 953 };
957 954
958 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype }; 955 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype };
959 956
960 /** 957 /**
961 * @override 958 * @override
962 */ 959 */
963 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) { 960 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) {
964 return viewport.getInverseTransformForRotatedImage(this.orientation_); 961 return viewport.getInverseTransformForRotatedImage(this.orientation_);
965 }; 962 };
OLDNEW
« no previous file with comments | « no previous file | ui/file_manager/gallery/js/image_editor/viewport.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698