From 6a1a6275ed069b86d5137004cf5224fa7f699a3c Mon Sep 17 00:00:00 2001 From: Mark Salsbery <> Date: Tue, 2 Mar 2021 10:29:44 -0800 Subject: [PATCH] MouseTracker: Allow pre-processing of click and dblclick events --- src/mousetracker.js | 52 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index 703e33ec..60de2503 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -1247,7 +1247,7 @@ * @property {Number} eventPhase * 0 == NONE, 1 == CAPTURING_PHASE, 2 == AT_TARGET, 3 == BUBBLING_PHASE. * @property {String} eventType - * "contextmenu", "gotpointercapture", "lostpointercapture", "pointerenter", "pointerleave", "pointerover", "pointerout", "pointerdown", "pointerup", "pointermove", "pointercancel", "wheel". + * "contextmenu", "gotpointercapture", "lostpointercapture", "pointerenter", "pointerleave", "pointerover", "pointerout", "pointerdown", "pointerup", "pointermove", "pointercancel", "wheel", "click", "dblclick". * @property {String} pointerType * "mouse", "touch", "pen", etc. * @property {Boolean} isEmulated @@ -1802,9 +1802,24 @@ * @inner */ function onClick( tracker, event ) { - if ( tracker.clickHandler ) { + event = $.getEvent( event ); + + //$.console.log('onClick ' + (tracker.userData ? tracker.userData.toString() : '')); + + var eventInfo = { + originalEvent: event, + eventType: 'click', + pointerType: 'mouse', + isEmulated: false + }; + preProcessEvent( tracker, eventInfo ); + + if ( eventInfo.preventDefault && !eventInfo.defaultPrevented ) { $.cancelEvent( event ); } + if ( eventInfo.stopPropagation ) { + $.stopEvent( event ); + } } @@ -1813,9 +1828,24 @@ * @inner */ function onDblClick( tracker, event ) { - if ( tracker.dblClickHandler ) { + event = $.getEvent( event ); + + //$.console.log('onDblClick ' + (tracker.userData ? tracker.userData.toString() : '')); + + var eventInfo = { + originalEvent: event, + eventType: 'dblclick', + pointerType: 'mouse', + isEmulated: false + }; + preProcessEvent( tracker, eventInfo ); + + if ( eventInfo.preventDefault && !eventInfo.defaultPrevented ) { $.cancelEvent( event ); } + if ( eventInfo.stopPropagation ) { + $.stopEvent( event ); + } } @@ -1972,7 +2002,7 @@ preProcessEvent( tracker, eventInfo ); // ContextMenu - if ( tracker.contextMenuHandler ) { + if ( tracker.contextMenuHandler && !eventInfo.preventGesture && !eventInfo.defaultPrevented ) { tracker.contextMenuHandler( { eventSource: tracker, @@ -3241,6 +3271,20 @@ eventInfo.preventGesture = false; eventInfo.stopPropagation = false; break; + case 'click': + eventInfo.isStopable = true; + eventInfo.isCancelable = true; + eventInfo.preventDefault = !!tracker.clickHandler; + eventInfo.preventGesture = false; + eventInfo.stopPropagation = false; + break; + case 'dblclick': + eventInfo.isStopable = true; + eventInfo.isCancelable = true; + eventInfo.preventDefault = !!tracker.dblClickHandler; + eventInfo.preventGesture = false; + eventInfo.stopPropagation = false; + break; case 'contextmenu': eventInfo.isStopable = true; eventInfo.isCancelable = true;