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

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

Issue 1294303003: Gallery: fix coordinate calculation of viewport.js. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « no previous file | no next file » | 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 /** 5 /**
6 * Formats string by replacing place holder with actual values. 6 * Formats string by replacing place holder with actual values.
7 * @param {string} str String includes placeholder '$n'. n starts from 1. 7 * @param {string} str String includes placeholder '$n'. n starts from 1.
8 * @param {...*} var_args Values inserted into the place holders. 8 * @param {...*} var_args Values inserted into the place holders.
9 * @return {string} 9 * @return {string}
10 */ 10 */
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 * Returns a rectangle with given geometry. 441 * Returns a rectangle with given geometry.
442 * @param {number} width Width of the rectangle. 442 * @param {number} width Width of the rectangle.
443 * @param {number} height Height of the rectangle. 443 * @param {number} height Height of the rectangle.
444 * @param {number} offsetX X-offset of center position of the rectangle. 444 * @param {number} offsetX X-offset of center position of the rectangle.
445 * @param {number} offsetY Y-offset of center position of the rectangle. 445 * @param {number} offsetY Y-offset of center position of the rectangle.
446 * @return {!ImageRect} Rectangle with given geometry. 446 * @return {!ImageRect} Rectangle with given geometry.
447 * @private 447 * @private
448 */ 448 */
449 Viewport.prototype.getCenteredRect_ = function( 449 Viewport.prototype.getCenteredRect_ = function(
450 width, height, offsetX, offsetY) { 450 width, height, offsetX, offsetY) {
451 var screenBounds = this.getScreenBounds();
451 return new ImageRect( 452 return new ImageRect(
452 ~~((this.getScreenBounds().width - width) / 2) + offsetX, 453 ~~((screenBounds.width - width) / 2) + offsetX,
453 ~~((this.getScreenBounds().height - height) / 2) + offsetY, 454 ~~((screenBounds.height - height) / 2) + screenBounds.top + offsetY,
454 width, 455 width,
455 height); 456 height);
456 }; 457 };
457 458
458 /** 459 /**
459 * Resets zoom and offset. 460 * Resets zoom and offset.
460 */ 461 */
461 Viewport.prototype.resetView = function() { 462 Viewport.prototype.resetView = function() {
462 this.zoom_ = 1; 463 this.zoom_ = 1;
463 this.offsetX_ = 0; 464 this.offsetX_ = 0;
(...skipping 26 matching lines...) Expand all
490 zoomedHeight = ~~(this.imageBounds_.width * scale * this.zoom_); 491 zoomedHeight = ~~(this.imageBounds_.width * scale * this.zoom_);
491 } 492 }
492 var dx = Math.max(zoomedWidht - this.getScreenBounds().width, 0) / 2; 493 var dx = Math.max(zoomedWidht - this.getScreenBounds().width, 0) / 2;
493 var dy = Math.max(zoomedHeight - this.getScreenBounds().height, 0) / 2; 494 var dy = Math.max(zoomedHeight - this.getScreenBounds().height, 0) / 2;
494 this.offsetX_ = ImageUtil.clamp(-dx, this.offsetX_, dx); 495 this.offsetX_ = ImageUtil.clamp(-dx, this.offsetX_, dx);
495 this.offsetY_ = ImageUtil.clamp(-dy, this.offsetY_, dy); 496 this.offsetY_ = ImageUtil.clamp(-dy, this.offsetY_, dy);
496 497
497 // Image bounds on screen. 498 // Image bounds on screen.
498 this.imageBoundsOnScreen_ = this.getCenteredRect_( 499 this.imageBoundsOnScreen_ = this.getCenteredRect_(
499 zoomedWidht, zoomedHeight, this.offsetX_, this.offsetY_); 500 zoomedWidht, zoomedHeight, this.offsetX_, this.offsetY_);
500 this.imageBoundsOnScreen_.top += this.screenTop_;
501 501
502 // Image bounds of element (that is not applied zoom and offset) on screen. 502 // Image bounds of element (that is not applied zoom and offset) on screen.
503 var oldBounds = this.imageElementBoundsOnScreen_; 503 var oldBounds = this.imageElementBoundsOnScreen_;
504 this.imageElementBoundsOnScreen_ = this.getCenteredRect_( 504 this.imageElementBoundsOnScreen_ = this.getCenteredRect_(
505 ~~(this.imageBounds_.width * this.scale_), 505 ~~(this.imageBounds_.width * this.scale_),
506 ~~(this.imageBounds_.height * this.scale_), 506 ~~(this.imageBounds_.height * this.scale_),
507 0, 507 0,
508 0); 508 0);
509 if (!oldBounds || 509 if (!oldBounds ||
510 this.imageElementBoundsOnScreen_.width != oldBounds.width || 510 this.imageElementBoundsOnScreen_.width != oldBounds.width ||
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 * @param {number=} opt_dx Amount of horizontal shift. 603 * @param {number=} opt_dx Amount of horizontal shift.
604 * @return {string} Transformation description. 604 * @return {string} Transformation description.
605 */ 605 */
606 Viewport.prototype.getTransformation = function(width, height, opt_dx) { 606 Viewport.prototype.getTransformation = function(width, height, opt_dx) {
607 return this.getTransformationInternal_( 607 return this.getTransformationInternal_(
608 width, 608 width,
609 height, 609 height,
610 this.rotation_, 610 this.rotation_,
611 this.zoom_, 611 this.zoom_,
612 this.offsetX_ + (opt_dx || 0), 612 this.offsetX_ + (opt_dx || 0),
613 this.offsetY_ + this.screenTop_); 613 this.offsetY_);
614 }; 614 };
615 615
616 /** 616 /**
617 * Obtains CSS transformation that makes the rotated image fit the original 617 * Obtains CSS transformation that makes the rotated image fit the original
618 * image. The new rotated image that the transformation is applied to looks the 618 * image. The new rotated image that the transformation is applied to looks the
619 * same with original image. 619 * same with original image.
620 * 620 *
621 * @param {number} width Width of image. 621 * @param {number} width Width of image.
622 * @param {number} height Height of image. 622 * @param {number} height Height of image.
623 * @param {number} rotation Number of clockwise 90 degree rotation. The rotation 623 * @param {number} rotation Number of clockwise 90 degree rotation. The rotation
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 661
662 // Offset for centering. 662 // Offset for centering.
663 var rect = this.getCenteredRect_(width, height, offsetX, offsetY); 663 var rect = this.getCenteredRect_(width, height, offsetX, offsetY);
664 return formatString( 664 return formatString(
665 'translate($1px,$2px) scale($3) rotate($4deg)', 665 'translate($1px,$2px) scale($3) rotate($4deg)',
666 rect.left, 666 rect.left,
667 rect.top, 667 rect.top,
668 fittingScale * zoom, 668 fittingScale * zoom,
669 rotation * 90); 669 rotation * 90);
670 }; 670 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698