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..0437b1a5dd8928aaa986258cb268507d2790be7e 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.<string, number>} |
yoshiki
2014/07/14 07:34:58
nit: s/Map/Object/
This is not a Map. And Map emb
hirono
2014/07/14 08:10:00
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,28 @@ 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]) |
+ return; |
+ |
+ this.zoomIndex_ = zoomIndex; |
+ this.zoom_ = Viewport.ZOOM_RATIOS[zoomIndex]; |
+ this.invalidateCaches(); |
+}; |
+ |
+/** |
+ * Returns the current zoom index. |
+ * @return {number} Zoon index. |
+ */ |
+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 +441,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_) + ')'; |
}; |
/** |