Skip to content

Commit

Permalink
Fixes incorrect PageX, PageY (fixes #21). Rework synthetic event crea…
Browse files Browse the repository at this point in the history
…tion/properties definition. Add intern test (fixes #6).
  • Loading branch information
Sebastien Pereira committed Sep 3, 2014
1 parent 6c6826c commit 02040d0
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 143 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ script:
- grunt jshint test:remote
env:
global:
- secure: eY1OxvXmDHrxYoO5hQwcWNptaJClL69aswUw5G+ZNppSEymNCTquYN/MS87iZm76G98o4A0aafM989d5UDhjU187NYdxf6K7jEPwtaxuHi6d48M0LRG/DoAWCNOUoNyNuhpRCVEB7XmwvZOG9nmoRcPvt+KjM5VkiOvp+CluCk0=
- secure: F0RyTrC3kdKomLNbKXJJA1Ju0ZCnB5E7oW7eYwkikLjlfn/4rBkuX4MYJqGBdCIwotpx0k30Wmql7cpYsk9pfM36NIqZoY3bOMITAY/FR8gxiE6zLjFEV/JBdY1hKIeDStsCEPJIRPd27oq4yK1j8dVFel9rI+aENWV1+CZ7o7o=
- secure: qWxE8Cml8cm35ztk4EAusV0WF7akjEjaH6GLjbAcpWTmQqLFHPbPODI0V7V6n9n2Cvxm7eV+70KTg7SgDa62pQndqlcP83mW0hnmfrbWwH0AsNYwDOnvfFDhCLDYN3dGpe7tQr0pLUNil6J/g7E6YYJmFxOrLDp3Y238c77Xdh8=
- secure: S2opjyuFArWLEl9H/82PYcHq63XNG6u9nCYZ+CobPT+h8CpKeoNfNwdwGyVnabLftbrB4c/y+L+DHT6p1G8PIr0Cm0T97ij5SRIsiFW/MqKL9NIzLiM/euXRvrQCkKBKndPo3DqYUe1iJIVNfmT8KtcAA0krQT9x2J258bsNo2c=
14 changes: 7 additions & 7 deletions handlers/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ define([
utils.dispatchEvent(e.target, createPointer(utils.events.OUT, e, {}));
// generate pointerleave events
utils.dispatchLeaveEvents(e.target, e.relatedTarget,
createPointer(utils.events.LEAVE, e, {bubbles: false}));
createPointer(utils.events.LEAVE, e));
}
MouseTracker.update(e);
}
Expand All @@ -80,7 +80,7 @@ define([
utils.dispatchEvent(e.target, createPointer(utils.events.OVER, e, {}));
// generate pointerenter events
utils.dispatchEnterEvents(e.target, e.relatedTarget,
createPointer(utils.events.ENTER, e, {bubbles: false}));
createPointer(utils.events.ENTER, e));
}
MouseTracker.update(e);
}
Expand Down Expand Up @@ -119,16 +119,16 @@ define([
props.altKey = mouseEvent.altKey;
props.shiftKey = mouseEvent.shiftKey;
props.metaKey = mouseEvent.metaKey;
props.pageX = mouseEvent.pageX;
props.pageY = mouseEvent.pageY;
// normalize button/buttons values
// http://www.w3.org/TR/pointerevents/#chorded-button-interactions
var buttonValue = mouseEvent.button,
buttonsValue = (mouseEvent.buttons !== undefined) ? mouseEvent.buttons :
utils.which2buttons(mouseEvent.which);
// on mouse move with no buttons pressed, buttonValue should be -1 but browsers implement
// with unsigned int: http://www.w3.org/TR/DOM-Level-3-Events/
// so we set it to 0.
if (mouseEvent.type === "mousemove" || mouseEvent.type === "mouseup") {
buttonValue = 0;

if (mouseEvent.type === "mousemove") {
buttonValue = -1;
}
props.button = buttonValue;
props.buttons = buttonsValue;
Expand Down
7 changes: 2 additions & 5 deletions handlers/mspointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ define([
function msPointerOut(e) {
utils.dispatchEvent(e.target, createPointer(utils.events.OUT, e, {}));
// generate pointerleave events
utils.dispatchLeaveEvents(e.target, e.relatedTarget, createPointer(utils.events.LEAVE, e, {bubbles: false}));
utils.dispatchLeaveEvents(e.target, e.relatedTarget, createPointer(utils.events.LEAVE, e));
}

/**
Expand All @@ -65,7 +65,7 @@ define([
function msPointerOver(e) {
utils.dispatchEvent(e.target, createPointer(utils.events.OVER, e, {}));
// generate pointerenter events
utils.dispatchEnterEvents(e.target, e.relatedTarget, createPointer(utils.events.ENTER, e, {bubbles: false}));
utils.dispatchEnterEvents(e.target, e.relatedTarget, createPointer(utils.events.ENTER, e));
}

/**
Expand Down Expand Up @@ -106,9 +106,6 @@ define([
function createPointer(pointerType, msPointerEvent, props) {
props = props || {};
// Mouse events properties
props.bubbles = msPointerEvent.bubbles;
props.cancelable = msPointerEvent.cancelable;
props.view = msPointerEvent.view;
props.detail = msPointerEvent.detail;
props.screenX = msPointerEvent.screenX;
props.screenY = msPointerEvent.screenY;
Expand Down
29 changes: 14 additions & 15 deletions handlers/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ define([
createPointer(utils.events.OUT, e, touch, {relatedTarget: touchTarget}));
// generate pointerleave event(s)
utils.dispatchLeaveEvents(lastElementFromPoint, touchTarget,
createPointer(utils.events.LEAVE, e, touch, {relatedTarget: touchTarget, bubbles: false}));
createPointer(utils.events.LEAVE, e, touch, {relatedTarget: touchTarget}));
// generate pointermove
utils.dispatchEvent(touchTarget, createPointer(utils.events.MOVE, e, touch, {}));
// generate pointerover
Expand All @@ -121,7 +121,7 @@ define([
// generate pointerenter event(s)
utils.dispatchEnterEvents(touchTarget, lastElementFromPoint,
createPointer(utils.events.ENTER, e, touch,
{relatedTarget: lastElementFromPoint, bubbles: false}));
{relatedTarget: lastElementFromPoint}));
} else {
utils.dispatchEvent(touchTarget, createPointer(utils.events.MOVE, e, touch, {}));
}
Expand Down Expand Up @@ -233,16 +233,16 @@ define([
props.altKey = touchEvent.altKey;
props.shiftKey = touchEvent.shiftKey;
props.metaKey = touchEvent.metaKey;
props.pageX = touch.pageX;
props.pageY = touch.pageY;
if (TouchTracker.hasCapture(touch.identifier)) { // W3C spec §10.1
props.relatedTarget = null;
}
// normalize button/buttons values
// http://www.w3.org/TR/pointerevents/#chorded-button-interactions
// for pointer: button=0, buttons=1, which=1 for all events but PointerMove: button=-1,buttons=0,which=0
// as it is not possible to assign negative value to button(s), just use 0.
props.button = 0;
props.button = (pointerType === utils.events.MOVE) ? -1 : 0;
props.buttons = 1;
props.which = 1;
props.which = props.button + 1;
// Pointer Events properties
props.pointerId = touch.identifier + 2; // avoid id collision: 1 is reserved for mouse events mapping
props.pointerType = "touch";
Expand Down Expand Up @@ -282,18 +282,17 @@ define([
* @return HTMLElement the DOM element.
*/
function elementFromTouch(touch) {
//todo: investigate #15821 (different behaviors?)
return touch.target.ownerDocument.elementFromPoint(touch.pageX, touch.pageY);
return touch.target.ownerDocument.elementFromPoint(touch.clientX, touch.clientY);
}

// todo:refactor + document TouchTracker/TouchInfo
/* function TouchInfo(touchId, touchAction) {
this.touchId = touchId;
this.touchAction = 0;
this.lastNativeEvent = null;
this.lastTargetElement = null;
this.captureTarget = null;
}*/
/* function TouchInfo(touchId, touchAction) {
this.touchId = touchId;
this.touchAction = 0;
this.lastNativeEvent = null;
this.lastTargetElement = null;
this.captureTarget = null;
}*/
var TouchTracker = {
// touchId of the primary pointer, or -1 if no primary pointer set.
primaryTouchId: -1,
Expand Down
Loading

0 comments on commit 02040d0

Please sign in to comment.