Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: ui/file_manager/gallery/js/image_editor/viewport.js

Issue 392543002: Gallery.app: Add shortcut keys for zooming in the slide mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/file_manager/gallery/js/slide_mode.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_) + ')';
};
/**
« no previous file with comments | « no previous file | ui/file_manager/gallery/js/slide_mode.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698