Bug 455943: outparamdel nsIPrivateTextRangeList r+sr=jst
authorTaras Glek <tglek@mozilla.com>
Thu, 09 Oct 2008 16:30:48 -0700
changeset 20235 ad837c22e1912743b56f1affe3411885568aa319
parent 20234 650e6b065018f570a56f7448304f479fb4eb3321
child 20236 98b7850b016840a123a6b5f589f9176361be925d
push idunknown
push userunknown
push dateunknown
bugs455943
milestone1.9.1b2pre
Bug 455943: outparamdel nsIPrivateTextRangeList r+sr=jst
content/events/public/nsIPrivateTextRange.h
content/events/src/nsPrivateTextRange.cpp
content/events/src/nsPrivateTextRange.h
editor/libeditor/base/IMETextTxn.cpp
editor/libeditor/base/nsEditor.cpp
--- a/content/events/public/nsIPrivateTextRange.h
+++ b/content/events/public/nsIPrivateTextRange.h
@@ -35,16 +35,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsIPrivateTextRange_h__
 #define nsIPrivateTextRange_h__
 
 #include "nsISupports.h"
 #include "nsString.h"
+#include "nsCOMPtr.h"
 
 #define NS_IPRIVATETEXTRANGE_IID \
 {0xb471ab41, 0x2a79, 0x11d3, \
 { 0x9e, 0xa4, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } } 
 
 class nsIPrivateTextRange : public nsISupports {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPRIVATETEXTRANGE_IID)
@@ -71,16 +72,16 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIPrivate
 #define NS_IPRIVATETEXTRANGELIST_IID \
 { 0x1ee9d531, 0x2a79, 0x11d3, \
 { 0x9e, 0xa4, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b} } 
 
 class nsIPrivateTextRangeList : public nsISupports {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPRIVATETEXTRANGELIST_IID)
 
-  NS_IMETHOD    GetLength(PRUint16* aLength)=0;
-  NS_IMETHOD    Item(PRUint16 aIndex, nsIPrivateTextRange** aReturn)=0;
+  NS_IMETHOD_(PRUint16) GetLength()=0;
+  NS_IMETHOD_(already_AddRefed<nsIPrivateTextRange>) Item(PRUint16 aIndex)=0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIPrivateTextRangeList,
                               NS_IPRIVATETEXTRANGELIST_IID)
 
 #endif // nsIPrivateTextRange_h__
--- a/content/events/src/nsPrivateTextRange.cpp
+++ b/content/events/src/nsPrivateTextRange.cpp
@@ -89,24 +89,24 @@ NS_METHOD nsPrivateTextRange::SetRangeTy
 
 NS_IMPL_ISUPPORTS1(nsPrivateTextRangeList, nsIPrivateTextRangeList)
 
 void nsPrivateTextRangeList::AppendTextRange(nsRefPtr<nsPrivateTextRange>& aRange)
 {
 	mList.AppendElement(aRange);
 }
 
-NS_METHOD nsPrivateTextRangeList::GetLength(PRUint16* aLength)
+NS_METHOD_(PRUint16) nsPrivateTextRangeList::GetLength()
 {
-	*aLength = static_cast<PRUint16>(mList.Length());
-	return NS_OK;
+  return static_cast<PRUint16>(mList.Length());
 }
 
-NS_METHOD nsPrivateTextRangeList::Item(PRUint16 aIndex, nsIPrivateTextRange** aReturn)
+NS_METHOD_(already_AddRefed<nsIPrivateTextRange>) nsPrivateTextRangeList::Item(PRUint16 aIndex)
 {
-	*aReturn = mList.ElementAt(aIndex);
-	if (*aReturn) {
-		NS_ADDREF(*aReturn);
-		return NS_OK;
-	}
-	return NS_ERROR_FAILURE;
+  nsRefPtr<nsPrivateTextRange> ret = mList.ElementAt(aIndex);
+  if (ret) {
+    nsPrivateTextRange *retPtr = nsnull;
+    ret.swap(retPtr);
+    return retPtr;
+  }
+  return nsnull;
 }
 
--- a/content/events/src/nsPrivateTextRange.h
+++ b/content/events/src/nsPrivateTextRange.h
@@ -69,17 +69,17 @@ protected:
 class nsPrivateTextRangeList: public nsIPrivateTextRangeList 
 {
 	NS_DECL_ISUPPORTS
 public:
 	nsPrivateTextRangeList(PRUint16 aLength) : mList(aLength) {}
 
 	void          AppendTextRange(nsRefPtr<nsPrivateTextRange>& aRange);
 
-	NS_IMETHOD    GetLength(PRUint16* aLength);
+	NS_IMETHOD_(PRUint16)    GetLength();
 
-	NS_IMETHOD    Item(PRUint16 aIndex, nsIPrivateTextRange** aReturn);
+	NS_IMETHOD_(already_AddRefed<nsIPrivateTextRange>)    Item(PRUint16 aIndex);
 protected:
 	nsTArray<nsRefPtr<nsPrivateTextRange> > mList;
 };
 
 
 #endif
--- a/editor/libeditor/base/IMETextTxn.cpp
+++ b/editor/libeditor/base/IMETextTxn.cpp
@@ -263,19 +263,17 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSe
     // run through the text range list, if any
     //
     nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
     if (!selCon) return NS_ERROR_NOT_INITIALIZED;
 
     PRUint16      textRangeListLength,selectionStart,selectionEnd,
                   textRangeType;
     
-    result = mRangeList->GetLength(&textRangeListLength);
-    if(NS_FAILED(result))
-        return result;
+    textRangeListLength = mRangeList->GetLength();
     nsCOMPtr<nsISelection> selection;
     result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
     if(NS_SUCCEEDED(result))
     {
       nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
       result = selPriv->StartBatchChanges();
       if (NS_SUCCEEDED(result))
       {
@@ -290,19 +288,19 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSe
             // we just ignore the result and clean up the next one here
           }
         }
 
         nsCOMPtr<nsIPrivateTextRange> textRange;
         PRBool setCaret=PR_FALSE;
         for(i=0;i<textRangeListLength;i++)
         {
-          result = mRangeList->Item(i, getter_AddRefs(textRange));
-          NS_ASSERTION(NS_SUCCEEDED(result), "cannot get item");
-          if(NS_FAILED(result))
+          textRange = mRangeList->Item(i);
+          NS_ASSERTION(textRange, "cannot get item");
+          if(!textRange)
                break;
 
           result = textRange->GetRangeType(&textRangeType);
           NS_ASSERTION(NS_SUCCEEDED(result), "cannot get range type");
           if(NS_FAILED(result))
                break;
 
           result = textRange->GetRangeStart(&selectionStart);
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -2541,35 +2541,35 @@ NS_IMETHODIMP nsEditor::InsertTextImpl(c
 }
 
 
 NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert, 
                                                      nsIDOMCharacterData *aTextNode, 
                                                      PRInt32 aOffset, PRBool suppressIME)
 {
   nsRefPtr<EditTxn> txn;
-  nsresult result;
+  nsresult result = NS_OK;
   // suppressIME s used when editor must insert text, yet this text is not
   // part of current ime operation.  example: adjusting whitespace around an ime insertion.
   if (mIMETextRangeList && mInIMEMode && !suppressIME)
   {
     if (!mIMETextNode)
     {
       mIMETextNode = aTextNode;
       mIMETextOffset = aOffset;
     }
     PRUint16 len ;
-    result = mIMETextRangeList->GetLength(&len);
-    if (NS_SUCCEEDED(result) && len > 0)
+    len = mIMETextRangeList->GetLength();
+    if (len > 0)
     {
       nsCOMPtr<nsIPrivateTextRange> range;
       for (PRUint16 i = 0; i < len; i++) 
       {
-        result = mIMETextRangeList->Item(i, getter_AddRefs(range));
-        if (NS_SUCCEEDED(result) && range)
+        range = mIMETextRangeList->Item(i);
+        if (range)
         {
           PRUint16 type;
           result = range->GetRangeType(&type);
           if (NS_SUCCEEDED(result)) 
           {
             if (type == nsIPrivateTextRange::TEXTRANGE_RAWINPUT) 
             {
               PRUint16 start, end;
@@ -4448,24 +4448,23 @@ nsEditor::GetIMEBufferLength(PRInt32* le
 
 void
 nsEditor::SetIsIMEComposing(){  
   // We set mIsIMEComposing according to mIMETextRangeList.
   nsCOMPtr<nsIPrivateTextRange> rangePtr;
   PRUint16 listlen, type;
 
   mIsIMEComposing = PR_FALSE;
-  nsresult result = mIMETextRangeList->GetLength(&listlen);
-  if (NS_FAILED(result)) return;
+  listlen = mIMETextRangeList->GetLength();
 
   for (PRUint16 i = 0; i < listlen; i++)
   {
-      result = mIMETextRangeList->Item(i, getter_AddRefs(rangePtr));
-      if (NS_FAILED(result)) continue;
-      result = rangePtr->GetRangeType(&type);
+      rangePtr = mIMETextRangeList->Item(i);
+      if (!rangePtr) continue;
+      nsresult result = rangePtr->GetRangeType(&type);
       if (NS_FAILED(result)) continue;
       if ( type == nsIPrivateTextRange::TEXTRANGE_RAWINPUT ||
            type == nsIPrivateTextRange::TEXTRANGE_CONVERTEDTEXT ||
            type == nsIPrivateTextRange::TEXTRANGE_SELECTEDRAWTEXT ||
            type == nsIPrivateTextRange::TEXTRANGE_SELECTEDCONVERTEDTEXT )
       {
         mIsIMEComposing = PR_TRUE;
 #ifdef DEBUG_IME