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

Capture: Assert node is connected #283

Merged
merged 1 commit into from
May 19, 2016
Merged
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
9 changes: 9 additions & 0 deletions src/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ function assertActive(id) {
throw error;
}
}
function assertConnected(elem) {
if (!elem.ownerDocument.contains(elem)) {
var error = new Error('InvalidStateError');
error.name = 'InvalidStateError';
throw error;
}
}
function inActiveButtonState(id) {
var p = dispatcher.pointermap.get(id);
return p.buttons !== 0;
}
if (n.msPointerEnabled) {
s = function(pointerId) {
assertActive(pointerId);
assertConnected(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that order matters here, but we should at least be consistent in our two paths. For msPointer, we check active then connected; for everyone else we check connected then active.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for catching that! Updating it to the order from http://www.w3.org/TR/pointerevents/#setting-pointer-capture

if (inActiveButtonState(pointerId)) {
this.msSetPointerCapture(pointerId);
}
Expand All @@ -27,6 +35,7 @@ if (n.msPointerEnabled) {
} else {
s = function setPointerCapture(pointerId) {
assertActive(pointerId);
assertConnected(this);
if (inActiveButtonState(pointerId)) {
dispatcher.setCapture(pointerId, this);
}
Expand Down
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_disconnected-manual';

registerSuite({
name: name,

main: function() {
return w3cTest(this.remote, name + '.html')
.findById('target0')
.moveMouseTo(50, 25)
.clickMouseButton(0)
.end()
.checkResults();
}
});
});
2 changes: 1 addition & 1 deletion tests/intern.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ define({
// '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_disconnected-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'
Expand Down