From 47cc04ff5371ea1bcbd8dde1236bfb274a763c14 Mon Sep 17 00:00:00 2001 From: Ronny Mikalsen Date: Tue, 22 Feb 2022 14:24:10 +0100 Subject: [PATCH 1/4] fix: contacts points on touch devices Swiping fast multiple times makes contacts points in mousetracker to be out of sync for touch event Fixes #2117 --- src/mousetracker.js | 22 ++++++++++++++-------- test/demo/iiif.html | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index a6a600d0..0a8c36c1 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -1400,11 +1400,20 @@ * @function */ removeContact: function() { - --this.contacts; + if ( + (this.type === "mouse" || + this.type === "pen" || + this.type === "touch") && + this.contacts > 0 + ) { + --this.contacts; - if (this.contacts < 0) { - $.console.warn('GesturePointList.removeContact() Implausible contacts value'); - this.contacts = 0; + if (this.contacts < 0) { + $.console.warn( + "GesturePointList.removeContact() Implausible contacts value" + ); + this.contacts = 0; + } } } }; @@ -2823,10 +2832,7 @@ // If child element relinquishes capture to a parent we may get here // from a pointerleave event while a pointerup event will never be received. // In that case, we'll clean up the contact count - if ( (pointsList.type === 'mouse' || pointsList.type === 'pen') && - pointsList.contacts > 0 ) { - pointsList.removeContact(); - } + pointsList.removeContact(); listLength = pointsList.removeById( gPoint.id ); } else { diff --git a/test/demo/iiif.html b/test/demo/iiif.html index 5d978df3..29ed803a 100644 --- a/test/demo/iiif.html +++ b/test/demo/iiif.html @@ -25,7 +25,7 @@ // debugMode: true, id: "contentDiv", prefixUrl: "../../build/openseadragon/images/", - tileSources: "http://wellcomelibrary.org/iiif-img/b11768265-0/a6801943-b8b4-4674-908c-7d5b27e70569/info.json", + tileSources: "https://iiif.wellcomecollection.org/image/V0021191/info.json", showNavigator:true }); From 0f984bd3b354f9e311438b5720bb1e1fd20b44f6 Mon Sep 17 00:00:00 2001 From: Ronny Mikalsen Date: Wed, 2 Mar 2022 10:10:30 +0100 Subject: [PATCH 2/4] refactor: removed unnecessary code --- src/mousetracker.js | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index 0a8c36c1..4e96d23b 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -1400,20 +1400,8 @@ * @function */ removeContact: function() { - if ( - (this.type === "mouse" || - this.type === "pen" || - this.type === "touch") && - this.contacts > 0 - ) { + if ( this.contacts > 0 ) { --this.contacts; - - if (this.contacts < 0) { - $.console.warn( - "GesturePointList.removeContact() Implausible contacts value" - ); - this.contacts = 0; - } } } }; From eeeccff1baabcbd18ea94062ccf90b46d01811ad Mon Sep 17 00:00:00 2001 From: Ronny Mikalsen Date: Wed, 2 Mar 2022 10:12:06 +0100 Subject: [PATCH 3/4] chore: revert code that should be in another PR --- test/demo/iiif.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/demo/iiif.html b/test/demo/iiif.html index 29ed803a..5d978df3 100644 --- a/test/demo/iiif.html +++ b/test/demo/iiif.html @@ -25,7 +25,7 @@ // debugMode: true, id: "contentDiv", prefixUrl: "../../build/openseadragon/images/", - tileSources: "https://iiif.wellcomecollection.org/image/V0021191/info.json", + tileSources: "http://wellcomelibrary.org/iiif-img/b11768265-0/a6801943-b8b4-4674-908c-7d5b27e70569/info.json", showNavigator:true }); From 576a0f9c3392bbdf01765b8595f28f57bd644f49 Mon Sep 17 00:00:00 2001 From: Ronny Mikalsen Date: Mon, 14 Mar 2022 14:26:11 +0100 Subject: [PATCH 4/4] fix: setting contacts to 0 if below 0 --- src/mousetracker.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index 4e96d23b..8c811326 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -1400,8 +1400,10 @@ * @function */ removeContact: function() { - if ( this.contacts > 0 ) { - --this.contacts; + --this.contacts; + + if (this.contacts < 0) { + this.contacts = 0; } } };