Chromium Code Reviews| 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 '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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 ImageUtil.trace.reportTimer('paint'); | 109 ImageUtil.trace.reportTimer('paint'); |
| 110 } | 110 } |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 /** | 113 /** |
| 114 * 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 |
| 115 * change or offset change) with animation. | 115 * change or offset change) with animation. |
| 116 */ | 116 */ |
| 117 ImageView.prototype.applyViewportChange = function() { | 117 ImageView.prototype.applyViewportChange = function() { |
| 118 if (this.screenImage_) { | 118 if (this.screenImage_) { |
| 119 this.setTransform( | 119 this.setTransform_( |
| 120 this.screenImage_, | 120 this.screenImage_, |
| 121 this.viewport_, | |
| 121 new ImageView.Effect.None(), | 122 new ImageView.Effect.None(), |
| 122 ImageView.Effect.DEFAULT_DURATION); | 123 ImageView.Effect.DEFAULT_DURATION); |
| 123 } | 124 } |
| 124 }; | 125 }; |
| 125 | 126 |
| 126 /** | 127 /** |
| 127 * @return {number} The cache generation. | 128 * @return {number} The cache generation. |
| 128 */ | 129 */ |
| 129 ImageView.prototype.getCacheGeneration = function() { | 130 ImageView.prototype.getCacheGeneration = function() { |
| 130 return this.contentGeneration_; | 131 return this.contentGeneration_; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 needRepaint = true; | 218 needRepaint = true; |
| 218 } | 219 } |
| 219 | 220 |
| 220 // Center the image. | 221 // Center the image. |
| 221 var imageBounds = this.viewport_.getImageElementBoundsOnScreen(); | 222 var imageBounds = this.viewport_.getImageElementBoundsOnScreen(); |
| 222 canvas.style.left = imageBounds.left + 'px'; | 223 canvas.style.left = imageBounds.left + 'px'; |
| 223 canvas.style.top = imageBounds.top + 'px'; | 224 canvas.style.top = imageBounds.top + 'px'; |
| 224 canvas.style.width = imageBounds.width + 'px'; | 225 canvas.style.width = imageBounds.width + 'px'; |
| 225 canvas.style.height = imageBounds.height + 'px'; | 226 canvas.style.height = imageBounds.height + 'px'; |
| 226 | 227 |
| 227 this.setTransform(canvas); | 228 this.setTransform_(canvas, this.viewport_); |
| 228 | 229 |
| 229 return needRepaint; | 230 return needRepaint; |
| 230 }; | 231 }; |
| 231 | 232 |
| 232 /** | 233 /** |
| 233 * @return {ImageData} A new ImageData object with a copy of the content. | 234 * @return {ImageData} A new ImageData object with a copy of the content. |
| 234 */ | 235 */ |
| 235 ImageView.prototype.copyScreenImageData = function() { | 236 ImageView.prototype.copyScreenImageData = function() { |
| 236 return this.screenImage_.getContext('2d').getImageData( | 237 return this.screenImage_.getContext('2d').getImageData( |
| 237 0, 0, this.screenImage_.width, this.screenImage_.height); | 238 0, 0, this.screenImage_.width, this.screenImage_.height); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 * Unloads content. | 442 * Unloads content. |
| 442 * @param {Rect} zoomToRect Target rectangle for zoom-out-effect. | 443 * @param {Rect} zoomToRect Target rectangle for zoom-out-effect. |
| 443 */ | 444 */ |
| 444 ImageView.prototype.unload = function(zoomToRect) { | 445 ImageView.prototype.unload = function(zoomToRect) { |
| 445 if (this.unloadTimer_) { | 446 if (this.unloadTimer_) { |
| 446 clearTimeout(this.unloadTimer_); | 447 clearTimeout(this.unloadTimer_); |
| 447 this.unloadTimer_ = null; | 448 this.unloadTimer_ = null; |
| 448 } | 449 } |
| 449 if (zoomToRect && this.screenImage_) { | 450 if (zoomToRect && this.screenImage_) { |
| 450 var effect = this.createZoomEffect(zoomToRect); | 451 var effect = this.createZoomEffect(zoomToRect); |
| 451 this.setTransform(this.screenImage_, effect); | 452 this.setTransform_(this.screenImage_, this.viewport_, effect); |
| 452 this.screenImage_.setAttribute('fade', true); | 453 this.screenImage_.setAttribute('fade', true); |
| 453 this.unloadTimer_ = setTimeout(function() { | 454 this.unloadTimer_ = setTimeout(function() { |
| 454 this.unloadTimer_ = null; | 455 this.unloadTimer_ = null; |
| 455 this.unload(null /* force unload */); | 456 this.unload(null /* force unload */); |
| 456 }.bind(this), | 457 }.bind(this), |
| 457 effect.getSafeInterval()); | 458 effect.getSafeInterval()); |
| 458 return; | 459 return; |
| 459 } | 460 } |
| 460 this.container_.textContent = ''; | 461 this.container_.textContent = ''; |
| 461 this.contentCanvas_ = null; | 462 this.contentCanvas_ = null; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 * | 546 * |
| 546 * @param {HTMLCanvasElement} content The image element. | 547 * @param {HTMLCanvasElement} content The image element. |
| 547 * @param {Object=} opt_effect Transition effect object. | 548 * @param {Object=} opt_effect Transition effect object. |
| 548 * @param {number=} opt_width Image width. | 549 * @param {number=} opt_width Image width. |
| 549 * @param {number=} opt_height Image height. | 550 * @param {number=} opt_height Image height. |
| 550 * @param {boolean=} opt_preview True if the image is a preview (not full res). | 551 * @param {boolean=} opt_preview True if the image is a preview (not full res). |
| 551 */ | 552 */ |
| 552 ImageView.prototype.replace = function( | 553 ImageView.prototype.replace = function( |
| 553 content, opt_effect, opt_width, opt_height, opt_preview) { | 554 content, opt_effect, opt_width, opt_height, opt_preview) { |
| 554 var oldScreenImage = this.screenImage_; | 555 var oldScreenImage = this.screenImage_; |
| 556 var oldViewport = this.viewport_.clone(); | |
|
mtomasz
2014/07/24 09:59:25
Do we need to clone? How about just creating a new
hirono
2014/07/24 10:13:08
It would not work because the viewport is shared b
| |
| 555 | 557 |
| 556 this.replaceContent_(content, opt_width, opt_height, opt_preview); | 558 this.replaceContent_(content, opt_width, opt_height, opt_preview); |
| 557 if (!opt_effect) { | 559 if (!opt_effect) { |
| 558 if (oldScreenImage) | 560 if (oldScreenImage) |
| 559 oldScreenImage.parentNode.removeChild(oldScreenImage); | 561 oldScreenImage.parentNode.removeChild(oldScreenImage); |
| 560 return; | 562 return; |
| 561 } | 563 } |
| 562 | 564 |
| 563 var newScreenImage = this.screenImage_; | 565 var newScreenImage = this.screenImage_; |
| 566 this.viewport_.resetView(); | |
| 564 | 567 |
| 565 if (oldScreenImage) | 568 if (oldScreenImage) |
| 566 ImageUtil.setAttribute(newScreenImage, 'fade', true); | 569 ImageUtil.setAttribute(newScreenImage, 'fade', true); |
| 567 this.setTransform(newScreenImage, opt_effect, 0 /* instant */); | 570 this.setTransform_( |
| 571 newScreenImage, this.viewport_, opt_effect, 0 /* instant */); | |
| 568 | 572 |
| 569 setTimeout(function() { | 573 setTimeout(function() { |
| 570 this.setTransform(newScreenImage, null, | 574 this.setTransform_( |
| 575 newScreenImage, | |
| 576 this.viewport_, | |
| 577 null, | |
| 571 opt_effect && opt_effect.getDuration()); | 578 opt_effect && opt_effect.getDuration()); |
| 572 if (oldScreenImage) { | 579 if (oldScreenImage) { |
| 573 ImageUtil.setAttribute(newScreenImage, 'fade', false); | 580 ImageUtil.setAttribute(newScreenImage, 'fade', false); |
| 574 ImageUtil.setAttribute(oldScreenImage, 'fade', true); | 581 ImageUtil.setAttribute(oldScreenImage, 'fade', true); |
| 575 console.assert(opt_effect.getReverse, 'Cannot revert an effect.'); | 582 console.assert(opt_effect.getReverse, 'Cannot revert an effect.'); |
| 576 var reverse = opt_effect.getReverse(); | 583 var reverse = opt_effect.getReverse(); |
| 577 this.setTransform(oldScreenImage, reverse); | 584 this.setTransform_(oldScreenImage, oldViewport, reverse); |
| 578 setTimeout(function() { | 585 setTimeout(function() { |
| 579 if (oldScreenImage.parentNode) | 586 if (oldScreenImage.parentNode) |
| 580 oldScreenImage.parentNode.removeChild(oldScreenImage); | 587 oldScreenImage.parentNode.removeChild(oldScreenImage); |
| 581 }, reverse.getSafeInterval()); | 588 }, reverse.getSafeInterval()); |
| 582 } | 589 } |
| 583 }.bind(this), 0); | 590 }.bind(this)); |
| 584 }; | 591 }; |
| 585 | 592 |
| 586 /** | 593 /** |
| 587 * @param {HTMLCanvasElement} element The element to transform. | 594 * @param {HTMLCanvasElement} element The element to transform. |
| 595 * @param {Viewport} viewport Viewport to be used for calculating | |
| 596 * transformation. | |
| 588 * @param {ImageView.Effect=} opt_effect The effect to apply. | 597 * @param {ImageView.Effect=} opt_effect The effect to apply. |
| 589 * @param {number=} opt_duration Transition duration. | 598 * @param {number=} opt_duration Transition duration. |
| 599 * @private | |
| 590 */ | 600 */ |
| 591 ImageView.prototype.setTransform = function(element, opt_effect, opt_duration) { | 601 ImageView.prototype.setTransform_ = function( |
| 602 element, viewport, opt_effect, opt_duration) { | |
| 592 if (!opt_effect) | 603 if (!opt_effect) |
| 593 opt_effect = new ImageView.Effect.None(); | 604 opt_effect = new ImageView.Effect.None(); |
| 594 if (typeof opt_duration !== 'number') | 605 if (typeof opt_duration !== 'number') |
| 595 opt_duration = opt_effect.getDuration(); | 606 opt_duration = opt_effect.getDuration(); |
| 596 element.style.webkitTransitionDuration = opt_duration + 'ms'; | 607 element.style.webkitTransitionDuration = opt_duration + 'ms'; |
| 597 element.style.webkitTransitionTimingFunction = opt_effect.getTiming(); | 608 element.style.webkitTransitionTimingFunction = opt_effect.getTiming(); |
| 598 element.style.webkitTransform = opt_effect.transform(element, this.viewport_); | 609 element.style.webkitTransform = opt_effect.transform(element, viewport); |
| 599 }; | 610 }; |
| 600 | 611 |
| 601 /** | 612 /** |
| 602 * @param {Rect} screenRect Target rectangle in screen coordinates. | 613 * @param {Rect} screenRect Target rectangle in screen coordinates. |
| 603 * @return {ImageView.Effect.Zoom} Zoom effect object. | 614 * @return {ImageView.Effect.Zoom} Zoom effect object. |
| 604 */ | 615 */ |
| 605 ImageView.prototype.createZoomEffect = function(screenRect) { | 616 ImageView.prototype.createZoomEffect = function(screenRect) { |
| 606 return new ImageView.Effect.ZoomToScreen( | 617 return new ImageView.Effect.ZoomToScreen( |
| 607 screenRect, | 618 screenRect, |
| 608 ImageView.MODE_TRANSITION_DURATION); | 619 ImageView.MODE_TRANSITION_DURATION); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 625 height: this.viewport_.getImageBounds().height | 636 height: this.viewport_.getImageBounds().height |
| 626 }; | 637 }; |
| 627 var oldScreenImage = this.screenImage_; | 638 var oldScreenImage = this.screenImage_; |
| 628 this.replaceContent_(canvas); | 639 this.replaceContent_(canvas); |
| 629 var newScreenImage = this.screenImage_; | 640 var newScreenImage = this.screenImage_; |
| 630 var effect = rotate90 ? | 641 var effect = rotate90 ? |
| 631 new ImageView.Effect.Rotate(rotate90 > 0) : | 642 new ImageView.Effect.Rotate(rotate90 > 0) : |
| 632 new ImageView.Effect.Zoom( | 643 new ImageView.Effect.Zoom( |
| 633 oldImageBounds.width, oldImageBounds.height, imageCropRect); | 644 oldImageBounds.width, oldImageBounds.height, imageCropRect); |
| 634 | 645 |
| 635 this.setTransform(newScreenImage, effect, 0 /* instant */); | 646 this.setTransform_(newScreenImage, this.viewport_, effect, 0 /* instant */); |
| 636 | 647 |
| 637 oldScreenImage.parentNode.appendChild(newScreenImage); | 648 oldScreenImage.parentNode.appendChild(newScreenImage); |
| 638 oldScreenImage.parentNode.removeChild(oldScreenImage); | 649 oldScreenImage.parentNode.removeChild(oldScreenImage); |
| 639 | 650 |
| 640 // Let the layout fire, then animate back to non-transformed state. | 651 // Let the layout fire, then animate back to non-transformed state. |
| 641 setTimeout( | 652 setTimeout( |
| 642 this.setTransform.bind( | 653 this.setTransform_.bind( |
| 643 this, newScreenImage, null, effect.getDuration()), | 654 this, newScreenImage, this.viewport_, null, effect.getDuration()), |
| 644 0); | 655 0); |
| 645 | 656 |
| 646 return effect.getSafeInterval(); | 657 return effect.getSafeInterval(); |
| 647 }; | 658 }; |
| 648 | 659 |
| 649 /** | 660 /** |
| 650 * Visualizes "undo crop". Shrink the current image to the given crop rectangle | 661 * Visualizes "undo crop". Shrink the current image to the given crop rectangle |
| 651 * while fading in the new image. | 662 * while fading in the new image. |
| 652 * | 663 * |
| 653 * @param {HTMLCanvasElement} canvas New content canvas. | 664 * @param {HTMLCanvasElement} canvas New content canvas. |
| 654 * @param {Rect} imageCropRect The crop rectangle in image coordinates. | 665 * @param {Rect} imageCropRect The crop rectangle in image coordinates. |
| 655 * @return {number} Animation duration. | 666 * @return {number} Animation duration. |
| 656 */ | 667 */ |
| 657 ImageView.prototype.animateAndReplace = function(canvas, imageCropRect) { | 668 ImageView.prototype.animateAndReplace = function(canvas, imageCropRect) { |
| 658 var oldScreenImage = this.screenImage_; | 669 var oldScreenImage = this.screenImage_; |
| 659 this.replaceContent_(canvas); | 670 this.replaceContent_(canvas); |
| 660 var newScreenImage = this.screenImage_; | 671 var newScreenImage = this.screenImage_; |
| 661 var setFade = ImageUtil.setAttribute.bind(null, newScreenImage, 'fade'); | 672 var setFade = ImageUtil.setAttribute.bind(null, newScreenImage, 'fade'); |
| 662 setFade(true); | 673 setFade(true); |
| 663 oldScreenImage.parentNode.insertBefore(newScreenImage, oldScreenImage); | 674 oldScreenImage.parentNode.insertBefore(newScreenImage, oldScreenImage); |
| 664 var effect = new ImageView.Effect.Zoom( | 675 var effect = new ImageView.Effect.Zoom( |
| 665 this.viewport_.getImageBounds().width, | 676 this.viewport_.getImageBounds().width, |
| 666 this.viewport_.getImageBounds().height, | 677 this.viewport_.getImageBounds().height, |
| 667 imageCropRect); | 678 imageCropRect); |
| 668 | 679 |
| 669 // Animate to the transformed state. | 680 // Animate to the transformed state. |
| 670 this.setTransform(oldScreenImage, effect); | 681 this.setTransform_(oldScreenImage, this,viewport_, effect); |
| 671 setTimeout(setFade.bind(null, false), 0); | 682 setTimeout(setFade.bind(null, false), 0); |
| 672 setTimeout(function() { | 683 setTimeout(function() { |
| 673 if (oldScreenImage.parentNode) | 684 if (oldScreenImage.parentNode) |
| 674 oldScreenImage.parentNode.removeChild(oldScreenImage); | 685 oldScreenImage.parentNode.removeChild(oldScreenImage); |
| 675 }, effect.getSafeInterval()); | 686 }, effect.getSafeInterval()); |
| 676 | 687 |
| 677 return effect.getSafeInterval(); | 688 return effect.getSafeInterval(); |
| 678 }; | 689 }; |
| 679 | 690 |
| 680 /** | 691 /** |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 954 }; | 965 }; |
| 955 | 966 |
| 956 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype }; | 967 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype }; |
| 957 | 968 |
| 958 /** | 969 /** |
| 959 * @override | 970 * @override |
| 960 */ | 971 */ |
| 961 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) { | 972 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) { |
| 962 return viewport.getInverseTransformForRotatedImage(this.orientation_); | 973 return viewport.getInverseTransformForRotatedImage(this.orientation_); |
| 963 }; | 974 }; |
| OLD | NEW |