Bug 633066: Remove nsICiter and make nsInternetCiter a static class. r=ehsan
authorSebastian Kromp <46b@gulli.com>
Thu, 31 Mar 2011 07:32:13 -0400
changeset 64453 b7534c685c11affc13e1ee4d7def829d694d6d67
parent 64452 ce53f5dd0092d187b810d65fe87fe39abad96a3a
child 64454 8e9eff6c5e696f8df6fff2094e69906f61b246ea
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs633066
milestone2.2a1pre
Bug 633066: Remove nsICiter and make nsInternetCiter a static class. r=ehsan
editor/idl/Makefile.in
editor/idl/nsICiter.idl
editor/libeditor/text/nsInternetCiter.cpp
editor/libeditor/text/nsInternetCiter.h
editor/libeditor/text/nsPlaintextEditor.cpp
--- a/editor/idl/Makefile.in
+++ b/editor/idl/Makefile.in
@@ -41,17 +41,16 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= editor
 GRE_MODULE	= 1
 
 XPIDLSRCS	= \
-		nsICiter.idl \
 		nsIDocumentStateListener.idl \
 		nsIEditActionListener.idl \
 		nsIEditor.idl \
 		nsIEditorIMESupport.idl \
 		nsIEditorLogging.idl \
 		nsIEditorMailSupport.idl \
 		nsIEditorObserver.idl \
 		nsIEditorSpellCheck.idl \
deleted file mode 100644
--- a/editor/idl/nsICiter.idl
+++ /dev/null
@@ -1,61 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsISupports.idl"
-#include "domstubs.idl"
-%{C++
-#include "nsString.h"
-%}
-/** Handle plaintext citations, as in mail quoting.
-  * Used by the editor but not dependant on it.
-  */
-
-[scriptable, uuid(a6cf9102-15b3-11d2-932e-00805f8add32)]
-
-interface nsICiter  : nsISupports
-{
-
-  DOMString GetCiteString(in DOMString aInString);
-
-  DOMString StripCites(in DOMString  aInString);
-
-  DOMString Rewrap(in DOMString aInString,
-                    in unsigned long aWrapCol, in unsigned long aFirstLineOffset,
-                    in boolean aRespectNewlines);
-};
-
-
--- a/editor/libeditor/text/nsInternetCiter.cpp
+++ b/editor/libeditor/text/nsInternetCiter.cpp
@@ -53,28 +53,17 @@ const PRUnichar gt ('>');
 const PRUnichar space (' ');
 const PRUnichar nbsp (0xa0);
 const PRUnichar nl ('\n');
 const PRUnichar cr('\r');
 
 /** Mail citations using the Internet style: > This is a citation
   */
 
-
-nsInternetCiter::nsInternetCiter()
-{
-}
-
-nsInternetCiter::~nsInternetCiter()
-{
-}
-
-NS_IMPL_ISUPPORTS1(nsInternetCiter, nsICiter)
-
-NS_IMETHODIMP
+nsresult
 nsInternetCiter::GetCiteString(const nsAString& aInString, nsAString& aOutString)
 {
   aOutString.Truncate();
   PRUnichar uch = nl;
 
   // Strip trailing new lines which will otherwise turn up
   // as ugly quoted empty lines.
   nsReadingIterator <PRUnichar> beginIter,endIter;
@@ -150,17 +139,17 @@ nsInternetCiter::StripCitesAndLinebreaks
 
     // Done with this line -- update cite level
     if (aCiteLevel && (thisLineCiteLevel > *aCiteLevel))
       *aCiteLevel = thisLineCiteLevel;
   }
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsInternetCiter::StripCites(const nsAString& aInString, nsAString& aOutString)
 {
   return StripCitesAndLinebreaks(aInString, aOutString, PR_FALSE, 0);
 }
 
 static void AddCite(nsAString& aOutString, PRInt32 citeLevel)
 {
   for (PRInt32 i = 0; i < citeLevel; ++i)
@@ -183,17 +172,17 @@ BreakLine(nsAString& aOutString, PRUint3
     outStringCol = 0;
 }
 
 static inline PRBool IsSpace(PRUnichar c)
 {
   return (nsCRT::IsAsciiSpace(c) || (c == nl) || (c == cr) || (c == nbsp));
 }
 
-NS_IMETHODIMP
+nsresult
 nsInternetCiter::Rewrap(const nsAString& aInString,
                         PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
                         PRBool aRespectNewlines,
                         nsAString& aOutString)
 {
   // There shouldn't be returns in this string, only dom newlines.
   // Check to make sure:
 #ifdef DEBUG
--- a/editor/libeditor/text/nsInternetCiter.h
+++ b/editor/libeditor/text/nsInternetCiter.h
@@ -33,39 +33,31 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsInternetCiter_h__
 #define nsInternetCiter_h__
 
-#include "nsICiter.h"
-
 #include "nsString.h"
 
 /** Mail citations using standard Internet style.
   */
-class nsInternetCiter  : public nsICiter
+class nsInternetCiter
 {
 public:
-  nsInternetCiter();
-  virtual ~nsInternetCiter();
-//Interfaces for addref and release and queryinterface
-//NOTE: Use   NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsEditor
-  NS_DECL_ISUPPORTS
+  static nsresult GetCiteString(const nsAString & aInString, nsAString & aOutString);
+
+  static nsresult StripCites(const nsAString & aInString, nsAString & aOutString);
 
-  NS_IMETHOD GetCiteString(const nsAString & aInString, nsAString & aOutString);
-
-  NS_IMETHOD StripCites(const nsAString & aInString, nsAString & aOutString);
-
-  NS_IMETHOD Rewrap(const nsAString & aInString,
-                    PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
-                    PRBool aRespectNewlines,
-                    nsAString & aOutString);
+  static nsresult Rewrap(const nsAString & aInString,
+                         PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
+                         PRBool aRespectNewlines,
+                         nsAString & aOutString);
 
 protected:
-  nsresult StripCitesAndLinebreaks(const nsAString& aInString, nsAString& aOutString,
-                                   PRBool aLinebreaksToo, PRInt32* aCiteLevel);
+  static nsresult StripCitesAndLinebreaks(const nsAString& aInString, nsAString& aOutString,
+                                          PRBool aLinebreaksToo, PRInt32* aCiteLevel);
 };
 
 #endif //nsInternetCiter_h__
 
--- a/editor/libeditor/text/nsPlaintextEditor.cpp
+++ b/editor/libeditor/text/nsPlaintextEditor.cpp
@@ -1525,22 +1525,19 @@ nsPlaintextEditor::PasteAsQuotation(PRIn
 
 NS_IMETHODIMP
 nsPlaintextEditor::InsertAsQuotation(const nsAString& aQuotedText,
                                      nsIDOMNode **aNodeInserted)
 {
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
 
-  // We have the text.  Cite it appropriately:
-  nsCOMPtr<nsICiter> citer = new nsInternetCiter();
-
   // Let the citer quote it for us:
   nsString quotedStuff;
-  nsresult rv = citer->GetCiteString(aQuotedText, quotedStuff);
+  nsresult rv = nsInternetCiter::GetCiteString(aQuotedText, quotedStuff);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // It's best to put a blank line after the quoted text so that mails
   // written without thinking won't be so ugly.
   if (!aQuotedText.IsEmpty() && (aQuotedText.Last() != PRUnichar('\n')))
     quotedStuff.Append(PRUnichar('\n'));
 
   // get selection
@@ -1625,23 +1622,19 @@ nsPlaintextEditor::Rewrap(PRBool aRespec
 
   nsAutoString current;
   PRBool isCollapsed;
   rv = SharedOutputString(nsIDocumentEncoder::OutputFormatted
                           | nsIDocumentEncoder::OutputLFLineBreak,
                           &isCollapsed, current);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsICiter> citer = new nsInternetCiter();
-  NS_ENSURE_SUCCESS(rv, rv);
-  NS_ENSURE_TRUE(citer, NS_ERROR_UNEXPECTED);
-
   nsString wrapped;
   PRUint32 firstLineOffset = 0;   // XXX need to reset this if there is a selection
-  rv = citer->Rewrap(current, wrapCol, firstLineOffset, aRespectNewlines,
+  rv = nsInternetCiter::Rewrap(current, wrapCol, firstLineOffset, aRespectNewlines,
                      wrapped);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (isCollapsed)    // rewrap the whole document
     SelectAll();
 
   return InsertTextWithQuotations(wrapped);
 }
@@ -1654,21 +1647,18 @@ nsPlaintextEditor::StripCites()
 #endif
 
   nsAutoString current;
   PRBool isCollapsed;
   nsresult rv = SharedOutputString(nsIDocumentEncoder::OutputFormatted,
                                    &isCollapsed, current);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsICiter> citer = new nsInternetCiter();
-  NS_ENSURE_TRUE(citer, NS_ERROR_UNEXPECTED);
-
   nsString stripped;
-  rv = citer->StripCites(current, stripped);
+  rv = nsInternetCiter::StripCites(current, stripped);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (isCollapsed)    // rewrap the whole document
   {
     rv = SelectAll();
     NS_ENSURE_SUCCESS(rv, rv);
   }