MouseTracker Original Events in Handlers

Touch events bug fix. Now uses touch object(s) properly when calculating
positions.
This commit is contained in:
Mark Salsbery 2013-09-10 17:23:19 -07:00
parent 13415b36f3
commit 1dc2d7e011

View File

@ -675,6 +675,7 @@
event = $.getEvent( event ); event = $.getEvent( event );
if ( !isTouch ) {
if ( $.Browser.vendor == $.BROWSERS.IE && if ( $.Browser.vendor == $.BROWSERS.IE &&
$.Browser.version < 9 && $.Browser.version < 9 &&
delegate.capturing && delegate.capturing &&
@ -694,6 +695,7 @@
isChild( tracker.element, from ) ) { isChild( tracker.element, from ) ) {
return; return;
} }
}
delegate.insideElement = true; delegate.insideElement = true;
@ -701,7 +703,7 @@
propagate = tracker.enterHandler( propagate = tracker.enterHandler(
tracker, tracker,
{ {
position: getMouseRelative( event, tracker.element ), position: getMouseRelative( isTouch ? event.changedTouches[ 0 ] : event, tracker.element ),
insideElementPressed: delegate.insideElementPressed, insideElementPressed: delegate.insideElementPressed,
buttonDownAny: IS_BUTTON_DOWN, buttonDownAny: IS_BUTTON_DOWN,
isTouchEvent: isTouch, isTouchEvent: isTouch,
@ -728,6 +730,7 @@
event = $.getEvent( event ); event = $.getEvent( event );
if ( !isTouch ) {
if ( $.Browser.vendor == $.BROWSERS.IE && if ( $.Browser.vendor == $.BROWSERS.IE &&
$.Browser.version < 9 && $.Browser.version < 9 &&
delegate.capturing && delegate.capturing &&
@ -748,6 +751,7 @@
isChild( tracker.element, to ) ) { isChild( tracker.element, to ) ) {
return; return;
} }
}
delegate.insideElement = false; delegate.insideElement = false;
@ -755,7 +759,7 @@
propagate = tracker.exitHandler( propagate = tracker.exitHandler(
tracker, tracker,
{ {
position: getMouseRelative( event, tracker.element ), position: getMouseRelative( isTouch ? event.changedTouches[ 0 ] : event, tracker.element ),
insideElementPressed: delegate.insideElementPressed, insideElementPressed: delegate.insideElementPressed,
buttonDownAny: IS_BUTTON_DOWN, buttonDownAny: IS_BUTTON_DOWN,
isTouchEvent: isTouch, isTouchEvent: isTouch,
@ -781,7 +785,9 @@
isTouch = isTouch || false; isTouch = isTouch || false;
event = $.getEvent( event ); var originalEvent = $.getEvent(event);
event = isTouch ? event.touches[ 0 ] : event;
if ( event.button == 2 ) { if ( event.button == 2 ) {
return; return;
@ -799,24 +805,25 @@
{ {
position: getMouseRelative( event, tracker.element ), position: getMouseRelative( event, tracker.element ),
isTouchEvent: isTouch, isTouchEvent: isTouch,
originalEvent: event, originalEvent: originalEvent,
userData: tracker.userData userData: tracker.userData
} }
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( event ); $.cancelEvent( originalEvent );
} }
} }
if ( tracker.pressHandler || tracker.dragHandler ) { if ( tracker.pressHandler || tracker.dragHandler ) {
$.cancelEvent( event ); $.cancelEvent( originalEvent );
} }
if ( noCapture ) { if ( noCapture ) {
return; return;
} }
if ( !( $.Browser.vendor == $.BROWSERS.IE && $.Browser.version < 9 ) || if ( isTouch ||
!( $.Browser.vendor == $.BROWSERS.IE && $.Browser.version < 9 ) ||
!IS_CAPTURING ) { !IS_CAPTURING ) {
captureMouse( tracker ); captureMouse( tracker );
IS_CAPTURING = true; IS_CAPTURING = true;
@ -879,7 +886,9 @@
isTouch = isTouch || false; isTouch = isTouch || false;
event = $.getEvent( event ); var originalEvent = $.getEvent(event);
event = isTouch ? event.changedTouches[ 0 ] : event;
if ( event.button == 2 ) { if ( event.button == 2 ) {
return; return;
@ -895,17 +904,17 @@
insideElementPressed: insideElementPressed, insideElementPressed: insideElementPressed,
insideElementRelease: insideElementRelease, insideElementRelease: insideElementRelease,
isTouchEvent: isTouch, isTouchEvent: isTouch,
originalEvent: event, originalEvent: originalEvent,
userData: tracker.userData userData: tracker.userData
} }
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( event ); $.cancelEvent( originalEvent );
} }
} }
if ( insideElementPressed && insideElementRelease ) { if ( insideElementPressed && insideElementRelease ) {
handleMouseClick( tracker, event ); handleMouseClick( tracker, originalEvent, isTouch );
} }
} }
@ -1064,6 +1073,9 @@
propagate = tracker.scrollHandler( propagate = tracker.scrollHandler(
tracker, tracker,
{ {
// Note: Ok to call getMouseRelative on passed event for isTouch==true since
// event.pageX/event.pageY are added to the original touchmove event in
// onTouchMove().
position: getMouseRelative( event, tracker.element ), position: getMouseRelative( event, tracker.element ),
scroll: nDelta, scroll: nDelta,
shift: event.shiftKey, shift: event.shiftKey,
@ -1083,11 +1095,15 @@
* @private * @private
* @inner * @inner
*/ */
function handleMouseClick( tracker, event ) { function handleMouseClick( tracker, event, isTouch ) {
var delegate = THIS[tracker.hash], var delegate = THIS[tracker.hash],
propagate; propagate;
event = $.getEvent( event ); isTouch = isTouch || false;
var originalEvent = $.getEvent( event );
event = isTouch ? event.changedTouches[0] : event;
if ( event.button == 2 ) { if ( event.button == 2 ) {
return; return;
@ -1105,14 +1121,14 @@
{ {
position: getMouseRelative( event, tracker.element ), position: getMouseRelative( event, tracker.element ),
quick: quick, quick: quick,
shift: event.shiftKey, shift: originalEvent.shiftKey,
isTouchEvent: false, isTouchEvent: isTouch,
originalEvent: event, originalEvent: originalEvent,
userData: tracker.userData userData: tracker.userData
} }
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( event ); $.cancelEvent( originalEvent );
} }
} }
} }
@ -1130,7 +1146,8 @@
isTouch = isTouch || false; isTouch = isTouch || false;
event = $.getEvent( event ); var originalEvent = $.getEvent(event);
event = isTouch ? event.touches[0] : event;
point = getMouseAbsolute( event ); point = getMouseAbsolute( event );
delta = point.minus( delegate.lastPoint ); delta = point.minus( delegate.lastPoint );
@ -1142,14 +1159,14 @@
{ {
position: getMouseRelative( event, tracker.element ), position: getMouseRelative( event, tracker.element ),
delta: delta, delta: delta,
shift: event.shiftKey, shift: originalEvent.shiftKey,
isTouchEvent: isTouch, isTouchEvent: isTouch,
originalEvent: event, originalEvent: originalEvent,
userData: tracker.userData userData: tracker.userData
} }
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( event ); $.cancelEvent( originalEvent );
} }
} }
} }