diff options
author | Cédric Bosdonnat <cbosdonnat@suse.com> | 2019-02-14 10:44:56 +0100 |
---|---|---|
committer | Jeremy White <jwhite@codeweavers.com> | 2019-02-15 10:06:21 -0600 |
commit | 54755c2565d41815806c18c325ca32dad3d5e69c (patch) | |
tree | a471ebbd28e81b28b3d3c10e1fe3cc76b434eaee | |
parent | d75dc564401a4166f7d2c58185f0f5a8549259a8 (diff) |
More reliable mouse position reportingspice-html5-0.2.1
Depending on the structure of the page, the computed mouse position was
not correct. Typically the case happend when there is no offset between
the canvas and the view area, but an offset on the view area.
The MouseEvent.offsetX and offsetY functions are now widely enough spread
to use them and avoid complex computations.
-rw-r--r-- | src/spicemsg.js | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/spicemsg.js b/src/spicemsg.js index f1b4c74..23ee9c7 100644 --- a/src/spicemsg.js +++ b/src/spicemsg.js @@ -952,13 +952,11 @@ function SpiceMsgcMousePosition(sc, e) this.buttons_state = sc.buttons_state; if (e) { - var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; - var scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft; + this.x = e.offsetX; + this.y = e.offsetY; - this.x = e.clientX - sc.display.surfaces[sc.display.primary_surface].canvas.offsetLeft + scrollLeft; - this.y = e.clientY - sc.display.surfaces[sc.display.primary_surface].canvas.offsetTop + scrollTop; - sc.mousex = this.x; - sc.mousey = this.y; + sc.mousex = e.offsetX; + sc.mousey = e.offsetY; } else { @@ -991,16 +989,16 @@ function SpiceMsgcMouseMotion(sc, e) this.buttons_state = sc.buttons_state; if (e) { - this.x = e.clientX - sc.display.surfaces[sc.display.primary_surface].canvas.offsetLeft; - this.y = e.clientY - sc.display.surfaces[sc.display.primary_surface].canvas.offsetTop; + this.x = e.offsetX; + this.y = e.offsetY; if (sc.mousex !== undefined) { this.x -= sc.mousex; this.y -= sc.mousey; } - sc.mousex = e.clientX - sc.display.surfaces[sc.display.primary_surface].canvas.offsetLeft; - sc.mousey = e.clientY - sc.display.surfaces[sc.display.primary_surface].canvas.offsetTop; + sc.mousex = e.offsetX; + sc.mousey = e.offsetY; } else { |