From 8d2e69f50e11714172436cdb7a06dfe25eabb194 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 26 Nov 2014 00:14:04 +0100 Subject: [PATCH 1/2] Support long press gesture event --- midp/midp.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/midp/midp.js b/midp/midp.js index 7272f292..f9ec8d36 100644 --- a/midp/midp.js +++ b/midp/midp.js @@ -622,14 +622,23 @@ MIDP.Context2D = (function() { // both. A distance threshold ensures that touches with an "intent // to tap" will likely result in a tap. + var LONG_PRESS_TIMEOUT = 500; var MIN_DRAG_DISTANCE_SQUARED = 5 * 5; var mouseDownInfo = null; + var longPressTimeoutID = null; + var longPressDetected = false; c.addEventListener(supportsTouch ? "touchstart" : "mousedown", function(event) { event.preventDefault(); // Prevent unnecessary fake mouse events. var pt = getEventPoint(event); sendPenEvent(pt, MIDP.PRESSED); mouseDownInfo = pt; + + longPressDetected = false; + longPressTimeoutID = setTimeout(function() { + longPressDetected = true; + sendGestureEvent(pt, null, MIDP.GESTURE_LONG_PRESS); + }, LONG_PRESS_TIMEOUT); }); c.addEventListener(supportsTouch ? "touchmove" : "mousemove", function(event) { @@ -662,9 +671,16 @@ MIDP.Context2D = (function() { } event.preventDefault(); + clearTimeout(longPressTimeoutID); + var pt = getEventPoint(event); sendPenEvent(pt, MIDP.RELEASED); - sendGestureEvent(pt, null, mouseDownInfo.isDragging ? MIDP.GESTURE_DROP : MIDP.GESTURE_TAP); + + if (mouseDownInfo.isDragging) { + sendGestureEvent(pt, null, MIDP.GESTURE_DROP); + } else if (!longPressDetected) { + sendGestureEvent(pt, null, MIDP.GESTURE_TAP); + } mouseDownInfo = null; // Clear the way for the next gesture. }); From 84b4622f29d063e0f3ba5e00aee9eb59e38ccf55 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 26 Nov 2014 00:22:29 +0100 Subject: [PATCH 2/2] Don't send GESTURE_DRAG or GESTURE_DROP if the gesture was a long press --- midp/midp.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/midp/midp.js b/midp/midp.js index f9ec8d36..0787aae4 100644 --- a/midp/midp.js +++ b/midp/midp.js @@ -622,7 +622,7 @@ MIDP.Context2D = (function() { // both. A distance threshold ensures that touches with an "intent // to tap" will likely result in a tap. - var LONG_PRESS_TIMEOUT = 500; + var LONG_PRESS_TIMEOUT = 1000; var MIN_DRAG_DISTANCE_SQUARED = 5 * 5; var mouseDownInfo = null; var longPressTimeoutID = null; @@ -646,6 +646,12 @@ MIDP.Context2D = (function() { return; // Mousemove on desktop; ignored. } event.preventDefault(); + + if (longPressTimeoutID) { + clearTimeout(longPressTimeoutID); + longPressTimeoutID = null; + } + var pt = getEventPoint(event); sendPenEvent(pt, MIDP.DRAGGED); var distance = { @@ -660,7 +666,9 @@ MIDP.Context2D = (function() { mouseDownInfo.isDragging = true; mouseDownInfo.x = pt.x; mouseDownInfo.y = pt.y; - sendGestureEvent(pt, distance, MIDP.GESTURE_DRAG); + if (!longPressDetected) { + sendGestureEvent(pt, distance, MIDP.GESTURE_DRAG); + } } }); @@ -671,15 +679,16 @@ MIDP.Context2D = (function() { } event.preventDefault(); - clearTimeout(longPressTimeoutID); + if (longPressTimeoutID) { + clearTimeout(longPressTimeoutID); + longPressTimeoutID = null; + } var pt = getEventPoint(event); sendPenEvent(pt, MIDP.RELEASED); - if (mouseDownInfo.isDragging) { - sendGestureEvent(pt, null, MIDP.GESTURE_DROP); - } else if (!longPressDetected) { - sendGestureEvent(pt, null, MIDP.GESTURE_TAP); + if (!longPressDetected) { + sendGestureEvent(pt, null, mouseDownInfo.isDragging ? MIDP.GESTURE_DROP : MIDP.GESTURE_TAP); } mouseDownInfo = null; // Clear the way for the next gesture.