Bug 1574852 - part 79: Make `HTMLEditor::IndentAsAction()` and `HTMLEditor::OutdentAsAction()` call specific `AsSubAction()` methods instead of `WillDoAction()` and `DidDoAction()` r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Sun, 08 Sep 2019 05:12:43 +0000
changeset 492207 4351a64b385e21772b047409a751fe6e712b57b5
parent 492206 7d116cd6cec39d16dec8d7de1ce4e306f7ec535b
child 492208 8c629098c9c9753a9fc81fee866735b8c96de883
push id36550
push usershindli@mozilla.com
push dateMon, 09 Sep 2019 15:36:52 +0000
treeherdermozilla-central@6f423e980a92 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1574852
milestone71.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 1574852 - part 79: Make `HTMLEditor::IndentAsAction()` and `HTMLEditor::OutdentAsAction()` call specific `AsSubAction()` methods instead of `WillDoAction()` and `DidDoAction()` r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D44783
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -779,34 +779,16 @@ nsresult HTMLEditRules::WillDoAction(Edi
       result = MOZ_KnownLive(HTMLEditorRef())
                    .HandleDeleteSelection(aInfo.collapsedAction,
                                           aInfo.stripWrappers);
       *aHandled = result.Handled();
       *aCancel = result.Canceled();
       NS_WARNING_ASSERTION(result.Succeeded(),
                            "HandleDeleteSelection() failed");
       return result.Rv();
-    case EditSubAction::eIndent: {
-      EditActionResult result =
-          MOZ_KnownLive(HTMLEditorRef()).HandleIndentAtSelection();
-      *aHandled = result.Handled();
-      *aCancel = result.Canceled();
-      NS_WARNING_ASSERTION(result.Succeeded(),
-                           "HandleIndentAtSelection() failed");
-      return result.Rv();
-    }
-    case EditSubAction::eOutdent: {
-      EditActionResult result =
-          MOZ_KnownLive(HTMLEditorRef()).HandleOutdentAtSelection();
-      *aHandled = result.Handled();
-      *aCancel = result.Canceled();
-      NS_WARNING_ASSERTION(result.Succeeded(),
-                           "HandleOutdentAtSelection() failed");
-      return result.Rv();
-    }
     case EditSubAction::eSetPositionToAbsolute:
       return WillAbsolutePosition(aCancel, aHandled);
     case EditSubAction::eSetPositionToStatic:
       return WillRemoveAbsolutePosition(aCancel, aHandled);
     case EditSubAction::eSetOrClearAlignment:
       return WillAlign(*aInfo.alignType, aCancel, aHandled);
     case EditSubAction::eInsertElement:
     case EditSubAction::eInsertQuotedText: {
@@ -819,18 +801,20 @@ nsresult HTMLEditRules::WillDoAction(Edi
     }
     case EditSubAction::eDecreaseZIndex:
       return WillRelativeChangeZIndex(-1, aCancel, aHandled);
     case EditSubAction::eIncreaseZIndex:
       return WillRelativeChangeZIndex(1, aCancel, aHandled);
     case EditSubAction::eCreateOrChangeDefinitionListItem:
     case EditSubAction::eCreateOrChangeList:
     case EditSubAction::eCreateOrRemoveBlock:
+    case EditSubAction::eIndent:
     case EditSubAction::eInsertHTMLSource:
     case EditSubAction::eInsertParagraphSeparator:
+    case EditSubAction::eOutdent:
     case EditSubAction::eUndo:
     case EditSubAction::eRedo:
     case EditSubAction::eRemoveList:
       MOZ_ASSERT_UNREACHABLE("This path should've been dead code");
       return NS_ERROR_UNEXPECTED;
     default:
       return TextEditRules::WillDoAction(aInfo, aCancel, aHandled);
   }
@@ -846,18 +830,16 @@ nsresult HTMLEditRules::DidDoAction(Edit
 
   switch (aInfo.mEditSubAction) {
     case EditSubAction::eInsertText:
     case EditSubAction::eInsertLineBreak:
     case EditSubAction::eInsertTextComingFromIME:
       return NS_OK;
     case EditSubAction::eDeleteSelectedContent:
       return DidDeleteSelection();
-    case EditSubAction::eIndent:
-    case EditSubAction::eOutdent:
     case EditSubAction::eSetOrClearAlignment:
       return MOZ_KnownLive(HTMLEditorRef())
           .MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
     case EditSubAction::eSetPositionToAbsolute: {
       nsresult rv =
           MOZ_KnownLive(HTMLEditorRef())
               .MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
       if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -866,18 +848,20 @@ nsresult HTMLEditRules::DidDoAction(Edit
       return DidAbsolutePosition();
     }
     case EditSubAction::eInsertElement:
     case EditSubAction::eInsertQuotedText:
       return NS_OK;
     case EditSubAction::eCreateOrChangeDefinitionListItem:
     case EditSubAction::eCreateOrChangeList:
     case EditSubAction::eCreateOrRemoveBlock:
+    case EditSubAction::eIndent:
     case EditSubAction::eInsertHTMLSource:
     case EditSubAction::eInsertParagraphSeparator:
+    case EditSubAction::eOutdent:
     case EditSubAction::eUndo:
     case EditSubAction::eRedo:
     case EditSubAction::eRemoveList:
       MOZ_ASSERT_UNREACHABLE("This path should've been dead code");
       return NS_ERROR_UNEXPECTED;
     default:
       return TextEditRules::DidDoAction(aInfo, aResult);
   }
@@ -4935,16 +4919,40 @@ nsresult HTMLEditor::MaybeInsertPaddingB
   nsresult rv =
       InsertPaddingBRElementForEmptyLastLineIfNeeded(startContainerElement);
   NS_WARNING_ASSERTION(
       NS_SUCCEEDED(rv),
       "InsertPaddingBRElementForEmptyLastLineIfNeeded() failed");
   return rv;
 }
 
+EditActionResult HTMLEditor::IndentAsSubAction() {
+  MOZ_ASSERT(IsEditActionDataAvailable());
+
+  AutoPlaceholderBatch treatAsOneTransaction(*this);
+  AutoEditSubActionNotifier startToHandleEditSubAction(
+      *this, EditSubAction::eIndent, nsIEditor::eNext);
+
+  EditActionResult result = CanHandleHTMLEditSubAction();
+  if (NS_WARN_IF(result.Failed()) || result.Canceled()) {
+    return result;
+  }
+
+  result |= HandleIndentAtSelection();
+  if (NS_WARN_IF(result.Failed()) || result.Canceled()) {
+    return result;
+  }
+
+  nsresult rv = MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
+  NS_WARNING_ASSERTION(
+      NS_SUCCEEDED(rv),
+      "MaybeInsertPaddingBRElementForEmptyLastLineAtSelection() failed");
+  return result.SetResult(rv);
+}
+
 EditActionResult HTMLEditor::HandleIndentAtSelection() {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   // FYI: Ignore cancel result of WillInsert().
   nsresult rv = WillInsert();
   if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
     return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
   }
@@ -5551,16 +5559,40 @@ nsresult HTMLEditor::HandleHTMLIndentAtS
       return rv;
     }
     // forget curList, if any
     curList = nullptr;
   }
   return NS_OK;
 }
 
+EditActionResult HTMLEditor::OutdentAsSubAction() {
+  MOZ_ASSERT(IsEditActionDataAvailable());
+
+  AutoPlaceholderBatch treatAsOneTransaction(*this);
+  AutoEditSubActionNotifier startToHandleEditSubAction(
+      *this, EditSubAction::eOutdent, nsIEditor::eNext);
+
+  EditActionResult result = CanHandleHTMLEditSubAction();
+  if (NS_WARN_IF(result.Failed()) || result.Canceled()) {
+    return result;
+  }
+
+  result |= HandleOutdentAtSelection();
+  if (NS_WARN_IF(result.Failed()) || result.Canceled()) {
+    return result;
+  }
+
+  nsresult rv = MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
+  NS_WARNING_ASSERTION(
+      NS_SUCCEEDED(rv),
+      "MaybeInsertPaddingBRElementForEmptyLastLineAtSelection() failed");
+  return result.SetResult(rv);
+}
+
 EditActionResult HTMLEditor::HandleOutdentAtSelection() {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   if (!SelectionRefPtr()->IsCollapsed()) {
     nsresult rv = MaybeExtendSelectionToHardLineEdgesForBlockEditAction();
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return EditActionHandled(rv);
     }
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -2162,70 +2162,35 @@ nsresult HTMLEditor::IndentAsAction(nsIP
   }
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eIndent,
                                           aPrincipal);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
-  AutoPlaceholderBatch treatAsOneTransaction(*this);
-  nsresult rv = IndentOrOutdentAsSubAction(EditSubAction::eIndent);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return EditorBase::ToGenericNSResult(rv);
-  }
-  return NS_OK;
+  EditActionResult result = IndentAsSubAction();
+  NS_WARNING_ASSERTION(result.Succeeded(), "IndentAsSubAction() failed");
+  return EditorBase::ToGenericNSResult(result.Rv());
 }
 
 nsresult HTMLEditor::OutdentAsAction(nsIPrincipal* aPrincipal) {
   if (!mRules) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eOutdent,
                                           aPrincipal);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
-  AutoPlaceholderBatch treatAsOneTransaction(*this);
-  nsresult rv = IndentOrOutdentAsSubAction(EditSubAction::eOutdent);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return EditorBase::ToGenericNSResult(rv);
-  }
-  return NS_OK;
-}
-
-nsresult HTMLEditor::IndentOrOutdentAsSubAction(
-    EditSubAction aIndentOrOutdent) {
-  MOZ_ASSERT(IsEditActionDataAvailable());
-  MOZ_ASSERT(mRules);
-  MOZ_ASSERT(mPlaceholderBatch);
-
-  MOZ_ASSERT(aIndentOrOutdent == EditSubAction::eIndent ||
-             aIndentOrOutdent == EditSubAction::eOutdent);
-
-  // Protect the edit rules object from dying
-  RefPtr<TextEditRules> rules(mRules);
-
-  bool cancel, handled;
-  AutoEditSubActionNotifier startToHandleEditSubAction(*this, aIndentOrOutdent,
-                                                       nsIEditor::eNext);
-
-  EditSubActionInfo subActionInfo(aIndentOrOutdent);
-  nsresult rv = rules->WillDoAction(subActionInfo, &cancel, &handled);
-  if (cancel || NS_FAILED(rv)) {
-    return rv;
-  }
-
-  rv = rules->DidDoAction(subActionInfo, rv);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  return NS_OK;
+  EditActionResult result = OutdentAsSubAction();
+  NS_WARNING_ASSERTION(result.Succeeded(), "OutdentAsSubAction() failed");
+  return EditorBase::ToGenericNSResult(result.Rv());
 }
 
 // TODO: IMPLEMENT ALIGNMENT!
 
 NS_IMETHODIMP
 HTMLEditor::Align(const nsAString& aAlignType) {
   nsresult rv = AlignAsAction(aAlignType);
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to align content");
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -2951,25 +2951,24 @@ class HTMLEditor final : public TextEdit
    * last chunk.  Then, each chunk starting with ">" is inserted after wrapping
    * with <span _moz_quote="true">, and each chunk not starting with ">" is
    * inserted as normal text.
    */
   MOZ_CAN_RUN_SCRIPT
   nsresult InsertTextWithQuotationsInternal(const nsAString& aStringToInsert);
 
   /**
-   * IndentOrOutdentAsSubAction() indents or outdents the content around
-   * Selection.  Callers have to guarantee that there is a placeholder
-   * transaction.
-   *
-   * @param aEditSubAction      Must be EditSubAction::eIndent or
-   *                            EditSubAction::eOutdent.
+   * IndentAsSubAction() indents the content around Selection.
    */
-  MOZ_CAN_RUN_SCRIPT
-  nsresult IndentOrOutdentAsSubAction(EditSubAction aEditSubAction);
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult IndentAsSubAction();
+
+  /**
+   * OutdentAsSubAction() outdents the content around Selection.
+   */
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult OutdentAsSubAction();
 
   MOZ_CAN_RUN_SCRIPT
   nsresult LoadHTML(const nsAString& aInputString);
 
   MOZ_CAN_RUN_SCRIPT
   nsresult SetInlinePropertyInternal(nsAtom& aProperty, nsAtom* aAttribute,
                                      const nsAString& aValue);
   MOZ_CAN_RUN_SCRIPT