On Apr 6, 9:05 am, Boris Zbarsky <[EMAIL PROTECTED]> wrote:
> krithika wrote:
> > Is there any document or diagram clearly explaining the relationship.
>
> http://www.mozilla.org/newlayout/doc/gecko-overview.htmis decent.
>
> > This is my understanding.DOM Node has one to one relationship with
> > content.
>
> Yes.
>
> > Where as a content has one to may relationship with frames.
>
> More or less, yes.
>
> > I actually need the last frame (after which page breaks) of a each
> > page and then get that frames content.
>
> Then you want to do basically
> whathttp://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/layout/base/nsLay...
> does, right?
>
> Note that the content for a frame may be anonymous content, not content in the
> original DOM...
>
> -Boris
Hi,
With the little understanding of things I tried this. I have problems
in blockFrame iteration as the page break comment node gets inserted
in wrong places for few block frames.Can you help me with blockFrame
iteration?.
The code for reference.
// Code to identify page break position and insert a comment node for
it.
nsresult result;
int pno=1;
nsIFrame* pageFirstElem,pageContentFrame,nsIFrame* pageElem;
nsIFrame* pageLastSibling;
nsIContent* cont;
nsresult res;
nsIAtom* atom;
nsAutoString str,comment,value,aString;
str.Assign(NS_LITERAL_STRING(" PAGE BREAK "));
comment.Assign(NS_LITERAL_STRING("<!-- PAGE BREAK -->"));
nsCOMPtr<nsIContent> text;
NS_NewCommentNode(getter_AddRefs(text),nsnull);
nsCOMPtr<nsIDOMNode> commentNode = do_QueryInterface(text);
commentNode->SetNodeValue(str);
//loop each page
for (nsIFrame* pageFrame = seqFrame->GetFirstChild(nsnull);
pageFrame; pageFrame = pageFrame->GetNextSibling())
{
pageContentFrame = pageFrame->GetFirstChild(nsnull);
pageElem = pageContentFrame->GetFirstChild(nsnull);
while (pageElem)
{
// just go to the frame after area and block frame in a page
if(pageElem)
{
cont = pageElem->GetContent();
cont->Tag()->ToString(str);
if(str.Equals(NS_LITERAL_STRING("body")) )
{
pageElem=pageElem->GetFirstChild(nsnull);
pageFirstElem=pageElem;
break;
}
}
pageElem=pageElem->GetFirstChild(nsnull);
}
nsIFrame* next;
next=nsLayoutUtils::GetLastSibling(pageFirstElem);
pageLastSibling=next;
cont=pageLastSibling->GetContent();
if(cont)
{
if(pageLastSibling->GetType() ==
nsLayoutAtoms::blockFrame)
{
nsIFrame* childFrame= pageLastSibling-
>GetFirstChild(nsnull);
if(childFrame)
{
cont=childFrame->GetContent();
nsFrameList frameList(childFrame);
PRInt32 flen =
frameList.GetLength();
if(flen > 0)
{
nsIFrame* lastFrame =
frameList.LastChild();
if(lastFrame)
{
atom = lastFrame-
>GetType();
res=atom-
>ToString(aString);
if
( NS_SUCCEEDED(res) )
{
printf("Block
Frame last Child Type: %s\n", NS_ConvertUCS2toUTF8(aString).get());
}
cont=lastFrame-
>GetContent();
}
}
}
PRInt32 childCount = cont->GetChildCount();
printf("child count is %d\n",childCount);
while(childCount > 0)
{
cont=cont->GetChildAt(childCount-1);
childCount=cont->GetChildCount();
}
if(cont)
{
printf("child child count %d\n",cont-
>GetChildCount());
nsCOMPtr<nsIDOMNode> node =
do_QueryInterface(cont);
//cont->AppendChildTo(text,PR_FALSE);
node->GetNodeValue(value);
value.Append(comment);
printf("BLOCK : INSERT PAGE BREAK NODE
HERE\n");
node->SetNodeValue(value);
node->GetNodeValue(value);
printf("Node value [%s]\n",
NS_LossyConvertUCS2toASCII(value).get());
}
else printf("content is null\n");
}
else if(pageLastSibling->GetType() ==
nsLayoutAtoms::imageFrame)
{
printf("IMG : INSERT PAGE BREAK NODE HERE\n");
cont->AppendChildTo(text,PR_FALSE);
}
else if(pageLastSibling->GetType() ==
nsLayoutAtoms::brFrame)
{
printf("BR : INSERT PAGE BREAK NODE HERE\n");
cont->AppendChildTo(text,PR_FALSE);
}
else if(pageLastSibling->GetType() ==
nsLayoutAtoms::textFrame)
{
printf("TEXT : INSERT PAGE BREAK NODE HERE
\n");
PRInt32 childCount = cont->GetChildCount();
printf("text frame content child count %d
\n",childCount);
nsCOMPtr<nsIDOMNode> node =
do_QueryInterface(cont);
node->GetNodeValue(value);
value.Append(comment);
node->SetNodeValue(value);
/*nsCOMPtr<nsIDOMDocument> doc;
node->GetOwnerDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMDocumentRange>
docRange(do_QueryInterface(doc));
if (docRange)
{
nsCOMPtr<nsIDOMRange> range;
docRange-
>CreateRange(getter_AddRefs(range));
if (range)
{
range->SelectNode(node);
nsCOMPtr<nsIDOMText> newtext;
doc-
>CreateTextNode(comment,getter_AddRefs(newtext));
res=range->InsertNode(newtext);
if(NS_SUCCEEDED(res))
{
printf("range node inserted
sucessfully ...........\n");
}
else printf("range insert node
failed\n");
}
}*/
node->GetNodeValue(value);
printf("Text Node value [%s]\n",
NS_LossyConvertUCS2toASCII(value).get());
}
}// for loop ends
Thanks in Advance,
Krithika
_______________________________________________
dev-tech-layout mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-layout