From a4dbae07545aecf978b7a4f12b1356abfd1bd4fb Mon Sep 17 00:00:00 2001 From: Daniel Zimmermann Date: Fri, 29 Apr 2016 18:30:30 +1000 Subject: [PATCH 1/3] Handle simultaneous touch events Found and tested on an iPhone 5s w/ iOS 9.2. Not sure about other devices. Fixes #877 --- src/mousetracker.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index 4528df03..6b78f4d8 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -1357,11 +1357,11 @@ * @private * @inner */ - function capturePointer( tracker, pointerType ) { + function capturePointer( tracker, pointerType, touchCount ) { var pointsList = tracker.getActivePointersListByType( pointerType ), eventParams; - pointsList.captureCount++; + pointsList.captureCount += (pointerType === 'touch' ? touchCount : 1); if ( pointsList.captureCount === 1 ) { if ( $.Browser.vendor === $.BROWSERS.IE && $.Browser.version < 9 ) { @@ -1400,11 +1400,11 @@ * @private * @inner */ - function releasePointer( tracker, pointerType ) { + function releasePointer( tracker, pointerType, touchCount ) { var pointsList = tracker.getActivePointersListByType( pointerType ), eventParams; - pointsList.captureCount--; + pointsList.captureCount -= (pointerType === 'touch' ? touchCount : 1); if ( pointsList.captureCount === 0 ) { if ( $.Browser.vendor === $.BROWSERS.IE && $.Browser.version < 9 ) { @@ -2074,7 +2074,7 @@ if ( updatePointersDown( tracker, event, gPoints, 0 ) ) { // 0 means primary button press/release or touch contact $.stopEvent( event ); - capturePointer( tracker, 'touch' ); + capturePointer( tracker, 'touch', touchCount ); } $.cancelEvent( event ); @@ -2128,7 +2128,7 @@ } if ( updatePointersUp( tracker, event, gPoints, 0 ) ) { - releasePointer( tracker, 'touch' ); + releasePointer( tracker, 'touch', touchCount ); } // simulate touchleave on our tracked element From c25bf0a2398abc95fec5fdead07ceac33aa14dfc Mon Sep 17 00:00:00 2001 From: Daniel Zimmermann Date: Sat, 14 May 2016 22:16:36 +1000 Subject: [PATCH 2/3] Correctly handle touch PointerEvents `onPointerDown/Up` may call `capture/releasePointer` with `"touch"` as the pointerType, which would result in a bug as `touchCount` would be `undefined`. `capture/releasePointer` should just default to a count of `1` if not specified. This properly retains the existing behaviour for non-TouchEvent handling. --- src/mousetracker.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index 6b78f4d8..498a72ac 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -1357,11 +1357,11 @@ * @private * @inner */ - function capturePointer( tracker, pointerType, touchCount ) { + function capturePointer( tracker, pointerType, pointerCount ) { var pointsList = tracker.getActivePointersListByType( pointerType ), eventParams; - pointsList.captureCount += (pointerType === 'touch' ? touchCount : 1); + pointsList.captureCount += (pointerCount || 1); if ( pointsList.captureCount === 1 ) { if ( $.Browser.vendor === $.BROWSERS.IE && $.Browser.version < 9 ) { @@ -1400,11 +1400,11 @@ * @private * @inner */ - function releasePointer( tracker, pointerType, touchCount ) { + function releasePointer( tracker, pointerType, pointerCount ) { var pointsList = tracker.getActivePointersListByType( pointerType ), eventParams; - pointsList.captureCount -= (pointerType === 'touch' ? touchCount : 1); + pointsList.captureCount -= (pointerCount || 1); if ( pointsList.captureCount === 0 ) { if ( $.Browser.vendor === $.BROWSERS.IE && $.Browser.version < 9 ) { From 7935ab82d4bbd7f26fcfb7acaed8fa85fa90f3d9 Mon Sep 17 00:00:00 2001 From: Daniel Zimmermann Date: Mon, 16 May 2016 06:26:18 +1000 Subject: [PATCH 3/3] Add unit tests for multi-touch --- test/coverage.html | 1 + test/helpers/touch.js | 134 +++++++++++++++++++++++++++++++++++++++++ test/modules/events.js | 78 +++++++++++++++++++++++- test/test.html | 1 + 4 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 test/helpers/touch.js diff --git a/test/coverage.html b/test/coverage.html index 81ffe579..b04d5fda 100644 --- a/test/coverage.html +++ b/test/coverage.html @@ -53,6 +53,7 @@ +