Bug 1546578 - part 4: Merge AbsolutePositioningCommand::IsCommandEnabled() with StateUpdatingCommandBase::IsCommandEnabled() r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 26 Apr 2019 11:06:45 +0000
changeset 530497 6f718d253d8d01518b70fd56f78941882474f3b5
parent 530496 bc7f7e832c4e8635df5b267e3c0a534ccc11424c
child 530498 409044e9dbbdcc622a42ea9da9d9ee88ea5d4e20
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 4: Merge AbsolutePositioningCommand::IsCommandEnabled() with StateUpdatingCommandBase::IsCommandEnabled() r=m_kato [`AbsolutePositioningCommand::IsCommandEnabled()`](https://searchfox.org/mozilla-central/rev/f46e2bf881d522a440b30cbf5cf8d76fc212eaf4/editor/libeditor/HTMLEditorCommands.cpp#1038-1056) overrides [`StateUpdatingCommandBase::IsCommandEnabled()`](https://searchfox.org/mozilla-central/rev/f46e2bf881d522a440b30cbf5cf8d76fc212eaf4/editor/libeditor/HTMLEditorCommands.cpp#65-77). There are only 2 differences between them: 1. `AbsolutePositioningCommand::IsCommandEnabled()` never returns true if given context is not an HTMLEditor instance. 2. `AbsolutePositioningCommand::IsCommandEnabled()` checks `HTMLEditor::IsAbsolutePositionEditorEnabled()` additionally. So, we can get rid of it if we make `StateUpdatingCommandBase::IsCommandEnabled()` check given command name is "cmd_absPos" or not. The mapping is here: https://searchfox.org/mozilla-central/rev/ec489aa170b6486891cf3625717d6fa12bcd11c1/editor/libeditor/HTMLEditorController.cpp#102 Differential Revision: https://phabricator.services.mozilla.com/D28685
editor/libeditor/EditorCommands.h
editor/libeditor/HTMLEditorCommands.cpp
--- a/editor/libeditor/EditorCommands.h
+++ b/editor/libeditor/EditorCommands.h
@@ -33,27 +33,27 @@ class EditorCommand : public nsIControll
   EditorCommand() = default;
   virtual ~EditorCommand() = default;
 };
 
 #define NS_DECL_EDITOR_COMMAND_METHODS(_cmd)                                  \
  public:                                                                      \
   NS_IMETHOD IsCommandEnabled(const char* aCommandName,                       \
                               nsISupports* aCommandRefCon, bool* aIsEnabled)  \
-      override;                                                               \
+      final;                                                                  \
   MOZ_CAN_RUN_SCRIPT                                                          \
   NS_IMETHOD DoCommand(const char* aCommandName, nsISupports* aCommandRefCon) \
-      override;                                                               \
+      final;                                                                  \
   MOZ_CAN_RUN_SCRIPT                                                          \
   NS_IMETHOD DoCommandParams(const char* aCommandName,                        \
                              nsICommandParams* aParams,                       \
-                             nsISupports* aCommandRefCon) override;           \
+                             nsISupports* aCommandRefCon) final;              \
   NS_IMETHOD GetCommandStateParams(const char* aCommandName,                  \
                                    nsICommandParams* aParams,                 \
-                                   nsISupports* aCommandRefCon) override;
+                                   nsISupports* aCommandRefCon) final;
 
 #define NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
  public:                                                   \
   static _cmd* GetInstance() {                             \
     if (!sInstance) {                                      \
       sInstance = new _cmd();                              \
     }                                                      \
     return sInstance;                                      \
@@ -373,18 +373,16 @@ class BackgroundColorStateCommand final 
 class AbsolutePositioningCommand final : public StateUpdatingCommandBase {
  public:
   NS_INLINE_DECL_EDITOR_COMMAND_MAKE_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;
 };
 
--- a/editor/libeditor/HTMLEditorCommands.cpp
+++ b/editor/libeditor/HTMLEditorCommands.cpp
@@ -58,19 +58,32 @@ NS_IMETHODIMP
 StateUpdatingCommandBase::IsCommandEnabled(const char* aCommandName,
                                            nsISupports* refCon,
                                            bool* outCmdEnabled) {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
   if (!editor) {
     *outCmdEnabled = false;
     return NS_OK;
   }
-  mozilla::EditorBase* editorBase = editor->AsEditorBase();
-  MOZ_ASSERT(editorBase);
-  *outCmdEnabled = editorBase->IsSelectionEditable();
+  TextEditor* textEditor = editor->AsTextEditor();
+  if (!textEditor) {
+    *outCmdEnabled = false;
+    return NS_OK;
+  }
+  if (!textEditor->IsSelectionEditable()) {
+    *outCmdEnabled = false;
+    return NS_OK;
+  }
+  if (!nsCRT::strcmp(aCommandName, "cmd_absPos")) {
+    HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
+    *outCmdEnabled =
+        htmlEditor && htmlEditor->IsAbsolutePositionEditorEnabled();
+    return NS_OK;
+  }
+  *outCmdEnabled = true;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 StateUpdatingCommandBase::DoCommand(const char* aCommandName,
                                     nsISupports* refCon) {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
   if (NS_WARN_IF(!editor)) {
@@ -1003,37 +1016,16 @@ nsresult AlignCommand::SetState(HTMLEdit
 }
 
 /*****************************************************************************
  * mozilla::AbsolutePositioningCommand
  *****************************************************************************/
 
 StaticRefPtr<AbsolutePositioningCommand> AbsolutePositioningCommand::sInstance;
 
-NS_IMETHODIMP
-AbsolutePositioningCommand::IsCommandEnabled(const char* aCommandName,
-                                             nsISupports* aCommandRefCon,
-                                             bool* aOutCmdEnabled) {
-  *aOutCmdEnabled = false;
-
-  nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
-  if (!editor) {
-    return NS_OK;
-  }
-  mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
-  if (!htmlEditor) {
-    return NS_OK;
-  }
-  if (!htmlEditor->IsSelectionEditable()) {
-    return NS_OK;
-  }
-  *aOutCmdEnabled = htmlEditor->IsAbsolutePositionEditorEnabled();
-  return NS_OK;
-}
-
 nsresult AbsolutePositioningCommand::GetCurrentState(
     nsAtom* aTagName, HTMLEditor* aHTMLEditor, nsICommandParams* aParams) {
   if (NS_WARN_IF(!aHTMLEditor)) {
     return NS_ERROR_INVALID_ARG;
   }
 
   nsCommandParams* params = aParams->AsCommandParams();
   if (!aHTMLEditor->IsAbsolutePositionEditorEnabled()) {