diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 0a33ac5acb7..7569d1984bc 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -1106,8 +1106,8 @@ nsEditorShell::TransferDocumentStateListeners() for (PRUint32 i = 0; i < numListeners; i ++) { - nsCOMPtr iSupports = getter_AddRefs(mDocStateListeners->ElementAt(i)); - nsCOMPtr docStateListener = do_QueryInterface(iSupports); + nsCOMPtr docStateListener = + do_QueryElementAt(mDocStateListeners, i); if (docStateListener) { // this checks for duplicates diff --git a/mozilla/editor/libeditor/base/EditAggregateTxn.cpp b/mozilla/editor/libeditor/base/EditAggregateTxn.cpp index 781feae3ed0..68d2ea641d2 100644 --- a/mozilla/editor/libeditor/base/EditAggregateTxn.cpp +++ b/mozilla/editor/libeditor/base/EditAggregateTxn.cpp @@ -64,8 +64,7 @@ NS_IMETHODIMP EditAggregateTxn::DoTransaction(void) mChildren->Count(&count); for (i=0; i<((PRInt32)count); i++) { - nsCOMPtr isupports = dont_AddRef(mChildren->ElementAt(i)); - nsCOMPtr txn ( do_QueryInterface(isupports) ); + nsCOMPtr txn (do_QueryElementAt(mChildren, i)); if (!txn) { return NS_ERROR_NULL_POINTER; } result = txn->DoTransaction(); if (NS_FAILED(result)) @@ -86,8 +85,7 @@ NS_IMETHODIMP EditAggregateTxn::UndoTransaction(void) // undo goes through children backwards for (i=count-1; i>=0; i--) { - nsCOMPtr isupports = dont_AddRef(mChildren->ElementAt(i)); - nsCOMPtr txn ( do_QueryInterface(isupports) ); + nsCOMPtr txn (do_QueryElementAt(mChildren, i)); if (!txn) { return NS_ERROR_NULL_POINTER; } result = txn->UndoTransaction(); if (NS_FAILED(result)) @@ -107,8 +105,7 @@ NS_IMETHODIMP EditAggregateTxn::RedoTransaction(void) mChildren->Count(&count); for (i=0; i<((PRInt32)count); i++) { - nsCOMPtr isupports = dont_AddRef(mChildren->ElementAt(i)); - nsCOMPtr txn ( do_QueryInterface(isupports) ); + nsCOMPtr txn (do_QueryElementAt(mChildren, i)); if (!txn) { return NS_ERROR_NULL_POINTER; } result = txn->RedoTransaction(); if (NS_FAILED(result)) @@ -138,8 +135,7 @@ NS_IMETHODIMP EditAggregateTxn::Merge(nsITransaction *aTransaction, PRBool *aDid NS_ASSERTION(count>0, "bad count"); if (0 isupports = dont_AddRef(mChildren->ElementAt(i)); - nsCOMPtr txn ( do_QueryInterface(isupports) ); + nsCOMPtr txn (do_QueryElementAt(mChildren, i)); if (!txn) { return NS_ERROR_NULL_POINTER; } result = txn->Merge(aTransaction, aDidMerge); } @@ -207,9 +203,8 @@ NS_IMETHODIMP EditAggregateTxn::GetTxnAt(PRInt32 aIndex, EditTxn **aTxn) if (0>aIndex || ((PRInt32)txnCount)<=aIndex) { return NS_ERROR_UNEXPECTED; } - nsCOMPtr isupports = dont_AddRef(mChildren->ElementAt(aIndex)); // ugh, this is all wrong - what a mess we have with editor transaction interfaces - isupports->QueryInterface(EditTxn::GetCID(), (void**)aTxn); + mChildren->QueryElementAt(aIndex, EditTxn::GetCID(), (void**)aTxn); if (!*aTxn) return NS_ERROR_UNEXPECTED; return NS_OK; diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index 74509217905..1fe7d85525d 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -2550,8 +2550,8 @@ nsEditor::NotifyDocumentListeners(TDocumentListenerNotification aNotificationTyp case eDocumentCreated: for (i = 0; i < numListeners;i++) { - nsCOMPtr iSupports = getter_AddRefs(mDocStateListeners->ElementAt(i)); - nsCOMPtr thisListener = do_QueryInterface(iSupports); + nsCOMPtr thisListener = + do_QueryElementAt(mDocStateListeners, i); if (thisListener) { rv = thisListener->NotifyDocumentCreated(); @@ -2564,8 +2564,8 @@ nsEditor::NotifyDocumentListeners(TDocumentListenerNotification aNotificationTyp case eDocumentToBeDestroyed: for (i = 0; i < numListeners;i++) { - nsCOMPtr iSupports = getter_AddRefs(mDocStateListeners->ElementAt(i)); - nsCOMPtr thisListener = do_QueryInterface(iSupports); + nsCOMPtr thisListener = + do_QueryElementAt(mDocStateListeners, i); if (thisListener) { rv = thisListener->NotifyDocumentWillBeDestroyed(); @@ -2588,8 +2588,8 @@ nsEditor::NotifyDocumentListeners(TDocumentListenerNotification aNotificationTyp for (i = 0; i < numListeners;i++) { - nsCOMPtr iSupports = getter_AddRefs(mDocStateListeners->ElementAt(i)); - nsCOMPtr thisListener = do_QueryInterface(iSupports); + nsCOMPtr thisListener = + do_QueryElementAt(mDocStateListeners, i); if (thisListener) { rv = thisListener->NotifyDocumentStateChanged(mDocDirtyState); diff --git a/mozilla/editor/libeditor/base/nsEditorUtils.cpp b/mozilla/editor/libeditor/base/nsEditorUtils.cpp index f087f92975d..fda366fa5c5 100644 --- a/mozilla/editor/libeditor/base/nsEditorUtils.cpp +++ b/mozilla/editor/libeditor/base/nsEditorUtils.cpp @@ -138,27 +138,20 @@ nsDOMIterator::ForEach(nsDomIterFunctor& functor) const } } -nsresult +inline nsresult nsDOMIterator::MakeList(nsBoolDomIterFunctor& functor, - nsCOMPtr *outArrayOfNodes) const + nsCOMArray& outArrayOfNodes) const { - nsresult res; - - // make a array - res = NS_NewISupportsArray(getter_AddRefs(*outArrayOfNodes)); - if (NS_FAILED(res)) return res; - - return AppendList(functor, *outArrayOfNodes); + NS_PRECONDITION(outArrayOfNodes.Count() == 0, "Calling MakeList on non-empty list!"); + return AppendList(functor, outArrayOfNodes); } nsresult nsDOMIterator::AppendList(nsBoolDomIterFunctor& functor, - nsCOMPtr arrayOfNodes) const + nsCOMArray& arrayOfNodes) const { - if (!arrayOfNodes) return NS_ERROR_NULL_POINTER; nsCOMPtr content; nsCOMPtr node; - nsCOMPtr isupports; nsresult res; // iterate through dom and build list @@ -170,8 +163,7 @@ nsDOMIterator::AppendList(nsBoolDomIterFunctor& functor, if (!node) return NS_ERROR_NULL_POINTER; if (functor(node)) { - isupports = do_QueryInterface(node); - arrayOfNodes->AppendElement(isupports); + arrayOfNodes.AppendObject(node); } res = mIter->Next(); if (NS_FAILED(res)) return res; diff --git a/mozilla/editor/libeditor/base/nsEditorUtils.h b/mozilla/editor/libeditor/base/nsEditorUtils.h index b9abfa05b2b..e6d534fdfbb 100644 --- a/mozilla/editor/libeditor/base/nsEditorUtils.h +++ b/mozilla/editor/libeditor/base/nsEditorUtils.h @@ -49,6 +49,7 @@ #include "nsVoidArray.h" #include "nsEditor.h" #include "nsIContentIterator.h" +#include "nsCOMArray.h" class nsPlaintextEditor; @@ -211,9 +212,9 @@ class nsDOMIterator nsresult Init(nsIDOMNode* aNode); void ForEach(nsDomIterFunctor& functor) const; nsresult MakeList(nsBoolDomIterFunctor& functor, - nsCOMPtr *outArrayOfNodes) const; + nsCOMArray& outArrayOfNodes) const; nsresult AppendList(nsBoolDomIterFunctor& functor, - nsCOMPtr arrayOfNodes) const; + nsCOMArray& arrayOfNodes) const; protected: nsCOMPtr mIter; }; diff --git a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp index 880caa716e9..9b9843475ea 100644 --- a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp @@ -84,6 +84,7 @@ #include "nsIDOMRange.h" #include "nsIDOMNSRange.h" #include "nsISupportsArray.h" +#include "nsCOMArray.h" #include "nsVoidArray.h" #include "nsFileSpec.h" #include "nsIFile.h" @@ -309,14 +310,10 @@ nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAString & aInputString, NS_ENSURE_SUCCESS(res, res); // make a list of what nodes in docFrag we need to move - nsCOMPtr nodeList; - res = CreateListOfNodesToPaste(fragmentAsNode, address_of(nodeList), rangeStartHint, rangeEndHint); + nsCOMArray nodeList; + res = CreateListOfNodesToPaste(fragmentAsNode, nodeList, rangeStartHint, rangeEndHint); NS_ENSURE_SUCCESS(res, res); - PRUint32 cc; - - nodeList->Count(&cc); - // are there any table elements in the list? // node and offset for insertion nsCOMPtr parentNode; @@ -338,8 +335,7 @@ nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAString & aInputString, // but if not we want to delete _contents_ of cells and replace // with non-table elements. Use cellSelectionMode bool to // indicate results. - nsCOMPtr isupports = dont_AddRef(nodeList->ElementAt(0)); - nsCOMPtr firstNode( do_QueryInterface(isupports) ); + nsIDOMNode* firstNode = nodeList[0]; if (!nsHTMLEditUtils::IsTableElement(firstNode)) cellSelectionMode = PR_FALSE; } @@ -408,13 +404,13 @@ nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAString & aInputString, // build up list of parents of first node in list that are either // lists or tables. First examine front of paste node list. - nsCOMPtr startListAndTableArray; - res = GetListAndTableParents(PR_FALSE, nodeList, address_of(startListAndTableArray)); + nsCOMArray startListAndTableArray; + res = GetListAndTableParents(PR_FALSE, nodeList, startListAndTableArray); NS_ENSURE_SUCCESS(res, res); // remember number of lists and tables above us PRInt32 highWaterMark = -1; - if (startListAndTableArray->ElementAt(0)) + if (startListAndTableArray.Count() > 0) { res = DiscoverPartialListsAndTables(nodeList, startListAndTableArray, &highWaterMark); NS_ENSURE_SUCCESS(res, res); @@ -430,13 +426,13 @@ nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAString & aInputString, } // Now go through the same process again for the end of the paste node list. - nsCOMPtr endListAndTableArray; - res = GetListAndTableParents(PR_TRUE, nodeList, address_of(endListAndTableArray)); + nsCOMArray endListAndTableArray; + res = GetListAndTableParents(PR_TRUE, nodeList, endListAndTableArray); NS_ENSURE_SUCCESS(res, res); highWaterMark = -1; // remember number of lists and tables above us - if (endListAndTableArray->ElementAt(0)) + if (endListAndTableArray.Count() > 0) { res = DiscoverPartialListsAndTables(nodeList, endListAndTableArray, &highWaterMark); NS_ENSURE_SUCCESS(res, res); @@ -452,8 +448,8 @@ nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAString & aInputString, // Loop over the node list and paste the nodes: PRBool bDidInsert = PR_FALSE; nsCOMPtr parentBlock, lastInsertNode, insertedContextParent; - PRUint32 listCount, j; - nodeList->Count(&listCount); + PRInt32 listCount = nodeList.Count(); + PRInt32 j; if (IsBlockNode(parentNode)) parentBlock = parentNode; else @@ -461,8 +457,7 @@ nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAString & aInputString, for (j=0; j isupports = dont_AddRef(nodeList->ElementAt(j)); - nsCOMPtr curNode( do_QueryInterface(isupports) ); + nsCOMPtr curNode = nodeList[j]; nsString namestr; curNode->GetNodeName(namestr); @@ -1989,11 +1984,11 @@ nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(nsIDOMNSRange *aNSRange, } nsresult nsHTMLEditor::CreateListOfNodesToPaste(nsIDOMNode *aFragmentAsNode, - nsCOMPtr *outNodeList, + nsCOMArray& outNodeList, PRInt32 aRangeStartHint, PRInt32 aRangeEndHint) { - if (!outNodeList || !aFragmentAsNode) + if (!aFragmentAsNode) return NS_ERROR_NULL_POINTER; // First off create a range over the portion of docFrag indicated by @@ -2029,73 +2024,60 @@ nsresult nsHTMLEditor::CreateListOfNodesToPaste(nsIDOMNode *aFragmentAsNode, // now use a subtree iterator over the range to create a list of nodes nsTrivialFunctor functor; nsDOMSubtreeIterator iter; - res = NS_NewISupportsArray(getter_AddRefs(*outNodeList)); - NS_ENSURE_SUCCESS(res, res); res = iter.Init(docFragRange); NS_ENSURE_SUCCESS(res, res); - res = iter.AppendList(functor, *outNodeList); + res = iter.AppendList(functor, outNodeList); return res; } nsresult nsHTMLEditor::GetListAndTableParents(PRBool aEnd, - nsISupportsArray *aListOfNodes, - nsCOMPtr *outArray) + nsCOMArray& aListOfNodes, + nsCOMArray& outArray) { - NS_ENSURE_TRUE(aListOfNodes, NS_ERROR_NULL_POINTER); - NS_ENSURE_TRUE(outArray, NS_ERROR_NULL_POINTER); - - PRUint32 listCount; - aListOfNodes->Count(&listCount); + PRInt32 listCount = aListOfNodes.Count(); if (listCount <= 0) return NS_ERROR_FAILURE; // no empty lists, please // build up list of parents of first (or last) node in list // that are either lists, or tables. - PRUint32 idx = 0; + PRInt32 idx = 0; if (aEnd) idx = listCount-1; - nsCOMPtr isup = dont_AddRef(aListOfNodes->ElementAt(idx)); - nsCOMPtr pNode( do_QueryInterface(isup) ); - nsCOMPtr listAndTableArray; - nsresult res = NS_NewISupportsArray(getter_AddRefs(listAndTableArray)); - NS_ENSURE_SUCCESS(res, res); + nsCOMPtr pNode = aListOfNodes[idx]; while (pNode) { if (nsHTMLEditUtils::IsList(pNode) || nsHTMLEditUtils::IsTable(pNode)) { - isup = do_QueryInterface(pNode); - listAndTableArray->AppendElement(isup); + if (!outArray.AppendObject(pNode)) + { + return NS_ERROR_FAILURE; + } } nsCOMPtr parent; pNode->GetParentNode(getter_AddRefs(parent)); pNode = parent; } - *outArray = listAndTableArray; return NS_OK; } nsresult -nsHTMLEditor::DiscoverPartialListsAndTables(nsISupportsArray *aPasteNodes, - nsISupportsArray *aListsAndTables, +nsHTMLEditor::DiscoverPartialListsAndTables(nsCOMArray& aPasteNodes, + nsCOMArray& aListsAndTables, PRInt32 *outHighWaterMark) { - NS_ENSURE_TRUE(aPasteNodes, NS_ERROR_NULL_POINTER); - NS_ENSURE_TRUE(aListsAndTables, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(outHighWaterMark, NS_ERROR_NULL_POINTER); *outHighWaterMark = -1; - PRUint32 listAndTableParents; - aListsAndTables->Count(&listAndTableParents); + PRInt32 listAndTableParents = aListsAndTables.Count(); // scan insertion list for table elements (other than table). - PRUint32 listCount, j; - aPasteNodes->Count(&listCount); + PRInt32 listCount = aPasteNodes.Count(); + PRInt32 j; for (j=0; j isupports = dont_AddRef(aPasteNodes->ElementAt(j)); - nsCOMPtr curNode( do_QueryInterface(isupports) ); + nsCOMPtr curNode = aPasteNodes[j]; NS_ENSURE_TRUE(curNode, NS_ERROR_FAILURE); if (nsHTMLEditUtils::IsTableElement(curNode) && !nsHTMLEditUtils::IsTable(curNode)) @@ -2103,12 +2085,11 @@ nsHTMLEditor::DiscoverPartialListsAndTables(nsISupportsArray *aPasteNodes, nsCOMPtr theTable = GetTableParent(curNode); if (theTable) { - nsCOMPtr isupTable(do_QueryInterface(theTable)); - PRInt32 indexT = aListsAndTables->IndexOf(isupTable); + PRInt32 indexT = aListsAndTables.IndexOf(theTable); if (indexT >= 0) { *outHighWaterMark = indexT; - if ((PRUint32)*outHighWaterMark == listAndTableParents-1) break; + if (*outHighWaterMark == listAndTableParents-1) break; } else { @@ -2121,12 +2102,11 @@ nsHTMLEditor::DiscoverPartialListsAndTables(nsISupportsArray *aPasteNodes, nsCOMPtr theList = GetListParent(curNode); if (theList) { - nsCOMPtr isupList(do_QueryInterface(theList)); - PRInt32 indexL = aListsAndTables->IndexOf(isupList); + PRInt32 indexL = aListsAndTables.IndexOf(theList); if (indexL >= 0) { *outHighWaterMark = indexL; - if ((PRUint32)*outHighWaterMark == listAndTableParents-1) break; + if (*outHighWaterMark == listAndTableParents-1) break; } else { @@ -2140,24 +2120,21 @@ nsHTMLEditor::DiscoverPartialListsAndTables(nsISupportsArray *aPasteNodes, nsresult nsHTMLEditor::ScanForListAndTableStructure( PRBool aEnd, - nsISupportsArray *aNodes, + nsCOMArray& aNodes, nsIDOMNode *aListOrTable, nsCOMPtr *outReplaceNode) { - NS_ENSURE_TRUE(aNodes, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(aListOrTable, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(outReplaceNode, NS_ERROR_NULL_POINTER); *outReplaceNode = 0; // look upward from first/last paste node for a piece of this list/table - PRUint32 listCount, idx = 0; - aNodes->Count(&listCount); + PRInt32 listCount = aNodes.Count(), idx = 0; if (aEnd) idx = listCount-1; PRBool bList = nsHTMLEditUtils::IsList(aListOrTable); - nsCOMPtr isup = dont_AddRef(aNodes->ElementAt(idx)); - nsCOMPtr pNode = do_QueryInterface(isup); + nsCOMPtr pNode = aNodes[idx]; nsCOMPtr originalNode = pNode; while (pNode) { @@ -2185,18 +2162,14 @@ nsHTMLEditor::ScanForListAndTableStructure( PRBool aEnd, nsresult nsHTMLEditor::ReplaceOrphanedStructure(PRBool aEnd, - nsISupportsArray *aNodeArray, - nsISupportsArray *aListAndTableArray, + nsCOMArray& aNodeArray, + nsCOMArray& aListAndTableArray, PRInt32 aHighWaterMark) { - NS_ENSURE_TRUE(aNodeArray, NS_ERROR_NULL_POINTER); - NS_ENSURE_TRUE(aListAndTableArray, NS_ERROR_NULL_POINTER); - - nsCOMPtr isupports = dont_AddRef(aListAndTableArray->ElementAt(aHighWaterMark)); - nsCOMPtr curNode( do_QueryInterface(isupports) ); + nsCOMPtr curNode = aListAndTableArray[aHighWaterMark]; NS_ENSURE_TRUE(curNode, NS_ERROR_NULL_POINTER); - nsCOMPtr replaceNode, originalNode, tmp; + nsCOMPtr replaceNode, originalNode; // find substructure of list or table that must be included in paste. nsresult res = ScanForListAndTableStructure(aEnd, aNodeArray, @@ -2208,36 +2181,35 @@ nsHTMLEditor::ReplaceOrphanedStructure(PRBool aEnd, { // postprocess list to remove any descendants of this node // so that we dont insert them twice. + nsCOMPtr endpoint; do { - isupports = GetArrayEndpoint(aEnd, aNodeArray); - if (!isupports) break; - tmp = do_QueryInterface(isupports); - if (tmp && nsHTMLEditUtils::IsDescendantOf(tmp, replaceNode)) - aNodeArray->RemoveElement(isupports); + endpoint = GetArrayEndpoint(aEnd, aNodeArray); + if (!endpoint) break; + if (nsHTMLEditUtils::IsDescendantOf(endpoint, replaceNode)) + aNodeArray.RemoveObject(endpoint); else break; - } while(tmp); + } while(endpoint); // now replace the removed nodes with the structural parent - isupports = do_QueryInterface(replaceNode); - if (aEnd) aNodeArray->AppendElement(isupports); - else aNodeArray->InsertElementAt(isupports, 0); + if (aEnd) aNodeArray.AppendObject(replaceNode); + else aNodeArray.InsertObjectAt(replaceNode, 0); } return NS_OK; } -nsISupports* nsHTMLEditor::GetArrayEndpoint(PRBool aEnd, nsISupportsArray *aNodeArray) +nsIDOMNode* nsHTMLEditor::GetArrayEndpoint(PRBool aEnd, + nsCOMArray& aNodeArray) { if (aEnd) { - PRUint32 listCount; - aNodeArray->Count(&listCount); + PRInt32 listCount = aNodeArray.Count(); if (listCount <= 0) return nsnull; - else return aNodeArray->ElementAt(listCount-1); + else return aNodeArray[listCount-1]; } else { - return aNodeArray->ElementAt(0); + return aNodeArray[0]; } } diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp index 695a4370f1f..fad76ceb533 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp @@ -546,18 +546,16 @@ nsHTMLEditRules::GetListState(PRBool *aMixed, PRBool *aOL, PRBool *aUL, PRBool * *aDL = PR_FALSE; PRBool bNonList = PR_FALSE; - nsCOMPtr arrayOfNodes; - nsresult res = GetListActionNodes(address_of(arrayOfNodes), PR_FALSE, PR_TRUE); + nsCOMArray arrayOfNodes; + nsresult res = GetListActionNodes(arrayOfNodes, PR_FALSE, PR_TRUE); if (NS_FAILED(res)) return res; // examine list type for nodes in selection - PRUint32 listCount; + PRInt32 listCount = arrayOfNodes.Count(); PRInt32 i; - arrayOfNodes->Count(&listCount); - for (i=(PRInt32)listCount-1; i>=0; i--) + for (i=listCount-1; i>=0; i--) { - nsCOMPtr isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr curNode( do_QueryInterface(isupports) ); + nsIDOMNode* curNode = arrayOfNodes[i]; if (mHTMLEditor->NodeIsType(curNode,nsIEditProperty::ul)) *aUL = PR_TRUE; @@ -600,18 +598,16 @@ nsHTMLEditRules::GetListItemState(PRBool *aMixed, PRBool *aLI, PRBool *aDT, PRBo *aDD = PR_FALSE; PRBool bNonList = PR_FALSE; - nsCOMPtr arrayOfNodes; - nsresult res = GetListActionNodes(address_of(arrayOfNodes), PR_FALSE, PR_TRUE); + nsCOMArray arrayOfNodes; + nsresult res = GetListActionNodes(arrayOfNodes, PR_FALSE, PR_TRUE); if (NS_FAILED(res)) return res; // examine list type for nodes in selection - PRUint32 listCount; + PRInt32 listCount = arrayOfNodes.Count(); PRInt32 i; - arrayOfNodes->Count(&listCount); - for (i=(PRInt32)listCount-1; i>=0; i--) + for (i = listCount-1; i>=0; i--) { - nsCOMPtr isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr curNode( do_QueryInterface(isupports) ); + nsIDOMNode* curNode = arrayOfNodes[i]; if (mHTMLEditor->NodeIsType(curNode,nsIEditProperty::ul) || mHTMLEditor->NodeIsType(curNode,nsIEditProperty::ol) || @@ -703,16 +699,15 @@ nsHTMLEditRules::GetAlignment(PRBool *aMixed, nsIHTMLEditor::EAlignment *aAlign) } else { - nsCOMPtr arrayOfRanges; - res = GetPromotedRanges(selection, address_of(arrayOfRanges), kAlign); + nsCOMArray arrayOfRanges; + res = GetPromotedRanges(selection, arrayOfRanges, kAlign); if (NS_FAILED(res)) return res; // use these ranges to contruct a list of nodes to act on. - nsCOMPtr arrayOfNodes; - res = GetNodesForOperation(arrayOfRanges, address_of(arrayOfNodes), kAlign, PR_TRUE); + nsCOMArray arrayOfNodes; + res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, kAlign, PR_TRUE); if (NS_FAILED(res)) return res; - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - nodeToExamine = do_QueryInterface(isupports ); + nodeToExamine = arrayOfNodes[0]; } if (!nodeToExamine) return NS_ERROR_NULL_POINTER; @@ -816,22 +811,20 @@ nsHTMLEditRules::GetIndentState(PRBool *aCanIndent, PRBool *aCanOutdent) return NS_ERROR_FAILURE; // contruct a list of nodes to act on. - nsCOMPtr arrayOfNodes; - res = GetNodesFromSelection(selection, kIndent, address_of(arrayOfNodes), PR_TRUE); + nsCOMArray arrayOfNodes; + res = GetNodesFromSelection(selection, kIndent, arrayOfNodes, PR_TRUE); if (NS_FAILED(res)) return res; // examine nodes in selection for blockquotes or list elements; // these we can outdent. Note that we return true for canOutdent // if *any* of the selection is outdentable, rather than all of it. - PRUint32 listCount; + PRInt32 listCount = arrayOfNodes.Count(); PRInt32 i; - arrayOfNodes->Count(&listCount); PRBool useCSS; mHTMLEditor->GetIsCSSEnabled(&useCSS); - for (i=(PRInt32)listCount-1; i>=0; i--) + for (i=listCount-1; i>=0; i--) { - nsCOMPtr isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr curNode( do_QueryInterface(isupports) ); + nsCOMPtr curNode = arrayOfNodes[i]; if (nsHTMLEditUtils::IsList(curNode) || nsHTMLEditUtils::IsListItem(curNode) || @@ -846,10 +839,9 @@ nsHTMLEditRules::GetIndentState(PRBool *aCanIndent, PRBool *aCanOutdent) // retrieve its specified value mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(curNode, nsIEditProperty::cssMarginLeft, value); float f; - nsIAtom * unit; + nsCOMPtr unit; // get its number part and its unit - mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, &unit); - NS_IF_RELEASE(unit); + mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit)); // if the number part is strictly positive, outdent is possible if (0 < f) { *aCanOutdent = PR_TRUE; @@ -928,26 +920,23 @@ nsHTMLEditRules::GetParagraphState(PRBool *aMixed, nsAString &outFormat) // using "x" as an uninitialized value, since "" is meaningful nsAutoString formatStr(NS_LITERAL_STRING("x")); - nsCOMPtr arrayOfNodes; - nsresult res = GetParagraphFormatNodes(address_of(arrayOfNodes), PR_TRUE); + nsCOMArray arrayOfNodes; + nsresult res = GetParagraphFormatNodes(arrayOfNodes, PR_TRUE); if (NS_FAILED(res)) return res; // post process list. We need to replace any block nodes that are not format // nodes with their content. This is so we only have to look "up" the heirarchy // to find format nodes, instead of both up and down. - nsCOMPtr isupports; - PRUint32 listCount; - arrayOfNodes->Count(&listCount); + PRInt32 listCount = arrayOfNodes.Count(); PRInt32 i; - for (i=(PRInt32)listCount-1; i>=0; i--) + for (i=listCount-1; i>=0; i--) { - isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr curNode( do_QueryInterface(isupports) ); + nsCOMPtr curNode = arrayOfNodes[i]; nsAutoString format; // if it is a known format node we have it easy if (IsBlockNode(curNode) && !IsFormatNode(curNode)) { - // arrayOfNodes->RemoveElement(isupports); + // arrayOfNodes.RemoveObject(curNode); res = AppendInnerFormatNodes(arrayOfNodes, curNode); if (NS_FAILED(res)) return res; } @@ -955,7 +944,7 @@ nsHTMLEditRules::GetParagraphState(PRBool *aMixed, nsAString &outFormat) // we might have an empty node list. if so, find selection parent // and put that on the list - arrayOfNodes->Count(&listCount); + listCount = arrayOfNodes.Count(); if (!listCount) { nsCOMPtr selNode; @@ -965,9 +954,8 @@ nsHTMLEditRules::GetParagraphState(PRBool *aMixed, nsAString &outFormat) if (NS_FAILED(res)) return res; res = mHTMLEditor->GetStartNodeAndOffset(selection, address_of(selNode), &selOffset); if (NS_FAILED(res)) return res; - isupports = do_QueryInterface(selNode); - if (!isupports) return NS_ERROR_NULL_POINTER; - arrayOfNodes->AppendElement(isupports); + if (!selNode) return NS_ERROR_NULL_POINTER; + arrayOfNodes.AppendObject(selNode); listCount = 1; } @@ -978,10 +966,9 @@ nsHTMLEditRules::GetParagraphState(PRBool *aMixed, nsAString &outFormat) if (!rootElem) return NS_ERROR_NULL_POINTER; // loop through the nodes in selection and examine their paragraph format - for (i=(PRInt32)listCount-1; i>=0; i--) + for (i=listCount-1; i>=0; i--) { - isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr curNode( do_QueryInterface(isupports) ); + nsCOMPtr curNode = arrayOfNodes[i]; nsAutoString format; // if it is a known format node we have it easy if (IsFormatNode(curNode)) @@ -1045,13 +1032,13 @@ nsHTMLEditRules::IsFormatNode(nsIDOMNode *aNode) } nsresult -nsHTMLEditRules::AppendInnerFormatNodes(nsISupportsArray *aArray, nsIDOMNode *aNode) +nsHTMLEditRules::AppendInnerFormatNodes(nsCOMArray& aArray, + nsIDOMNode *aNode) { - if (!aArray || !aNode) return NS_ERROR_NULL_POINTER; + if (!aNode) return NS_ERROR_NULL_POINTER; nsCOMPtr childList; nsCOMPtr child; - nsCOMPtr isupports; aNode->GetChildNodes(getter_AddRefs(childList)); if (!childList) return NS_OK; @@ -1072,14 +1059,12 @@ nsHTMLEditRules::AppendInnerFormatNodes(nsISupportsArray *aArray, nsIDOMNode *aN AppendInnerFormatNodes(aArray, child); else if (isFormat) { - isupports = do_QueryInterface(child); - aArray->AppendElement(isupports); + aArray.AppendObject(child); } else if (!foundInline) // if this is the first inline we've found, use it { foundInline = PR_TRUE; - isupports = do_QueryInterface(child); - aArray->AppendElement(isupports); + aArray.AppendObject(child); } j++; } @@ -2027,27 +2012,23 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, // build a list of nodes in the range nsCOMPtr range( do_QueryInterface(currentItem) ); - nsCOMPtr arrayOfNodes; + nsCOMArray arrayOfNodes; nsTrivialFunctor functor; nsDOMSubtreeIterator iter; res = iter.Init(range); if (NS_FAILED(res)) return res; - res = iter.MakeList(functor, address_of(arrayOfNodes)); + res = iter.MakeList(functor, arrayOfNodes); if (NS_FAILED(res)) return res; // now that we have the list, delete non table elements - PRUint32 listCount; - PRUint32 j; - nsCOMPtr somenode; - nsCOMPtr isupports; + PRInt32 listCount = arrayOfNodes.Count(); + PRInt32 j; - arrayOfNodes->Count(&listCount); for (j = 0; j < listCount; j++) { - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - somenode = do_QueryInterface(isupports); + nsIDOMNode* somenode = arrayOfNodes[0]; res = DeleteNonTableElements(somenode); - arrayOfNodes->RemoveElementAt(0); + arrayOfNodes.RemoveObjectAt(0); } } @@ -2279,20 +2260,17 @@ nsHTMLEditRules::JoinBlocks(nsCOMPtr *aLeftBlock, nsresult nsHTMLEditRules::MoveBlock(nsIDOMNode *aLeftBlock, nsIDOMNode *aRightBlock, PRInt32 aLeftOffset, PRInt32 aRightOffset) { - nsCOMPtr arrayOfNodes; + nsCOMArray arrayOfNodes; nsCOMPtr isupports; - nsCOMPtr curNode; // GetNodesFromPoint is the workhorse that figures out what we wnat to move. - nsresult res = GetNodesFromPoint(DOMPoint(aRightBlock,aRightOffset), kMakeList, address_of(arrayOfNodes), PR_TRUE); + nsresult res = GetNodesFromPoint(DOMPoint(aRightBlock,aRightOffset), kMakeList, arrayOfNodes, PR_TRUE); if (NS_FAILED(res)) return res; - PRUint32 listCount; - arrayOfNodes->Count(&listCount); - PRUint32 i; + PRInt32 listCount = arrayOfNodes.Count(); + PRInt32 i; for (i=0; iElementAt(i)); - curNode = do_QueryInterface(isupports); + nsIDOMNode* curNode = arrayOfNodes[i]; if (IsBlockNode(curNode)) { // For block nodes, move their contents only, then delete block. @@ -2446,20 +2424,18 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, if (NS_FAILED(res)) return res; nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); - nsCOMPtr arrayOfNodes; - res = GetListActionNodes(address_of(arrayOfNodes), aEntireList); + nsCOMArray arrayOfNodes; + res = GetListActionNodes(arrayOfNodes, aEntireList); if (NS_FAILED(res)) return res; - PRUint32 listCount; - arrayOfNodes->Count(&listCount); + PRInt32 listCount = arrayOfNodes.Count(); // check if all our nodes are
s, or empty inlines PRBool bOnlyBreaks = PR_TRUE; PRInt32 j; - for (j=0; j<(PRInt32)listCount; j++) + for (j=0; j isupports = dont_AddRef(arrayOfNodes->ElementAt(j)); - nsCOMPtr curNode( do_QueryInterface(isupports ) ); + nsIDOMNode* curNode = arrayOfNodes[j]; // if curNode is not a Break or empty inline, we're done if ( (!nsTextEditUtils::IsBreak(curNode)) && (!IsEmptyInline(curNode)) ) { @@ -2479,9 +2455,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, { for (j=0; j<(PRInt32)listCount; j++) { - nsCOMPtr isupports = dont_AddRef(arrayOfNodes->ElementAt(j)); - nsCOMPtr curNode( do_QueryInterface(isupports ) ); - res = mHTMLEditor->DeleteNode(curNode); + res = mHTMLEditor->DeleteNode(arrayOfNodes[j]); if (NS_FAILED(res)) return res; } } @@ -2515,18 +2489,17 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, // Ok, now go through all the nodes and put then in the list, // or whatever is approriate. Wohoo! - arrayOfNodes->Count(&listCount); + listCount = arrayOfNodes.Count(); nsCOMPtr curParent; nsCOMPtr curList; nsCOMPtr prevListItem; PRInt32 i; - for (i=0; i<(PRInt32)listCount; i++) + for (i=0; i newBlock; - nsCOMPtr isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr curNode( do_QueryInterface(isupports ) ); + nsCOMPtr curNode = arrayOfNodes[i]; PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); if (NS_FAILED(res)) return res; @@ -2663,7 +2636,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, if (NS_FAILED(res)) return res; res = mHTMLEditor->RemoveContainer(curNode); if (NS_FAILED(res)) return res; - arrayOfNodes->Count(&listCount); + listCount = arrayOfNodes.Count(); continue; } @@ -2741,39 +2714,36 @@ nsHTMLEditRules::WillRemoveList(nsISelection *aSelection, if (NS_FAILED(res)) return res; nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); - nsCOMPtr arrayOfRanges; - res = GetPromotedRanges(aSelection, address_of(arrayOfRanges), kMakeList); + nsCOMArray arrayOfRanges; + res = GetPromotedRanges(aSelection, arrayOfRanges, kMakeList); if (NS_FAILED(res)) return res; // use these ranges to contruct a list of nodes to act on. - nsCOMPtr arrayOfNodes; - res = GetListActionNodes(address_of(arrayOfNodes), PR_FALSE); + nsCOMArray arrayOfNodes; + res = GetListActionNodes(arrayOfNodes, PR_FALSE); if (NS_FAILED(res)) return res; // Remove all non-editable nodes. Leave them be. - PRUint32 listCount; + PRInt32 listCount = arrayOfNodes.Count(); PRInt32 i; - arrayOfNodes->Count(&listCount); for (i=listCount-1; i>=0; i--) { - nsCOMPtr isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr testNode( do_QueryInterface(isupports ) ); + nsIDOMNode* testNode = arrayOfNodes[i]; if (!mHTMLEditor->IsEditable(testNode)) { - arrayOfNodes->RemoveElementAt(i); + arrayOfNodes.RemoveObjectAt(i); } } // reset list count - arrayOfNodes->Count(&listCount); + listCount = arrayOfNodes.Count(); // Only act on lists or list items in the array nsCOMPtr curParent; - for (i=0; i<(PRInt32)listCount; i++) + for (i=0; i isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr curNode( do_QueryInterface(isupports ) ); + nsIDOMNode* curNode = arrayOfNodes[i]; PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); if (NS_FAILED(res)) return res; @@ -2833,26 +2803,23 @@ nsHTMLEditRules::WillMakeBasicBlock(nsISelection *aSelection, nsString tString(*aBlockType); // contruct a list of nodes to act on. - nsCOMPtr arrayOfNodes; - res = GetNodesFromSelection(aSelection, kMakeBasicBlock, address_of(arrayOfNodes)); + nsCOMArray arrayOfNodes; + res = GetNodesFromSelection(aSelection, kMakeBasicBlock, arrayOfNodes); if (NS_FAILED(res)) return res; // Remove all non-editable nodes. Leave them be. - PRUint32 listCount; + PRInt32 listCount = arrayOfNodes.Count(); PRInt32 i; - arrayOfNodes->Count(&listCount); for (i=listCount-1; i>=0; i--) { - nsCOMPtr isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr testNode( do_QueryInterface(isupports ) ); - if (!mHTMLEditor->IsEditable(testNode)) + if (!mHTMLEditor->IsEditable(arrayOfNodes[i])) { - arrayOfNodes->RemoveElementAt(i); + arrayOfNodes.RemoveObjectAt(i); } } // reset list count - arrayOfNodes->Count(&listCount); + listCount = arrayOfNodes.Count(); // if nothing visible in list, make an empty block if (ListIsEmptyLine(arrayOfNodes)) @@ -2927,16 +2894,14 @@ nsHTMLEditRules::WillMakeBasicBlock(nsISelection *aSelection, // remember our new block for postprocessing mNewBlock = theBlock; // delete anything that was in the list of nodes - nsCOMPtr isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - nsCOMPtr curNode; - while (isupports) + nsCOMPtr curNode = arrayOfNodes[0]; + while (curNode) { - curNode = do_QueryInterface(isupports); res = mHTMLEditor->DeleteNode(curNode); if (NS_FAILED(res)) return res; - res = arrayOfNodes->RemoveElementAt(0); + res = arrayOfNodes.RemoveObjectAt(0); if (NS_FAILED(res)) return res; - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); + curNode = arrayOfNodes[0]; } // put selection in new block res = aSelection->Collapse(theBlock,0); @@ -3013,8 +2978,8 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool res = NormalizeSelection(aSelection); if (NS_FAILED(res)) return res; nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); - nsCOMPtr arrayOfRanges; - nsCOMPtr arrayOfNodes; + nsCOMArray arrayOfRanges; + nsCOMArray arrayOfNodes; // short circuit: detect case of collapsed selection inside an
  • . // just sublist that
  • . This prevents bug 97797. @@ -3039,10 +3004,7 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool if (liNode) { - res = NS_NewISupportsArray(getter_AddRefs(arrayOfNodes)); - if (NS_FAILED(res)) return res; - nsCOMPtr isupports = do_QueryInterface(liNode); - arrayOfNodes->AppendElement(isupports); + arrayOfNodes.AppendObject(liNode); } else { @@ -3050,7 +3012,7 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool // this basically just expands the range to include the immediate // block parent, and then further expands to include any ancestors // whose children are all in the range - res = GetNodesFromSelection(aSelection, kIndent, address_of(arrayOfNodes)); + res = GetNodesFromSelection(aSelection, kIndent, arrayOfNodes); if (NS_FAILED(res)) return res; } @@ -3073,16 +3035,14 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool mNewBlock = theBlock; RelativeChangeIndentation(theBlock, +1); // delete anything that was in the list of nodes - nsCOMPtr isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - nsCOMPtr curNode; - while (isupports) + nsCOMPtr curNode = arrayOfNodes[0]; + while (curNode) { - curNode = do_QueryInterface(isupports); res = mHTMLEditor->DeleteNode(curNode); if (NS_FAILED(res)) return res; - res = arrayOfNodes->RemoveElementAt(0); + res = arrayOfNodes.RemoveObjectAt(0); if (NS_FAILED(res)) return res; - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); + curNode = arrayOfNodes[0]; } // put selection in new block res = aSelection->Collapse(theBlock,0); @@ -3094,7 +3054,7 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool // means that adjacent nodes in the array don't have the same parent. nsVoidArray transitionList; - res = MakeTransitionList(arrayOfNodes, &transitionList); + res = MakeTransitionList(arrayOfNodes, transitionList); if (NS_FAILED(res)) return res; // Ok, now go through all the nodes and put them in a blockquote, @@ -3103,13 +3063,11 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool nsCOMPtr curParent; nsCOMPtr curQuote; nsCOMPtr curList; - PRUint32 listCount; - arrayOfNodes->Count(&listCount); - for (i=0; i<(PRInt32)listCount; i++) + PRInt32 listCount = arrayOfNodes.Count(); + for (i=0; i isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr curNode( do_QueryInterface(isupports ) ); + nsCOMPtr curNode = arrayOfNodes[i]; PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); if (NS_FAILED(res)) return res; @@ -3192,13 +3150,13 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo // block parent, and then further expands to include any ancestors // whose children are all in the range - nsCOMPtr arrayOfRanges; - res = GetPromotedRanges(aSelection, address_of(arrayOfRanges), kIndent); + nsCOMArray arrayOfRanges; + res = GetPromotedRanges(aSelection, arrayOfRanges, kIndent); if (NS_FAILED(res)) return res; // use these ranges to contruct a list of nodes to act on. - nsCOMPtr arrayOfNodes; - res = GetNodesForOperation(arrayOfRanges, address_of(arrayOfNodes), kIndent); + nsCOMArray arrayOfNodes; + res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, kIndent); if (NS_FAILED(res)) return res; NS_NAMED_LITERAL_STRING(quoteType, "blockquote"); @@ -3220,16 +3178,14 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo // remember our new block for postprocessing mNewBlock = theBlock; // delete anything that was in the list of nodes - nsCOMPtr isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - nsCOMPtr curNode; - while (isupports) + nsCOMPtr curNode = arrayOfNodes[0]; + while (curNode) { - curNode = do_QueryInterface(isupports); res = mHTMLEditor->DeleteNode(curNode); if (NS_FAILED(res)) return res; - res = arrayOfNodes->RemoveElementAt(0); + res = arrayOfNodes.RemoveObjectAt(0); if (NS_FAILED(res)) return res; - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); + curNode = arrayOfNodes[0]; } // put selection in new block res = aSelection->Collapse(theBlock,0); @@ -3242,13 +3198,11 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo // or whatever is appropriate. Wohoo! PRInt32 i; nsCOMPtr curParent, curQuote, curList, indentedLI, sibling; - PRUint32 listCount; - arrayOfNodes->Count(&listCount); - for (i=0; i<(PRInt32)listCount; i++) + PRInt32 listCount = arrayOfNodes.Count(); + for (i=0; i isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr curNode( do_QueryInterface(isupports ) ); + nsCOMPtr curNode = arrayOfNodes[i]; // Ignore all non-editable nodes. Leave them be. if (!mHTMLEditor->IsEditable(curNode)) continue; @@ -3388,23 +3342,21 @@ nsHTMLEditRules::WillOutdent(nsISelection *aSelection, PRBool *aCancel, PRBool * // this basically just expands the range to include the immediate // block parent, and then further expands to include any ancestors // whose children are all in the range - nsCOMPtr arrayOfNodes; - res = GetNodesFromSelection(aSelection, kOutdent, address_of(arrayOfNodes)); + nsCOMArray arrayOfNodes; + res = GetNodesFromSelection(aSelection, kOutdent, arrayOfNodes); if (NS_FAILED(res)) return res; // Ok, now go through all the nodes and remove a level of blockquoting, // or whatever is appropriate. Wohoo! nsCOMPtr curBlockQuote, firstBQChild, lastBQChild; - PRUint32 listCount; + PRInt32 listCount = arrayOfNodes.Count(); PRInt32 i; - arrayOfNodes->Count(&listCount); nsCOMPtr curParent; - for (i=0; i<(PRInt32)listCount; i++) + for (i=0; i isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr curNode( do_QueryInterface(isupports ) ); + nsCOMPtr curNode = arrayOfNodes[i]; PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); if (NS_FAILED(res)) return res; @@ -3872,20 +3824,18 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, // block parent, and then further expands to include any ancestors // whose children are all in the range *aHandled = PR_TRUE; - nsCOMPtr arrayOfNodes; - res = GetNodesFromSelection(aSelection, kAlign, address_of(arrayOfNodes)); + nsCOMArray arrayOfNodes; + res = GetNodesFromSelection(aSelection, kAlign, arrayOfNodes); if (NS_FAILED(res)) return res; // if we don't have any nodes, or we have only a single br, then we are // creating an empty alignment div. We have to do some different things for these. PRBool emptyDiv = PR_FALSE; - PRUint32 listCount; - arrayOfNodes->Count(&listCount); + PRInt32 listCount = arrayOfNodes.Count(); if (!listCount) emptyDiv = PR_TRUE; if (listCount == 1) { - nsCOMPtr isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - nsCOMPtr theNode( do_QueryInterface(isupports ) ); + nsCOMPtr theNode = arrayOfNodes[0]; if (nsHTMLEditUtils::SupportsAlignAttr(theNode)) { @@ -3969,7 +3919,7 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, // means that adjacent nodes in the array don't have the same parent. nsVoidArray transitionList; - res = MakeTransitionList(arrayOfNodes, &transitionList); + res = MakeTransitionList(arrayOfNodes, transitionList); if (NS_FAILED(res)) return res; // Ok, now go through all the nodes and give them an align attrib or put them in a div, @@ -3980,11 +3930,10 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, nsCOMPtr curDiv; PRBool useCSS; mHTMLEditor->GetIsCSSEnabled(&useCSS); - for (i=0; i<(PRInt32)listCount; i++) + for (i=0; i isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - nsCOMPtr curNode( do_QueryInterface(isupports ) ); + nsCOMPtr curNode = arrayOfNodes[i]; PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); if (NS_FAILED(res)) return res; @@ -4078,28 +4027,24 @@ nsHTMLEditRules::AlignInnerBlocks(nsIDOMNode *aNode, const nsAString *alignType) nsresult res; // gather list of table cells or list items - nsCOMPtr arrayOfNodes; + nsCOMArray arrayOfNodes; nsTableCellAndListItemFunctor functor; nsDOMIterator iter; res = iter.Init(aNode); if (NS_FAILED(res)) return res; - res = iter.MakeList(functor, address_of(arrayOfNodes)); + res = iter.MakeList(functor, arrayOfNodes); if (NS_FAILED(res)) return res; // now that we have the list, align their contents as requested - PRUint32 listCount; - PRUint32 j; - nsCOMPtr node; - nsCOMPtr isupports; + PRInt32 listCount = arrayOfNodes.Count(); + PRInt32 j; - arrayOfNodes->Count(&listCount); for (j = 0; j < listCount; j++) { - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - node = do_QueryInterface(isupports); + nsIDOMNode* node = arrayOfNodes[0]; res = AlignBlockContents(node, alignType); if (NS_FAILED(res)) return res; - arrayOfNodes->RemoveElementAt(0); + arrayOfNodes.RemoveObjectAt(0); } return res; @@ -4282,13 +4227,12 @@ nsHTMLEditRules::CheckForInvisibleBR(nsIDOMNode *aBlock, // aIndex is updated to point past inserted elements. // nsresult -nsHTMLEditRules::GetInnerContent(nsIDOMNode *aNode, nsISupportsArray *outArrayOfNodes, +nsHTMLEditRules::GetInnerContent(nsIDOMNode *aNode, nsCOMArray &outArrayOfNodes, PRInt32 *aIndex, PRBool aList, PRBool aTbl) { - if (!aNode || !outArrayOfNodes || !aIndex) return NS_ERROR_NULL_POINTER; + if (!aNode || !aIndex) return NS_ERROR_NULL_POINTER; nsCOMPtr node; - nsCOMPtr isupports; nsresult res = mHTMLEditor->GetFirstEditableChild(aNode, address_of(node)); while (NS_SUCCEEDED(res) && node) @@ -4302,8 +4246,7 @@ nsHTMLEditRules::GetInnerContent(nsIDOMNode *aNode, nsISupportsArray *outArrayOf } else { - isupports = do_QueryInterface(node); - outArrayOfNodes->InsertElementAt(isupports, *aIndex); + outArrayOfNodes.InsertObjectAt(node, *aIndex); (*aIndex)++; } nsCOMPtr tmp; @@ -4835,16 +4778,13 @@ nsHTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt // nsresult nsHTMLEditRules::GetPromotedRanges(nsISelection *inSelection, - nsCOMPtr *outArrayOfRanges, + nsCOMArray &outArrayOfRanges, PRInt32 inOperationType) { - if (!inSelection || !outArrayOfRanges) return NS_ERROR_NULL_POINTER; + if (!inSelection) return NS_ERROR_NULL_POINTER; - nsresult res = NS_NewISupportsArray(getter_AddRefs(*outArrayOfRanges)); - if (NS_FAILED(res)) return res; - PRInt32 rangeCount; - res = inSelection->GetRangeCount(&rangeCount); + nsresult res = inSelection->GetRangeCount(&rangeCount); if (NS_FAILED(res)) return res; PRInt32 i; @@ -4867,9 +4807,8 @@ nsHTMLEditRules::GetPromotedRanges(nsISelection *inSelection, res = PromoteRange(opRange, inOperationType); if (NS_FAILED(res)) return res; - // stuff new opRange into nsISupportsArray - nsCOMPtr isupports = do_QueryInterface(opRange); - (*outArrayOfRanges)->AppendElement(isupports); + // stuff new opRange into array + outArrayOfRanges.AppendObject(opRange); } return res; } @@ -4959,28 +4898,21 @@ nsHTMLEditRules::PromoteRange(nsIDOMRange *inRange, // a new array of nodes to be acted on. // nsresult -nsHTMLEditRules::GetNodesForOperation(nsISupportsArray *inArrayOfRanges, - nsCOMPtr *outArrayOfNodes, - PRInt32 inOperationType, - PRBool aDontTouchContent) +nsHTMLEditRules::GetNodesForOperation(nsCOMArray& inArrayOfRanges, + nsCOMArray& outArrayOfNodes, + PRInt32 inOperationType, + PRBool aDontTouchContent) { - if (!inArrayOfRanges || !outArrayOfNodes) return NS_ERROR_NULL_POINTER; - - // make a array - nsresult res = NS_NewISupportsArray(getter_AddRefs(*outArrayOfNodes)); - if (NS_FAILED(res)) return res; - - PRUint32 rangeCount; - res = inArrayOfRanges->Count(&rangeCount); - if (NS_FAILED(res)) return res; + PRInt32 rangeCount = inArrayOfRanges.Count(); PRInt32 i; nsCOMPtr opRange; - nsCOMPtr isupports; PRBool useCSS; mHTMLEditor->GetIsCSSEnabled(&useCSS); + nsresult res = NS_OK; + // bust up any inlines that cross our range endpoints, // but only if we are allowed to touch content. @@ -4988,26 +4920,27 @@ nsHTMLEditRules::GetNodesForOperation(nsISupportsArray *inArrayOfRanges, { nsVoidArray rangeItemArray; // first register ranges for special editor gravity + // XXXbz doesn't this leak all the nsRangeStore structs on error + // conditions?? for (i = 0; i < (PRInt32)rangeCount; i++) { - isupports = dont_AddRef(inArrayOfRanges->ElementAt(0)); - opRange = do_QueryInterface(isupports); + opRange = inArrayOfRanges[0]; nsRangeStore *item = new nsRangeStore(); if (!item) return NS_ERROR_NULL_POINTER; item->StoreRange(opRange); mHTMLEditor->mRangeUpdater.RegisterRangeItem(item); rangeItemArray.AppendElement((void*)item); - inArrayOfRanges->RemoveElementAt(0); + inArrayOfRanges.RemoveObjectAt(0); } // now bust up inlines - for (i = (PRInt32)rangeCount-1; i >= 0; i--) + for (i = rangeCount-1; i >= 0; i--) { nsRangeStore *item = (nsRangeStore*)rangeItemArray.ElementAt(i); res = BustUpInlinesAtRangeEndpoints(*item); if (NS_FAILED(res)) return res; } // then unregister the ranges - for (i = 0; i < (PRInt32)rangeCount; i++) + for (i = 0; i < rangeCount; i++) { nsRangeStore *item = (nsRangeStore*)rangeItemArray.ElementAt(0); if (!item) return NS_ERROR_NULL_POINTER; @@ -5016,21 +4949,19 @@ nsHTMLEditRules::GetNodesForOperation(nsISupportsArray *inArrayOfRanges, res = item->GetRange(address_of(opRange)); if (NS_FAILED(res)) return res; delete item; - isupports = do_QueryInterface(opRange); - inArrayOfRanges->AppendElement(isupports); + inArrayOfRanges.AppendObject(opRange); } } // gather up a list of all the nodes - for (i = 0; i < (PRInt32)rangeCount; i++) + for (i = 0; i < rangeCount; i++) { - isupports = dont_AddRef(inArrayOfRanges->ElementAt(i)); - opRange = do_QueryInterface(isupports); + opRange = inArrayOfRanges[i]; nsTrivialFunctor functor; nsDOMSubtreeIterator iter; res = iter.Init(opRange); if (NS_FAILED(res)) return res; - res = iter.AppendList(functor, *outArrayOfNodes); + res = iter.AppendList(functor, outArrayOfNodes); if (NS_FAILED(res)) return res; } @@ -5038,17 +4969,15 @@ nsHTMLEditRules::GetNodesForOperation(nsISupportsArray *inArrayOfRanges, // them. alter the list as needed if (inOperationType == kMakeBasicBlock) { - PRUint32 listCount; - (*outArrayOfNodes)->Count(&listCount); - for (i=(PRInt32)listCount-1; i>=0; i--) + PRInt32 listCount = outArrayOfNodes.Count(); + for (i=listCount-1; i>=0; i--) { - isupports = dont_AddRef((*outArrayOfNodes)->ElementAt(i)); - nsCOMPtr node( do_QueryInterface(isupports) ); + nsCOMPtr node = outArrayOfNodes[i]; if (nsHTMLEditUtils::IsListItem(node)) { PRInt32 j=i; - (*outArrayOfNodes)->RemoveElementAt(i); - res = GetInnerContent(node, *outArrayOfNodes, &j); + outArrayOfNodes.RemoveObjectAt(i); + res = GetInnerContent(node, outArrayOfNodes, &j); if (NS_FAILED(res)) return res; } } @@ -5058,17 +4987,15 @@ nsHTMLEditRules::GetNodesForOperation(nsISupportsArray *inArrayOfRanges, else if ( (inOperationType == kOutdent) || (inOperationType == kIndent) ) { - PRUint32 listCount; - (*outArrayOfNodes)->Count(&listCount); - for (i=(PRInt32)listCount-1; i>=0; i--) + PRInt32 listCount = outArrayOfNodes.Count(); + for (i=listCount-1; i>=0; i--) { - isupports = dont_AddRef((*outArrayOfNodes)->ElementAt(i)); - nsCOMPtr node( do_QueryInterface(isupports) ); + nsCOMPtr node = outArrayOfNodes[i]; if ( (nsHTMLEditUtils::IsTableElement(node) && !nsHTMLEditUtils::IsTable(node)) ) { PRInt32 j=i; - (*outArrayOfNodes)->RemoveElementAt(i); - res = GetInnerContent(node, *outArrayOfNodes, &j); + outArrayOfNodes.RemoveObjectAt(i); + res = GetInnerContent(node, outArrayOfNodes, &j); if (NS_FAILED(res)) return res; } } @@ -5076,17 +5003,15 @@ nsHTMLEditRules::GetNodesForOperation(nsISupportsArray *inArrayOfRanges, // outdent should look inside of divs. if (inOperationType == kOutdent && !useCSS) { - PRUint32 listCount; - (*outArrayOfNodes)->Count(&listCount); - for (i=(PRInt32)listCount-1; i>=0; i--) + PRInt32 listCount = outArrayOfNodes.Count(); + for (i=listCount-1; i>=0; i--) { - isupports = dont_AddRef((*outArrayOfNodes)->ElementAt(i)); - nsCOMPtr node( do_QueryInterface(isupports) ); + nsCOMPtr node = outArrayOfNodes[i]; if (nsHTMLEditUtils::IsDiv(node)) { PRInt32 j=i; - (*outArrayOfNodes)->RemoveElementAt(i); - res = GetInnerContent(node, *outArrayOfNodes, &j, PR_FALSE, PR_FALSE); + outArrayOfNodes.RemoveObjectAt(i); + res = GetInnerContent(node, outArrayOfNodes, &j, PR_FALSE, PR_FALSE); if (NS_FAILED(res)) return res; } } @@ -5101,31 +5026,19 @@ nsHTMLEditRules::GetNodesForOperation(nsISupportsArray *inArrayOfRanges, (inOperationType == kIndent) || (inOperationType == kOutdent) ) { - PRUint32 listCount; - (*outArrayOfNodes)->Count(&listCount); - for (i=(PRInt32)listCount-1; i>=0; i--) + PRInt32 listCount = outArrayOfNodes.Count(); + for (i=listCount-1; i>=0; i--) { - isupports = dont_AddRef((*outArrayOfNodes)->ElementAt(i)); - nsCOMPtr node( do_QueryInterface(isupports) ); + nsCOMPtr node = outArrayOfNodes[i]; if (!aDontTouchContent && IsInlineNode(node) && mHTMLEditor->IsContainer(node) && !mHTMLEditor->IsTextNode(node)) { - nsCOMPtr arrayOfInlines; - res = BustUpInlinesAtBRs(node, address_of(arrayOfInlines)); + nsCOMArray arrayOfInlines; + res = BustUpInlinesAtBRs(node, arrayOfInlines); if (NS_FAILED(res)) return res; // put these nodes in outArrayOfNodes, replacing the current node - (*outArrayOfNodes)->RemoveElementAt((PRUint32)i); - // i sure wish nsISupportsArray had an IsEmpty() and DeleteLastElement() - // calls. For that matter, if I could just insert one nsISupportsArray - // into another at a given position, that would do everything I need here. - PRUint32 iCount; - arrayOfInlines->Count(&iCount); - while (iCount) - { - iCount--; - isupports = dont_AddRef(arrayOfInlines->ElementAt(iCount)); - (*outArrayOfNodes)->InsertElementAt(isupports, i); - } + outArrayOfNodes.RemoveObjectAt(i); + outArrayOfNodes.InsertObjectsAt(arrayOfInlines, i); } } } @@ -5139,15 +5052,12 @@ nsHTMLEditRules::GetNodesForOperation(nsISupportsArray *inArrayOfRanges, // nsresult nsHTMLEditRules::GetChildNodesForOperation(nsIDOMNode *inNode, - nsCOMPtr *outArrayOfNodes) + nsCOMArray& outArrayOfNodes) { - if (!inNode || !outArrayOfNodes) return NS_ERROR_NULL_POINTER; - - nsresult res = NS_NewISupportsArray(getter_AddRefs(*outArrayOfNodes)); - if (NS_FAILED(res)) return res; + if (!inNode) return NS_ERROR_NULL_POINTER; nsCOMPtr childNodes; - res = inNode->GetChildNodes(getter_AddRefs(childNodes)); + nsresult res = inNode->GetChildNodes(getter_AddRefs(childNodes)); if (NS_FAILED(res)) return res; if (!childNodes) return NS_ERROR_NULL_POINTER; PRUint32 childCount; @@ -5156,14 +5066,12 @@ nsHTMLEditRules::GetChildNodesForOperation(nsIDOMNode *inNode, PRUint32 i; nsCOMPtr node; - nsCOMPtr isupports; for (i = 0; i < childCount; i++) { res = childNodes->Item( i, getter_AddRefs(node)); if (!node) return NS_ERROR_FAILURE; - isupports = do_QueryInterface(node); - (*outArrayOfNodes)->AppendElement(isupports); - if (NS_FAILED(res)) return res; + if (!outArrayOfNodes.AppendObject(node)) + return NS_ERROR_FAILURE; } return res; } @@ -5174,11 +5082,10 @@ nsHTMLEditRules::GetChildNodesForOperation(nsIDOMNode *inNode, // GetListActionNodes: // nsresult -nsHTMLEditRules::GetListActionNodes(nsCOMPtr *outArrayOfNodes, +nsHTMLEditRules::GetListActionNodes(nsCOMArray &outArrayOfNodes, PRBool aEntireList, PRBool aDontTouchContent) { - if (!outArrayOfNodes) return NS_ERROR_NULL_POINTER; nsresult res = NS_OK; nsCOMPtrselection; @@ -5191,8 +5098,6 @@ nsHTMLEditRules::GetListActionNodes(nsCOMPtr *outArrayOfNodes, // is only in part of it. used by list item dialog. if (aEntireList) { - res = NS_NewISupportsArray(getter_AddRefs(*outArrayOfNodes)); - if (NS_FAILED(res)) return res; nsCOMPtr enumerator; res = selPriv->GetEnumerator(getter_AddRefs(enumerator)); if (NS_FAILED(res)) return res; @@ -5215,8 +5120,7 @@ nsHTMLEditRules::GetListActionNodes(nsCOMPtr *outArrayOfNodes, { if (nsHTMLEditUtils::IsList(parent)) { - nsCOMPtr isupports = do_QueryInterface(parent); - (*outArrayOfNodes)->AppendElement(isupports); + outArrayOfNodes.AppendObject(parent); break; } parent->GetParentNode(getter_AddRefs(tmp)); @@ -5226,12 +5130,7 @@ nsHTMLEditRules::GetListActionNodes(nsCOMPtr *outArrayOfNodes, } // if we didn't find any nodes this way, then try the normal way. perhaps the // selection spans multiple lists but with no common list parent. - if (*outArrayOfNodes) - { - PRUint32 nodeCount; - (*outArrayOfNodes)->Count(&nodeCount); - if (nodeCount) return NS_OK; - } + if (outArrayOfNodes.Count()) return NS_OK; } // contruct a list of nodes to act on. @@ -5239,18 +5138,16 @@ nsHTMLEditRules::GetListActionNodes(nsCOMPtr *outArrayOfNodes, if (NS_FAILED(res)) return res; // pre process our list of nodes... - PRUint32 listCount; + PRInt32 listCount = outArrayOfNodes.Count(); PRInt32 i; - (*outArrayOfNodes)->Count(&listCount); - for (i=(PRInt32)listCount-1; i>=0; i--) + for (i=listCount-1; i>=0; i--) { - nsCOMPtr isupports = dont_AddRef((*outArrayOfNodes)->ElementAt(i)); - nsCOMPtr testNode( do_QueryInterface(isupports ) ); + nsCOMPtr testNode = outArrayOfNodes[i]; // Remove all non-editable nodes. Leave them be. if (!mHTMLEditor->IsEditable(testNode)) { - (*outArrayOfNodes)->RemoveElementAt(i); + outArrayOfNodes.RemoveObjectAt(i); } // scan for table elements and divs. If we find table elements other than table, @@ -5258,15 +5155,15 @@ nsHTMLEditRules::GetListActionNodes(nsCOMPtr *outArrayOfNodes, if (nsHTMLEditUtils::IsTableElement(testNode) && !nsHTMLEditUtils::IsTable(testNode)) { PRInt32 j=i; - (*outArrayOfNodes)->RemoveElementAt(i); - res = GetInnerContent(testNode, *outArrayOfNodes, &j, PR_FALSE); + outArrayOfNodes.RemoveObjectAt(i); + res = GetInnerContent(testNode, outArrayOfNodes, &j, PR_FALSE); if (NS_FAILED(res)) return res; } } // if there is only one node in the array, and it is a list, div, or blockquote, // then look inside of it until we find inner list or content. - res = LookInsideDivBQandList(*outArrayOfNodes); + res = LookInsideDivBQandList(outArrayOfNodes); return res; } @@ -5275,17 +5172,15 @@ nsHTMLEditRules::GetListActionNodes(nsCOMPtr *outArrayOfNodes, // LookInsideDivBQandList: // nsresult -nsHTMLEditRules::LookInsideDivBQandList(nsISupportsArray *aNodeArray) +nsHTMLEditRules::LookInsideDivBQandList(nsCOMArray& aNodeArray) { // if there is only one node in the array, and it is a list, div, or blockquote, // then look inside of it until we find inner list or content. nsresult res = NS_OK; - PRUint32 listCount; - aNodeArray->Count(&listCount); + PRInt32 listCount = aNodeArray.Count(); if (listCount == 1) { - nsCOMPtr isupports = dont_AddRef(aNodeArray->ElementAt(0)); - nsCOMPtr curNode( do_QueryInterface(isupports) ); + nsCOMPtr curNode = aNodeArray[0]; while (nsHTMLEditUtils::IsDiv(curNode) || nsHTMLEditUtils::IsList(curNode) @@ -5313,7 +5208,7 @@ nsHTMLEditRules::LookInsideDivBQandList(nsISupportsArray *aNodeArray) } // we've found innermost list/blockquote/div: // replace the one node in the array with these nodes - aNodeArray->RemoveElementAt(0); + aNodeArray.RemoveObjectAt(0); if ((nsHTMLEditUtils::IsDiv(curNode) || nsHTMLEditUtils::IsBlockquote(curNode))) { PRInt32 j=0; @@ -5321,8 +5216,7 @@ nsHTMLEditRules::LookInsideDivBQandList(nsISupportsArray *aNodeArray) } else { - nsCOMPtr isupports (do_QueryInterface(curNode)); - aNodeArray->AppendElement(isupports); + aNodeArray.AppendObject(curNode); } } return res; @@ -5354,11 +5248,9 @@ nsHTMLEditRules::GetDefinitionListItemTypes(nsIDOMNode *aNode, PRBool &aDT, PRBo // GetParagraphFormatNodes: // nsresult -nsHTMLEditRules::GetParagraphFormatNodes(nsCOMPtr *outArrayOfNodes, +nsHTMLEditRules::GetParagraphFormatNodes(nsCOMArray& outArrayOfNodes, PRBool aDontTouchContent) -{ - if (!outArrayOfNodes) return NS_ERROR_NULL_POINTER; - +{ nsCOMPtrselection; nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); if (NS_FAILED(res)) return res; @@ -5368,18 +5260,16 @@ nsHTMLEditRules::GetParagraphFormatNodes(nsCOMPtr *outArrayOfN if (NS_FAILED(res)) return res; // pre process our list of nodes... - PRUint32 listCount; + PRInt32 listCount = outArrayOfNodes.Count(); PRInt32 i; - (*outArrayOfNodes)->Count(&listCount); - for (i=(PRInt32)listCount-1; i>=0; i--) + for (i=listCount-1; i>=0; i--) { - nsCOMPtr isupports = dont_AddRef((*outArrayOfNodes)->ElementAt(i)); - nsCOMPtr testNode( do_QueryInterface(isupports ) ); + nsCOMPtr testNode = outArrayOfNodes[i]; // Remove all non-editable nodes. Leave them be. if (!mHTMLEditor->IsEditable(testNode)) { - (*outArrayOfNodes)->RemoveElementAt(i); + outArrayOfNodes.RemoveObjectAt(i); } // scan for table elements. If we find table elements other than table, @@ -5389,8 +5279,8 @@ nsHTMLEditRules::GetParagraphFormatNodes(nsCOMPtr *outArrayOfN nsHTMLEditUtils::IsListItem(testNode) ) { PRInt32 j=i; - (*outArrayOfNodes)->RemoveElementAt(i); - res = GetInnerContent(testNode, *outArrayOfNodes, &j); + outArrayOfNodes.RemoveObjectAt(i); + res = GetInnerContent(testNode, outArrayOfNodes, &j); if (NS_FAILED(res)) return res; } } @@ -5446,32 +5336,26 @@ nsHTMLEditRules::BustUpInlinesAtRangeEndpoints(nsRangeStore &item) // nsresult nsHTMLEditRules::BustUpInlinesAtBRs(nsIDOMNode *inNode, - nsCOMPtr *outArrayOfNodes) + nsCOMArray& outArrayOfNodes) { - if (!inNode || !outArrayOfNodes) return NS_ERROR_NULL_POINTER; + if (!inNode) return NS_ERROR_NULL_POINTER; - nsresult res = NS_NewISupportsArray(getter_AddRefs(*outArrayOfNodes)); - if (NS_FAILED(res)) return res; - // first step is to build up a list of all the break nodes inside // the inline container. - nsCOMPtr arrayOfBreaks; + nsCOMArray arrayOfBreaks; nsBRNodeFunctor functor; nsDOMIterator iter; - res = iter.Init(inNode); + nsresult res = iter.Init(inNode); if (NS_FAILED(res)) return res; - res = iter.MakeList(functor, address_of(arrayOfBreaks)); + res = iter.MakeList(functor, arrayOfBreaks); if (NS_FAILED(res)) return res; // if there aren't any breaks, just put inNode itself in the array - nsCOMPtr isupports; - PRUint32 listCount; - arrayOfBreaks->Count(&listCount); + PRInt32 listCount = arrayOfBreaks.Count(); if (!listCount) { - isupports = do_QueryInterface(inNode); - (*outArrayOfNodes)->AppendElement(isupports); - if (NS_FAILED(res)) return res; + if (!outArrayOfNodes.AppendObject(inNode)) + return NS_ERROR_FAILURE; } else { @@ -5485,10 +5369,9 @@ nsHTMLEditRules::BustUpInlinesAtBRs(nsIDOMNode *inNode, PRInt32 splitOffset, resultOffset, i; inNode->GetParentNode(getter_AddRefs(inlineParentNode)); - for (i=0; i< (PRInt32)listCount; i++) + for (i=0; i< listCount; i++) { - isupports = dont_AddRef(arrayOfBreaks->ElementAt(i)); - breakNode = do_QueryInterface(isupports); + breakNode = arrayOfBreaks[i]; if (!breakNode) return NS_ERROR_NULL_POINTER; if (!splitDeepNode) return NS_ERROR_NULL_POINTER; res = nsEditor::GetNodeLocation(breakNode, address_of(splitParentNode), &splitOffset); @@ -5502,25 +5385,22 @@ nsHTMLEditRules::BustUpInlinesAtBRs(nsIDOMNode *inNode, // might not be a left node. a break might have been at the very // beginning of inline container, in which case splitnodedeep // would not actually split anything - isupports = do_QueryInterface(leftNode); - (*outArrayOfNodes)->AppendElement(isupports); - if (NS_FAILED(res)) return res; + if (!outArrayOfNodes.AppendObject(leftNode)) + return NS_ERROR_FAILURE; } // move break outside of container and also put in node list res = mHTMLEditor->MoveNode(breakNode, inlineParentNode, resultOffset); if (NS_FAILED(res)) return res; - isupports = do_QueryInterface(breakNode); - (*outArrayOfNodes)->AppendElement(isupports); - if (NS_FAILED(res)) return res; + if (!outArrayOfNodes.AppendObject(breakNode)) + return NS_ERROR_FAILURE; // now rightNode becomes the new node to split splitDeepNode = rightNode; } // now tack on remaining rightNode, if any, to the list if (rightNode) { - isupports = do_QueryInterface(rightNode); - (*outArrayOfNodes)->AppendElement(isupports); - if (NS_FAILED(res)) return res; + if (!outArrayOfNodes.AppendObject(rightNode)) + return NS_ERROR_FAILURE; } } return res; @@ -5550,10 +5430,9 @@ nsHTMLEditRules::GetHighestInlineParent(nsIDOMNode* aNode) nsresult nsHTMLEditRules::GetNodesFromPoint(DOMPoint point, PRInt32 operation, - nsCOMPtr *arrayOfNodes, + nsCOMArray &arrayOfNodes, PRBool dontTouchContent) { - if (!arrayOfNodes) return NS_ERROR_NULL_POINTER; nsresult res; // get our point @@ -5574,13 +5453,10 @@ nsHTMLEditRules::GetNodesFromPoint(DOMPoint point, if (NS_FAILED(res)) return res; // make array of ranges - nsCOMPtr arrayOfRanges; - res = NS_NewISupportsArray(getter_AddRefs(arrayOfRanges)); - if (NS_FAILED(res)) return res; + nsCOMArray arrayOfRanges; // stuff new opRange into array - nsCOMPtr isupports = do_QueryInterface(range); - arrayOfRanges->AppendElement(isupports); + arrayOfRanges.AppendObject(range); // use these ranges to contruct a list of nodes to act on. res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, operation, dontTouchContent); @@ -5595,15 +5471,15 @@ nsHTMLEditRules::GetNodesFromPoint(DOMPoint point, nsresult nsHTMLEditRules::GetNodesFromSelection(nsISelection *selection, PRInt32 operation, - nsCOMPtr *arrayOfNodes, + nsCOMArray& arrayOfNodes, PRBool dontTouchContent) { - if (!selection || !arrayOfNodes) return NS_ERROR_NULL_POINTER; + if (!selection) return NS_ERROR_NULL_POINTER; nsresult res; // promote selection ranges - nsCOMPtr arrayOfRanges; - res = GetPromotedRanges(selection, address_of(arrayOfRanges), operation); + nsCOMArray arrayOfRanges; + res = GetPromotedRanges(selection, arrayOfRanges, operation); if (NS_FAILED(res)) return res; // use these ranges to contruct a list of nodes to act on. @@ -5618,32 +5494,28 @@ nsHTMLEditRules::GetNodesFromSelection(nsISelection *selection, // don't have the same parent. // nsresult -nsHTMLEditRules::MakeTransitionList(nsISupportsArray *inArrayOfNodes, - nsVoidArray *inTransitionArray) +nsHTMLEditRules::MakeTransitionList(nsCOMArray& inArrayOfNodes, + nsVoidArray &inTransitionArray) { - if (!inArrayOfNodes || !inTransitionArray) return NS_ERROR_NULL_POINTER; - - PRUint32 listCount; - PRUint32 i; - inArrayOfNodes->Count(&listCount); + PRInt32 listCount = inArrayOfNodes.Count(); + PRInt32 i; nsVoidArray transitionList; nsCOMPtr prevElementParent; nsCOMPtr curElementParent; for (i=0; i isupports = dont_AddRef(inArrayOfNodes->ElementAt(i)); - nsCOMPtr transNode( do_QueryInterface(isupports ) ); + nsIDOMNode* transNode = inArrayOfNodes[i]; transNode->GetParentNode(getter_AddRefs(curElementParent)); if (curElementParent != prevElementParent) { // different parents, or seperated by
    : transition point - inTransitionArray->InsertElementAt((void*)PR_TRUE,i); + inTransitionArray.InsertElementAt((void*)PR_TRUE,i); } else { // same parents: these nodes grew up together - inTransitionArray->InsertElementAt((void*)PR_FALSE,i); + inTransitionArray.InsertElementAt((void*)PR_FALSE,i); } prevElementParent = curElementParent; } @@ -6031,29 +5903,26 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection, // MakeBlockquote: put the list of nodes into one or more blockquotes. // nsresult -nsHTMLEditRules::MakeBlockquote(nsISupportsArray *arrayOfNodes) +nsHTMLEditRules::MakeBlockquote(nsCOMArray& arrayOfNodes) { // the idea here is to put the nodes into a minimal number of // blockquotes. When the user blockquotes something, they expect // one blockquote. That may not be possible (for instance, if they // have two table cells selected, you need two blockquotes inside the cells). - if (!arrayOfNodes) return NS_ERROR_NULL_POINTER; nsresult res = NS_OK; nsCOMPtr curNode, curParent, curBlock, newBlock; PRInt32 offset; - PRUint32 listCount; + PRInt32 listCount = arrayOfNodes.Count(); - arrayOfNodes->Count(&listCount); nsCOMPtr prevParent; - PRUint32 i; + PRInt32 i; for (i=0; i isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - curNode = do_QueryInterface(isupports); + curNode = arrayOfNodes[i]; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); if (NS_FAILED(res)) return res; @@ -6063,8 +5932,8 @@ nsHTMLEditRules::MakeBlockquote(nsISupportsArray *arrayOfNodes) { curBlock = 0; // forget any previous block // recursion time - nsCOMPtr childArray; - res = GetChildNodesForOperation(curNode, address_of(childArray)); + nsCOMArray childArray; + res = GetChildNodesForOperation(curNode, childArray); if (NS_FAILED(res)) return res; res = MakeBlockquote(childArray); if (NS_FAILED(res)) return res; @@ -6113,27 +5982,23 @@ nsHTMLEditRules::MakeBlockquote(nsISupportsArray *arrayOfNodes) // RemoveBlockStyle: make the nodes have no special block type. // nsresult -nsHTMLEditRules::RemoveBlockStyle(nsISupportsArray *arrayOfNodes) +nsHTMLEditRules::RemoveBlockStyle(nsCOMArray& arrayOfNodes) { // intent of this routine is to be used for converting to/from // headers, paragraphs, pre, and address. Those blocks // that pretty much just contain inline things... - if (!arrayOfNodes) return NS_ERROR_NULL_POINTER; nsresult res = NS_OK; nsCOMPtr curNode, curParent, curBlock, firstNode, lastNode; PRInt32 offset; - PRUint32 listCount; + PRInt32 listCount = arrayOfNodes.Count(); - arrayOfNodes->Count(&listCount); - - PRUint32 i; + PRInt32 i; for (i=0; i isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - curNode = do_QueryInterface(isupports); + curNode = arrayOfNodes[i]; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); if (NS_FAILED(res)) return res; nsAutoString curNodeTag, curBlockTag; @@ -6181,8 +6046,8 @@ nsHTMLEditRules::RemoveBlockStyle(nsISupportsArray *arrayOfNodes) curBlock = 0; firstNode = 0; lastNode = 0; } // recursion time - nsCOMPtr childArray; - res = GetChildNodesForOperation(curNode, address_of(childArray)); + nsCOMArray childArray; + res = GetChildNodesForOperation(curNode, childArray); if (NS_FAILED(res)) return res; res = RemoveBlockStyle(childArray); if (NS_FAILED(res)) return res; @@ -6254,42 +6119,38 @@ nsHTMLEditRules::RemoveBlockStyle(nsISupportsArray *arrayOfNodes) // one or more blocks of type blockTag. // nsresult -nsHTMLEditRules::ApplyBlockStyle(nsISupportsArray *arrayOfNodes, const nsAString *aBlockTag) +nsHTMLEditRules::ApplyBlockStyle(nsCOMArray& arrayOfNodes, const nsAString *aBlockTag) { // intent of this routine is to be used for converting to/from // headers, paragraphs, pre, and address. Those blocks // that pretty much just contain inline things... - if (!arrayOfNodes || !aBlockTag) return NS_ERROR_NULL_POINTER; + if (!aBlockTag) return NS_ERROR_NULL_POINTER; nsresult res = NS_OK; nsCOMPtr curNode, curParent, curBlock, newBlock; PRInt32 offset; - PRUint32 listCount; + PRInt32 listCount = arrayOfNodes.Count(); nsString tString(*aBlockTag);////MJUDGE SCC NEED HELP // Remove all non-editable nodes. Leave them be. PRInt32 j; - arrayOfNodes->Count(&listCount); for (j=listCount-1; j>=0; j--) { - nsCOMPtr isupports = dont_AddRef(arrayOfNodes->ElementAt(j)); - nsCOMPtr testNode( do_QueryInterface(isupports ) ); - if (!mHTMLEditor->IsEditable(testNode)) + if (!mHTMLEditor->IsEditable(arrayOfNodes[j])) { - arrayOfNodes->RemoveElementAt(j); + arrayOfNodes.RemoveObjectAt(j); } } // reset list count - arrayOfNodes->Count(&listCount); + listCount = arrayOfNodes.Count(); - PRUint32 i; + PRInt32 i; for (i=0; i isupports = dont_AddRef(arrayOfNodes->ElementAt(i)); - curNode = do_QueryInterface(isupports); + curNode = arrayOfNodes[i]; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); if (NS_FAILED(res)) return res; nsAutoString curNodeTag; @@ -6334,11 +6195,10 @@ nsHTMLEditRules::ApplyBlockStyle(nsISupportsArray *arrayOfNodes, const nsAString { curBlock = 0; // forget any previous block used for previous inline nodes // recursion time - nsCOMPtr childArray; - res = GetChildNodesForOperation(curNode, address_of(childArray)); + nsCOMArray childArray; + res = GetChildNodesForOperation(curNode, childArray); if (NS_FAILED(res)) return res; - PRUint32 childCount; - childArray->Count(&childCount); + PRInt32 childCount = childArray.Count(); if (childCount) { res = ApplyBlockStyle(childArray, aBlockTag); @@ -6582,21 +6442,20 @@ nsHTMLEditRules::GetTopEnclosingMailCite(nsIDOMNode *aNode, nsresult nsHTMLEditRules::AdjustSpecialBreaks(PRBool aSafeToAskFrames) { - nsCOMPtr arrayOfNodes; + nsCOMArray arrayOfNodes; nsCOMPtr isupports; - PRUint32 nodeCount,j; + PRInt32 nodeCount,j; // gather list of empty nodes nsEmptyFunctor functor(mHTMLEditor); nsDOMIterator iter; nsresult res = iter.Init(mDocChangeRange); if (NS_FAILED(res)) return res; - res = iter.MakeList(functor, address_of(arrayOfNodes)); + res = iter.MakeList(functor, arrayOfNodes); if (NS_FAILED(res)) return res; // put moz-br's into these empty li's and td's - res = arrayOfNodes->Count(&nodeCount); - if (NS_FAILED(res)) return res; + nodeCount = arrayOfNodes.Count(); for (j = 0; j < nodeCount; j++) { // need to put br at END of node. It may have @@ -6604,9 +6463,8 @@ nsHTMLEditRules::AdjustSpecialBreaks(PRBool aSafeToAskFrames) // and we want the br's to be after them. Also, we want the br // to be after the selection if the selection is in this node. PRUint32 len; - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - nsCOMPtr brNode, theNode( do_QueryInterface(isupports ) ); - arrayOfNodes->RemoveElementAt(0); + nsCOMPtr brNode, theNode = arrayOfNodes[0]; + arrayOfNodes.RemoveObjectAt(0); res = nsEditor::GetLengthOfDOMNode(theNode, len); if (NS_FAILED(res)) return res; res = CreateMozBR(theNode, (PRInt32)len, address_of(brNode)); @@ -6993,9 +6851,9 @@ nsresult nsHTMLEditRules::RemoveEmptyNodes() { nsCOMPtr iter; - nsCOMPtr arrayOfEmptyNodes, arrayOfEmptyCites; + nsCOMArray arrayOfEmptyNodes, arrayOfEmptyCites; nsCOMPtr isupports; - PRUint32 nodeCount,j; + PRInt32 nodeCount,j; // some general notes on the algorithm used here: the goal is to examine all the // nodes in mDocChangeRange, and remove the empty ones. We do this by using a @@ -7019,17 +6877,11 @@ nsHTMLEditRules::RemoveEmptyNodes() // some children of a node while excluding others. Thus I could find all the // _examined_ children empty, but still not have an empty parent. - // make an isupportsArray to hold a list of nodes, and a seperate list for empty mailcites - nsresult res = NS_NewISupportsArray(getter_AddRefs(arrayOfEmptyNodes)); - if (NS_FAILED(res)) return res; - res = NS_NewISupportsArray(getter_AddRefs(arrayOfEmptyCites)); - if (NS_FAILED(res)) return res; - // need an iterator iter = do_CreateInstance(kContentIteratorCID); if (!iter) return NS_ERROR_NULL_POINTER; - res = iter->Init(mDocChangeRange); + nsresult res = iter->Init(mDocChangeRange); if (NS_FAILED(res)) return res; nsVoidArray skipList; @@ -7113,15 +6965,11 @@ nsHTMLEditRules::RemoveEmptyNodes() { if (bIsMailCite) // mailcites go on a seperate list from other empty nodes { - isupports = do_QueryInterface(node); - if (!isupports) return NS_ERROR_NULL_POINTER; - arrayOfEmptyCites->AppendElement(isupports); + arrayOfEmptyCites.AppendObject(node); } else { - isupports = do_QueryInterface(node); - if (!isupports) return NS_ERROR_NULL_POINTER; - arrayOfEmptyNodes->AppendElement(isupports); + arrayOfEmptyNodes.AppendObject(node); } } } @@ -7137,26 +6985,22 @@ nsHTMLEditRules::RemoveEmptyNodes() } // now delete the empty nodes - res = arrayOfEmptyNodes->Count(&nodeCount); - if (NS_FAILED(res)) return res; + nodeCount = arrayOfEmptyNodes.Count(); for (j = 0; j < nodeCount; j++) { - isupports = dont_AddRef(arrayOfEmptyNodes->ElementAt(0)); - nsCOMPtr delNode( do_QueryInterface(isupports ) ); - arrayOfEmptyNodes->RemoveElementAt(0); + nsCOMPtr delNode = arrayOfEmptyNodes[0]; + arrayOfEmptyNodes.RemoveObjectAt(0); res = mHTMLEditor->DeleteNode(delNode); if (NS_FAILED(res)) return res; } // now delete the empty mailcites // this is a seperate step because we want to pull out any br's and preserve them. - res = arrayOfEmptyCites->Count(&nodeCount); - if (NS_FAILED(res)) return res; + nodeCount = arrayOfEmptyCites.Count(); for (j = 0; j < nodeCount; j++) { - isupports = dont_AddRef(arrayOfEmptyCites->ElementAt(0)); - nsCOMPtr delNode( do_QueryInterface(isupports ) ); - arrayOfEmptyCites->RemoveElementAt(0); + nsCOMPtr delNode = arrayOfEmptyCites[0]; + arrayOfEmptyCites.RemoveObjectAt(0); PRBool bIsEmptyNode; res = mHTMLEditor->IsEmptyNode(delNode, &bIsEmptyNode, PR_FALSE, PR_TRUE); if (NS_FAILED(res)) return res; @@ -7255,23 +7099,18 @@ nsHTMLEditRules::IsEmptyInline(nsIDOMNode *aNode) PRBool -nsHTMLEditRules::ListIsEmptyLine(nsISupportsArray *arrayOfNodes) +nsHTMLEditRules::ListIsEmptyLine(nsCOMArray &arrayOfNodes) { // we have a list of nodes which we are candidates for being moved // into a new block. Determine if it's anything more than a blank line. // Look for editable content above and beyond one single BR. - if (!arrayOfNodes) return PR_TRUE; - PRUint32 listCount; - arrayOfNodes->Count(&listCount); + PRInt32 listCount = arrayOfNodes.Count(); if (!listCount) return PR_TRUE; nsCOMPtr somenode; - nsCOMPtr isupports; PRInt32 j, brCount=0; - arrayOfNodes->Count(&listCount); for (j = 0; j < listCount; j++) { - isupports = dont_AddRef(arrayOfNodes->ElementAt(j)); - somenode = do_QueryInterface(isupports); + somenode = arrayOfNodes[j]; if (somenode && mHTMLEditor->IsEditable(somenode)) { if (nsTextEditUtils::IsBreak(somenode)) diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.h b/mozilla/editor/libeditor/html/nsHTMLEditRules.h index 1944732edd8..0ba76506e2d 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditRules.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.h @@ -43,12 +43,11 @@ #include "nsTextEditRules.h" #include "nsIHTMLEditRules.h" #include "nsIEditActionListener.h" -#include "nsISupportsArray.h" +#include "nsCOMArray.h" #include "nsCOMPtr.h" #include "nsString.h" #include "nsEditorUtils.h" -class nsISupportsArray; class nsVoidArray; class nsIDOMElement; class nsIEditor; @@ -152,9 +151,10 @@ protected: nsresult AlignInnerBlocks(nsIDOMNode *aNode, const nsAString *alignType); nsresult AlignBlockContents(nsIDOMNode *aNode, const nsAString *alignType); PRBool IsFormatNode(nsIDOMNode *aNode); - nsresult AppendInnerFormatNodes(nsISupportsArray *aArray, nsIDOMNode *aNode); + nsresult AppendInnerFormatNodes(nsCOMArray& aArray, + nsIDOMNode *aNode); nsresult GetFormatString(nsIDOMNode *aNode, nsAString &outFormat); - nsresult GetInnerContent(nsIDOMNode *aNode, nsISupportsArray *outArrayOfNodes, PRInt32 *aIndex, PRBool aList = PR_TRUE, PRBool aTble = PR_TRUE); + nsresult GetInnerContent(nsIDOMNode *aNode, nsCOMArray& outArrayOfNodes, PRInt32 *aIndex, PRBool aList = PR_TRUE, PRBool aTble = PR_TRUE); nsCOMPtr IsInListItem(nsIDOMNode *aNode); nsresult ReturnInHeader(nsISelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, PRInt32 aOffset); nsresult ReturnInParagraph(nsISelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, PRInt32 aOffset, PRBool *aCancel, PRBool *aHandled); @@ -193,36 +193,36 @@ protected: nsresult GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt32 aOffset, PRInt32 actionID, nsCOMPtr *outNode, PRInt32 *outOffset); nsresult GetPromotedRanges(nsISelection *inSelection, - nsCOMPtr *outArrayOfRanges, + nsCOMArray &outArrayOfRanges, PRInt32 inOperationType); nsresult PromoteRange(nsIDOMRange *inRange, PRInt32 inOperationType); - nsresult GetNodesForOperation(nsISupportsArray *inArrayOfRanges, - nsCOMPtr *outArrayOfNodes, + nsresult GetNodesForOperation(nsCOMArray& inArrayOfRanges, + nsCOMArray& outArrayOfNodes, PRInt32 inOperationType, PRBool aDontTouchContent=PR_FALSE); nsresult GetChildNodesForOperation(nsIDOMNode *inNode, - nsCOMPtr *outArrayOfNodes); + nsCOMArray& outArrayOfNodes); nsresult GetNodesFromPoint(DOMPoint point, PRInt32 operation, - nsCOMPtr *arrayOfNodes, + nsCOMArray& arrayOfNodes, PRBool dontTouchContent); nsresult GetNodesFromSelection(nsISelection *selection, - PRInt32 operation, - nsCOMPtr *arrayOfNodes, - PRBool aDontTouchContent=PR_FALSE); - nsresult GetListActionNodes(nsCOMPtr *outArrayOfNodes, PRBool aEntireList, PRBool aDontTouchContent=PR_FALSE); + PRInt32 operation, + nsCOMArray& arrayOfNodes, + PRBool aDontTouchContent=PR_FALSE); + nsresult GetListActionNodes(nsCOMArray &outArrayOfNodes, PRBool aEntireList, PRBool aDontTouchContent=PR_FALSE); nsresult GetDefinitionListItemTypes(nsIDOMNode *aNode, PRBool &aDT, PRBool &aDD); - nsresult GetParagraphFormatNodes(nsCOMPtr *outArrayOfNodes, PRBool aDontTouchContent=PR_FALSE); - nsresult LookInsideDivBQandList(nsISupportsArray *aNodeArray); + nsresult GetParagraphFormatNodes(nsCOMArray& outArrayOfNodes, PRBool aDontTouchContent=PR_FALSE); + nsresult LookInsideDivBQandList(nsCOMArray& aNodeArray); nsresult BustUpInlinesAtRangeEndpoints(nsRangeStore &inRange); nsresult BustUpInlinesAtBRs(nsIDOMNode *inNode, - nsCOMPtr *outArrayOfNodes); + nsCOMArray& outArrayOfNodes); nsCOMPtr GetHighestInlineParent(nsIDOMNode* aNode); - nsresult MakeTransitionList(nsISupportsArray *inArrayOfNodes, - nsVoidArray *inTransitionArray); - nsresult RemoveBlockStyle(nsISupportsArray *arrayOfNodes); - nsresult ApplyBlockStyle(nsISupportsArray *arrayOfNodes, const nsAString *aBlockTag); - nsresult MakeBlockquote(nsISupportsArray *arrayOfNodes); + nsresult MakeTransitionList(nsCOMArray& inArrayOfNodes, + nsVoidArray &inTransitionArray); + nsresult RemoveBlockStyle(nsCOMArray& arrayOfNodes); + nsresult ApplyBlockStyle(nsCOMArray& arrayOfNodes, const nsAString *aBlockTag); + nsresult MakeBlockquote(nsCOMArray& arrayOfNodes); nsresult SplitAsNeeded(const nsAString *aTag, nsCOMPtr *inOutParent, PRInt32 *inOutOffset); nsresult AddTerminatingBR(nsIDOMNode *aBlock); nsresult JoinNodesSmart( nsIDOMNode *aNodeLeft, @@ -248,7 +248,7 @@ protected: nsresult ConfirmSelectionInBody(); nsresult InsertMozBRIfNeeded(nsIDOMNode *aNode); PRBool IsEmptyInline(nsIDOMNode *aNode); - PRBool ListIsEmptyLine(nsISupportsArray *arrayOfNodes); + PRBool ListIsEmptyLine(nsCOMArray &arrayOfNodes); nsresult RemoveAlignment(nsIDOMNode * aNode, const nsAString & aAlignType, PRBool aChildrenOnly); nsresult MakeSureElemStartsOrEndsOnCR(nsIDOMNode *aNode, PRBool aStarts); nsresult MakeSureElemStartsOrEndsOnCR(nsIDOMNode *aNode); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index 0408bea6ab5..6d2fb483608 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -865,9 +865,9 @@ nsHTMLEditor::GetBlockSection(nsIDOMNode *aChild, // this range nsresult nsHTMLEditor::GetBlockSectionsForRange(nsIDOMRange *aRange, - nsISupportsArray *aSections) + nsCOMArray& aSections) { - if (!aRange || !aSections) {return NS_ERROR_NULL_POINTER;} + if (!aRange) {return NS_ERROR_NULL_POINTER;} nsresult result; nsCOMPtriter; @@ -887,9 +887,9 @@ nsHTMLEditor::GetBlockSectionsForRange(nsIDOMRange *aRange, nsCOMPtr currentContentTag; currentContent->GetTag(*getter_AddRefs(currentContentTag)); //
    divides block content ranges. We can achieve this by nulling out lastRange - if (nsIEditProperty::br==currentContentTag.get()) + if (nsIEditProperty::br==currentContentTag) { - lastRange = do_QueryInterface(nsnull); + lastRange = nsnull; } else { @@ -945,7 +945,7 @@ nsHTMLEditor::GetBlockSectionsForRange(nsIDOMRange *aRange, { // initialize the range range->SetStart(leftNode, 0); range->SetEnd(rightNode, 0); - aSections->AppendElement(range); + aSections.AppendObject(range); lastRange = do_QueryInterface(range); } } @@ -989,7 +989,7 @@ nsHTMLEditor::NextNodeInBlock(nsIDOMNode *aNode, IterDirection aDir) PRBool isBlock; if (NS_SUCCEEDED(NodeIsBlockStatic(aNode, &isBlock)) && isBlock) { - blockParent = do_QueryInterface(aNode); + blockParent = aNode; } else { @@ -2188,15 +2188,11 @@ nsHTMLEditor::GetParentBlockTags(nsStringArray *aTagList, PRBool aGetLists) nsCOMPtr range( do_QueryInterface(currentItem) ); // scan the range for all the independent block content blockSections // and get the block parent of each - nsISupportsArray *blockSections; - res = NS_NewISupportsArray(&blockSections); - if (NS_FAILED(res)) return res; - if (!blockSections) return NS_ERROR_NULL_POINTER; + nsCOMArray blockSections; res = GetBlockSectionsForRange(range, blockSections); if (NS_SUCCEEDED(res)) { - nsIDOMRange *subRange; - subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); + nsCOMPtr subRange = blockSections[0]; while (subRange) { nsCOMPtrstartParent; @@ -2224,14 +2220,14 @@ nsHTMLEditor::GetParentBlockTags(nsStringArray *aTagList, PRBool aGetLists) } } } - NS_RELEASE(subRange); if (NS_FAILED(res)) - break; // don't return here, need to release blockSections - blockSections->RemoveElementAt(0); - subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); + return res; + blockSections.RemoveObject(0); + if (blockSections.Count() == 0) + break; + subRange = blockSections[0]; } } - NS_RELEASE(blockSections); } return res; } @@ -3719,41 +3715,25 @@ nsHTMLEditor::EnableExistingStyleSheet(const nsAString &aURL) return PR_FALSE; } -nsresult -nsHTMLEditor::EnsureStyleSheetArrays() -{ - nsresult rv = NS_OK; - if (!mStyleSheets) - rv = NS_NewISupportsArray(getter_AddRefs(mStyleSheets)); - - return rv; -} - nsresult nsHTMLEditor::AddNewStyleSheetToList(const nsAString &aURL, nsICSSStyleSheet *aStyleSheet) { - PRUint32 countSS; - nsresult rv = mStyleSheets->Count(&countSS); - NS_ENSURE_SUCCESS(rv, rv); - + PRInt32 countSS = mStyleSheets.Count(); PRInt32 countU = mStyleSheetURLs.Count(); - if (countU < 0 || countSS != (PRUint32)countU) + if (countU < 0 || countSS != countU) return NS_ERROR_UNEXPECTED; if (!mStyleSheetURLs.AppendString(aURL)) return NS_ERROR_UNEXPECTED; - return mStyleSheets->AppendElement(aStyleSheet); + return mStyleSheets.AppendObject(aStyleSheet) ? NS_OK : NS_ERROR_UNEXPECTED; } nsresult nsHTMLEditor::RemoveStyleSheetFromList(const nsAString &aURL) { - nsresult rv = EnsureStyleSheetArrays(); - NS_ENSURE_SUCCESS(rv, rv); - // is it already in the list? PRInt32 foundIndex; foundIndex = mStyleSheetURLs.IndexOf(aURL); @@ -3761,7 +3741,8 @@ nsHTMLEditor::RemoveStyleSheetFromList(const nsAString &aURL) return NS_ERROR_FAILURE; // Attempt both removals; if one fails there's not much we can do. - if (!mStyleSheets->RemoveElementAt(foundIndex)) + nsresult rv = NS_OK; + if (!mStyleSheets.RemoveObjectAt(foundIndex)) rv = NS_ERROR_FAILURE; if (!mStyleSheetURLs.RemoveStringAt(foundIndex)) rv = NS_ERROR_FAILURE; @@ -3775,8 +3756,6 @@ nsHTMLEditor::GetStyleSheetForURL(const nsAString &aURL, { NS_ENSURE_ARG_POINTER(aStyleSheet); *aStyleSheet = 0; - nsresult rv = EnsureStyleSheetArrays(); - NS_ENSURE_SUCCESS(rv, rv); // is it already in the list? PRInt32 foundIndex; @@ -3784,11 +3763,12 @@ nsHTMLEditor::GetStyleSheetForURL(const nsAString &aURL, if (foundIndex < 0) return NS_OK; //No sheet -- don't fail! - *aStyleSheet = (nsICSSStyleSheet*)mStyleSheets->ElementAt(foundIndex); + *aStyleSheet = mStyleSheets[foundIndex]; if (!*aStyleSheet) return NS_ERROR_FAILURE; NS_ADDREF(*aStyleSheet); + return NS_OK; } @@ -3796,16 +3776,8 @@ NS_IMETHODIMP nsHTMLEditor::GetURLForStyleSheet(nsICSSStyleSheet *aStyleSheet, nsAString &aURL) { - nsresult rv = EnsureStyleSheetArrays(); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr iSupports = do_QueryInterface(aStyleSheet, &rv); - NS_ENSURE_SUCCESS(rv, rv); - // is it already in the list? - PRInt32 foundIndex; - rv = mStyleSheets->GetIndexOf(iSupports, &foundIndex); - NS_ENSURE_SUCCESS(rv, rv); + PRInt32 foundIndex = mStyleSheets.IndexOf(aStyleSheet); // Don't fail if we don't find it in our list if (foundIndex == -1) @@ -5659,15 +5631,10 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) if (NS_FAILED(res)) return res; if (!iter) return NS_ERROR_FAILURE; - nsCOMPtr arrayOfNodes; + nsCOMArray arrayOfNodes; nsCOMPtr content; nsCOMPtr node; - nsCOMPtr isupports; - - // make a array - res = NS_NewISupportsArray(getter_AddRefs(arrayOfNodes)); - if (NS_FAILED(res)) return res; - + // iterate range and build up array res = iter->Init(range); // init returns an error if no nodes in range. @@ -5683,9 +5650,8 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) node = do_QueryInterface(content); if (!node) return NS_ERROR_FAILURE; if (IsEditable(node)) - { - isupports = do_QueryInterface(node); - arrayOfNodes->AppendElement(isupports); + { + arrayOfNodes.AppendObject(node); } res = iter->Next(); if (NS_FAILED(res)) return res; @@ -5709,13 +5675,11 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) } // then loop through the list, set the property on each node - PRUint32 listCount; - PRUint32 j; - arrayOfNodes->Count(&listCount); + PRInt32 listCount = arrayOfNodes.Count(); + PRInt32 j; for (j = 0; j < listCount; j++) { - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - node = do_QueryInterface(isupports); + node = arrayOfNodes[j]; // do we have a block here ? PRBool isBlock =PR_FALSE; res = NodeIsBlockStatic(node, &isBlock); @@ -5734,8 +5698,8 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(element, nsnull, &bgcolor, &aColor, &count, PR_FALSE); if (NS_FAILED(res)) return res; } - arrayOfNodes->RemoveElementAt(0); } + arrayOfNodes.Clear(); // last check the end parent of the range to see if it needs to // be seperately handled (it does if it's a text node, due to how the diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h index 403561aeff2..22bd223236e 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h @@ -41,7 +41,7 @@ #define nsHTMLEditor_h__ #include "nsCOMPtr.h" - +#include "nsCOMArray.h" #include "nsPlaintextEditor.h" #include "nsIEditor.h" #include "nsIHTMLEditor.h" @@ -341,7 +341,7 @@ public: * @param aSections Allocated storage for the resulting set, stored as nsIDOMRanges. */ static nsresult GetBlockSectionsForRange(nsIDOMRange *aRange, - nsISupportsArray *aSections); + nsCOMArray& aSections); static nsCOMPtr NextNodeInBlock(nsIDOMNode *aNode, IterDirection aDir); nsresult IsNextCharWhitespace(nsIDOMNode *aParentNode, @@ -469,7 +469,6 @@ public: PRBool EnableExistingStyleSheet(const nsAString& aURL); // Dealing with the internal style sheet lists: - nsresult EnsureStyleSheetArrays(); NS_IMETHOD GetStyleSheetForURL(const nsAString &aURL, nsICSSStyleSheet **_retval); NS_IMETHOD GetURLForStyleSheet(nsICSSStyleSheet *aStyleSheet, nsAString &aURL); @@ -664,24 +663,24 @@ protected: PRInt32 *outRangeStartHint, PRInt32 *outRangeEndHint); nsresult CreateListOfNodesToPaste(nsIDOMNode *aFragmentAsNode, - nsCOMPtr *outNodeList, + nsCOMArray& outNodeList, PRInt32 aRangeStartHint, PRInt32 aRangeEndHint); nsresult GetListAndTableParents( PRBool aEnd, - nsISupportsArray *aListOfNodes, - nsCOMPtr *outArray); - nsresult DiscoverPartialListsAndTables( nsISupportsArray *aPasteNodes, - nsISupportsArray *aListsAndTables, - PRInt32 *outHighWaterMark); + nsCOMArray& aListOfNodes, + nsCOMArray& outArray); + nsresult DiscoverPartialListsAndTables(nsCOMArray& aPasteNodes, + nsCOMArray& aListsAndTables, + PRInt32 *outHighWaterMark); nsresult ScanForListAndTableStructure(PRBool aEnd, - nsISupportsArray *aNodes, + nsCOMArray& aNodes, nsIDOMNode *aListOrTable, nsCOMPtr *outReplaceNode); nsresult ReplaceOrphanedStructure( PRBool aEnd, - nsISupportsArray *aNodeArray, - nsISupportsArray *aListAndTableArray, + nsCOMArray& aNodeArray, + nsCOMArray& aListAndTableArray, PRInt32 aHighWaterMark); - nsISupports* GetArrayEndpoint(PRBool aEnd, nsISupportsArray *aNodeArray); + nsIDOMNode* GetArrayEndpoint(PRBool aEnd, nsCOMArray& aNodeArray); /** simple utility to handle any error with event listener allocation or registration */ void HandleEventListenerError(); @@ -815,7 +814,7 @@ protected: // Maintain a list of associated style sheets and their urls. nsStringArray mStyleSheetURLs; - nsCOMPtr mStyleSheets; + nsCOMArray mStyleSheets; PRInt32 mNumStyleSheets; // Maintain a static parser service ... diff --git a/mozilla/editor/libeditor/html/nsHTMLEditorStyle.cpp b/mozilla/editor/libeditor/html/nsHTMLEditorStyle.cpp index 47528ae5350..982feaa2220 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditorStyle.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditorStyle.cpp @@ -225,14 +225,9 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, if (NS_FAILED(res)) return res; if (!iter) return NS_ERROR_FAILURE; - nsCOMPtr arrayOfNodes; + nsCOMArray arrayOfNodes; nsCOMPtr content; nsCOMPtr node; - nsCOMPtr isupports; - - // make a array - res = NS_NewISupportsArray(getter_AddRefs(arrayOfNodes)); - if (NS_FAILED(res)) return res; // iterate range and build up array res = iter->Init(range); @@ -250,8 +245,7 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, if (!node) return NS_ERROR_FAILURE; if (IsEditable(node)) { - isupports = do_QueryInterface(node); - arrayOfNodes->AppendElement(isupports); + arrayOfNodes.AppendObject(node); } res = iter->Next(); if (NS_FAILED(res)) return res; @@ -272,17 +266,15 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, } // then loop through the list, set the property on each node - PRUint32 listCount; - PRUint32 j; - arrayOfNodes->Count(&listCount); + PRInt32 listCount = arrayOfNodes.Count(); + PRInt32 j; for (j = 0; j < listCount; j++) { - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - node = do_QueryInterface(isupports); + node = arrayOfNodes[j]; res = SetInlinePropertyOnNode(node, aProperty, &aAttribute, &aValue); if (NS_FAILED(res)) return res; - arrayOfNodes->RemoveElementAt(0); } + arrayOfNodes.Clear(); // last check the end parent of the range to see if it needs to // be seperately handled (it does if it's a text node, due to how the @@ -500,13 +492,8 @@ nsHTMLEditor::SetInlinePropertyOnNode( nsIDOMNode *aNode, childNodes->GetLength(&childCount); if (childCount) { - nsCOMPtr arrayOfNodes; + nsCOMArray arrayOfNodes; nsCOMPtr node; - nsCOMPtr isupports; - - // make a array - res = NS_NewISupportsArray(getter_AddRefs(arrayOfNodes)); - if (NS_FAILED(res)) return res; // populate the list for (j=0 ; j < (PRInt32)childCount; j++) @@ -515,22 +502,19 @@ nsHTMLEditor::SetInlinePropertyOnNode( nsIDOMNode *aNode, res = childNodes->Item(j, getter_AddRefs(childNode)); if ((NS_SUCCEEDED(res)) && (childNode) && IsEditable(childNode)) { - isupports = do_QueryInterface(childNode); - arrayOfNodes->AppendElement(isupports); + arrayOfNodes.AppendObject(childNode); } } // then loop through the list, set the property on each node - PRUint32 listCount; - arrayOfNodes->Count(&listCount); - for (j = 0; j < (PRInt32)listCount; j++) + PRInt32 listCount = arrayOfNodes.Count(); + for (j = 0; j < listCount; j++) { - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - node = do_QueryInterface(isupports); + node = arrayOfNodes[j]; res = SetInlinePropertyOnNode(node, aProperty, aAttribute, aValue); if (NS_FAILED(res)) return res; - arrayOfNodes->RemoveElementAt(0); } + arrayOfNodes.Clear(); } } return res; @@ -1340,14 +1324,9 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr if (NS_FAILED(res)) return res; if (!iter) return NS_ERROR_FAILURE; - nsCOMPtr arrayOfNodes; + nsCOMArray arrayOfNodes; nsCOMPtr content; nsCOMPtr node; - nsCOMPtr isupports; - - // make a array - res = NS_NewISupportsArray(getter_AddRefs(arrayOfNodes)); - if (NS_FAILED(res)) return res; // iterate range and build up array iter->Init(range); @@ -1359,21 +1338,18 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr if (!node) return NS_ERROR_FAILURE; if (IsEditable(node)) { - isupports = do_QueryInterface(node); - arrayOfNodes->AppendElement(isupports); + arrayOfNodes.AppendObject(node); } res = iter->Next(); if (NS_FAILED(res)) return res; } // loop through the list, remove the property on each node - PRUint32 listCount; - PRUint32 j; - arrayOfNodes->Count(&listCount); + PRInt32 listCount = arrayOfNodes.Count(); + PRInt32 j; for (j = 0; j < listCount; j++) { - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - node = do_QueryInterface(isupports); + node = arrayOfNodes[j]; res = RemoveStyleInside(node, aProperty, aAttribute); if (NS_FAILED(res)) return res; if (useCSS && mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)) { @@ -1398,8 +1374,8 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr } } } - arrayOfNodes->RemoveElementAt(0); } + arrayOfNodes.Clear(); } enumerator->Next(); } @@ -1529,14 +1505,9 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange) if (NS_FAILED(res)) return res; if (!iter) return NS_ERROR_FAILURE; - nsCOMPtr arrayOfNodes; + nsCOMArray arrayOfNodes; nsCOMPtr content; nsCOMPtr node; - nsCOMPtr isupports; - - // make a array - res = NS_NewISupportsArray(getter_AddRefs(arrayOfNodes)); - if (NS_FAILED(res)) return res; // iterate range and build up array res = iter->Init(range); @@ -1550,24 +1521,21 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange) if (!node) return NS_ERROR_FAILURE; if (IsEditable(node)) { - isupports = do_QueryInterface(node); - arrayOfNodes->AppendElement(isupports); + arrayOfNodes.AppendObject(node); } iter->Next(); } // now that we have the list, do the font size change on each node - PRUint32 listCount; - PRUint32 j; - arrayOfNodes->Count(&listCount); + PRInt32 listCount = arrayOfNodes.Count(); + PRInt32 j; for (j = 0; j < listCount; j++) { - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - node = do_QueryInterface(isupports); + node = arrayOfNodes[j]; res = RelativeFontChangeOnNode(aSizeChange, node); if (NS_FAILED(res)) return res; - arrayOfNodes->RemoveElementAt(0); } + arrayOfNodes.Clear(); } // now check the start and end parents of the range to see if they need to // be seperately handled (they do if they are text nodes, due to how the diff --git a/mozilla/editor/libeditor/html/nsWSRunObject.cpp b/mozilla/editor/libeditor/html/nsWSRunObject.cpp index 8e30184a74f..8bba0fab452 100644 --- a/mozilla/editor/libeditor/html/nsWSRunObject.cpp +++ b/mozilla/editor/libeditor/html/nsWSRunObject.cpp @@ -38,7 +38,6 @@ #include "nsTextFragment.h" #include "nsWSRunObject.h" -#include "nsISupportsArray.h" #include "nsIDOMNode.h" //#include "nsIModule.h" #include "nsHTMLEditor.h" @@ -88,7 +87,6 @@ mNode(aNode) ,mEndRun(nsnull) ,mHTMLEditor(aEd) { - mNodeArray = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID); GetWSNodes(); GetRuns(); } @@ -131,7 +129,6 @@ nsWSRunObject::PrepareToJoinBlocks(nsHTMLEditor *aHTMLEd, { if (!aLeftParent || !aRightParent || !aHTMLEd) return NS_ERROR_NULL_POINTER; - nsresult res = NS_OK; PRUint32 count; aHTMLEd->GetLengthOfDOMNode(aLeftParent, count); nsWSRunObject leftWSObj(aHTMLEd, aLeftParent, count); @@ -149,7 +146,6 @@ nsWSRunObject::PrepareToDeleteRange(nsHTMLEditor *aHTMLEd, { if (!aStartNode || !aEndNode || !*aStartNode || !*aEndNode || !aStartOffset || !aEndOffset || !aHTMLEd) return NS_ERROR_NULL_POINTER; - nsresult res = NS_OK; nsAutoTrackDOMPoint trackerStart(aHTMLEd->mRangeUpdater, aStartNode, aStartOffset); nsAutoTrackDOMPoint trackerEnd(aHTMLEd->mRangeUpdater, aEndNode, aEndOffset); @@ -186,7 +182,6 @@ nsWSRunObject::PrepareToSplitAcrossBlocks(nsHTMLEditor *aHTMLEd, { if (!aSplitNode || !aSplitOffset || !*aSplitNode || !aHTMLEd) return NS_ERROR_NULL_POINTER; - nsresult res = NS_OK; nsAutoTrackDOMPoint tracker(aHTMLEd->mRangeUpdater, aSplitNode, aSplitOffset); @@ -430,7 +425,7 @@ nsWSRunObject::InsertText(const nsAString& aStringToInsert, // MOOSE: don't need to convert tabs here since that is done by WillInsertText() // before we are called. Eventually, all that logic will be pushed down into // here and made more efficient. - PRInt32 j; + PRUint32 j; PRBool prevWS = PR_FALSE; for (j=0; j<=lastCharIndex; j++) { @@ -580,7 +575,7 @@ nsWSRunObject::PriorVisibleNode(nsIDOMNode *aNode, *outType = eNone; WSFragment *run; - nsresult res = FindRun(aNode, aOffset, &run, PR_FALSE); + FindRun(aNode, aOffset, &run, PR_FALSE); // is there a visible run there or earlier? while (run) @@ -635,7 +630,7 @@ nsWSRunObject::NextVisibleNode (nsIDOMNode *aNode, return NS_ERROR_NULL_POINTER; WSFragment *run; - nsresult res = FindRun(aNode, aOffset, &run, PR_TRUE); + FindRun(aNode, aOffset, &run, PR_TRUE); // is there a visible run there or later? while (run) @@ -1164,19 +1159,19 @@ nsWSRunObject::MakeSingleWSRun(PRInt16 aType) nsresult nsWSRunObject::PrependNodeToList(nsIDOMNode *aNode) { - if (!aNode || !mNodeArray) return NS_ERROR_NULL_POINTER; - nsCOMPtr isupports (do_QueryInterface(aNode)); - nsresult res = mNodeArray->InsertElementAt(isupports,0); - return res; + if (!aNode) return NS_ERROR_NULL_POINTER; + if (!mNodeArray.InsertObjectAt(aNode, 0)) + return NS_ERROR_FAILURE; + return NS_OK; } nsresult nsWSRunObject::AppendNodeToList(nsIDOMNode *aNode) { if (!aNode) return NS_ERROR_NULL_POINTER; - nsCOMPtr isupports (do_QueryInterface(aNode)); - nsresult res = mNodeArray->AppendElement(isupports); - return res; + if (!mNodeArray.AppendObject(aNode)) + return NS_ERROR_FAILURE; + return NS_OK; } nsresult @@ -1531,8 +1526,7 @@ nsWSRunObject::DeleteChars(nsIDOMNode *aStartNode, PRInt32 aStartOffset, return NS_OK; // nothing to delete nsresult res = NS_OK; - nsCOMPtr isupps(do_QueryInterface(aStartNode)); - PRInt32 idx = mNodeArray->IndexOf(isupps); + PRInt32 idx = mNodeArray.IndexOf(aStartNode); if (idx==-1) idx = 0; // if our strarting point wasn't one of our ws text nodes, // then just go through them from the beginning. nsCOMPtr node; @@ -1549,17 +1543,15 @@ nsWSRunObject::DeleteChars(nsIDOMNode *aStartNode, PRInt32 aStartOffset, } } - PRUint32 count; - mNodeArray->Count(&count); + PRInt32 count = mNodeArray.Count(); while (idx < count) { - isupps = dont_AddRef(mNodeArray->ElementAt(idx)); - node = do_QueryInterface(isupps); + node = mNodeArray[idx]; if (!node) break; // we ran out of ws nodes; must have been deleting to end if (node == aStartNode) { - textnode = do_QueryInterface(isupps); + textnode = do_QueryInterface(node); PRUint32 len; textnode->GetLength(&len); if (aStartOffsetDeleteText(textnode, 0, (PRUint32)aEndOffset); NS_ENSURE_SUCCESS(res, res); } @@ -1600,7 +1592,7 @@ nsWSRunObject::DeleteChars(nsIDOMNode *aStartNode, PRInt32 aStartOffset, { res = mHTMLEditor->DeleteNode(node); NS_ENSURE_SUCCESS(res, res); - mNodeArray->RemoveElement(isupps); + mNodeArray.RemoveObject(node); } } idx++; @@ -1614,8 +1606,7 @@ nsWSRunObject::GetCharAfter(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outPoin if (!aNode || !outPoint) return NS_ERROR_NULL_POINTER; - nsCOMPtr isupps(do_QueryInterface(aNode)); - PRInt32 idx = mNodeArray->IndexOf(isupps); + PRInt32 idx = mNodeArray.IndexOf(aNode); if (idx == -1) { // use range comparisons to get right ws node @@ -1637,8 +1628,7 @@ nsWSRunObject::GetCharBefore(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outPoi if (!aNode || !outPoint) return NS_ERROR_NULL_POINTER; - nsCOMPtr isupps(do_QueryInterface(aNode)); - PRInt32 idx = mNodeArray->IndexOf(isupps); + PRInt32 idx = mNodeArray.IndexOf(aNode); if (idx == -1) { // use range comparisons to get right ws node @@ -1663,12 +1653,11 @@ nsWSRunObject::GetCharAfter(WSPoint &aPoint, WSPoint *outPoint) outPoint->mTextNode = nsnull; outPoint->mOffset = 0; outPoint->mChar = 0; - - nsCOMPtr isupps(do_QueryInterface(aPoint.mTextNode)); - PRInt32 idx = mNodeArray->IndexOf(isupps); + + nsCOMPtr pointTextNode(do_QueryInterface(aPoint.mTextNode)); + PRInt32 idx = mNodeArray.IndexOf(pointTextNode); if (idx == -1) return NS_OK; // can't find point, but it's not an error - PRUint32 numNodes; - mNodeArray->Count(&numNodes); + PRInt32 numNodes = mNodeArray.Count(); PRInt32 len; nsresult res = aPoint.mTextNode->GetTextLength(&len); @@ -1681,9 +1670,9 @@ nsWSRunObject::GetCharAfter(WSPoint &aPoint, WSPoint *outPoint) } else if (idx < (PRInt32)(numNodes-1)) { - nsCOMPtr isupps = dont_AddRef(mNodeArray->ElementAt(idx+1)); - if (!isupps) return NS_ERROR_FAILURE; - outPoint->mTextNode = do_QueryInterface(isupps); + nsIDOMNode* node = mNodeArray[idx+1]; + if (!node) return NS_ERROR_FAILURE; + outPoint->mTextNode = do_QueryInterface(node); outPoint->mOffset = 0; outPoint->mChar = GetCharAt(outPoint->mTextNode, 0); } @@ -1701,8 +1690,8 @@ nsWSRunObject::GetCharBefore(WSPoint &aPoint, WSPoint *outPoint) outPoint->mChar = 0; nsresult res = NS_OK; - nsCOMPtr isupps(do_QueryInterface(aPoint.mTextNode)); - PRInt32 idx = mNodeArray->IndexOf(isupps); + nsCOMPtr pointTextNode(do_QueryInterface(aPoint.mTextNode)); + PRInt32 idx = mNodeArray.IndexOf(pointTextNode); if (idx == -1) return NS_OK; // can't find point, but it's not an error if (aPoint.mOffset != 0) @@ -1713,9 +1702,9 @@ nsWSRunObject::GetCharBefore(WSPoint &aPoint, WSPoint *outPoint) } else if (idx) { - nsCOMPtr isupps = dont_AddRef(mNodeArray->ElementAt(idx-1)); - if (!isupps) return NS_ERROR_FAILURE; - outPoint->mTextNode = do_QueryInterface(isupps); + nsIDOMNode* node = mNodeArray[idx-1]; + if (!node) return NS_ERROR_FAILURE; + outPoint->mTextNode = do_QueryInterface(node); PRInt32 len; res = outPoint->mTextNode->GetTextLength(&len); NS_ENSURE_SUCCESS(res, res); @@ -1923,8 +1912,8 @@ nsWSRunObject::GetWSPointAfter(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outP // Note: only to be called if aNode is not a ws node. // binary search on wsnodes - PRUint32 numNodes, curNum, lastNum; - mNodeArray->Count(&numNodes); + PRInt32 numNodes, curNum, lastNum; + numNodes = mNodeArray.Count(); if (!numNodes) return NS_OK; // do nothing if there are no nodes to search @@ -1932,7 +1921,6 @@ nsWSRunObject::GetWSPointAfter(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outP curNum = numNodes/2; lastNum = numNodes; PRInt16 cmp=0; - nsCOMPtr isupps; nsCOMPtr curNode; // begin binary search @@ -1941,8 +1929,7 @@ nsWSRunObject::GetWSPointAfter(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outP while (curNum != lastNum) { PRUint32 savedCur = curNum; - isupps = dont_AddRef(mNodeArray->ElementAt(curNum)); - curNode = do_QueryInterface(isupps); + curNode = mNodeArray[curNum]; cmp = mHTMLEditor->mRangeHelper->ComparePoints(aNode, aOffset, curNode, 0); if (cmp < 0) { @@ -1985,8 +1972,8 @@ nsWSRunObject::GetWSPointBefore(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *out // Note: only to be called if aNode is not a ws node. // binary search on wsnodes - PRUint32 numNodes, curNum, lastNum; - mNodeArray->Count(&numNodes); + PRInt32 numNodes, curNum, lastNum; + numNodes = mNodeArray.Count(); if (!numNodes) return NS_OK; // do nothing if there are no nodes to search @@ -1994,7 +1981,6 @@ nsWSRunObject::GetWSPointBefore(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *out curNum = numNodes/2; lastNum = numNodes; PRInt16 cmp=0; - nsCOMPtr isupps; nsCOMPtr curNode; // begin binary search @@ -2003,8 +1989,7 @@ nsWSRunObject::GetWSPointBefore(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *out while (curNum != lastNum) { PRUint32 savedCur = curNum; - isupps = dont_AddRef(mNodeArray->ElementAt(curNum)); - curNode = do_QueryInterface(isupps); + curNode = mNodeArray[curNum]; cmp = mHTMLEditor->mRangeHelper->ComparePoints(aNode, aOffset, curNode, 0); if (cmp < 0) { diff --git a/mozilla/editor/libeditor/html/nsWSRunObject.h b/mozilla/editor/libeditor/html/nsWSRunObject.h index 087993a4a31..71bb66fb725 100644 --- a/mozilla/editor/libeditor/html/nsWSRunObject.h +++ b/mozilla/editor/libeditor/html/nsWSRunObject.h @@ -40,9 +40,8 @@ #define __wsrunobject_h__ #include "nsCOMPtr.h" -#include "nsISupportsArray.h" #include "nsIDOMNode.h" -#include "nsISupportsArray.h" +#include "nsCOMArray.h" #include "nsITextContent.h" #include "nsIEditor.h" #include "nsEditorUtils.h" @@ -318,7 +317,7 @@ class nsWSRunObject nsCOMPtr mLastNBSPNode; // location of last nbsp in ws run, if any PRInt32 mLastNBSPOffset; // ... - nsCOMPtr mNodeArray;//the list of nodes containing ws in this run + nsCOMArray mNodeArray;//the list of nodes containing ws in this run WSFragment *mStartRun; // the first WSFragment in the run WSFragment *mEndRun; // the last WSFragment in the run, may be same as first diff --git a/mozilla/editor/libeditor/text/nsTextEditRules.cpp b/mozilla/editor/libeditor/text/nsTextEditRules.cpp index 50731a8121c..d4f1d2df296 100644 --- a/mozilla/editor/libeditor/text/nsTextEditRules.cpp +++ b/mozilla/editor/libeditor/text/nsTextEditRules.cpp @@ -1129,18 +1129,14 @@ nsTextEditRules::ReplaceNewlines(nsIDOMRange *aRange) nsCOMPtr iter; nsCOMPtr isupports; - PRUint32 nodeCount,j; - nsCOMPtr arrayOfNodes; + PRInt32 nodeCount,j; + nsCOMArray arrayOfNodes; - // make an isupportsArray to hold a list of nodes - nsresult res = NS_NewISupportsArray(getter_AddRefs(arrayOfNodes)); - if (NS_FAILED(res)) return res; - // need an iterator - res = nsComponentManager::CreateInstance(kContentIteratorCID, - nsnull, - NS_GET_IID(nsIContentIterator), - getter_AddRefs(iter)); + nsresult res = nsComponentManager::CreateInstance(kContentIteratorCID, + nsnull, + NS_GET_IID(nsIContentIterator), + getter_AddRefs(iter)); if (NS_FAILED(res)) return res; res = iter->Init(aRange); if (NS_FAILED(res)) return res; @@ -1162,8 +1158,8 @@ nsTextEditRules::ReplaceNewlines(nsIDOMRange *aRange) if (NS_FAILED(res)) return res; if (isPRE) { - isupports = do_QueryInterface(node); - arrayOfNodes->AppendElement(isupports); + nsCOMPtr data = do_QueryInterface(node); + arrayOfNodes.AppendObject(data); } } res = iter->Next(); @@ -1173,14 +1169,12 @@ nsTextEditRules::ReplaceNewlines(nsIDOMRange *aRange) // replace newlines with breaks. have to do this left to right, // since inserting the break can split the text node, and the // original node becomes the righthand node. - res = arrayOfNodes->Count(&nodeCount); - if (NS_FAILED(res)) return res; + nodeCount = arrayOfNodes.Count(); for (j = 0; j < nodeCount; j++) { - isupports = dont_AddRef(arrayOfNodes->ElementAt(0)); - nsCOMPtr brNode, theNode( do_QueryInterface(isupports) ); - nsCOMPtr textNode( do_QueryInterface(theNode) ); - arrayOfNodes->RemoveElementAt(0); + nsCOMPtr brNode; + nsCOMPtr textNode = arrayOfNodes[0]; + arrayOfNodes.RemoveObjectAt(0); // find the newline PRInt32 offset; nsAutoString tempString;