diff --git a/content/xslt/src/xpath/nsXPathResult.cpp b/content/xslt/src/xpath/nsXPathResult.cpp index c88c4a1a004f..4f9b843b6a67 100644 --- a/content/xslt/src/xpath/nsXPathResult.cpp +++ b/content/xslt/src/xpath/nsXPathResult.cpp @@ -45,8 +45,8 @@ #include "nsIContent.h" #include "nsIDOMClassInfo.h" #include "nsIDOMNode.h" -#include "nsSupportsArray.h" #include "nsXPathException.h" +#include "nsIDOMDocument.h" NS_IMPL_ADDREF(nsXPathResult) NS_IMPL_RELEASE(nsXPathResult) @@ -151,9 +151,9 @@ nsXPathResult::GetSnapshotLength(PRUint32 *aSnapshotLength) return NS_ERROR_DOM_TYPE_ERR; NS_ENSURE_ARG(aSnapshotLength); - if (mElements) - return mElements->Count(aSnapshotLength); *aSnapshotLength = 0; + if (mElements) + *aSnapshotLength = mElements->Count(); return NS_OK; } @@ -171,14 +171,10 @@ nsXPathResult::IterateNext(nsIDOMNode **aResult) return NS_ERROR_DOM_INVALID_STATE_ERR; NS_ENSURE_ARG(aResult); - if (mElements) { - PRUint32 count; - mElements->Count(&count); - if (mCurrentPos < count) { - return mElements->QueryElementAt(mCurrentPos++, - NS_GET_IID(nsIDOMNode), - (void**)aResult); - } + if (mElements && mCurrentPos < mElements->Count()) { + *aResult = mElements->ObjectAt(mCurrentPos++); + NS_ADDREF(*aResult); + return NS_OK; } *aResult = nsnull; return NS_OK; @@ -192,14 +188,10 @@ nsXPathResult::SnapshotItem(PRUint32 aIndex, nsIDOMNode **aResult) return NS_ERROR_DOM_TYPE_ERR; NS_ENSURE_ARG(aResult); - if (mElements) { - PRUint32 count; - mElements->Count(&count); - if (aIndex < count) { - return mElements->QueryElementAt(aIndex, - NS_GET_IID(nsIDOMNode), - (void**)aResult); - } + if (mElements && aIndex < mElements->Count()) { + *aResult = mElements->ObjectAt(aIndex); + NS_ADDREF(*aResult); + return NS_OK; } *aResult = nsnull; return NS_OK; @@ -316,23 +308,28 @@ nsXPathResult::SetExprResult(ExprResult* aExprResult, PRUint16 aResultType) if (count == 0) return NS_OK; - NS_NewISupportsArray(&mElements); + mElements = new nsCOMArray; NS_ENSURE_TRUE(mElements, NS_ERROR_OUT_OF_MEMORY); - nsISupports* mozNode = nsnull; + nsCOMPtr node; int i; for (i = 0; i < count; ++i) { - mozNode = nodeSet->get(i)->getNSObj(); - mElements->AppendElement(mozNode); - NS_ADDREF(mozNode); + node = do_QueryInterface(nodeSet->get(i)->getNSObj()); + NS_ASSERTION(node, "node isn't an nsIDOMNode"); + mElements->AppendObject(node); } + + // If we support the document() function in DOM-XPath we need to + // observe all documents that we have resultnodes in. if (mResultType == UNORDERED_NODE_ITERATOR_TYPE || mResultType == ORDERED_NODE_ITERATOR_TYPE) { - nsCOMPtr content = do_QueryInterface(mozNode); - if (content) - content->GetDocument(*getter_AddRefs(mDocument)); + nsCOMPtr document; + node->GetOwnerDocument(getter_AddRefs(document)); + if (document) + mDocument = do_QueryInterface(document); else - mDocument = do_QueryInterface(mozNode); + mDocument = do_QueryInterface(node); + NS_ASSERTION(mDocument, "We need a document!"); if (mDocument) mDocument->AddObserver(this); @@ -367,7 +364,7 @@ nsXPathResult::Reset() mResultType == ORDERED_NODE_ITERATOR_TYPE || mResultType == UNORDERED_NODE_SNAPSHOT_TYPE || mResultType == ORDERED_NODE_SNAPSHOT_TYPE) { - NS_IF_RELEASE(mElements); + delete mElements; mCurrentPos = 0; } else if (mResultType == FIRST_ORDERED_NODE_TYPE || diff --git a/content/xslt/src/xpath/nsXPathResult.h b/content/xslt/src/xpath/nsXPathResult.h index 3c0d8ccc5fc0..ffcfb9fdaf89 100644 --- a/content/xslt/src/xpath/nsXPathResult.h +++ b/content/xslt/src/xpath/nsXPathResult.h @@ -44,10 +44,10 @@ #include "nsIDocument.h" #include "nsIDocumentObserver.h" #include "nsCOMPtr.h" +#include "nsCOMArray.h" class ExprResult; class String; -class nsISupportsArray; // {15b9b301-2012-11d6-a7f2-e6d0a678995c} #define NS_IXPATHRESULT_IID \ @@ -93,7 +93,7 @@ private: String* mStringValue; PRBool mBooleanValue; nsIDOMNode* mNode; - nsISupportsArray* mElements; + nsCOMArray* mElements; }; nsCOMPtr mDocument; PRUint32 mCurrentPos; diff --git a/content/xslt/src/xslt/txMozillaXMLOutput.cpp b/content/xslt/src/xslt/txMozillaXMLOutput.cpp index 13d0e38144a5..ad6bb1c07b04 100644 --- a/content/xslt/src/xslt/txMozillaXMLOutput.cpp +++ b/content/xslt/src/xslt/txMozillaXMLOutput.cpp @@ -318,11 +318,7 @@ void txMozillaXMLOutput::processingInstruction(const String& aTarget, const Stri void txMozillaXMLOutput::removeScriptElement(nsIDOMHTMLScriptElement *aElement) { - if (mScriptElements) { - PRInt32 index = mScriptElements->IndexOf(aElement); - if (index > -1) - mScriptElements->RemoveElementAt(index); - } + mScriptElements.RemoveObject(aElement); } void txMozillaXMLOutput::startDocument() @@ -547,11 +543,7 @@ void txMozillaXMLOutput::endHTMLElement(nsIDOMElement* aElement, nsCOMPtr scriptElement = do_QueryInterface(mCurrentNode); NS_ASSERTION(scriptElement, "Need script element"); - if (!mScriptElements) - NS_NewISupportsArray(getter_AddRefs(mScriptElements)); - NS_ASSERTION(mScriptElements, "Can't create array"); - if (mScriptElements) - mScriptElements->AppendElement(scriptElement); + mScriptElements.AppendObject(scriptElement); } // Set document title else if (mCreatingNewDocument && @@ -776,12 +768,8 @@ txMozillaXMLOutput::SignalTransformEnd() return; } - if (mScriptElements) { - PRUint32 scriptCount = 0; - mScriptElements->Count(&scriptCount); - if (scriptCount != 0) { - return; - } + if (mScriptElements.Count() > 0) { + return; } // Make sure that we don't get deleted while this function is executed and diff --git a/content/xslt/src/xslt/txMozillaXMLOutput.h b/content/xslt/src/xslt/txMozillaXMLOutput.h index 16ddbc4e4e83..86896690b6d2 100644 --- a/content/xslt/src/xslt/txMozillaXMLOutput.h +++ b/content/xslt/src/xslt/txMozillaXMLOutput.h @@ -47,9 +47,9 @@ #include "nsIScriptLoaderObserver.h" #include "nsIStyleSheetLinkingElement.h" #include "nsString.h" -#include "nsSupportsArray.h" #include "nsWeakPtr.h" #include "txOutputFormat.h" +#include "nsCOMArray.h" class txMozillaXMLOutput : public txIOutputXMLEventHandler, public nsIScriptLoaderObserver @@ -191,7 +191,7 @@ private: PRUint32 mBadChildLevel; nsCString mRefreshString; - nsCOMPtr mScriptElements; + nsCOMArray mScriptElements; nsAutoString mText;