Bug 761306 - Make nsInsertTagCommand::mTagName an nsIAtom*; r=ehsan
authorMs2ger <ms2ger@gmail.com>
Wed, 06 Jun 2012 09:42:01 +0200
changeset 95859 14b0be173b03bde9f28a08222f44496deb093952
parent 95858 4dd1d701614d1f0169bbdf39eb37e45a9705f4c4
child 95860 8216b90cef741838756c860d9bd8e6d9f661e4d7
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersehsan
bugs761306
milestone16.0a1
Bug 761306 - Make nsInsertTagCommand::mTagName an nsIAtom*; r=ehsan
editor/composer/src/nsComposerCommands.cpp
editor/composer/src/nsComposerCommands.h
editor/composer/src/nsComposerController.cpp
--- a/editor/composer/src/nsComposerCommands.cpp
+++ b/editor/composer/src/nsComposerCommands.cpp
@@ -16,17 +16,16 @@
 
 #include "nsCOMPtr.h"
 
 #include "nsComposerCommands.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsICommandParams.h"
 #include "nsComponentManagerUtils.h"
-#include "nsCRT.h"
 
 #include "mozilla/Assertions.h"
 
 //prototype
 nsresult GetListState(nsIHTMLEditor* aEditor, bool* aMixed,
                       nsAString& aLocalName);
 nsresult RemoveOneProperty(nsIHTMLEditor* aEditor, const nsAString& aProp);
 nsresult RemoveTextProperty(nsIHTMLEditor* aEditor, const nsAString& aProp);
@@ -1346,20 +1345,21 @@ nsInsertHTMLCommand::GetCommandStatePara
 
   bool outCmdEnabled = false;
   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
   return aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled);
 }
 
 NS_IMPL_ISUPPORTS_INHERITED0(nsInsertTagCommand, nsBaseComposerCommand)
 
-nsInsertTagCommand::nsInsertTagCommand(const char* aTagName)
+nsInsertTagCommand::nsInsertTagCommand(nsIAtom* aTagName)
 : nsBaseComposerCommand()
 , mTagName(aTagName)
 {
+  MOZ_ASSERT(mTagName);
 }
 
 nsInsertTagCommand::~nsInsertTagCommand()
 {
 }
 
 NS_IMETHODIMP
 nsInsertTagCommand::IsCommandEnabled(const char * aCommandName,
@@ -1375,43 +1375,40 @@ nsInsertTagCommand::IsCommandEnabled(con
   return NS_OK;
 }
 
 
 // corresponding STATE_ATTRIBUTE is: src (img) and href (a) 
 NS_IMETHODIMP
 nsInsertTagCommand::DoCommand(const char *aCmdName, nsISupports *refCon)
 {
-  if (0 == nsCRT::strcmp(mTagName, "hr"))
-  {
-    nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
-    NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
+  NS_ENSURE_TRUE(mTagName == nsGkAtoms::hr, NS_ERROR_NOT_IMPLEMENTED);
+
+  nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
+  NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
 
-    nsCOMPtr<nsIDOMElement> domElem;
-    nsresult rv;
-    rv = editor->CreateElementWithDefaults(NS_ConvertASCIItoUTF16(mTagName),
-                                           getter_AddRefs(domElem));
-    NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIDOMElement> domElem;
+  nsresult rv = editor->CreateElementWithDefaults(
+    nsDependentAtomString(mTagName), getter_AddRefs(domElem));
+  NS_ENSURE_SUCCESS(rv, rv);
 
-    return editor->InsertElementAtSelection(domElem, true);
-  }
-
-  return NS_ERROR_NOT_IMPLEMENTED;
+  return editor->InsertElementAtSelection(domElem, true);
 }
 
 NS_IMETHODIMP
 nsInsertTagCommand::DoCommandParams(const char *aCommandName,
                                     nsICommandParams *aParams,
                                     nsISupports *refCon)
 {
   NS_ENSURE_ARG_POINTER(refCon);
 
   // inserting an hr shouldn't have an parameters, just call DoCommand for that
-  if (0 == nsCRT::strcmp(mTagName, "hr"))
+  if (mTagName == nsGkAtoms::hr) {
     return DoCommand(aCommandName, refCon);
+  }
 
   NS_ENSURE_ARG_POINTER(aParams);
 
   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
   NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
 
   // do we have an href to use for creating link?
   nsXPIDLCString s;
@@ -1419,34 +1416,34 @@ nsInsertTagCommand::DoCommandParams(cons
   NS_ENSURE_SUCCESS(rv, rv);
   nsAutoString attrib; attrib.AssignWithConversion(s);
 
   if (attrib.IsEmpty())
     return NS_ERROR_INVALID_ARG;
 
   // filter out tags we don't know how to insert
   nsAutoString attributeType;
-  if (0 == nsCRT::strcmp(mTagName, "a")) {
+  if (mTagName == nsGkAtoms::a) {
     attributeType.AssignLiteral("href");
-  } else if (0 == nsCRT::strcmp(mTagName, "img")) {
+  } else if (mTagName == nsGkAtoms::img) {
     attributeType.AssignLiteral("src");
   } else {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   nsCOMPtr<nsIDOMElement> domElem;
-  rv = editor->CreateElementWithDefaults(NS_ConvertASCIItoUTF16(mTagName),
+  rv = editor->CreateElementWithDefaults(nsDependentAtomString(mTagName),
                                          getter_AddRefs(domElem));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = domElem->SetAttribute(attributeType, attrib);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // do actual insertion
-  if (0 == nsCRT::strcmp(mTagName, "a"))
+  if (mTagName == nsGkAtoms::a)
     return editor->InsertLinkAroundSelection(domElem);
 
   return editor->InsertElementAtSelection(domElem, true);
 }
 
 NS_IMETHODIMP
 nsInsertTagCommand::GetCommandStateParams(const char *aCommandName,
                                           nsICommandParams *aParams,
--- a/editor/composer/src/nsComposerCommands.h
+++ b/editor/composer/src/nsComposerCommands.h
@@ -84,27 +84,26 @@ protected:
   // add/remove the style
   virtual nsresult  ToggleState(nsIEditor* aEditor);
 };
 
 
 class nsInsertTagCommand : public nsBaseComposerCommand
 {
 public:
-
-              nsInsertTagCommand(const char* aTagName);
+  explicit nsInsertTagCommand(nsIAtom* aTagName);
   virtual     ~nsInsertTagCommand();
     
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_DECL_NSICONTROLLERCOMMAND
 
 protected:
 
-  const char* mTagName;
+  nsIAtom* mTagName;
 };
 
 
 class nsListCommand : public nsBaseStateUpdatingCommand
 {
 public:
   nsListCommand(nsIAtom* aTagName);
 
--- a/editor/composer/src/nsComposerController.cpp
+++ b/editor/composer/src/nsComposerController.cpp
@@ -119,18 +119,18 @@ nsComposerController::RegisterHTMLEditor
   NS_REGISTER_ONE_COMMAND(nsAlignCommand, "cmd_align");
   NS_REGISTER_ONE_COMMAND(nsRemoveStylesCommand, "cmd_removeStyles");
 
   NS_REGISTER_ONE_COMMAND(nsIncreaseFontSizeCommand, "cmd_increaseFont");
   NS_REGISTER_ONE_COMMAND(nsDecreaseFontSizeCommand, "cmd_decreaseFont");
 
   // Insert content
   NS_REGISTER_ONE_COMMAND(nsInsertHTMLCommand, "cmd_insertHTML");
-  NS_REGISTER_TAG_COMMAND(nsInsertTagCommand, "cmd_insertLinkNoUI", "a");
-  NS_REGISTER_TAG_COMMAND(nsInsertTagCommand, "cmd_insertImageNoUI", "img");
-  NS_REGISTER_TAG_COMMAND(nsInsertTagCommand, "cmd_insertHR", "hr");
+  NS_REGISTER_TAG_COMMAND(nsInsertTagCommand, "cmd_insertLinkNoUI", nsGkAtoms::a);
+  NS_REGISTER_TAG_COMMAND(nsInsertTagCommand, "cmd_insertImageNoUI", nsGkAtoms::img);
+  NS_REGISTER_TAG_COMMAND(nsInsertTagCommand, "cmd_insertHR", nsGkAtoms::hr);
 
   NS_REGISTER_ONE_COMMAND(nsAbsolutePositioningCommand, "cmd_absPos");
   NS_REGISTER_ONE_COMMAND(nsDecreaseZIndexCommand, "cmd_decreaseZIndex");
   NS_REGISTER_ONE_COMMAND(nsIncreaseZIndexCommand, "cmd_increaseZIndex");
 
   return NS_OK;
 }