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
3 // found in the LICENSE file.
8 * The overlay displaying the image.
10 * @param {HTMLElement} container The container element.
11 * @param {Viewport} viewport The viewport.
13 * @extends {ImageBuffer.Overlay}
15 function ImageView(container, viewport) {
16 ImageBuffer.Overlay.call(this);
18 this.container_ = container;
19 this.viewport_ = viewport;
20 this.document_ = container.ownerDocument;
21 this.contentGeneration_ = 0;
22 this.displayedContentGeneration_ = 0;
24 this.imageLoader_ = new ImageUtil.ImageLoader(this.document_);
25 // We have a separate image loader for prefetch which does not get cancelled
26 // when the selection changes.
27 this.prefetchLoader_ = new ImageUtil.ImageLoader(this.document_);
29 this.contentCallbacks_ = [];
32 * The element displaying the current content.
34 * @type {HTMLCanvasElement}
37 this.screenImage_ = null;
41 * Duration of transition between modes in ms.
43 ImageView.MODE_TRANSITION_DURATION = 350;
46 * If the user flips though images faster than this interval we do not apply
47 * the slide-in/slide-out transition.
49 ImageView.FAST_SCROLL_INTERVAL = 300;
52 * Image load type: full resolution image loaded from cache.
54 ImageView.LOAD_TYPE_CACHED_FULL = 0;
57 * Image load type: screen resolution preview loaded from cache.
59 ImageView.LOAD_TYPE_CACHED_SCREEN = 1;
62 * Image load type: image read from file.
64 ImageView.LOAD_TYPE_IMAGE_FILE = 2;
67 * Image load type: error occurred.
69 ImageView.LOAD_TYPE_ERROR = 3;
72 * Image load type: the file contents is not available offline.
74 ImageView.LOAD_TYPE_OFFLINE = 4;
77 * The total number of load types.
79 ImageView.LOAD_TYPE_TOTAL = 5;
81 ImageView.prototype = {__proto__: ImageBuffer.Overlay.prototype};
86 ImageView.prototype.getZIndex = function() { return -1; };
91 ImageView.prototype.draw = function() {
92 if (!this.contentCanvas_) // Do nothing if the image content is not set.
94 if (this.setupDeviceBuffer(this.screenImage_) ||
95 this.displayedContentGeneration_ !== this.contentGeneration_) {
96 this.displayedContentGeneration_ = this.contentGeneration_;
97 ImageUtil.trace.resetTimer('paint');
98 this.paintDeviceRect(this.contentCanvas_, new Rect(this.contentCanvas_));
99 ImageUtil.trace.reportTimer('paint');
104 * Applies the viewport change that does not affect the screen cache size (zoom
105 * change or offset change) with animation.
107 ImageView.prototype.applyViewportChange = function() {
108 if (this.screenImage_) {
112 new ImageView.Effect.None(),
113 ImageView.Effect.DEFAULT_DURATION);
118 * @return {number} The cache generation.
120 ImageView.prototype.getCacheGeneration = function() {
121 return this.contentGeneration_;
125 * Invalidates the caches to force redrawing the screen canvas.
127 ImageView.prototype.invalidateCaches = function() {
128 this.contentGeneration_++;
132 * @return {HTMLCanvasElement} The content canvas element.
134 ImageView.prototype.getCanvas = function() { return this.contentCanvas_; };
137 * @return {boolean} True if the a valid image is currently loaded.
139 ImageView.prototype.hasValidImage = function() {
140 return !this.preview_ && this.contentCanvas_ && this.contentCanvas_.width;
144 * @return {HTMLCanvasElement} The cached thumbnail image.
146 ImageView.prototype.getThumbnail = function() { return this.thumbnailCanvas_; };
149 * @return {number} The content revision number.
151 ImageView.prototype.getContentRevision = function() {
152 return this.contentRevision_;
156 * Copies an image fragment from a full resolution canvas to a device resolution
159 * @param {HTMLCanvasElement} canvas Canvas containing whole image. The canvas
160 * may not be full resolution (scaled).
161 * @param {Rect} imageRect Rectangle region of the canvas to be rendered.
163 ImageView.prototype.paintDeviceRect = function(canvas, imageRect) {
164 // Map the rectangle in full resolution image to the rectangle in the device
166 var deviceBounds = this.viewport_.getDeviceBounds();
167 var scaleX = deviceBounds.width / canvas.width;
168 var scaleY = deviceBounds.height / canvas.height;
169 var deviceRect = new Rect(
170 imageRect.left * scaleX,
171 imageRect.top * scaleY,
172 imageRect.width * scaleX,
173 imageRect.height * scaleY);
176 this.screenImage_.getContext('2d'), canvas, deviceRect, imageRect);
180 * Creates an overlay canvas with properties similar to the screen canvas.
181 * Useful for showing quick feedback when editing.
183 * @return {HTMLCanvasElement} Overlay canvas.
185 ImageView.prototype.createOverlayCanvas = function() {
186 var canvas = this.document_.createElement('canvas');
187 canvas.className = 'image';
188 this.container_.appendChild(canvas);
193 * Sets up the canvas as a buffer in the device resolution.
195 * @param {HTMLCanvasElement} canvas The buffer canvas.
196 * @return {boolean} True if the canvas needs to be rendered.
198 ImageView.prototype.setupDeviceBuffer = function(canvas) {
199 // Set the canvas position and size in device pixels.
200 var deviceRect = this.viewport_.getDeviceBounds();
201 var needRepaint = false;
202 if (canvas.width !== deviceRect.width) {
203 canvas.width = deviceRect.width;
206 if (canvas.height !== deviceRect.height) {
207 canvas.height = deviceRect.height;
212 var imageBounds = this.viewport_.getImageElementBoundsOnScreen();
213 canvas.style.left = imageBounds.left + 'px';
214 canvas.style.top = imageBounds.top + 'px';
215 canvas.style.width = imageBounds.width + 'px';
216 canvas.style.height = imageBounds.height + 'px';
218 this.setTransform_(canvas, this.viewport_);
224 * @return {ImageData} A new ImageData object with a copy of the content.
226 ImageView.prototype.copyScreenImageData = function() {
227 return this.screenImage_.getContext('2d').getImageData(
228 0, 0, this.screenImage_.width, this.screenImage_.height);
232 * @return {boolean} True if the image is currently being loaded.
234 ImageView.prototype.isLoading = function() {
235 return this.imageLoader_.isBusy();
239 * Cancels the current image loading operation. The callbacks will be ignored.
241 ImageView.prototype.cancelLoad = function() {
242 this.imageLoader_.cancel();
246 * Loads and display a new image.
248 * Loads the thumbnail first, then replaces it with the main image.
249 * Takes into account the image orientation encoded in the metadata.
251 * @param {Gallery.Item} item Gallery item to be loaded.
252 * @param {Object} effect Transition effect object.
253 * @param {function(number} displayCallback Called when the image is displayed
254 * (possibly as a preview).
255 * @param {function(number} loadCallback Called when the image is fully loaded.
256 * The parameter is the load type.
258 ImageView.prototype.load =
259 function(item, effect, displayCallback, loadCallback) {
260 var entry = item.getEntry();
261 var metadata = item.getMetadata() || {};
264 // Skip effects when reloading repeatedly very quickly.
265 var time = Date.now();
266 if (this.lastLoadTime_ &&
267 (time - this.lastLoadTime_) < ImageView.FAST_SCROLL_INTERVAL) {
270 this.lastLoadTime_ = time;
273 ImageUtil.metrics.startInterval(ImageUtil.getMetricName('DisplayTime'));
277 this.contentItem_ = item;
278 this.contentRevision_ = -1;
280 var cached = item.contentImage;
282 displayMainImage(ImageView.LOAD_TYPE_CACHED_FULL,
283 false /* no preview */, cached);
285 var cachedScreen = item.screenImage;
286 var imageWidth = metadata.media && metadata.media.width ||
287 metadata.external && metadata.external.imageWidth;
288 var imageHeight = metadata.media && metadata.media.height ||
289 metadata.external && metadata.external.imageHeight;
291 // We have a cached screen-scale canvas, use it instead of a thumbnail.
292 displayThumbnail(ImageView.LOAD_TYPE_CACHED_SCREEN, cachedScreen);
293 // As far as the user can tell the image is loaded. We still need to load
294 // the full res image to make editing possible, but we can report now.
295 ImageUtil.metrics.recordInterval(ImageUtil.getMetricName('DisplayTime'));
296 } else if ((effect && effect.constructor.name === 'Slide') &&
297 (metadata.thumbnail && metadata.thumbnail.url)) {
298 // Only show thumbnails if there is no effect or the effect is Slide.
299 // Also no thumbnail if the image is too large to be loaded.
300 var thumbnailLoader = new ThumbnailLoader(
302 ThumbnailLoader.LoaderType.CANVAS,
304 thumbnailLoader.loadDetachedImage(function(success) {
305 displayThumbnail(ImageView.LOAD_TYPE_IMAGE_FILE,
306 success ? thumbnailLoader.getImage() : null);
309 loadMainImage(ImageView.LOAD_TYPE_IMAGE_FILE, entry,
310 false /* no preview*/, 0 /* delay */);
314 function displayThumbnail(loadType, canvas) {
318 if (metadata.media) {
319 width = metadata.media.width;
320 height = metadata.media.height;
322 // If metadata.external.present is true, the image data is loaded directly
323 // from local cache, whose size may be out of sync with the drive
325 if (metadata.external && !metadata.external.present) {
326 width = metadata.external.imageWidth;
327 height = metadata.external.imageHeight;
335 if (displayCallback) displayCallback();
337 loadMainImage(loadType, entry, !!canvas,
338 (effect && canvas) ? effect.getSafeInterval() : 0);
341 function loadMainImage(loadType, contentEntry, previewShown, delay) {
342 if (self.prefetchLoader_.isLoading(contentEntry)) {
343 // The image we need is already being prefetched. Initiating another load
344 // would be a waste. Hijack the load instead by overriding the callback.
345 self.prefetchLoader_.setCallback(
346 displayMainImage.bind(null, loadType, previewShown));
348 // Swap the loaders so that the self.isLoading works correctly.
349 var temp = self.prefetchLoader_;
350 self.prefetchLoader_ = self.imageLoader_;
351 self.imageLoader_ = temp;
354 self.prefetchLoader_.cancel(); // The prefetch was doing something useless.
356 self.imageLoader_.load(
358 displayMainImage.bind(null, loadType, previewShown),
362 function displayMainImage(loadType, previewShown, content, opt_error) {
364 loadType = ImageView.LOAD_TYPE_ERROR;
366 // If we already displayed the preview we should not replace the content if
367 // the full content failed to load.
368 var animationDuration = 0;
369 if (!(previewShown && loadType === ImageView.LOAD_TYPE_ERROR)) {
370 var replaceEffect = previewShown ? null : effect;
371 animationDuration = replaceEffect ? replaceEffect.getSafeInterval() : 0;
372 self.replace(content, replaceEffect);
373 if (!previewShown && displayCallback) displayCallback();
376 if (loadType !== ImageView.LOAD_TYPE_ERROR &&
377 loadType !== ImageView.LOAD_TYPE_CACHED_SCREEN) {
378 ImageUtil.metrics.recordInterval(ImageUtil.getMetricName('DisplayTime'));
380 ImageUtil.metrics.recordEnum(ImageUtil.getMetricName('LoadMode'),
381 loadType, ImageView.LOAD_TYPE_TOTAL);
383 if (loadType === ImageView.LOAD_TYPE_ERROR &&
384 !navigator.onLine && !metadata.external.present) {
385 loadType = ImageView.LOAD_TYPE_OFFLINE;
387 if (loadCallback) loadCallback(loadType, animationDuration, opt_error);
392 * Prefetches an image.
393 * @param {Gallery.Item} item The image item.
394 * @param {number} delay Image load delay in ms.
396 ImageView.prototype.prefetch = function(item, delay) {
397 if (item.contentImage)
399 this.prefetchLoader_.load(item, function(canvas) {
400 if (canvas.width && canvas.height && !item.contentImage)
401 item.contentImage = canvas;
407 * @param {Rect} zoomToRect Target rectangle for zoom-out-effect.
409 ImageView.prototype.unload = function(zoomToRect) {
410 if (this.unloadTimer_) {
411 clearTimeout(this.unloadTimer_);
412 this.unloadTimer_ = null;
414 if (zoomToRect && this.screenImage_) {
415 var effect = this.createZoomEffect(zoomToRect);
416 this.setTransform_(this.screenImage_, this.viewport_, effect);
417 this.screenImage_.setAttribute('fade', true);
418 this.unloadTimer_ = setTimeout(function() {
419 this.unloadTimer_ = null;
420 this.unload(null /* force unload */);
421 }.bind(this), effect.getSafeInterval());
424 this.container_.textContent = '';
425 this.contentCanvas_ = null;
426 this.screenImage_ = null;
430 * @param {HTMLCanvasElement} content The image element.
431 * @param {number=} opt_width Image width.
432 * @param {number=} opt_height Image height.
433 * @param {boolean=} opt_preview True if the image is a preview (not full res).
436 ImageView.prototype.replaceContent_ = function(
437 content, opt_width, opt_height, opt_preview) {
439 if (this.contentCanvas_ && this.contentCanvas_.parentNode === this.container_)
440 this.container_.removeChild(this.contentCanvas_);
442 this.screenImage_ = this.document_.createElement('canvas');
443 this.screenImage_.className = 'image';
445 this.contentCanvas_ = content;
446 this.invalidateCaches();
447 this.viewport_.setImageSize(
448 opt_width || this.contentCanvas_.width,
449 opt_height || this.contentCanvas_.height);
452 this.container_.appendChild(this.screenImage_);
454 this.preview_ = opt_preview;
455 // If this is not a thumbnail, cache the content and the screen-scale image.
456 if (this.hasValidImage()) {
457 // Insert the full resolution canvas into DOM so that it can be printed.
458 this.container_.appendChild(this.contentCanvas_);
459 this.contentCanvas_.classList.add('fullres');
461 this.contentItem_.contentImage = this.contentCanvas_;
462 this.contentItem_.screenImage = this.screenImage_;
464 // TODO(kaznacheev): It is better to pass screenImage_ as it is usually
465 // much smaller than contentCanvas_ and still contains the entire image.
466 // Once we implement zoom/pan we should pass contentCanvas_ instead.
467 this.updateThumbnail_(this.screenImage_);
469 this.contentRevision_++;
470 for (var i = 0; i !== this.contentCallbacks_.length; i++) {
472 this.contentCallbacks_[i]();
481 * Adds a listener for content changes.
482 * @param {function} callback Callback.
484 ImageView.prototype.addContentCallback = function(callback) {
485 this.contentCallbacks_.push(callback);
489 * Updates the cached thumbnail image.
491 * @param {HTMLCanvasElement} canvas The source canvas.
494 ImageView.prototype.updateThumbnail_ = function(canvas) {
495 ImageUtil.trace.resetTimer('thumb');
496 var pixelCount = 10000;
498 Math.max(1, Math.sqrt(canvas.width * canvas.height / pixelCount));
500 this.thumbnailCanvas_ = canvas.ownerDocument.createElement('canvas');
501 this.thumbnailCanvas_.width = Math.round(canvas.width / downScale);
502 this.thumbnailCanvas_.height = Math.round(canvas.height / downScale);
503 Rect.drawImage(this.thumbnailCanvas_.getContext('2d'), canvas);
504 ImageUtil.trace.reportTimer('thumb');
508 * Replaces the displayed image, possibly with slide-in animation.
510 * @param {HTMLCanvasElement} content The image element.
511 * @param {Object=} opt_effect Transition effect object.
512 * @param {number=} opt_width Image width.
513 * @param {number=} opt_height Image height.
514 * @param {boolean=} opt_preview True if the image is a preview (not full res).
516 ImageView.prototype.replace = function(
517 content, opt_effect, opt_width, opt_height, opt_preview) {
518 var oldScreenImage = this.screenImage_;
519 var oldViewport = this.viewport_.clone();
521 this.replaceContent_(content, opt_width, opt_height, opt_preview);
524 oldScreenImage.parentNode.removeChild(oldScreenImage);
528 var newScreenImage = this.screenImage_;
529 this.viewport_.resetView();
532 ImageUtil.setAttribute(newScreenImage, 'fade', true);
534 newScreenImage, this.viewport_, opt_effect, 0 /* instant */);
536 setTimeout(function() {
541 opt_effect && opt_effect.getDuration());
542 if (oldScreenImage) {
543 ImageUtil.setAttribute(newScreenImage, 'fade', false);
544 ImageUtil.setAttribute(oldScreenImage, 'fade', true);
545 console.assert(opt_effect.getReverse, 'Cannot revert an effect.');
546 var reverse = opt_effect.getReverse();
547 this.setTransform_(oldScreenImage, oldViewport, reverse);
548 setTimeout(function() {
549 if (oldScreenImage.parentNode)
550 oldScreenImage.parentNode.removeChild(oldScreenImage);
551 }, reverse.getSafeInterval());
557 * @param {HTMLCanvasElement} element The element to transform.
558 * @param {Viewport} viewport Viewport to be used for calculating
560 * @param {ImageView.Effect=} opt_effect The effect to apply.
561 * @param {number=} opt_duration Transition duration.
564 ImageView.prototype.setTransform_ = function(
565 element, viewport, opt_effect, opt_duration) {
567 opt_effect = new ImageView.Effect.None();
568 if (typeof opt_duration !== 'number')
569 opt_duration = opt_effect.getDuration();
570 element.style.webkitTransitionDuration = opt_duration + 'ms';
571 element.style.webkitTransitionTimingFunction = opt_effect.getTiming();
572 element.style.webkitTransform = opt_effect.transform(element, viewport);
576 * @param {Rect} screenRect Target rectangle in screen coordinates.
577 * @return {ImageView.Effect.Zoom} Zoom effect object.
579 ImageView.prototype.createZoomEffect = function(screenRect) {
580 return new ImageView.Effect.ZoomToScreen(
582 ImageView.MODE_TRANSITION_DURATION);
586 * Visualizes crop or rotate operation. Hide the old image instantly, animate
587 * the new image to visualize the operation.
589 * @param {HTMLCanvasElement} canvas New content canvas.
590 * @param {Rect} imageCropRect The crop rectangle in image coordinates.
591 * Null for rotation operations.
592 * @param {number} rotate90 Rotation angle in 90 degree increments.
593 * @return {number} Animation duration.
595 ImageView.prototype.replaceAndAnimate = function(
596 canvas, imageCropRect, rotate90) {
597 var oldImageBounds = {
598 width: this.viewport_.getImageBounds().width,
599 height: this.viewport_.getImageBounds().height
601 var oldScreenImage = this.screenImage_;
602 this.replaceContent_(canvas);
603 var newScreenImage = this.screenImage_;
604 var effect = rotate90 ?
605 new ImageView.Effect.Rotate(rotate90 > 0) :
606 new ImageView.Effect.Zoom(
607 oldImageBounds.width, oldImageBounds.height, imageCropRect);
609 this.setTransform_(newScreenImage, this.viewport_, effect, 0 /* instant */);
611 oldScreenImage.parentNode.appendChild(newScreenImage);
612 oldScreenImage.parentNode.removeChild(oldScreenImage);
614 // Let the layout fire, then animate back to non-transformed state.
616 this.setTransform_.bind(
617 this, newScreenImage, this.viewport_, null, effect.getDuration()),
620 return effect.getSafeInterval();
624 * Visualizes "undo crop". Shrink the current image to the given crop rectangle
625 * while fading in the new image.
627 * @param {HTMLCanvasElement} canvas New content canvas.
628 * @param {Rect} imageCropRect The crop rectangle in image coordinates.
629 * @return {number} Animation duration.
631 ImageView.prototype.animateAndReplace = function(canvas, imageCropRect) {
632 var oldScreenImage = this.screenImage_;
633 this.replaceContent_(canvas);
634 var newScreenImage = this.screenImage_;
635 var setFade = ImageUtil.setAttribute.bind(null, newScreenImage, 'fade');
637 oldScreenImage.parentNode.insertBefore(newScreenImage, oldScreenImage);
638 var effect = new ImageView.Effect.Zoom(
639 this.viewport_.getImageBounds().width,
640 this.viewport_.getImageBounds().height,
643 // Animate to the transformed state.
644 this.setTransform_(oldScreenImage, this.viewport_, effect);
645 setTimeout(setFade.bind(null, false), 0);
646 setTimeout(function() {
647 if (oldScreenImage.parentNode)
648 oldScreenImage.parentNode.removeChild(oldScreenImage);
649 }, effect.getSafeInterval());
651 return effect.getSafeInterval();
654 /* Transition effects */
657 * Base class for effects.
659 * @param {number} duration Duration in ms.
660 * @param {string=} opt_timing CSS transition timing function name.
663 ImageView.Effect = function(duration, opt_timing) {
664 this.duration_ = duration;
665 this.timing_ = opt_timing || 'linear';
671 ImageView.Effect.DEFAULT_DURATION = 180;
676 ImageView.Effect.MARGIN = 100;
679 * @return {number} Effect duration in ms.
681 ImageView.Effect.prototype.getDuration = function() { return this.duration_; };
684 * @return {number} Delay in ms since the beginning of the animation after which
685 * it is safe to perform CPU-heavy operations without disrupting the animation.
687 ImageView.Effect.prototype.getSafeInterval = function() {
688 return this.getDuration() + ImageView.Effect.MARGIN;
692 * @return {string} CSS transition timing function name.
694 ImageView.Effect.prototype.getTiming = function() { return this.timing_; };
697 * Obtains the CSS transformation string of the effect.
698 * @param {DOMCanvas} element Canvas element to be applied the transformation.
699 * @param {Viewport} viewport Current viewport.
700 * @return {string} CSS transformation description.
702 ImageView.Effect.prototype.transform = function(element, viewport) {
703 throw new Error('Not implemented.');
711 * @extends {ImageView.Effect}
713 ImageView.Effect.None = function() {
714 ImageView.Effect.call(this, 0, 'easy-out');
718 * Inherits from ImageView.Effect.
720 ImageView.Effect.None.prototype = { __proto__: ImageView.Effect.prototype };
723 * @param {HTMLCanvasElement} element Element.
724 * @param {Viewport} viewport Current viewport.
725 * @return {string} Transform string.
727 ImageView.Effect.None.prototype.transform = function(element, viewport) {
728 return viewport.getTransformation();
734 * @param {number} direction -1 for left, 1 for right.
735 * @param {boolean=} opt_slow True if slow (as in slideshow).
737 * @extends {ImageView.Effect}
739 ImageView.Effect.Slide = function Slide(direction, opt_slow) {
740 ImageView.Effect.call(this,
741 opt_slow ? 800 : ImageView.Effect.DEFAULT_DURATION, 'ease-out');
742 this.direction_ = direction;
743 this.slow_ = opt_slow;
744 this.shift_ = opt_slow ? 100 : 40;
745 if (this.direction_ < 0) this.shift_ = -this.shift_;
748 ImageView.Effect.Slide.prototype = { __proto__: ImageView.Effect.prototype };
751 * Reverses the slide effect.
752 * @return {ImageView.Effect.Slide} Reversed effect.
754 ImageView.Effect.Slide.prototype.getReverse = function() {
755 return new ImageView.Effect.Slide(-this.direction_, this.slow_);
761 ImageView.Effect.Slide.prototype.transform = function(element, viewport) {
762 return viewport.getShiftTransformation(this.shift_);
768 * Animates the original rectangle to the target rectangle.
770 * @param {number} previousImageWidth Width of the full resolution image.
771 * @param {number} previousImageHeight Height of the full resolution image.
772 * @param {Rect} imageCropRect Crop rectangle in the full resolution image.
773 * @param {number=} opt_duration Duration of the effect.
775 * @extends {ImageView.Effect}
777 ImageView.Effect.Zoom = function(
778 previousImageWidth, previousImageHeight, imageCropRect, opt_duration) {
779 ImageView.Effect.call(this,
780 opt_duration || ImageView.Effect.DEFAULT_DURATION, 'ease-out');
781 this.previousImageWidth_ = previousImageWidth;
782 this.previousImageHeight_ = previousImageHeight;
783 this.imageCropRect_ = imageCropRect;
786 ImageView.Effect.Zoom.prototype = { __proto__: ImageView.Effect.prototype };
791 ImageView.Effect.Zoom.prototype.transform = function(element, viewport) {
792 return viewport.getInverseTransformForCroppedImage(
793 this.previousImageWidth_, this.previousImageHeight_, this.imageCropRect_);
797 * Effect to zoom to a screen rectangle.
799 * @param {Rect} screenRect Rectangle in the application window's coordinate.
800 * @param {number=} opt_duration Duration of effect.
802 * @extends {ImageView.Effect}
804 ImageView.Effect.ZoomToScreen = function(screenRect, opt_duration) {
805 ImageView.Effect.call(this, opt_duration);
806 this.screenRect_ = screenRect;
809 ImageView.Effect.ZoomToScreen.prototype = {
810 __proto__: ImageView.Effect.prototype
816 ImageView.Effect.ZoomToScreen.prototype.transform = function(
818 return viewport.getScreenRectTransformForImage(this.screenRect_);
824 * @param {boolean} orientation Orientation of rotation. True is for clockwise
825 * and false is for counterclockwise.
827 * @extends {ImageView.Effect}
829 ImageView.Effect.Rotate = function(orientation) {
830 ImageView.Effect.call(this, ImageView.Effect.DEFAULT_DURATION);
831 this.orientation_ = orientation;
834 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype };
839 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) {
840 return viewport.getInverseTransformForRotatedImage(this.orientation_);