[webkit-dev] Mouse event position related to actual element content
Sergiy Byelozyorov
byelozyorov at cs.uni-saarland.de
Sat Jul 9 09:23:27 PDT 2011
Hello,
After some experimenting I have figured out that computing mouse position
relative to the actual content (also ignoring all borders, margins and
padding) can be done as following:
int innerX = xPos - tx - x();
int innerY = yPos - ty - y();
It has worked for me for a long time already. Please let me know if I am
wrong and not taking some special cases into account.
Sergiy Byelozyorov
Computer Graphics Chair
Universitat des Saarlandes
Tel.: +49 (681) 302-3837
Web: http://graphics.cs.uni-saarland.de/sbyelozyorov/
On Thu, Mar 3, 2011 at 13:50, Sergiy Byelozyorov <
byelozyorov at cs.uni-saarland.de> wrote:
> Hello,
>
> I develop an extension to WebKit which adds support for XML3D<http://www.xml3d.org>.
> For mouse events on XML3D element I have created custom event type
> XML3DMouseEvent that inherits from MouseEvent. In addition to normal
> coordinates it also has 3D position and normal of the element under the
> cursor. In order to avoid massive changes into WebKit I have decided to
> convert existing event from MouseEvent into XML3DMouseEvent when going
> though overloaded XML3DElement::dispatchEvent which allows me to create
> custom event class only for XML3D elements.
>
> There I also need to perform picking again to actually receive normal and
> position. However at this stage I don't have actual coordinates where mouse
> was relative to the actual rendered image (line x, y, tx and ty in
> RenderObject::nodeAtPoint). All I get is MouseEvent with all it's parameters
> and the element itself.
>
> Originally I tried using pageX and pageY and deducted offsetTop and
> offsetLeft from them, but this does not take borders and padding into
> account. I have tried accessing computedStyle to get border and padding
> width, but the value in there has type Length and I am not sure how to
> convert it to actual pixels.
>
> Please let me know how can mouse event position relative to element content
> (not to border or padding). If there is a nicer and more straitforward way
> to implement XML3DMouseEvent I would be happy to hear them.
>
> Sergiy Byelozyorov
> Computer Graphics Chair
> Universitat des Saarlandes
> Tel.: +49 (681) 302-3837
> Web: http://graphics.cs.uni-saarland.de/sbyelozyorov/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20110709/b3230343/attachment.html>
More information about the webkit-dev
mailing list