Bug 742884 - Part a: Cleanup RemoveOneProperty / RemoveTextProperty (nsComposerCommands.cpp); r=ehsan
authorMs2ger <ms2ger@gmail.com>
Sat, 14 Apr 2012 15:07:34 +0200
changeset 95022 75531f9c6a5894a01bc63535d2bc30009d8d950b
parent 95021 6c5c349b434b2fd07314cec3894c79460c23c425
child 95023 00243f9b9febbd5994539dd9bcf90feb697d1460
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs742884
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 742884 - Part a: Cleanup RemoveOneProperty / RemoveTextProperty (nsComposerCommands.cpp); r=ehsan
editor/composer/src/nsComposerCommands.cpp
--- a/editor/composer/src/nsComposerCommands.cpp
+++ b/editor/composer/src/nsComposerCommands.cpp
@@ -55,20 +55,18 @@
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsICommandParams.h"
 #include "nsComponentManagerUtils.h"
 #include "nsCRT.h"
 
 //prototype
 nsresult GetListState(nsIEditor *aEditor, bool *aMixed, PRUnichar **tagStr);
-nsresult RemoveOneProperty(nsIHTMLEditor *aEditor,const nsString& aProp,
-                           const nsString &aAttr);
-nsresult RemoveTextProperty(nsIEditor *aEditor, const PRUnichar *prop,
-                            const PRUnichar *attr);
+nsresult RemoveOneProperty(nsIHTMLEditor* aEditor, const nsAString& aProp);
+nsresult RemoveTextProperty(nsIHTMLEditor* aEditor, const nsAString& aProp);
 nsresult SetTextProperty(nsIEditor *aEditor, const PRUnichar *prop,
                          const PRUnichar *attr, const PRUnichar *value);
 
 
 //defines
 #define STATE_ENABLED  "state_enabled"
 #define STATE_ALL "state_all"
 #define STATE_ANY "state_any"
@@ -259,44 +257,36 @@ nsStyleUpdatingCommand::ToggleState(nsIE
     NS_ENSURE_SUCCESS(rv, rv);
     rv = params->GetBooleanValue(STATE_ALL, &doTagRemoval);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (doTagRemoval) {
     // Also remove equivalent properties (bug 317093)
     if (tagName.EqualsLiteral("b")) {
-      rv = RemoveTextProperty(aEditor, NS_LITERAL_STRING("strong").get(), nsnull);
+      rv = RemoveTextProperty(htmlEditor, NS_LITERAL_STRING("strong"));
       NS_ENSURE_SUCCESS(rv, rv);
     } else if (tagName.EqualsLiteral("i")) {
-      rv = RemoveTextProperty(aEditor, NS_LITERAL_STRING("em").get(), nsnull);
+      rv = RemoveTextProperty(htmlEditor, NS_LITERAL_STRING("em"));
       NS_ENSURE_SUCCESS(rv, rv);
     } else if (tagName.EqualsLiteral("strike")) {
-      rv = RemoveTextProperty(aEditor, NS_LITERAL_STRING("s").get(), nsnull);
+      rv = RemoveTextProperty(htmlEditor, NS_LITERAL_STRING("s"));
       NS_ENSURE_SUCCESS(rv, rv);
     }
 
-    rv = RemoveTextProperty(aEditor, tagName.get(), nsnull);
+    rv = RemoveTextProperty(htmlEditor, tagName);
   } else {
     // Superscript and Subscript styles are mutually exclusive
-    nsAutoString removeName; 
     aEditor->BeginTransaction();
 
-    if (tagName.EqualsLiteral("sub"))
-    {
-      removeName.AssignLiteral("sup");
-      rv = RemoveTextProperty(aEditor,tagName.get(), nsnull);
-    } 
-    else if (tagName.EqualsLiteral("sup"))
-    {
-      removeName.AssignLiteral("sub");
-      rv = RemoveTextProperty(aEditor, tagName.get(), nsnull);
+    if (tagName.EqualsLiteral("sub") || tagName.EqualsLiteral("sup")) {
+      rv = RemoveTextProperty(htmlEditor, tagName);
     }
     if (NS_SUCCEEDED(rv))
-      rv = SetTextProperty(aEditor,tagName.get(), nsnull, nsnull);
+      rv = SetTextProperty(aEditor, tagName.get(), nsnull, nsnull);
 
     aEditor->EndTransaction();
   }
 
   return rv;
 }
 
 nsListCommand::nsListCommand(const char* aTagName)
@@ -1578,58 +1568,40 @@ GetListState(nsIEditor *aEditor, bool *a
         *_retval = ToNewUnicode(tagStr);
       }
     }  
   }
   return err;
 }
 
 nsresult
-RemoveOneProperty(nsIHTMLEditor *aEditor,const nsString& aProp, 
-                  const nsString &aAttr)
+RemoveOneProperty(nsIHTMLEditor* aEditor, const nsAString& aProp)
 {
-  NS_ENSURE_TRUE(aEditor, NS_ERROR_NOT_INITIALIZED);
+  MOZ_ASSERT(aEditor);
 
   /// XXX Hack alert! Look in nsIEditProperty.h for this
   nsCOMPtr<nsIAtom> styleAtom = do_GetAtom(aProp);
-  NS_ENSURE_TRUE( styleAtom, NS_ERROR_OUT_OF_MEMORY);
+  NS_ENSURE_TRUE(styleAtom, NS_ERROR_OUT_OF_MEMORY);
 
-  return aEditor->RemoveInlineProperty(styleAtom, aAttr);
+  return aEditor->RemoveInlineProperty(styleAtom, EmptyString());
 }
 
 
 // the name of the attribute here should be the contents of the appropriate
 // tag, e.g. 'b' for bold, 'i' for italics.
 nsresult
-RemoveTextProperty(nsIEditor *aEditor, const PRUnichar *prop, 
-                   const PRUnichar *attr)
+RemoveTextProperty(nsIHTMLEditor* aEditor, const nsAString& aProp)
 {
-  NS_ENSURE_TRUE(aEditor, NS_ERROR_NOT_INITIALIZED);
-  nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(aEditor);
-  NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
-  // OK, I'm really hacking now. This is just so that 
-  //     we can accept 'all' as input.  
-  nsAutoString  allStr(prop);
-  
-  ToLowerCase(allStr);
-  bool      doingAll = (allStr.EqualsLiteral("all"));
-  nsresult  err = NS_OK;
+  MOZ_ASSERT(aEditor);
 
-  if (doingAll)
-  {
-    err = editor->RemoveAllInlineProperties();
-  }
-  else
-  {
-    nsAutoString  aProp(prop);
-    nsAutoString  aAttr(attr);
-    err = RemoveOneProperty(editor,aProp, aAttr);
+  if (aProp.LowerCaseEqualsLiteral("all")) {
+    return aEditor->RemoveAllInlineProperties();
   }
   
-  return err;
+  return RemoveOneProperty(aEditor, aProp);
 }
 
 // the name of the attribute here should be the contents of the appropriate
 // tag, e.g. 'b' for bold, 'i' for italics.
 nsresult
 SetTextProperty(nsIEditor *aEditor, const PRUnichar *prop, 
                 const PRUnichar *attr, const PRUnichar *value)
 {