mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 15:01:01 +01:00
Revert "[web] Move tap recognition to touchend"
This reverts commit 7db69c0cd0.
This commit is contained in:
1 parent
7db69c0cd0
commit
db6d2c27ec
1 file changed
+15
-48
+15
-48
@@ -211,35 +211,28 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset</span>
|
||||
var skipNextPinchMove = false;
|
||||
var longPressTimer = null;
|
||||
var longPressFired = false;
|
||||
var pendingTapTimer = null;
|
||||
var singleTouchActive = false;
|
||||
var singleTouchMoved = false;
|
||||
var lastTapTime = 0;
|
||||
var doubleTapZoom = false;
|
||||
var doubleTapY = 0;
|
||||
function swallowTouch (e) {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
}
|
||||
function clearPendingTapTimer () {
|
||||
if (!pendingTapTimer)
|
||||
return;
|
||||
clearTimeout(pendingTapTimer);
|
||||
pendingTapTimer = null;
|
||||
}
|
||||
if (!isWebGPU) canvas.addEventListener('touchstart', function (e) {
|
||||
if (e.touches.length === 1) {
|
||||
if (pendingTapTimer) {
|
||||
/* A second tap claims double-tap zoom before the first tap commits. */
|
||||
clearPendingTapTimer();
|
||||
swallowTouch(e);
|
||||
var now = performance.now();
|
||||
if (now - lastTapTime < 300) {
|
||||
/* Double-tap: start zoom drag.
|
||||
* Undo animation toggle from first tap. */
|
||||
e.preventDefault();
|
||||
if (typeof _web_toggle_animation === 'function')
|
||||
_web_toggle_animation();
|
||||
doubleTapZoom = true;
|
||||
doubleTapY = e.touches[0].clientY;
|
||||
singleTouchActive = false;
|
||||
singleTouchMoved = false;
|
||||
lastTapTime = 0;
|
||||
if (longPressTimer) { clearTimeout(longPressTimer); longPressTimer = null; }
|
||||
} else {
|
||||
singleTouchActive = true;
|
||||
singleTouchMoved = false;
|
||||
lastTapTime = now;
|
||||
longPressX = e.touches[0].clientX;
|
||||
longPressY = e.touches[0].clientY;
|
||||
longPressTimer = setTimeout(function () {
|
||||
@@ -248,14 +241,9 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset</span>
|
||||
if (typeof _web_reset === 'function') _web_reset();
|
||||
}, 500);
|
||||
}
|
||||
} else {
|
||||
clearPendingTapTimer();
|
||||
singleTouchActive = false;
|
||||
singleTouchMoved = false;
|
||||
if (longPressTimer) {
|
||||
clearTimeout(longPressTimer);
|
||||
longPressTimer = null;
|
||||
}
|
||||
} else if (longPressTimer) {
|
||||
clearTimeout(longPressTimer);
|
||||
longPressTimer = null;
|
||||
}
|
||||
if (e.touches.length === 2) {
|
||||
swallowTouch(e);
|
||||
@@ -296,13 +284,10 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset</span>
|
||||
}, {passive: false, capture: true});
|
||||
var longPressX = 0, longPressY = 0;
|
||||
if (!isWebGPU) canvas.addEventListener('touchmove', function (e) {
|
||||
if (e.touches.length === 1 && singleTouchActive) {
|
||||
if (longPressTimer && e.touches.length === 1) {
|
||||
var dx = e.touches[0].clientX - longPressX;
|
||||
var dy = e.touches[0].clientY - longPressY;
|
||||
var dist2 = dx*dx + dy*dy;
|
||||
if (dist2 > 25)
|
||||
singleTouchMoved = true;
|
||||
if (longPressTimer && dist2 > 100) { clearTimeout(longPressTimer); longPressTimer = null; }
|
||||
if (dx*dx + dy*dy > 100) { clearTimeout(longPressTimer); longPressTimer = null; }
|
||||
}
|
||||
if (doubleTapZoom && e.touches.length === 1) {
|
||||
swallowTouch(e);
|
||||
@@ -370,26 +355,11 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset</span>
|
||||
if (threeFingerActive || skipNextPinchMove || e.touches.length >= 2 || doubleTapZoom)
|
||||
swallowTouch(e);
|
||||
if (longPressTimer) { clearTimeout(longPressTimer); longPressTimer = null; }
|
||||
var cleanTap = singleTouchActive && !singleTouchMoved &&
|
||||
!longPressFired && !doubleTapZoom &&
|
||||
e.touches.length === 0;
|
||||
if (cleanTap && typeof _web_cancel_gesture === 'function')
|
||||
_web_cancel_gesture();
|
||||
if (longPressFired) {
|
||||
longPressFired = false;
|
||||
e.preventDefault(); /* Don't let GLFW see this as a click */
|
||||
}
|
||||
singleTouchActive = false;
|
||||
singleTouchMoved = false;
|
||||
doubleTapZoom = false;
|
||||
if (cleanTap) {
|
||||
clearPendingTapTimer();
|
||||
pendingTapTimer = setTimeout(function () {
|
||||
pendingTapTimer = null;
|
||||
if (typeof _web_toggle_animation === 'function')
|
||||
_web_toggle_animation();
|
||||
}, 300);
|
||||
}
|
||||
if (threeFingerActive && e.touches.length < 3) {
|
||||
threeFingerActive = false;
|
||||
var releaseX = gestureX, releaseY = gestureY;
|
||||
@@ -423,11 +393,8 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset</span>
|
||||
e.touches.length >= 2 || doubleTapZoom;
|
||||
if (handledGesture)
|
||||
swallowTouch(e);
|
||||
clearPendingTapTimer();
|
||||
if (longPressTimer) { clearTimeout(longPressTimer); longPressTimer = null; }
|
||||
longPressFired = false;
|
||||
singleTouchActive = false;
|
||||
singleTouchMoved = false;
|
||||
doubleTapZoom = false;
|
||||
skipNextPinchMove = false;
|
||||
if (threeFingerActive) {
|
||||
|
||||
Reference in new issue
Block a user