Re: ISSUE-136 (getCoordsAt): Consider adding MouseEvent.getCoordsAt(element)

Hi folks,

Per our resolution on our resolution on 2010-10-13, I have resolved this issue for D3E. Our recommendation is that this proposal be made to CSSOM-View since it is not necessarily specific to mouse events.

Thanks,

Jacob

[1] http://lists.w3.org/Archives/Public/www-dom/2010OctDec/0062.html


From: Jonathan Watt <jwatt@jwatt.org<mailto:jwatt@jwatt.org?Subject=Re%3A%20%5BDOM%20Level%203%20Events%5D%20MouseEvent.getCoordsAt(element)&In-Reply-To=%253C4CACF1F3.9090601%40jwatt.org%253E&References=%253C4CACF1F3.9090601%40jwatt.org%253E>>
Date: Wed, 06 Oct 2010 23:02:27 +0100
Message-ID: <4CACF1F3.9090601@jwatt.org>
To: Jonas Sicking <jonas@sicking.cc<mailto:jonas@sicking.cc?Subject=Re%3A%20%5BDOM%20Level%203%20Events%5D%20MouseEvent.getCoordsAt(element)&In-Reply-To=%253C4CACF1F3.9090601%40jwatt.org%253E&References=%253C4CACF1F3.9090601%40jwatt.org%253E>>
CC: www-dom@w3.org<mailto:www-dom@w3.org?Subject=Re%3A%20%5BDOM%20Level%203%20Events%5D%20MouseEvent.getCoordsAt(element)&In-Reply-To=%253C4CACF1F3.9090601%40jwatt.org%253E&References=%253C4CACF1F3.9090601%40jwatt.org%253E>

On 06/10/2010 05:29, Jonas Sicking wrote:

> This would this also take account for things like parent plain HTML

> elements being scrolled and things like that right?



Yes. It wouldn't be much use if it didn't.



> What happens if you pass in an element which the mouse isn't actually

> over? Would it be possible to transform the coordinates to that

> elements coordinate space anyway?



Yes. I don't see any reason why the pointer should be over the specified

element. The function just transforms the pointer's x/y by the transform from

the pointer event's coordinate system (the window coordinate system) to the

specified element's coordinate system. It's just a transform after all.



Jonathan

From: Jonas Sicking <jonas@sicking.cc<mailto:jonas@sicking.cc?Subject=Re%3A%20%5BDOM%20Level%203%20Events%5D%20MouseEvent.getCoordsAt(element)&In-Reply-To=%253CAANLkTinaoyv90tYuPovk8eZL76Nz1RzZUsQ1WSnJHgxg%40mail.gmail.com%253E&References=%253CAANLkTinaoyv90tYuPovk8eZL76Nz1RzZUsQ1WSnJHgxg%40mail.gmail.com%253E>>
Date: Tue, 5 Oct 2010 21:29:45 -0700
Message-ID: <AANLkTinaoyv90tYuPovk8eZL76Nz1RzZUsQ1WSnJHgxg@mail.gmail.com>
To: Jonathan Watt <jwatt@jwatt.org<mailto:jwatt@jwatt.org?Subject=Re%3A%20%5BDOM%20Level%203%20Events%5D%20MouseEvent.getCoordsAt(element)&In-Reply-To=%253CAANLkTinaoyv90tYuPovk8eZL76Nz1RzZUsQ1WSnJHgxg%40mail.gmail.com%253E&References=%253CAANLkTinaoyv90tYuPovk8eZL76Nz1RzZUsQ1WSnJHgxg%40mail.gmail.com%253E>>
Cc: www-dom@w3.org<mailto:www-dom@w3.org?Subject=Re%3A%20%5BDOM%20Level%203%20Events%5D%20MouseEvent.getCoordsAt(element)&In-Reply-To=%253CAANLkTinaoyv90tYuPovk8eZL76Nz1RzZUsQ1WSnJHgxg%40mail.gmail.com%253E&References=%253CAANLkTinaoyv90tYuPovk8eZL76Nz1RzZUsQ1WSnJHgxg%40mail.gmail.com%253E>

On Tue, Oct 5, 2010 at 3:06 AM, Jonathan Watt <jwatt@jwatt.org<mailto:jwatt@jwatt.org?Subject=Re%3A%20%5BDOM%20Level%203%20Events%5D%20MouseEvent.getCoordsAt(element)&In-Reply-To=%253CAANLkTinaoyv90tYuPovk8eZL76Nz1RzZUsQ1WSnJHgxg%40mail.gmail.com%253E&References=%253CAANLkTinaoyv90tYuPovk8eZL76Nz1RzZUsQ1WSnJHgxg%40mail.gmail.com%253E>> wrote:

> Hi WG,

>

> Background:

>

> Positioning elements based off the position of a pointer event is regularly

> tripping people up in SVG, and with the advent of CSS-transforms, I imagine also

> in HTML.

>

> To position an element based off the position of a pointer event you need to get

> the coordinates of the event in the local coordinate system of the element. To

> do that currently authors have to get the *correct* element-to-root transform,

> invert it, create an SVGPoint, copy the event coordinates to the SVGPoint, then

> use the inverted transform to transform the point and read back the coordinates.

> For something so simple, it's not obvious that this is what you need to do, or

> even how to do it.

>

> Proposal:

>

> To make life easier for authors I'd like to propose the addition of a

> 'getCoordsAt' method to the MouseEvent interface. This method would be passed

> the element at which the local coordinates of the event are required, and return

> an object implementing the SVGPoint interface[1] (or a new interface

> implementing 'x' and 'y' properties).

>

> I've uploaded a JavaScript implemented demo of this method here:

>

>  http://jwatt.org/svg/tmp/mouse-relative-positioning.svg

>

> See also the comments in the source code.

>

> Regards,

> Jonathan

>

> [1] http://www.w3.org/TR/SVG11/coords.html#InterfaceSVGPoint



This would this also take account for things like parent plain HTML

elements being scrolled and things like that right?



What happens if you pass in an element which the mouse isn't actually

over? Would it be possible to transform the coordinates to that

elements coordinate space anyway? Or would it simply return a

null-like value? I would hope for the former.



/ Jonas

From: Jonathan Watt <jwatt@jwatt.org<mailto:jwatt@jwatt.org?Subject=Re%3A%20%5BDOM%20Level%203%20Events%5D%20MouseEvent.getCoordsAt(element)&In-Reply-To=%253C4CAAF88C.6000307%40jwatt.org%253E&References=%253C4CAAF88C.6000307%40jwatt.org%253E>>
Date: Tue, 05 Oct 2010 11:06:04 +0100
Message-ID: <4CAAF88C.6000307@jwatt.org>
To: www-dom@w3.org<mailto:www-dom@w3.org?Subject=Re%3A%20%5BDOM%20Level%203%20Events%5D%20MouseEvent.getCoordsAt(element)&In-Reply-To=%253C4CAAF88C.6000307%40jwatt.org%253E&References=%253C4CAAF88C.6000307%40jwatt.org%253E>

Hi WG,



Background:



Positioning elements based off the position of a pointer event is regularly

tripping people up in SVG, and with the advent of CSS-transforms, I imagine also

in HTML.



To position an element based off the position of a pointer event you need to get

the coordinates of the event in the local coordinate system of the element. To

do that currently authors have to get the *correct* element-to-root transform,

invert it, create an SVGPoint, copy the event coordinates to the SVGPoint, then

use the inverted transform to transform the point and read back the coordinates.

For something so simple, it's not obvious that this is what you need to do, or

even how to do it.



Proposal:



To make life easier for authors I'd like to propose the addition of a

'getCoordsAt' method to the MouseEvent interface. This method would be passed

the element at which the local coordinates of the event are required, and return

an object implementing the SVGPoint interface[1] (or a new interface

implementing 'x' and 'y' properties).



I've uploaded a JavaScript implemented demo of this method here:



  http://jwatt.org/svg/tmp/mouse-relative-positioning.svg



See also the comments in the source code.



Regards,

Jonathan



[1] http://www.w3.org/TR/SVG11/coords.html#InterfaceSVGPoint

Received on Friday, 8 April 2011 23:39:38 UTC