Index: ui/file_manager/gallery/js/image_editor/viewport.js |
diff --git a/ui/file_manager/gallery/js/image_editor/viewport.js b/ui/file_manager/gallery/js/image_editor/viewport.js |
index df53d7476c4b98db1aa87ea62e9dbaea90dfd9cf..ed1751ae0ec1522655a8489373076d3de33fcbb2 100644 |
--- a/ui/file_manager/gallery/js/image_editor/viewport.js |
+++ b/ui/file_manager/gallery/js/image_editor/viewport.js |
@@ -30,6 +30,21 @@ function Viewport() { |
* @private |
*/ |
this.scale_ = 1; |
+ |
+ /** |
+ * Index of zoom ratio. 0 is "zoom ratio = 1". |
+ * @type {number} |
+ * @private |
+ */ |
+ this.zoomIndex_ = 0; |
+ |
+ /** |
+ * Zoom ratio specified by user operations. |
+ * @type {number} |
+ * @private |
+ */ |
+ this.zoom_ = 1; |
+ |
this.offsetX_ = 0; |
this.offsetY_ = 0; |
@@ -39,6 +54,22 @@ function Viewport() { |
} |
/** |
+ * Zoom ratios. |
+ * |
+ * @type {Map.<number, number>} |
yoshiki
2014/07/14 07:27:20
<string, number>?
hirono
2014/07/14 07:30:05
Done.
|
+ * @const |
+ */ |
+Viewport.ZOOM_RATIOS = Object.freeze({ |
+ '3': 3, |
+ '2': 2, |
+ '1': 1.5, |
+ '0': 1, |
+ '-1': 0.75, |
+ '-2': 0.5, |
+ '-3': 0.25 |
+}); |
+ |
+/** |
* @param {number} width Image width. |
* @param {number} height Image height. |
*/ |
@@ -57,6 +88,27 @@ Viewport.prototype.setScreenSize = function(width, height) { |
}; |
/** |
+ * Sets the new zoom ratio. |
+ * @param {number} zoomIndex New zoom index. |
+ */ |
+Viewport.prototype.setZoomIndex = function(zoomIndex) { |
+ // Ignore the invalid zoomIndex. |
+ if (!Viewport.ZOOM_RATIOS[zoomIndex]) |
yoshiki
2014/07/14 07:34:58
nit: Using toString() method for zoomIndex is bett
hirono
2014/07/14 08:10:00
Done.
|
+ return; |
+ |
+ this.zoomIndex_ = zoomIndex; |
+ this.zoom_ = Viewport.ZOOM_RATIOS[zoomIndex]; |
+ this.invalidateCaches(); |
+}; |
+ |
+/** |
+ * Returns the current zoom index. |
yoshiki
2014/07/14 07:27:20
@return
hirono
2014/07/14 07:30:06
Done.
|
+ */ |
+Viewport.prototype.getZoomIndex = function() { |
+ return this.zoomIndex_; |
+}; |
+ |
+/** |
* Set the size by an HTML element. |
* |
* @param {HTMLElement} frame The element acting as the "screen". |
@@ -388,7 +440,7 @@ Viewport.prototype.update = function() { |
* @return {string} Transformation description. |
*/ |
Viewport.prototype.getTransformation = function() { |
- return 'scale(' + (1 / window.devicePixelRatio) + ')'; |
+ return 'scale(' + (1 / window.devicePixelRatio * this.zoom_) + ')'; |
}; |
/** |