Bug 1791223 - Use `MoveNodeResult` as the ok type of `mozilla::Result` r=m_kato

Unfortunately, it's hard to split this (and similar) patch because we need to
touch `MoveNodeResult` itself for making it available as the ok type of
`Result`.  However, I guess that it's not so hard to investigate regression
point if something would be found later because `MoveNodeResult` is mainly
used by deletion which is the most complicated part of `HTMLEditor`, but
`MoveNodeResult` is used only in a few cases.

Differential Revision: https://phabricator.services.mozilla.com/D157574
This commit is contained in:
Masayuki Nakano 2022-09-26 00:56:46 +00:00
Родитель 023357051f
Коммит 69d7bf65c8
10 изменённых файлов: 421 добавлений и 436 удалений

Просмотреть файл

@ -24,6 +24,9 @@ class RefPtr;
namespace mozilla {
template <typename V, typename E>
class Result;
template <typename T>
class OwningNonNull;

Просмотреть файл

@ -37,29 +37,31 @@ using namespace dom;
*****************************************************************************/
EditActionResult& EditActionResult::operator|=(
const MoveNodeResult& aMoveNodeResult) {
mHandled |= aMoveNodeResult.Handled();
// When both result are same, keep the result.
if (mRv == aMoveNodeResult.inspectErr()) {
return *this;
}
const Result<MoveNodeResult, nsresult>& aMoveNodeResult) {
mHandled |= aMoveNodeResult.isOk() && aMoveNodeResult.inspect().Handled();
// If one of the result is NS_ERROR_EDITOR_DESTROYED, use it since it's
// the most important error code for editor.
if (EditorDestroyed() || aMoveNodeResult.EditorDestroyed()) {
if (EditorDestroyed() ||
(aMoveNodeResult.isErr() &&
aMoveNodeResult.inspectErr() == NS_ERROR_EDITOR_DESTROYED)) {
mRv = NS_ERROR_EDITOR_DESTROYED;
return *this;
}
// If aMoveNodeResult hasn't been set explicit nsresult value, keep current
// result.
if (aMoveNodeResult.NotInitialized()) {
return *this;
}
// If one of the results is error, use NS_ERROR_FAILURE.
// If one of the results is error, return error.
if (Failed() || aMoveNodeResult.isErr()) {
// If both failed and the error codes are same, just return.
if (Failed() && aMoveNodeResult.isErr() &&
mRv == aMoveNodeResult.inspectErr()) {
return *this;
}
// If the error codes is different or one of them succeeded, use the general
// error code.
mRv = NS_ERROR_FAILURE;
return *this;
}
// Otherwise, use generic success code, NS_OK.
// Otherwise, use general success code.
mRv = NS_OK;
return *this;
}

Просмотреть файл

@ -88,7 +88,8 @@ class MOZ_STACK_CLASS EditActionResult final {
return *this;
}
EditActionResult& operator|=(const MoveNodeResult& aMoveNodeResult);
EditActionResult& operator|=(
const Result<MoveNodeResult, nsresult>& aMoveNodeResult);
private:
nsresult mRv;

Просмотреть файл

@ -21,6 +21,7 @@
#include "mozilla/IntegerRange.h"
#include "mozilla/Maybe.h"
#include "mozilla/RangeBoundary.h"
#include "mozilla/Result.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/StaticRange.h"
#include "nsCOMPtr.h"
@ -72,33 +73,27 @@ static inline std::ostream& operator<<(std::ostream& aStream,
/*****************************************************************************
* MoveNodeResult is a simple class for MoveSomething() methods.
* This holds error code and next insertion point if moving contents succeeded.
* TODO: Perhaps, we can make this inherits mozilla::Result for guaranteeing
* same API. Then, changing to/from Result<*, nsresult> can be easier.
* For now, we should give same API name rather than same as
* mozilla::ErrorResult.
* This stores whether it's handled or not, and next insertion point and a
* suggestion for new caret position.
*****************************************************************************/
class MOZ_STACK_CLASS MoveNodeResult final {
public:
// FYI: NS_SUCCEEDED and NS_FAILED contain MOZ_(UN)LIKELY so that isOk() and
// isErr() must not required to wrap with them.
bool isOk() const { return NS_SUCCEEDED(mRv); }
bool isErr() const { return NS_FAILED(mRv); }
constexpr bool Handled() const { return mHandled; }
constexpr bool Ignored() const { return !Handled(); }
constexpr nsresult inspectErr() const { return mRv; }
constexpr nsresult unwrapErr() const { return mRv; }
constexpr bool EditorDestroyed() const {
return MOZ_UNLIKELY(mRv == NS_ERROR_EDITOR_DESTROYED);
}
constexpr bool NotInitialized() const {
return mRv == NS_ERROR_NOT_INITIALIZED;
}
constexpr const EditorDOMPoint& NextInsertionPointRef() const {
return mNextInsertionPoint;
}
EditorDOMPoint NextInsertionPoint() const { return mNextInsertionPoint; }
constexpr EditorDOMPoint&& UnwrapNextInsertionPoint() {
return std::move(mNextInsertionPoint);
}
template <typename EditorDOMPointType>
EditorDOMPointType NextInsertionPoint() const {
return mNextInsertionPoint.To<EditorDOMPointType>();
}
/**
* Override the result as "handled" forcibly.
*/
void MarkAsHandled() { mHandled = true; }
/**
@ -134,18 +129,13 @@ class MOZ_STACK_CLASS MoveNodeResult final {
const HTMLEditor& aHTMLEditor,
const SuggestCaretOptions& aOptions);
MoveNodeResult() : mRv(NS_ERROR_NOT_INITIALIZED), mHandled(false) {}
explicit MoveNodeResult(nsresult aRv) : mRv(aRv), mHandled(false) {
MOZ_DIAGNOSTIC_ASSERT(NS_FAILED(mRv));
}
MoveNodeResult(const MoveNodeResult& aOther) = delete;
MoveNodeResult& operator=(const MoveNodeResult& aOther) = delete;
MoveNodeResult(MoveNodeResult&& aOther) = default;
MoveNodeResult& operator=(MoveNodeResult&& aOther) = default;
MoveNodeResult& operator|=(const MoveNodeResult& aOther) {
MOZ_ASSERT(this != &aOther);
// aOther is merged with this instance so that its caret suggestion
// shouldn't be handled anymore.
aOther.mHandledCaretPoint = true;
@ -153,44 +143,11 @@ class MOZ_STACK_CLASS MoveNodeResult final {
mHandledCaretPoint = false;
mHandled |= aOther.mHandled;
// When both result are same, keep the result but use newer point.
if (mRv == aOther.mRv) {
mNextInsertionPoint = aOther.mNextInsertionPoint;
if (aOther.mCaretPoint.IsSet()) {
mCaretPoint = aOther.mCaretPoint;
}
return *this;
}
// If one of the result is NS_ERROR_EDITOR_DESTROYED, use it since it's
// the most important error code for editor.
if (EditorDestroyed() || aOther.EditorDestroyed()) {
mRv = NS_ERROR_EDITOR_DESTROYED;
mNextInsertionPoint.Clear();
mCaretPoint.Clear();
return *this;
}
// If the other one has not been set explicit nsresult, keep current
// value.
if (aOther.NotInitialized()) {
return *this;
}
// If this one has not been set explicit nsresult, copy the other one's.
if (NotInitialized()) {
mRv = aOther.mRv;
mNextInsertionPoint = aOther.mNextInsertionPoint;
mCaretPoint = aOther.mCaretPoint;
return *this;
}
// If one of the results is error, use NS_ERROR_FAILURE.
if (isErr() || aOther.isErr()) {
mRv = NS_ERROR_FAILURE;
mNextInsertionPoint.Clear();
mCaretPoint.Clear();
return *this;
}
// Otherwise, use generic success code, NS_OK, and use newer point.
mRv = NS_OK;
// Take the new one for the next insertion point.
mNextInsertionPoint = aOther.mNextInsertionPoint;
// Take the new caret point if and only if it's suggested.
if (aOther.mCaretPoint.IsSet()) {
mCaretPoint = aOther.mCaretPoint;
}
@ -199,148 +156,112 @@ class MOZ_STACK_CLASS MoveNodeResult final {
#ifdef DEBUG
~MoveNodeResult() {
MOZ_ASSERT_IF(isOk() && Handled(),
!mCaretPoint.IsSet() || mHandledCaretPoint);
MOZ_ASSERT_IF(Handled(), !mCaretPoint.IsSet() || mHandledCaretPoint);
}
#endif
/*****************************************************************************
* When a move node handler (or its helper) does nothing,
* the result of these factory methods should be returned.
* aNextInsertionPoint Must be set and valid.
*****************************************************************************/
static MoveNodeResult IgnoredResult(
const EditorDOMPoint& aNextInsertionPoint) {
return MoveNodeResult(aNextInsertionPoint, false);
}
static MoveNodeResult IgnoredResult(EditorDOMPoint&& aNextInsertionPoint) {
return MoveNodeResult(std::move(aNextInsertionPoint), false);
}
/*****************************************************************************
* When a move node handler (or its helper) handled and not canceled,
* the result of these factory methods should be returned.
* aNextInsertionPoint Must be set and valid.
*****************************************************************************/
static MoveNodeResult HandledResult(
const EditorDOMPoint& aNextInsertionPoint) {
return MoveNodeResult(aNextInsertionPoint, true);
}
static MoveNodeResult HandledResult(EditorDOMPoint&& aNextInsertionPoint) {
return MoveNodeResult(std::move(aNextInsertionPoint), true);
}
static MoveNodeResult HandledResult(const EditorDOMPoint& aNextInsertionPoint,
const EditorDOMPoint& aPointToPutCaret) {
return MoveNodeResult(aNextInsertionPoint, aPointToPutCaret);
}
static MoveNodeResult HandledResult(EditorDOMPoint&& aNextInsertionPoint,
const EditorDOMPoint& aPointToPutCaret) {
return MoveNodeResult(std::move(aNextInsertionPoint), aPointToPutCaret);
}
static MoveNodeResult HandledResult(const EditorDOMPoint& aNextInsertionPoint,
EditorDOMPoint&& aPointToPutCaret) {
return MoveNodeResult(aNextInsertionPoint, std::move(aPointToPutCaret));
}
static MoveNodeResult HandledResult(EditorDOMPoint&& aNextInsertionPoint,
EditorDOMPoint&& aPointToPutCaret) {
return MoveNodeResult(std::move(aNextInsertionPoint),
std::move(aPointToPutCaret));
}
private:
explicit MoveNodeResult(const EditorDOMPoint& aNextInsertionPoint,
bool aHandled)
: mNextInsertionPoint(aNextInsertionPoint),
mRv(aNextInsertionPoint.IsSet() ? NS_OK : NS_ERROR_FAILURE),
mHandled(aHandled && aNextInsertionPoint.IsSet()) {
if (mNextInsertionPoint.IsSet()) {
AutoEditorDOMPointChildInvalidator computeOffsetAndForgetChild(
mNextInsertionPoint);
}
AutoEditorDOMPointChildInvalidator computeOffsetAndForgetChild(
mNextInsertionPoint);
}
explicit MoveNodeResult(EditorDOMPoint&& aNextInsertionPoint, bool aHandled)
: mNextInsertionPoint(std::move(aNextInsertionPoint)),
mRv(mNextInsertionPoint.IsSet() ? NS_OK : NS_ERROR_FAILURE),
mHandled(aHandled && mNextInsertionPoint.IsSet()) {
if (mNextInsertionPoint.IsSet()) {
AutoEditorDOMPointChildInvalidator computeOffsetAndForgetChild(
mNextInsertionPoint);
}
AutoEditorDOMPointChildInvalidator computeOffsetAndForgetChild(
mNextInsertionPoint);
}
explicit MoveNodeResult(const EditorDOMPoint& aNextInsertionPoint,
const EditorDOMPoint& aPointToPutCaret)
: mNextInsertionPoint(aNextInsertionPoint),
mCaretPoint(aPointToPutCaret),
mRv(mNextInsertionPoint.IsSet() ? NS_OK : NS_ERROR_FAILURE),
mHandled(mNextInsertionPoint.IsSet()) {
if (mNextInsertionPoint.IsSet()) {
AutoEditorDOMPointChildInvalidator computeOffsetAndForgetChild(
mNextInsertionPoint);
}
AutoEditorDOMPointChildInvalidator computeOffsetAndForgetChild(
mNextInsertionPoint);
}
explicit MoveNodeResult(EditorDOMPoint&& aNextInsertionPoint,
const EditorDOMPoint& aPointToPutCaret)
: mNextInsertionPoint(std::move(aNextInsertionPoint)),
mCaretPoint(aPointToPutCaret),
mRv(mNextInsertionPoint.IsSet() ? NS_OK : NS_ERROR_FAILURE),
mHandled(mNextInsertionPoint.IsSet()) {
if (mNextInsertionPoint.IsSet()) {
AutoEditorDOMPointChildInvalidator computeOffsetAndForgetChild(
mNextInsertionPoint);
}
AutoEditorDOMPointChildInvalidator computeOffsetAndForgetChild(
mNextInsertionPoint);
}
explicit MoveNodeResult(const EditorDOMPoint& aNextInsertionPoint,
EditorDOMPoint&& aPointToPutCaret)
: mNextInsertionPoint(aNextInsertionPoint),
mCaretPoint(std::move(aPointToPutCaret)),
mRv(mNextInsertionPoint.IsSet() ? NS_OK : NS_ERROR_FAILURE),
mHandled(mNextInsertionPoint.IsSet()) {
if (mNextInsertionPoint.IsSet()) {
AutoEditorDOMPointChildInvalidator computeOffsetAndForgetChild(
mNextInsertionPoint);
}
AutoEditorDOMPointChildInvalidator computeOffsetAndForgetChild(
mNextInsertionPoint);
}
explicit MoveNodeResult(EditorDOMPoint&& aNextInsertionPoint,
EditorDOMPoint&& aPointToPutCaret)
: mNextInsertionPoint(std::move(aNextInsertionPoint)),
mCaretPoint(std::move(aPointToPutCaret)),
mRv(mNextInsertionPoint.IsSet() ? NS_OK : NS_ERROR_FAILURE),
mHandled(mNextInsertionPoint.IsSet()) {
if (mNextInsertionPoint.IsSet()) {
AutoEditorDOMPointChildInvalidator computeOffsetAndForgetChild(
mNextInsertionPoint);
}
AutoEditorDOMPointChildInvalidator computeOffsetAndForgetChild(
mNextInsertionPoint);
}
EditorDOMPoint mNextInsertionPoint;
// Recommended caret point after moving a node.
EditorDOMPoint mCaretPoint;
nsresult mRv;
bool mHandled;
bool mutable mHandledCaretPoint = false;
friend MoveNodeResult MoveNodeIgnored(
const EditorDOMPoint& aNextInsertionPoint);
friend MoveNodeResult MoveNodeIgnored(EditorDOMPoint&& aNextInsertionPoint);
friend MoveNodeResult MoveNodeHandled(
const EditorDOMPoint& aNextInsertionPoint);
friend MoveNodeResult MoveNodeHandled(EditorDOMPoint&& aNextInsertionPoint);
friend MoveNodeResult MoveNodeHandled(
const EditorDOMPoint& aNextInsertionPoint,
const EditorDOMPoint& aPointToPutCaret);
friend MoveNodeResult MoveNodeHandled(EditorDOMPoint&& aNextInsertionPoint,
const EditorDOMPoint& aPointToPutCaret);
friend MoveNodeResult MoveNodeHandled(
const EditorDOMPoint& aNextInsertionPoint,
EditorDOMPoint&& aPointToPutCaret);
friend MoveNodeResult MoveNodeHandled(EditorDOMPoint&& aNextInsertionPoint,
EditorDOMPoint&& aPointToPutCaret);
};
/*****************************************************************************
* When a move node handler (or its helper) does nothing,
* MoveNodeIgnored should be returned.
*****************************************************************************/
inline MoveNodeResult MoveNodeIgnored(
const EditorDOMPoint& aNextInsertionPoint) {
return MoveNodeResult(aNextInsertionPoint, false);
}
inline MoveNodeResult MoveNodeIgnored(EditorDOMPoint&& aNextInsertionPoint) {
return MoveNodeResult(std::move(aNextInsertionPoint), false);
}
/*****************************************************************************
* When a move node handler (or its helper) handled and not canceled,
* MoveNodeHandled should be returned.
*****************************************************************************/
inline MoveNodeResult MoveNodeHandled(
const EditorDOMPoint& aNextInsertionPoint) {
return MoveNodeResult(aNextInsertionPoint, true);
}
inline MoveNodeResult MoveNodeHandled(EditorDOMPoint&& aNextInsertionPoint) {
return MoveNodeResult(std::move(aNextInsertionPoint), true);
}
inline MoveNodeResult MoveNodeHandled(const EditorDOMPoint& aNextInsertionPoint,
const EditorDOMPoint& aPointToPutCaret) {
return MoveNodeResult(aNextInsertionPoint, aPointToPutCaret);
}
inline MoveNodeResult MoveNodeHandled(EditorDOMPoint&& aNextInsertionPoint,
const EditorDOMPoint& aPointToPutCaret) {
return MoveNodeResult(std::move(aNextInsertionPoint), aPointToPutCaret);
}
inline MoveNodeResult MoveNodeHandled(const EditorDOMPoint& aNextInsertionPoint,
EditorDOMPoint&& aPointToPutCaret) {
return MoveNodeResult(aNextInsertionPoint, std::move(aPointToPutCaret));
}
inline MoveNodeResult MoveNodeHandled(EditorDOMPoint&& aNextInsertionPoint,
EditorDOMPoint&& aPointToPutCaret) {
return MoveNodeResult(std::move(aNextInsertionPoint),
std::move(aPointToPutCaret));
}
/*****************************************************************************
* SplitNodeResult is a simple class for
* HTMLEditor::SplitNodeDeepWithTransaction().

Просмотреть файл

@ -2078,14 +2078,16 @@ CreateElementResult HTMLEditor::HandleInsertBRElement(
if (brElement->GetNextSibling() !=
forwardScanFromAfterBRElementResult.BRElementPtr()) {
MOZ_ASSERT(forwardScanFromAfterBRElementResult.BRElementPtr());
const MoveNodeResult moveBRElementResult = MoveNodeWithTransaction(
MOZ_KnownLive(*forwardScanFromAfterBRElementResult.BRElementPtr()),
afterBRElement);
if (moveBRElementResult.isErr()) {
Result<MoveNodeResult, nsresult> moveBRElementResult =
MoveNodeWithTransaction(
MOZ_KnownLive(
*forwardScanFromAfterBRElementResult.BRElementPtr()),
afterBRElement);
if (MOZ_UNLIKELY(moveBRElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return CreateElementResult(moveBRElementResult.unwrapErr());
}
nsresult rv = moveBRElementResult.SuggestCaretPointTo(
nsresult rv = moveBRElementResult.inspect().SuggestCaretPointTo(
*this, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaret::AndIgnoreTrivialError});
@ -3354,14 +3356,14 @@ EditActionResult HTMLEditor::ConvertContentAroundRangesToList(
// of the list, append current node to end of the current list element.
// Then, wrap it with list item element and delete the old container.
if (curList && !EditorUtils::IsDescendantOf(*content, *curList)) {
const MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(*content, *curList);
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return EditActionResult(moveNodeResult.inspectErr());
return EditActionResult(moveNodeResult.unwrapErr());
}
MOZ_ASSERT(aRanges.HasSavedRanges());
moveNodeResult.IgnoreCaretPointSuggestion();
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
const CreateElementResult convertListTypeResult =
ChangeListElementType(MOZ_KnownLive(*content->AsElement()),
@ -3446,14 +3448,14 @@ EditActionResult HTMLEditor::ConvertContentAroundRangesToList(
curList = createNewListElementResult.UnwrapNewNode();
}
// Then, move current node into current list element.
const MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(*content, *curList);
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return EditActionResult(moveNodeResult.unwrapErr());
}
MOZ_ASSERT(aRanges.HasSavedRanges());
moveNodeResult.IgnoreCaretPointSuggestion();
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
// Convert list item type if current node is different list item type.
if (!content->IsHTMLElement(&aListItemElementTagName)) {
@ -3480,14 +3482,14 @@ EditActionResult HTMLEditor::ConvertContentAroundRangesToList(
// If current list item element is not a child of current list element,
// move it into current list item.
else if (atContent.GetContainer() != curList) {
const MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(*content, *curList);
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return EditActionResult(moveNodeResult.inspectErr());
return EditActionResult(moveNodeResult.unwrapErr());
}
MOZ_ASSERT(aRanges.HasSavedRanges());
moveNodeResult.IgnoreCaretPointSuggestion();
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
}
// Then, if current list item element is not proper type for current
// list element, convert list item element to proper element.
@ -3602,14 +3604,14 @@ EditActionResult HTMLEditor::ConvertContentAroundRangesToList(
// If we're currently handling contents of a list item and current node
// is not a block element, move current node into the list item.
if (HTMLEditUtils::IsInlineElement(content) && prevListItem) {
const MoveNodeResult moveInlineElementResult =
Result<MoveNodeResult, nsresult> moveInlineElementResult =
MoveNodeToEndWithTransaction(*content, *prevListItem);
if (moveInlineElementResult.isErr()) {
if (MOZ_UNLIKELY(moveInlineElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return EditActionResult(moveInlineElementResult.unwrapErr());
}
MOZ_ASSERT(aRanges.HasSavedRanges());
moveInlineElementResult.IgnoreCaretPointSuggestion();
moveInlineElementResult.inspect().IgnoreCaretPointSuggestion();
continue;
}
@ -3630,15 +3632,15 @@ EditActionResult HTMLEditor::ConvertContentAroundRangesToList(
newListItemElementOrError.IgnoreCaretPointSuggestion();
MOZ_ASSERT(newListItemElementOrError.GetNewNode());
const MoveNodeResult moveListItemElementResult =
Result<MoveNodeResult, nsresult> moveListItemElementResult =
MoveNodeToEndWithTransaction(
MOZ_KnownLive(*newListItemElementOrError.GetNewNode()), *curList);
if (moveListItemElementResult.isErr()) {
if (MOZ_UNLIKELY(moveListItemElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return EditActionResult(moveListItemElementResult.unwrapErr());
}
MOZ_ASSERT(aRanges.HasSavedRanges());
moveListItemElementResult.IgnoreCaretPointSuggestion();
moveListItemElementResult.inspect().IgnoreCaretPointSuggestion();
prevListItem = nullptr;
// XXX Why don't we set `type` attribute here??
@ -3659,16 +3661,16 @@ EditActionResult HTMLEditor::ConvertContentAroundRangesToList(
// MOZ_KnownLive(wrapContentInListItemElementResult.GetNewNode()): The
// result is grabbed by wrapContentInListItemElementResult.
const MoveNodeResult moveListItemElementResult =
Result<MoveNodeResult, nsresult> moveListItemElementResult =
MoveNodeToEndWithTransaction(
MOZ_KnownLive(*wrapContentInListItemElementResult.GetNewNode()),
*curList);
if (moveListItemElementResult.isErr()) {
if (MOZ_UNLIKELY(moveListItemElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return EditActionResult(moveListItemElementResult.inspectErr());
}
MOZ_ASSERT(aRanges.HasSavedRanges());
moveListItemElementResult.IgnoreCaretPointSuggestion();
moveListItemElementResult.inspect().IgnoreCaretPointSuggestion();
// If current node is not a block element, new list item should have
// following inline nodes too.
@ -4183,13 +4185,14 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::IndentListChildWithTransaction(
nextEditableSibling->NodeInfo()->NameAtom() &&
aPointInListElement.GetContainer()->NodeInfo()->NamespaceID() ==
nextEditableSibling->NodeInfo()->NamespaceID()) {
MoveNodeResult moveListElementResult = MoveNodeWithTransaction(
aContentMovingToSubList, EditorDOMPoint(nextEditableSibling, 0u));
if (moveListElementResult.isErr()) {
Result<MoveNodeResult, nsresult> moveListElementResult =
MoveNodeWithTransaction(aContentMovingToSubList,
EditorDOMPoint(nextEditableSibling, 0u));
if (MOZ_UNLIKELY(moveListElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return Err(moveListElementResult.unwrapErr());
return moveListElementResult.propagateErr();
}
return moveListElementResult.UnwrapCaretPoint();
return moveListElementResult.unwrap().UnwrapCaretPoint();
}
}
@ -4205,13 +4208,14 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::IndentListChildWithTransaction(
previousEditableSibling->NodeInfo()->NameAtom() &&
aPointInListElement.GetContainer()->NodeInfo()->NamespaceID() ==
previousEditableSibling->NodeInfo()->NamespaceID()) {
MoveNodeResult moveListElementResult = MoveNodeToEndWithTransaction(
aContentMovingToSubList, *previousEditableSibling);
if (moveListElementResult.isErr()) {
Result<MoveNodeResult, nsresult> moveListElementResult =
MoveNodeToEndWithTransaction(aContentMovingToSubList,
*previousEditableSibling);
if (MOZ_UNLIKELY(moveListElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return Err(moveListElementResult.unwrapErr());
return moveListElementResult.propagateErr();
}
return moveListElementResult.UnwrapCaretPoint();
return moveListElementResult.unwrap().UnwrapCaretPoint();
}
}
@ -4249,14 +4253,15 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::IndentListChildWithTransaction(
// Finally, we should move aContentMovingToSubList into aSubListElement.
const RefPtr<Element> subListElement = *aSubListElement;
MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(aContentMovingToSubList, *subListElement);
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return Err(moveNodeResult.unwrapErr());
return moveNodeResult.propagateErr();
}
if (moveNodeResult.HasCaretPointSuggestion()) {
pointToPutCaret = moveNodeResult.UnwrapCaretPoint();
MoveNodeResult unwrappedMoveNodeResult = moveNodeResult.unwrap();
if (unwrappedMoveNodeResult.HasCaretPointSuggestion()) {
pointToPutCaret = unwrappedMoveNodeResult.UnwrapCaretPoint();
}
return pointToPutCaret;
}
@ -4622,14 +4627,15 @@ nsresult HTMLEditor::HandleCSSIndentAroundRanges(AutoRangeArray& aRanges,
// Move the content into the <div> which has start margin.
// MOZ_KnownLive because 'arrayOfContents' is guaranteed to
// keep it alive.
MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(MOZ_KnownLive(content), *divElement);
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return moveNodeResult.unwrapErr();
}
if (moveNodeResult.HasCaretPointSuggestion()) {
pointToPutCaret = moveNodeResult.UnwrapCaretPoint();
MoveNodeResult unwrappedMoveNodeResult = moveNodeResult.unwrap();
if (unwrappedMoveNodeResult.HasCaretPointSuggestion()) {
pointToPutCaret = unwrappedMoveNodeResult.UnwrapCaretPoint();
}
}
@ -4888,14 +4894,16 @@ nsresult HTMLEditor::HandleHTMLIndentAroundRanges(AutoRangeArray& aRanges,
subListElement = createNewListElementResult.UnwrapNewNode();
}
MoveNodeResult moveListItemElementResult =
Result<MoveNodeResult, nsresult> moveListItemElementResult =
MoveNodeToEndWithTransaction(*listItem, *subListElement);
if (moveListItemElementResult.isErr()) {
if (MOZ_UNLIKELY(moveListItemElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return moveListItemElementResult.unwrapErr();
}
if (moveListItemElementResult.HasCaretPointSuggestion()) {
pointToPutCaret = moveListItemElementResult.UnwrapCaretPoint();
MoveNodeResult unwrappedMoveListItemElementResult =
moveListItemElementResult.unwrap();
if (unwrappedMoveListItemElementResult.HasCaretPointSuggestion()) {
pointToPutCaret = unwrappedMoveListItemElementResult.UnwrapCaretPoint();
}
// Remember the list item element which we indented now for ignoring its
@ -4952,14 +4960,16 @@ nsresult HTMLEditor::HandleHTMLIndentAroundRanges(AutoRangeArray& aRanges,
// tuck the node into the end of the active blockquote
// MOZ_KnownLive because 'arrayOfContents' is guaranteed to
// keep it alive.
MoveNodeResult moveNodeResult = MoveNodeToEndWithTransaction(
MOZ_KnownLive(content), *blockquoteElement);
if (moveNodeResult.isErr()) {
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(MOZ_KnownLive(content),
*blockquoteElement);
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return moveNodeResult.unwrapErr();
}
if (moveNodeResult.HasCaretPointSuggestion()) {
pointToPutCaret = moveNodeResult.UnwrapCaretPoint();
MoveNodeResult unwrappedMoveNodeResult = moveNodeResult.unwrap();
if (unwrappedMoveNodeResult.HasCaretPointSuggestion()) {
pointToPutCaret = unwrappedMoveNodeResult.UnwrapCaretPoint();
}
subListElement = nullptr;
}
@ -5464,14 +5474,14 @@ SplitRangeOffFromNodeResult HTMLEditor::HandleOutdentAtSelectionInternal(
NS_WARNING_ASSERTION(
afterCurrentList.IsSet(),
"Failed to set it to after current list element");
const MoveNodeResult moveListElementResult =
Result<MoveNodeResult, nsresult> moveListElementResult =
MoveNodeWithTransaction(*lastChildContent, afterCurrentList);
if (moveListElementResult.isErr()) {
if (MOZ_UNLIKELY(moveListElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return SplitRangeOffFromNodeResult(
moveListElementResult.unwrapErr());
}
nsresult rv = moveListElementResult.SuggestCaretPointTo(
nsresult rv = moveListElementResult.inspect().SuggestCaretPointTo(
*this, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaret::AndIgnoreTrivialError});
@ -6455,14 +6465,16 @@ CreateElementResult HTMLEditor::AlignNodesAndDescendants(
// Tuck the node into the end of the active div
//
// MOZ_KnownLive because 'aArrayOfContents' is guaranteed to keep it alive.
MoveNodeResult moveNodeResult = MoveNodeToEndWithTransaction(
MOZ_KnownLive(content), *createdDivElement);
if (moveNodeResult.isErr()) {
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(MOZ_KnownLive(content),
*createdDivElement);
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return CreateElementResult(moveNodeResult.unwrapErr());
}
if (moveNodeResult.HasCaretPointSuggestion()) {
pointToPutCaret = moveNodeResult.UnwrapCaretPoint();
MoveNodeResult unwrappedMoveNodeResult = moveNodeResult.unwrap();
if (unwrappedMoveNodeResult.HasCaretPointSuggestion()) {
pointToPutCaret = unwrappedMoveNodeResult.UnwrapCaretPoint();
}
}
@ -6580,14 +6592,15 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::AlignBlockContentsWithDivElement(
// Anyway, I don't think that we should move editable contents
// over non-editable contents. Chrome does no do that.
while (lastEditableContent && (lastEditableContent != newDivElement)) {
MoveNodeResult moveNodeResult = MoveNodeWithTransaction(
Result<MoveNodeResult, nsresult> moveNodeResult = MoveNodeWithTransaction(
*lastEditableContent, EditorDOMPoint(newDivElement, 0u));
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return Err(moveNodeResult.unwrapErr());
return moveNodeResult.propagateErr();
}
if (moveNodeResult.HasCaretPointSuggestion()) {
pointToPutCaret = moveNodeResult.UnwrapCaretPoint();
MoveNodeResult unwrappedMoveNodeResult = moveNodeResult.unwrap();
if (unwrappedMoveNodeResult.HasCaretPointSuggestion()) {
pointToPutCaret = unwrappedMoveNodeResult.UnwrapCaretPoint();
}
lastEditableContent = HTMLEditUtils::GetLastChild(
aBlockElement, {WalkTreeOption::IgnoreNonEditableNode});
@ -6985,15 +6998,17 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::SplitElementsAtEveryBRElement(
// Move break outside of container and also put in node list
// MOZ_KnownLive because 'arrayOfBRElements' is guaranteed to keep it alive.
MoveNodeResult moveBRElementResult = MoveNodeWithTransaction(
MOZ_KnownLive(brElement),
splitNodeResult.AtNextContent<EditorDOMPoint>());
if (moveBRElementResult.isErr()) {
Result<MoveNodeResult, nsresult> moveBRElementResult =
MoveNodeWithTransaction(
MOZ_KnownLive(brElement),
splitNodeResult.AtNextContent<EditorDOMPoint>());
if (MOZ_UNLIKELY(moveBRElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return Err(moveBRElementResult.unwrapErr());
return moveBRElementResult.propagateErr();
}
moveBRElementResult.MoveCaretPointTo(pointToPutCaret,
{SuggestCaret::OnlyIfHasSuggestion});
MoveNodeResult unwrappedMoveBRElementResult = moveBRElementResult.unwrap();
unwrappedMoveBRElementResult.MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
aOutArrayOfContents.AppendElement(brElement);
nextContent = splitNodeResult.GetNextContent();
@ -7732,13 +7747,13 @@ HTMLEditor::HandleInsertParagraphInListItemElement(
// If aListItemElement is in an invalid sub-list element, move it into
// the grand parent list element in order to outdent.
if (HTMLEditUtils::IsAnyListElement(afterLeftListElement.GetContainer())) {
const MoveNodeResult moveListItemElementResult =
Result<MoveNodeResult, nsresult> moveListItemElementResult =
MoveNodeWithTransaction(aListItemElement, afterLeftListElement);
if (moveListItemElementResult.isErr()) {
if (MOZ_UNLIKELY(moveListItemElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return Err(moveListItemElementResult.unwrapErr());
return moveListItemElementResult.propagateErr();
}
moveListItemElementResult.IgnoreCaretPointSuggestion();
moveListItemElementResult.inspect().IgnoreCaretPointSuggestion();
return EditorDOMPoint(&aListItemElement, 0u);
}
@ -8007,14 +8022,15 @@ CreateElementResult HTMLEditor::WrapContentsInBlockquoteElementsWithTransaction(
}
// MOZ_KnownLive because 'aArrayOfContents' is guaranteed to/ keep it alive.
MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(MOZ_KnownLive(content), *curBlock);
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return CreateElementResult(moveNodeResult.unwrapErr());
}
moveNodeResult.MoveCaretPointTo(pointToPutCaret,
{SuggestCaret::OnlyIfHasSuggestion});
MoveNodeResult unwrappedMoveNodeResult = moveNodeResult.unwrap();
unwrappedMoveNodeResult.MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
}
return blockElementToPutCaret
? CreateElementResult(std::move(blockElementToPutCaret),
@ -8328,14 +8344,16 @@ CreateElementResult HTMLEditor::CreateOrChangeBlockContainerElement(
blockElementToPutCaret = newBlockElement;
// MOZ_KnownLive because 'aArrayOfContents' is guaranteed to keep it
// alive.
MoveNodeResult moveNodeResult = MoveNodeToEndWithTransaction(
MOZ_KnownLive(content), *newBlockElement);
if (moveNodeResult.isErr()) {
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(MOZ_KnownLive(content),
*newBlockElement);
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return CreateElementResult(moveNodeResult.unwrapErr());
}
moveNodeResult.MoveCaretPointTo(pointToPutCaret,
{SuggestCaret::OnlyIfHasSuggestion});
MoveNodeResult unwrappedMoveNodeResult = moveNodeResult.unwrap();
unwrappedMoveNodeResult.MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
curBlock = std::move(newBlockElement);
continue;
}
@ -8392,14 +8410,15 @@ CreateElementResult HTMLEditor::CreateOrChangeBlockContainerElement(
// alive. We could try to make that a rvalue ref and create a const array
// on the stack here, but callers are passing in auto arrays, and we don't
// want to introduce copies..
MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(MOZ_KnownLive(content), *curBlock);
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return CreateElementResult(moveNodeResult.unwrapErr());
}
moveNodeResult.MoveCaretPointTo(pointToPutCaret,
{SuggestCaret::OnlyIfHasSuggestion});
MoveNodeResult unwrappedMoveNodeResult = moveNodeResult.unwrap();
unwrappedMoveNodeResult.MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
}
}
return blockElementToPutCaret
@ -8561,13 +8580,13 @@ nsresult HTMLEditor::JoinNearestEditableNodesWithTransaction(
// If they don't have the same parent, first move the right node to after
// the left one
if (aNodeLeft.GetParentNode() != aNodeRight.GetParentNode()) {
const MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeWithTransaction(aNodeRight, EditorDOMPoint(&aNodeLeft));
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return moveNodeResult.unwrapErr();
}
nsresult rv = moveNodeResult.SuggestCaretPointTo(
nsresult rv = moveNodeResult.inspect().SuggestCaretPointTo(
*this, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaret::AndIgnoreTrivialError});
@ -9475,16 +9494,20 @@ nsresult HTMLEditor::LiftUpListItemElement(
}
EditorDOMPoint pointToPutCaret;
MoveNodeResult moveListItemElementResult =
MoveNodeWithTransaction(aListItemElement, pointToInsertListItem);
if (moveListItemElementResult.isErr()) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return moveListItemElementResult.unwrapErr();
{
Result<MoveNodeResult, nsresult> moveListItemElementResult =
MoveNodeWithTransaction(aListItemElement, pointToInsertListItem);
if (MOZ_UNLIKELY(moveListItemElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return moveListItemElementResult.unwrapErr();
}
MoveNodeResult unwrappedMoveListItemElementResult =
moveListItemElementResult.unwrap();
unwrappedMoveListItemElementResult.MoveCaretPointTo(
pointToPutCaret, *this,
{SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt});
}
moveListItemElementResult.MoveCaretPointTo(
pointToPutCaret, *this,
{SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt});
// Unwrap list item contents if they are no longer in a list
// XXX If the parent list element is a child of another list element
@ -10461,13 +10484,14 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition(
// new list element in the target `<div>` element to be positioned
// absolutely.
// MOZ_KnownLive because 'arrayOfContents' is guaranteed to keep it alive.
const MoveNodeResult moveNodeResult = MoveNodeToEndWithTransaction(
MOZ_KnownLive(content), *createdListElement);
if (moveNodeResult.isErr()) {
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(MOZ_KnownLive(content),
*createdListElement);
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return Err(moveNodeResult.unwrapErr());
return moveNodeResult.propagateErr();
}
nsresult rv = moveNodeResult.SuggestCaretPointTo(
nsresult rv = moveNodeResult.inspect().SuggestCaretPointTo(
*this, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaret::AndIgnoreTrivialError});
@ -10571,13 +10595,13 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition(
// Move current list item element into the createdListElement (could be
// non-list element due to the above bug) in a candidate `<div>` element
// to be positioned absolutely.
const MoveNodeResult moveListItemElementResult =
Result<MoveNodeResult, nsresult> moveListItemElementResult =
MoveNodeToEndWithTransaction(*listItemElement, *createdListElement);
if (moveListItemElementResult.isErr()) {
if (MOZ_UNLIKELY(moveListItemElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return Err(moveListItemElementResult.unwrapErr());
return moveListItemElementResult.unwrapErr();
}
nsresult rv = moveListItemElementResult.SuggestCaretPointTo(
nsresult rv = moveListItemElementResult.inspect().SuggestCaretPointTo(
*this, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaret::AndIgnoreTrivialError});
@ -10628,13 +10652,13 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition(
}
// MOZ_KnownLive because 'arrayOfContents' is guaranteed to keep it alive.
const MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(MOZ_KnownLive(content), *targetDivElement);
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return moveNodeResult.unwrapErr();
}
nsresult rv = moveNodeResult.SuggestCaretPointTo(
nsresult rv = moveNodeResult.inspect().SuggestCaretPointTo(
*this, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaret::AndIgnoreTrivialError});

Просмотреть файл

@ -4023,16 +4023,16 @@ CreateElementResult HTMLEditor::ReplaceContainerWithTransactionInternal(
// For making all MoveNodeTransactions have a referenc node in the current
// parent, move nodes from last one to preceding ones.
for (const OwningNonNull<nsIContent>& child : Reversed(arrayOfChildren)) {
MoveNodeResult moveChildResult =
Result<MoveNodeResult, nsresult> moveChildResult =
MoveNodeWithTransaction(MOZ_KnownLive(child), // due to bug 1622253.
EditorDOMPoint(newContainer, 0u));
if (moveChildResult.isErr()) {
if (MOZ_UNLIKELY(moveChildResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return CreateElementResult(moveChildResult.unwrapErr());
}
// We'll suggest new caret point which is suggested by new container
// element insertion result. Therefore, we need to do nothing here.
moveChildResult.IgnoreCaretPointSuggestion();
moveChildResult.inspect().IgnoreCaretPointSuggestion();
}
}
@ -4088,13 +4088,13 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::RemoveContainerWithTransaction(
// For making all MoveNodeTransactions have a referenc node in the current
// parent, move nodes from last one to preceding ones.
for (const OwningNonNull<nsIContent>& child : Reversed(arrayOfChildren)) {
MoveNodeResult moveChildResult = MoveNodeWithTransaction(
Result<MoveNodeResult, nsresult> moveChildResult = MoveNodeWithTransaction(
MOZ_KnownLive(child), // due to bug 1622253.
previousChild ? EditorDOMPoint::After(previousChild)
: EditorDOMPoint(parentNode, 0u));
if (moveChildResult.isErr()) {
if (MOZ_UNLIKELY(moveChildResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return Err(moveChildResult.unwrapErr());
return moveChildResult.propagateErr();
}
// If the reference node was moved to different container, try to recover
// the original position.
@ -4104,14 +4104,14 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::RemoveContainerWithTransaction(
NS_WARNING(
"Neither the reference (previous) sibling nor the moved child was "
"in the expected parent node");
moveChildResult.IgnoreCaretPointSuggestion();
moveChildResult.inspect().IgnoreCaretPointSuggestion();
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
previousChild = child->GetPreviousSibling();
}
// We'll need to put caret at next sibling of aElement if nobody moves
// content nodes under the parent node except us.
moveChildResult.IgnoreCaretPointSuggestion();
moveChildResult.inspect().IgnoreCaretPointSuggestion();
}
if (aElement.GetParentNode() && aElement.GetParentNode() != parentNode) {
@ -5326,32 +5326,32 @@ nsresult HTMLEditor::DoJoinNodes(nsIContent& aContentToKeep,
return NS_OK;
}
MoveNodeResult HTMLEditor::MoveNodeWithTransaction(
Result<MoveNodeResult, nsresult> HTMLEditor::MoveNodeWithTransaction(
nsIContent& aContentToMove, const EditorDOMPoint& aPointToInsert) {
MOZ_ASSERT(aPointToInsert.IsSetAndValid());
EditorDOMPoint oldPoint(&aContentToMove);
if (NS_WARN_IF(!oldPoint.IsSet())) {
return MoveNodeResult(NS_ERROR_FAILURE);
return Err(NS_ERROR_FAILURE);
}
// Don't do anything if it's already in right place.
if (aPointToInsert == oldPoint) {
return MoveNodeIgnored(aPointToInsert.NextPoint());
return MoveNodeResult::IgnoredResult(aPointToInsert.NextPoint());
}
RefPtr<MoveNodeTransaction> moveNodeTransaction =
MoveNodeTransaction::MaybeCreate(*this, aContentToMove, aPointToInsert);
if (MOZ_UNLIKELY(!moveNodeTransaction)) {
NS_WARNING("MoveNodeTransaction::MaybeCreate() failed");
return MoveNodeResult(NS_ERROR_FAILURE);
return Err(NS_ERROR_FAILURE);
}
IgnoredErrorResult ignoredError;
AutoEditSubActionNotifier startToHandleEditSubAction(
*this, EditSubAction::eMoveNode, nsIEditor::eNext, ignoredError);
if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) {
return MoveNodeResult(ignoredError.StealNSResult());
return Err(ignoredError.StealNSResult());
}
NS_WARNING_ASSERTION(
!ignoredError.Failed(),
@ -5381,17 +5381,17 @@ MoveNodeResult HTMLEditor::MoveNodeWithTransaction(
if (MOZ_UNLIKELY(Destroyed())) {
NS_WARNING(
"MoveNodeTransaction::DoTransaction() caused destroying the editor");
return MoveNodeResult(NS_ERROR_EDITOR_DESTROYED);
return Err(NS_ERROR_EDITOR_DESTROYED);
}
if (NS_FAILED(rv)) {
NS_WARNING("MoveNodeTransaction::DoTransaction() failed");
return MoveNodeResult(rv);
return Err(rv);
}
TopLevelEditSubActionDataRef().DidInsertContent(*this, aContentToMove);
return MoveNodeHandled(
return MoveNodeResult::HandledResult(
moveNodeTransaction->SuggestNextInsertionPoint<EditorDOMPoint>(),
moveNodeTransaction->SuggestPointToPutCaret<EditorDOMPoint>());
}

Просмотреть файл

@ -1845,8 +1845,9 @@ class HTMLEditor final : public EditorBase,
* @param aContentToMove The node to be moved.
* @param aPointToInsert The point where aContentToMove will be inserted.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT MoveNodeResult MoveNodeWithTransaction(
nsIContent& aContentToMove, const EditorDOMPoint& aPointToInsert);
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<MoveNodeResult, nsresult>
MoveNodeWithTransaction(nsIContent& aContentToMove,
const EditorDOMPoint& aPointToInsert);
/**
* MoveNodeToEndWithTransaction() moves aContentToMove to end of
@ -1856,8 +1857,9 @@ class HTMLEditor final : public EditorBase,
* @param aNewContainer The new container which will contain aContentToMove
* as its last child.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT MoveNodeResult MoveNodeToEndWithTransaction(
nsIContent& aContentToMove, nsINode& aNewContainer) {
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<MoveNodeResult, nsresult>
MoveNodeToEndWithTransaction(nsIContent& aContentToMove,
nsINode& aNewContainer) {
return MoveNodeWithTransaction(aContentToMove,
EditorDOMPoint::AtEndOf(aNewContainer));
}
@ -1876,7 +1878,7 @@ class HTMLEditor final : public EditorBase,
* moving node or creating new <span> element.
*/
enum class PreserveWhiteSpaceStyle { No, Yes };
[[nodiscard]] MOZ_CAN_RUN_SCRIPT MoveNodeResult
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<MoveNodeResult, nsresult>
MoveNodeOrChildrenWithTransaction(
nsIContent& aContentToMove, const EditorDOMPoint& aPointToInsert,
PreserveWhiteSpaceStyle aPreserveWhiteSpaceStyle);
@ -1905,9 +1907,10 @@ class HTMLEditor final : public EditorBase,
* style, this method will set `style` attribute to
* moving node or creating new <span> element.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT MoveNodeResult MoveChildrenWithTransaction(
Element& aElement, const EditorDOMPoint& aPointToInsert,
PreserveWhiteSpaceStyle aPreserveWhiteSpaceStyle);
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<MoveNodeResult, nsresult>
MoveChildrenWithTransaction(Element& aElement,
const EditorDOMPoint& aPointToInsert,
PreserveWhiteSpaceStyle aPreserveWhiteSpaceStyle);
/**
* CanMoveChildren() returns true if `MoveChildrenWithTransaction()` can move
@ -1992,7 +1995,7 @@ class HTMLEditor final : public EditorBase,
* container while we're moving nodes.
*/
enum class MoveToEndOfContainer { Yes, No };
[[nodiscard]] MOZ_CAN_RUN_SCRIPT MoveNodeResult
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<MoveNodeResult, nsresult>
MoveOneHardLineContentsWithTransaction(
const EditorDOMPoint& aPointInHardLine,
const EditorDOMPoint& aPointToInsert, const Element& aEditingHost,

Просмотреть файл

@ -4862,7 +4862,8 @@ Result<bool, nsresult> HTMLEditor::CanMoveOrDeleteSomethingInHardLine(
return startPoint.GetNextSiblingOfChild() != endPoint.GetChild();
}
MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
Result<MoveNodeResult, nsresult>
HTMLEditor::MoveOneHardLineContentsWithTransaction(
const EditorDOMPoint& aPointInHardLine,
const EditorDOMPoint& aPointToInsert, const Element& aEditingHost,
MoveToEndOfContainer
@ -4872,7 +4873,7 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
MOZ_ASSERT(aPointToInsert.IsSetAndValid());
if (NS_WARN_IF(aPointToInsert.IsInNativeAnonymousSubtree())) {
return MoveNodeResult(NS_ERROR_INVALID_ARG);
return Err(NS_ERROR_INVALID_ARG);
}
const RefPtr<Element> srcInclusiveAncestorBlock =
@ -4964,7 +4965,7 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
"AutoRangeArray::"
"SplitTextNodesAtEndBoundariesAndParentInlineElementsAtBoundaries()"
" failed");
return MoveNodeResult(splitResult.unwrapErr());
return Err(splitResult.unwrapErr());
}
if (splitResult.inspect().IsSet()) {
pointToPutCaret = splitResult.unwrap();
@ -4976,7 +4977,7 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
NS_WARNING(
"AutoRangeArray::CollectEditTargetNodes(EditSubAction::"
"eMergeBlockContents, CollectNonEditableNodes::Yes) failed");
return MoveNodeResult(rv);
return Err(rv);
}
}
@ -4987,7 +4988,7 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
NS_WARNING(
"HTMLEditor::MaybeSplitElementsAtEveryBRElement(EditSubAction::"
"eMergeBlockContents) failed");
return MoveNodeResult(splitAtBRElementsResult.inspectErr());
return splitAtBRElementsResult.propagateErr();
}
if (splitAtBRElementsResult.inspect().IsSet()) {
pointToPutCaret = splitAtBRElementsResult.unwrap();
@ -4995,24 +4996,25 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
}
if (!pointToInsert.IsSetAndValid()) {
return MoveNodeResult(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
if (AllowsTransactionsToChangeSelection() && pointToPutCaret.IsSet()) {
nsresult rv = CollapseSelectionTo(pointToPutCaret);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::CollapseSelectionTo() failed");
return MoveNodeResult(rv);
return Err(rv);
}
}
if (arrayOfContents.IsEmpty()) {
return MoveNodeIgnored(std::move(pointToInsert));
return MoveNodeResult::IgnoredResult(std::move(pointToInsert));
}
// Track the range which contains the moved contents.
EditorDOMRange movedContentRange(pointToInsert);
MoveNodeResult moveContentsInLineResult = MoveNodeIgnored(pointToInsert);
MoveNodeResult moveContentsInLineResult =
MoveNodeResult::IgnoredResult(pointToInsert);
if (aMoveToEndOfContainer == MoveToEndOfContainer::Yes) {
pointToInsert.SetToEndOf(pointToInsert.GetContainer());
}
@ -5022,20 +5024,20 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
// If the content is a block element, move all children of it to the
// new container, and then, remove the (probably) empty block element.
if (HTMLEditUtils::IsBlockElement(content)) {
moveContentsInLineResult |=
Result<MoveNodeResult, nsresult> moveChildrenResult =
MoveChildrenWithTransaction(MOZ_KnownLive(*content->AsElement()),
pointToInsert, preserveWhiteSpaceStyle);
if (moveContentsInLineResult.isErr()) {
if (MOZ_UNLIKELY(moveChildrenResult.isErr())) {
NS_WARNING("HTMLEditor::MoveChildrenWithTransaction() failed");
return moveContentsInLineResult;
return moveChildrenResult;
}
moveContentsInLineResult |= moveChildrenResult.inspect();
moveContentsInLineResult.MarkAsHandled();
// MOZ_KnownLive due to bug 1622253
nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(content));
if (MOZ_UNLIKELY(rv == NS_ERROR_EDITOR_DESTROYED)) {
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed");
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
moveContentsInLineResult.IgnoreCaretPointSuggestion();
return MoveNodeResult(NS_ERROR_EDITOR_DESTROYED);
return Err(NS_ERROR_EDITOR_DESTROYED);
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
@ -5056,16 +5058,18 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
nsresult rv = DeleteNodeWithTransaction(*emptyContent);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed");
return MoveNodeResult(rv);
return Err(rv);
}
} else {
// MOZ_KnownLive due to bug 1622253
moveContentsInLineResult |= MoveNodeOrChildrenWithTransaction(
MOZ_KnownLive(content), pointToInsert, preserveWhiteSpaceStyle);
if (moveContentsInLineResult.isErr()) {
Result<MoveNodeResult, nsresult> moveNodeOrChildrenResult =
MoveNodeOrChildrenWithTransaction(
MOZ_KnownLive(content), pointToInsert, preserveWhiteSpaceStyle);
if (MOZ_UNLIKELY(moveNodeOrChildrenResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeOrChildrenWithTransaction() failed");
return moveContentsInLineResult;
return moveNodeOrChildrenResult;
}
moveContentsInLineResult |= moveNodeOrChildrenResult.inspect();
}
}
// For backward compatibility, we should move contents to end of the
@ -5141,7 +5145,7 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
*textNodeEndingWithUnnecessaryLineBreak));
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed");
return MoveNodeResult(rv);
return Err(rv);
}
} else {
nsresult rv = DeleteTextWithTransaction(
@ -5149,7 +5153,7 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
textNodeEndingWithUnnecessaryLineBreak->TextDataLength() - 1u, 1u);
if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::DeleteTextWithTransaction() failed");
return MoveNodeResult(rv);
return Err(rv);
}
}
}
@ -5166,7 +5170,7 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
}
EditorRawDOMPoint atUnnecessaryLineBreak(lastLineBreakContent);
if (NS_WARN_IF(!atUnnecessaryLineBreak.IsSet())) {
return MoveNodeResult(NS_ERROR_FAILURE);
return Err(NS_ERROR_FAILURE);
}
// If the found unnecessary line break is not what we moved above, we
// shouldn't remove it. E.g., the web app may have inserted it intentionally.
@ -5184,7 +5188,7 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
MOZ_KnownLive(*textNode), textNode->TextDataLength() - 1u, 1u);
if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::DeleteTextWithTransaction() failed");
return MoveNodeResult(rv);
return Err(rv);
}
return moveContentsInLineResult;
}
@ -5199,7 +5203,7 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
nsresult rv = DeleteNodeWithTransaction(*inlineElement);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed");
return MoveNodeResult(rv);
return Err(rv);
}
return moveContentsInLineResult;
}
@ -5208,7 +5212,7 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
nsresult rv = DeleteNodeWithTransaction(*lastLineBreakContent);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed");
return MoveNodeResult(rv);
return Err(rv);
}
return moveContentsInLineResult;
}
@ -5224,7 +5228,7 @@ Result<bool, nsresult> HTMLEditor::CanMoveNodeOrChildren(
return true;
}
MoveNodeResult HTMLEditor::MoveNodeOrChildrenWithTransaction(
Result<MoveNodeResult, nsresult> HTMLEditor::MoveNodeOrChildrenWithTransaction(
nsIContent& aContentToMove, const EditorDOMPoint& aPointToInsert,
PreserveWhiteSpaceStyle aPreserveWhiteSpaceStyle) {
MOZ_ASSERT(IsEditActionDataAvailable());
@ -5294,7 +5298,7 @@ MoveNodeResult HTMLEditor::MoveNodeOrChildrenWithTransaction(
*this, MOZ_KnownLive(*styledElement), *nsGkAtoms::white_space,
GetWhiteSpaceStyleValue(srcWhiteSpaceStyle.value()));
if (NS_WARN_IF(Destroyed())) {
return MoveNodeResult(NS_ERROR_EDITOR_DESTROYED);
return Err(NS_ERROR_EDITOR_DESTROYED);
}
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"CSSEditUtils::SetCSSPropertyWithTransaction("
@ -5308,7 +5312,7 @@ MoveNodeResult HTMLEditor::MoveNodeOrChildrenWithTransaction(
aContentToMove)) {
RefPtr<Element> newSpanElement = CreateHTMLContent(nsGkAtoms::span);
if (NS_WARN_IF(!newSpanElement)) {
return MoveNodeResult(NS_ERROR_FAILURE);
return Err(NS_ERROR_FAILURE);
}
nsAutoString styleAttrValue(u"white-space: "_ns);
styleAttrValue.Append(
@ -5322,7 +5326,7 @@ MoveNodeResult HTMLEditor::MoveNodeOrChildrenWithTransaction(
InsertNodeWithTransaction<Element>(*newSpanElement,
aPointToInsert);
if (NS_WARN_IF(insertSpanElementResult.EditorDestroyed())) {
return MoveNodeResult(NS_ERROR_EDITOR_DESTROYED);
return Err(NS_ERROR_EDITOR_DESTROYED);
}
NS_WARNING_ASSERTION(
insertSpanElementResult.isOk(),
@ -5339,38 +5343,43 @@ MoveNodeResult HTMLEditor::MoveNodeOrChildrenWithTransaction(
}
}
// If it can, move it there.
MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeWithTransaction(aContentToMove, pointToInsert);
NS_WARNING_ASSERTION(moveNodeResult.isOk(),
"HTMLEditor::MoveNodeWithTransaction() failed");
// XXX This is odd to override the handled state here, but stopping this
// hits an NS_ASSERTION in WhiteSpaceVisibilityKeeper::
// MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement.
moveNodeResult.MarkAsHandled();
if (moveNodeResult.isOk()) {
MoveNodeResult unwrappedMoveNodeResult = moveNodeResult.unwrap();
unwrappedMoveNodeResult.MarkAsHandled();
return unwrappedMoveNodeResult;
}
return moveNodeResult;
}
// If it can't, move its children (if any), and then delete it.
MoveNodeResult moveNodeResult = [&]() MOZ_CAN_RUN_SCRIPT {
auto moveNodeResult =
[&]() MOZ_CAN_RUN_SCRIPT -> Result<MoveNodeResult, nsresult> {
if (!aContentToMove.IsElement()) {
return MoveNodeHandled(aPointToInsert);
return MoveNodeResult::HandledResult(aPointToInsert);
}
MoveNodeResult moveChildrenResult =
Result<MoveNodeResult, nsresult> moveChildrenResult =
MoveChildrenWithTransaction(MOZ_KnownLive(*aContentToMove.AsElement()),
aPointToInsert, aPreserveWhiteSpaceStyle);
NS_WARNING_ASSERTION(moveChildrenResult.isOk(),
"HTMLEditor::MoveChildrenWithTransaction() failed");
return moveChildrenResult;
}();
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
return moveNodeResult; // Already warned in the lambda.
}
nsresult rv = DeleteNodeWithTransaction(aContentToMove);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed");
moveNodeResult.IgnoreCaretPointSuggestion();
return MoveNodeResult(rv);
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
return Err(rv);
}
if (!MayHaveMutationEventListeners()) {
return moveNodeResult;
@ -5378,11 +5387,11 @@ MoveNodeResult HTMLEditor::MoveNodeOrChildrenWithTransaction(
// Mutation event listener may make `offset` value invalid with
// removing some previous children while we call
// `DeleteNodeWithTransaction()` so that we should adjust it here.
if (moveNodeResult.NextInsertionPointRef().IsSetAndValid()) {
if (moveNodeResult.inspect().NextInsertionPointRef().IsSetAndValid()) {
return moveNodeResult;
}
moveNodeResult.IgnoreCaretPointSuggestion();
return MoveNodeHandled(
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
return MoveNodeResult::HandledResult(
EditorDOMPoint::AtEndOf(*aPointToInsert.GetContainer()));
}
@ -5402,24 +5411,28 @@ Result<bool, nsresult> HTMLEditor::CanMoveChildren(
return false;
}
MoveNodeResult HTMLEditor::MoveChildrenWithTransaction(
Result<MoveNodeResult, nsresult> HTMLEditor::MoveChildrenWithTransaction(
Element& aElement, const EditorDOMPoint& aPointToInsert,
PreserveWhiteSpaceStyle aPreserveWhiteSpaceStyle) {
MOZ_ASSERT(aPointToInsert.IsSet());
if (NS_WARN_IF(&aElement == aPointToInsert.GetContainer())) {
return MoveNodeResult(NS_ERROR_INVALID_ARG);
return Err(NS_ERROR_INVALID_ARG);
}
MoveNodeResult moveChildrenResult = MoveNodeIgnored(aPointToInsert);
MoveNodeResult moveChildrenResult =
MoveNodeResult::IgnoredResult(aPointToInsert);
while (aElement.GetFirstChild()) {
moveChildrenResult |= MoveNodeOrChildrenWithTransaction(
MOZ_KnownLive(*aElement.GetFirstChild()),
moveChildrenResult.NextInsertionPoint(), aPreserveWhiteSpaceStyle);
if (moveChildrenResult.isErr()) {
Result<MoveNodeResult, nsresult> moveNodeOrChildrenResult =
MoveNodeOrChildrenWithTransaction(
MOZ_KnownLive(*aElement.GetFirstChild()),
moveChildrenResult.NextInsertionPointRef(),
aPreserveWhiteSpaceStyle);
if (MOZ_UNLIKELY(moveNodeOrChildrenResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeOrChildrenWithTransaction() failed");
return moveChildrenResult;
return moveNodeOrChildrenResult;
}
moveChildrenResult |= moveNodeOrChildrenResult.inspect();
}
return moveChildrenResult;
}

Просмотреть файл

@ -593,13 +593,16 @@ SplitRangeOffFromNodeResult HTMLEditor::SetInlinePropertyOnTextNode(
}
if (result.inspect()) {
// Previous sib is already right kind of inline node; slide this over
MoveNodeResult moveTextNodeResult = MoveNodeToEndWithTransaction(
MOZ_KnownLive(*middleTextNode), element);
if (moveTextNodeResult.isErr()) {
Result<MoveNodeResult, nsresult> moveTextNodeResult =
MoveNodeToEndWithTransaction(MOZ_KnownLive(*middleTextNode),
element);
if (MOZ_UNLIKELY(moveTextNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return SplitRangeOffFromNodeResult(moveTextNodeResult.unwrapErr());
}
moveTextNodeResult.MoveCaretPointTo(
MoveNodeResult unwrappedMoveTextNodeResult =
moveTextNodeResult.unwrap();
unwrappedMoveTextNodeResult.MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
return SplitRangeOffFromNodeResult(leftTextNode, middleTextNode,
rightTextNode,
@ -618,13 +621,16 @@ SplitRangeOffFromNodeResult HTMLEditor::SetInlinePropertyOnTextNode(
}
if (result.inspect()) {
// Following sib is already right kind of inline node; slide this over
MoveNodeResult moveTextNodeResult = MoveNodeWithTransaction(
MOZ_KnownLive(*middleTextNode), EditorDOMPoint(sibling, 0u));
if (moveTextNodeResult.isErr()) {
Result<MoveNodeResult, nsresult> moveTextNodeResult =
MoveNodeWithTransaction(MOZ_KnownLive(*middleTextNode),
EditorDOMPoint(sibling, 0u));
if (MOZ_UNLIKELY(moveTextNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return SplitRangeOffFromNodeResult(moveTextNodeResult.unwrapErr());
}
moveTextNodeResult.MoveCaretPointTo(
MoveNodeResult unwrappedMoveTextNodeResult =
moveTextNodeResult.unwrap();
unwrappedMoveTextNodeResult.MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
return SplitRangeOffFromNodeResult(leftTextNode, middleTextNode,
rightTextNode,
@ -699,14 +705,15 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::SetInlinePropertyOnNodeImpl(
return canMoveIntoPreviousSibling.propagateErr();
}
if (canMoveIntoPreviousSibling.inspect()) {
MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(aContent, *previousSibling);
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return Err(moveNodeResult.unwrapErr());
return moveNodeResult.propagateErr();
}
MoveNodeResult unwrappedMoveNodeResult = moveNodeResult.unwrap();
if (!nextSibling || !nextSibling->IsElement()) {
return moveNodeResult.UnwrapCaretPoint();
return unwrappedMoveNodeResult.UnwrapCaretPoint();
}
OwningNonNull<Element> nextElement(*nextSibling->AsElement());
Result<bool, nsresult> canMoveIntoNextSibling =
@ -714,13 +721,13 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::SetInlinePropertyOnNodeImpl(
&aValue);
if (canMoveIntoNextSibling.isErr()) {
NS_WARNING("HTMLEditor::ElementIsGoodContainerForTheStyle() failed");
moveNodeResult.IgnoreCaretPointSuggestion();
unwrappedMoveNodeResult.IgnoreCaretPointSuggestion();
return canMoveIntoNextSibling.propagateErr();
}
if (!canMoveIntoNextSibling.inspect()) {
return moveNodeResult.UnwrapCaretPoint();
return unwrappedMoveNodeResult.UnwrapCaretPoint();
}
moveNodeResult.IgnoreCaretPointSuggestion();
unwrappedMoveNodeResult.IgnoreCaretPointSuggestion();
// JoinNodesWithTransaction (DoJoinNodes) tries to collapse selection to
// the joined point and we want to skip updating `Selection` here.
@ -746,13 +753,13 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::SetInlinePropertyOnNodeImpl(
return canMoveIntoNextSibling.propagateErr();
}
if (canMoveIntoNextSibling.inspect()) {
MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeWithTransaction(aContent, EditorDOMPoint(nextElement, 0u));
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return Err(moveNodeResult.unwrapErr());
return moveNodeResult.propagateErr();
}
return moveNodeResult.UnwrapCaretPoint();
return moveNodeResult.unwrap().UnwrapCaretPoint();
}
}
@ -1284,16 +1291,20 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::ClearStyleAt(
// the left node left node. This is so we you don't revert back to the
// previous style if you happen to click at the end of a line.
if (brElement) {
MoveNodeResult moveBRElementResult =
MoveNodeWithTransaction(*brElement, pointToPutCaret);
if (moveBRElementResult.isErr()) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return Err(moveBRElementResult.unwrapErr());
{
Result<MoveNodeResult, nsresult> moveBRElementResult =
MoveNodeWithTransaction(*brElement, pointToPutCaret);
if (MOZ_UNLIKELY(moveBRElementResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return moveBRElementResult.propagateErr();
}
MoveNodeResult unwrappedMoveBRElementResult =
moveBRElementResult.unwrap();
unwrappedMoveBRElementResult.MoveCaretPointTo(
pointToPutCaret, *this,
{SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt});
}
moveBRElementResult.MoveCaretPointTo(
pointToPutCaret, *this,
{SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt});
if (splitResultAtStartOfNextNode.GetNextContent() &&
splitResultAtStartOfNextNode.GetNextContent()->IsInComposedDoc()) {
@ -2880,14 +2891,15 @@ CreateElementResult HTMLEditor::SetFontSizeOnTextNode(
*textNodeForTheRange, {WalkTreeOption::IgnoreNonEditableNode});
if (sibling && sibling->IsHTMLElement(bigOrSmallTagName)) {
// Previous sib is already right kind of inline node; slide this over
MoveNodeResult moveTextNodeResult =
Result<MoveNodeResult, nsresult> moveTextNodeResult =
MoveNodeToEndWithTransaction(*textNodeForTheRange, *sibling);
if (moveTextNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveTextNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return CreateElementResult(moveTextNodeResult.unwrapErr());
}
moveTextNodeResult.MoveCaretPointTo(pointToPutCaret, *this,
{SuggestCaret::OnlyIfHasSuggestion});
MoveNodeResult unwrappedMoveTextNodeResult = moveTextNodeResult.unwrap();
unwrappedMoveTextNodeResult.MoveCaretPointTo(
pointToPutCaret, *this, {SuggestCaret::OnlyIfHasSuggestion});
// XXX Should we return the new container?
return CreateElementResult::NotHandled(std::move(pointToPutCaret));
}
@ -2895,14 +2907,16 @@ CreateElementResult HTMLEditor::SetFontSizeOnTextNode(
*textNodeForTheRange, {WalkTreeOption::IgnoreNonEditableNode});
if (sibling && sibling->IsHTMLElement(bigOrSmallTagName)) {
// Following sib is already right kind of inline node; slide this over
MoveNodeResult moveTextNodeResult = MoveNodeWithTransaction(
*textNodeForTheRange, EditorDOMPoint(sibling, 0u));
if (moveTextNodeResult.isErr()) {
Result<MoveNodeResult, nsresult> moveTextNodeResult =
MoveNodeWithTransaction(*textNodeForTheRange,
EditorDOMPoint(sibling, 0u));
if (MOZ_UNLIKELY(moveTextNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return CreateElementResult(moveTextNodeResult.unwrapErr());
}
moveTextNodeResult.MoveCaretPointTo(pointToPutCaret, *this,
{SuggestCaret::OnlyIfHasSuggestion});
MoveNodeResult unwrappedMoveTextNodeResult = moveTextNodeResult.unwrap();
unwrappedMoveTextNodeResult.MoveCaretPointTo(
pointToPutCaret, *this, {SuggestCaret::OnlyIfHasSuggestion});
// XXX Should we return the new container?
return CreateElementResult::NotHandled(std::move(pointToPutCaret));
}
@ -3024,28 +3038,30 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::SetFontSizeWithBigOrSmallElement(
nsCOMPtr<nsIContent> sibling = HTMLEditUtils::GetPreviousSibling(
aContent, {WalkTreeOption::IgnoreNonEditableNode});
if (sibling && sibling->IsHTMLElement(bigOrSmallTagName)) {
MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeToEndWithTransaction(aContent, *sibling);
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeToEndWithTransaction() failed");
return Err(moveNodeResult.unwrapErr());
return moveNodeResult.propagateErr();
}
moveNodeResult.MoveCaretPointTo(pointToPutCaret,
{SuggestCaret::OnlyIfHasSuggestion});
MoveNodeResult unwrappedMoveNodeResult = moveNodeResult.unwrap();
unwrappedMoveNodeResult.MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
return pointToPutCaret;
}
sibling = HTMLEditUtils::GetNextSibling(
aContent, {WalkTreeOption::IgnoreNonEditableNode});
if (sibling && sibling->IsHTMLElement(bigOrSmallTagName)) {
MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
MoveNodeWithTransaction(aContent, EditorDOMPoint(sibling, 0u));
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
return Err(moveNodeResult.unwrapErr());
return moveNodeResult.propagateErr();
}
moveNodeResult.MoveCaretPointTo(pointToPutCaret,
{SuggestCaret::OnlyIfHasSuggestion});
MoveNodeResult unwrappedMoveNodeResult = moveNodeResult.unwrap();
unwrappedMoveNodeResult.MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
return pointToPutCaret;
}

Просмотреть файл

@ -288,7 +288,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
EditorDOMPoint(rightBlockElement, afterRightBlockChild.Offset()),
aEditingHost);
#endif // #ifdef DEBUG
MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
aHTMLEditor.MoveOneHardLineContentsWithTransaction(
EditorDOMPoint(rightBlockElement, afterRightBlockChild.Offset()),
EditorDOMPoint(&aLeftBlockElement, 0u), aEditingHost,
@ -303,17 +303,17 @@ EditActionResult WhiteSpaceVisibilityKeeper::
#ifdef DEBUG
MOZ_ASSERT(!firstLineHasContent.isErr());
if (firstLineHasContent.inspect()) {
NS_ASSERTION(moveNodeResult.Handled(),
NS_ASSERTION(moveNodeResult.inspect().Handled(),
"Failed to consider whether moving or not something");
} else {
NS_ASSERTION(moveNodeResult.Ignored(),
NS_ASSERTION(moveNodeResult.inspect().Ignored(),
"Failed to consider whether moving or not something");
}
#endif // #ifdef DEBUG
// We don't need to update selection here because of dontChangeMySelection
// above.
moveNodeResult.IgnoreCaretPointSuggestion();
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
ret |= moveNodeResult;
// Now, all children of rightBlockElement were moved to leftBlockElement.
// So, afterRightBlockChild is now invalid.
@ -457,30 +457,32 @@ EditActionResult WhiteSpaceVisibilityKeeper::
aHTMLEditor.CanMoveChildren(aRightBlockElement, aLeftBlockElement);
#endif // #ifdef DEBUG
// TODO: Stop using HTMLEditor::PreserveWhiteSpaceStyle::No due to no tests.
MoveNodeResult moveNodeResult = aHTMLEditor.MoveChildrenWithTransaction(
aRightBlockElement,
EditorDOMPoint(atLeftBlockChild.GetContainer(),
atLeftBlockChild.Offset()),
HTMLEditor::PreserveWhiteSpaceStyle::No);
if (NS_WARN_IF(moveNodeResult.EditorDestroyed())) {
return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
}
NS_WARNING_ASSERTION(
moveNodeResult.isOk(),
"HTMLEditor::MoveChildrenWithTransaction() failed, but ignored");
if (moveNodeResult.isOk()) {
Result<MoveNodeResult, nsresult> moveNodeResult =
aHTMLEditor.MoveChildrenWithTransaction(
aRightBlockElement,
EditorDOMPoint(atLeftBlockChild.GetContainer(),
atLeftBlockChild.Offset()),
HTMLEditor::PreserveWhiteSpaceStyle::No);
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
if (NS_WARN_IF(moveNodeResult.inspectErr() ==
NS_ERROR_EDITOR_DESTROYED)) {
return EditActionResult(moveNodeResult.unwrapErr());
}
NS_WARNING(
"HTMLEditor::MoveChildrenWithTransaction() failed, but ignored");
} else {
// We don't need to update selection here because of dontChangeMySelection
// above.
moveNodeResult.IgnoreCaretPointSuggestion();
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
ret |= moveNodeResult;
#ifdef DEBUG
MOZ_ASSERT(!rightBlockHasContent.isErr());
if (rightBlockHasContent.inspect()) {
NS_ASSERTION(moveNodeResult.Handled(),
NS_ASSERTION(moveNodeResult.inspect().Handled(),
"Failed to consider whether moving or not children");
} else {
NS_ASSERTION(moveNodeResult.Ignored(),
NS_ASSERTION(moveNodeResult.inspect().Ignored(),
"Failed to consider whether moving or not children");
}
#endif // #ifdef DEBUG
@ -576,7 +578,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
MOZ_DIAGNOSTIC_ASSERT(pointToMoveFirstLineContent.IsSetAndValid());
}
MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
aHTMLEditor.MoveOneHardLineContentsWithTransaction(
EditorDOMPoint(&aRightBlockElement, 0u),
pointToMoveFirstLineContent, aEditingHost);
@ -588,17 +590,17 @@ EditActionResult WhiteSpaceVisibilityKeeper::
#ifdef DEBUG
MOZ_ASSERT(!firstLineHasContent.isErr());
if (firstLineHasContent.inspect()) {
NS_ASSERTION(moveNodeResult.Handled(),
NS_ASSERTION(moveNodeResult.inspect().Handled(),
"Failed to consider whether moving or not something");
} else {
NS_ASSERTION(moveNodeResult.Ignored(),
NS_ASSERTION(moveNodeResult.inspect().Ignored(),
"Failed to consider whether moving or not something");
}
#endif // #ifdef DEBUG
// We don't need to update selection here because of dontChangeMySelection
// above.
moveNodeResult.IgnoreCaretPointSuggestion();
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
ret |= moveNodeResult;
}
@ -699,12 +701,12 @@ EditActionResult WhiteSpaceVisibilityKeeper::
#endif // #ifdef DEBUG
// Nodes are dissimilar types.
MoveNodeResult moveNodeResult =
Result<MoveNodeResult, nsresult> moveNodeResult =
aHTMLEditor.MoveOneHardLineContentsWithTransaction(
EditorDOMPoint(&aRightBlockElement, 0u),
EditorDOMPoint(&aLeftBlockElement, 0u), aEditingHost,
HTMLEditor::MoveToEndOfContainer::Yes);
if (moveNodeResult.isErr()) {
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
NS_WARNING(
"HTMLEditor::MoveOneHardLineContentsWithTransaction("
"MoveToEndOfContainer::Yes) failed");
@ -714,17 +716,17 @@ EditActionResult WhiteSpaceVisibilityKeeper::
#ifdef DEBUG
MOZ_ASSERT(!firstLineHasContent.isErr());
if (firstLineHasContent.inspect()) {
NS_ASSERTION(moveNodeResult.Handled(),
NS_ASSERTION(moveNodeResult.inspect().Handled(),
"Failed to consider whether moving or not something");
} else {
NS_ASSERTION(moveNodeResult.Ignored(),
NS_ASSERTION(moveNodeResult.inspect().Ignored(),
"Failed to consider whether moving or not something");
}
#endif // #ifdef DEBUG
// We don't need to update selection here because of dontChangeMySelection
// above.
moveNodeResult.IgnoreCaretPointSuggestion();
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
ret |= moveNodeResult;
}