Bug 1546578 - part 1: Get rid of HTMLEditorCommands.h r=m_kato

When declaring a common base class of all editor command classes in
EditorCommands.h, we need to declare some useful macro to declare its
subclasses.  However, such macro should be `#undef`ed in the header file.

Therefore, this patch moves all contents in HTMLEditorCommands.h to
EditorCommands.h and removes it from the tree.

Differential Revision: https://phabricator.services.mozilla.com/D28682

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-04-26 02:20:22 +00:00
parent 46175d5797
commit 129a809380
6 changed files with 389 additions and 427 deletions

View File

@ -3,19 +3,22 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef EditorCommands_h_ #ifndef mozilla_EditorCommands_h
#define EditorCommands_h_ #define mozilla_EditorCommands_h
#include "mozilla/StaticPtr.h" #include "mozilla/StaticPtr.h"
#include "nsIControllerCommand.h" #include "nsIControllerCommand.h"
#include "nsISupportsImpl.h" #include "nsISupportsImpl.h"
#include "nscore.h" #include "nsRefPtrHashtable.h"
#include "nsStringFwd.h"
class nsAtom;
class nsICommandParams; class nsICommandParams;
class nsISupports;
namespace mozilla { namespace mozilla {
class HTMLEditor;
/** /**
* This is a base class for commands registered with the editor controller. * This is a base class for commands registered with the editor controller.
* Note that such commands are designed as singleton classes. So, MUST be * Note that such commands are designed as singleton classes. So, MUST be
@ -93,25 +96,382 @@ NS_DECL_EDITOR_COMMAND(InsertParagraphCommand)
NS_DECL_EDITOR_COMMAND(InsertLineBreakCommand) NS_DECL_EDITOR_COMMAND(InsertLineBreakCommand)
NS_DECL_EDITOR_COMMAND(PasteQuotationCommand) NS_DECL_EDITOR_COMMAND(PasteQuotationCommand)
#if 0 /******************************************************************************
// template for new command * Commands for HTML editor
NS_IMETHODIMP ******************************************************************************/
FooCommand::IsCommandEnabled(const char* aCommandName,
nsISupports* aCommandRefCon,
bool* aIsEnabled)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP // This is a base class for commands registered with window which includes
FooCommand::DoCommand(const char* aCommandName, // HTMLEditor. Like editor commands, these command classes are also designed
const nsAString& aCommandParams, // as singleton classes. So, MUST be stateless. Also note that
nsISupports* aCommandRefCon) // 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
return NS_ERROR_NOT_IMPLEMENTED; // 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
#endif // the document the editor is editing can change under you (if the user
// Reverts the file, for instance).
class HTMLEditorCommandBase : public nsIControllerCommand {
public:
// nsISupports
NS_DECL_ISUPPORTS
protected:
HTMLEditorCommandBase() = default;
virtual ~HTMLEditorCommandBase() = default;
};
#define NS_DECL_HTML_EDITOR_COMMAND(_cmd) \
class _cmd final : public HTMLEditorCommandBase { \
public: \
NS_DECL_NSICONTROLLERCOMMAND \
\
static _cmd* GetInstance() { \
if (!sInstance) { \
sInstance = new _cmd(); \
} \
return sInstance; \
} \
\
static void Shutdown() { sInstance = nullptr; } \
\
private: \
static StaticRefPtr<_cmd> sInstance; \
};
#define NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(_cmd) \
public: \
static _cmd* GetInstance() { \
if (!sInstance) { \
sInstance = new _cmd(); \
} \
return sInstance; \
} \
\
static void Shutdown() { sInstance = nullptr; } \
\
private: \
static StaticRefPtr<_cmd> sInstance;
// virtual base class for commands that need to save and update Boolean state
// (like styles etc)
class StateUpdatingCommandBase : public HTMLEditorCommandBase {
public:
NS_INLINE_DECL_REFCOUNTING_INHERITED(StateUpdatingCommandBase,
HTMLEditorCommandBase)
NS_DECL_NSICONTROLLERCOMMAND
protected:
StateUpdatingCommandBase() = default;
virtual ~StateUpdatingCommandBase() { sTagNameTable.Clear(); }
// get the current state (on or off) for this style or block format
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
virtual nsresult
GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
nsICommandParams* aParams) = 0;
// add/remove the style
MOZ_CAN_RUN_SCRIPT
virtual nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) = 0;
static already_AddRefed<nsAtom> TagName(const char* aCommandName) {
MOZ_DIAGNOSTIC_ASSERT(aCommandName);
if (NS_WARN_IF(!aCommandName)) {
return nullptr;
}
if (!sTagNameTable.Count()) {
sTagNameTable.Put("cmd_bold", nsGkAtoms::b);
sTagNameTable.Put("cmd_italic", nsGkAtoms::i);
sTagNameTable.Put("cmd_underline", nsGkAtoms::u);
sTagNameTable.Put("cmd_tt", nsGkAtoms::tt);
sTagNameTable.Put("cmd_strikethrough", nsGkAtoms::strike);
sTagNameTable.Put("cmd_superscript", nsGkAtoms::sup);
sTagNameTable.Put("cmd_subscript", nsGkAtoms::sub);
sTagNameTable.Put("cmd_nobreak", nsGkAtoms::nobr);
sTagNameTable.Put("cmd_em", nsGkAtoms::em);
sTagNameTable.Put("cmd_strong", nsGkAtoms::strong);
sTagNameTable.Put("cmd_cite", nsGkAtoms::cite);
sTagNameTable.Put("cmd_abbr", nsGkAtoms::abbr);
sTagNameTable.Put("cmd_acronym", nsGkAtoms::acronym);
sTagNameTable.Put("cmd_code", nsGkAtoms::code);
sTagNameTable.Put("cmd_samp", nsGkAtoms::samp);
sTagNameTable.Put("cmd_var", nsGkAtoms::var);
sTagNameTable.Put("cmd_removeLinks", nsGkAtoms::href);
sTagNameTable.Put("cmd_ol", nsGkAtoms::ol);
sTagNameTable.Put("cmd_ul", nsGkAtoms::ul);
sTagNameTable.Put("cmd_dt", nsGkAtoms::dt);
sTagNameTable.Put("cmd_dd", nsGkAtoms::dd);
sTagNameTable.Put("cmd_absPos", nsGkAtoms::_empty);
}
RefPtr<nsAtom> tagName = sTagNameTable.Get(aCommandName);
MOZ_DIAGNOSTIC_ASSERT(tagName);
return tagName.forget();
}
static nsRefPtrHashtable<nsCharPtrHashKey, nsAtom> sTagNameTable;
};
// Shared class for the various style updating commands like bold, italics etc.
// Suitable for commands whose state is either 'on' or 'off'.
class StyleUpdatingCommand final : public StateUpdatingCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(StyleUpdatingCommand)
protected:
StyleUpdatingCommand() = default;
virtual ~StyleUpdatingCommand() = default;
// get the current state (on or off) for this style or block format
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
nsICommandParams* aParams) final;
// add/remove the style
MOZ_CAN_RUN_SCRIPT
nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) final;
};
class InsertTagCommand final : public HTMLEditorCommandBase {
public:
NS_INLINE_DECL_REFCOUNTING_INHERITED(InsertTagCommand, HTMLEditorCommandBase)
NS_DECL_NSICONTROLLERCOMMAND
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(InsertTagCommand)
protected:
InsertTagCommand() = default;
virtual ~InsertTagCommand() { sTagNameTable.Clear(); }
static already_AddRefed<nsAtom> TagName(const char* aCommandName) {
MOZ_DIAGNOSTIC_ASSERT(aCommandName);
if (NS_WARN_IF(!aCommandName)) {
return nullptr;
}
if (!sTagNameTable.Count()) {
sTagNameTable.Put("cmd_insertLinkNoUI", nsGkAtoms::a);
sTagNameTable.Put("cmd_insertImageNoUI", nsGkAtoms::img);
sTagNameTable.Put("cmd_insertHR", nsGkAtoms::hr);
}
RefPtr<nsAtom> tagName = sTagNameTable.Get(aCommandName);
MOZ_DIAGNOSTIC_ASSERT(tagName);
return tagName.forget();
}
static nsRefPtrHashtable<nsCharPtrHashKey, nsAtom> sTagNameTable;
};
class ListCommand final : public StateUpdatingCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(ListCommand)
protected:
ListCommand() = default;
virtual ~ListCommand() = default;
// get the current state (on or off) for this style or block format
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
nsICommandParams* aParams) final;
// add/remove the style
MOZ_CAN_RUN_SCRIPT
nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) final;
};
class ListItemCommand final : public StateUpdatingCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(ListItemCommand)
protected:
ListItemCommand() = default;
virtual ~ListItemCommand() = default;
// get the current state (on or off) for this style or block format
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
nsICommandParams* aParams) final;
// add/remove the style
MOZ_CAN_RUN_SCRIPT
nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) final;
};
// Base class for commands whose state consists of a string (e.g. para format)
class MultiStateCommandBase : public HTMLEditorCommandBase {
public:
NS_INLINE_DECL_REFCOUNTING_INHERITED(MultiStateCommandBase,
HTMLEditorCommandBase)
NS_DECL_NSICONTROLLERCOMMAND
protected:
MultiStateCommandBase() = default;
virtual ~MultiStateCommandBase() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
virtual nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) = 0;
MOZ_CAN_RUN_SCRIPT
virtual nsresult SetState(HTMLEditor* aHTMLEditor,
const nsString& newState) = 0;
};
class ParagraphStateCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(ParagraphStateCommand)
protected:
ParagraphStateCommand() = default;
virtual ~ParagraphStateCommand() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class FontFaceStateCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(FontFaceStateCommand)
protected:
FontFaceStateCommand() = default;
virtual ~FontFaceStateCommand() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class FontSizeStateCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(FontSizeStateCommand)
protected:
FontSizeStateCommand() = default;
virtual ~FontSizeStateCommand() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class HighlightColorStateCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(HighlightColorStateCommand)
protected:
HighlightColorStateCommand() = default;
virtual ~HighlightColorStateCommand() = default;
NS_IMETHOD IsCommandEnabled(const char* aCommandName,
nsISupports* aCommandRefCon, bool* _retval) final;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class FontColorStateCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(FontColorStateCommand)
protected:
FontColorStateCommand() = default;
virtual ~FontColorStateCommand() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class AlignCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(AlignCommand)
protected:
AlignCommand() = default;
virtual ~AlignCommand() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class BackgroundColorStateCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(BackgroundColorStateCommand)
protected:
BackgroundColorStateCommand() = default;
virtual ~BackgroundColorStateCommand() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class AbsolutePositioningCommand final : public StateUpdatingCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(AbsolutePositioningCommand)
protected:
AbsolutePositioningCommand() = default;
virtual ~AbsolutePositioningCommand() = default;
NS_IMETHOD IsCommandEnabled(const char* aCommandName,
nsISupports* aCommandRefCon, bool* _retval) final;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) final;
};
// composer commands
NS_DECL_HTML_EDITOR_COMMAND(DocumentStateCommand)
NS_DECL_HTML_EDITOR_COMMAND(SetDocumentStateCommand)
NS_DECL_HTML_EDITOR_COMMAND(DecreaseZIndexCommand)
NS_DECL_HTML_EDITOR_COMMAND(IncreaseZIndexCommand)
// Generic commands
// Edit menu
NS_DECL_HTML_EDITOR_COMMAND(PasteNoFormattingCommand)
// Block transformations
NS_DECL_HTML_EDITOR_COMMAND(IndentCommand)
NS_DECL_HTML_EDITOR_COMMAND(OutdentCommand)
NS_DECL_HTML_EDITOR_COMMAND(RemoveListCommand)
NS_DECL_HTML_EDITOR_COMMAND(RemoveStylesCommand)
NS_DECL_HTML_EDITOR_COMMAND(IncreaseFontSizeCommand)
NS_DECL_HTML_EDITOR_COMMAND(DecreaseFontSizeCommand)
// Insert content commands
NS_DECL_HTML_EDITOR_COMMAND(InsertHTMLCommand)
#undef NS_DECL_EDITOR_COMMAND
#undef NS_DECL_HTML_EDITOR_COMMAND
#undef NS_DECL_HTML_EDITOR_COMMAND_SINGLETON
} // namespace mozilla } // namespace mozilla
#endif // #ifndef EditorCommands_h_ #endif // #ifndef mozilla_EditorCommands_h

View File

@ -3,13 +3,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <stdio.h> // for printf #include "mozilla/EditorCommands.h"
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/EditorBase.h" // for EditorBase #include "mozilla/EditorBase.h" // for EditorBase
#include "mozilla/ErrorResult.h" #include "mozilla/ErrorResult.h"
#include "mozilla/HTMLEditor.h" // for HTMLEditor #include "mozilla/HTMLEditor.h" // for HTMLEditor
#include "mozilla/HTMLEditorCommands.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "nsAString.h" #include "nsAString.h"
#include "nsCommandParams.h" // for nsCommandParams, etc #include "nsCommandParams.h" // for nsCommandParams, etc
@ -602,13 +601,8 @@ MultiStateCommandBase::IsCommandEnabled(const char* aCommandName,
NS_IMETHODIMP NS_IMETHODIMP
MultiStateCommandBase::DoCommand(const char* aCommandName, MultiStateCommandBase::DoCommand(const char* aCommandName,
nsISupports* refCon) { nsISupports* refCon) {
#ifdef DEBUG NS_WARNING(
printf( "who is calling MultiStateCommandBase::DoCommand (no implementation)?");
"who is calling MultiStateCommandBase::DoCommand \
(no implementation)? %s\n",
aCommandName);
#endif
return NS_OK; return NS_OK;
} }

View File

@ -1,393 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_HTMLEditorCommands_h_
#define mozilla_HTMLEditorCommands_h_
#include "mozilla/StaticPtr.h"
#include "nsIControllerCommand.h"
#include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED, etc
#include "nsRefPtrHashtable.h"
#include "nsStringFwd.h"
#include "nscore.h" // for nsresult, NS_IMETHOD
class nsAtom;
class nsICommandParams;
class nsISupports;
namespace mozilla {
class HTMLEditor;
// This is a base class for commands registered with window which includes
// HTMLEditor. Like editor commands, these command classes are also designed
// as singleton classes. So, MUST be stateless. 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 editor is editing can change under you (if the user
// Reverts the file, for instance).
class HTMLEditorCommandBase : public nsIControllerCommand {
public:
// nsISupports
NS_DECL_ISUPPORTS
protected:
HTMLEditorCommandBase() = default;
virtual ~HTMLEditorCommandBase() = default;
};
#define NS_DECL_HTML_EDITOR_COMMAND(_cmd) \
class _cmd final : public HTMLEditorCommandBase { \
public: \
NS_DECL_NSICONTROLLERCOMMAND \
\
static _cmd* GetInstance() { \
if (!sInstance) { \
sInstance = new _cmd(); \
} \
return sInstance; \
} \
\
static void Shutdown() { sInstance = nullptr; } \
\
private: \
static StaticRefPtr<_cmd> sInstance; \
};
#define NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(_cmd) \
public: \
static _cmd* GetInstance() { \
if (!sInstance) { \
sInstance = new _cmd(); \
} \
return sInstance; \
} \
\
static void Shutdown() { sInstance = nullptr; } \
\
private: \
static StaticRefPtr<_cmd> sInstance;
// virtual base class for commands that need to save and update Boolean state
// (like styles etc)
class StateUpdatingCommandBase : public HTMLEditorCommandBase {
public:
NS_INLINE_DECL_REFCOUNTING_INHERITED(StateUpdatingCommandBase,
HTMLEditorCommandBase)
NS_DECL_NSICONTROLLERCOMMAND
protected:
StateUpdatingCommandBase() = default;
virtual ~StateUpdatingCommandBase() { sTagNameTable.Clear(); }
// get the current state (on or off) for this style or block format
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
virtual nsresult
GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
nsICommandParams* aParams) = 0;
// add/remove the style
MOZ_CAN_RUN_SCRIPT
virtual nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) = 0;
static already_AddRefed<nsAtom> TagName(const char* aCommandName) {
MOZ_DIAGNOSTIC_ASSERT(aCommandName);
if (NS_WARN_IF(!aCommandName)) {
return nullptr;
}
if (!sTagNameTable.Count()) {
sTagNameTable.Put("cmd_bold", nsGkAtoms::b);
sTagNameTable.Put("cmd_italic", nsGkAtoms::i);
sTagNameTable.Put("cmd_underline", nsGkAtoms::u);
sTagNameTable.Put("cmd_tt", nsGkAtoms::tt);
sTagNameTable.Put("cmd_strikethrough", nsGkAtoms::strike);
sTagNameTable.Put("cmd_superscript", nsGkAtoms::sup);
sTagNameTable.Put("cmd_subscript", nsGkAtoms::sub);
sTagNameTable.Put("cmd_nobreak", nsGkAtoms::nobr);
sTagNameTable.Put("cmd_em", nsGkAtoms::em);
sTagNameTable.Put("cmd_strong", nsGkAtoms::strong);
sTagNameTable.Put("cmd_cite", nsGkAtoms::cite);
sTagNameTable.Put("cmd_abbr", nsGkAtoms::abbr);
sTagNameTable.Put("cmd_acronym", nsGkAtoms::acronym);
sTagNameTable.Put("cmd_code", nsGkAtoms::code);
sTagNameTable.Put("cmd_samp", nsGkAtoms::samp);
sTagNameTable.Put("cmd_var", nsGkAtoms::var);
sTagNameTable.Put("cmd_removeLinks", nsGkAtoms::href);
sTagNameTable.Put("cmd_ol", nsGkAtoms::ol);
sTagNameTable.Put("cmd_ul", nsGkAtoms::ul);
sTagNameTable.Put("cmd_dt", nsGkAtoms::dt);
sTagNameTable.Put("cmd_dd", nsGkAtoms::dd);
sTagNameTable.Put("cmd_absPos", nsGkAtoms::_empty);
}
RefPtr<nsAtom> tagName = sTagNameTable.Get(aCommandName);
MOZ_DIAGNOSTIC_ASSERT(tagName);
return tagName.forget();
}
static nsRefPtrHashtable<nsCharPtrHashKey, nsAtom> sTagNameTable;
};
// Shared class for the various style updating commands like bold, italics etc.
// Suitable for commands whose state is either 'on' or 'off'.
class StyleUpdatingCommand final : public StateUpdatingCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(StyleUpdatingCommand)
protected:
StyleUpdatingCommand() = default;
virtual ~StyleUpdatingCommand() = default;
// get the current state (on or off) for this style or block format
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
nsICommandParams* aParams) final;
// add/remove the style
MOZ_CAN_RUN_SCRIPT
nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) final;
};
class InsertTagCommand final : public HTMLEditorCommandBase {
public:
NS_INLINE_DECL_REFCOUNTING_INHERITED(InsertTagCommand, HTMLEditorCommandBase)
NS_DECL_NSICONTROLLERCOMMAND
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(InsertTagCommand)
protected:
InsertTagCommand() = default;
virtual ~InsertTagCommand() { sTagNameTable.Clear(); }
static already_AddRefed<nsAtom> TagName(const char* aCommandName) {
MOZ_DIAGNOSTIC_ASSERT(aCommandName);
if (NS_WARN_IF(!aCommandName)) {
return nullptr;
}
if (!sTagNameTable.Count()) {
sTagNameTable.Put("cmd_insertLinkNoUI", nsGkAtoms::a);
sTagNameTable.Put("cmd_insertImageNoUI", nsGkAtoms::img);
sTagNameTable.Put("cmd_insertHR", nsGkAtoms::hr);
}
RefPtr<nsAtom> tagName = sTagNameTable.Get(aCommandName);
MOZ_DIAGNOSTIC_ASSERT(tagName);
return tagName.forget();
}
static nsRefPtrHashtable<nsCharPtrHashKey, nsAtom> sTagNameTable;
};
class ListCommand final : public StateUpdatingCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(ListCommand)
protected:
ListCommand() = default;
virtual ~ListCommand() = default;
// get the current state (on or off) for this style or block format
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
nsICommandParams* aParams) final;
// add/remove the style
MOZ_CAN_RUN_SCRIPT
nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) final;
};
class ListItemCommand final : public StateUpdatingCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(ListItemCommand)
protected:
ListItemCommand() = default;
virtual ~ListItemCommand() = default;
// get the current state (on or off) for this style or block format
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
nsICommandParams* aParams) final;
// add/remove the style
MOZ_CAN_RUN_SCRIPT
nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) final;
};
// Base class for commands whose state consists of a string (e.g. para format)
class MultiStateCommandBase : public HTMLEditorCommandBase {
public:
NS_INLINE_DECL_REFCOUNTING_INHERITED(MultiStateCommandBase,
HTMLEditorCommandBase)
NS_DECL_NSICONTROLLERCOMMAND
protected:
MultiStateCommandBase() = default;
virtual ~MultiStateCommandBase() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
virtual nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) = 0;
MOZ_CAN_RUN_SCRIPT
virtual nsresult SetState(HTMLEditor* aHTMLEditor,
const nsString& newState) = 0;
};
class ParagraphStateCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(ParagraphStateCommand)
protected:
ParagraphStateCommand() = default;
virtual ~ParagraphStateCommand() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class FontFaceStateCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(FontFaceStateCommand)
protected:
FontFaceStateCommand() = default;
virtual ~FontFaceStateCommand() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class FontSizeStateCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(FontSizeStateCommand)
protected:
FontSizeStateCommand() = default;
virtual ~FontSizeStateCommand() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class HighlightColorStateCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(HighlightColorStateCommand)
protected:
HighlightColorStateCommand() = default;
virtual ~HighlightColorStateCommand() = default;
NS_IMETHOD IsCommandEnabled(const char* aCommandName,
nsISupports* aCommandRefCon, bool* _retval) final;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class FontColorStateCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(FontColorStateCommand)
protected:
FontColorStateCommand() = default;
virtual ~FontColorStateCommand() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class AlignCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(AlignCommand)
protected:
AlignCommand() = default;
virtual ~AlignCommand() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class BackgroundColorStateCommand final : public MultiStateCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(BackgroundColorStateCommand)
protected:
BackgroundColorStateCommand() = default;
virtual ~BackgroundColorStateCommand() = default;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
};
class AbsolutePositioningCommand final : public StateUpdatingCommandBase {
public:
NS_DECL_HTML_EDITOR_COMMAND_SINGLETON(AbsolutePositioningCommand)
protected:
AbsolutePositioningCommand() = default;
virtual ~AbsolutePositioningCommand() = default;
NS_IMETHOD IsCommandEnabled(const char* aCommandName,
nsISupports* aCommandRefCon, bool* _retval) final;
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsresult
GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) final;
};
// composer commands
NS_DECL_HTML_EDITOR_COMMAND(DocumentStateCommand)
NS_DECL_HTML_EDITOR_COMMAND(SetDocumentStateCommand)
NS_DECL_HTML_EDITOR_COMMAND(DecreaseZIndexCommand)
NS_DECL_HTML_EDITOR_COMMAND(IncreaseZIndexCommand)
// Generic commands
// Edit menu
NS_DECL_HTML_EDITOR_COMMAND(PasteNoFormattingCommand)
// Block transformations
NS_DECL_HTML_EDITOR_COMMAND(IndentCommand)
NS_DECL_HTML_EDITOR_COMMAND(OutdentCommand)
NS_DECL_HTML_EDITOR_COMMAND(RemoveListCommand)
NS_DECL_HTML_EDITOR_COMMAND(RemoveStylesCommand)
NS_DECL_HTML_EDITOR_COMMAND(IncreaseFontSizeCommand)
NS_DECL_HTML_EDITOR_COMMAND(DecreaseFontSizeCommand)
// Insert content commands
NS_DECL_HTML_EDITOR_COMMAND(InsertHTMLCommand)
} // namespace mozilla
#endif // mozilla_HTMLEditorCommands_h_

View File

@ -5,7 +5,7 @@
#include "mozilla/HTMLEditorController.h" #include "mozilla/HTMLEditorController.h"
#include "mozilla/HTMLEditorCommands.h" // for StyleUpdatingCommand, etc #include "mozilla/EditorCommands.h" // for StyleUpdatingCommand, etc
#include "mozilla/mozalloc.h" // for operator new #include "mozilla/mozalloc.h" // for operator new
#include "nsControllerCommandTable.h" // for nsControllerCommandTable #include "nsControllerCommandTable.h" // for nsControllerCommandTable
#include "nsError.h" // for NS_OK #include "nsError.h" // for NS_OK

View File

@ -3,8 +3,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/EditorCommands.h"
#include "mozilla/HTMLEditor.h" // for HTMLEditor #include "mozilla/HTMLEditor.h" // for HTMLEditor
#include "mozilla/HTMLEditorCommands.h" // for SetDocumentStateCommand, etc
#include "mozilla/TextEditor.h" // for TextEditor #include "mozilla/TextEditor.h" // for TextEditor
#include "nsCommandParams.h" // for nsCommandParams #include "nsCommandParams.h" // for nsCommandParams
#include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc #include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc

View File

@ -18,12 +18,12 @@ EXPORTS.mozilla += [
'CSSEditUtils.h', 'CSSEditUtils.h',
'EditAction.h', 'EditAction.h',
'EditorBase.h', 'EditorBase.h',
'EditorCommands.h',
'EditorController.h', 'EditorController.h',
'EditorDOMPoint.h', 'EditorDOMPoint.h',
'EditorUtils.h', 'EditorUtils.h',
'EditTransactionBase.h', 'EditTransactionBase.h',
'HTMLEditor.h', 'HTMLEditor.h',
'HTMLEditorCommands.h',
'HTMLEditorController.h', 'HTMLEditorController.h',
'ManualNAC.h', 'ManualNAC.h',
'SelectionState.h', 'SelectionState.h',