mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 15:12:18 +00:00
Updated passive and capture states of the input handlers
This commit is contained in:
parent
c328d1ea59
commit
fb2c2c75b2
3 changed files with 90 additions and 40 deletions
|
@ -46,6 +46,7 @@ var ValueToColor = require('../display/color/ValueToColor');
|
||||||
* @property {object} [?input.mouse.target=null] - [description]
|
* @property {object} [?input.mouse.target=null] - [description]
|
||||||
* @property {boolean} [input.touch=true] - [description]
|
* @property {boolean} [input.touch=true] - [description]
|
||||||
* @property {object} [?input.touch.target=null] - [description]
|
* @property {object} [?input.touch.target=null] - [description]
|
||||||
|
* @property {object} [?input.touch.capture=true] - [description]
|
||||||
* @property {boolean} [input.gamepad=false] - [description]
|
* @property {boolean} [input.gamepad=false] - [description]
|
||||||
* @property {boolean} [disableContextMenu=false] - [description]
|
* @property {boolean} [disableContextMenu=false] - [description]
|
||||||
* @property {boolean} [banner=false] - [description]
|
* @property {boolean} [banner=false] - [description]
|
||||||
|
@ -124,9 +125,11 @@ var Config = new Class({
|
||||||
|
|
||||||
this.inputMouse = GetValue(config, 'input.mouse', true);
|
this.inputMouse = GetValue(config, 'input.mouse', true);
|
||||||
this.inputMouseEventTarget = GetValue(config, 'input.mouse.target', null);
|
this.inputMouseEventTarget = GetValue(config, 'input.mouse.target', null);
|
||||||
|
this.inputMouseCapture = GetValue(config, 'input.mouse.capture', true);
|
||||||
|
|
||||||
this.inputTouch = GetValue(config, 'input.touch', true);
|
this.inputTouch = GetValue(config, 'input.touch', true);
|
||||||
this.inputTouchEventTarget = GetValue(config, 'input.touch.target', null);
|
this.inputTouchEventTarget = GetValue(config, 'input.touch.target', null);
|
||||||
|
this.inputTouchCapture = GetValue(config, 'input.touch.capture', true);
|
||||||
|
|
||||||
this.inputGamepad = GetValue(config, 'input.gamepad', false);
|
this.inputGamepad = GetValue(config, 'input.gamepad', false);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ var MouseManager = new Class({
|
||||||
this.manager = inputManager;
|
this.manager = inputManager;
|
||||||
|
|
||||||
// @property {boolean} capture - If true the DOM mouse events will have event.preventDefault applied to them, if false they will propagate fully.
|
// @property {boolean} capture - If true the DOM mouse events will have event.preventDefault applied to them, if false they will propagate fully.
|
||||||
this.capture = false;
|
this.capture = true;
|
||||||
|
|
||||||
this.enabled = false;
|
this.enabled = false;
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ var MouseManager = new Class({
|
||||||
|
|
||||||
this.enabled = config.inputMouse;
|
this.enabled = config.inputMouse;
|
||||||
this.target = config.inputMouseEventTarget;
|
this.target = config.inputMouseEventTarget;
|
||||||
|
this.capture = config.inputMouseCapture;
|
||||||
|
|
||||||
if (!this.target)
|
if (!this.target)
|
||||||
{
|
{
|
||||||
|
@ -112,10 +113,16 @@ var MouseManager = new Class({
|
||||||
startListeners: function ()
|
startListeners: function ()
|
||||||
{
|
{
|
||||||
var queue = this.manager.queue;
|
var queue = this.manager.queue;
|
||||||
|
var target = this.target;
|
||||||
|
|
||||||
var _this = this;
|
var passive = { passive: true };
|
||||||
|
var nonPassive = { passive: false };
|
||||||
|
|
||||||
var handler = function (event)
|
var handler;
|
||||||
|
|
||||||
|
if (this.capture)
|
||||||
|
{
|
||||||
|
handler = function (event)
|
||||||
{
|
{
|
||||||
if (event.preventDefaulted)
|
if (event.preventDefaulted)
|
||||||
{
|
{
|
||||||
|
@ -125,21 +132,37 @@ var MouseManager = new Class({
|
||||||
|
|
||||||
queue.push(event);
|
queue.push(event);
|
||||||
|
|
||||||
if (_this.capture)
|
|
||||||
{
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.handler = handler;
|
target.addEventListener('mousemove', handler, nonPassive);
|
||||||
|
target.addEventListener('mousedown', handler, nonPassive);
|
||||||
|
target.addEventListener('mouseup', handler, nonPassive);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
handler = function (event)
|
||||||
|
{
|
||||||
|
if (event.preventDefaulted)
|
||||||
|
{
|
||||||
|
// Do nothing if event already handled
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.target.addEventListener('mousemove', handler, false);
|
queue.push(event);
|
||||||
this.target.addEventListener('mousedown', handler, false);
|
};
|
||||||
this.target.addEventListener('mouseup', handler, false);
|
|
||||||
|
target.addEventListener('mousemove', handler, passive);
|
||||||
|
target.addEventListener('mousedown', handler, passive);
|
||||||
|
target.addEventListener('mouseup', handler, passive);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.handler = handler;
|
||||||
|
|
||||||
if (Features.pointerLock)
|
if (Features.pointerLock)
|
||||||
{
|
{
|
||||||
this.pointerLockChange = this.pointerLockChange.bind(this);
|
this.pointerLockChange = this.pointerLockChange.bind(this);
|
||||||
|
|
||||||
document.addEventListener('pointerlockchange', this.pointerLockChange, true);
|
document.addEventListener('pointerlockchange', this.pointerLockChange, true);
|
||||||
document.addEventListener('mozpointerlockchange', this.pointerLockChange, true);
|
document.addEventListener('mozpointerlockchange', this.pointerLockChange, true);
|
||||||
document.addEventListener('webkitpointerlockchange', this.pointerLockChange, true);
|
document.addEventListener('webkitpointerlockchange', this.pointerLockChange, true);
|
||||||
|
@ -148,9 +171,11 @@ var MouseManager = new Class({
|
||||||
|
|
||||||
stopListeners: function ()
|
stopListeners: function ()
|
||||||
{
|
{
|
||||||
this.target.removeEventListener('mousemove', this.handler);
|
var target = this.target;
|
||||||
this.target.removeEventListener('mousedown', this.handler);
|
|
||||||
this.target.removeEventListener('mouseup', this.handler);
|
target.removeEventListener('mousemove', this.handler);
|
||||||
|
target.removeEventListener('mousedown', this.handler);
|
||||||
|
target.removeEventListener('mouseup', this.handler);
|
||||||
|
|
||||||
if (Features.pointerLock)
|
if (Features.pointerLock)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,7 @@ var TouchManager = new Class({
|
||||||
this.manager = inputManager;
|
this.manager = inputManager;
|
||||||
|
|
||||||
// @property {boolean} capture - If true the DOM events will have event.preventDefault applied to them, if false they will propagate fully.
|
// @property {boolean} capture - If true the DOM events will have event.preventDefault applied to them, if false they will propagate fully.
|
||||||
this.capture = false;
|
this.capture = true;
|
||||||
|
|
||||||
this.enabled = false;
|
this.enabled = false;
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ var TouchManager = new Class({
|
||||||
|
|
||||||
this.enabled = config.inputTouch;
|
this.enabled = config.inputTouch;
|
||||||
this.target = config.inputTouchEventTarget;
|
this.target = config.inputTouchEventTarget;
|
||||||
|
this.capture = config.inputTouchCapture;
|
||||||
|
|
||||||
if (!this.target)
|
if (!this.target)
|
||||||
{
|
{
|
||||||
|
@ -43,10 +44,16 @@ var TouchManager = new Class({
|
||||||
startListeners: function ()
|
startListeners: function ()
|
||||||
{
|
{
|
||||||
var queue = this.manager.queue;
|
var queue = this.manager.queue;
|
||||||
|
var target = this.target;
|
||||||
|
|
||||||
var _this = this;
|
var passive = { passive: true };
|
||||||
|
var nonPassive = { passive: false };
|
||||||
|
|
||||||
var handler = function (event)
|
var handler;
|
||||||
|
|
||||||
|
if (this.capture)
|
||||||
|
{
|
||||||
|
handler = function (event)
|
||||||
{
|
{
|
||||||
if (event.preventDefaulted)
|
if (event.preventDefaulted)
|
||||||
{
|
{
|
||||||
|
@ -54,28 +61,43 @@ var TouchManager = new Class({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log(event);
|
|
||||||
|
|
||||||
queue.push(event);
|
queue.push(event);
|
||||||
|
|
||||||
if (_this.capture)
|
|
||||||
{
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.handler = handler;
|
target.addEventListener('touchstart', handler, nonPassive);
|
||||||
|
target.addEventListener('touchmove', handler, nonPassive);
|
||||||
|
target.addEventListener('touchend', handler, nonPassive);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
handler = function (event)
|
||||||
|
{
|
||||||
|
if (event.preventDefaulted)
|
||||||
|
{
|
||||||
|
// Do nothing if event already handled
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.target.addEventListener('touchstart', handler, false);
|
queue.push(event);
|
||||||
this.target.addEventListener('touchmove', handler, false);
|
};
|
||||||
this.target.addEventListener('touchend', handler, false);
|
|
||||||
|
target.addEventListener('touchstart', handler, passive);
|
||||||
|
target.addEventListener('touchmove', handler, passive);
|
||||||
|
target.addEventListener('touchend', handler, passive);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.handler = handler;
|
||||||
},
|
},
|
||||||
|
|
||||||
stopListeners: function ()
|
stopListeners: function ()
|
||||||
{
|
{
|
||||||
this.target.removeEventListener('touchstart', this.handler);
|
var target = this.target;
|
||||||
this.target.removeEventListener('touchmove', this.handler);
|
|
||||||
this.target.removeEventListener('touchend', this.handler);
|
target.removeEventListener('touchstart', this.handler);
|
||||||
|
target.removeEventListener('touchmove', this.handler);
|
||||||
|
target.removeEventListener('touchend', this.handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue