Bug 1791501 - Use EditActionResult as ok type of mozilla::Result r=m_kato

Any callers do not refer "ignored", "handled" and "cancel" state without
checking whether the method returns error or not.  Therefore, error state
can be (and should be) managed by `mozilla::Result`'s error state.

Perhaps, it should store a caret position later because deletion handlers
of `HTMLEditor` use it, but update `Selection` immediately.

Differential Revision: https://phabricator.services.mozilla.com/D158080
This commit is contained in:
Masayuki Nakano
2022-09-28 07:21:37 +00:00
parent a6d1bf0cc4
commit 767307c38d
16 changed files with 1265 additions and 1134 deletions

View File

@@ -681,11 +681,16 @@ nsresult HTMLEditor::HTMLWithContextInserter::Run(
return NS_OK;
}
EditActionResult result = mHTMLEditor.CanHandleHTMLEditSubAction();
if (result.Failed() || result.Canceled()) {
NS_WARNING_ASSERTION(result.Succeeded(),
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
return result.Rv();
{
Result<EditActionResult, nsresult> result =
mHTMLEditor.CanHandleHTMLEditSubAction();
if (MOZ_UNLIKELY(result.isErr())) {
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
return result.unwrapErr();
}
if (result.inspect().Canceled()) {
return NS_OK;
}
}
mHTMLEditor.UndefineCaretBidiLevel();
@@ -2594,12 +2599,16 @@ nsresult HTMLEditor::PasteAsQuotationAsAction(int32_t aClipboardType,
// If it's not in plain text edit mode, paste text into new
// <blockquote type="cite"> element after removing selection.
// XXX Why don't we test these first?
EditActionResult result = CanHandleHTMLEditSubAction();
if (result.Failed() || result.Canceled()) {
NS_WARNING_ASSERTION(result.Succeeded(),
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
return EditorBase::ToGenericNSResult(result.Rv());
{
// XXX Why don't we test these first?
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
if (MOZ_UNLIKELY(result.isErr())) {
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
return EditorBase::ToGenericNSResult(result.unwrapErr());
}
if (result.inspect().Canceled()) {
return NS_OK;
}
}
UndefineCaretBidiLevel();
@@ -2762,11 +2771,15 @@ nsresult HTMLEditor::InsertWithQuotationsAsSubAction(
return NS_OK;
}
EditActionResult result = CanHandleHTMLEditSubAction();
if (result.Failed() || result.Canceled()) {
NS_WARNING_ASSERTION(result.Succeeded(),
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
return result.Rv();
{
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
if (MOZ_UNLIKELY(result.isErr())) {
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
return result.unwrapErr();
}
if (result.inspect().Canceled()) {
return NS_OK;
}
}
UndefineCaretBidiLevel();
@@ -3008,11 +3021,15 @@ nsresult HTMLEditor::InsertAsPlaintextQuotation(const nsAString& aQuotedText,
return NS_OK;
}
EditActionResult result = CanHandleHTMLEditSubAction();
if (result.Failed() || result.Canceled()) {
NS_WARNING_ASSERTION(result.Succeeded(),
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
return result.Rv();
{
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
if (MOZ_UNLIKELY(result.isErr())) {
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
return result.unwrapErr();
}
if (result.inspect().Canceled()) {
return NS_OK;
}
}
UndefineCaretBidiLevel();
@@ -3285,11 +3302,15 @@ nsresult HTMLEditor::InsertAsCitedQuotationInternal(
return NS_OK;
}
EditActionResult result = CanHandleHTMLEditSubAction();
if (result.Failed() || result.Canceled()) {
NS_WARNING_ASSERTION(result.Succeeded(),
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
return result.Rv();
{
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
if (MOZ_UNLIKELY(result.isErr())) {
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
return result.unwrapErr();
}
if (result.inspect().Canceled()) {
return NS_OK;
}
}
UndefineCaretBidiLevel();