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

Unified Diff: ui/file_manager/gallery/js/slide_mode.js

Issue 416023002: Gallery.app: Add touch operation to rotate images. (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
Index: ui/file_manager/gallery/js/slide_mode.js
diff --git a/ui/file_manager/gallery/js/slide_mode.js b/ui/file_manager/gallery/js/slide_mode.js
index 4c480f4fdd3f122edf5ebf8864ced53100cb5edb..99370d8cf8bec51f0b025a6ef522c456cf97b7d4 100644
--- a/ui/file_manager/gallery/js/slide_mode.js
+++ b/ui/file_manager/gallery/js/slide_mode.js
@@ -1372,6 +1372,13 @@ function TouchHandler(targetElement, slideMode) {
this.gestureStartEvent_ = null;
/**
+ * Rotation value on beginning of the current gesture.
+ * @type {number}
+ * @private
+ */
+ this.gestureStartRotation_ = 0;
+
+ /**
* Last touch event.
* @type {TouchEvent}
* @private
@@ -1425,6 +1432,24 @@ TouchHandler.prototype = {
};
/**
+ * Obtains the radian of the pinch twist angle.
+ * @param {TouchEvent} event1 Start touch event. It should include more than two
+ * touches.
+ * @param {TouchEvent} event2 Current touch event. It should include more than
+ * two touches.
+ * @return {number} Radian of the pinch twist angle.
mtomasz 2014/07/24 09:59:25 Here we return radians, but in other places we wor
hirono 2014/07/24 10:13:08 Let me choose degrees that works fine with CSS tra
+ */
+TouchHandler.getTwistRadian = function(event1, event2) {
+ var dx1 = event1.touches[1].clientX - event1.touches[0].clientX;
+ var dy1 = event1.touches[1].clientY - event1.touches[0].clientY;
+ var dx2 = event2.touches[1].clientX - event2.touches[0].clientX;
+ var dy2 = event2.touches[1].clientY - event2.touches[0].clientY;
+ var innerProduce = dx1 * dx2 + dy1 * dy2; // |v1| * |v2| * cos(t) = x / r
mtomasz 2014/07/24 09:59:25 nit: Did you mean inner product?
hirono 2014/07/24 10:13:08 Oops, yes.
+ var outerProduce = dx1 * dy2 - dy1 * dx2; // |v1| * |v2| * sin(t) = y / r
+ return Math.atan2(outerProduce, innerProduce); // atan(y / x)
+};
+
+/**
* Stops the current touch operation.
*/
TouchHandler.prototype.stopOperation = function() {
@@ -1456,15 +1481,18 @@ TouchHandler.prototype.onTouchEvent_ = function(event) {
}
// Check if a new gesture started or not.
+ var viewport = this.slideMode_.getViewport();
if (!this.lastEvent_ ||
this.lastEvent_.touches.length !== event.touches.length) {
if (event.touches.length === 2 ||
event.touches.length === 1) {
this.gestureStartEvent_ = event;
+ this.gestureStartRotation_ = viewport.getRotation();
this.lastEvent_ = event;
- this.lastZoom_ = this.slideMode_.getViewport().getZoom();
+ this.lastZoom_ = viewport.getZoom();
} else {
this.gestureStartEvent_ = null;
+ this.gestureStartRotation_ = 0;
this.lastEvent_ = null;
this.lastZoom_ = 1.0;
}
@@ -1472,7 +1500,6 @@ TouchHandler.prototype.onTouchEvent_ = function(event) {
}
// Handle the gesture movement.
- var viewport = this.slideMode_.getViewport();
switch (event.touches.length) {
case 1:
if (viewport.isZoomed()) {
@@ -1507,6 +1534,15 @@ TouchHandler.prototype.onTouchEvent_ = function(event) {
break;
var zoom = distance2 / distance1 * this.lastZoom_;
viewport.setZoom(zoom);
+
+ // Pinch rotation.
+ var radian = TouchHandler.getTwistRadian(this.gestureStartEvent_, event);
+ if (radian > Math.PI / 8)
+ viewport.setRotation(this.gestureStartRotation_ + 1);
+ else if (radian < -Math.PI / 8)
+ viewport.setRotation(this.gestureStartRotation_ - 1);
+ else
+ viewport.setRotation(this.gestureStartRotation_);
this.slideMode_.applyViewportChange();
break;
}

Powered by Google App Engine
This is Rietveld 408576698