Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit c7ac0ce

Browse files
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 --HG-- extra : moz-landing-system : lando
1 parent 62ca738 commit c7ac0ce

3 files changed

Lines changed: 65 additions & 69 deletions

File tree

editor/libeditor/HTMLEditRules.cpp

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -784,24 +784,6 @@ nsresult HTMLEditRules::WillDoAction(EditSubActionInfo& aInfo, bool* aCancel,
784784
NS_WARNING_ASSERTION(result.Succeeded(),
785785
"HandleDeleteSelection() failed");
786786
return result.Rv();
787-
case EditSubAction::eIndent: {
788-
EditActionResult result =
789-
MOZ_KnownLive(HTMLEditorRef()).HandleIndentAtSelection();
790-
*aHandled = result.Handled();
791-
*aCancel = result.Canceled();
792-
NS_WARNING_ASSERTION(result.Succeeded(),
793-
"HandleIndentAtSelection() failed");
794-
return result.Rv();
795-
}
796-
case EditSubAction::eOutdent: {
797-
EditActionResult result =
798-
MOZ_KnownLive(HTMLEditorRef()).HandleOutdentAtSelection();
799-
*aHandled = result.Handled();
800-
*aCancel = result.Canceled();
801-
NS_WARNING_ASSERTION(result.Succeeded(),
802-
"HandleOutdentAtSelection() failed");
803-
return result.Rv();
804-
}
805787
case EditSubAction::eSetPositionToAbsolute:
806788
return WillAbsolutePosition(aCancel, aHandled);
807789
case EditSubAction::eSetPositionToStatic:
@@ -824,8 +806,10 @@ nsresult HTMLEditRules::WillDoAction(EditSubActionInfo& aInfo, bool* aCancel,
824806
case EditSubAction::eCreateOrChangeDefinitionListItem:
825807
case EditSubAction::eCreateOrChangeList:
826808
case EditSubAction::eCreateOrRemoveBlock:
809+
case EditSubAction::eIndent:
827810
case EditSubAction::eInsertHTMLSource:
828811
case EditSubAction::eInsertParagraphSeparator:
812+
case EditSubAction::eOutdent:
829813
case EditSubAction::eUndo:
830814
case EditSubAction::eRedo:
831815
case EditSubAction::eRemoveList:
@@ -851,8 +835,6 @@ nsresult HTMLEditRules::DidDoAction(EditSubActionInfo& aInfo,
851835
return NS_OK;
852836
case EditSubAction::eDeleteSelectedContent:
853837
return DidDeleteSelection();
854-
case EditSubAction::eIndent:
855-
case EditSubAction::eOutdent:
856838
case EditSubAction::eSetOrClearAlignment:
857839
return MOZ_KnownLive(HTMLEditorRef())
858840
.MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
@@ -871,8 +853,10 @@ nsresult HTMLEditRules::DidDoAction(EditSubActionInfo& aInfo,
871853
case EditSubAction::eCreateOrChangeDefinitionListItem:
872854
case EditSubAction::eCreateOrChangeList:
873855
case EditSubAction::eCreateOrRemoveBlock:
856+
case EditSubAction::eIndent:
874857
case EditSubAction::eInsertHTMLSource:
875858
case EditSubAction::eInsertParagraphSeparator:
859+
case EditSubAction::eOutdent:
876860
case EditSubAction::eUndo:
877861
case EditSubAction::eRedo:
878862
case EditSubAction::eRemoveList:
@@ -4940,6 +4924,30 @@ nsresult HTMLEditor::MaybeInsertPaddingBRElementForEmptyLastLineAtSelection() {
49404924
return rv;
49414925
}
49424926

4927+
EditActionResult HTMLEditor::IndentAsSubAction() {
4928+
MOZ_ASSERT(IsEditActionDataAvailable());
4929+
4930+
AutoPlaceholderBatch treatAsOneTransaction(*this);
4931+
AutoEditSubActionNotifier startToHandleEditSubAction(
4932+
*this, EditSubAction::eIndent, nsIEditor::eNext);
4933+
4934+
EditActionResult result = CanHandleHTMLEditSubAction();
4935+
if (NS_WARN_IF(result.Failed()) || result.Canceled()) {
4936+
return result;
4937+
}
4938+
4939+
result |= HandleIndentAtSelection();
4940+
if (NS_WARN_IF(result.Failed()) || result.Canceled()) {
4941+
return result;
4942+
}
4943+
4944+
nsresult rv = MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
4945+
NS_WARNING_ASSERTION(
4946+
NS_SUCCEEDED(rv),
4947+
"MaybeInsertPaddingBRElementForEmptyLastLineAtSelection() failed");
4948+
return result.SetResult(rv);
4949+
}
4950+
49434951
EditActionResult HTMLEditor::HandleIndentAtSelection() {
49444952
MOZ_ASSERT(IsEditActionDataAvailable());
49454953

@@ -5556,6 +5564,30 @@ nsresult HTMLEditor::HandleHTMLIndentAtSelectionInternal() {
55565564
return NS_OK;
55575565
}
55585566

5567+
EditActionResult HTMLEditor::OutdentAsSubAction() {
5568+
MOZ_ASSERT(IsEditActionDataAvailable());
5569+
5570+
AutoPlaceholderBatch treatAsOneTransaction(*this);
5571+
AutoEditSubActionNotifier startToHandleEditSubAction(
5572+
*this, EditSubAction::eOutdent, nsIEditor::eNext);
5573+
5574+
EditActionResult result = CanHandleHTMLEditSubAction();
5575+
if (NS_WARN_IF(result.Failed()) || result.Canceled()) {
5576+
return result;
5577+
}
5578+
5579+
result |= HandleOutdentAtSelection();
5580+
if (NS_WARN_IF(result.Failed()) || result.Canceled()) {
5581+
return result;
5582+
}
5583+
5584+
nsresult rv = MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
5585+
NS_WARNING_ASSERTION(
5586+
NS_SUCCEEDED(rv),
5587+
"MaybeInsertPaddingBRElementForEmptyLastLineAtSelection() failed");
5588+
return result.SetResult(rv);
5589+
}
5590+
55595591
EditActionResult HTMLEditor::HandleOutdentAtSelection() {
55605592
MOZ_ASSERT(IsEditActionDataAvailable());
55615593

editor/libeditor/HTMLEditor.cpp

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,12 +2167,9 @@ nsresult HTMLEditor::IndentAsAction(nsIPrincipal* aPrincipal) {
21672167
return NS_ERROR_NOT_INITIALIZED;
21682168
}
21692169

2170-
AutoPlaceholderBatch treatAsOneTransaction(*this);
2171-
nsresult rv = IndentOrOutdentAsSubAction(EditSubAction::eIndent);
2172-
if (NS_WARN_IF(NS_FAILED(rv))) {
2173-
return EditorBase::ToGenericNSResult(rv);
2174-
}
2175-
return NS_OK;
2170+
EditActionResult result = IndentAsSubAction();
2171+
NS_WARNING_ASSERTION(result.Succeeded(), "IndentAsSubAction() failed");
2172+
return EditorBase::ToGenericNSResult(result.Rv());
21762173
}
21772174

21782175
nsresult HTMLEditor::OutdentAsAction(nsIPrincipal* aPrincipal) {
@@ -2186,41 +2183,9 @@ nsresult HTMLEditor::OutdentAsAction(nsIPrincipal* aPrincipal) {
21862183
return NS_ERROR_NOT_INITIALIZED;
21872184
}
21882185

2189-
AutoPlaceholderBatch treatAsOneTransaction(*this);
2190-
nsresult rv = IndentOrOutdentAsSubAction(EditSubAction::eOutdent);
2191-
if (NS_WARN_IF(NS_FAILED(rv))) {
2192-
return EditorBase::ToGenericNSResult(rv);
2193-
}
2194-
return NS_OK;
2195-
}
2196-
2197-
nsresult HTMLEditor::IndentOrOutdentAsSubAction(
2198-
EditSubAction aIndentOrOutdent) {
2199-
MOZ_ASSERT(IsEditActionDataAvailable());
2200-
MOZ_ASSERT(mRules);
2201-
MOZ_ASSERT(mPlaceholderBatch);
2202-
2203-
MOZ_ASSERT(aIndentOrOutdent == EditSubAction::eIndent ||
2204-
aIndentOrOutdent == EditSubAction::eOutdent);
2205-
2206-
// Protect the edit rules object from dying
2207-
RefPtr<TextEditRules> rules(mRules);
2208-
2209-
bool cancel, handled;
2210-
AutoEditSubActionNotifier startToHandleEditSubAction(*this, aIndentOrOutdent,
2211-
nsIEditor::eNext);
2212-
2213-
EditSubActionInfo subActionInfo(aIndentOrOutdent);
2214-
nsresult rv = rules->WillDoAction(subActionInfo, &cancel, &handled);
2215-
if (cancel || NS_FAILED(rv)) {
2216-
return rv;
2217-
}
2218-
2219-
rv = rules->DidDoAction(subActionInfo, rv);
2220-
if (NS_WARN_IF(NS_FAILED(rv))) {
2221-
return rv;
2222-
}
2223-
return NS_OK;
2186+
EditActionResult result = OutdentAsSubAction();
2187+
NS_WARNING_ASSERTION(result.Succeeded(), "OutdentAsSubAction() failed");
2188+
return EditorBase::ToGenericNSResult(result.Rv());
22242189
}
22252190

22262191
// TODO: IMPLEMENT ALIGNMENT!

editor/libeditor/HTMLEditor.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,15 +2956,14 @@ class HTMLEditor final : public TextEditor,
29562956
nsresult InsertTextWithQuotationsInternal(const nsAString& aStringToInsert);
29572957

29582958
/**
2959-
* IndentOrOutdentAsSubAction() indents or outdents the content around
2960-
* Selection. Callers have to guarantee that there is a placeholder
2961-
* transaction.
2962-
*
2963-
* @param aEditSubAction Must be EditSubAction::eIndent or
2964-
* EditSubAction::eOutdent.
2959+
* IndentAsSubAction() indents the content around Selection.
29652960
*/
2966-
MOZ_CAN_RUN_SCRIPT
2967-
nsresult IndentOrOutdentAsSubAction(EditSubAction aEditSubAction);
2961+
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult IndentAsSubAction();
2962+
2963+
/**
2964+
* OutdentAsSubAction() outdents the content around Selection.
2965+
*/
2966+
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult OutdentAsSubAction();
29682967

29692968
MOZ_CAN_RUN_SCRIPT
29702969
nsresult LoadHTML(const nsAString& aInputString);

0 commit comments

Comments
 (0)