From c98a4265f6e2b4b5659cad21565e6ff05f020607 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Fri, 11 Mar 2022 09:21:36 +0000 Subject: [PATCH] Bug 1742933 - part 12: Make all `aInitializer` arguments optional r=m_kato For making the callers simpler, they should be able to be omitted if they want to do nothing. Differential Revision: https://phabricator.services.mozilla.com/D140701 --- editor/libeditor/HTMLEditSubActionHandler.cpp | 88 +++++++------------ editor/libeditor/HTMLEditor.cpp | 3 +- editor/libeditor/HTMLEditor.h | 16 ++-- 3 files changed, 44 insertions(+), 63 deletions(-) diff --git a/editor/libeditor/HTMLEditSubActionHandler.cpp b/editor/libeditor/HTMLEditSubActionHandler.cpp index 269bf9adbd06..76f19606e603 100644 --- a/editor/libeditor/HTMLEditSubActionHandler.cpp +++ b/editor/libeditor/HTMLEditSubActionHandler.cpp @@ -3051,14 +3051,11 @@ EditActionResult HTMLEditor::ChangeSelectedHardLinesToList( // MOZ_CAN_RUN_SCRIPT_BOUNDARY due to bug 1758868 [&](Element& aListElement) MOZ_CAN_RUN_SCRIPT_BOUNDARY { Result, nsresult> listItemElementOrError = - CreateAndInsertElement( - aListElement.IsInComposedDoc() ? WithTransaction::Yes - : WithTransaction::No, - aListItemElementTagName, - EditorDOMPoint(&aListElement, 0u), - [](Element& aListItemElement) -> nsresult { - return NS_OK; - }); + CreateAndInsertElement(aListElement.IsInComposedDoc() + ? WithTransaction::Yes + : WithTransaction::No, + aListItemElementTagName, + EditorDOMPoint(&aListElement, 0u)); if (listItemElementOrError.isErr()) { NS_WARNING(nsPrintfCString( "HTMLEditor::CreateAndInsertElement(%s) failed", @@ -3227,8 +3224,7 @@ EditActionResult HTMLEditor::ChangeSelectedHardLinesToList( Result, nsresult> maybeNewListElement = CreateAndInsertElement( WithTransaction::Yes, aListElementTagName, - splitListItemParentResult.AtNextContent(), - [](Element& aListElement) -> nsresult { return NS_OK; }); + splitListItemParentResult.AtNextContent()); if (maybeNewListElement.isErr()) { NS_WARNING( "HTMLEditor::CreateAndInsertElement(WithTransaction::Yes) " @@ -3366,8 +3362,7 @@ EditActionResult HTMLEditor::ChangeSelectedHardLinesToList( prevListItem = nullptr; Result, nsresult> newListElementOrError = InsertElementWithSplittingAncestorsWithTransaction( - aListElementTagName, atContent, BRElementNextToSplitPoint::Keep, - [](Element& aListElement) -> nsresult { return NS_OK; }); + aListElementTagName, atContent, BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newListElementOrError.isErr())) { NS_WARNING( nsPrintfCString( @@ -3689,8 +3684,7 @@ nsresult HTMLEditor::FormatBlockContainerWithTransaction(nsAtom& blockType) { // Make sure we can put a block here. Result, nsresult> newBlockElementOrError = InsertElementWithSplittingAncestorsWithTransaction( - blockType, pointToInsertBlock, BRElementNextToSplitPoint::Keep, - [](Element& aBlockElement) -> nsresult { return NS_OK; }); + blockType, pointToInsertBlock, BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newBlockElementOrError.isErr())) { NS_WARNING( nsPrintfCString( @@ -3895,8 +3889,7 @@ nsresult HTMLEditor::IndentListChild(RefPtr* aCurList, Result, nsresult> newListElementOrError = InsertElementWithSplittingAncestorsWithTransaction( MOZ_KnownLive(*containerName), aCurPoint, - BRElementNextToSplitPoint::Keep, - [](Element& aListElement) -> nsresult { return NS_OK; }); + BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newListElementOrError.isErr())) { NS_WARNING( nsPrintfCString( @@ -4058,8 +4051,7 @@ nsresult HTMLEditor::HandleCSSIndentAtSelectionInternal() { Result, nsresult> newDivElementOrError = InsertElementWithSplittingAncestorsWithTransaction( *nsGkAtoms::div, atStartOfSelection, - BRElementNextToSplitPoint::Keep, - [](Element& aDivElement) -> nsresult { return NS_OK; }); + BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newDivElementOrError.isErr())) { NS_WARNING( "HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction(" @@ -4155,8 +4147,7 @@ nsresult HTMLEditor::HandleCSSIndentAtSelectionInternal() { Result, nsresult> newDivElementOrError = InsertElementWithSplittingAncestorsWithTransaction( - *nsGkAtoms::div, atContent, BRElementNextToSplitPoint::Keep, - [](Element& aDivElement) -> nsresult { return NS_OK; }); + *nsGkAtoms::div, atContent, BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newDivElementOrError.isErr())) { NS_WARNING( "HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction(" @@ -4267,8 +4258,7 @@ nsresult HTMLEditor::HandleHTMLIndentAtSelectionInternal() { Result, nsresult> newBlockQuoteElementOrError = InsertElementWithSplittingAncestorsWithTransaction( *nsGkAtoms::blockquote, atStartOfSelection, - BRElementNextToSplitPoint::Keep, - [](Element& aBlockquoteElement) -> nsresult { return NS_OK; }); + BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newBlockQuoteElementOrError.isErr())) { NS_WARNING( "HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction(" @@ -4372,8 +4362,7 @@ nsresult HTMLEditor::HandleHTMLIndentAtSelectionInternal() { Result, nsresult> newListElementOrError = InsertElementWithSplittingAncestorsWithTransaction( MOZ_KnownLive(*containerName), atListItem, - BRElementNextToSplitPoint::Keep, - [](Element& aListElement) -> nsresult { return NS_OK; }); + BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newListElementOrError.isErr())) { NS_WARNING(nsPrintfCString("HTMLEditor::" "InsertElementWithSplittingAncestorsWithTr" @@ -4421,8 +4410,7 @@ nsresult HTMLEditor::HandleHTMLIndentAtSelectionInternal() { Result, nsresult> newBlockQuoteElementOrError = InsertElementWithSplittingAncestorsWithTransaction( *nsGkAtoms::blockquote, atContent, - BRElementNextToSplitPoint::Keep, - [](Element& aBlockquoteElement) -> nsresult { return NS_OK; }); + BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newBlockQuoteElementOrError.isErr())) { NS_WARNING( "HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction(" @@ -5426,8 +5414,7 @@ EditActionResult HTMLEditor::AlignContentsAtSelectionWithEmptyDivElement( Result, nsresult> newDivElementOrError = InsertElementWithSplittingAncestorsWithTransaction( *nsGkAtoms::div, atStartOfSelection, - BRElementNextToSplitPoint::Delete, - [](Element& aDivElement) -> nsresult { return NS_OK; }); + BRElementNextToSplitPoint::Delete); if (newDivElementOrError.isErr()) { NS_WARNING( "HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction(" @@ -5603,8 +5590,7 @@ nsresult HTMLEditor::AlignNodesAndDescendants( Result, nsresult> newDivElementOrError = InsertElementWithSplittingAncestorsWithTransaction( - *nsGkAtoms::div, atContent, BRElementNextToSplitPoint::Keep, - [](Element& aDivElement) -> nsresult { return NS_OK; }); + *nsGkAtoms::div, atContent, BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newDivElementOrError.isErr())) { NS_WARNING( "HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction(" @@ -7502,8 +7488,8 @@ nsresult HTMLEditor::HandleInsertParagraphInListItemElement( Result, nsresult> maybeNewListItemElement = CreateAndInsertElement( WithTransaction::Yes, - MOZ_KnownLive(*nextDefinitionListItemTagName), atNextListItem, - [](Element& aListItemElement) -> nsresult { return NS_OK; }); + MOZ_KnownLive(*nextDefinitionListItemTagName), + atNextListItem); if (maybeNewListItemElement.isErr()) { NS_WARNING( "HTMLEditor::CreateAndInsertElement(WithTransaction::Yes) " @@ -7634,8 +7620,7 @@ nsresult HTMLEditor::MoveNodesIntoNewBlockquoteElement( Result, nsresult> newBlockQuoteElementOrError = InsertElementWithSplittingAncestorsWithTransaction( *nsGkAtoms::blockquote, EditorDOMPoint(content), - BRElementNextToSplitPoint::Keep, - [](Element& aBlockquoteElement) -> nsresult { return NS_OK; }); + BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newBlockQuoteElementOrError.isErr())) { NS_WARNING( "HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction(" @@ -7885,8 +7870,7 @@ nsresult HTMLEditor::CreateOrChangeBlockContainerElement( // Make sure we can put a block here Result, nsresult> newBlockElementOrError = InsertElementWithSplittingAncestorsWithTransaction( - aBlockTag, atContent, BRElementNextToSplitPoint::Keep, - [](Element& aBlockElement) -> nsresult { return NS_OK; }); + aBlockTag, atContent, BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newBlockElementOrError.isErr())) { NS_WARNING( nsPrintfCString( @@ -7926,8 +7910,7 @@ nsresult HTMLEditor::CreateOrChangeBlockContainerElement( // block for it. Result, nsresult> newBlockElementOrError = InsertElementWithSplittingAncestorsWithTransaction( - aBlockTag, atContent, BRElementNextToSplitPoint::Keep, - [](Element& aBlockElement) -> nsresult { return NS_OK; }); + aBlockTag, atContent, BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newBlockElementOrError.isErr())) { NS_WARNING( nsPrintfCString( @@ -7975,8 +7958,7 @@ nsresult HTMLEditor::CreateOrChangeBlockContainerElement( if (!curBlock) { Result, nsresult> newBlockElementOrError = InsertElementWithSplittingAncestorsWithTransaction( - aBlockTag, atContent, BRElementNextToSplitPoint::Keep, - [](Element& aBlockElement) -> nsresult { return NS_OK; }); + aBlockTag, atContent, BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newBlockElementOrError.isErr())) { NS_WARNING(nsPrintfCString("HTMLEditor::" "InsertElementWithSplittingAncestorsWithTr" @@ -9741,8 +9723,7 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition( // Make sure we can put a block here. Result, nsresult> newDivElementOrError = InsertElementWithSplittingAncestorsWithTransaction( - *nsGkAtoms::div, atCaret, BRElementNextToSplitPoint::Keep, - [](Element& aDivElement) -> nsresult { return NS_OK; }); + *nsGkAtoms::div, atCaret, BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newDivElementOrError.isErr())) { NS_WARNING( "HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction(" @@ -9833,8 +9814,7 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition( // element with splitting the ancestors. Result, nsresult> newDivElementOrError = InsertElementWithSplittingAncestorsWithTransaction( - *nsGkAtoms::div, atContent, BRElementNextToSplitPoint::Keep, - [](Element& aDivElement) -> nsresult { return NS_OK; }); + *nsGkAtoms::div, atContent, BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newDivElementOrError.isErr())) { NS_WARNING( "HTMLEditor::" @@ -9846,10 +9826,9 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition( targetDivElement = newDivElementOrError.unwrap(); } Result, nsresult> maybeNewListElement = - CreateAndInsertElement( - WithTransaction::Yes, MOZ_KnownLive(*ULOrOLOrDLTagName), - EditorDOMPoint::AtEndOf(targetDivElement), - [](Element& aListElement) -> nsresult { return NS_OK; }); + CreateAndInsertElement(WithTransaction::Yes, + MOZ_KnownLive(*ULOrOLOrDLTagName), + EditorDOMPoint::AtEndOf(targetDivElement)); if (maybeNewListElement.isErr()) { NS_WARNING( "HTMLEditor::CreateAndInsertElement(WithTransaction::Yes) " @@ -9916,8 +9895,7 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition( // element with splitting the ancestors. Result, nsresult> newDivElementOrError = InsertElementWithSplittingAncestorsWithTransaction( - *nsGkAtoms::div, atContent, BRElementNextToSplitPoint::Keep, - [](Element& aDivElement) -> nsresult { return NS_OK; }); + *nsGkAtoms::div, atContent, BRElementNextToSplitPoint::Keep); if (MOZ_UNLIKELY(newDivElementOrError.isErr())) { NS_WARNING( "HTMLEditor::" @@ -9930,10 +9908,9 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition( } // XXX So, createdListElement may be set to a non-list element. Result, nsresult> maybeNewListElement = - CreateAndInsertElement( - WithTransaction::Yes, MOZ_KnownLive(*containerName), - EditorDOMPoint::AtEndOf(targetDivElement), - [](Element& aListElement) -> nsresult { return NS_OK; }); + CreateAndInsertElement(WithTransaction::Yes, + MOZ_KnownLive(*containerName), + EditorDOMPoint::AtEndOf(targetDivElement)); if (maybeNewListElement.isErr()) { NS_WARNING( "HTMLEditor::CreateAndInsertElement(WithTransaction::Yes) " @@ -9975,8 +9952,7 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition( // and to contain all selected nodes. Result, nsresult> newDivElementOrError = InsertElementWithSplittingAncestorsWithTransaction( - *nsGkAtoms::div, atContent, BRElementNextToSplitPoint::Keep, - [](Element& aDivElement) -> nsresult { return NS_OK; }); + *nsGkAtoms::div, atContent, BRElementNextToSplitPoint::Keep); if (newDivElementOrError.isErr()) { NS_WARNING( "HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction(" diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index 5f88d473cc69..8508b355f83b 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -3668,8 +3668,7 @@ Result, nsresult> HTMLEditor::InsertBRElement( MOZ_ASSERT(maybePointToInsert.inspect().IsSetAndValid()); Result, nsresult> maybeNewBRElement = CreateAndInsertElement( - aWithTransaction, *nsGkAtoms::br, maybePointToInsert.inspect(), - [](Element& aBRElement) -> nsresult { return NS_OK; }); + aWithTransaction, *nsGkAtoms::br, maybePointToInsert.inspect()); if (maybeNewBRElement.isErr()) { NS_WARNING(nsPrintfCString("HTMLEditor::CreateAndInsertElement(%s) failed", ToString(aWithTransaction).c_str()) diff --git a/editor/libeditor/HTMLEditor.h b/editor/libeditor/HTMLEditor.h index a09c6963ad3f..080f9c42f256 100644 --- a/editor/libeditor/HTMLEditor.h +++ b/editor/libeditor/HTMLEditor.h @@ -1505,9 +1505,12 @@ class HTMLEditor final : public EditorBase, * @return The created new element node or an error. */ [[nodiscard]] MOZ_CAN_RUN_SCRIPT Result, nsresult> - CreateAndInsertElement(WithTransaction aWithTransaction, nsAtom& aTagName, - const EditorDOMPoint& aPointToInsert, - const std::function& aInitializer); + CreateAndInsertElement( + WithTransaction aWithTransaction, nsAtom& aTagName, + const EditorDOMPoint& aPointToInsert, + const std::function& aInitializer = [](Element&) { + return NS_OK; + }); /** * MaybeSplitAncestorsForInsertWithTransaction() does nothing if container of @@ -1555,7 +1558,9 @@ class HTMLEditor final : public EditorBase, InsertElementWithSplittingAncestorsWithTransaction( nsAtom& aTagName, const EditorDOMPoint& aPointToInsert, BRElementNextToSplitPoint aBRElementNextToSplitPoint, - const std::function& aInitializer); + const std::function& aInitializer = [](Element&) { + return NS_OK; + }); /** * SplitRangeOffFromBlock() splits aBlockElement at two points, before @@ -3435,7 +3440,8 @@ class HTMLEditor final : public EditorBase, */ MOZ_CAN_RUN_SCRIPT Result, nsresult> DeleteSelectionAndCreateElement( - nsAtom& aTag, const std::function& aInitializer); + nsAtom& aTag, const std::function& aInitializer = + [](Element&) { return NS_OK; }); /** * This method first deletes the selection, if it's not collapsed. Then if