зеркало из https://github.com/mozilla/pluotsorbet.git
Merge pull request #646 from marco-c/long_press
Support long press gesture event
This commit is contained in:
Коммит
57f2cd6c2f
29
midp/midp.js
29
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 = 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.
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче