OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 }; |
OLD | NEW |