OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * Viewport class controls the way the image is displayed (scale, offset etc). | 6 * Viewport class controls the way the image is displayed (scale, offset etc). |
7 * @constructor | 7 * @constructor |
8 */ | 8 */ |
9 function Viewport() { | 9 function Viewport() { |
10 this.imageBounds_ = new Rect(); | 10 this.imageBounds_ = new Rect(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 Viewport.prototype.sizeByFrameAndFit = function(frame) { | 70 Viewport.prototype.sizeByFrameAndFit = function(frame) { |
71 var wasFitting = this.getScale() == this.getFittingScale(); | 71 var wasFitting = this.getScale() == this.getFittingScale(); |
72 this.sizeByFrame(frame); | 72 this.sizeByFrame(frame); |
73 var minScale = this.getFittingScale(); | 73 var minScale = this.getFittingScale(); |
74 if (wasFitting || (this.getScale() < minScale)) { | 74 if (wasFitting || (this.getScale() < minScale)) { |
75 this.setScale(minScale, true); | 75 this.setScale(minScale, true); |
76 } | 76 } |
77 }; | 77 }; |
78 | 78 |
79 /** | 79 /** |
80 * @return {number} Scale | 80 * @return {number} Scale. |
81 */ | 81 */ |
82 Viewport.prototype.getScale = function() { return this.scale_ }; | 82 Viewport.prototype.getScale = function() { return this.scale_ }; |
83 | 83 |
84 /** | 84 /** |
85 * @param {number} scale The new scale. | 85 * @param {number} scale The new scale. |
86 * @param {boolean} notify True if the change should be reflected in the UI. | 86 * @param {boolean} notify True if the change should be reflected in the UI. |
87 */ | 87 */ |
88 Viewport.prototype.setScale = function(scale, notify) { | 88 Viewport.prototype.setScale = function(scale, notify) { |
89 if (this.scale_ == scale) return; | 89 if (this.scale_ == scale) return; |
90 this.scale_ = scale; | 90 this.scale_ = scale; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 191 |
192 /** | 192 /** |
193 * @return {Rect} The visible part of the image, in screen coordinates. | 193 * @return {Rect} The visible part of the image, in screen coordinates. |
194 */ | 194 */ |
195 Viewport.prototype.getScreenClipped = function() { return this.screenClipped_ }; | 195 Viewport.prototype.getScreenClipped = function() { return this.screenClipped_ }; |
196 | 196 |
197 /** | 197 /** |
198 * A counter that is incremented with each viewport state change. | 198 * A counter that is incremented with each viewport state change. |
199 * Clients that cache anything that depends on the viewport state should keep | 199 * Clients that cache anything that depends on the viewport state should keep |
200 * track of this counter. | 200 * track of this counter. |
201 * @return {number} counter | 201 * @return {number} counter. |
202 */ | 202 */ |
203 Viewport.prototype.getCacheGeneration = function() { return this.generation_ }; | 203 Viewport.prototype.getCacheGeneration = function() { return this.generation_ }; |
204 | 204 |
205 /** | 205 /** |
206 * Called on evert view port state change (even if repaint has not been called). | 206 * Called on evert view port state change (even if repaint has not been called). |
207 */ | 207 */ |
208 Viewport.prototype.invalidateCaches = function() { this.generation_++ }; | 208 Viewport.prototype.invalidateCaches = function() { this.generation_++ }; |
209 | 209 |
210 /** | 210 /** |
211 * @return {Rect} The image bounds in screen coordinates. | 211 * @return {Rect} The image bounds in screen coordinates. |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 }; | 419 }; |
420 | 420 |
421 /** | 421 /** |
422 * Repaint all clients. | 422 * Repaint all clients. |
423 */ | 423 */ |
424 Viewport.prototype.repaint = function() { | 424 Viewport.prototype.repaint = function() { |
425 this.update(); | 425 this.update(); |
426 for (var i = 0; i != this.repaintCallbacks_.length; i++) | 426 for (var i = 0; i != this.repaintCallbacks_.length; i++) |
427 this.repaintCallbacks_[i](); | 427 this.repaintCallbacks_[i](); |
428 }; | 428 }; |
OLD | NEW |