diff options
author | Pierre Ossman <ossman@cendio.se> | 2016-10-05 10:21:17 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2017-10-18 15:07:17 +0200 |
commit | 2afda54456fc45b1d343cc4b7e8edada9b71b088 (patch) | |
tree | 96428fa3e0e27754410377629b732f8ea088a292 /core/input | |
parent | 69411b9ea3df595c08f6fbd8466b2c645028ab81 (diff) | |
download | novnc-2afda54456fc45b1d343cc4b7e8edada9b71b088.tar.gz |
Only grab key events on canvas
Give the canvas proper focus handling. This avoids messy logic that
needs to disable and enable event handling when we want to interact
with other UI elements.
It also makes sure we can properly inhibit the browser from triggering
local actions on key presses.
Diffstat (limited to 'core/input')
-rw-r--r-- | core/input/keyboard.js | 12 | ||||
-rw-r--r-- | core/input/mouse.js | 10 |
2 files changed, 2 insertions, 20 deletions
diff --git a/core/input/keyboard.js b/core/input/keyboard.js index 7aa6288..fa4a5ae 100644 --- a/core/input/keyboard.js +++ b/core/input/keyboard.js @@ -24,8 +24,7 @@ export default function Keyboard(defaults) { this._pendingKey = null; // Key waiting for keypress set_defaults(this, defaults, { - 'target': document, - 'focused': true + 'target': null, }); // keep these here so we can refer to them later @@ -131,8 +130,6 @@ Keyboard.prototype = { }, _handleKeyDown: function (e) { - if (!this._focused) { return; } - var code = this._getKeyCode(e); var keysym = KeyboardUtil.getKeysym(e); @@ -214,8 +211,6 @@ Keyboard.prototype = { // Legacy event for browsers without code/key _handleKeyPress: function (e) { - if (!this._focused) { return; } - stopEvent(e); // Are we expecting a keypress? @@ -244,8 +239,6 @@ Keyboard.prototype = { this._sendKeyEvent(keysym, code, true); }, _handleKeyPressTimeout: function (e) { - if (!this._focused) { return; } - // Did someone manage to sort out the key already? if (this._pendingKey === null) { return; @@ -282,8 +275,6 @@ Keyboard.prototype = { }, _handleKeyUp: function (e) { - if (!this._focused) { return; } - stopEvent(e); var code = this._getKeyCode(e); @@ -348,7 +339,6 @@ Keyboard.prototype = { make_properties(Keyboard, [ ['target', 'wo', 'dom'], // DOM element that captures keyboard input - ['focused', 'rw', 'bool'], // Capture and send key events ['onKeyEvent', 'rw', 'func'] // Handler for key press/release ]); diff --git a/core/input/mouse.js b/core/input/mouse.js index 2e75807..49b5c39 100644 --- a/core/input/mouse.js +++ b/core/input/mouse.js @@ -31,7 +31,6 @@ export default function Mouse(defaults) { // Configuration attributes set_defaults(this, defaults, { 'target': document, - 'focused': true, 'touchButton': 1 }); @@ -52,8 +51,6 @@ Mouse.prototype = { }, _handleMouseButton: function (e, down) { - if (!this._focused) { return; } - this._updateMousePosition(e); var pos = this._pos; @@ -156,7 +153,7 @@ Mouse.prototype = { }, _handleMouseWheel: function (e) { - if (!this._focused || !this._onMouseButton) { return; } + if (!this._onMouseButton) { return; } this._resetWheelStepTimers(); @@ -201,8 +198,6 @@ Mouse.prototype = { }, _handleMouseMove: function (e) { - if (! this._focused) { return; } - this._updateMousePosition(e); if (this._onMouseMove) { this._onMouseMove(this._pos.x, this._pos.y); @@ -211,8 +206,6 @@ Mouse.prototype = { }, _handleMouseDisable: function (e) { - if (!this._focused) { return; } - /* * Stop propagation if inside canvas area * Note: This is only needed for the 'click' event as it fails @@ -292,7 +285,6 @@ Mouse.prototype = { make_properties(Mouse, [ ['target', 'ro', 'dom'], // DOM element that captures mouse input - ['focused', 'rw', 'bool'], // Capture and send mouse clicks/movement ['onMouseButton', 'rw', 'func'], // Handler for mouse button click/release ['onMouseMove', 'rw', 'func'], // Handler for mouse movement |