forked from mirrors/gecko-dev
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
This commit is contained in:
parent
75a4321f48
commit
c98a4265f6
3 changed files with 44 additions and 63 deletions
|
|
@ -3051,14 +3051,11 @@ EditActionResult HTMLEditor::ChangeSelectedHardLinesToList(
|
|||
// MOZ_CAN_RUN_SCRIPT_BOUNDARY due to bug 1758868
|
||||
[&](Element& aListElement) MOZ_CAN_RUN_SCRIPT_BOUNDARY {
|
||||
Result<RefPtr<Element>, 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<RefPtr<Element>, nsresult> maybeNewListElement =
|
||||
CreateAndInsertElement(
|
||||
WithTransaction::Yes, aListElementTagName,
|
||||
splitListItemParentResult.AtNextContent<EditorDOMPoint>(),
|
||||
[](Element& aListElement) -> nsresult { return NS_OK; });
|
||||
splitListItemParentResult.AtNextContent<EditorDOMPoint>());
|
||||
if (maybeNewListElement.isErr()) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::CreateAndInsertElement(WithTransaction::Yes) "
|
||||
|
|
@ -3366,8 +3362,7 @@ EditActionResult HTMLEditor::ChangeSelectedHardLinesToList(
|
|||
prevListItem = nullptr;
|
||||
Result<RefPtr<Element>, 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<RefPtr<Element>, 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<Element>* aCurList,
|
|||
Result<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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<RefPtr<Element>, 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("
|
||||
|
|
|
|||
|
|
@ -3668,8 +3668,7 @@ Result<RefPtr<Element>, nsresult> HTMLEditor::InsertBRElement(
|
|||
MOZ_ASSERT(maybePointToInsert.inspect().IsSetAndValid());
|
||||
|
||||
Result<RefPtr<Element>, 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())
|
||||
|
|
|
|||
|
|
@ -1505,9 +1505,12 @@ class HTMLEditor final : public EditorBase,
|
|||
* @return The created new element node or an error.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<RefPtr<Element>, nsresult>
|
||||
CreateAndInsertElement(WithTransaction aWithTransaction, nsAtom& aTagName,
|
||||
const EditorDOMPoint& aPointToInsert,
|
||||
const std::function<nsresult(Element&)>& aInitializer);
|
||||
CreateAndInsertElement(
|
||||
WithTransaction aWithTransaction, nsAtom& aTagName,
|
||||
const EditorDOMPoint& aPointToInsert,
|
||||
const std::function<nsresult(Element&)>& 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<nsresult(Element&)>& aInitializer);
|
||||
const std::function<nsresult(Element&)>& 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<RefPtr<Element>, nsresult>
|
||||
DeleteSelectionAndCreateElement(
|
||||
nsAtom& aTag, const std::function<nsresult(Element&)>& aInitializer);
|
||||
nsAtom& aTag, const std::function<nsresult(Element&)>& aInitializer =
|
||||
[](Element&) { return NS_OK; });
|
||||
|
||||
/**
|
||||
* This method first deletes the selection, if it's not collapsed. Then if
|
||||
|
|
|
|||
Loading…
Reference in a new issue