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

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

Issue 411853002: Gallery.app: Add touch handlers for the zoom/scroll feature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. 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 | « ui/file_manager/gallery/js/image_editor/image_editor.js ('k') | 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 4ecea71c0588de34d26a1f840d257068b37b9fc2..388f2664528522e7aa956bf1c7e9b11e69ec7f3b 100644
--- a/ui/file_manager/gallery/js/image_editor/viewport.js
+++ b/ui/file_manager/gallery/js/image_editor/viewport.js
@@ -53,13 +53,6 @@ function Viewport() {
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
@@ -93,18 +86,10 @@ function Viewport() {
/**
* Zoom ratios.
*
- * @type {Object.<string, number>}
+ * @type {Array.<number>}
* @const
*/
-Viewport.ZOOM_RATIOS = Object.freeze({
- '3': 3,
- '2': 2,
- '1': 1.5,
- '0': 1,
- '-1': 0.75,
- '-2': 0.5,
- '-3': 0.25
-});
+Viewport.ZOOM_RATIOS = Object.freeze([1, 1.5, 2, 3]);
/**
* @param {number} width Image width.
@@ -125,32 +110,57 @@ Viewport.prototype.setScreenSize = function(width, height) {
};
/**
- * Sets the new zoom ratio.
- * @param {number} zoomIndex New zoom index.
+ * Sets zoom value directly.
+ * @param {number} zoom New zoom value.
*/
-Viewport.prototype.setZoomIndex = function(zoomIndex) {
- // Ignore the invalid zoomIndex.
- if (!Viewport.ZOOM_RATIOS[zoomIndex.toString()])
- return;
- this.zoomIndex_ = zoomIndex;
- this.zoom_ = Viewport.ZOOM_RATIOS[zoomIndex];
+Viewport.prototype.setZoom = function(zoom) {
+ var zoomMin = Viewport.ZOOM_RATIOS[0];
+ var zoomMax = Viewport.ZOOM_RATIOS[Viewport.ZOOM_RATIOS.length - 1];
+ var adjustedZoom = Math.max(zoomMin, Math.min(zoom, zoomMax));
+ this.zoom_ = adjustedZoom;
this.update_();
};
/**
- * Returns the current zoom index.
- * @return {number} Zoon index.
+ * Returns the value of zoom.
+ * @return {number} Zoom value.
*/
-Viewport.prototype.getZoomIndex = function() {
- return this.zoomIndex_;
+Viewport.prototype.getZoom = function() {
+ return this.zoom_;
};
/**
- * Returns the value of zoom.
- * @return {number} Zoom value.
+ * Sets the nearset larger value of ZOOM_RATIOS.
*/
-Viewport.prototype.getZoom = function() {
- return this.zoomIndex_;
+Viewport.prototype.zoomIn = function() {
+ var zoom = Viewport.ZOOM_RATIOS[0];
+ for (var i = 0; i < Viewport.ZOOM_RATIOS.length; i++) {
+ zoom = Viewport.ZOOM_RATIOS[i];
+ if (zoom > this.zoom_)
+ break;
+ }
+ this.setZoom(zoom);
+};
+
+/**
+ * Sets the nearest smaller value of ZOOM_RATIOS.
+ */
+Viewport.prototype.zoomOut = function() {
+ var zoom = Viewport.ZOOM_RATIOS[Viewport.ZOOM_RATIOS.length - 1];
+ for (var i = Viewport.ZOOM_RATIOS.length - 1; i >= 0; i--) {
+ zoom = Viewport.ZOOM_RATIOS[i];
+ if (zoom < this.zoom_)
+ break;
+ }
+ this.setZoom(zoom);
+};
+
+/**
+ * Obtains whether the picture is zoomed or not.
+ * @return {boolean}
+ */
+Viewport.prototype.isZoomed = function() {
+ return this.zoom_ !== 1;
};
/**
@@ -379,7 +389,6 @@ Viewport.prototype.getCenteredRect_ = function(
* Resets zoom and offset.
*/
Viewport.prototype.resetView = function() {
- this.zoomIndex_ = 0;
this.zoom_ = 1;
this.offsetX_ = 0;
this.offsetY_ = 0;
« no previous file with comments | « ui/file_manager/gallery/js/image_editor/image_editor.js ('k') | ui/file_manager/gallery/js/slide_mode.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698