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 [email protected] https://lists.mozilla.org/listinfo/dev-tech-layout

