From 8dc9be8a348826380e01536b1a2f536a5e4947d9 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Mon, 21 Oct 2013 15:48:25 -0700 Subject: [PATCH] A few spec compliance changes to pass the w3c tests - relatedTarget must be null if pointerevent is capturing - `new PointerEvent(..) instanceof PointerEvent === true` - Manual tests: http://github.com/w3c/web-platform-tests --- src/PointerEvent.js | 6 ++++++ src/dispatcher.js | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/PointerEvent.js b/src/PointerEvent.js index 79d9eeb8..ed296aba 100644 --- a/src/PointerEvent.js +++ b/src/PointerEvent.js @@ -117,6 +117,9 @@ ); } + // make the event pass instanceof checks + e.__proto__ = PointerEvent.prototype; + // define the buttons property according to DOM Level 3 spec if (!HAS_BUTTONS) { // IE 10 has buttons on MouseEvent.prototype as a getter w/o any setting @@ -148,6 +151,9 @@ return e; } + // PointerEvent extends MouseEvent + PointerEvent.prototype = Object.create(MouseEvent.prototype); + // attach to window if (!scope.PointerEvent) { scope.PointerEvent = PointerEvent; diff --git a/src/dispatcher.js b/src/dispatcher.js index f2c7d8ee..058fcdc4 100644 --- a/src/dispatcher.js +++ b/src/dispatcher.js @@ -215,6 +215,10 @@ * @return {Event} A PointerEvent of type `inType` */ makeEvent: function(inType, inEvent) { + // relatedTarget must be null if pointer is captured + if (this.captureInfo) { + inEvent.relatedTarget = null; + } var e = new PointerEvent(inType, inEvent); this.targets.set(e, this.targets.get(inEvent) || inEvent.target); return e;