Get x and y page coordinates

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Get x and y page coordinates

Rajat Gogri
Hello,

I am trying to get x and y coordinates for the link using framepointer. I am
using following code.

 float p2t = tPresContext->PixelsToTwips();
 nsCOMPtr<nsIRenderingContext> rcontext;
  tPresShell->CreateRenderingContext(tFrame, getter_AddRefs(rcontext));

 nsRect rect = tFrame->GetRect();

This *rect.x* and *rext.y* gives the screen coordinates which are
approximately 5000, 2000 for some link but for my event I need page
coordinates which I get while debugging as 350,150

Could you please tell me how to convert these coordinates to page
coordinates. Is these coordinates calles view coordiates?????

Thanks in advance,

Regards,
Raj
_______________________________________________
dev-tech-layout mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-layout
Reply | Threaded
Open this post in threaded view
|

Re: Get x and y page coordinates

Eli Friedman
Rajat Gogri wrote:

> Hello,
>
> I am trying to get x and y coordinates for the link using framepointer.
> I am
> using following code.
>
> float p2t = tPresContext->PixelsToTwips();
> nsCOMPtr<nsIRenderingContext> rcontext;
>  tPresShell->CreateRenderingContext(tFrame, getter_AddRefs(rcontext));
>
> nsRect rect = tFrame->GetRect();
>
> This *rect.x* and *rext.y* gives the screen coordinates which are
> approximately 5000, 2000 for some link but for my event I need page
> coordinates which I get while debugging as 350,150

rect.x and rect.y are relative to the parent frame.  To get offsets from
the viewport, you can use something like
tframe->GetOffsetToExternal(tPresContext->GetPresShell()->GetRootFrame());
(untested, but should work.)  To get screen coordinates, you can use
tframe->GetScreenRectExternal().  Of course, the results are all in
twips; multiply by tPresContext->TwipsToPixels() to get pixels.

I'd like to stress, though, that it's not a good idea to be messing with
frames unless you really must; you'll have to recompile for every new
Gecko version, and the APIs change all the time (for example,
TwipsToPixels() doesn't exist on the trunk.)  For HTML content, the
offsetTop and offsetLeft properties would probably suffice in most cases.

-Eli
_______________________________________________
dev-tech-layout mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-layout