Commit b1b342a9 authored by jalf's avatar jalf

Capture mouse events and filter irrelevant ones

parent 0d0f754a
...@@ -486,7 +486,8 @@ function Mouse(defaults) { ...@@ -486,7 +486,8 @@ function Mouse(defaults) {
"use strict"; "use strict";
var that = {}, // Public API methods var that = {}, // Public API methods
conf = {}; // Configuration attributes conf = {}, // Configuration attributes
mouseCaptured = false;
// Configuration attributes // Configuration attributes
Util.conf_defaults(conf, that, defaults, [ Util.conf_defaults(conf, that, defaults, [
...@@ -499,7 +500,23 @@ 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)'] ['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 // Private functions
// //
...@@ -536,11 +553,17 @@ function onMouseButton(e, down) { ...@@ -536,11 +553,17 @@ function onMouseButton(e, down) {
} }
function onMouseDown(e) { function onMouseDown(e) {
captureMouse();
onMouseButton(e, 1); onMouseButton(e, 1);
} }
function onMouseUp(e) { function onMouseUp(e) {
if (!mouseCaptured) {
return;
}
onMouseButton(e, 0); onMouseButton(e, 0);
releaseMouse();
} }
function onMouseWheel(e) { function onMouseWheel(e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment