Bug 1546578 - part 1: Get rid of HTMLEditorCommands.h r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 26 Apr 2019 02:20:22 +0000
changeset 530494 adbd46962f21820f20a236c66fe1f3bdb57e52b4
parent 530493 8c3a37a0a53e8a2b99473cb8bb44201165b402be
child 530495 fa8572b81eaac032bafe2b38028746f7491dbffe
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1546578
milestone68.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 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
editor/libeditor/EditorCommands.h
editor/libeditor/HTMLEditorCommands.cpp
editor/libeditor/HTMLEditorCommands.h
editor/libeditor/HTMLEditorController.cpp
editor/libeditor/HTMLEditorDocumentCommands.cpp
editor/libeditor/moz.build
--- a/editor/libeditor/EditorCommands.h
+++ b/editor/libeditor/EditorCommands.h
@@ -1,26 +1,29 @@
 /* -*- 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 EditorCommands_h_
-#define EditorCommands_h_
+#ifndef mozilla_EditorCommands_h
+#define mozilla_EditorCommands_h
 
 #include "mozilla/StaticPtr.h"
 #include "nsIControllerCommand.h"
 #include "nsISupportsImpl.h"
-#include "nscore.h"
+#include "nsRefPtrHashtable.h"
+#include "nsStringFwd.h"
 
+class nsAtom;
 class nsICommandParams;
-class nsISupports;
 
 namespace mozilla {
 
+class HTMLEditor;
+
 /**
  * This is a base class for commands registered with the editor controller.
  * Note that such commands are designed as singleton classes.  So, MUST be
  * stateless. Any state must be stored via the refCon (an nsIEditor).
  */
 
 class EditorCommandBase : public nsIControllerCommand {
  public:
@@ -88,30 +91,387 @@ NS_DECL_EDITOR_COMMAND(SelectAllCommand)
 NS_DECL_EDITOR_COMMAND(SelectionMoveCommands)
 
 // Insert content commands
 NS_DECL_EDITOR_COMMAND(InsertPlaintextCommand)
 NS_DECL_EDITOR_COMMAND(InsertParagraphCommand)
 NS_DECL_EDITOR_COMMAND(InsertLineBreakCommand)
 NS_DECL_EDITOR_COMMAND(PasteQuotationCommand)
 
-#if 0
-// template for new command
-NS_IMETHODIMP
-FooCommand::IsCommandEnabled(const char* aCommandName,
-                             nsISupports* aCommandRefCon,
-                             bool* aIsEnabled)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
+/******************************************************************************
+ * Commands for HTML editor
+ ******************************************************************************/
+
+// 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)
 
-NS_IMETHODIMP
-FooCommand::DoCommand(const char* aCommandName,
-                      const nsAString& aCommandParams,
-                      nsISupports* aCommandRefCon)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-#endif
+ 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
 
-#endif  // #ifndef EditorCommands_h_
+#endif  // #ifndef mozilla_EditorCommands_h
--- a/editor/libeditor/HTMLEditorCommands.cpp
+++ b/editor/libeditor/HTMLEditorCommands.cpp
@@ -1,20 +1,19 @@
 /* -*- 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/. */
 
-#include <stdio.h>  // for printf
+#include "mozilla/EditorCommands.h"
 
 #include "mozilla/Assertions.h"  // for MOZ_ASSERT, etc
 #include "mozilla/EditorBase.h"  // for EditorBase
 #include "mozilla/ErrorResult.h"
 #include "mozilla/HTMLEditor.h"  // for HTMLEditor
-#include "mozilla/HTMLEditorCommands.h"
 #include "mozilla/dom/Element.h"
 #include "nsAString.h"
 #include "nsCommandParams.h"          // for nsCommandParams, etc
 #include "nsCOMPtr.h"                 // for nsCOMPtr, do_QueryInterface, etc
 #include "nsComponentManagerUtils.h"  // for do_CreateInstance
 #include "nsDebug.h"                  // for NS_ENSURE_TRUE, etc
 #include "nsError.h"                  // for NS_OK, NS_ERROR_FAILURE, etc
 #include "nsGkAtoms.h"                // for nsGkAtoms, nsGkAtoms::font, etc
@@ -597,23 +596,18 @@ MultiStateCommandBase::IsCommandEnabled(
   // should be disabled sometimes, like if the current selection is an image
   *outCmdEnabled = editorBase->IsSelectionEditable();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 MultiStateCommandBase::DoCommand(const char* aCommandName,
                                  nsISupports* refCon) {
-#ifdef DEBUG
-  printf(
-      "who is calling MultiStateCommandBase::DoCommand \
-          (no implementation)? %s\n",
-      aCommandName);
-#endif
-
+  NS_WARNING(
+      "who is calling MultiStateCommandBase::DoCommand (no implementation)?");
   return NS_OK;
 }
 
 NS_IMETHODIMP
 MultiStateCommandBase::DoCommandParams(const char* aCommandName,
                                        nsICommandParams* aParams,
                                        nsISupports* refCon) {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
deleted file mode 100644
--- a/editor/libeditor/HTMLEditorCommands.h
+++ /dev/null
@@ -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_
--- a/editor/libeditor/HTMLEditorController.cpp
+++ b/editor/libeditor/HTMLEditorController.cpp
@@ -1,16 +1,16 @@
 /* -*- 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/. */
 
 #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 "nsControllerCommandTable.h"    // for nsControllerCommandTable
 #include "nsError.h"                     // for NS_OK
 
 namespace mozilla {
 
 #define NS_REGISTER_COMMAND(_cmdClass, _cmdName)                        \
   {                                                                     \
--- a/editor/libeditor/HTMLEditorDocumentCommands.cpp
+++ b/editor/libeditor/HTMLEditorDocumentCommands.cpp
@@ -1,15 +1,16 @@
 /* -*- 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/. */
 
+#include "mozilla/EditorCommands.h"
+
 #include "mozilla/HTMLEditor.h"          // for HTMLEditor
-#include "mozilla/HTMLEditorCommands.h"  // for SetDocumentStateCommand, etc
 #include "mozilla/TextEditor.h"          // for TextEditor
 #include "nsCommandParams.h"             // for nsCommandParams
 #include "nsCOMPtr.h"                    // for nsCOMPtr, do_QueryInterface, etc
 #include "nsCRT.h"                       // for nsCRT
 #include "nsDebug.h"                     // for NS_ENSURE_ARG_POINTER, etc
 #include "nsError.h"                     // for NS_ERROR_INVALID_ARG, etc
 #include "nsIDocShell.h"                 // for nsIDocShell
 #include "mozilla/dom/Document.h"        // for Document
--- a/editor/libeditor/moz.build
+++ b/editor/libeditor/moz.build
@@ -13,22 +13,22 @@ MOCHITEST_CHROME_MANIFESTS += ['tests/ch
 
 BROWSER_CHROME_MANIFESTS += ['tests/browser.ini']
 
 EXPORTS.mozilla += [
     'ChangeStyleTransaction.h',
     'CSSEditUtils.h',
     'EditAction.h',
     'EditorBase.h',
+    'EditorCommands.h',
     'EditorController.h',
     'EditorDOMPoint.h',
     'EditorUtils.h',
     'EditTransactionBase.h',
     'HTMLEditor.h',
-    'HTMLEditorCommands.h',
     'HTMLEditorController.h',
     'ManualNAC.h',
     'SelectionState.h',
     'TextEditor.h',
     'TextEditRules.h',
 ]
 
 UNIFIED_SOURCES += [