[Spice-devel] [spice-html5][PATCH 12/12] More reliable mouse position reporting
Cédric Bosdonnat
cbosdonnat at suse.com
Mon Feb 11 17:48:05 UTC 2019
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.
---
src/spicemsg.js | 18 ++++++++----------
1 file 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
{
--
2.19.2
More information about the Spice-devel
mailing list