Bug 1468708 - Part 3. Clean up local functions not to calculate atom again. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 15 Jun 2018 08:56:25 -0700
changeset 807750 42140bd2efb46b98d082e4e0989b0c0c02a27fe7
parent 807397 1b0bc96b893a1e1a3e5ff461ce1aeaf60122f16c
child 807751 7d97ad2bee09911aa66fa697fb1e1fb0e6f5df76
push id113196
push userbmo:m_kato@ga2.so-net.ne.jp
push dateFri, 15 Jun 2018 17:12:54 +0000
reviewersmasayuki
bugs1468708
milestone62.0a1
Bug 1468708 - Part 3. Clean up local functions not to calculate atom again. r?masayuki nsComposerCommands has unnecessary atom calculation, so we should remove it. Also, since nsStyleUpdatingCommand doesn't hava "all" tag names, we don't need to support it. MozReview-Commit-ID: Q0EBsK2mxr
editor/composer/nsComposerCommands.cpp
--- a/editor/composer/nsComposerCommands.cpp
+++ b/editor/composer/nsComposerCommands.cpp
@@ -29,26 +29,20 @@
 #include "nsString.h"                   // for nsAutoString, nsString, etc
 #include "nsStringFwd.h"                // for nsString
 
 class nsISupports;
 using mozilla::dom::Element;
 using mozilla::ErrorResult;
 
 //prototype
-nsresult GetListState(mozilla::HTMLEditor* aHTMLEditor,
-                      bool* aMixed,
-                      nsAString& aLocalName);
-nsresult RemoveOneProperty(mozilla::HTMLEditor* aHTMLEditor,
-                           const nsAString& aProp);
-nsresult RemoveTextProperty(mozilla::HTMLEditor* aHTMLEditor,
-                            const nsAString& aProp);
-nsresult SetTextProperty(mozilla::HTMLEditor* aHTMLEditor,
-                         const nsAString& aProp);
-
+static nsresult
+GetListState(mozilla::HTMLEditor* aHTMLEditor,
+             bool* aMixed,
+             nsAString& aLocalName);
 
 //defines
 #define STATE_ENABLED  "state_enabled"
 #define STATE_ALL "state_all"
 #define STATE_ANY "state_any"
 #define STATE_MIXED "state_mixed"
 #define STATE_BEGIN "state_begin"
 #define STATE_END "state_end"
@@ -248,40 +242,50 @@ nsStyleUpdatingCommand::ToggleState(mozi
     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 (mTagName == nsGkAtoms::b) {
-      rv = RemoveTextProperty(aHTMLEditor, NS_LITERAL_STRING("strong"));
-      NS_ENSURE_SUCCESS(rv, rv);
+      rv = aHTMLEditor->RemoveInlineProperty(nsGkAtoms::strong, nullptr);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     } else if (mTagName == nsGkAtoms::i) {
-      rv = RemoveTextProperty(aHTMLEditor, NS_LITERAL_STRING("em"));
-      NS_ENSURE_SUCCESS(rv, rv);
+      rv = aHTMLEditor->RemoveInlineProperty(nsGkAtoms::em, nullptr);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     } else if (mTagName == nsGkAtoms::strike) {
-      rv = RemoveTextProperty(aHTMLEditor, NS_LITERAL_STRING("s"));
-      NS_ENSURE_SUCCESS(rv, rv);
+      rv = aHTMLEditor->RemoveInlineProperty(nsGkAtoms::s, nullptr);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     }
 
-    rv = RemoveTextProperty(aHTMLEditor, nsDependentAtomString(mTagName));
-  } else {
-    // Superscript and Subscript styles are mutually exclusive
-    aHTMLEditor->BeginTransaction();
+    rv = aHTMLEditor->RemoveInlineProperty(mTagName, nullptr);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+    return rv;
+  }
 
-    nsDependentAtomString tagName(mTagName);
-    if (mTagName == nsGkAtoms::sub || mTagName == nsGkAtoms::sup) {
-      rv = RemoveTextProperty(aHTMLEditor, tagName);
-    }
-    if (NS_SUCCEEDED(rv))
-      rv = SetTextProperty(aHTMLEditor, tagName);
+  // Superscript and Subscript styles are mutually exclusive
+  aHTMLEditor->BeginTransaction();
 
-    aHTMLEditor->EndTransaction();
+  if (mTagName == nsGkAtoms::sub || mTagName == nsGkAtoms::sup) {
+    rv = aHTMLEditor->RemoveInlineProperty(mTagName, nullptr);
   }
+  if (NS_SUCCEEDED(rv)) {
+    rv = aHTMLEditor->SetInlineProperty(mTagName, nullptr, EmptyString());
+  }
+
+  aHTMLEditor->EndTransaction();
 
   return rv;
 }
 
 nsListCommand::nsListCommand(nsAtom* aTagName)
 : nsBaseStateUpdatingCommand(aTagName)
 {
 }
@@ -1536,17 +1540,17 @@ nsInsertTagCommand::GetCommandStateParam
   return aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled);
 }
 
 
 /****************************/
 //HELPER METHODS
 /****************************/
 
-nsresult
+static nsresult
 GetListState(mozilla::HTMLEditor* aHTMLEditor,
              bool* aMixed,
              nsAString& aLocalName)
 {
   MOZ_ASSERT(aHTMLEditor);
   MOZ_ASSERT(aMixed);
 
   *aMixed = false;
@@ -1564,52 +1568,8 @@ GetListState(mozilla::HTMLEditor* aHTMLE
     aLocalName.AssignLiteral("ol");
   } else if (bUL) {
     aLocalName.AssignLiteral("ul");
   } else if (bDL) {
     aLocalName.AssignLiteral("dl");
   }
   return NS_OK;
 }
-
-nsresult
-RemoveOneProperty(mozilla::HTMLEditor* aHTMLEditor,
-                  const nsAString& aProp)
-{
-  MOZ_ASSERT(aHTMLEditor);
-
-  /// XXX Hack alert! Look in nsIEditProperty.h for this
-  RefPtr<nsAtom> styleAtom = NS_Atomize(aProp);
-  NS_ENSURE_TRUE(styleAtom, NS_ERROR_OUT_OF_MEMORY);
-
-  return aHTMLEditor->RemoveInlineProperty(styleAtom, nullptr);
-}
-
-
-// the name of the attribute here should be the contents of the appropriate
-// tag, e.g. 'b' for bold, 'i' for italics.
-nsresult
-RemoveTextProperty(mozilla::HTMLEditor* aHTMLEditor,
-                   const nsAString& aProp)
-{
-  MOZ_ASSERT(aHTMLEditor);
-
-  if (aProp.LowerCaseEqualsLiteral("all")) {
-    return aHTMLEditor->RemoveAllInlineProperties();
-  }
-
-  return RemoveOneProperty(aHTMLEditor, 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(mozilla::HTMLEditor* aHTMLEditor,
-                const nsAString& aProp)
-{
-  MOZ_ASSERT(aHTMLEditor);
-
-  /// XXX Hack alert! Look in nsIEditProperty.h for this
-  RefPtr<nsAtom> styleAtom = NS_Atomize(aProp);
-  NS_ENSURE_TRUE(styleAtom, NS_ERROR_OUT_OF_MEMORY);
-
-  return aHTMLEditor->SetInlineProperty(styleAtom, nullptr, EmptyString());
-}