mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 06:36:11 +03:00
Multi-Touch MouseTracker Update
Refactored, fixed a couple bugs, unit tests working. Issuing a pull request.
This commit is contained in:
parent
73b7519471
commit
d324aea761
@ -157,17 +157,6 @@
|
|||||||
* Are we currently tracking mouse events.
|
* Are we currently tracking mouse events.
|
||||||
* @property {Boolean} capturing
|
* @property {Boolean} capturing
|
||||||
* Are we curruently capturing mouse events.
|
* Are we curruently capturing mouse events.
|
||||||
* @property {Boolean} insideElementPressed
|
|
||||||
* True if the left mouse button is currently being pressed and was
|
|
||||||
* initiated inside the tracked element, otherwise false.
|
|
||||||
* @property {Boolean} insideElement
|
|
||||||
* Are we currently inside the screen area of the tracked element.
|
|
||||||
* @property {OpenSeadragon.Point} lastPoint
|
|
||||||
* Position of last mouse down/move
|
|
||||||
* @property {Number} lastMouseDownTime
|
|
||||||
* Time of last mouse down.
|
|
||||||
* @property {OpenSeadragon.Point} lastMouseDownPoint
|
|
||||||
* Position of last mouse down
|
|
||||||
*/
|
*/
|
||||||
THIS[ this.hash ] = {
|
THIS[ this.hash ] = {
|
||||||
click: function ( event ) { onClick( _this, event ); },
|
click: function ( event ) { onClick( _this, event ); },
|
||||||
@ -215,6 +204,7 @@
|
|||||||
|
|
||||||
tracking: false,
|
tracking: false,
|
||||||
capturing: false,
|
capturing: false,
|
||||||
|
|
||||||
// Active Contact Points
|
// Active Contact Points
|
||||||
mousePoints: new $.MouseTracker.GesturePointList(),
|
mousePoints: new $.MouseTracker.GesturePointList(),
|
||||||
touchPoints: new $.MouseTracker.GesturePointList(),
|
touchPoints: new $.MouseTracker.GesturePointList(),
|
||||||
@ -777,11 +767,11 @@
|
|||||||
* @property {Number} id
|
* @property {Number} id
|
||||||
* Identifier unique from all other active GesturePoints for a given pointer device.
|
* Identifier unique from all other active GesturePoints for a given pointer device.
|
||||||
* @property {String} type
|
* @property {String} type
|
||||||
* "mouse", "touch", "pen", or "".
|
* The pointer device type: "mouse", "touch", "pen", or "".
|
||||||
* @property {Boolean} insideElementPressed
|
* @property {Boolean} insideElementPressed
|
||||||
* True if mouse button pressed or contact point initiated inside the screen area of the tracked element.
|
* True if mouse button pressed or contact point initiated inside the screen area of the tracked element.
|
||||||
* @property {Boolean} insideElement
|
* @property {Boolean} insideElement
|
||||||
* True if mouse cursor or contact point is currently inside the screen area of the tracked element.
|
* True if mouse cursor or contact point is currently inside the bounds of the tracked element.
|
||||||
* @property {Number} speed
|
* @property {Number} speed
|
||||||
* Continuously computed speed, in pixels per second.
|
* Continuously computed speed, in pixels per second.
|
||||||
* @property {Number} direction
|
* @property {Number} direction
|
||||||
@ -1107,14 +1097,14 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function getMouseRelative( event, element ) {
|
function getMouseRelative( event, element ) {
|
||||||
return getPointRelative( getMouseAbsolute( event ), element );
|
return getPointRelativeToAbsolute( getMouseAbsolute( event ), element );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function getPointRelative( point, element ) {
|
function getPointRelativeToAbsolute( point, element ) {
|
||||||
var offset = $.getElementOffset( element );
|
var offset = $.getElementOffset( element );
|
||||||
return point.minus( offset );
|
return point.minus( offset );
|
||||||
}
|
}
|
||||||
@ -1268,27 +1258,16 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onMouseOver( tracker, event ) {
|
function onMouseOver( tracker, event ) {
|
||||||
var time,
|
var gPoint;
|
||||||
position,
|
|
||||||
gPoint;
|
|
||||||
|
|
||||||
event = $.getEvent( event );
|
event = $.getEvent( event );
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
position = getMouseAbsolute( event );
|
|
||||||
|
|
||||||
gPoint = {
|
gPoint = {
|
||||||
id: $.MouseTracker.mousePointerId,
|
id: $.MouseTracker.mousePointerId,
|
||||||
type: 'mouse',
|
type: 'mouse',
|
||||||
//insideElementPressed: true,
|
|
||||||
insideElement: true,
|
insideElement: true,
|
||||||
//speed: 0,
|
currentPos: getMouseAbsolute( event ),
|
||||||
//startPos: position,
|
currentTime: $.now()
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
};
|
};
|
||||||
|
|
||||||
updatePointersOver( tracker, event, [ gPoint ] );
|
updatePointersOver( tracker, event, [ gPoint ] );
|
||||||
@ -1300,29 +1279,16 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onMouseOut( tracker, event ) {
|
function onMouseOut( tracker, event ) {
|
||||||
var time,
|
var gPoint;
|
||||||
position,
|
|
||||||
gPoint;
|
|
||||||
|
|
||||||
event = $.getEvent( event );
|
event = $.getEvent( event );
|
||||||
|
|
||||||
var eventOrTouchPoint = event;//isTouch ? event.touches[ 0 ] : event;
|
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
position = getMouseAbsolute( event );
|
|
||||||
|
|
||||||
gPoint = {
|
gPoint = {
|
||||||
id: $.MouseTracker.mousePointerId,
|
id: $.MouseTracker.mousePointerId,
|
||||||
type: 'mouse',
|
type: 'mouse',
|
||||||
//insideElementPressed: true,
|
|
||||||
insideElement: false,
|
insideElement: false,
|
||||||
//speed: 0,
|
currentPos: getMouseAbsolute( event ),
|
||||||
//startPos: position,
|
currentTime: $.now()
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
};
|
};
|
||||||
|
|
||||||
updatePointersOut( tracker, event, [ gPoint ] );
|
updatePointersOut( tracker, event, [ gPoint ] );
|
||||||
@ -1334,10 +1300,7 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onMouseDown( tracker, event ) {
|
function onMouseDown( tracker, event ) {
|
||||||
var delegate = THIS[ tracker.hash ],
|
var gPoint;
|
||||||
time,
|
|
||||||
position,
|
|
||||||
gPoint;
|
|
||||||
|
|
||||||
event = $.getEvent( event );
|
event = $.getEvent( event );
|
||||||
|
|
||||||
@ -1345,21 +1308,11 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
position = getMouseAbsolute( event );
|
|
||||||
|
|
||||||
gPoint = {
|
gPoint = {
|
||||||
id: $.MouseTracker.mousePointerId,
|
id: $.MouseTracker.mousePointerId,
|
||||||
type: 'mouse',
|
type: 'mouse',
|
||||||
insideElementPressed: true,
|
currentPos: getMouseAbsolute( event ),
|
||||||
insideElement: true,
|
currentTime: $.now()
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
};
|
};
|
||||||
|
|
||||||
addPointers( tracker, event, [ gPoint ] );
|
addPointers( tracker, event, [ gPoint ] );
|
||||||
@ -1454,8 +1407,11 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onMouseMove( tracker, event ) {
|
function onMouseMove( tracker, event ) {
|
||||||
|
var delegate = THIS[ tracker.hash ];
|
||||||
|
if ( !delegate.capturing ) {
|
||||||
handleMouseMove( tracker, event );
|
handleMouseMove( tracker, event );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1491,29 +1447,17 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onTouchEnter( tracker, event ) {
|
function onTouchEnter( tracker, event ) {
|
||||||
var time,
|
var i,
|
||||||
position,
|
|
||||||
i,
|
|
||||||
touchCount = event.changedTouches.length,
|
touchCount = event.changedTouches.length,
|
||||||
gPoints = [];
|
gPoints = [];
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
|
|
||||||
for ( i = 0; i < touchCount; i++ ) {
|
for ( i = 0; i < touchCount; i++ ) {
|
||||||
position = getMouseAbsolute( event.changedTouches[ i ] );
|
|
||||||
|
|
||||||
gPoints.push( {
|
gPoints.push( {
|
||||||
id: event.changedTouches[ i ].identifier,
|
id: event.changedTouches[ i ].identifier,
|
||||||
type: 'touch',
|
type: 'touch',
|
||||||
//insideElementPressed: true,
|
|
||||||
insideElement: true,
|
insideElement: true,
|
||||||
//speed: 0,
|
currentPos: getMouseAbsolute( event.changedTouches[ i ] ),
|
||||||
//startPos: position,
|
currentTime: $.now()
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1526,29 +1470,17 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onTouchLeave( tracker, event ) {
|
function onTouchLeave( tracker, event ) {
|
||||||
var time,
|
var i,
|
||||||
position,
|
|
||||||
i,
|
|
||||||
touchCount = event.changedTouches.length,
|
touchCount = event.changedTouches.length,
|
||||||
gPoints = [];
|
gPoints = [];
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
|
|
||||||
for ( i = 0; i < touchCount; i++ ) {
|
for ( i = 0; i < touchCount; i++ ) {
|
||||||
position = getMouseAbsolute( event.changedTouches[ i ] );
|
|
||||||
|
|
||||||
gPoints.push( {
|
gPoints.push( {
|
||||||
id: event.changedTouches[ i ].identifier,
|
id: event.changedTouches[ i ].identifier,
|
||||||
type: 'touch',
|
type: 'touch',
|
||||||
//insideElementPressed: true,
|
|
||||||
insideElement: false,
|
insideElement: false,
|
||||||
//speed: 0,
|
currentPos: getMouseAbsolute( event.changedTouches[ i ] ),
|
||||||
//startPos: position,
|
currentTime: $.now()
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1563,7 +1495,6 @@
|
|||||||
function onTouchStart( tracker, event ) {
|
function onTouchStart( tracker, event ) {
|
||||||
var delegate = THIS[ tracker.hash ],
|
var delegate = THIS[ tracker.hash ],
|
||||||
time,
|
time,
|
||||||
position,
|
|
||||||
gPoint,
|
gPoint,
|
||||||
i,
|
i,
|
||||||
touchCount = event.changedTouches.length,
|
touchCount = event.changedTouches.length,
|
||||||
@ -1575,13 +1506,7 @@
|
|||||||
gPoint = {
|
gPoint = {
|
||||||
id: event.changedTouches[ 0 ].identifier,
|
id: event.changedTouches[ 0 ].identifier,
|
||||||
type: 'touch',
|
type: 'touch',
|
||||||
//insideElementPressed: true,
|
|
||||||
insideElement: true,
|
insideElement: true,
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: getMouseAbsolute( event.changedTouches[ 0 ] ),
|
currentPos: getMouseAbsolute( event.changedTouches[ 0 ] ),
|
||||||
currentTime: time
|
currentTime: time
|
||||||
};
|
};
|
||||||
@ -1589,19 +1514,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
for ( i = 0; i < touchCount; i++ ) {
|
for ( i = 0; i < touchCount; i++ ) {
|
||||||
position = getMouseAbsolute( event.changedTouches[ i ] );
|
|
||||||
|
|
||||||
gPoints.push( {
|
gPoints.push( {
|
||||||
id: event.changedTouches[ i ].identifier,
|
id: event.changedTouches[ i ].identifier,
|
||||||
type: 'touch',
|
type: 'touch',
|
||||||
insideElementPressed: true,
|
currentPos: getMouseAbsolute( event.changedTouches[ i ] ),
|
||||||
insideElement: true,
|
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
currentTime: time
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
@ -1623,7 +1539,6 @@
|
|||||||
function onTouchEnd( tracker, event ) {
|
function onTouchEnd( tracker, event ) {
|
||||||
var delegate = THIS[ tracker.hash ],
|
var delegate = THIS[ tracker.hash ],
|
||||||
time,
|
time,
|
||||||
position,
|
|
||||||
gPoint,
|
gPoint,
|
||||||
i,
|
i,
|
||||||
touchCount = event.changedTouches.length,
|
touchCount = event.changedTouches.length,
|
||||||
@ -1632,19 +1547,10 @@
|
|||||||
time = $.now();
|
time = $.now();
|
||||||
|
|
||||||
for ( i = 0; i < touchCount; i++ ) {
|
for ( i = 0; i < touchCount; i++ ) {
|
||||||
position = getMouseAbsolute( event.changedTouches[ i ] );
|
|
||||||
|
|
||||||
gPoints.push( {
|
gPoints.push( {
|
||||||
id: event.changedTouches[ i ].identifier,
|
id: event.changedTouches[ i ].identifier,
|
||||||
type: 'touch',
|
type: 'touch',
|
||||||
//insideElementPressed: true,
|
currentPos: getMouseAbsolute( event.changedTouches[ i ] ),
|
||||||
//insideElement: true,
|
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
currentTime: time
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
@ -1655,13 +1561,7 @@
|
|||||||
gPoint = {
|
gPoint = {
|
||||||
id: event.changedTouches[ 0 ].identifier,
|
id: event.changedTouches[ 0 ].identifier,
|
||||||
type: 'touch',
|
type: 'touch',
|
||||||
//insideElementPressed: true,
|
|
||||||
insideElement: false,
|
insideElement: false,
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: getMouseAbsolute( event.changedTouches[ 0 ] ),
|
currentPos: getMouseAbsolute( event.changedTouches[ 0 ] ),
|
||||||
currentTime: time
|
currentTime: time
|
||||||
};
|
};
|
||||||
@ -1681,29 +1581,16 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onTouchMove( tracker, event ) {
|
function onTouchMove( tracker, event ) {
|
||||||
var time,
|
var i,
|
||||||
position,
|
|
||||||
i,
|
|
||||||
touchCount = event.changedTouches.length,
|
touchCount = event.changedTouches.length,
|
||||||
gPoints = [];
|
gPoints = [];
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
|
|
||||||
for ( i = 0; i < touchCount; i++ ) {
|
for ( i = 0; i < touchCount; i++ ) {
|
||||||
position = getMouseAbsolute( event.changedTouches[ i ] );
|
|
||||||
|
|
||||||
gPoints.push( {
|
gPoints.push( {
|
||||||
id: event.changedTouches[ i ].identifier,
|
id: event.changedTouches[ i ].identifier,
|
||||||
type: 'touch',
|
type: 'touch',
|
||||||
//insideElementPressed: true,
|
currentPos: getMouseAbsolute( event.changedTouches[ i ] ),
|
||||||
//insideElement: true,
|
currentTime: $.now()
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1722,29 +1609,14 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onTouchCancel( tracker, event ) {
|
function onTouchCancel( tracker, event ) {
|
||||||
var //time,
|
var i,
|
||||||
//position,
|
|
||||||
i,
|
|
||||||
touchCount = event.changedTouches.length,
|
touchCount = event.changedTouches.length,
|
||||||
gPoints = [];
|
gPoints = [];
|
||||||
|
|
||||||
//time = $.now();
|
|
||||||
|
|
||||||
for ( i = 0; i < touchCount; i++ ) {
|
for ( i = 0; i < touchCount; i++ ) {
|
||||||
//position = getMouseAbsolute( event.changedTouches[ i ] );
|
|
||||||
|
|
||||||
gPoints.push( {
|
gPoints.push( {
|
||||||
id: event.changedTouches[ i ].identifier,
|
id: event.changedTouches[ i ].identifier,
|
||||||
type: 'touch',
|
type: 'touch',
|
||||||
//insideElementPressed: true,
|
|
||||||
//insideElement: true,
|
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
//currentPos: position,
|
|
||||||
//currentTime: time
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1779,25 +1651,14 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onPointerOver( tracker, event ) {
|
function onPointerOver( tracker, event ) {
|
||||||
var time,
|
var gPoint;
|
||||||
position,
|
|
||||||
gPoint;
|
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
position = getMouseAbsolute( event );
|
|
||||||
|
|
||||||
gPoint = {
|
gPoint = {
|
||||||
id: event.pointerId,
|
id: event.pointerId,
|
||||||
type: getPointerType( event ),
|
type: getPointerType( event ),
|
||||||
//insideElementPressed: true,
|
|
||||||
insideElement: true,
|
insideElement: true,
|
||||||
//speed: 0,
|
currentPos: getMouseAbsolute( event ),
|
||||||
//startPos: position,
|
currentTime: $.now()
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
};
|
};
|
||||||
|
|
||||||
updatePointersOver( tracker, event, [ gPoint ] );
|
updatePointersOver( tracker, event, [ gPoint ] );
|
||||||
@ -1809,25 +1670,14 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onPointerOut( tracker, event ) {
|
function onPointerOut( tracker, event ) {
|
||||||
var time,
|
var gPoint;
|
||||||
position,
|
|
||||||
gPoint;
|
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
position = getMouseAbsolute( event );
|
|
||||||
|
|
||||||
gPoint = {
|
gPoint = {
|
||||||
id: event.pointerId,
|
id: event.pointerId,
|
||||||
type: getPointerType( event ),
|
type: getPointerType( event ),
|
||||||
//insideElementPressed: true,
|
|
||||||
insideElement: false,
|
insideElement: false,
|
||||||
//speed: 0,
|
currentPos: getMouseAbsolute( event ),
|
||||||
//startPos: position,
|
currentTime: $.now()
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
};
|
};
|
||||||
|
|
||||||
updatePointersOut( tracker, event, [ gPoint ] );
|
updatePointersOut( tracker, event, [ gPoint ] );
|
||||||
@ -1839,10 +1689,7 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onPointerDown( tracker, event ) {
|
function onPointerDown( tracker, event ) {
|
||||||
var delegate = THIS[ tracker.hash ],
|
var gPoint;
|
||||||
time,
|
|
||||||
position,
|
|
||||||
gPoint;
|
|
||||||
|
|
||||||
if ( event.button == 2 ) {
|
if ( event.button == 2 ) {
|
||||||
return;
|
return;
|
||||||
@ -1855,21 +1702,11 @@
|
|||||||
event.currentTarget.msSetPointerCapture( event.pointerId );
|
event.currentTarget.msSetPointerCapture( event.pointerId );
|
||||||
}
|
}
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
position = getMouseAbsolute( event );
|
|
||||||
|
|
||||||
gPoint = {
|
gPoint = {
|
||||||
id: event.pointerId,
|
id: event.pointerId,
|
||||||
type: getPointerType( event ),
|
type: getPointerType( event ),
|
||||||
insideElementPressed: true,
|
currentPos: getMouseAbsolute( event ),
|
||||||
insideElement: true,
|
currentTime: $.now()
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
};
|
};
|
||||||
|
|
||||||
addPointers( tracker, event, [ gPoint ] );
|
addPointers( tracker, event, [ gPoint ] );
|
||||||
@ -1887,10 +1724,7 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onPointerUp( tracker, event ) {
|
function onPointerUp( tracker, event ) {
|
||||||
var delegate = THIS[ tracker.hash ],
|
var gPoint;
|
||||||
time,
|
|
||||||
position,
|
|
||||||
gPoint;
|
|
||||||
|
|
||||||
if ( event.button == 2 ) {
|
if ( event.button == 2 ) {
|
||||||
return;
|
return;
|
||||||
@ -1903,21 +1737,11 @@
|
|||||||
event.currentTarget.msReleasePointerCapture( event.pointerId );
|
event.currentTarget.msReleasePointerCapture( event.pointerId );
|
||||||
}
|
}
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
position = getMouseAbsolute( event );
|
|
||||||
|
|
||||||
gPoint = {
|
gPoint = {
|
||||||
id: event.pointerId,
|
id: event.pointerId,
|
||||||
type: getPointerType( event ),
|
type: getPointerType( event ),
|
||||||
//insideElementPressed: true,
|
currentPos: getMouseAbsolute( event ),
|
||||||
//insideElement: true,
|
currentTime: $.now()
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
};
|
};
|
||||||
|
|
||||||
removePointers(tracker, event, [ gPoint ]);
|
removePointers(tracker, event, [ gPoint ]);
|
||||||
@ -1936,25 +1760,13 @@
|
|||||||
*/
|
*/
|
||||||
function onPointerMove( tracker, event ) {
|
function onPointerMove( tracker, event ) {
|
||||||
// Pointer changed coordinates, button state, pressure, tilt, or contact geometry (e.g. width and height)
|
// Pointer changed coordinates, button state, pressure, tilt, or contact geometry (e.g. width and height)
|
||||||
var time,
|
var gPoint;
|
||||||
position,
|
|
||||||
gPoint;
|
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
position = getMouseAbsolute( event );
|
|
||||||
|
|
||||||
gPoint = {
|
gPoint = {
|
||||||
id: event.pointerId,
|
id: event.pointerId,
|
||||||
type: getPointerType( event ),
|
type: getPointerType( event ),
|
||||||
//insideElementPressed: true,
|
currentPos: getMouseAbsolute( event ),
|
||||||
//insideElement: true,
|
currentTime: $.now()
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
};
|
};
|
||||||
|
|
||||||
updatePointers(tracker, event, [ gPoint ]);
|
updatePointers(tracker, event, [ gPoint ]);
|
||||||
@ -1972,25 +1784,11 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onPointerCancel( tracker, event ) {
|
function onPointerCancel( tracker, event ) {
|
||||||
var //time,
|
var gPoint;
|
||||||
//position,
|
|
||||||
gPoint;
|
|
||||||
|
|
||||||
//time = $.now();
|
|
||||||
//position = getMouseAbsolute( event );
|
|
||||||
|
|
||||||
gPoint = {
|
gPoint = {
|
||||||
id: event.pointerId,
|
id: event.pointerId,
|
||||||
type: getPointerType( event ),
|
type: getPointerType( event ),
|
||||||
//insideElementPressed: true,
|
|
||||||
//insideElement: true,
|
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
//currentPos: position,
|
|
||||||
//currentTime: time
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cancelPointers( tracker, event, [ gPoint ] );
|
cancelPointers( tracker, event, [ gPoint ] );
|
||||||
@ -2045,27 +1843,15 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function handleMouseMove( tracker, event ) {
|
function handleMouseMove( tracker, event ) {
|
||||||
var time,
|
var gPoint;
|
||||||
position,
|
|
||||||
gPoint;
|
|
||||||
|
|
||||||
event = $.getEvent( event );
|
event = $.getEvent( event );
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
position = getMouseAbsolute( event );
|
|
||||||
|
|
||||||
gPoint = {
|
gPoint = {
|
||||||
id: $.MouseTracker.mousePointerId,
|
id: $.MouseTracker.mousePointerId,
|
||||||
type: 'mouse',
|
type: 'mouse',
|
||||||
//insideElementPressed: true,
|
currentPos: getMouseAbsolute( event ),
|
||||||
//insideElement: true,
|
currentTime: $.now()
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
};
|
};
|
||||||
|
|
||||||
updatePointers( tracker, event, [ gPoint ] );
|
updatePointers( tracker, event, [ gPoint ] );
|
||||||
@ -2077,9 +1863,7 @@
|
|||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function handleMouseUp( tracker, event ) {
|
function handleMouseUp( tracker, event ) {
|
||||||
var time,
|
var gPoint;
|
||||||
position,
|
|
||||||
gPoint;
|
|
||||||
|
|
||||||
event = $.getEvent( event );
|
event = $.getEvent( event );
|
||||||
|
|
||||||
@ -2087,21 +1871,11 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
time = $.now();
|
|
||||||
position = getMouseAbsolute( event );
|
|
||||||
|
|
||||||
gPoint = {
|
gPoint = {
|
||||||
id: $.MouseTracker.mousePointerId,
|
id: $.MouseTracker.mousePointerId,
|
||||||
type: 'mouse',
|
type: 'mouse',
|
||||||
//insideElementPressed: true,
|
currentPos: getMouseAbsolute( event ),
|
||||||
//insideElement: true,
|
currentTime: $.now()
|
||||||
//speed: 0,
|
|
||||||
//startPos: position,
|
|
||||||
//startTime: time,
|
|
||||||
//lastPos: position,
|
|
||||||
//lastTime: time,
|
|
||||||
currentPos: position,
|
|
||||||
currentTime: time
|
|
||||||
};
|
};
|
||||||
|
|
||||||
removePointers( tracker, event, [ gPoint ] );
|
removePointers( tracker, event, [ gPoint ] );
|
||||||
@ -2145,6 +1919,8 @@
|
|||||||
curGPoint = gPoints[ i ];
|
curGPoint = gPoints[ i ];
|
||||||
|
|
||||||
// Initialize for drag/swipe/pinch
|
// Initialize for drag/swipe/pinch
|
||||||
|
curGPoint.insideElementPressed = true;
|
||||||
|
curGPoint.insideElement = true;
|
||||||
curGPoint.speed = 0;
|
curGPoint.speed = 0;
|
||||||
curGPoint.direction = 0;
|
curGPoint.direction = 0;
|
||||||
curGPoint.startPos = curGPoint.currentPos;
|
curGPoint.startPos = curGPoint.currentPos;
|
||||||
@ -2165,7 +1941,7 @@
|
|||||||
{
|
{
|
||||||
eventSource: tracker,
|
eventSource: tracker,
|
||||||
pointerType: curGPoint.type,
|
pointerType: curGPoint.type,
|
||||||
position: getPointRelative( curGPoint.startPos, tracker.element ),
|
position: getPointRelativeToAbsolute( curGPoint.startPos, tracker.element ),
|
||||||
isTouchEvent: curGPoint.type === 'touch',
|
isTouchEvent: curGPoint.type === 'touch',
|
||||||
originalEvent: event,
|
originalEvent: event,
|
||||||
preventDefaultAction: false,
|
preventDefaultAction: false,
|
||||||
@ -2227,7 +2003,7 @@
|
|||||||
{
|
{
|
||||||
eventSource: tracker,
|
eventSource: tracker,
|
||||||
pointerType: curGPoint.type,
|
pointerType: curGPoint.type,
|
||||||
position: getPointRelative( curGPoint.currentPos, tracker.element ),
|
position: getPointRelativeToAbsolute( curGPoint.currentPos, tracker.element ),
|
||||||
insideElementPressed: insideElementPressed,
|
insideElementPressed: insideElementPressed,
|
||||||
buttonDownAny: IS_BUTTON_DOWN,
|
buttonDownAny: IS_BUTTON_DOWN,
|
||||||
isTouchEvent: curGPoint.type === 'touch',
|
isTouchEvent: curGPoint.type === 'touch',
|
||||||
@ -2282,7 +2058,7 @@
|
|||||||
{
|
{
|
||||||
eventSource: tracker,
|
eventSource: tracker,
|
||||||
pointerType: curGPoint.type,
|
pointerType: curGPoint.type,
|
||||||
position: getPointRelative( curGPoint.currentPos, tracker.element ),
|
position: getPointRelativeToAbsolute( curGPoint.currentPos, tracker.element ),
|
||||||
insideElementPressed: insideElementPressed,
|
insideElementPressed: insideElementPressed,
|
||||||
buttonDownAny: IS_BUTTON_DOWN,
|
buttonDownAny: IS_BUTTON_DOWN,
|
||||||
isTouchEvent: curGPoint.type === 'touch',
|
isTouchEvent: curGPoint.type === 'touch',
|
||||||
@ -2340,7 +2116,26 @@
|
|||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( pointsListLength == 1 ) {
|
if ( pointsListLength === 0 ) {
|
||||||
|
// Move (no contacts)
|
||||||
|
if ( tracker.moveHandler ) {
|
||||||
|
propagate = tracker.moveHandler(
|
||||||
|
{
|
||||||
|
eventSource: tracker,
|
||||||
|
pointerType: curGPoint.type,
|
||||||
|
position: getPointRelativeToAbsolute( curGPoint.currentPos, tracker.element ),
|
||||||
|
isTouchEvent: curGPoint.type === 'touch',
|
||||||
|
originalEvent: event,
|
||||||
|
preventDefaultAction: false,
|
||||||
|
userData: tracker.userData
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if ( propagate === false ) {
|
||||||
|
$.cancelEvent( event );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( pointsListLength === 1 ) {
|
||||||
// Move (1 contact)
|
// Move (1 contact)
|
||||||
if ( tracker.moveHandler ) {
|
if ( tracker.moveHandler ) {
|
||||||
updateGPoint = pointsList.asArray()[ 0 ];
|
updateGPoint = pointsList.asArray()[ 0 ];
|
||||||
@ -2348,7 +2143,7 @@
|
|||||||
{
|
{
|
||||||
eventSource: tracker,
|
eventSource: tracker,
|
||||||
pointerType: updateGPoint.type,
|
pointerType: updateGPoint.type,
|
||||||
position: getPointRelative( updateGPoint.currentPos, tracker.element ),
|
position: getPointRelativeToAbsolute( updateGPoint.currentPos, tracker.element ),
|
||||||
isTouchEvent: updateGPoint.type === 'touch',
|
isTouchEvent: updateGPoint.type === 'touch',
|
||||||
originalEvent: event,
|
originalEvent: event,
|
||||||
preventDefaultAction: false,
|
preventDefaultAction: false,
|
||||||
@ -2368,7 +2163,7 @@
|
|||||||
{
|
{
|
||||||
eventSource: tracker,
|
eventSource: tracker,
|
||||||
pointerType: updateGPoint.type,
|
pointerType: updateGPoint.type,
|
||||||
position: getPointRelative( updateGPoint.currentPos, tracker.element ),
|
position: getPointRelativeToAbsolute( updateGPoint.currentPos, tracker.element ),
|
||||||
delta: delta,
|
delta: delta,
|
||||||
speed: updateGPoint.speed,
|
speed: updateGPoint.speed,
|
||||||
direction: updateGPoint.direction,
|
direction: updateGPoint.direction,
|
||||||
@ -2384,7 +2179,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( pointsListLength == 2 ) {
|
else if ( pointsListLength === 2 ) {
|
||||||
// Move (2 contacts, use center)
|
// Move (2 contacts, use center)
|
||||||
if ( tracker.moveHandler ) {
|
if ( tracker.moveHandler ) {
|
||||||
gPointArray = pointsList.asArray();
|
gPointArray = pointsList.asArray();
|
||||||
@ -2392,7 +2187,7 @@
|
|||||||
{
|
{
|
||||||
eventSource: tracker,
|
eventSource: tracker,
|
||||||
pointerType: gPointArray[ 0 ].type,
|
pointerType: gPointArray[ 0 ].type,
|
||||||
position: getPointRelative( getCenterPoint( gPointArray[ 0 ].currentPos, gPointArray[ 1 ].currentPos ), tracker.element ),
|
position: getPointRelativeToAbsolute( getCenterPoint( gPointArray[ 0 ].currentPos, gPointArray[ 1 ].currentPos ), tracker.element ),
|
||||||
isTouchEvent: gPointArray[ 0 ].type === 'touch',
|
isTouchEvent: gPointArray[ 0 ].type === 'touch',
|
||||||
originalEvent: event,
|
originalEvent: event,
|
||||||
preventDefaultAction: false,
|
preventDefaultAction: false,
|
||||||
@ -2417,8 +2212,8 @@
|
|||||||
eventSource: tracker,
|
eventSource: tracker,
|
||||||
pointerType: 'touch',
|
pointerType: 'touch',
|
||||||
gesturePoints: delegate.pinchGPoints,
|
gesturePoints: delegate.pinchGPoints,
|
||||||
lastCenter: getPointRelative( delegate.lastPinchCenter, tracker.element ),
|
lastCenter: getPointRelativeToAbsolute( delegate.lastPinchCenter, tracker.element ),
|
||||||
center: getPointRelative( delegate.currentPinchCenter, tracker.element ),
|
center: getPointRelativeToAbsolute( delegate.currentPinchCenter, tracker.element ),
|
||||||
lastDistance: delegate.lastPinchDist,
|
lastDistance: delegate.lastPinchDist,
|
||||||
distance: delegate.currentPinchDist,
|
distance: delegate.currentPinchDist,
|
||||||
shift: event.shiftKey,
|
shift: event.shiftKey,
|
||||||
@ -2476,7 +2271,7 @@
|
|||||||
if ( pointsListLength === 0 ) {
|
if ( pointsListLength === 0 ) {
|
||||||
|
|
||||||
insideElementPressed = removedGPoint.insideElementPressed;
|
insideElementPressed = removedGPoint.insideElementPressed;
|
||||||
insideElementReleased = $.pointInElement( tracker.element, releasePoint );
|
insideElementReleased = removedGPoint.insideElement || $.pointInElement( tracker.element, releasePoint );
|
||||||
|
|
||||||
// Release
|
// Release
|
||||||
if ( tracker.releaseHandler ) {
|
if ( tracker.releaseHandler ) {
|
||||||
@ -2484,7 +2279,7 @@
|
|||||||
{
|
{
|
||||||
eventSource: tracker,
|
eventSource: tracker,
|
||||||
pointerType: removedGPoint.type,
|
pointerType: removedGPoint.type,
|
||||||
position: getPointRelative( releasePoint, tracker.element ),
|
position: getPointRelativeToAbsolute( releasePoint, tracker.element ),
|
||||||
insideElementPressed: insideElementPressed,
|
insideElementPressed: insideElementPressed,
|
||||||
insideElementReleased: insideElementReleased,
|
insideElementReleased: insideElementReleased,
|
||||||
isTouchEvent: removedGPoint.type === 'touch',
|
isTouchEvent: removedGPoint.type === 'touch',
|
||||||
@ -2504,7 +2299,7 @@
|
|||||||
{
|
{
|
||||||
eventSource: tracker,
|
eventSource: tracker,
|
||||||
pointerType: removedGPoint.type,
|
pointerType: removedGPoint.type,
|
||||||
position: getPointRelative( removedGPoint.currentPos, tracker.element ),
|
position: getPointRelativeToAbsolute( removedGPoint.currentPos, tracker.element ),
|
||||||
speed: removedGPoint.speed,
|
speed: removedGPoint.speed,
|
||||||
direction: removedGPoint.direction,
|
direction: removedGPoint.direction,
|
||||||
shift: event.shiftKey,
|
shift: event.shiftKey,
|
||||||
@ -2530,7 +2325,7 @@
|
|||||||
{
|
{
|
||||||
eventSource: tracker,
|
eventSource: tracker,
|
||||||
pointerType: curGPoint.type,
|
pointerType: curGPoint.type,
|
||||||
position: getPointRelative( curGPoint.currentPos, tracker.element ),
|
position: getPointRelativeToAbsolute( curGPoint.currentPos, tracker.element ),
|
||||||
quick: quick,
|
quick: quick,
|
||||||
shift: event.shiftKey,
|
shift: event.shiftKey,
|
||||||
isTouchEvent: curGPoint.type === 'touch',
|
isTouchEvent: curGPoint.type === 'touch',
|
||||||
|
@ -2281,6 +2281,7 @@ function onCanvasDrag( event ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onCanvasDragEnd( event ) {
|
function onCanvasDragEnd( event ) {
|
||||||
|
// TODO: Make the magic numbers configurable (20 pixels-per-second speed threshold and 0.35 momentum dampener).
|
||||||
if ( event.pointerType !== 'mouse' && !event.preventDefaultAction && this.viewport && event.speed > 20 ) {
|
if ( event.pointerType !== 'mouse' && !event.preventDefaultAction && this.viewport && event.speed > 20 ) {
|
||||||
var amplitudeX = 0.35 * ( event.speed * Math.cos( event.direction ) ),
|
var amplitudeX = 0.35 * ( event.speed * Math.cos( event.direction ) ),
|
||||||
amplitudeY = 0.35 * ( event.speed * Math.sin( event.direction ) ),
|
amplitudeY = 0.35 * ( event.speed * Math.sin( event.direction ) ),
|
||||||
|
34
test/legacy.mouse.shim.js
Normal file
34
test/legacy.mouse.shim.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
(function($, undefined) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plugin to force OpenSeadragon to use the legacy mouse pointer event model
|
||||||
|
*/
|
||||||
|
|
||||||
|
$.MouseTracker.subscribeEvents = [ "click", "keypress", "focus", "blur", $.MouseTracker.wheelEventName ];
|
||||||
|
|
||||||
|
if( $.MouseTracker.wheelEventName == "DOMMouseScroll" ) {
|
||||||
|
// Older Firefox
|
||||||
|
$.MouseTracker.subscribeEvents.push( "MozMousePixelScroll" );
|
||||||
|
}
|
||||||
|
|
||||||
|
$.MouseTracker.subscribeEvents.push( "mouseover", "mouseout", "mousedown", "mouseup", "mousemove" );
|
||||||
|
if ( 'ontouchstart' in window ) {
|
||||||
|
// iOS, Android, and other W3c Touch Event implementations (see http://www.w3.org/TR/2011/WD-touch-events-20110505)
|
||||||
|
$.MouseTracker.subscribeEvents.push( "touchstart", "touchend", "touchmove", "touchcancel" );
|
||||||
|
if ( 'ontouchenter' in window ) {
|
||||||
|
$.MouseTracker.subscribeEvents.push( "touchenter", "touchleave" );
|
||||||
|
$.MouseTracker.haveTouchEnter = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$.MouseTracker.haveTouchEnter = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( 'ongesturestart' in window ) {
|
||||||
|
// iOS (see https://developer.apple.com/library/safari/documentation/UserExperience/Reference/GestureEventClassReference/GestureEvent/GestureEvent.html)
|
||||||
|
// Subscribe to these to prevent default gesture handling
|
||||||
|
$.MouseTracker.subscribeEvents.push( "gesturestart", "gesturechange" );
|
||||||
|
}
|
||||||
|
$.MouseTracker.mousePointerId = "legacy-mouse";
|
||||||
|
$.MouseTracker.maxTouchPoints = 10;
|
||||||
|
|
||||||
|
}(OpenSeadragon));
|
@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
@ -15,6 +15,7 @@
|
|||||||
<script src="/test/lib/jquery-ui-1.10.2/js/jquery-ui-1.10.2.min.js"></script>
|
<script src="/test/lib/jquery-ui-1.10.2/js/jquery-ui-1.10.2.min.js"></script>
|
||||||
<script src="/test/lib/jquery.simulate.js"></script>
|
<script src="/test/lib/jquery.simulate.js"></script>
|
||||||
<script src="/build/openseadragon/openseadragon.min.js"></script>
|
<script src="/build/openseadragon/openseadragon.min.js"></script>
|
||||||
|
<script src="/test/legacy.mouse.shim.js"></script>
|
||||||
<script src="/test/test.js"></script>
|
<script src="/test/test.js"></script>
|
||||||
|
|
||||||
<!-- Polyfill must be inserted first because it is testing functions
|
<!-- Polyfill must be inserted first because it is testing functions
|
||||||
|
Loading…
Reference in New Issue
Block a user