]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Clamp mouseclick coordinates to target element bounds
authorjalf <jalf@medical-insight.com>
Tue, 29 Jan 2013 16:06:03 +0000 (17:06 +0100)
committerjalf <jalf@medical-insight.com>
Wed, 30 Jan 2013 12:17:32 +0000 (13:17 +0100)
include/util.js

index 6f6c52a63f42abf2bc93937b2a7f6393c62bcbee..dd1f252fbdb5913c5d7c8366b57854d12430dcd7 100644 (file)
@@ -298,7 +298,9 @@ Util.getEventPosition = function (e, obj, scale) {
     if (typeof scale === "undefined") {
         scale = 1;
     }
-    return {'x': (docX - pos.x) / scale, 'y': (docY - pos.y) / scale};
+    var x = Math.max(Math.min(docX - pos.x, obj.width-1), 0);
+       var y = Math.max(Math.min(docY - pos.y, obj.height-1), 0);
+    return {'x': x / scale, 'y': y / scale};
 };