Commit b5339433 authored by hirono@chromium.org's avatar hirono@chromium.org

Gallery.app: Add touch handlers for the zoom/scroll feature.

Previously touch operations are handled by SwipeOverlay class. Overlay is a
common way to obtain mouse/touch events in Gallery, but it does not support
touch specific capability (e.g. multi fingers). The CL newly adds TouchHandlers
class to the SlideMode class and let it call the zoom/scroll feature of the
slide mode depending on user's touch gestures.

BUG=245926
TEST=on link

Review URL: https://codereview.chromium.org/411853002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284926 0039d316-1c4b-4281-b951-d872f2087c98
parent 2fda997e
...@@ -747,8 +747,10 @@ ImageEditor.MouseControl.prototype.onTouchStart = function(e) { ...@@ -747,8 +747,10 @@ ImageEditor.MouseControl.prototype.onTouchStart = function(e) {
* @param {TouchEvent} e Event. * @param {TouchEvent} e Event.
*/ */
ImageEditor.MouseControl.prototype.onTouchEnd = function(e) { ImageEditor.MouseControl.prototype.onTouchEnd = function(e) {
if (!this.dragHappened_ && Date.now() - this.touchStartInfo_.time <= if (!this.dragHappened_ &&
ImageEditor.MouseControl.MAX_TAP_DURATION_) { this.touchStartInfo_ &&
Date.now() - this.touchStartInfo_.time <=
ImageEditor.MouseControl.MAX_TAP_DURATION_) {
this.buffer_.onClick(this.touchStartInfo_.x, this.touchStartInfo_.y); this.buffer_.onClick(this.touchStartInfo_.x, this.touchStartInfo_.y);
if (this.previousTouchStartInfo_ && if (this.previousTouchStartInfo_ &&
Date.now() - this.previousTouchStartInfo_.time < Date.now() - this.previousTouchStartInfo_.time <
......
...@@ -52,13 +52,6 @@ function Viewport() { ...@@ -52,13 +52,6 @@ function Viewport() {
*/ */
this.scale_ = 1; this.scale_ = 1;
/**
* Index of zoom ratio. 0 is "zoom ratio = 1".
* @type {number}
* @private
*/
this.zoomIndex_ = 0;
/** /**
* Zoom ratio specified by user operations. * Zoom ratio specified by user operations.
* @type {number} * @type {number}
...@@ -93,18 +86,10 @@ function Viewport() { ...@@ -93,18 +86,10 @@ function Viewport() {
/** /**
* Zoom ratios. * Zoom ratios.
* *
* @type {Object.<string, number>} * @type {Array.<number>}
* @const * @const
*/ */
Viewport.ZOOM_RATIOS = Object.freeze({ Viewport.ZOOM_RATIOS = Object.freeze([1, 1.5, 2, 3]);
'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} width Image width.
...@@ -125,32 +110,57 @@ Viewport.prototype.setScreenSize = function(width, height) { ...@@ -125,32 +110,57 @@ Viewport.prototype.setScreenSize = function(width, height) {
}; };
/** /**
* Sets the new zoom ratio. * Sets zoom value directly.
* @param {number} zoomIndex New zoom index. * @param {number} zoom New zoom value.
*/ */
Viewport.prototype.setZoomIndex = function(zoomIndex) { Viewport.prototype.setZoom = function(zoom) {
// Ignore the invalid zoomIndex. var zoomMin = Viewport.ZOOM_RATIOS[0];
if (!Viewport.ZOOM_RATIOS[zoomIndex.toString()]) var zoomMax = Viewport.ZOOM_RATIOS[Viewport.ZOOM_RATIOS.length - 1];
return; var adjustedZoom = Math.max(zoomMin, Math.min(zoom, zoomMax));
this.zoomIndex_ = zoomIndex; this.zoom_ = adjustedZoom;
this.zoom_ = Viewport.ZOOM_RATIOS[zoomIndex];
this.update_(); this.update_();
}; };
/** /**
* Returns the current zoom index. * Returns the value of zoom.
* @return {number} Zoon index. * @return {number} Zoom value.
*/ */
Viewport.prototype.getZoomIndex = function() { Viewport.prototype.getZoom = function() {
return this.zoomIndex_; return this.zoom_;
}; };
/** /**
* Returns the value of zoom. * Sets the nearset larger value of ZOOM_RATIOS.
* @return {number} Zoom value.
*/ */
Viewport.prototype.getZoom = function() { Viewport.prototype.zoomIn = function() {
return this.zoomIndex_; 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( ...@@ -379,7 +389,6 @@ Viewport.prototype.getCenteredRect_ = function(
* Resets zoom and offset. * Resets zoom and offset.
*/ */
Viewport.prototype.resetView = function() { Viewport.prototype.resetView = function() {
this.zoomIndex_ = 0;
this.zoom_ = 1; this.zoom_ = 1;
this.offsetX_ = 0; this.offsetX_ = 0;
this.offsetY_ = 0; this.offsetY_ = 0;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment