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

Gallery: Scroll images by two finger swipe on a track pad.

Two finger swipe on a track pad generates 'mouseweel' event.
The CL adds a handler for the event.

BUG=401310
TEST=on link

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

Cr-Commit-Position: refs/heads/master@{#288311}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288311 0039d316-1c4b-4281-b951-d872f2087c98
parent 617363a5
...@@ -1385,6 +1385,8 @@ function TouchHandler(targetElement, slideMode) { ...@@ -1385,6 +1385,8 @@ function TouchHandler(targetElement, slideMode) {
var onTouchEventBound = this.onTouchEvent_.bind(this); var onTouchEventBound = this.onTouchEvent_.bind(this);
targetElement.ownerDocument.addEventListener('touchmove', onTouchEventBound); targetElement.ownerDocument.addEventListener('touchmove', onTouchEventBound);
targetElement.ownerDocument.addEventListener('touchend', onTouchEventBound); targetElement.ownerDocument.addEventListener('touchend', onTouchEventBound);
targetElement.addEventListener('mousewheel', this.onMouseWheel_.bind(this));
} }
/** /**
...@@ -1416,17 +1418,6 @@ TouchHandler.getDistance = function(event) { ...@@ -1416,17 +1418,6 @@ TouchHandler.getDistance = function(event) {
return Math.sqrt(dx * dx + dy * dy); return Math.sqrt(dx * dx + dy * dy);
}; };
TouchHandler.prototype = {
/**
* @param {boolean} flag New value.
*/
set enabled(flag) {
this.enabled_ = flag;
if (!this.enabled_)
this.stopOperation();
}
};
/** /**
* Obtains the degrees of the pinch twist angle. * Obtains the degrees of the pinch twist angle.
* @param {TouchEvent} event1 Start touch event. It should include more than two * @param {TouchEvent} event1 Start touch event. It should include more than two
...@@ -1445,6 +1436,17 @@ TouchHandler.getTwistAngle = function(event1, event2) { ...@@ -1445,6 +1436,17 @@ TouchHandler.getTwistAngle = function(event1, event2) {
return Math.atan2(outerProduct, innerProduct) * 180 / Math.PI; // atan(y / x) return Math.atan2(outerProduct, innerProduct) * 180 / Math.PI; // atan(y / x)
}; };
TouchHandler.prototype = {
/**
* @param {boolean} flag New value.
*/
set enabled(flag) {
this.enabled_ = flag;
if (!this.enabled_)
this.stopOperation();
}
};
/** /**
* Stops the current touch operation. * Stops the current touch operation.
*/ */
...@@ -1456,13 +1458,20 @@ TouchHandler.prototype.stopOperation = function() { ...@@ -1456,13 +1458,20 @@ TouchHandler.prototype.stopOperation = function() {
this.lastZoom_ = 1.0; this.lastZoom_ = 1.0;
}; };
/**
* Handles touch start events.
* @param {TouchEvent} event Touch event.
* @private
*/
TouchHandler.prototype.onTouchStart_ = function(event) { TouchHandler.prototype.onTouchStart_ = function(event) {
if (this.enabled_ && event.touches.length === 1) if (this.enabled_ && event.touches.length === 1)
this.touchStarted_ = true; this.touchStarted_ = true;
}; };
/** /**
* @param {event} event Touch event. * Handles touch move and touch end events.
* @param {TouchEvent} event Touch event.
* @private
*/ */
TouchHandler.prototype.onTouchEvent_ = function(event) { TouchHandler.prototype.onTouchEvent_ = function(event) {
// Check if the current touch operation started from the target element or // Check if the current touch operation started from the target element or
...@@ -1547,3 +1556,19 @@ TouchHandler.prototype.onTouchEvent_ = function(event) { ...@@ -1547,3 +1556,19 @@ TouchHandler.prototype.onTouchEvent_ = function(event) {
this.lastEvent_ = event; this.lastEvent_ = event;
this.lastZoom_ = viewport.getZoom(); this.lastZoom_ = viewport.getZoom();
}; };
/**
* Handles mouse wheel events.
* @param {MouseEvent} event Wheel event.
* @private
*/
TouchHandler.prototype.onMouseWheel_ = function(event) {
var viewport = this.slideMode_.getViewport();
if (!this.enabled_ || !viewport.isZoomed())
return;
this.stopOperation();
viewport.setOffset(
viewport.getOffsetX() + event.wheelDeltaX,
viewport.getOffsetY() + event.wheelDeltaY);
this.slideMode_.applyViewportChange();
};
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