diff options
author | jalf <jalf@medical-insight.com> | 2013-01-30 11:48:33 +0100 |
---|---|---|
committer | jalf <jalf@medical-insight.com> | 2013-01-30 13:17:50 +0100 |
commit | b1b342a97e6ea31a6080e2bf5cdf94988563b03a (patch) | |
tree | 1334805aeff4a552cc1065599ea59c67a493dc68 | |
parent | 0d0f754aade74dbd74a1a9766b66f3d00c754b3c (diff) | |
download | novnc-b1b342a97e6ea31a6080e2bf5cdf94988563b03a.tar.gz |
Capture mouse events and filter irrelevant ones
-rw-r--r-- | include/input.js | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/include/input.js b/include/input.js index fa753d9..b996c7d 100644 --- a/include/input.js +++ b/include/input.js @@ -486,7 +486,8 @@ function Mouse(defaults) { "use strict"; var that = {}, // Public API methods - conf = {}; // Configuration attributes + conf = {}, // Configuration attributes + mouseCaptured = false; // Configuration attributes Util.conf_defaults(conf, that, defaults, [ @@ -499,7 +500,23 @@ Util.conf_defaults(conf, that, defaults, [ ['touchButton', 'rw', 'int', 1, 'Button mask (1, 2, 4) for touch devices (0 means ignore clicks)'] ]); +function captureMouse() { + // capturing the mouse ensures we get the mouseup event + if (conf.target.setCapture) { + conf.target.setCapture(); + } + + // some browsers give us mouseup events regardless, + // so if we never captured the mouse, we can disregard the event + mouseCaptured = true; +} +function releaseMouse() { + if (conf.target.releaseCapture) { + conf.target.releaseCapture(); + } + mouseCaptured = false; +} // // Private functions // @@ -536,11 +553,17 @@ function onMouseButton(e, down) { } function onMouseDown(e) { + captureMouse(); onMouseButton(e, 1); } function onMouseUp(e) { + if (!mouseCaptured) { + return; + } + onMouseButton(e, 0); + releaseMouse(); } function onMouseWheel(e) { |