зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1762115 - part 10: Make `HTMLEditor::InsertBRElement` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D144653
This commit is contained in:
Родитель
ee27c4910b
Коммит
57b3cd700f
|
@ -637,7 +637,7 @@ class EditorDOMPointBase final {
|
|||
const StrongPtr<ContainerType>& aContainer,
|
||||
InterlinePosition aInterlinePosition = InterlinePosition::Undefined) {
|
||||
MOZ_ASSERT(aContainer.get());
|
||||
return After(*aContainer.get());
|
||||
return After(*aContainer.get(), aInterlinePosition);
|
||||
}
|
||||
template <typename PT, typename CT>
|
||||
MOZ_NEVER_INLINE_DEBUG static SelfType After(
|
||||
|
|
|
@ -692,14 +692,20 @@ nsresult HTMLEditor::SetPositionToAbsolute(Element& aElement) {
|
|||
if (parentNode->GetChildCount() != 1) {
|
||||
return NS_OK;
|
||||
}
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
CreateElementResult insertBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes, EditorDOMPoint(parentNode, 0u));
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
return NS_OK;
|
||||
// XXX Is this intentional selection change?
|
||||
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
|
||||
*this, {SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt});
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"CreateElementResult::SuggestCaretPointTo() failed");
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult HTMLEditor::SetPositionToStatic(Element& aElement) {
|
||||
|
|
|
@ -1229,18 +1229,21 @@ EditActionResult HTMLEditor::HandleInsertText(
|
|||
|
||||
// is it a return?
|
||||
if (subStr.Equals(newlineStr)) {
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElement(WithTransaction::Yes, currentPoint,
|
||||
nsIEditor::eNone);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
CreateElementResult insertBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes, currentPoint);
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::InsertBRElement(WithTransaction::Yes, eNone) "
|
||||
"failed");
|
||||
return EditActionHandled(resultOfInsertingBRElement.unwrapErr());
|
||||
"HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return EditActionHandled(insertBRElementResult.unwrapErr());
|
||||
}
|
||||
// We don't want to update selection here because we've blocked
|
||||
// InsertNodeTransaction updating selection with
|
||||
// dontChangeMySelection.
|
||||
insertBRElementResult.IgnoreCaretPointSuggestion();
|
||||
MOZ_ASSERT(!AllowsTransactionsToChangeSelection());
|
||||
|
||||
pos++;
|
||||
RefPtr<Element> brElement(
|
||||
resultOfInsertingBRElement.unwrap().forget());
|
||||
RefPtr<Element> brElement = insertBRElementResult.UnwrapNewNode();
|
||||
if (brElement->GetNextSibling()) {
|
||||
pointToInsert.Set(brElement->GetNextSibling());
|
||||
} else {
|
||||
|
@ -1447,16 +1450,17 @@ nsresult HTMLEditor::InsertLineBreakAsSubAction() {
|
|||
if (GetDefaultParagraphSeparator() == ParagraphSeparator::br ||
|
||||
!HTMLEditUtils::ShouldInsertLinefeedCharacter(atStartOfSelection,
|
||||
*editingHost)) {
|
||||
// InsertBRElement() will set selection after the new <br> element.
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElement(WithTransaction::Yes, atStartOfSelection,
|
||||
nsIEditor::eNext);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
CreateElementResult insertBRElementResult = InsertBRElement(
|
||||
WithTransaction::Yes, atStartOfSelection, nsIEditor::eNext);
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
return NS_OK;
|
||||
nsresult rv = insertBRElementResult.SuggestCaretPointTo(*this, {});
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"CreateElementResult::SuggestCaretPointTo() failed");
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult rv = EnsureNoPaddingBRElementForEmptyEditor();
|
||||
|
@ -1798,13 +1802,25 @@ EditActionResult HTMLEditor::InsertParagraphSeparatorAsSubAction() {
|
|||
AutoEditorDOMPointChildInvalidator lockOffset(atStartOfSelection);
|
||||
EditorDOMPoint endOfBlockParent;
|
||||
endOfBlockParent.SetToEndOf(editableBlockElement);
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
const CreateElementResult insertBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes, endOfBlockParent);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return EditActionIgnored(resultOfInsertingBRElement.unwrapErr());
|
||||
return EditActionIgnored(insertBRElementResult.unwrapErr());
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
// XXX Is this intentional selection change?
|
||||
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
|
||||
*this, {SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
||||
SuggestCaret::AndIgnoreTrivialError});
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("CreateElementResult::SuggestCaretPointTo() failed");
|
||||
return EditActionHandled(rv);
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
|
||||
"CreateElementResult::SuggestCaretPointTo() failed, but ignored");
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
}
|
||||
|
||||
RefPtr<Element> maybeNonEditableListItem =
|
||||
|
@ -1923,14 +1939,17 @@ CreateElementResult HTMLEditor::HandleInsertBRElement(
|
|||
// First, insert a <br> element.
|
||||
RefPtr<Element> brElement;
|
||||
if (IsInPlaintextMode()) {
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
CreateElementResult insertBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes, aPointToBreak);
|
||||
if (MOZ_UNLIKELY(resultOfInsertingBRElement.isErr())) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return CreateElementResult(resultOfInsertingBRElement.unwrapErr());
|
||||
return CreateElementResult(insertBRElementResult.unwrapErr());
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
brElement = resultOfInsertingBRElement.unwrap().forget();
|
||||
// We'll return with suggesting new caret position and nobody refers
|
||||
// selection after here. So we don't need to update selection here.
|
||||
insertBRElementResult.IgnoreCaretPointSuggestion();
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
brElement = insertBRElementResult.UnwrapNewNode();
|
||||
} else {
|
||||
EditorDOMPoint pointToBreak(aPointToBreak);
|
||||
WSRunScanner wsRunScanner(&aEditingHost, pointToBreak);
|
||||
|
@ -2140,15 +2159,17 @@ nsresult HTMLEditor::HandleInsertLinefeed(const EditorDOMPoint& aPointToBreak,
|
|||
&pointToInsert);
|
||||
AutoTrackDOMPoint trackingNewCaretPosition(RangeUpdaterRef(),
|
||||
&newCaretPosition);
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElement(WithTransaction::Yes, newCaretPosition,
|
||||
nsIEditor::ePrevious);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
CreateElementResult insertBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes, newCaretPosition);
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
// We're tracking next caret position with newCaretPosition. Therefore,
|
||||
// we don't need to update selection here.
|
||||
insertBRElementResult.IgnoreCaretPointSuggestion();
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
}
|
||||
caretAfterInsert = newCaretPosition.To<EditorRawDOMPoint>();
|
||||
}
|
||||
|
@ -2277,29 +2298,34 @@ HTMLEditor::HandleInsertParagraphInMailCiteElement(
|
|||
leftCiteElement->GetPrimaryFrame()->IsBlockFrameOrSubclass()) {
|
||||
nsIContent* lastChild = leftCiteElement->GetLastChild();
|
||||
if (lastChild && !lastChild->IsHTMLElement(nsGkAtoms::br)) {
|
||||
// We ignore the result here.
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingInvisibleBRElement =
|
||||
const CreateElementResult insertInvisibleBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes,
|
||||
EditorDOMPoint::AtEndOf(*leftCiteElement));
|
||||
if (MOZ_UNLIKELY(resultOfInsertingInvisibleBRElement.isErr())) {
|
||||
if (insertInvisibleBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return Err(resultOfInsertingInvisibleBRElement.unwrapErr());
|
||||
return Err(insertInvisibleBRElementResult.unwrapErr());
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingInvisibleBRElement.inspect());
|
||||
// We don't need to update selection here because we'll do another
|
||||
// InsertBRElement call soon.
|
||||
insertInvisibleBRElementResult.IgnoreCaretPointSuggestion();
|
||||
MOZ_ASSERT(insertInvisibleBRElementResult.GetNewNode());
|
||||
}
|
||||
}
|
||||
|
||||
// In most cases, <br> should be inserted after current cite. However, if
|
||||
// left cite hasn't been created because the split point was start of the
|
||||
// cite node, <br> should be inserted before the current cite.
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
CreateElementResult insertBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes,
|
||||
splitCiteElementResult.AtSplitPoint<EditorDOMPoint>());
|
||||
if (MOZ_UNLIKELY(resultOfInsertingBRElement.isErr())) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return Err(resultOfInsertingBRElement.unwrapErr());
|
||||
return Err(insertBRElementResult.unwrapErr());
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
// We'll return with suggesting caret position. Therefore, we don't need
|
||||
// to update selection here.
|
||||
insertBRElementResult.IgnoreCaretPointSuggestion();
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
|
||||
// if aMailCiteElement wasn't a block, we might also want another break before
|
||||
// it. We need to examine the content both before the br we just added and
|
||||
|
@ -2309,7 +2335,7 @@ HTMLEditor::HandleInsertParagraphInMailCiteElement(
|
|||
if (HTMLEditUtils::IsInlineElement(aMailCiteElement)) {
|
||||
nsresult rvOfInsertingBRElement = [&]() MOZ_CAN_RUN_SCRIPT {
|
||||
EditorDOMPoint pointToCreateNewBRElement(
|
||||
resultOfInsertingBRElement.inspect());
|
||||
insertBRElementResult.GetNewNode());
|
||||
|
||||
// XXX Cannot we replace this complicated check with just a call of
|
||||
// HTMLEditUtils::IsVisibleBRElement with
|
||||
|
@ -2347,17 +2373,18 @@ HTMLEditor::HandleInsertParagraphInMailCiteElement(
|
|||
.ReachedCurrentBlockBoundary()) {
|
||||
return NS_SUCCESS_DOM_NO_OPERATION;
|
||||
}
|
||||
Result<RefPtr<Element>, nsresult> result =
|
||||
CreateElementResult insertBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes, pointToCreateNewBRElement);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return result.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(result.inspect());
|
||||
insertBRElementResult.IgnoreCaretPointSuggestion();
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
return NS_OK;
|
||||
}();
|
||||
|
||||
if (MOZ_UNLIKELY(NS_FAILED(rvOfInsertingBRElement))) {
|
||||
if (NS_FAILED(rvOfInsertingBRElement)) {
|
||||
NS_WARNING(
|
||||
"Failed to insert additional <br> element before the inline right "
|
||||
"mail-cite element");
|
||||
|
@ -2369,7 +2396,7 @@ HTMLEditor::HandleInsertParagraphInMailCiteElement(
|
|||
// MOZ_KnownLive(leftCiteElement) because it's grabbed by
|
||||
// splitCiteElementResult.
|
||||
nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*leftCiteElement));
|
||||
if (MOZ_UNLIKELY(NS_WARN_IF(Destroyed()))) {
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -2382,7 +2409,7 @@ HTMLEditor::HandleInsertParagraphInMailCiteElement(
|
|||
// MOZ_KnownLive(rightCiteElement) because it's grabbed by
|
||||
// splitCiteElementResult.
|
||||
nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*rightCiteElement));
|
||||
if (MOZ_UNLIKELY(NS_WARN_IF(Destroyed()))) {
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -2391,11 +2418,11 @@ HTMLEditor::HandleInsertParagraphInMailCiteElement(
|
|||
}
|
||||
}
|
||||
|
||||
if (MOZ_UNLIKELY(!resultOfInsertingBRElement.inspect()->GetParent())) {
|
||||
if (MOZ_UNLIKELY(!insertBRElementResult.GetNewNode()->GetParent())) {
|
||||
NS_WARNING("Inserted <br> shouldn't become an orphan node");
|
||||
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
}
|
||||
return EditorDOMPoint(resultOfInsertingBRElement.inspect());
|
||||
return EditorDOMPoint(insertBRElementResult.GetNewNode());
|
||||
}
|
||||
|
||||
HTMLEditor::CharPointData
|
||||
|
@ -2906,16 +2933,17 @@ nsresult HTMLEditor::InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElement(WithTransaction::Yes, aPointToInsert,
|
||||
nsIEditor::ePrevious);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
CreateElementResult insertBRElementResult = InsertBRElement(
|
||||
WithTransaction::Yes, aPointToInsert, nsIEditor::ePrevious);
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::InsertBRElement(WithTransaction::Yes, ePrevious) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
return NS_OK;
|
||||
nsresult rv = insertBRElementResult.SuggestCaretPointTo(*this, {});
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"CreateElementResult::SuggestCaretPointTo() failed");
|
||||
return rv;
|
||||
}
|
||||
|
||||
EditActionResult HTMLEditor::MakeOrChangeListAndListItemAsSubAction(
|
||||
|
@ -3756,20 +3784,19 @@ nsresult HTMLEditor::FormatBlockContainerWithTransaction(nsAtom& blockType) {
|
|||
return splitNodeResult.unwrapErr();
|
||||
}
|
||||
// Put a <br> element at the split point
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElement(WithTransaction::Yes,
|
||||
splitNodeResult.AtSplitPoint<EditorDOMPoint>());
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
const CreateElementResult insertBRElementResult = InsertBRElement(
|
||||
WithTransaction::Yes, splitNodeResult.AtSplitPoint<EditorDOMPoint>());
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
// Don't restore the selection
|
||||
restoreSelectionLater.Abort();
|
||||
// Put selection at the split point
|
||||
splitNodeResult.IgnoreCaretPointSuggestion();
|
||||
nsresult rv = CollapseSelectionTo(
|
||||
EditorRawDOMPoint(resultOfInsertingBRElement.inspect()));
|
||||
EditorRawDOMPoint(insertBRElementResult.GetNewNode()));
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"EditorBase::CollapseSelectionTo() failed");
|
||||
return rv;
|
||||
|
@ -7284,17 +7311,19 @@ HTMLEditor::HandleInsertParagraphInHeadingElement(
|
|||
const auto withTransaction =
|
||||
aDivOrParagraphElement.IsInComposedDoc() ? WithTransaction::Yes
|
||||
: WithTransaction::No;
|
||||
Result<RefPtr<Element>, nsresult> brElementOrError =
|
||||
CreateElementResult insertBRElementResult =
|
||||
aHTMLEditor.InsertBRElement(
|
||||
withTransaction,
|
||||
EditorDOMPoint(&aDivOrParagraphElement, 0u));
|
||||
if (brElementOrError.isErr()) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING(
|
||||
nsPrintfCString("HTMLEditor::InsertBRElement(%s) failed",
|
||||
ToString(withTransaction).c_str())
|
||||
.get());
|
||||
return brElementOrError.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
// We'll update selection after inserting the new paragraph.
|
||||
insertBRElementResult.IgnoreCaretPointSuggestion();
|
||||
return NS_OK;
|
||||
});
|
||||
if (createNewParagraphElementResult.isErr()) {
|
||||
|
@ -7517,20 +7546,31 @@ EditActionResult HTMLEditor::HandleInsertParagraphInParagraph(
|
|||
return EditActionResult(NS_OK);
|
||||
}
|
||||
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
CreateElementResult insertBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes, pointToInsertBR);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return EditActionResult(resultOfInsertingBRElement.unwrapErr());
|
||||
return EditActionResult(insertBRElementResult.unwrapErr());
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
|
||||
*this, {SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
||||
SuggestCaret::AndIgnoreTrivialError});
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("CreateElementResult::SuggestCaretPointTo() failed");
|
||||
return EditActionResult(rv);
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
|
||||
"CreateElementResult::SuggestCaretPointTo() failed, but ignored");
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
if (splitAfterNewBR) {
|
||||
// We split the parent after the br we've just inserted.
|
||||
pointToSplitParentDivOrP.SetAfter(resultOfInsertingBRElement.inspect());
|
||||
pointToSplitParentDivOrP.SetAfter(insertBRElementResult.GetNewNode());
|
||||
NS_WARNING_ASSERTION(pointToSplitParentDivOrP.IsSet(),
|
||||
"Failed to set after the new <br>");
|
||||
}
|
||||
brContent = resultOfInsertingBRElement.unwrap().forget();
|
||||
brContent = insertBRElementResult.UnwrapNewNode();
|
||||
}
|
||||
EditActionResult result(
|
||||
SplitParagraph(aParentDivOrP, pointToSplitParentDivOrP, brContent));
|
||||
|
@ -7754,17 +7794,19 @@ HTMLEditor::HandleInsertParagraphInListItemElement(
|
|||
aDivOrParagraphElement.IsInComposedDoc()
|
||||
? WithTransaction::Yes
|
||||
: WithTransaction::No;
|
||||
Result<RefPtr<Element>, nsresult> brElementOrError =
|
||||
CreateElementResult insertBRElementResult =
|
||||
aHTMLEditor.InsertBRElement(
|
||||
withTransaction,
|
||||
EditorDOMPoint(&aDivOrParagraphElement, 0u));
|
||||
if (brElementOrError.isErr()) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING(
|
||||
nsPrintfCString("HTMLEditor::InsertBRElement(%s) failed",
|
||||
ToString(withTransaction).c_str())
|
||||
.get());
|
||||
return brElementOrError.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
// We'll update selection after inserting the paragraph.
|
||||
insertBRElementResult.IgnoreCaretPointSuggestion();
|
||||
return NS_OK;
|
||||
});
|
||||
if (createNewParagraphElementResult.isErr()) {
|
||||
|
@ -9337,6 +9379,7 @@ nsresult HTMLEditor::RemoveEmptyNodesIn(nsRange& aRange) {
|
|||
|
||||
// Now delete the empty mailcites. This is a separate step because we want
|
||||
// to pull out any br's and preserve them.
|
||||
EditorDOMPoint pointToPutCaret;
|
||||
for (OwningNonNull<nsIContent>& emptyCite : arrayOfEmptyCites) {
|
||||
if (!HTMLEditUtils::IsEmptyNode(
|
||||
emptyCite, {EmptyCheckOption::TreatSingleBRElementAsVisible,
|
||||
|
@ -9344,13 +9387,18 @@ nsresult HTMLEditor::RemoveEmptyNodesIn(nsRange& aRange) {
|
|||
EmptyCheckOption::TreatTableCellAsVisible})) {
|
||||
// We are deleting a cite that has just a `<br>`. We want to delete cite,
|
||||
// but preserve `<br>`.
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
CreateElementResult insertBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes, EditorDOMPoint(emptyCite));
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
// XXX Is this intentional selection change?
|
||||
insertBRElementResult.MoveCaretPointTo(
|
||||
pointToPutCaret, *this,
|
||||
{SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt});
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
}
|
||||
// MOZ_KnownLive because 'arrayOfEmptyCites' is guaranteed to keep it alive.
|
||||
rv = DeleteNodeWithTransaction(MOZ_KnownLive(emptyCite));
|
||||
|
@ -9362,6 +9410,18 @@ nsresult HTMLEditor::RemoveEmptyNodesIn(nsRange& aRange) {
|
|||
return rv;
|
||||
}
|
||||
}
|
||||
// XXX Is this intentional selection change?
|
||||
if (pointToPutCaret.IsSet()) {
|
||||
nsresult rv = CollapseSelectionTo(pointToPutCaret);
|
||||
if (MOZ_UNLIKELY(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||
NS_WARNING(
|
||||
"EditorBase::CollapseSelectionTo() caused destroying the editor");
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
NS_SUCCEEDED(rv),
|
||||
"EditorBase::CollapseSelectionTo() failed, but ignored");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -9651,13 +9711,25 @@ nsresult HTMLEditor::InsertBRElementIfEmptyBlockElement(Element& aElement) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
CreateElementResult insertBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes, EditorDOMPoint(&aElement, 0u));
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
// XXX Is this intentional selection change?
|
||||
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
|
||||
*this, {SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
||||
SuggestCaret::AndIgnoreTrivialError});
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("CreateElementResult::SuggestCaretPointTo() failed");
|
||||
return rv;
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
|
||||
"CreateElementResult::SuggestCaretPointTo() failed, but ignored");
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -9821,14 +9893,25 @@ nsresult HTMLEditor::EnsureHardLineBeginsWithFirstChildOf(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElement(WithTransaction::Yes,
|
||||
EditorDOMPoint(&aRemovingContainerElement, 0u));
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
CreateElementResult insertBRElementResult = InsertBRElement(
|
||||
WithTransaction::Yes, EditorDOMPoint(&aRemovingContainerElement, 0u));
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
// XXX Is this intentional selection change?
|
||||
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
|
||||
*this, {SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
||||
SuggestCaret::AndIgnoreTrivialError});
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("CreateElementResult::SuggestCaretPointTo() failed");
|
||||
return rv;
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
|
||||
"CreateElementResult::SuggestCaretPointTo() failed, but ignored");
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -9858,14 +9941,24 @@ nsresult HTMLEditor::EnsureHardLineEndsWithLastChildOf(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElement(WithTransaction::Yes,
|
||||
EditorDOMPoint::AtEndOf(aRemovingContainerElement));
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
CreateElementResult insertBRElementResult = InsertBRElement(
|
||||
WithTransaction::Yes, EditorDOMPoint::AtEndOf(aRemovingContainerElement));
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
|
||||
*this, {SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
||||
SuggestCaret::AndIgnoreTrivialError});
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("CreateElementResult::SuggestCaretPointTo() failed");
|
||||
return rv;
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
|
||||
"CreateElementResult::SuggestCaretPointTo() failed, but ignored");
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -1894,16 +1894,18 @@ nsresult HTMLEditor::InsertElementAtSelectionAsAction(
|
|||
NS_WARNING_ASSERTION(advanced,
|
||||
"Failed to advance offset from inserted point");
|
||||
// Collapse selection to the new `<br>` element node after creating it.
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
const CreateElementResult insertBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes, insertedPoint, ePrevious);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::InsertBRElement(WithTransaction::Yes, ePrevious) failed");
|
||||
return EditorBase::ToGenericNSResult(
|
||||
resultOfInsertingBRElement.unwrapErr());
|
||||
return EditorBase::ToGenericNSResult(insertBRElementResult.unwrapErr());
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
return NS_OK;
|
||||
rv = insertBRElementResult.SuggestCaretPointTo(*this, {});
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"EditorBase::CollapseSelectionTo() failed");
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
return EditorBase::ToGenericNSResult(rv);
|
||||
}
|
||||
|
||||
EditorDOMPoint HTMLEditor::InsertNodeIntoProperAncestorWithTransaction(
|
||||
|
@ -3677,7 +3679,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::PrepareToInsertBRElement(
|
|||
return atNextContent;
|
||||
}
|
||||
|
||||
Result<RefPtr<Element>, nsresult> HTMLEditor::InsertBRElement(
|
||||
CreateElementResult HTMLEditor::InsertBRElement(
|
||||
WithTransaction aWithTransaction, const EditorDOMPoint& aPointToInsert,
|
||||
EDirection aSelect /* = eNone */) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
@ -3689,7 +3691,7 @@ Result<RefPtr<Element>, nsresult> HTMLEditor::InsertBRElement(
|
|||
nsPrintfCString("HTMLEditor::PrepareToInsertBRElement(%s) failed",
|
||||
ToString(aWithTransaction).c_str())
|
||||
.get());
|
||||
return Err(maybePointToInsert.unwrapErr());
|
||||
return CreateElementResult(maybePointToInsert.unwrapErr());
|
||||
}
|
||||
MOZ_ASSERT(maybePointToInsert.inspect().IsSetAndValid());
|
||||
|
||||
|
@ -3699,43 +3701,22 @@ Result<RefPtr<Element>, nsresult> HTMLEditor::InsertBRElement(
|
|||
NS_WARNING(nsPrintfCString("HTMLEditor::CreateAndInsertElement(%s) failed",
|
||||
ToString(aWithTransaction).c_str())
|
||||
.get());
|
||||
return Err(createNewBRElementResult.unwrapErr());
|
||||
return CreateElementResult(createNewBRElementResult.unwrapErr());
|
||||
}
|
||||
RefPtr<Element> newBRElement = createNewBRElementResult.UnwrapNewNode();
|
||||
MOZ_ASSERT(newBRElement);
|
||||
|
||||
createNewBRElementResult.IgnoreCaretPointSuggestion();
|
||||
switch (aSelect) {
|
||||
case eNext: {
|
||||
createNewBRElementResult.IgnoreCaretPointSuggestion();
|
||||
// Collapse selection after the <br> node.
|
||||
const auto afterBRElement = EditorRawDOMPoint::After(
|
||||
*newBRElement, InterlinePosition::StartOfNextLine);
|
||||
if (MOZ_UNLIKELY(!afterBRElement.IsSet())) {
|
||||
NS_WARNING("Setting point to after <br> element failed");
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
nsresult rv = CollapseSelectionTo(afterBRElement);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("EditorBase::CollapseSelectionTo() failed, but ignored");
|
||||
return Err(rv);
|
||||
}
|
||||
return newBRElement;
|
||||
const auto pointToPutCaret = EditorDOMPoint::After(
|
||||
*newBRElement, Selection::InterlinePosition::StartOfNextLine);
|
||||
return CreateElementResult(std::move(newBRElement), pointToPutCaret);
|
||||
}
|
||||
case ePrevious: {
|
||||
createNewBRElementResult.IgnoreCaretPointSuggestion();
|
||||
// Collapse selection at the <br> node.
|
||||
EditorRawDOMPoint atBRElement(newBRElement,
|
||||
InterlinePosition::StartOfNextLine);
|
||||
if (MOZ_UNLIKELY(!atBRElement.IsSet())) {
|
||||
NS_WARNING("Setting point to at <br> element failed");
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
nsresult rv = CollapseSelectionTo(atBRElement);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("EditorBase::CollapseSelectionTo() failed, but ignored");
|
||||
return Err(rv);
|
||||
}
|
||||
return newBRElement;
|
||||
const auto pointToPutCaret = EditorDOMPoint(
|
||||
newBRElement, Selection::InterlinePosition::StartOfNextLine);
|
||||
return CreateElementResult(std::move(newBRElement), pointToPutCaret);
|
||||
}
|
||||
default:
|
||||
NS_WARNING(
|
||||
|
@ -3743,19 +3724,8 @@ Result<RefPtr<Element>, nsresult> HTMLEditor::InsertBRElement(
|
|||
"by itself");
|
||||
[[fallthrough]];
|
||||
case eNone:
|
||||
// XXX Is this expecgted behavior?
|
||||
nsresult rv = createNewBRElementResult.SuggestCaretPointTo(
|
||||
*this, {SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
||||
SuggestCaret::AndIgnoreTrivialError});
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("CreateElementResult::SuggestCaretPointTo() failed");
|
||||
return Err(rv);
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
|
||||
"CreateElementResult::SuggestCaretPointTo() failed, but ignored");
|
||||
return newBRElement;
|
||||
return CreateElementResult(std::move(newBRElement),
|
||||
createNewBRElementResult.UnwrapCaretPoint());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4281,6 +4251,7 @@ nsresult HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement) {
|
|||
// sibling and first child to determine if we need a leading br, and compare
|
||||
// following sibling and last child to determine if we need a trailing br.
|
||||
|
||||
EditorDOMPoint pointToPutCaret;
|
||||
if (nsCOMPtr<nsIContent> child = HTMLEditUtils::GetFirstChild(
|
||||
aElement, {WalkTreeOption::IgnoreNonEditableNode})) {
|
||||
// The case of aNode not being empty. We need a br at start unless:
|
||||
|
@ -4295,15 +4266,16 @@ nsresult HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement) {
|
|||
!previousSibling->IsHTMLElement(nsGkAtoms::br) &&
|
||||
!HTMLEditUtils::IsBlockElement(*child)) {
|
||||
// Insert br node
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElement(WithTransaction::Yes,
|
||||
EditorDOMPoint(&aElement, 0u));
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
CreateElementResult insertBRElementResult = InsertBRElement(
|
||||
WithTransaction::Yes, EditorDOMPoint(&aElement, 0u));
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
insertBRElementResult.MoveCaretPointTo(
|
||||
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4320,15 +4292,16 @@ nsresult HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement) {
|
|||
aElement, {WalkTreeOption::IgnoreNonEditableNode})) {
|
||||
if (!HTMLEditUtils::IsBlockElement(*lastChild) &&
|
||||
!lastChild->IsHTMLElement(nsGkAtoms::br)) {
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElement(WithTransaction::Yes,
|
||||
EditorDOMPoint::AtEndOf(aElement));
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
CreateElementResult insertBRElementResult = InsertBRElement(
|
||||
WithTransaction::Yes, EditorDOMPoint::AtEndOf(aElement));
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
insertBRElementResult.MoveCaretPointTo(
|
||||
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4347,20 +4320,34 @@ nsresult HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement) {
|
|||
aElement, {WalkTreeOption::IgnoreNonEditableNode})) {
|
||||
if (!HTMLEditUtils::IsBlockElement(*nextSibling) &&
|
||||
!nextSibling->IsHTMLElement(nsGkAtoms::br)) {
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElement(WithTransaction::Yes,
|
||||
EditorDOMPoint(&aElement, 0u));
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
CreateElementResult insertBRElementResult = InsertBRElement(
|
||||
WithTransaction::Yes, EditorDOMPoint(&aElement, 0u));
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
insertBRElementResult.MoveCaretPointTo(
|
||||
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// XXX Is this intentional selection change?
|
||||
if (pointToPutCaret.IsSet()) {
|
||||
nsresult rv = CollapseSelectionTo(pointToPutCaret);
|
||||
if (MOZ_UNLIKELY(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||
NS_WARNING(
|
||||
"EditorBase::CollapseSelectionTo() caused destroying the editor");
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
NS_SUCCEEDED(rv),
|
||||
"EditorBase::CollapseSelectionTo() failed, but ignored");
|
||||
}
|
||||
|
||||
// Now remove container
|
||||
nsresult rv = RemoveContainerWithTransaction(aElement);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
|
@ -5859,19 +5846,27 @@ HTMLEditor::CopyLastEditableChildStylesWithTransaction(Element& aPreviousBlock,
|
|||
return RefPtr<HTMLBRElement>();
|
||||
}
|
||||
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElement(WithTransaction::Yes,
|
||||
EditorDOMPoint(firstClonedElement, 0u));
|
||||
if (MOZ_UNLIKELY(NS_WARN_IF(Destroyed()))) {
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (MOZ_UNLIKELY(resultOfInsertingBRElement.isErr())) {
|
||||
CreateElementResult insertBRElementResult = InsertBRElement(
|
||||
WithTransaction::Yes, EditorDOMPoint(firstClonedElement, 0u));
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return Err(resultOfInsertingBRElement.unwrapErr());
|
||||
return Err(insertBRElementResult.unwrapErr());
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
// XXX Is this intentional selection change?
|
||||
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
|
||||
*this, {SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
||||
SuggestCaret::AndIgnoreTrivialError});
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("CreateElementResult::SuggestCaretPointTo() failed");
|
||||
return Err(rv);
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
|
||||
"CreateElementResult::SuggestCaretPointTo() failed, but ignored");
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
return RefPtr<HTMLBRElement>(
|
||||
HTMLBRElement::FromNode(resultOfInsertingBRElement.unwrap().get()));
|
||||
HTMLBRElement::FromNode(insertBRElementResult.GetNewNode()));
|
||||
}
|
||||
|
||||
nsresult HTMLEditor::GetElementOrigin(Element& aElement, int32_t& aX,
|
||||
|
|
|
@ -729,9 +729,8 @@ class HTMLEditor final : public EditorBase,
|
|||
}
|
||||
|
||||
/**
|
||||
* InsertBRElement() creates a <br> element and inserts it
|
||||
* before aPointToInsert. Then, tries to collapse selection at or after the
|
||||
* new <br> node if aSelect is not eNone.
|
||||
* InsertBRElement() creates a <br> element and inserts it before
|
||||
* aPointToInsert.
|
||||
*
|
||||
* @param aWithTransaction Whether the inserting is new element is undoable
|
||||
* or not. WithTransaction::No is useful only when
|
||||
|
@ -739,15 +738,16 @@ class HTMLEditor final : public EditorBase,
|
|||
* which has not been connected yet.
|
||||
* @param aPointToInsert The DOM point where should be <br> node inserted
|
||||
* before.
|
||||
* @param aSelect If eNone, this won't change selection.
|
||||
* If eNext, selection will be collapsed after
|
||||
* the <br> element.
|
||||
* If ePrevious, selection will be collapsed at
|
||||
* the <br> element.
|
||||
* @return The new <br> node. If failed to create new
|
||||
* <br> node, returns error.
|
||||
* @param aSelect If eNone, returns a point to put caret which is
|
||||
* suggested by InsertNodeTransaction.
|
||||
* If eNext, returns a point after the new <br>
|
||||
* element.
|
||||
* If ePrevious, returns a point at the new <br>
|
||||
* element.
|
||||
* @return The new <br> node and suggesting point to put
|
||||
* caret which respects aSelect.
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT Result<RefPtr<Element>, nsresult> InsertBRElement(
|
||||
MOZ_CAN_RUN_SCRIPT CreateElementResult InsertBRElement(
|
||||
WithTransaction aWithTransaction, const EditorDOMPoint& aPointToInsert,
|
||||
EDirection aSelect = eNone);
|
||||
|
||||
|
|
|
@ -5140,15 +5140,16 @@ nsresult HTMLEditor::DeleteMostAncestorMailCiteElementIfEmpty(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
CreateElementResult insertBRElementResult =
|
||||
InsertBRElement(WithTransaction::Yes, atEmptyMailCiteElement);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
insertBRElementResult.IgnoreCaretPointSuggestion();
|
||||
nsresult rv = CollapseSelectionTo(
|
||||
EditorRawDOMPoint(resultOfInsertingBRElement.inspect()));
|
||||
EditorRawDOMPoint(insertBRElementResult.GetNewNode()));
|
||||
if (MOZ_UNLIKELY(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||
NS_WARNING(
|
||||
"EditorBase::CollapseSelectionTo() caused destroying the editor");
|
||||
|
@ -5306,15 +5307,22 @@ HTMLEditor::AutoDeleteRangesHandler::AutoEmptyBlockAncestorDeleter::
|
|||
if (HTMLEditUtils::IsAnyListElement(atParentOfEmptyListItem.GetContainer())) {
|
||||
return RefPtr<Element>();
|
||||
}
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
aHTMLEditor.InsertBRElement(WithTransaction::Yes,
|
||||
atParentOfEmptyListItem);
|
||||
NS_WARNING_ASSERTION(
|
||||
resultOfInsertingBRElement.isOk(),
|
||||
"HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
MOZ_ASSERT_IF(resultOfInsertingBRElement.isOk(),
|
||||
resultOfInsertingBRElement.inspect());
|
||||
return resultOfInsertingBRElement;
|
||||
CreateElementResult insertBRElementResult = aHTMLEditor.InsertBRElement(
|
||||
WithTransaction::Yes, atParentOfEmptyListItem);
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return Err(insertBRElementResult.unwrapErr());
|
||||
}
|
||||
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
|
||||
aHTMLEditor, {SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
||||
SuggestCaret::AndIgnoreTrivialError});
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("CreateElementResult::SuggestCaretPointTo() failed");
|
||||
return Err(rv);
|
||||
}
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
return insertBRElementResult.UnwrapNewNode();
|
||||
}
|
||||
|
||||
Result<EditorDOMPoint, nsresult> HTMLEditor::AutoDeleteRangesHandler::
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "WSRunObject.h"
|
||||
|
||||
#include "EditorDOMPoint.h"
|
||||
#include "EditorUtils.h"
|
||||
#include "HTMLEditor.h"
|
||||
#include "HTMLEditUtils.h"
|
||||
#include "SelectionState.h"
|
||||
|
@ -871,15 +872,26 @@ Result<RefPtr<Element>, nsresult> WhiteSpaceVisibilityKeeper::InsertBRElement(
|
|||
}
|
||||
}
|
||||
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
aHTMLEditor.InsertBRElement(HTMLEditor::WithTransaction::Yes,
|
||||
pointToInsert, nsIEditor::eNone);
|
||||
CreateElementResult insertBRElementResult = aHTMLEditor.InsertBRElement(
|
||||
HTMLEditor::WithTransaction::Yes, pointToInsert);
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return Err(insertBRElementResult.unwrapErr());
|
||||
}
|
||||
// XXX Is this intentional selection change?
|
||||
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
|
||||
aHTMLEditor, {SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
||||
SuggestCaret::AndIgnoreTrivialError});
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("CreateElementResult::SuggestCaretPointTo() failed");
|
||||
return Err(rv);
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
resultOfInsertingBRElement.isOk(),
|
||||
"HTMLEditor::InsertBRElement(WithTransaction::Yes, eNone) failed");
|
||||
MOZ_ASSERT_IF(resultOfInsertingBRElement.isOk(),
|
||||
resultOfInsertingBRElement.inspect());
|
||||
return resultOfInsertingBRElement;
|
||||
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
|
||||
"CreateElementResult::SuggestCaretPointTo() failed, but ignored");
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
return insertBRElementResult.UnwrapNewNode();
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -3114,15 +3126,27 @@ nsresult WhiteSpaceVisibilityKeeper::NormalizeVisibleWhiteSpacesAt(
|
|||
// the beginning of soft wrapped lines, and lets the user see 2 spaces
|
||||
// when they type 2 spaces.
|
||||
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
const CreateElementResult insertBRElementResult =
|
||||
aHTMLEditor.InsertBRElement(HTMLEditor::WithTransaction::Yes,
|
||||
atEndOfVisibleWhiteSpaces);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
if (insertBRElementResult.isErr()) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
return insertBRElementResult.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
// XXX Is this intentional selection change?
|
||||
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
|
||||
aHTMLEditor, {SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
||||
SuggestCaret::AndIgnoreTrivialError});
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("CreateElementResult::SuggestCaretPointTo() failed");
|
||||
return rv;
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
|
||||
"CreateElementResult::SuggestCaretPointTo() failed, but ignored");
|
||||
MOZ_ASSERT(insertBRElementResult.GetNewNode());
|
||||
|
||||
atPreviousCharOfEndOfVisibleWhiteSpaces =
|
||||
textFragmentData.GetPreviousEditableCharPoint(
|
||||
|
|
Загрузка…
Ссылка в новой задаче