[webkit-dev] the absolute coordinates in the webkit

Simon Fraser simon.fraser at apple.com
Thu Jan 8 08:37:02 PST 2009


On Jan 8, 2009, at 2:17 AM, Ariya Hidayat wrote:

>
>> Now I want to obtain  the absolute coordinates of  <img> in the  
>> webkit,
>>
>> Through code how to achieve
>
> Hint: have a look at RenderImage::paintReplaced() function. If you  
> get the
> render object for that <img>, which is a RenderImage instance, then  
> you are
> set.

HTMLImageElement already has x() and y() methods that return the  
absolute coordinates of the image. However, these methods don't take  
CSS transforms into account.

Node::getRect() will also give you back an absolute rect for a node,  
but again it's broken with transforms.

If you're in renderer code, the correct solution is to call  
localToAbsolute() on the image's renderer, passing 'true' for the  
useTransforms parameter.

In general, you should be wary of using absolute coordinates unless  
you absolutely have to. I've been fixing many bugs caused by the use  
of absolute coordinates for event handling and repainting that show up  
when CSS transforms are being used. The general rule should be that  
your coordinate math should be as "local" as possible.

Simon



More information about the webkit-dev mailing list