Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Mouse: Mouse is always an active pointer #282

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,37 @@ import dispatcher from 'dispatcher';

var n = window.navigator;
var s, r;
function assertDown(id) {
function assertActive(id) {
if (!dispatcher.pointermap.has(id)) {
throw new Error('InvalidPointerId');
var error = new Error('InvalidPointerId');
error.name = 'InvalidPointerId';
throw error;
}
}
function inActiveButtonState(id) {
var p = dispatcher.pointermap.get(id);
return p.buttons !== 0;
}
if (n.msPointerEnabled) {
s = function(pointerId) {
assertDown(pointerId);
this.msSetPointerCapture(pointerId);
assertActive(pointerId);
if (inActiveButtonState(pointerId)) {
this.msSetPointerCapture(pointerId);
}
};
r = function(pointerId) {
assertDown(pointerId);
assertActive(pointerId);
this.msReleasePointerCapture(pointerId);
};
} else {
s = function setPointerCapture(pointerId) {
assertDown(pointerId);
dispatcher.setCapture(pointerId, this);
assertActive(pointerId);
if (inActiveButtonState(pointerId)) {
dispatcher.setCapture(pointerId, this);
}
};
r = function releasePointerCapture(pointerId) {
assertDown(pointerId);
assertActive(pointerId);
dispatcher.releaseCapture(pointerId, this);
};
}
Expand Down
9 changes: 5 additions & 4 deletions src/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var mouseEvents = {
inEvent.buttons = e.buttons;
}
pointermap.set(this.POINTER_ID, inEvent);
if (!p) {
if (!p || p.buttons === 0) {
dispatcher.down(e);
} else {
dispatcher.move(e);
Expand All @@ -88,6 +88,7 @@ var mouseEvents = {
var e = this.prepareEvent(inEvent);
if (!HAS_BUTTONS) { this.prepareButtonsForMove(e, inEvent); }
e.button = -1;
pointermap.set(this.POINTER_ID, inEvent);
dispatcher.move(e);
}
},
Expand All @@ -112,7 +113,6 @@ var mouseEvents = {
// https://bugzilla.mozilla.org/show_bug.cgi?id=1223366
e.buttons &= ~BUTTON_TO_BUTTONS[e.button];
if (e.buttons === 0) {
this.cleanupMouse();
dispatcher.up(e);
} else {
dispatcher.move(e);
Expand All @@ -124,6 +124,7 @@ var mouseEvents = {
var e = this.prepareEvent(inEvent);
if (!HAS_BUTTONS) { this.prepareButtonsForMove(e, inEvent); }
e.button = -1;
pointermap.set(this.POINTER_ID, inEvent);
dispatcher.enterOver(e);
}
},
Expand All @@ -138,9 +139,9 @@ var mouseEvents = {
cancel: function(inEvent) {
var e = this.prepareEvent(inEvent);
dispatcher.cancel(e);
this.cleanupMouse();
this.deactivateMouse();
},
cleanupMouse: function() {
deactivateMouse: function() {
pointermap.delete(this.POINTER_ID);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
define(function(require) {
var registerSuite = require('intern!object');
var w3cTest = require('../support/w3cTest');
var name = 'pointerevent_releasepointercapture_invalid_pointerid-manual';

registerSuite({
name: name,

main: function() {
return w3cTest(this.remote, name + '.html')
.findById('target0')
.moveMouseTo(50, 25)
.pressMouseButton(0)
.moveMouseTo(60, 25)
.releaseMouseButton(0)
.end()
.checkResults();
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
define(function(require) {
var registerSuite = require('intern!object');
var w3cTest = require('../support/w3cTest');
var name = 'pointerevent_setpointercapture_inactive_button_mouse-manual';

registerSuite({
name: name,

main: function() {
return w3cTest(this.remote, name + '.html')
.findById('target0')
.moveMouseTo(50, 25)
.moveMouseTo(60, -25)
.end()
.checkResults();
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
define(function(require) {
var registerSuite = require('intern!object');
var w3cTest = require('../support/w3cTest');
var name = 'pointerevent_setpointercapture_invalid_pointerid-manual';

registerSuite({
name: name,

main: function() {
return w3cTest(this.remote, name + '.html')
.findById('target0')
.moveMouseTo(50, 25)
.clickMouseButton(0)
.end()
.checkResults();
}
});
});
6 changes: 3 additions & 3 deletions tests/intern.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ define({
'tests/functional/pointerevent_pointerup_pointertype-manual.js',

'tests/functional/pointerevent_releasepointercapture_events_to_original_target-manual.js',
'tests/functional/pointerevent_releasepointercapture_invalid_pointerid-manual.js',

// 'tests/functional/pointerevent_releasepointercapture_invalid_pointerid-manual.js',
// 'tests/functional/pointerevent_releasepointercapture_onpointercancel_touch-manual.js',
'tests/functional/pointerevent_releasepointercapture_onpointerup_mouse-manual',

// 'tests/functional/pointerevent_setpointercapture_disconnected-manual.js',
// 'tests/functional/pointerevent_setpointercapture_inactive_button_mouse-manual.js',
// 'tests/functional/pointerevent_setpointercapture_invalid_pointerid-manual.js',
'tests/functional/pointerevent_setpointercapture_inactive_button_mouse-manual.js',
'tests/functional/pointerevent_setpointercapture_invalid_pointerid-manual.js',
'tests/functional/pointerevent_setpointercapture_relatedtarget-manual.js'

// 'tests/functional/pointerevent_touch-action-auto-css_touch-manual.js',
Expand Down
11 changes: 6 additions & 5 deletions tests/support/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ define([
prep('pointer' + shortType, target, callback);
}
var e, type;
var buttons = shortType === 'down' ? 1 : 0;
if (HAS_MS) {
var cap = shortType.slice(0, 1).toUpperCase() + shortType.slice(1);
type = 'MSPointer' + cap;
Expand All @@ -30,11 +31,11 @@ define([
);
} else {
type = 'mouse' + shortType;
e = document.createEvent('MouseEvent');
e.initMouseEvent(
type, true, true, null, null, 0, 0, 0, 0, false, false,
false, false, 0, null
);
e = new MouseEvent(type, {
bubbles: true,
cancelable: true,
buttons: buttons
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh look, a sane API.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not supported on IE11 is it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😠 You're right, we still can't use this.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sane API should have given it away. 😈 I'm having the same problem when spitballing jQuery 4.0 event work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😭 We'll need to find a way to set the buttons property on IE's mouse event. I think it is only relevant for IE9, since IE10 uses MSPointerEvent and IE11 has native pointer events.

The need for a valid buttons property arises from proper button state checking during capture.

Alternatively, with more and more functional tests, we may be able to skip the four capture related unit tests on IE9 (or in general).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, well PEP doesn't support IE9 :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that solves it. 😆

}
target.dispatchEvent(e);
}
Expand Down