mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-01-31 23:21:42 +03:00
Fix more issues with tracking multiple pointers.
This commit is contained in:
parent
ad206a7738
commit
d9bda20e59
@ -317,6 +317,20 @@
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {Array.<OpenSeadragon.MouseTracker>} excluding the given pointer device type
|
||||||
|
* @function
|
||||||
|
* @param {String} type - The pointer device type: "mouse", "touch", "pen", etc.
|
||||||
|
* @returns {Array.<OpenSeadragon.MouseTracker>}
|
||||||
|
*/
|
||||||
|
getActivePointersListExceptType: function ( type ) {
|
||||||
|
var delegate = THIS[ this.hash ];
|
||||||
|
|
||||||
|
return delegate.activePointersLists.filter(function(pointersList) {
|
||||||
|
return pointersList.type !== type;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link OpenSeadragon.MouseTracker.GesturePointList|GesturePointList} for the given pointer device type,
|
* Returns the {@link OpenSeadragon.MouseTracker.GesturePointList|GesturePointList} for the given pointer device type,
|
||||||
* creating and caching a new {@link OpenSeadragon.MouseTracker.GesturePointList|GesturePointList} if one doesn't already exist for the type.
|
* creating and caching a new {@link OpenSeadragon.MouseTracker.GesturePointList|GesturePointList} if one doesn't already exist for the type.
|
||||||
@ -1201,6 +1215,30 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function Increment this pointer's contact count.
|
||||||
|
* It will evaluate whether this pointer type is allowed to have multiple contacts.
|
||||||
|
*/
|
||||||
|
addContact: function() {
|
||||||
|
++this.contacts;
|
||||||
|
|
||||||
|
if (this.contacts > 1 && (this.type === "mouse" || this.type === "pen")) {
|
||||||
|
this.contacts = 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function Decrement this pointer's contact count.
|
||||||
|
* It will make sure the count does not go below 0.
|
||||||
|
*/
|
||||||
|
removeContact: function() {
|
||||||
|
--this.contacts;
|
||||||
|
|
||||||
|
if (this.contacts < 0) {
|
||||||
|
this.contacts = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2005,7 +2043,7 @@
|
|||||||
* @private
|
* @private
|
||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function abortTouchContacts( tracker, event, pointsList ) {
|
function abortContacts( tracker, event, pointsList ) {
|
||||||
var i,
|
var i,
|
||||||
gPointCount = pointsList.getLength(),
|
gPointCount = pointsList.getLength(),
|
||||||
abortGPoints = [];
|
abortGPoints = [];
|
||||||
@ -2015,12 +2053,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( abortGPoints.length > 0 ) {
|
if ( abortGPoints.length > 0 ) {
|
||||||
// simulate touchend
|
// simulate touchend/mouseup
|
||||||
updatePointersUp( tracker, event, abortGPoints, 0 ); // 0 means primary button press/release or touch contact
|
updatePointersUp( tracker, event, abortGPoints, 0 ); // 0 means primary button press/release or touch contact
|
||||||
// release pointer capture
|
// release pointer capture
|
||||||
pointsList.captureCount = 1;
|
pointsList.captureCount = 1;
|
||||||
releasePointer( tracker, 'touch' );
|
releasePointer( tracker, pointsList.type );
|
||||||
// simulate touchleave
|
// simulate touchleave/mouseout
|
||||||
updatePointersExit( tracker, event, abortGPoints );
|
updatePointersExit( tracker, event, abortGPoints );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2043,7 +2081,7 @@
|
|||||||
|
|
||||||
if ( pointsList.getLength() > event.touches.length - touchCount ) {
|
if ( pointsList.getLength() > event.touches.length - touchCount ) {
|
||||||
$.console.warn('Tracked touch contact count doesn\'t match event.touches.length. Removing all tracked touch pointers.');
|
$.console.warn('Tracked touch contact count doesn\'t match event.touches.length. Removing all tracked touch pointers.');
|
||||||
abortTouchContacts( tracker, event, pointsList );
|
abortContacts( tracker, event, pointsList );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( i = 0; i < touchCount; i++ ) {
|
for ( i = 0; i < touchCount; i++ ) {
|
||||||
@ -2213,7 +2251,7 @@
|
|||||||
function onTouchCancel( tracker, event ) {
|
function onTouchCancel( tracker, event ) {
|
||||||
var pointsList = tracker.getActivePointersListByType('touch');
|
var pointsList = tracker.getActivePointersListByType('touch');
|
||||||
|
|
||||||
abortTouchContacts( tracker, event, pointsList );
|
abortContacts( tracker, event, pointsList );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2690,6 +2728,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Some pointers may steal control from another pointer without firing the appropriate release events
|
||||||
|
// e.g. Touching a screen while click-dragging with certain mice.
|
||||||
|
var otherPointsLists = tracker.getActivePointersListExceptType(gPoints[ 0 ].type);
|
||||||
|
for (i = 0; i < otherPointsLists.length; i++) {
|
||||||
|
//If another pointer has contact, simulate the release
|
||||||
|
abortContacts(tracker, event, otherPointsLists[i]); // No-op if no active pointer
|
||||||
|
}
|
||||||
|
|
||||||
// Only capture and track primary button, pen, and touch contacts
|
// Only capture and track primary button, pen, and touch contacts
|
||||||
if ( buttonChanged !== 0 ) {
|
if ( buttonChanged !== 0 ) {
|
||||||
// Aux Press
|
// Aux Press
|
||||||
@ -2740,7 +2786,7 @@
|
|||||||
startTrackingPointer( pointsList, curGPoint );
|
startTrackingPointer( pointsList, curGPoint );
|
||||||
}
|
}
|
||||||
|
|
||||||
pointsList.contacts++;
|
pointsList.addContact();
|
||||||
//$.console.log('contacts++ ', pointsList.contacts);
|
//$.console.log('contacts++ ', pointsList.contacts);
|
||||||
|
|
||||||
if ( tracker.dragHandler || tracker.dragEndHandler || tracker.pinchHandler ) {
|
if ( tracker.dragHandler || tracker.dragEndHandler || tracker.pinchHandler ) {
|
||||||
@ -2880,11 +2926,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A primary mouse button may have been released while the non-primary button was down
|
// A primary mouse button may have been released while the non-primary button was down
|
||||||
if (pointsList.contacts > 0 && pointsList.type === 'mouse') {
|
var otherPointsList = tracker.getActivePointersListByType("mouse");
|
||||||
// Stop tracking the mouse; see https://github.com/openseadragon/openseadragon/pull/1223
|
// Stop tracking the mouse; see https://github.com/openseadragon/openseadragon/pull/1223
|
||||||
pointsList.contacts--;
|
abortContacts(tracker, event, otherPointsList); // No-op if no active pointer
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2913,7 +2958,7 @@
|
|||||||
if ( wasCaptured ) {
|
if ( wasCaptured ) {
|
||||||
// Pointer was activated in our element but could have been removed in any element since events are captured to our element
|
// Pointer was activated in our element but could have been removed in any element since events are captured to our element
|
||||||
|
|
||||||
pointsList.contacts--;
|
pointsList.removeContact();
|
||||||
//$.console.log('contacts-- ', pointsList.contacts);
|
//$.console.log('contacts-- ', pointsList.contacts);
|
||||||
|
|
||||||
if ( tracker.dragHandler || tracker.dragEndHandler || tracker.pinchHandler ) {
|
if ( tracker.dragHandler || tracker.dragEndHandler || tracker.pinchHandler ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user