mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-04 07:40:42 +00:00
Bug 1707630 - part 1: Make HTMLEditor::InsertBREelementWithTransaction()
return error when it fails r=m_kato
The testcase hits the assertion because `CreateNodeTransaction::DoTransaction()` returns error, but it's not handled by `HandledInsertParagraphInParagraph()` so that we should make `InsertBRElementWithTransaction()` and its callees should return error if they meet unexpected cases. Depends on D113471 Differential Revision: https://phabricator.services.mozilla.com/D113472
This commit is contained in:
parent
a6ae919f0e
commit
867fd9ab9a
@ -698,11 +698,14 @@ nsresult HTMLEditor::SetPositionToAbsolute(Element& aElement) {
|
||||
if (parentNode->GetChildCount() != 1) {
|
||||
return NS_OK;
|
||||
}
|
||||
RefPtr<Element> newBRElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(EditorDOMPoint(parentNode, 0));
|
||||
NS_WARNING_ASSERTION(newBRElement,
|
||||
"HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return newBRElement ? NS_OK : NS_ERROR_FAILURE;
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult HTMLEditor::SetPositionToStatic(Element& aElement) {
|
||||
|
@ -997,17 +997,16 @@ EditActionResult HTMLEditor::HandleInsertText(
|
||||
|
||||
// is it a return?
|
||||
if (subStr.Equals(newlineStr)) {
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(currentPoint, nsIEditor::eNone);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionHandled(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (!brElement) {
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::InsertBRElementWithTransaction(eNone) failed");
|
||||
return EditActionHandled(NS_ERROR_FAILURE);
|
||||
return EditActionHandled(resultOfInsertingBRElement.unwrapErr());
|
||||
}
|
||||
pos++;
|
||||
RefPtr<Element> brElement(
|
||||
resultOfInsertingBRElement.unwrap().forget());
|
||||
if (brElement->GetNextSibling()) {
|
||||
pointToInsert.Set(brElement->GetNextSibling());
|
||||
} else {
|
||||
@ -1393,15 +1392,13 @@ EditActionResult HTMLEditor::InsertParagraphSeparatorAsSubAction() {
|
||||
AutoEditorDOMPointChildInvalidator lockOffset(atStartOfSelection);
|
||||
EditorDOMPoint endOfBlockParent;
|
||||
endOfBlockParent.SetToEndOf(blockElement);
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(endOfBlockParent);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (!brElement) {
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return EditActionIgnored(NS_ERROR_FAILURE);
|
||||
return EditActionIgnored(resultOfInsertingBRElement.unwrapErr());
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
}
|
||||
|
||||
RefPtr<Element> listItem = GetNearestAncestorListItemElement(*blockElement);
|
||||
@ -1487,14 +1484,14 @@ nsresult HTMLEditor::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
|
||||
// First, insert a <br> element.
|
||||
RefPtr<Element> brElement;
|
||||
if (IsPlaintextEditor()) {
|
||||
brElement = InsertBRElementWithTransaction(aPointToBreak);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (!brElement) {
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(aPointToBreak);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
brElement = resultOfInsertingBRElement.unwrap().forget();
|
||||
} else {
|
||||
EditorDOMPoint pointToBreak(aPointToBreak);
|
||||
WSRunScanner wsRunScanner(editingHost, pointToBreak);
|
||||
@ -1694,14 +1691,14 @@ EditActionResult HTMLEditor::SplitMailCiteElements(
|
||||
// We ignore the result here.
|
||||
EditorDOMPoint endOfPreviousNodeOfSplitPoint;
|
||||
endOfPreviousNodeOfSplitPoint.SetToEndOf(previousNodeOfSplitPoint);
|
||||
RefPtr<Element> invisibleBRElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingInvisibleBRElement =
|
||||
InsertBRElementWithTransaction(endOfPreviousNodeOfSplitPoint);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
|
||||
if (resultOfInsertingInvisibleBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return EditActionIgnored(
|
||||
resultOfInsertingInvisibleBRElement.unwrapErr());
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
invisibleBRElement,
|
||||
"HTMLEditor::InsertBRElementWithTransaction() failed, but ignored");
|
||||
MOZ_ASSERT(resultOfInsertingInvisibleBRElement.inspect());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1709,20 +1706,18 @@ EditActionResult HTMLEditor::SplitMailCiteElements(
|
||||
// left cite hasn't been created because the split point was start of the
|
||||
// cite node, <br> should be inserted before the current cite.
|
||||
EditorDOMPoint pointToInsertBRNode(splitCiteNodeResult.SplitPoint());
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(pointToInsertBRNode);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (!brElement) {
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return EditActionIgnored(NS_ERROR_FAILURE);
|
||||
return EditActionIgnored(resultOfInsertingBRElement.unwrapErr());
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
// Now, offset of pointToInsertBRNode is invalid. Let's clear it.
|
||||
pointToInsertBRNode.Clear();
|
||||
|
||||
// Want selection before the break, and on same line.
|
||||
EditorDOMPoint atBRElement(brElement);
|
||||
EditorDOMPoint atBRElement(resultOfInsertingBRElement.inspect());
|
||||
{
|
||||
AutoEditorDOMPointChildInvalidator lockOffset(atBRElement);
|
||||
IgnoredErrorResult ignoredError;
|
||||
@ -1774,14 +1769,13 @@ EditActionResult HTMLEditor::SplitMailCiteElements(
|
||||
// In case we're at the very end.
|
||||
forwardScanFromPointAfterNewBRElementResult
|
||||
.ReachedCurrentBlockBoundary()) {
|
||||
brElement = InsertBRElementWithTransaction(pointToCreateNewBRElement);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (!brElement) {
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(pointToCreateNewBRElement);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return EditActionIgnored(NS_ERROR_FAILURE);
|
||||
return EditActionIgnored(resultOfInsertingBRElement.unwrapErr());
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
// Now, those points may be invalid.
|
||||
pointToCreateNewBRElement.Clear();
|
||||
pointAfterNewBRElement.Clear();
|
||||
@ -2318,14 +2312,14 @@ nsresult HTMLEditor::InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(aPointToInsert, nsIEditor::ePrevious);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
NS_WARNING_ASSERTION(brElement,
|
||||
"HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return brElement ? NS_OK : NS_ERROR_FAILURE;
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditorDOMPoint HTMLEditor::GetGoodCaretPointFor(
|
||||
@ -3163,19 +3157,18 @@ nsresult HTMLEditor::FormatBlockContainerWithTransaction(nsAtom& blockType) {
|
||||
}
|
||||
EditorDOMPoint pointToInsertBRNode(splitNodeResult.SplitPoint());
|
||||
// Put a <br> element at the split point
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(pointToInsertBRNode);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (!brElement) {
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
// Don't restore the selection
|
||||
restoreSelectionLater.Abort();
|
||||
// Put selection at the split point
|
||||
nsresult rv = CollapseSelectionTo(EditorRawDOMPoint(brElement));
|
||||
nsresult rv = CollapseSelectionTo(
|
||||
EditorRawDOMPoint(resultOfInsertingBRElement.inspect()));
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"HTMLEditor::CollapseSelectionTo() failed");
|
||||
return rv;
|
||||
@ -6558,15 +6551,13 @@ nsresult HTMLEditor::HandleInsertParagraphInHeadingElement(Element& aHeader,
|
||||
}
|
||||
|
||||
// Append a <br> to it
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(EditorDOMPoint(pOrDivElement, 0));
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (!brElement) {
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
|
||||
// Set selection to before the break
|
||||
nsresult rv = CollapseSelectionToStartOf(*pOrDivElement);
|
||||
@ -6763,19 +6754,20 @@ EditActionResult HTMLEditor::HandleInsertParagraphInParagraph(
|
||||
return EditActionResult(NS_OK);
|
||||
}
|
||||
|
||||
brContent = InsertBRElementWithTransaction(pointToInsertBR);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(pointToInsertBR);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return EditActionResult(resultOfInsertingBRElement.unwrapErr());
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
brContent,
|
||||
"HTMLEditor::InsertBRElementWithTransaction() failed, but ignored");
|
||||
if (splitAfterNewBR && brContent) {
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
if (splitAfterNewBR) {
|
||||
// We split the parent after the br we've just inserted.
|
||||
pointToSplitParentDivOrP.SetAfter(brContent);
|
||||
pointToSplitParentDivOrP.SetAfter(resultOfInsertingBRElement.inspect());
|
||||
NS_WARNING_ASSERTION(pointToSplitParentDivOrP.IsSet(),
|
||||
"Failed to set after the new <br>");
|
||||
}
|
||||
brContent = resultOfInsertingBRElement.unwrap().forget();
|
||||
}
|
||||
EditActionResult result(
|
||||
SplitParagraph(aParentDivOrP, pointToSplitParentDivOrP, brContent));
|
||||
@ -6976,15 +6968,13 @@ nsresult HTMLEditor::HandleInsertParagraphInListItemElement(Element& aListItem,
|
||||
}
|
||||
|
||||
// Append a <br> to it
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(EditorDOMPoint(pOrDivElement, 0));
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (!brElement) {
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
|
||||
// Set selection to before the break
|
||||
rv = CollapseSelectionToStartOf(*pOrDivElement);
|
||||
@ -8511,15 +8501,13 @@ 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>`.
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(EditorDOMPoint(emptyCite));
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (!brElement) {
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
}
|
||||
// MOZ_KnownLive because 'arrayOfEmptyCites' is guaranteed to keep it alive.
|
||||
rv = DeleteNodeWithTransaction(MOZ_KnownLive(emptyCite));
|
||||
@ -8839,14 +8827,14 @@ nsresult HTMLEditor::InsertBRElementIfEmptyBlockElement(Element& aElement) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(EditorDOMPoint(&aElement, 0));
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
NS_WARNING_ASSERTION(brElement,
|
||||
"HTMELditor::InsertBRElementWithTransaction() failed");
|
||||
return brElement ? NS_OK : NS_ERROR_FAILURE;
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult HTMLEditor::RemoveAlignFromDescendants(Element& aElement,
|
||||
@ -9009,14 +8997,15 @@ nsresult HTMLEditor::EnsureHardLineBeginsWithFirstChildOf(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<Element> brElement = InsertBRElementWithTransaction(
|
||||
EditorDOMPoint(&aRemovingContainerElement, 0));
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(
|
||||
EditorDOMPoint(&aRemovingContainerElement, 0));
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
NS_WARNING_ASSERTION(brElement,
|
||||
"HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return brElement ? NS_OK : NS_ERROR_FAILURE;
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult HTMLEditor::EnsureHardLineEndsWithLastChildOf(
|
||||
@ -9045,14 +9034,15 @@ nsresult HTMLEditor::EnsureHardLineEndsWithLastChildOf(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<Element> brElement = InsertBRElementWithTransaction(
|
||||
EditorDOMPoint::AtEndOf(aRemovingContainerElement));
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(
|
||||
EditorDOMPoint::AtEndOf(aRemovingContainerElement));
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
NS_WARNING_ASSERTION(brElement,
|
||||
"HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return brElement ? NS_OK : NS_ERROR_FAILURE;
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult HTMLEditor::SetBlockElementAlign(Element& aBlockOrHRElement,
|
||||
|
@ -1267,11 +1267,14 @@ nsresult HTMLEditor::InsertBRElementAtSelectionWithTransaction() {
|
||||
|
||||
// InsertBRElementWithTransaction() will set selection after the new <br>
|
||||
// element.
|
||||
RefPtr<Element> newBRElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(atStartOfSelection, eNext);
|
||||
NS_WARNING_ASSERTION(newBRElement,
|
||||
"HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return newBRElement ? NS_OK : NS_ERROR_FAILURE;
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void HTMLEditor::CollapseSelectionToDeepestNonTableFirstChild(nsINode* aNode) {
|
||||
@ -1857,23 +1860,22 @@ nsresult HTMLEditor::InsertElementAtSelectionAsAction(
|
||||
|
||||
// check for inserting a whole table at the end of a block. If so insert
|
||||
// a br after it.
|
||||
if (HTMLEditUtils::IsTable(aElement) && IsLastEditableChild(aElement)) {
|
||||
DebugOnly<bool> advanced = insertedPoint.AdvanceOffset();
|
||||
NS_WARNING_ASSERTION(advanced,
|
||||
"Failed to advance offset from inserted point");
|
||||
// Collapse selection to the new `<br>` element node after creating it.
|
||||
RefPtr<Element> newBRElement =
|
||||
InsertBRElementWithTransaction(insertedPoint, ePrevious);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (!newBRElement) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::InsertBRElementWithTransaction(ePrevious) failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (!HTMLEditUtils::IsTable(aElement) || !IsLastEditableChild(aElement)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DebugOnly<bool> advanced = insertedPoint.AdvanceOffset();
|
||||
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 =
|
||||
InsertBRElementWithTransaction(insertedPoint, ePrevious);
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction(ePrevious) failed");
|
||||
return EditorBase::ToGenericNSResult(
|
||||
resultOfInsertingBRElement.unwrapErr());
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -3474,65 +3476,63 @@ EditorDOMPoint HTMLEditor::PrepareToInsertBRElement(
|
||||
return pointInContainer;
|
||||
}
|
||||
|
||||
already_AddRefed<Element> HTMLEditor::InsertBRElementWithTransaction(
|
||||
Result<RefPtr<Element>, nsresult> HTMLEditor::InsertBRElementWithTransaction(
|
||||
const EditorDOMPoint& aPointToInsert, EDirection aSelect /* = eNone */) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
EditorDOMPoint pointToInsert = PrepareToInsertBRElement(aPointToInsert);
|
||||
if (NS_WARN_IF(!pointToInsert.IsSet())) {
|
||||
return nullptr;
|
||||
NS_WARNING("HTMLEditor::PrepareToInsertBRElement() failed");
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
RefPtr<Element> newBRElement =
|
||||
CreateNodeWithTransaction(*nsGkAtoms::br, pointToInsert);
|
||||
if (NS_WARN_IF(!newBRElement)) {
|
||||
return nullptr;
|
||||
NS_WARNING("EditorBase::CreateNodeWithTransaction() failed");
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
switch (aSelect) {
|
||||
case eNone:
|
||||
break;
|
||||
case eNext: {
|
||||
IgnoredErrorResult ignoredError;
|
||||
SelectionRef().SetInterlinePosition(true, ignoredError);
|
||||
NS_WARNING_ASSERTION(
|
||||
!ignoredError.Failed(),
|
||||
"Selection::SetInterlinePosition(true) failed, but ignored");
|
||||
ErrorResult error;
|
||||
SelectionRef().SetInterlinePosition(true, error);
|
||||
if (error.Failed()) {
|
||||
NS_WARNING("Selection::SetInterlinePosition(true) failed");
|
||||
return Err(error.StealNSResult());
|
||||
}
|
||||
// Collapse selection after the <br> node.
|
||||
EditorRawDOMPoint afterBRElement(EditorRawDOMPoint::After(*newBRElement));
|
||||
NS_WARNING_ASSERTION(afterBRElement.IsSet(),
|
||||
"Setting after <br> element failed, but ignored");
|
||||
if (afterBRElement.IsSet()) {
|
||||
ignoredError.SuppressException();
|
||||
CollapseSelectionTo(afterBRElement, ignoredError);
|
||||
if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) {
|
||||
return nullptr;
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
!ignoredError.Failed(),
|
||||
"HTMLEditor::CollapseSelectionTo() failed, but ignored");
|
||||
if (!afterBRElement.IsSet()) {
|
||||
NS_WARNING("Setting point to after <br> element failed");
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
CollapseSelectionTo(afterBRElement, error);
|
||||
if (error.Failed()) {
|
||||
NS_WARNING("HTMLEditor::CollapseSelectionTo() failed, but ignored");
|
||||
return Err(error.StealNSResult());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ePrevious: {
|
||||
IgnoredErrorResult ignoredError;
|
||||
SelectionRef().SetInterlinePosition(true, ignoredError);
|
||||
NS_WARNING_ASSERTION(
|
||||
!ignoredError.Failed(),
|
||||
"Selection::SetInterlinePosition(true) failed, but ignored");
|
||||
ErrorResult error;
|
||||
SelectionRef().SetInterlinePosition(true, error);
|
||||
if (error.Failed()) {
|
||||
NS_WARNING("Selection::SetInterlinePosition(true) failed");
|
||||
return Err(error.StealNSResult());
|
||||
}
|
||||
// Collapse selection at the <br> node.
|
||||
EditorRawDOMPoint atBRElement(newBRElement);
|
||||
NS_WARNING_ASSERTION(atBRElement.IsSet(),
|
||||
"Setting at <br> element failed, but ignored");
|
||||
if (atBRElement.IsSet()) {
|
||||
ignoredError.SuppressException();
|
||||
CollapseSelectionTo(atBRElement, ignoredError);
|
||||
if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) {
|
||||
return nullptr;
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
!ignoredError.Failed(),
|
||||
"HTMLEditor::CollapseSelectionTo() failed, but ignored");
|
||||
if (!atBRElement.IsSet()) {
|
||||
NS_WARNING("Setting point to at <br> element failed");
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
CollapseSelectionTo(atBRElement, error);
|
||||
if (error.Failed()) {
|
||||
NS_WARNING("HTMLEditor::CollapseSelectionTo() failed, but ignored");
|
||||
return Err(error.StealNSResult());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -3543,7 +3543,7 @@ already_AddRefed<Element> HTMLEditor::InsertBRElementWithTransaction(
|
||||
break;
|
||||
}
|
||||
|
||||
return newBRElement.forget();
|
||||
return std::move(newBRElement);
|
||||
}
|
||||
|
||||
already_AddRefed<Element> HTMLEditor::InsertContainerWithTransactionInternal(
|
||||
@ -4122,15 +4122,13 @@ nsresult HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement) {
|
||||
!previousSibling->IsHTMLElement(nsGkAtoms::br) &&
|
||||
!HTMLEditUtils::IsBlockElement(*child)) {
|
||||
// Insert br node
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(EditorDOMPoint(&aElement, 0));
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (!brElement) {
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
}
|
||||
}
|
||||
|
||||
@ -4145,15 +4143,14 @@ nsresult HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement) {
|
||||
if (nsIContent* lastChild = GetLastEditableChild(aElement)) {
|
||||
if (!HTMLEditUtils::IsBlockElement(*lastChild) &&
|
||||
!lastChild->IsHTMLElement(nsGkAtoms::br)) {
|
||||
RefPtr<Element> brElement = InsertBRElementWithTransaction(
|
||||
EditorDOMPoint::AtEndOf(aElement));
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (!brElement) {
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(
|
||||
EditorDOMPoint::AtEndOf(aElement));
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4170,15 +4167,13 @@ nsresult HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement) {
|
||||
if (nsIContent* nextSibling = GetNextHTMLSibling(&aElement)) {
|
||||
if (!HTMLEditUtils::IsBlockElement(*nextSibling) &&
|
||||
!nextSibling->IsHTMLElement(nsGkAtoms::br)) {
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(EditorDOMPoint(&aElement, 0));
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (!brElement) {
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5704,13 +5699,14 @@ nsresult HTMLEditor::CopyLastEditableChildStylesWithTransaction(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(EditorDOMPoint(firstClonsedElement, 0));
|
||||
if (!brElement) {
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
*aNewBRElement = std::move(brElement);
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
*aNewBRElement = resultOfInsertingBRElement.unwrap().forget();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -698,10 +698,11 @@ class HTMLEditor final : public TextEditor,
|
||||
* If ePrevious, selection will be collapsed at
|
||||
* the <br> element.
|
||||
* @return The new <br> node. If failed to create new
|
||||
* <br> node, returns nullptr.
|
||||
* <br> node, returns error.
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element> InsertBRElementWithTransaction(
|
||||
const EditorDOMPoint& aPointToInsert, EDirection aSelect = eNone);
|
||||
MOZ_CAN_RUN_SCRIPT Result<RefPtr<Element>, nsresult>
|
||||
InsertBRElementWithTransaction(const EditorDOMPoint& aPointToInsert,
|
||||
EDirection aSelect = eNone);
|
||||
|
||||
/**
|
||||
* DeleteNodeWithTransaction() removes aContent from the DOM tree if it's
|
||||
|
@ -4993,16 +4993,15 @@ nsresult HTMLEditor::DeleteMostAncestorMailCiteElementIfEmpty(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
InsertBRElementWithTransaction(atEmptyMailCiteElement);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (!brElement) {
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
nsresult rv = CollapseSelectionTo(EditorRawDOMPoint(brElement));
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
nsresult rv = CollapseSelectionTo(
|
||||
EditorRawDOMPoint(resultOfInsertingBRElement.inspect()));
|
||||
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
@ -5155,16 +5154,13 @@ HTMLEditor::AutoDeleteRangesHandler::AutoEmptyBlockAncestorDeleter::
|
||||
if (HTMLEditUtils::IsAnyListElement(atParentOfEmptyListItem.GetContainer())) {
|
||||
return RefPtr<Element>();
|
||||
}
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
aHTMLEditor.InsertBRElementWithTransaction(atParentOfEmptyListItem);
|
||||
if (NS_WARN_IF(aHTMLEditor.Destroyed())) {
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (!brElement) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
return brElement;
|
||||
NS_WARNING_ASSERTION(resultOfInsertingBRElement.isOk(),
|
||||
"HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
MOZ_ASSERT_IF(resultOfInsertingBRElement.isOk(),
|
||||
resultOfInsertingBRElement.inspect());
|
||||
return resultOfInsertingBRElement;
|
||||
}
|
||||
|
||||
Result<EditorDOMPoint, nsresult> HTMLEditor::AutoDeleteRangesHandler::
|
||||
|
@ -714,16 +714,15 @@ Result<RefPtr<Element>, nsresult> WhiteSpaceVisibilityKeeper::InsertBRElement(
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<Element> newBRElement = aHTMLEditor.InsertBRElementWithTransaction(
|
||||
pointToInsert, nsIEditor::eNone);
|
||||
if (NS_WARN_IF(aHTMLEditor.Destroyed())) {
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (!newBRElement) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
return newBRElement;
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
aHTMLEditor.InsertBRElementWithTransaction(pointToInsert,
|
||||
nsIEditor::eNone);
|
||||
NS_WARNING_ASSERTION(
|
||||
resultOfInsertingBRElement.isOk(),
|
||||
"HTMLEditor::InsertBRElementWithTransaction(eNone) failed");
|
||||
MOZ_ASSERT_IF(resultOfInsertingBRElement.isOk(),
|
||||
resultOfInsertingBRElement.inspect());
|
||||
return resultOfInsertingBRElement;
|
||||
}
|
||||
|
||||
// static
|
||||
@ -2790,16 +2789,14 @@ nsresult WhiteSpaceVisibilityKeeper::NormalizeVisibleWhiteSpacesAt(
|
||||
// the beginning of soft wrapped lines, and lets the user see 2 spaces
|
||||
// when they type 2 spaces.
|
||||
|
||||
RefPtr<Element> brElement =
|
||||
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
|
||||
aHTMLEditor.InsertBRElementWithTransaction(
|
||||
atEndOfVisibleWhiteSpaces);
|
||||
if (NS_WARN_IF(aHTMLEditor.Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (!brElement) {
|
||||
if (resultOfInsertingBRElement.isErr()) {
|
||||
NS_WARNING("HTMLEditor::InsertBRElementWithTransaction() failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
return resultOfInsertingBRElement.unwrapErr();
|
||||
}
|
||||
MOZ_ASSERT(resultOfInsertingBRElement.inspect());
|
||||
|
||||
atPreviousCharOfEndOfVisibleWhiteSpaces =
|
||||
textFragmentData.GetPreviousEditableCharPoint(
|
||||
|
Loading…
x
Reference in New Issue
Block a user