--- a/editor/composer/src/nsComposerCommands.cpp
+++ b/editor/composer/src/nsComposerCommands.cpp
@@ -54,16 +54,18 @@
#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);
nsresult SetTextProperty(nsIHTMLEditor *aEditor, const nsAString& aProp);
@@ -80,20 +82,21 @@ nsresult SetTextProperty(nsIHTMLEditor *
nsBaseComposerCommand::nsBaseComposerCommand()
{
}
NS_IMPL_ISUPPORTS1(nsBaseComposerCommand, nsIControllerCommand)
-nsBaseStateUpdatingCommand::nsBaseStateUpdatingCommand(const char* aTagName)
+nsBaseStateUpdatingCommand::nsBaseStateUpdatingCommand(nsIAtom* aTagName)
: nsBaseComposerCommand()
, mTagName(aTagName)
{
+ MOZ_ASSERT(mTagName);
}
nsBaseStateUpdatingCommand::~nsBaseStateUpdatingCommand()
{
}
NS_IMPL_ISUPPORTS_INHERITED0(nsBaseStateUpdatingCommand, nsBaseComposerCommand)
@@ -189,41 +192,38 @@ nsPasteNoFormattingCommand::GetCommandSt
bool enabled = false;
nsresult rv = IsCommandEnabled(aCommandName, refCon, &enabled);
NS_ENSURE_SUCCESS(rv, rv);
return aParams->SetBooleanValue(STATE_ENABLED, enabled);
}
-nsStyleUpdatingCommand::nsStyleUpdatingCommand(const char* aTagName)
+nsStyleUpdatingCommand::nsStyleUpdatingCommand(nsIAtom* aTagName)
: nsBaseStateUpdatingCommand(aTagName)
{
}
nsresult
nsStyleUpdatingCommand::GetCurrentState(nsIEditor *aEditor,
nsICommandParams *aParams)
{
NS_ASSERTION(aEditor, "Need editor here");
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_INITIALIZED);
- nsresult rv = NS_OK;
-
bool firstOfSelectionHasProp = false;
bool anyOfSelectionHasProp = false;
bool allOfSelectionHasProp = false;
- nsCOMPtr<nsIAtom> styleAtom = do_GetAtom(mTagName);
- rv = htmlEditor->GetInlineProperty(styleAtom, EmptyString(),
- EmptyString(),
- &firstOfSelectionHasProp,
- &anyOfSelectionHasProp,
- &allOfSelectionHasProp);
+ nsresult rv = htmlEditor->GetInlineProperty(mTagName, EmptyString(),
+ EmptyString(),
+ &firstOfSelectionHasProp,
+ &anyOfSelectionHasProp,
+ &allOfSelectionHasProp);
aParams->SetBooleanValue(STATE_ENABLED, NS_SUCCEEDED(rv));
aParams->SetBooleanValue(STATE_ALL, allOfSelectionHasProp);
aParams->SetBooleanValue(STATE_ANY, anyOfSelectionHasProp);
aParams->SetBooleanValue(STATE_MIXED, anyOfSelectionHasProp
&& !allOfSelectionHasProp);
aParams->SetBooleanValue(STATE_BEGIN, firstOfSelectionHasProp);
aParams->SetBooleanValue(STATE_END, allOfSelectionHasProp);//not completely accurate
@@ -240,114 +240,112 @@ nsStyleUpdatingCommand::ToggleState(nsIE
nsresult rv;
nsCOMPtr<nsICommandParams> params =
do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
if (NS_FAILED(rv) || !params)
return rv;
// tags "href" and "name" are special cases in the core editor
// they are used to remove named anchor/link and shouldn't be used for insertion
- nsAutoString tagName; tagName.AssignWithConversion(mTagName);
bool doTagRemoval;
- if (tagName.EqualsLiteral("href") ||
- tagName.EqualsLiteral("name"))
+ if (mTagName == nsGkAtoms::href || mTagName == nsGkAtoms::name) {
doTagRemoval = true;
- else
- {
+ } else {
// check current selection; set doTagRemoval if formatting should be removed
rv = GetCurrentState(aEditor, params);
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")) {
+ if (mTagName == nsGkAtoms::b) {
rv = RemoveTextProperty(htmlEditor, NS_LITERAL_STRING("strong"));
NS_ENSURE_SUCCESS(rv, rv);
- } else if (tagName.EqualsLiteral("i")) {
+ } else if (mTagName == nsGkAtoms::i) {
rv = RemoveTextProperty(htmlEditor, NS_LITERAL_STRING("em"));
NS_ENSURE_SUCCESS(rv, rv);
- } else if (tagName.EqualsLiteral("strike")) {
+ } else if (mTagName == nsGkAtoms::strike) {
rv = RemoveTextProperty(htmlEditor, NS_LITERAL_STRING("s"));
NS_ENSURE_SUCCESS(rv, rv);
}
- rv = RemoveTextProperty(htmlEditor, tagName);
+ rv = RemoveTextProperty(htmlEditor, nsDependentAtomString(mTagName));
} else {
// Superscript and Subscript styles are mutually exclusive
aEditor->BeginTransaction();
- if (tagName.EqualsLiteral("sub") || tagName.EqualsLiteral("sup")) {
+ nsDependentAtomString tagName(mTagName);
+ if (mTagName == nsGkAtoms::sub || mTagName == nsGkAtoms::sup) {
rv = RemoveTextProperty(htmlEditor, tagName);
}
if (NS_SUCCEEDED(rv))
rv = SetTextProperty(htmlEditor, tagName);
aEditor->EndTransaction();
}
return rv;
}
-nsListCommand::nsListCommand(const char* aTagName)
+nsListCommand::nsListCommand(nsIAtom* aTagName)
: nsBaseStateUpdatingCommand(aTagName)
{
}
nsresult
nsListCommand::GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams)
{
NS_ASSERTION(aEditor, "Need editor here");
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NO_INTERFACE);
bool bMixed;
nsAutoString localName;
nsresult rv = GetListState(htmlEditor, &bMixed, localName);
NS_ENSURE_SUCCESS(rv, rv);
- // Need to use mTagName????
- bool inList = localName.EqualsASCII(mTagName);
+ bool inList = mTagName->Equals(localName);
aParams->SetBooleanValue(STATE_ALL, !bMixed && inList);
aParams->SetBooleanValue(STATE_MIXED, bMixed);
aParams->SetBooleanValue(STATE_ENABLED, true);
return NS_OK;
}
nsresult
nsListCommand::ToggleState(nsIEditor *aEditor)
{
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(aEditor);
NS_ENSURE_TRUE(editor, NS_NOINTERFACE);
- bool inList;
- // Need to use mTagName????
+
nsresult rv;
nsCOMPtr<nsICommandParams> params =
do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
if (NS_FAILED(rv) || !params)
return rv;
rv = GetCurrentState(aEditor, params);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ bool inList;
rv = params->GetBooleanValue(STATE_ALL,&inList);
NS_ENSURE_SUCCESS(rv, rv);
- nsAutoString listType; listType.AssignWithConversion(mTagName);
- if (inList)
+ nsDependentAtomString listType(mTagName);
+ if (inList) {
rv = editor->RemoveList(listType);
- else
- {
+ } else {
rv = editor->MakeOrChangeList(listType, false, EmptyString());
}
return rv;
}
-nsListItemCommand::nsListItemCommand(const char* aTagName)
+nsListItemCommand::nsListItemCommand(nsIAtom* aTagName)
: nsBaseStateUpdatingCommand(aTagName)
{
}
nsresult
nsListItemCommand::GetCurrentState(nsIEditor* aEditor,
nsICommandParams *aParams)
{
@@ -358,19 +356,23 @@ nsListItemCommand::GetCurrentState(nsIEd
bool bMixed, bLI, bDT, bDD;
nsresult rv = htmlEditor->GetListItemState(&bMixed, &bLI, &bDT, &bDD);
NS_ENSURE_SUCCESS(rv, rv);
bool inList = false;
if (!bMixed)
{
- if (bLI) inList = (0 == nsCRT::strcmp(mTagName, "li"));
- else if (bDT) inList = (0 == nsCRT::strcmp(mTagName, "dt"));
- else if (bDD) inList = (0 == nsCRT::strcmp(mTagName, "dd"));
+ if (bLI) {
+ inList = mTagName == nsGkAtoms::li;
+ } else if (bDT) {
+ inList = mTagName == nsGkAtoms::dt;
+ } else if (bDD) {
+ inList = mTagName == nsGkAtoms::dd;
+ }
}
aParams->SetBooleanValue(STATE_ALL, !bMixed && inList);
aParams->SetBooleanValue(STATE_MIXED, bMixed);
return NS_OK;
}
@@ -400,22 +402,21 @@ nsListItemCommand::ToggleState(nsIEditor
rv = GetListState(htmlEditor, &bMixed, localName);
NS_ENSURE_SUCCESS(rv, rv);
if (localName.IsEmpty() || bMixed) {
return rv;
}
return htmlEditor->RemoveList(localName);
}
- nsAutoString itemType; itemType.AssignWithConversion(mTagName);
// Set to the requested paragraph type
//XXX Note: This actually doesn't work for "LI",
// but we currently don't use this for non DL lists anyway.
// Problem: won't this replace any current block paragraph style?
- return htmlEditor->SetParagraphFormat(itemType);
+ return htmlEditor->SetParagraphFormat(nsDependentAtomString(mTagName));
}
NS_IMETHODIMP
nsRemoveListCommand::IsCommandEnabled(const char * aCommandName,
nsISupports *refCon,
bool *outCmdEnabled)
{
*outCmdEnabled = false;
@@ -1001,17 +1002,17 @@ nsAlignCommand::SetState(nsIEditor *aEdi
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
return htmlEditor->Align(newState);
}
nsAbsolutePositioningCommand::nsAbsolutePositioningCommand()
-: nsBaseStateUpdatingCommand("")
+: nsBaseStateUpdatingCommand(nsGkAtoms::_empty)
{
}
NS_IMETHODIMP
nsAbsolutePositioningCommand::IsCommandEnabled(const char * aCommandName,
nsISupports *aCommandRefCon,
bool *outCmdEnabled)
{
--- a/editor/composer/src/nsComposerCommands.h
+++ b/editor/composer/src/nsComposerCommands.h
@@ -40,16 +40,17 @@
#ifndef nsComposerCommands_h_
#define nsComposerCommands_h_
#include "nsIControllerCommand.h"
#include "nsString.h"
class nsIEditor;
+class nsIAtom;
// This is a virtual base class for commands registered with the composer controller.
// Note that such commands are instantiated once per composer, so can store state.
// Also note that IsCommandEnabled can be called with an editor that may not
// have an editor yet (because the document is loading). Most commands will want
// to return false in this case.
// Don't hold on to any references to the editor or document from
// your command. This will cause leaks. Also, be aware that the document the
@@ -78,45 +79,42 @@ class _cmd : public nsBaseComposerComman
public: \
NS_DECL_NSICONTROLLERCOMMAND \
};
// virtual base class for commands that need to save and update Boolean state (like styles etc)
class nsBaseStateUpdatingCommand : public nsBaseComposerCommand
{
public:
-
- nsBaseStateUpdatingCommand(const char* aTagName);
- virtual ~nsBaseStateUpdatingCommand();
+ nsBaseStateUpdatingCommand(nsIAtom* aTagName);
+ virtual ~nsBaseStateUpdatingCommand();
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSICONTROLLERCOMMAND
protected:
// get the current state (on or off) for this style or block format
virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams) = 0;
// add/remove the style
virtual nsresult ToggleState(nsIEditor* aEditor) = 0;
protected:
-
- const char* mTagName;
+ nsIAtom* mTagName;
};
// Shared class for the various style updating commands like bold, italics etc.
// Suitable for commands whose state is either 'on' or 'off'.
class nsStyleUpdatingCommand : public nsBaseStateUpdatingCommand
{
public:
-
- nsStyleUpdatingCommand(const char* aTagName);
+ nsStyleUpdatingCommand(nsIAtom* aTagName);
protected:
// get the current state (on or off) for this style or block format
virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
// add/remove the style
virtual nsresult ToggleState(nsIEditor* aEditor);
@@ -138,33 +136,31 @@ protected:
const char* mTagName;
};
class nsListCommand : public nsBaseStateUpdatingCommand
{
public:
-
- nsListCommand(const char* aTagName);
+ nsListCommand(nsIAtom* aTagName);
protected:
// get the current state (on or off) for this style or block format
virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
// add/remove the style
virtual nsresult ToggleState(nsIEditor* aEditor);
};
class nsListItemCommand : public nsBaseStateUpdatingCommand
{
public:
-
- nsListItemCommand(const char* aTagName);
+ nsListItemCommand(nsIAtom* aTagName);
protected:
// get the current state (on or off) for this style or block format
virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
// add/remove the style
virtual nsresult ToggleState(nsIEditor* aEditor);
@@ -267,17 +263,17 @@ protected:
virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
};
class nsAbsolutePositioningCommand : public nsBaseStateUpdatingCommand
{
public:
- nsAbsolutePositioningCommand();
+ nsAbsolutePositioningCommand();
protected:
NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval);
virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
virtual nsresult ToggleState(nsIEditor* aEditor);
};
--- a/editor/composer/src/nsComposerController.cpp
+++ b/editor/composer/src/nsComposerController.cpp
@@ -36,16 +36,17 @@
* 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 "nsIControllerCommandTable.h"
#include "nsComposerController.h"
#include "nsComposerCommands.h"
+#include "nsGkAtoms.h"
#define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName) \
{ \
_cmdClass* theCmd = new _cmdClass(); \
inCommandTable->RegisterCommand(_cmdName, \
static_cast<nsIControllerCommand *>(theCmd)); \
}
@@ -110,41 +111,41 @@ nsComposerController::RegisterHTMLEditor
// Edit menu
NS_REGISTER_ONE_COMMAND(nsPasteNoFormattingCommand, "cmd_pasteNoFormatting");
// indent/outdent
NS_REGISTER_ONE_COMMAND(nsIndentCommand, "cmd_indent");
NS_REGISTER_ONE_COMMAND(nsOutdentCommand, "cmd_outdent");
// Styles
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_bold", "b");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_italic", "i");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_underline", "u");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_tt", "tt");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_bold", nsGkAtoms::b);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_italic", nsGkAtoms::i);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_underline", nsGkAtoms::u);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_tt", nsGkAtoms::tt);
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strikethrough", "strike");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_superscript", "sup");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_subscript", "sub");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_nobreak", "nobr");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strikethrough", nsGkAtoms::strike);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_superscript", nsGkAtoms::sup);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_subscript", nsGkAtoms::sub);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_nobreak", nsGkAtoms::nobr);
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_em", "em");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strong", "strong");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_cite", "cite");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_abbr", "abbr");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_acronym", "acronym");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_code", "code");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_samp", "samp");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_var", "var");
- NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_removeLinks", "href");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_em", nsGkAtoms::em);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strong", nsGkAtoms::strong);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_cite", nsGkAtoms::cite);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_abbr", nsGkAtoms::abbr);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_acronym", nsGkAtoms::acronym);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_code", nsGkAtoms::code);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_samp", nsGkAtoms::samp);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_var", nsGkAtoms::var);
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_removeLinks", nsGkAtoms::href);
// lists
- NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol");
- NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul");
- NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dt", "dt");
- NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dd", "dd");
+ NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", nsGkAtoms::ol);
+ NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", nsGkAtoms::ul);
+ NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dt", nsGkAtoms::dt);
+ NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dd", nsGkAtoms::dd);
NS_REGISTER_ONE_COMMAND(nsRemoveListCommand, "cmd_removeList");
// format stuff
NS_REGISTER_ONE_COMMAND(nsParagraphStateCommand, "cmd_paragraphState");
NS_REGISTER_ONE_COMMAND(nsFontFaceStateCommand, "cmd_fontFace");
NS_REGISTER_ONE_COMMAND(nsFontSizeStateCommand, "cmd_fontSize");
NS_REGISTER_ONE_COMMAND(nsFontColorStateCommand, "cmd_fontColor");
NS_REGISTER_ONE_COMMAND(nsBackgroundColorStateCommand, "cmd_backgroundColor");