Merge pull request #646 from marco-c/long_press

Support long press gesture event
This commit is contained in:
Myk Melez 2014-11-26 17:24:54 -08:00
Родитель 7e7b13c235 84b4622f29
Коммит 57f2cd6c2f
1 изменённых файлов: 27 добавлений и 2 удалений

Просмотреть файл

@ -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 = 1000;
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) {
@ -637,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 = {
@ -651,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);
}
}
});
@ -662,9 +679,17 @@ MIDP.Context2D = (function() {
}
event.preventDefault();
if (longPressTimeoutID) {
clearTimeout(longPressTimeoutID);
longPressTimeoutID = null;
}
var pt = getEventPoint(event);
sendPenEvent(pt, MIDP.RELEASED);
sendGestureEvent(pt, null, mouseDownInfo.isDragging ? MIDP.GESTURE_DROP : 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.
});