From 232d08fd543fdfee679828e6886a536ed0a2545d Mon Sep 17 00:00:00 2001 From: "waterson%netscape.com" Date: Fri, 3 Aug 2001 07:34:28 +0000 Subject: [PATCH] Bug 92190. Add anonymous children to nsIContent::List() output, add gdb-callable routines for listing frame and content trees. r=hyatt, sr=jst --- content/base/src/nsGenericElement.cpp | 72 ++++++++++ content/xbl/public/nsIBindingManager.h | 1 + content/xbl/src/nsBindingManager.cpp | 16 +++ content/xul/content/src/nsXULElement.cpp | 156 ++++++++++++++-------- layout/generic/nsContainerFrame.cpp | 3 +- layout/generic/nsFrame.cpp | 29 ++++ layout/html/base/src/nsContainerFrame.cpp | 3 +- layout/html/base/src/nsFrame.cpp | 29 ++++ 8 files changed, 249 insertions(+), 60 deletions(-) diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 48264084f3f..83b7c56bc25 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -83,6 +83,20 @@ // baseURI #include "nsIXMLDocument.h" +#ifdef DEBUG_waterson + +/** + * List a content tree to stdout. Meant to be called from gdb. + */ +void +DebugListContentTree(nsIContent* aElement) +{ + aElement->List(stdout, 0); + printf("\n"); +} + +#endif + //---------------------------------------------------------------------- nsChildContentList::nsChildContentList(nsIContent *aContent) @@ -3284,6 +3298,64 @@ nsGenericContainerElement::List(FILE* out, PRInt32 aIndent) const } fputs(">\n", out); + if (mDocument) { + nsCOMPtr bindingManager; + mDocument->GetBindingManager(getter_AddRefs(bindingManager)); + if (bindingManager) { + nsCOMPtr anonymousChildren; + bindingManager->GetAnonymousNodesFor(NS_STATIC_CAST(nsIContent*, NS_CONST_CAST(nsGenericContainerElement*, this)), + getter_AddRefs(anonymousChildren)); + + if (anonymousChildren) { + PRUint32 length; + anonymousChildren->GetLength(&length); + if (length) { + for (index = aIndent; --index >= 0; ) fputs(" ", out); + fputs("anonymous-children<\n", out); + + for (PRUint32 i = 0; i < length; ++i) { + nsCOMPtr node; + anonymousChildren->Item(i, getter_AddRefs(node)); + nsCOMPtr child = do_QueryInterface(node); + child->List(out, aIndent + 1); + } + + for (index = aIndent; --index >= 0; ) fputs(" ", out); + fputs(">\n", out); + } + } + + PRBool hasContentList; + bindingManager->HasContentListFor(NS_STATIC_CAST(nsIContent*, NS_CONST_CAST(nsGenericContainerElement*, this)), + &hasContentList); + + if (hasContentList) { + nsCOMPtr contentList; + bindingManager->GetContentListFor(NS_STATIC_CAST(nsIContent*, NS_CONST_CAST(nsGenericContainerElement*, this)), + getter_AddRefs(contentList)); + + NS_ASSERTION(contentList != nsnull, "oops, binding manager lied"); + + PRUint32 length; + contentList->GetLength(&length); + if (length) { + for (index = aIndent; --index >= 0; ) fputs(" ", out); + fputs("content-list<\n", out); + + for (PRUint32 i = 0; i < length; ++i) { + nsCOMPtr node; + contentList->Item(i, getter_AddRefs(node)); + nsCOMPtr child = do_QueryInterface(node); + child->List(out, aIndent + 1); + } + + for (index = aIndent; --index >= 0; ) fputs(" ", out); + fputs(">\n", out); + } + } + } + } + return NS_OK; } diff --git a/content/xbl/public/nsIBindingManager.h b/content/xbl/public/nsIBindingManager.h index 2ab9f3724fa..2a53f175dc5 100644 --- a/content/xbl/public/nsIBindingManager.h +++ b/content/xbl/public/nsIBindingManager.h @@ -86,6 +86,7 @@ public: // For a given element with an insertion point child, returns a flat list of all the real children. NS_IMETHOD GetContentListFor(nsIContent* aContent, nsIDOMNodeList** aResult) = 0; NS_IMETHOD SetContentListFor(nsIContent* aContent, nsISupportsArray* aList)=0; + NS_IMETHOD HasContentListFor(nsIContent* aContent, PRBool* aResult) = 0; NS_IMETHOD GetAnonymousNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult) = 0; NS_IMETHOD SetAnonymousNodesFor(nsIContent* aContent, nsISupportsArray* aList) = 0; diff --git a/content/xbl/src/nsBindingManager.cpp b/content/xbl/src/nsBindingManager.cpp index 312db198bb7..010d4a6033f 100644 --- a/content/xbl/src/nsBindingManager.cpp +++ b/content/xbl/src/nsBindingManager.cpp @@ -309,6 +309,7 @@ public: NS_IMETHOD GetContentListFor(nsIContent* aContent, nsIDOMNodeList** aResult); NS_IMETHOD SetContentListFor(nsIContent* aContent, nsISupportsArray* aList); + NS_IMETHOD HasContentListFor(nsIContent* aContent, PRBool* aResult); NS_IMETHOD GetAnonymousNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult); NS_IMETHOD SetAnonymousNodesFor(nsIContent* aContent, nsISupportsArray* aList); @@ -717,6 +718,21 @@ nsBindingManager::SetContentListFor(nsIContent* aContent, nsISupportsArray* aLis return NS_OK; } +NS_IMETHODIMP +nsBindingManager::HasContentListFor(nsIContent* aContent, PRBool* aResult) +{ + *aResult = PR_FALSE; + if (mContentListTable) { + nsISupportsKey key(aContent); + nsCOMPtr list = + NS_STATIC_CAST(nsIDOMNodeList*, mContentListTable->Get(&key)); + + *aResult = (list != nsnull); + } + + return NS_OK; +} + NS_IMETHODIMP nsBindingManager::GetAnonymousNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult) { diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 5d9418cd021..796debd4613 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -17,10 +17,8 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Original Author(s): + * Contributor(s): * Chris Waterson - * - * Contributor(s): * Pierre Phaneuf * Peter Annema * Brendan Eich @@ -3401,79 +3399,121 @@ nsXULElement::List(FILE* out, PRInt32 aIndent) const { NS_PRECONDITION(mDocument != nsnull, "bad content"); - nsresult rv; - { - rdf_Indent(out, aIndent); - fputs("GetQualifiedName(as); + fputs(NS_ConvertUCS2toUTF8(as).get(), out); + + fprintf(out, "@%p", this); + + PRInt32 nattrs; + GetAttributeCount(nattrs); + + for (i = 0; i < nattrs; ++i) { + nsCOMPtr attr; + nsCOMPtr prefix; + PRInt32 nameSpaceID; + GetAttributeNameAt(i, nameSpaceID, *getter_AddRefs(attr), *getter_AddRefs(prefix)); + + nsAutoString v; + GetAttribute(nameSpaceID, attr, v); + fputs(" ", out); - PRInt32 namespaceID; - NodeInfo()->GetNamespaceID(namespaceID); + nsAutoString s; - if (namespaceID == kNameSpaceID_Unknown) { - fputs("unknown:", out); + if (prefix) { + prefix->ToString(s); + + fputs(NS_ConvertUCS2toUTF8(s).get(), out); + fputs(":", out); } - nsAutoString as; - NodeInfo()->GetQualifiedName(as); - fputs(as, out); + attr->ToString(s); + + fputs(NS_ConvertUCS2toUTF8(s).get(), out); + fputs("=", out); + fputs(NS_ConvertUCS2toUTF8(v).get(), out); } - { - PRInt32 nattrs; + PRInt32 nchildren; + ChildCount(nchildren); - if (NS_SUCCEEDED(rv = GetAttributeCount(nattrs))) { - for (PRInt32 i = 0; i < nattrs; ++i) { - nsIAtom* attr = nsnull; - nsCOMPtr prefix; - PRInt32 nameSpaceID; - GetAttributeNameAt(i, nameSpaceID, attr, *getter_AddRefs(prefix)); + if (nchildren) { + fputs("\n", out); - nsAutoString v; - GetAttribute(nameSpaceID, attr, v); + for (i = 0; i < nchildren; ++i) { + nsCOMPtr child; + ChildAt(i, *getter_AddRefs(child)); - fputs(" ", out); - - nsAutoString s; - - if (prefix) { - prefix->ToString(s); - - fputs(s, out); - fputs(":", out); - } - - attr->ToString(s); - NS_RELEASE(attr); - - fputs(s, out); - fputs("=", out); - fputs(v, out); - } + child->List(out, aIndent + 1); } - if (NS_FAILED(rv)) - return rv; + rdf_Indent(out, aIndent); } - fputs(">\n", out); - { - PRInt32 nchildren; - if (NS_FAILED(rv = ChildCount(nchildren))) - return rv; + if (mDocument) { + nsCOMPtr bindingManager; + mDocument->GetBindingManager(getter_AddRefs(bindingManager)); + if (bindingManager) { + nsCOMPtr anonymousChildren; + bindingManager->GetAnonymousNodesFor(NS_STATIC_CAST(nsIContent*, NS_CONST_CAST(nsXULElement*, this)), + getter_AddRefs(anonymousChildren)); - for (PRInt32 i = 0; i < nchildren; ++i) { - nsIContent* child; - if (NS_FAILED(rv = ChildAt(i, child))) - return rv; + if (anonymousChildren) { + PRUint32 length; + anonymousChildren->GetLength(&length); + if (length) { + rdf_Indent(out, aIndent); + fputs("anonymous-children<\n", out); - rv = child->List(out, aIndent + 1); - NS_RELEASE(child); + for (PRUint32 i2 = 0; i2 < length; ++i2) { + nsCOMPtr node; + anonymousChildren->Item(i2, getter_AddRefs(node)); + nsCOMPtr child = do_QueryInterface(node); + child->List(out, aIndent + 1); + } - if (NS_FAILED(rv)) - return rv; + rdf_Indent(out, aIndent); + fputs(">\n", out); + } + } + + PRBool hasContentList; + bindingManager->HasContentListFor(NS_STATIC_CAST(nsIContent*, NS_CONST_CAST(nsXULElement*, this)), + &hasContentList); + + if (hasContentList) { + nsCOMPtr contentList; + bindingManager->GetContentListFor(NS_STATIC_CAST(nsIContent*, NS_CONST_CAST(nsXULElement*, this)), + getter_AddRefs(contentList)); + + NS_ASSERTION(contentList != nsnull, "oops, binding manager lied"); + + PRUint32 length; + contentList->GetLength(&length); + if (length) { + rdf_Indent(out, aIndent); + fputs("content-list<\n", out); + + for (PRUint32 i2 = 0; i2 < length; ++i2) { + nsCOMPtr node; + contentList->Item(i2, getter_AddRefs(node)); + nsCOMPtr child = do_QueryInterface(node); + child->List(out, aIndent + 1); + } + + rdf_Indent(out, aIndent); + fputs(">\n", out); + } + } } } diff --git a/layout/generic/nsContainerFrame.cpp b/layout/generic/nsContainerFrame.cpp index dced2f052a7..b220e2b28e4 100644 --- a/layout/generic/nsContainerFrame.cpp +++ b/layout/generic/nsContainerFrame.cpp @@ -1111,7 +1111,8 @@ nsContainerFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) if (0 != mState) { fprintf(out, " [state=%08x]", mState); } - fprintf(out, " sc=%p", mStyleContext); + fprintf(out, " [content=%p]", mContent); + fprintf(out, " [sc=%p]", mStyleContext); // Output the children nsIAtom* listName = nsnull; diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index d73a4ccb28a..4e4b79cd9f0 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -2319,6 +2319,34 @@ PRInt32 nsFrame::ContentIndexInContainer(const nsIFrame* aFrame) } #ifdef NS_DEBUG + +#ifdef DEBUG_waterson + +/** + * List a single frame to stdout. Meant to be called from gdb. + */ +void +DebugListFrame(nsIPresContext* aPresContext, nsIFrame* aFrame) +{ + ((nsFrame*) aFrame)->List(aPresContext, stdout, 0); + printf("\n"); +} + +/** + * List a frame tree to stdout. Meant to be called from gdb. + */ +void +DebugListFrameTree(nsIPresContext* aPresContext, nsIFrame* aFrame) +{ + nsIFrameDebug* fdbg; + aFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**) &fdbg); + if (fdbg) + fdbg->List(aPresContext, stdout, 0); +} + +#endif + + // Debugging NS_IMETHODIMP nsFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) const @@ -2337,6 +2365,7 @@ nsFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) const if (0 != mState) { fprintf(out, " [state=%08x]", mState); } + fprintf(out, " [content=%p]", mContent); fputs("\n", out); return NS_OK; } diff --git a/layout/html/base/src/nsContainerFrame.cpp b/layout/html/base/src/nsContainerFrame.cpp index dced2f052a7..b220e2b28e4 100644 --- a/layout/html/base/src/nsContainerFrame.cpp +++ b/layout/html/base/src/nsContainerFrame.cpp @@ -1111,7 +1111,8 @@ nsContainerFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) if (0 != mState) { fprintf(out, " [state=%08x]", mState); } - fprintf(out, " sc=%p", mStyleContext); + fprintf(out, " [content=%p]", mContent); + fprintf(out, " [sc=%p]", mStyleContext); // Output the children nsIAtom* listName = nsnull; diff --git a/layout/html/base/src/nsFrame.cpp b/layout/html/base/src/nsFrame.cpp index d73a4ccb28a..4e4b79cd9f0 100644 --- a/layout/html/base/src/nsFrame.cpp +++ b/layout/html/base/src/nsFrame.cpp @@ -2319,6 +2319,34 @@ PRInt32 nsFrame::ContentIndexInContainer(const nsIFrame* aFrame) } #ifdef NS_DEBUG + +#ifdef DEBUG_waterson + +/** + * List a single frame to stdout. Meant to be called from gdb. + */ +void +DebugListFrame(nsIPresContext* aPresContext, nsIFrame* aFrame) +{ + ((nsFrame*) aFrame)->List(aPresContext, stdout, 0); + printf("\n"); +} + +/** + * List a frame tree to stdout. Meant to be called from gdb. + */ +void +DebugListFrameTree(nsIPresContext* aPresContext, nsIFrame* aFrame) +{ + nsIFrameDebug* fdbg; + aFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**) &fdbg); + if (fdbg) + fdbg->List(aPresContext, stdout, 0); +} + +#endif + + // Debugging NS_IMETHODIMP nsFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) const @@ -2337,6 +2365,7 @@ nsFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) const if (0 != mState) { fprintf(out, " [state=%08x]", mState); } + fprintf(out, " [content=%p]", mContent); fputs("\n", out); return NS_OK; }