how to get an element position and size in gecko?

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

how to get an element position and size in gecko?

wayne.tangwei
Where can I find more detailed information about gecko,including every
class ,function defined in gecko,even relationship between classes? I
found it's diffcult to get more detailed information for mozilla
software.Not like some java software,you can get api documents easily
by javadoc.I know lxr,but I am not familliar with it and can't use it
effectively.

I am planning to develop an application based on gecko,which need to
know that the size of every frame in HTML file,the position and the
size of every element in every frame.
I try some code like this,but it dos not work:


               presShell->GetPrimaryFrameFor(content, &frame);
                if (frame)
                {
                        nsRect rect=frame->GetRect();
                        printf("x=%f\ty=%f width=%f height=%f
\n",rect.x,rect.y,rect.width,rect.height);
                }

the rsult is x=0 y=0 width=0 height=0
What's wrong with these codes?Why all 0?

If I want to get the position and size of every element in frame,what
more need I do?
I am newbie to gecko even mozilla.Hope somebody point a direction to
me.Thanks in advance.

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

Re: how to get an element position and size in gecko?

Neil Deakin
[hidden email] wrote:

>
>                presShell->GetPrimaryFrameFor(content, &frame);
> if (frame)
> {
> nsRect rect=frame->GetRect();
>                         printf("x=%f\ty=%f width=%f height=%f
> \n",rect.x,rect.y,rect.width,rect.height);
> }
>
> the rsult is x=0 y=0 width=0 height=0
> What's wrong with these codes?Why all 0?
>

Unless you're writing code which changes Gecko layout code itself, you
shouldn't be using frames directly at all.

Can you please state what you're overall goal is? That is, what you plan
on doing with the position and size information once you have it.

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

Re: how to get an element position and size in gecko?

wayne.tangwei

Neil Deakin 写道:

> [hidden email] wrote:
> >
> >                presShell->GetPrimaryFrameFor(content, &frame);
> > if (frame)
> > {
> > nsRect rect=frame->GetRect();
> >                         printf("x=%f\ty=%f width=%f height=%f
> > \n",rect.x,rect.y,rect.width,rect.height);
> > }
> >
> > the rsult is x=0 y=0 width=0 height=0
> > What's wrong with these codes?Why all 0?
> >
>
> Unless you're writing code which changes Gecko layout code itself, you
> shouldn't be using frames directly at all.
>
> Can you please state what you're overall goal is? That is, what you plan
> on doing with the position and size information once you have it.
>
> / Neil

I need calculate a kind of relationship between elements ,which based
on their coordinate . So, I need to know their posiztion and size.But I
am lost in gecko source code and not know how to do this.
Can I  do this with gecko? And how?

Wayne

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

Re: how to get an element position and size in gecko?

Boris Zbarsky
[hidden email] wrote:
> So, I need to know their posiztion and size.

First, neither concept is well-defined for an "element".  In particular, an
"element" may appear at several different places on the page at once.

If you just want some random numbers that will sometimes work, and only care
about HTML, you can use offsetWidth/Height and offsetLeft/Top together with
offsetParent to compute "sizes" and "positions".  See the MSDN documentation for
these properties.

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