diff --git a/content/base/public/nsIContent.h b/content/base/public/nsIContent.h index 15003393598..41a2595f9c8 100644 --- a/content/base/public/nsIContent.h +++ b/content/base/public/nsIContent.h @@ -26,7 +26,6 @@ // Forward declarations class nsIAtom; -class nsIContentDelegate; class nsIDocument; class nsIPresContext; class nsString; @@ -37,6 +36,7 @@ class nsIDOMEvent; class nsIContent; class nsISupportsArray; class nsIDOMRange; +class nsISizeOfHandler; // IID for the nsIContent interface #define NS_ICONTENT_IID \ @@ -187,6 +187,23 @@ public: */ NS_IMETHOD GetAttributeCount(PRInt32& aCountResult) const = 0; + /** + * Get the size of the content object. The size value should include + * all subordinate data referenced by the content that is not + * accounted for by child content. However, this value should not + * include the frame objects, style contexts, views or other data + * that lies logically outside the content model. + * + * If the implementation so chooses, instead of returning the total + * subordinate data it may instead use the sizeof handler to store + * away subordinate data under its own key so that the subordinate + * data may be tabulated independently of the frame itself. + * + * The caller is responsible for recursing over all children that + * the content contains. + */ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const = 0; + /** * List the content (and anything it contains) out to the given * file stream. Use aIndent as the base indent during formatting. diff --git a/content/base/src/nsCommentNode.cpp b/content/base/src/nsCommentNode.cpp index c612d96c0ca..fcc69bcc317 100644 --- a/content/base/src/nsCommentNode.cpp +++ b/content/base/src/nsCommentNode.cpp @@ -170,6 +170,17 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } +#ifdef DEBUG + *aResult = sizeof(*this); +#else + *aResult = 0; +#endif + return NS_OK; + } NS_IMETHOD GetText(const nsTextFragment*& aFragmentsResult, PRInt32& aNumFragmentsResult) diff --git a/content/base/src/nsDocumentFragment.cpp b/content/base/src/nsDocumentFragment.cpp index 991040cd292..74d7e776b58 100644 --- a/content/base/src/nsDocumentFragment.cpp +++ b/content/base/src/nsDocumentFragment.cpp @@ -202,6 +202,17 @@ public: { return mInner.RangeRemove(aRange); } NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } +#ifdef DEBUG + *aResult = sizeof(*this); +#else + *aResult = 0; +#endif + return NS_OK; + } protected: nsGenericContainerElement mInner; diff --git a/content/base/src/nsGenericDOMDataNode.cpp b/content/base/src/nsGenericDOMDataNode.cpp index 357454e4fa3..a67788c10a5 100644 --- a/content/base/src/nsGenericDOMDataNode.cpp +++ b/content/base/src/nsGenericDOMDataNode.cpp @@ -821,6 +821,22 @@ nsGenericDOMDataNode::GetRangeList(nsVoidArray*& aResult) const return NS_OK; } +nsresult +nsGenericDOMDataNode::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const +{ + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = 0; +#ifdef DEBUG + sum += (PRUint32) aInstanceSize; + sum += mText.GetLength() * + (mText.Is2b() ? sizeof(PRUnichar) : sizeof(char)); +#endif + *aResult = sum; + return NS_OK; +} //---------------------------------------------------------------------- diff --git a/content/base/src/nsGenericDOMDataNode.h b/content/base/src/nsGenericDOMDataNode.h index ddddca59f93..89f29b2d164 100644 --- a/content/base/src/nsGenericDOMDataNode.h +++ b/content/base/src/nsGenericDOMDataNode.h @@ -172,6 +172,8 @@ struct nsGenericDOMDataNode { nsresult RangeAdd(nsIDOMRange& aRange); nsresult RangeRemove(nsIDOMRange& aRange); nsresult GetRangeList(nsVoidArray*& aResult) const; + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const; // Implementation for nsIContent nsresult BeginConvertToXIF(nsXIFConverter& aConverter) const; @@ -476,7 +478,10 @@ struct nsGenericDOMDataNode { } \ NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ - } + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { \ + return _g.SizeOf(aSizer, aResult, sizeof(*this)); \ + } /** * Implement the nsIDOMText API by forwarding the methods to a diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 470fdd3802b..0356496ec42 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -883,6 +883,21 @@ nsGenericElement::GetRangeList(nsVoidArray*& aResult) const return NS_OK; } +nsresult +nsGenericElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const +{ + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } +#ifdef DEBUG + *aResult = (PRUint32) aInstanceSize; +#else + *aResult = 0; +#endif + return NS_OK; +} + //---------------------------------------------------------------------- nsresult @@ -1351,6 +1366,20 @@ struct nsGenericAttribute NS_IF_RELEASE(mName); } +#ifdef DEBUG + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = sizeof(*this) - sizeof(mValue); + PRUint32 ssize; + mValue.SizeOf(aSizer, &ssize); + sum += ssize; + *aResult = sum; + return NS_OK; + } +#endif + PRInt32 mNameSpaceID; nsIAtom* mName; nsString mValue; @@ -2156,3 +2185,36 @@ nsGenericContainerElement::FinishConvertToXIF(nsXIFConverter& aConverter) const { return NS_OK; } + +nsresult +nsGenericContainerElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const +{ + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = 0; +#ifdef DEBUG + sum += aInstanceSize; + if (mAttributes) { + // Add in array of attributes size + PRUint32 asize; + mAttributes->SizeOf(aSizer, &asize); + sum += asize; + + // Add in each attributes size + PRInt32 i, n = mAttributes->Count(); + for (i = 0; i < n; i++) { + const nsGenericAttribute* attr = (const nsGenericAttribute*) + mAttributes->ElementAt(i); + if (attr) { + PRUint32 asum = 0; + attr->SizeOf(aSizer, &asum); + sum += asum; + } + } + } +#endif + *aResult = sum; + return NS_OK; +} diff --git a/content/base/src/nsGenericElement.h b/content/base/src/nsGenericElement.h index 6ffc807233b..19cf519b119 100644 --- a/content/base/src/nsGenericElement.h +++ b/content/base/src/nsGenericElement.h @@ -163,6 +163,8 @@ public: nsresult RangeAdd(nsIDOMRange& aRange); nsresult RangeRemove(nsIDOMRange& aRange); nsresult GetRangeList(nsVoidArray*& aResult) const; + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const; // Implementation for nsIJSScriptObject PRBool AddProperty(JSContext *aContext, jsval aID, jsval *aVp); @@ -277,6 +279,8 @@ public: nsresult BeginConvertToXIF(nsXIFConverter& aConverter) const; nsresult ConvertContentToXIF(nsXIFConverter& aConverter) const; nsresult FinishConvertToXIF(nsXIFConverter& aConverter) const; + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const; void ListAttributes(FILE* out) const; @@ -526,7 +530,10 @@ public: } \ NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ - } + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { \ + return _g.SizeOf(aSizer, aResult, sizeof(*this)); \ + } #define NS_IMPL_ICONTENT_NO_SETPARENT_USING_GENERIC(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ @@ -634,7 +641,10 @@ public: } \ NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ - } + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { \ + return _g.SizeOf(aSizer, aResult, sizeof(*this)); \ + } #define NS_IMPL_ICONTENT_NO_SETDOCUMENT_USING_GENERIC(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ @@ -742,7 +752,10 @@ public: } \ NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ - } + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { \ + return _g.SizeOf(aSizer, aResult, sizeof(*this)); \ + } #define NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_USING_GENERIC(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ @@ -848,7 +861,10 @@ public: } \ NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ - } + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { \ + return _g.SizeOf(aSizer, aResult, sizeof(*this)); \ + } /** * Implement the nsIScriptObjectOwner API by forwarding the methods to a diff --git a/content/html/content/src/nsAttributeContent.cpp b/content/html/content/src/nsAttributeContent.cpp index aece688affe..4565b4c7993 100644 --- a/content/html/content/src/nsAttributeContent.cpp +++ b/content/html/content/src/nsAttributeContent.cpp @@ -131,6 +131,17 @@ public: NS_IMETHOD GetAttributeCount(PRInt32& aResult) const { aResult = 0; return NS_OK; } NS_IMETHOD List(FILE* out, PRInt32 aIndent) const { return NS_OK; } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } +#ifdef DEBUG + *aResult = sizeof(*this); +#else + *aResult = 0; +#endif + return NS_OK; + } NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 48ef1f5f702..f50ec00c9a6 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -573,18 +573,6 @@ nsGenericHTMLElement::GetNameSpaceID(PRInt32& aID) const return NS_OK; } - -//void -//nsHTMLTagContent::SizeOfWithoutThis(nsISizeOfHandler* aHandler) const -//{ -// if (!aHandler->HaveSeen(mTag)) { -// mTag->SizeOf(aHandler); -// } -// if (!aHandler->HaveSeen(mAttributes)) { -// mAttributes->SizeOf(aHandler); -// } -//} - nsresult nsGenericHTMLElement::ParseAttributeString(const nsString& aStr, nsIAtom*& aName, @@ -1233,6 +1221,26 @@ nsGenericHTMLElement::List(FILE* out, PRInt32 aIndent) const return NS_OK; } +nsresult +nsGenericHTMLElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const +{ + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = 0; +#ifdef DEBUG + sum += (PRUint32) aInstanceSize; + if (mAttributes) { + PRUint32 attrs = 0; + mAttributes->SizeOf(aSizer, &attrs); + sum += attrs; + } +#endif + *aResult = sum; + return NS_OK; +} + nsresult nsGenericHTMLElement::ToHTML(FILE* out) const { diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index 41869746a51..47a5e0544e9 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -126,6 +126,8 @@ public: nsresult GetBaseTarget(nsString& aBaseTarget) const; nsresult ToHTMLString(nsString& aResult) const; nsresult ToHTML(FILE* out) const; + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const; //---------------------------------------- nsresult AttributeToString(nsIAtom* aAttribute, diff --git a/content/html/content/src/nsHTMLMapElement.cpp b/content/html/content/src/nsHTMLMapElement.cpp index 8510514ab3c..84d0896b93f 100644 --- a/content/html/content/src/nsHTMLMapElement.cpp +++ b/content/html/content/src/nsHTMLMapElement.cpp @@ -175,6 +175,9 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + return mInner.SizeOf(aSizer, aResult, sizeof(*this)); + } // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) diff --git a/content/html/style/src/nsHTMLAttributes.cpp b/content/html/style/src/nsHTMLAttributes.cpp index 4874a6f5fd6..02195b8b441 100644 --- a/content/html/style/src/nsHTMLAttributes.cpp +++ b/content/html/style/src/nsHTMLAttributes.cpp @@ -27,6 +27,7 @@ #include "nsHTMLAtoms.h" #include "nsIHTMLContent.h" #include "nsVoidArray.h" +#include "nsISizeOfHandler.h" //#define DEBUG_REFS @@ -204,6 +205,16 @@ struct HTMLAttribute { return PR_FALSE; } +#ifdef DEBUG + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + *aResult = sizeof(*this); + return NS_OK; + } +#endif + nsIAtom* mAttribute; nsHTMLValue mValue; HTMLAttribute* mNext; @@ -289,6 +300,16 @@ public: NS_IMETHOD List(FILE* out, PRInt32 aIndent) const; +#ifdef DEBUG + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + *aResult = sizeof(*this); + return NS_OK; + } +#endif + nsIHTMLStyleSheet* mSheet; PRInt32 mUseCount; PRInt32 mAttrCount; @@ -780,6 +801,8 @@ public: NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; + protected: virtual nsresult SetAttributeName(nsIAtom* aAttrName, PRBool& aFound); virtual nsresult UnsetAttributeName(nsIAtom* aAttrName, PRBool& aFound); @@ -1460,6 +1483,41 @@ HTMLAttributesImpl::List(FILE* out, PRInt32 aIndent) const return NS_OK; } +NS_IMETHODIMP +HTMLAttributesImpl::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const +{ + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = 0; +#ifdef DEBUG + sum = sizeof(*this); + if (mAttrNames != mNameBuffer) { + sum += sizeof(*mAttrNames) * mAttrSize; + } + if (mFirstUnmapped) { + HTMLAttribute* ha = mFirstUnmapped; + while (ha) { + PRUint32 asum = 0; + ha->SizeOf(aSizer, &asum); + sum += asum; + ha = ha->mNext; + } + } + if (mMapped) { + PRBool recorded; + aSizer->RecordObject((void*)mMapped, &recorded); + if (!recorded) { + PRUint32 asum = 0; + mMapped->SizeOf(aSizer, &asum); + sum += asum; + } + } +#endif + *aResult = sum; + return NS_OK; +} + extern NS_HTML nsresult NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult) { diff --git a/content/html/style/src/nsIHTMLAttributes.h b/content/html/style/src/nsIHTMLAttributes.h index 9362ea9191f..9cfe5038116 100644 --- a/content/html/style/src/nsIHTMLAttributes.h +++ b/content/html/style/src/nsIHTMLAttributes.h @@ -87,6 +87,8 @@ public: #endif NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0; + + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const = 0; }; class nsIHTMLMappedAttributes : public nsISupports { diff --git a/content/xml/content/src/nsXMLElement.h b/content/xml/content/src/nsXMLElement.h index 97b82834cd9..4cca98e7e3f 100644 --- a/content/xml/content/src/nsXMLElement.h +++ b/content/xml/content/src/nsXMLElement.h @@ -164,6 +164,17 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } +#ifdef DEBUG + *aResult = sizeof(*this); +#else + *aResult = 0; +#endif + return NS_OK; + } // nsIXMLContent NS_IMETHOD SetContainingNameSpace(nsINameSpace* aNameSpace) { diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index b849c9e27e9..d0827a67776 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -289,7 +289,7 @@ public: NS_IMETHOD BeginConvertToXIF(nsXIFConverter& aConverter) const; NS_IMETHOD ConvertContentToXIF(nsXIFConverter& aConverter) const; NS_IMETHOD FinishConvertToXIF(nsXIFConverter& aConverter) const; - NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, @@ -2810,10 +2810,17 @@ RDFElementImpl::FinishConvertToXIF(nsXIFConverter& aConverter) const } NS_IMETHODIMP -RDFElementImpl::SizeOf(nsISizeOfHandler* aHandler) const +RDFElementImpl::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { - NS_NOTYETIMPLEMENTED("write me!"); - return NS_ERROR_NOT_IMPLEMENTED; + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = 0; +#ifdef DEBUG + sum += (PRUint32) sizeof(this); +#endif + *aResult = sum; + return NS_OK; } diff --git a/layout/base/public/nsIContent.h b/layout/base/public/nsIContent.h index 15003393598..41a2595f9c8 100644 --- a/layout/base/public/nsIContent.h +++ b/layout/base/public/nsIContent.h @@ -26,7 +26,6 @@ // Forward declarations class nsIAtom; -class nsIContentDelegate; class nsIDocument; class nsIPresContext; class nsString; @@ -37,6 +36,7 @@ class nsIDOMEvent; class nsIContent; class nsISupportsArray; class nsIDOMRange; +class nsISizeOfHandler; // IID for the nsIContent interface #define NS_ICONTENT_IID \ @@ -187,6 +187,23 @@ public: */ NS_IMETHOD GetAttributeCount(PRInt32& aCountResult) const = 0; + /** + * Get the size of the content object. The size value should include + * all subordinate data referenced by the content that is not + * accounted for by child content. However, this value should not + * include the frame objects, style contexts, views or other data + * that lies logically outside the content model. + * + * If the implementation so chooses, instead of returning the total + * subordinate data it may instead use the sizeof handler to store + * away subordinate data under its own key so that the subordinate + * data may be tabulated independently of the frame itself. + * + * The caller is responsible for recursing over all children that + * the content contains. + */ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const = 0; + /** * List the content (and anything it contains) out to the given * file stream. Use aIndent as the base indent during formatting. diff --git a/layout/base/src/nsCommentNode.cpp b/layout/base/src/nsCommentNode.cpp index c612d96c0ca..fcc69bcc317 100644 --- a/layout/base/src/nsCommentNode.cpp +++ b/layout/base/src/nsCommentNode.cpp @@ -170,6 +170,17 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } +#ifdef DEBUG + *aResult = sizeof(*this); +#else + *aResult = 0; +#endif + return NS_OK; + } NS_IMETHOD GetText(const nsTextFragment*& aFragmentsResult, PRInt32& aNumFragmentsResult) diff --git a/layout/base/src/nsDocumentFragment.cpp b/layout/base/src/nsDocumentFragment.cpp index 991040cd292..74d7e776b58 100644 --- a/layout/base/src/nsDocumentFragment.cpp +++ b/layout/base/src/nsDocumentFragment.cpp @@ -202,6 +202,17 @@ public: { return mInner.RangeRemove(aRange); } NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } +#ifdef DEBUG + *aResult = sizeof(*this); +#else + *aResult = 0; +#endif + return NS_OK; + } protected: nsGenericContainerElement mInner; diff --git a/layout/base/src/nsGenericDOMDataNode.cpp b/layout/base/src/nsGenericDOMDataNode.cpp index 357454e4fa3..a67788c10a5 100644 --- a/layout/base/src/nsGenericDOMDataNode.cpp +++ b/layout/base/src/nsGenericDOMDataNode.cpp @@ -821,6 +821,22 @@ nsGenericDOMDataNode::GetRangeList(nsVoidArray*& aResult) const return NS_OK; } +nsresult +nsGenericDOMDataNode::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const +{ + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = 0; +#ifdef DEBUG + sum += (PRUint32) aInstanceSize; + sum += mText.GetLength() * + (mText.Is2b() ? sizeof(PRUnichar) : sizeof(char)); +#endif + *aResult = sum; + return NS_OK; +} //---------------------------------------------------------------------- diff --git a/layout/base/src/nsGenericDOMDataNode.h b/layout/base/src/nsGenericDOMDataNode.h index ddddca59f93..89f29b2d164 100644 --- a/layout/base/src/nsGenericDOMDataNode.h +++ b/layout/base/src/nsGenericDOMDataNode.h @@ -172,6 +172,8 @@ struct nsGenericDOMDataNode { nsresult RangeAdd(nsIDOMRange& aRange); nsresult RangeRemove(nsIDOMRange& aRange); nsresult GetRangeList(nsVoidArray*& aResult) const; + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const; // Implementation for nsIContent nsresult BeginConvertToXIF(nsXIFConverter& aConverter) const; @@ -476,7 +478,10 @@ struct nsGenericDOMDataNode { } \ NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ - } + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { \ + return _g.SizeOf(aSizer, aResult, sizeof(*this)); \ + } /** * Implement the nsIDOMText API by forwarding the methods to a diff --git a/layout/base/src/nsGenericElement.cpp b/layout/base/src/nsGenericElement.cpp index 470fdd3802b..0356496ec42 100644 --- a/layout/base/src/nsGenericElement.cpp +++ b/layout/base/src/nsGenericElement.cpp @@ -883,6 +883,21 @@ nsGenericElement::GetRangeList(nsVoidArray*& aResult) const return NS_OK; } +nsresult +nsGenericElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const +{ + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } +#ifdef DEBUG + *aResult = (PRUint32) aInstanceSize; +#else + *aResult = 0; +#endif + return NS_OK; +} + //---------------------------------------------------------------------- nsresult @@ -1351,6 +1366,20 @@ struct nsGenericAttribute NS_IF_RELEASE(mName); } +#ifdef DEBUG + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = sizeof(*this) - sizeof(mValue); + PRUint32 ssize; + mValue.SizeOf(aSizer, &ssize); + sum += ssize; + *aResult = sum; + return NS_OK; + } +#endif + PRInt32 mNameSpaceID; nsIAtom* mName; nsString mValue; @@ -2156,3 +2185,36 @@ nsGenericContainerElement::FinishConvertToXIF(nsXIFConverter& aConverter) const { return NS_OK; } + +nsresult +nsGenericContainerElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const +{ + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = 0; +#ifdef DEBUG + sum += aInstanceSize; + if (mAttributes) { + // Add in array of attributes size + PRUint32 asize; + mAttributes->SizeOf(aSizer, &asize); + sum += asize; + + // Add in each attributes size + PRInt32 i, n = mAttributes->Count(); + for (i = 0; i < n; i++) { + const nsGenericAttribute* attr = (const nsGenericAttribute*) + mAttributes->ElementAt(i); + if (attr) { + PRUint32 asum = 0; + attr->SizeOf(aSizer, &asum); + sum += asum; + } + } + } +#endif + *aResult = sum; + return NS_OK; +} diff --git a/layout/base/src/nsGenericElement.h b/layout/base/src/nsGenericElement.h index 6ffc807233b..19cf519b119 100644 --- a/layout/base/src/nsGenericElement.h +++ b/layout/base/src/nsGenericElement.h @@ -163,6 +163,8 @@ public: nsresult RangeAdd(nsIDOMRange& aRange); nsresult RangeRemove(nsIDOMRange& aRange); nsresult GetRangeList(nsVoidArray*& aResult) const; + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const; // Implementation for nsIJSScriptObject PRBool AddProperty(JSContext *aContext, jsval aID, jsval *aVp); @@ -277,6 +279,8 @@ public: nsresult BeginConvertToXIF(nsXIFConverter& aConverter) const; nsresult ConvertContentToXIF(nsXIFConverter& aConverter) const; nsresult FinishConvertToXIF(nsXIFConverter& aConverter) const; + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const; void ListAttributes(FILE* out) const; @@ -526,7 +530,10 @@ public: } \ NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ - } + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { \ + return _g.SizeOf(aSizer, aResult, sizeof(*this)); \ + } #define NS_IMPL_ICONTENT_NO_SETPARENT_USING_GENERIC(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ @@ -634,7 +641,10 @@ public: } \ NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ - } + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { \ + return _g.SizeOf(aSizer, aResult, sizeof(*this)); \ + } #define NS_IMPL_ICONTENT_NO_SETDOCUMENT_USING_GENERIC(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ @@ -742,7 +752,10 @@ public: } \ NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ - } + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { \ + return _g.SizeOf(aSizer, aResult, sizeof(*this)); \ + } #define NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_USING_GENERIC(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ @@ -848,7 +861,10 @@ public: } \ NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ - } + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { \ + return _g.SizeOf(aSizer, aResult, sizeof(*this)); \ + } /** * Implement the nsIScriptObjectOwner API by forwarding the methods to a diff --git a/layout/html/content/src/nsAttributeContent.cpp b/layout/html/content/src/nsAttributeContent.cpp index aece688affe..4565b4c7993 100644 --- a/layout/html/content/src/nsAttributeContent.cpp +++ b/layout/html/content/src/nsAttributeContent.cpp @@ -131,6 +131,17 @@ public: NS_IMETHOD GetAttributeCount(PRInt32& aResult) const { aResult = 0; return NS_OK; } NS_IMETHOD List(FILE* out, PRInt32 aIndent) const { return NS_OK; } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } +#ifdef DEBUG + *aResult = sizeof(*this); +#else + *aResult = 0; +#endif + return NS_OK; + } NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, diff --git a/layout/html/content/src/nsGenericHTMLElement.cpp b/layout/html/content/src/nsGenericHTMLElement.cpp index 48ef1f5f702..f50ec00c9a6 100644 --- a/layout/html/content/src/nsGenericHTMLElement.cpp +++ b/layout/html/content/src/nsGenericHTMLElement.cpp @@ -573,18 +573,6 @@ nsGenericHTMLElement::GetNameSpaceID(PRInt32& aID) const return NS_OK; } - -//void -//nsHTMLTagContent::SizeOfWithoutThis(nsISizeOfHandler* aHandler) const -//{ -// if (!aHandler->HaveSeen(mTag)) { -// mTag->SizeOf(aHandler); -// } -// if (!aHandler->HaveSeen(mAttributes)) { -// mAttributes->SizeOf(aHandler); -// } -//} - nsresult nsGenericHTMLElement::ParseAttributeString(const nsString& aStr, nsIAtom*& aName, @@ -1233,6 +1221,26 @@ nsGenericHTMLElement::List(FILE* out, PRInt32 aIndent) const return NS_OK; } +nsresult +nsGenericHTMLElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const +{ + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = 0; +#ifdef DEBUG + sum += (PRUint32) aInstanceSize; + if (mAttributes) { + PRUint32 attrs = 0; + mAttributes->SizeOf(aSizer, &attrs); + sum += attrs; + } +#endif + *aResult = sum; + return NS_OK; +} + nsresult nsGenericHTMLElement::ToHTML(FILE* out) const { diff --git a/layout/html/content/src/nsGenericHTMLElement.h b/layout/html/content/src/nsGenericHTMLElement.h index 41869746a51..47a5e0544e9 100644 --- a/layout/html/content/src/nsGenericHTMLElement.h +++ b/layout/html/content/src/nsGenericHTMLElement.h @@ -126,6 +126,8 @@ public: nsresult GetBaseTarget(nsString& aBaseTarget) const; nsresult ToHTMLString(nsString& aResult) const; nsresult ToHTML(FILE* out) const; + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, + size_t aInstanceSize) const; //---------------------------------------- nsresult AttributeToString(nsIAtom* aAttribute, diff --git a/layout/html/content/src/nsHTMLMapElement.cpp b/layout/html/content/src/nsHTMLMapElement.cpp index 8510514ab3c..84d0896b93f 100644 --- a/layout/html/content/src/nsHTMLMapElement.cpp +++ b/layout/html/content/src/nsHTMLMapElement.cpp @@ -175,6 +175,9 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + return mInner.SizeOf(aSizer, aResult, sizeof(*this)); + } // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) diff --git a/layout/html/style/src/nsHTMLAttributes.cpp b/layout/html/style/src/nsHTMLAttributes.cpp index 4874a6f5fd6..02195b8b441 100644 --- a/layout/html/style/src/nsHTMLAttributes.cpp +++ b/layout/html/style/src/nsHTMLAttributes.cpp @@ -27,6 +27,7 @@ #include "nsHTMLAtoms.h" #include "nsIHTMLContent.h" #include "nsVoidArray.h" +#include "nsISizeOfHandler.h" //#define DEBUG_REFS @@ -204,6 +205,16 @@ struct HTMLAttribute { return PR_FALSE; } +#ifdef DEBUG + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + *aResult = sizeof(*this); + return NS_OK; + } +#endif + nsIAtom* mAttribute; nsHTMLValue mValue; HTMLAttribute* mNext; @@ -289,6 +300,16 @@ public: NS_IMETHOD List(FILE* out, PRInt32 aIndent) const; +#ifdef DEBUG + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + *aResult = sizeof(*this); + return NS_OK; + } +#endif + nsIHTMLStyleSheet* mSheet; PRInt32 mUseCount; PRInt32 mAttrCount; @@ -780,6 +801,8 @@ public: NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; + protected: virtual nsresult SetAttributeName(nsIAtom* aAttrName, PRBool& aFound); virtual nsresult UnsetAttributeName(nsIAtom* aAttrName, PRBool& aFound); @@ -1460,6 +1483,41 @@ HTMLAttributesImpl::List(FILE* out, PRInt32 aIndent) const return NS_OK; } +NS_IMETHODIMP +HTMLAttributesImpl::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const +{ + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = 0; +#ifdef DEBUG + sum = sizeof(*this); + if (mAttrNames != mNameBuffer) { + sum += sizeof(*mAttrNames) * mAttrSize; + } + if (mFirstUnmapped) { + HTMLAttribute* ha = mFirstUnmapped; + while (ha) { + PRUint32 asum = 0; + ha->SizeOf(aSizer, &asum); + sum += asum; + ha = ha->mNext; + } + } + if (mMapped) { + PRBool recorded; + aSizer->RecordObject((void*)mMapped, &recorded); + if (!recorded) { + PRUint32 asum = 0; + mMapped->SizeOf(aSizer, &asum); + sum += asum; + } + } +#endif + *aResult = sum; + return NS_OK; +} + extern NS_HTML nsresult NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult) { diff --git a/layout/html/style/src/nsIHTMLAttributes.h b/layout/html/style/src/nsIHTMLAttributes.h index 9362ea9191f..9cfe5038116 100644 --- a/layout/html/style/src/nsIHTMLAttributes.h +++ b/layout/html/style/src/nsIHTMLAttributes.h @@ -87,6 +87,8 @@ public: #endif NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0; + + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const = 0; }; class nsIHTMLMappedAttributes : public nsISupports { diff --git a/layout/xml/content/src/nsXMLElement.h b/layout/xml/content/src/nsXMLElement.h index 97b82834cd9..4cca98e7e3f 100644 --- a/layout/xml/content/src/nsXMLElement.h +++ b/layout/xml/content/src/nsXMLElement.h @@ -164,6 +164,17 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } +#ifdef DEBUG + *aResult = sizeof(*this); +#else + *aResult = 0; +#endif + return NS_OK; + } // nsIXMLContent NS_IMETHOD SetContainingNameSpace(nsINameSpace* aNameSpace) { diff --git a/rdf/content/src/nsRDFElement.cpp b/rdf/content/src/nsRDFElement.cpp index b849c9e27e9..d0827a67776 100644 --- a/rdf/content/src/nsRDFElement.cpp +++ b/rdf/content/src/nsRDFElement.cpp @@ -289,7 +289,7 @@ public: NS_IMETHOD BeginConvertToXIF(nsXIFConverter& aConverter) const; NS_IMETHOD ConvertContentToXIF(nsXIFConverter& aConverter) const; NS_IMETHOD FinishConvertToXIF(nsXIFConverter& aConverter) const; - NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, @@ -2810,10 +2810,17 @@ RDFElementImpl::FinishConvertToXIF(nsXIFConverter& aConverter) const } NS_IMETHODIMP -RDFElementImpl::SizeOf(nsISizeOfHandler* aHandler) const +RDFElementImpl::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { - NS_NOTYETIMPLEMENTED("write me!"); - return NS_ERROR_NOT_IMPLEMENTED; + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = 0; +#ifdef DEBUG + sum += (PRUint32) sizeof(this); +#endif + *aResult = sum; + return NS_OK; } diff --git a/rdf/content/src/nsXULElement.cpp b/rdf/content/src/nsXULElement.cpp index b849c9e27e9..d0827a67776 100644 --- a/rdf/content/src/nsXULElement.cpp +++ b/rdf/content/src/nsXULElement.cpp @@ -289,7 +289,7 @@ public: NS_IMETHOD BeginConvertToXIF(nsXIFConverter& aConverter) const; NS_IMETHOD ConvertContentToXIF(nsXIFConverter& aConverter) const; NS_IMETHOD FinishConvertToXIF(nsXIFConverter& aConverter) const; - NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, @@ -2810,10 +2810,17 @@ RDFElementImpl::FinishConvertToXIF(nsXIFConverter& aConverter) const } NS_IMETHODIMP -RDFElementImpl::SizeOf(nsISizeOfHandler* aHandler) const +RDFElementImpl::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { - NS_NOTYETIMPLEMENTED("write me!"); - return NS_ERROR_NOT_IMPLEMENTED; + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PRUint32 sum = 0; +#ifdef DEBUG + sum += (PRUint32) sizeof(this); +#endif + *aResult = sum; + return NS_OK; }