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

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

Issue 398283002: Gallery: Add the offset feature in the slide mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. 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
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 * Viewport class controls the way the image is displayed (scale, offset etc). 8 * Viewport class controls the way the image is displayed (scale, offset etc).
9 * @constructor 9 * @constructor
10 */ 10 */
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 this.offsetY_ = 0; 79 this.offsetY_ = 0;
80 80
81 /** 81 /**
82 * Generation of the screen size image cache. 82 * Generation of the screen size image cache.
83 * This is incremented every time when the size of image cache is changed. 83 * This is incremented every time when the size of image cache is changed.
84 * @type {number} 84 * @type {number}
85 * @private 85 * @private
86 */ 86 */
87 this.generation_ = 0; 87 this.generation_ = 0;
88 88
89 this.update(); 89 this.update_();
90 Object.seal(this); 90 Object.seal(this);
91 } 91 }
92 92
93 /** 93 /**
94 * Zoom ratios. 94 * Zoom ratios.
95 * 95 *
96 * @type {Object.<string, number>} 96 * @type {Object.<string, number>}
97 * @const 97 * @const
98 */ 98 */
99 Viewport.ZOOM_RATIOS = Object.freeze({ 99 Viewport.ZOOM_RATIOS = Object.freeze({
100 '3': 3, 100 '3': 3,
101 '2': 2, 101 '2': 2,
102 '1': 1.5, 102 '1': 1.5,
103 '0': 1, 103 '0': 1,
104 '-1': 0.75, 104 '-1': 0.75,
105 '-2': 0.5, 105 '-2': 0.5,
106 '-3': 0.25 106 '-3': 0.25
107 }); 107 });
108 108
109 /** 109 /**
110 * @param {number} width Image width. 110 * @param {number} width Image width.
111 * @param {number} height Image height. 111 * @param {number} height Image height.
112 */ 112 */
113 Viewport.prototype.setImageSize = function(width, height) { 113 Viewport.prototype.setImageSize = function(width, height) {
114 this.imageBounds_ = new Rect(width, height); 114 this.imageBounds_ = new Rect(width, height);
115 this.update(); 115 this.update_();
116 this.invalidateCaches();
117 }; 116 };
118 117
119 /** 118 /**
120 * @param {number} width Screen width. 119 * @param {number} width Screen width.
121 * @param {number} height Screen height. 120 * @param {number} height Screen height.
122 */ 121 */
123 Viewport.prototype.setScreenSize = function(width, height) { 122 Viewport.prototype.setScreenSize = function(width, height) {
124 this.screenBounds_ = new Rect(width, height); 123 this.screenBounds_ = new Rect(width, height);
125 this.update(); 124 this.update_();
126 this.invalidateCaches();
127 }; 125 };
128 126
129 /** 127 /**
130 * Sets the new zoom ratio. 128 * Sets the new zoom ratio.
131 * @param {number} zoomIndex New zoom index. 129 * @param {number} zoomIndex New zoom index.
132 */ 130 */
133 Viewport.prototype.setZoomIndex = function(zoomIndex) { 131 Viewport.prototype.setZoomIndex = function(zoomIndex) {
134 // Ignore the invalid zoomIndex. 132 // Ignore the invalid zoomIndex.
135 if (!Viewport.ZOOM_RATIOS[zoomIndex.toString()]) 133 if (!Viewport.ZOOM_RATIOS[zoomIndex.toString()])
136 return; 134 return;
137 this.zoomIndex_ = zoomIndex; 135 this.zoomIndex_ = zoomIndex;
138 this.zoom_ = Viewport.ZOOM_RATIOS[zoomIndex]; 136 this.zoom_ = Viewport.ZOOM_RATIOS[zoomIndex];
139 this.update(); 137 this.update_();
140 }; 138 };
141 139
142 /** 140 /**
143 * Returns the current zoom index. 141 * Returns the current zoom index.
144 * @return {number} Zoon index. 142 * @return {number} Zoon index.
145 */ 143 */
146 Viewport.prototype.getZoomIndex = function() { 144 Viewport.prototype.getZoomIndex = function() {
147 return this.zoomIndex_; 145 return this.zoomIndex_;
148 }; 146 };
149 147
150 /** 148 /**
151 * @return {number} Scale. 149 * Returns the value of zoom.
150 * @return {number} Zoom value.
152 */ 151 */
153 Viewport.prototype.getScale = function() { return this.scale_; }; 152 Viewport.prototype.getZoom = function() {
154 153 return this.zoomIndex_;
155 /**
156 * @param {number} scale The new scale.
157 */
158 Viewport.prototype.setScale = function(scale) {
159 if (this.scale_ == scale)
160 return;
161 this.scale_ = scale;
162 this.update();
163 this.invalidateCaches();
164 }; 154 };
165 155
166 /** 156 /**
167 * @return {number} Best scale to fit the current image into the current screen.
168 */
169 Viewport.prototype.getFittingScale = function() {
170 return this.getFittingScaleForImageSize_(
171 this.imageBounds_.width, this.imageBounds_.height);
172 };
173
174 /**
175 * Obtains the scale for the specified image size. 157 * Obtains the scale for the specified image size.
176 * 158 *
177 * @param {number} width Width of the full resolution image. 159 * @param {number} width Width of the full resolution image.
178 * @param {number} height Height of the full resolution image. 160 * @param {number} height Height of the full resolution image.
179 * @return {number} The ratio of the fullresotion image size and the calculated 161 * @return {number} The ratio of the fullresotion image size and the calculated
180 * displayed image size. 162 * displayed image size.
181 */ 163 */
182 Viewport.prototype.getFittingScaleForImageSize_ = function(width, height) { 164 Viewport.prototype.getFittingScaleForImageSize_ = function(width, height) {
183 var scaleX = this.screenBounds_.width / width; 165 var scaleX = this.screenBounds_.width / width;
184 var scaleY = this.screenBounds_.height / height; 166 var scaleY = this.screenBounds_.height / height;
185 // Scales > (1 / devicePixelRatio) do not look good. Also they are 167 // Scales > (1 / devicePixelRatio) do not look good. Also they are
186 // not really useful as we do not have any pixel-level operations. 168 // not really useful as we do not have any pixel-level operations.
187 return Math.min(1 / window.devicePixelRatio, scaleX, scaleY); 169 return Math.min(1 / window.devicePixelRatio, scaleX, scaleY);
188 }; 170 };
189 171
190 /** 172 /**
191 * Set the scale to fit the image into the screen.
192 */
193 Viewport.prototype.fitImage = function() {
194 this.setScale(this.getFittingScale());
195 };
196
197 /**
198 * @return {number} X-offset of the viewport. 173 * @return {number} X-offset of the viewport.
199 */ 174 */
200 Viewport.prototype.getOffsetX = function() { return this.offsetX_; }; 175 Viewport.prototype.getOffsetX = function() { return this.offsetX_; };
201 176
202 /** 177 /**
203 * @return {number} Y-offset of the viewport. 178 * @return {number} Y-offset of the viewport.
204 */ 179 */
205 Viewport.prototype.getOffsetY = function() { return this.offsetY_; }; 180 Viewport.prototype.getOffsetY = function() { return this.offsetY_; };
206 181
207 /** 182 /**
208 * Set the image offset in the viewport. 183 * Set the image offset in the viewport.
209 * @param {number} x X-offset. 184 * @param {number} x X-offset.
210 * @param {number} y Y-offset. 185 * @param {number} y Y-offset.
211 * @param {boolean} ignoreClipping True if no clipping should be applied.
212 */ 186 */
213 Viewport.prototype.setOffset = function(x, y, ignoreClipping) { 187 Viewport.prototype.setOffset = function(x, y) {
214 if (!ignoreClipping) { 188 if (this.offsetX_ == x && this.offsetY_ == y)
215 x = this.clampOffsetX_(x); 189 return;
216 y = this.clampOffsetY_(y);
217 }
218 if (this.offsetX_ == x && this.offsetY_ == y) return;
219 this.offsetX_ = x; 190 this.offsetX_ = x;
220 this.offsetY_ = y; 191 this.offsetY_ = y;
221 this.invalidateCaches(); 192 this.update_();
222 }; 193 };
223 194
224 /** 195 /**
225 * @return {Rect} The image bounds in image coordinates. 196 * @return {Rect} The image bounds in image coordinates.
226 */ 197 */
227 Viewport.prototype.getImageBounds = function() { return this.imageBounds_; }; 198 Viewport.prototype.getImageBounds = function() { return this.imageBounds_; };
228 199
229 /** 200 /**
230 * @return {Rect} The screen bounds in screen coordinates. 201 * @return {Rect} The screen bounds in screen coordinates.
231 */ 202 */
(...skipping 11 matching lines...) Expand all
243 214
244 /** 215 /**
245 * A counter that is incremented with each viewport state change. 216 * A counter that is incremented with each viewport state change.
246 * Clients that cache anything that depends on the viewport state should keep 217 * Clients that cache anything that depends on the viewport state should keep
247 * track of this counter. 218 * track of this counter.
248 * @return {number} counter. 219 * @return {number} counter.
249 */ 220 */
250 Viewport.prototype.getCacheGeneration = function() { return this.generation_; }; 221 Viewport.prototype.getCacheGeneration = function() { return this.generation_; };
251 222
252 /** 223 /**
253 * Called on event view port state change.
254 */
255 Viewport.prototype.invalidateCaches = function() { this.generation_++; };
256
257 /**
258 * @return {Rect} The image bounds in screen coordinates. 224 * @return {Rect} The image bounds in screen coordinates.
259 */ 225 */
260 Viewport.prototype.getImageBoundsOnScreen = function() { 226 Viewport.prototype.getImageBoundsOnScreen = function() {
261 return this.imageBoundsOnScreen_; 227 return this.imageBoundsOnScreen_;
262 }; 228 };
263 229
264 /** 230 /**
265 * The image bounds in screen coordinates. 231 * The image bounds in screen coordinates.
266 * This returns the bounds of element before applying zoom and offset. 232 * This returns the bounds of element before applying zoom and offset.
267 * @return {Rect} 233 * @return {Rect}
268 */ 234 */
269 Viewport.prototype.getImageElementBoundsOnScreen = function() { 235 Viewport.prototype.getImageElementBoundsOnScreen = function() {
270 return this.imageElementBoundsOnScreen_; 236 return this.imageElementBoundsOnScreen_;
271 }; 237 };
272 238
273 /** 239 /**
274 * The image bounds on screen, which is clipped with the screen size. 240 * The image bounds on screen, which is clipped with the screen size.
275 * @return {Rect} 241 * @return {Rect}
276 */ 242 */
277 Viewport.prototype.getImageBoundsOnScreenClipped = function() { 243 Viewport.prototype.getImageBoundsOnScreenClipped = function() {
278 return this.imageBoundsOnScreenClipped_; 244 return this.imageBoundsOnScreenClipped_;
279 }; 245 };
280 246
281 /** 247 /**
282 * @param {number} size Size in screen coordinates. 248 * @param {number} size Size in screen coordinates.
283 * @return {number} Size in image coordinates. 249 * @return {number} Size in image coordinates.
284 */ 250 */
285 Viewport.prototype.screenToImageSize = function(size) { 251 Viewport.prototype.screenToImageSize = function(size) {
286 return size / this.getScale(); 252 return size / this.scale_;
287 }; 253 };
288 254
289 /** 255 /**
290 * @param {number} x X in screen coordinates. 256 * @param {number} x X in screen coordinates.
291 * @return {number} X in image coordinates. 257 * @return {number} X in image coordinates.
292 */ 258 */
293 Viewport.prototype.screenToImageX = function(x) { 259 Viewport.prototype.screenToImageX = function(x) {
294 return Math.round((x - this.imageBoundsOnScreen_.left) / this.getScale()); 260 return Math.round((x - this.imageBoundsOnScreen_.left) / this.scale_);
295 }; 261 };
296 262
297 /** 263 /**
298 * @param {number} y Y in screen coordinates. 264 * @param {number} y Y in screen coordinates.
299 * @return {number} Y in image coordinates. 265 * @return {number} Y in image coordinates.
300 */ 266 */
301 Viewport.prototype.screenToImageY = function(y) { 267 Viewport.prototype.screenToImageY = function(y) {
302 return Math.round((y - this.imageBoundsOnScreen_.top) / this.getScale()); 268 return Math.round((y - this.imageBoundsOnScreen_.top) / this.scale_);
303 }; 269 };
304 270
305 /** 271 /**
306 * @param {Rect} rect Rectangle in screen coordinates. 272 * @param {Rect} rect Rectangle in screen coordinates.
307 * @return {Rect} Rectangle in image coordinates. 273 * @return {Rect} Rectangle in image coordinates.
308 */ 274 */
309 Viewport.prototype.screenToImageRect = function(rect) { 275 Viewport.prototype.screenToImageRect = function(rect) {
310 return new Rect( 276 return new Rect(
311 this.screenToImageX(rect.left), 277 this.screenToImageX(rect.left),
312 this.screenToImageY(rect.top), 278 this.screenToImageY(rect.top),
313 this.screenToImageSize(rect.width), 279 this.screenToImageSize(rect.width),
314 this.screenToImageSize(rect.height)); 280 this.screenToImageSize(rect.height));
315 }; 281 };
316 282
317 /** 283 /**
318 * @param {number} size Size in image coordinates. 284 * @param {number} size Size in image coordinates.
319 * @return {number} Size in screen coordinates. 285 * @return {number} Size in screen coordinates.
320 */ 286 */
321 Viewport.prototype.imageToScreenSize = function(size) { 287 Viewport.prototype.imageToScreenSize = function(size) {
322 return size * this.getScale(); 288 return size * this.scale_;
323 }; 289 };
324 290
325 /** 291 /**
326 * @param {number} x X in image coordinates. 292 * @param {number} x X in image coordinates.
327 * @return {number} X in screen coordinates. 293 * @return {number} X in screen coordinates.
328 */ 294 */
329 Viewport.prototype.imageToScreenX = function(x) { 295 Viewport.prototype.imageToScreenX = function(x) {
330 return Math.round(this.imageBoundsOnScreen_.left + x * this.getScale()); 296 return Math.round(this.imageBoundsOnScreen_.left + x * this.scale_);
331 }; 297 };
332 298
333 /** 299 /**
334 * @param {number} y Y in image coordinates. 300 * @param {number} y Y in image coordinates.
335 * @return {number} Y in screen coordinates. 301 * @return {number} Y in screen coordinates.
336 */ 302 */
337 Viewport.prototype.imageToScreenY = function(y) { 303 Viewport.prototype.imageToScreenY = function(y) {
338 return Math.round(this.imageBoundsOnScreen_.top + y * this.getScale()); 304 return Math.round(this.imageBoundsOnScreen_.top + y * this.scale_);
339 }; 305 };
340 306
341 /** 307 /**
342 * @param {Rect} rect Rectangle in image coordinates. 308 * @param {Rect} rect Rectangle in image coordinates.
343 * @return {Rect} Rectangle in screen coordinates. 309 * @return {Rect} Rectangle in screen coordinates.
344 */ 310 */
345 Viewport.prototype.imageToScreenRect = function(rect) { 311 Viewport.prototype.imageToScreenRect = function(rect) {
346 return new Rect( 312 return new Rect(
347 this.imageToScreenX(rect.left), 313 this.imageToScreenX(rect.left),
348 this.imageToScreenY(rect.top), 314 this.imageToScreenY(rect.top),
(...skipping 27 matching lines...) Expand all
376 return Math.round( 342 return Math.round(
377 (this.screenBounds_.height - this.imageBounds_.height * this.scale_) / 2); 343 (this.screenBounds_.height - this.imageBounds_.height * this.scale_) / 2);
378 }; 344 };
379 345
380 /** 346 /**
381 * @param {number} x X-offset. 347 * @param {number} x X-offset.
382 * @return {number} X-offset clamped to the valid range. 348 * @return {number} X-offset clamped to the valid range.
383 * @private 349 * @private
384 */ 350 */
385 Viewport.prototype.clampOffsetX_ = function(x) { 351 Viewport.prototype.clampOffsetX_ = function(x) {
386 var limit = Math.round(Math.max(0, -this.getMarginX_() / this.getScale())); 352 var limit = Math.round(Math.max(0, -this.getMarginX_() / this.scale_));
387 return ImageUtil.clamp(-limit, x, limit); 353 return ImageUtil.clamp(-limit, x, limit);
388 }; 354 };
389 355
390 /** 356 /**
391 * @param {number} y Y-offset. 357 * @param {number} y Y-offset.
392 * @return {number} Y-offset clamped to the valid range. 358 * @return {number} Y-offset clamped to the valid range.
393 * @private 359 * @private
394 */ 360 */
395 Viewport.prototype.clampOffsetY_ = function(y) { 361 Viewport.prototype.clampOffsetY_ = function(y) {
396 var limit = Math.round(Math.max(0, -this.getMarginY_() / this.getScale())); 362 var limit = Math.round(Math.max(0, -this.getMarginY_() / this.scale_));
397 return ImageUtil.clamp(-limit, y, limit); 363 return ImageUtil.clamp(-limit, y, limit);
398 }; 364 };
399 365
400 /** 366 /**
401 * @private 367 * @private
402 */ 368 */
403 Viewport.prototype.getCenteredRect_ = function( 369 Viewport.prototype.getCenteredRect_ = function(
404 width, height, offsetX, offsetY) { 370 width, height, offsetX, offsetY) {
405 return new Rect( 371 return new Rect(
406 ~~((this.screenBounds_.width - width) / 2) + offsetX, 372 ~~((this.screenBounds_.width - width) / 2) + offsetX,
407 ~~((this.screenBounds_.height - height) / 2) + offsetY, 373 ~~((this.screenBounds_.height - height) / 2) + offsetY,
408 width, 374 width,
409 height); 375 height);
410 }; 376 };
411 377
412 /** 378 /**
379 * Resets zoom and offset.
380 */
381 Viewport.prototype.resetView = function() {
382 this.zoomIndex_ = 0;
383 this.zoom_ = 1;
384 this.offsetX_ = 0;
385 this.offsetY_ = 0;
386 this.update_();
387 };
388
389 /**
413 * Recalculate the viewport parameters. 390 * Recalculate the viewport parameters.
391 * @private
414 */ 392 */
415 Viewport.prototype.update = function() { 393 Viewport.prototype.update_ = function() {
416 var scale = this.getScale(); 394 // Update scale.
395 this.scale_ = this.getFittingScaleForImageSize_(
396 this.imageBounds_.width, this.imageBounds_.height);
397
398 // Limit offset values.
399 var zoomedWidht = ~~(this.imageBounds_.width * this.scale_ * this.zoom_);
400 var zoomedHeight = ~~(this.imageBounds_.height * this.scale_ * this.zoom_);
401 var dx = Math.max(zoomedWidht - this.screenBounds_.width, 0) / 2;
402 var dy = Math.max(zoomedHeight - this.screenBounds_.height, 0) /2;
403 this.offsetX_ = ImageUtil.clamp(-dx, this.offsetX_, dx);
404 this.offsetY_ = ImageUtil.clamp(-dy, this.offsetY_, dy);
417 405
418 // Image bounds on screen. 406 // Image bounds on screen.
419 this.imageBoundsOnScreen_ = this.getCenteredRect_( 407 this.imageBoundsOnScreen_ = this.getCenteredRect_(
420 ~~(this.imageBounds_.width * scale * this.zoom_), 408 zoomedWidht, zoomedHeight, this.offsetX_, this.offsetY_);
421 ~~(this.imageBounds_.height * scale * this.zoom_),
422 this.offsetX_,
423 this.offsetY_);
424 409
425 // Image bounds of element (that is not applied zoom and offset) on screen. 410 // Image bounds of element (that is not applied zoom and offset) on screen.
411 var oldBounds = this.imageElementBoundsOnScreen_;
426 this.imageElementBoundsOnScreen_ = this.getCenteredRect_( 412 this.imageElementBoundsOnScreen_ = this.getCenteredRect_(
427 ~~(this.imageBounds_.width * scale), 413 ~~(this.imageBounds_.width * this.scale_),
428 ~~(this.imageBounds_.height * scale), 414 ~~(this.imageBounds_.height * this.scale_),
429 0, 415 0,
430 0); 416 0);
417 if (!oldBounds ||
418 this.imageElementBoundsOnScreen_.width != oldBounds.width ||
419 this.imageElementBoundsOnScreen_.height != oldBounds.height) {
420 this.generation_++;
421 }
431 422
432 // Image bounds on screen cliped with the screen bounds. 423 // Image bounds on screen cliped with the screen bounds.
433 var left = Math.max(this.imageBoundsOnScreen_.left, 0); 424 var left = Math.max(this.imageBoundsOnScreen_.left, 0);
434 var top = Math.max(this.imageBoundsOnScreen_.top, 0); 425 var top = Math.max(this.imageBoundsOnScreen_.top, 0);
435 var right = Math.min( 426 var right = Math.min(
436 this.imageBoundsOnScreen_.right, this.screenBounds_.width); 427 this.imageBoundsOnScreen_.right, this.screenBounds_.width);
437 var bottom = Math.min( 428 var bottom = Math.min(
438 this.imageBoundsOnScreen_.bottom, this.screenBounds_.height); 429 this.imageBoundsOnScreen_.bottom, this.screenBounds_.height);
439 this.imageBoundsOnScreenClipped_ = new Rect( 430 this.imageBoundsOnScreenClipped_ = new Rect(
440 left, top, right - left, bottom - top); 431 left, top, right - left, bottom - top);
441 }; 432 };
442 433
443 /** 434 /**
444 * Obtains CSS transformation for the screen image. 435 * Obtains CSS transformation for the screen image.
445 * @return {string} Transformation description. 436 * @return {string} Transformation description.
446 */ 437 */
447 Viewport.prototype.getTransformation = function() { 438 Viewport.prototype.getTransformation = function() {
448 return 'scale(' + (1 / window.devicePixelRatio * this.zoom_) + ')'; 439 return 'translate(' + this.offsetX_ + 'px, ' + this.offsetY_ + 'px) ' +
440 'scale(' + (1 / window.devicePixelRatio * this.zoom_) + ')';
449 }; 441 };
450 442
451 /** 443 /**
452 * Obtains shift CSS transformation for the screen image. 444 * Obtains shift CSS transformation for the screen image.
453 * @param {number} dx Amount of shift. 445 * @param {number} dx Amount of shift.
454 * @return {string} Transformation description. 446 * @return {string} Transformation description.
455 */ 447 */
456 Viewport.prototype.getShiftTransformation = function(dx) { 448 Viewport.prototype.getShiftTransformation = function(dx) {
457 return 'translateX(' + dx + 'px) ' + this.getTransformation(); 449 return 'translateX(' + dx + 'px) ' + this.getTransformation();
458 }; 450 };
459 451
460 /** 452 /**
461 * Obtains CSS transformation that makes the rotated image fit the original 453 * Obtains CSS transformation that makes the rotated image fit the original
462 * image. The new rotated image that the transformation is applied to looks the 454 * image. The new rotated image that the transformation is applied to looks the
463 * same with original image. 455 * same with original image.
464 * 456 *
465 * @param {boolean} orientation Orientation of the rotation from the original 457 * @param {boolean} orientation Orientation of the rotation from the original
466 * image to the rotated image. True is for clockwise and false is for 458 * image to the rotated image. True is for clockwise and false is for
467 * counterclockwise. 459 * counterclockwise.
468 * @return {string} Transformation description. 460 * @return {string} Transformation description.
469 */ 461 */
470 Viewport.prototype.getInverseTransformForRotatedImage = function(orientation) { 462 Viewport.prototype.getInverseTransformForRotatedImage = function(orientation) {
471 var previousImageWidth = this.imageBounds_.height; 463 var previousImageWidth = this.imageBounds_.height;
472 var previousImageHeight = this.imageBounds_.width; 464 var previousImageHeight = this.imageBounds_.width;
473 var oldScale = this.getFittingScaleForImageSize_( 465 var oldScale = this.getFittingScaleForImageSize_(
474 previousImageWidth, previousImageHeight); 466 previousImageWidth, previousImageHeight);
475 var scaleRatio = oldScale / this.getScale(); 467 var scaleRatio = oldScale / this.scale_;
476 var degree = orientation ? '-90deg' : '90deg'; 468 var degree = orientation ? '-90deg' : '90deg';
477 return [ 469 return [
478 'scale(' + scaleRatio + ')', 470 'scale(' + scaleRatio + ')',
479 'rotate(' + degree + ')', 471 'rotate(' + degree + ')',
480 this.getTransformation() 472 this.getTransformation()
481 ].join(' '); 473 ].join(' ');
482 }; 474 };
483 475
484 /** 476 /**
485 * Obtains CSS transformation that makes the cropped image fit the original 477 * Obtains CSS transformation that makes the cropped image fit the original
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 var screenWidth = this.screenBounds_.width; 515 var screenWidth = this.screenBounds_.width;
524 var screenHeight = this.screenBounds_.height; 516 var screenHeight = this.screenBounds_.height;
525 var dx = screenRect.left + screenRect.width / 2 - screenWidth / 2; 517 var dx = screenRect.left + screenRect.width / 2 - screenWidth / 2;
526 var dy = screenRect.top + screenRect.height / 2 - screenHeight / 2; 518 var dy = screenRect.top + screenRect.height / 2 - screenHeight / 2;
527 return [ 519 return [
528 'translate(' + dx + 'px,' + dy + 'px)', 520 'translate(' + dx + 'px,' + dy + 'px)',
529 'scale(' + scaleX + ',' + scaleY + ')', 521 'scale(' + scaleX + ',' + scaleY + ')',
530 this.getTransformation() 522 this.getTransformation()
531 ].join(' '); 523 ].join(' ');
532 }; 524 };
OLDNEW
« no previous file with comments | « ui/file_manager/gallery/js/image_editor/image_view.js ('k') | ui/file_manager/gallery/js/slide_mode.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698