Bug 1460509 - part 78: Make HTMLEditRules::MoveBlock() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: 7RKXiYaH2l0
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -3478,16 +3478,21 @@ HTMLEditRules::TryToJoinBlocksWithTransa
// XXX Although, we don't do nothing here, but for keeping traditional
// behavior, we should mark as handled.
ret.MarkAsHandled();
} else {
// XXX Why do we ignore the result of MoveBlock()?
EditActionResult retMoveBlock =
MoveBlock(*leftBlock, *rightBlock,
-1, atRightBlockChild.Offset());
+ if (NS_WARN_IF(retMoveBlock.Rv() == NS_ERROR_EDITOR_DESTROYED)) {
+ return ret;
+ }
+ NS_WARNING_ASSERTION(retMoveBlock.Succeeded(),
+ "Failed to move contents of the right block to the left block");
if (retMoveBlock.Handled()) {
ret.MarkAsHandled();
}
// Now, all children of rightBlock were moved to leftBlock. So,
// atRightBlockChild is now invalid.
atRightBlockChild.Clear();
}
if (brNode &&
@@ -3701,16 +3706,19 @@ HTMLEditRules::MoveBlock(Element& aLeftB
if (IsBlockNode(arrayOfNodes[i])) {
// For block nodes, move their contents only, then delete block.
ret |=
MoveContents(*arrayOfNodes[i]->AsElement(), aLeftBlock, &aLeftOffset);
if (NS_WARN_IF(ret.Failed())) {
return ret;
}
rv = HTMLEditorRef().DeleteNodeWithTransaction(*arrayOfNodes[i]);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return ret.SetResult(NS_ERROR_EDITOR_DESTROYED);
+ }
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"Failed to remove a block node");
ret.MarkAsHandled();
} else {
// Otherwise move the content as is, checking against the DTD.
ret |=
MoveNodeSmart(*arrayOfNodes[i]->AsContent(), aLeftBlock, &aLeftOffset);
if (NS_WARN_IF(ret.Rv() == NS_ERROR_EDITOR_DESTROYED)) {
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -294,18 +294,19 @@ protected:
* MoveBlock() moves the content from aRightBlock starting from aRightOffset
* into aLeftBlock at aLeftOffset. Note that the "block" can be inline nodes
* between <br>s, or between blocks, etc. DTD containment rules are followed
* throughout.
*
* @return Sets handled to true if this actually joins the nodes.
* canceled is always false.
*/
- EditActionResult MoveBlock(Element& aLeftBlock, Element& aRightBlock,
- int32_t aLeftOffset, int32_t aRightOffset);
+ MOZ_MUST_USE EditActionResult
+ MoveBlock(Element& aLeftBlock, Element& aRightBlock,
+ int32_t aLeftOffset, int32_t aRightOffset);
/**
* MoveNodeSmart() moves aNode to (aDestElement, aInOutDestOffset).
* DTD containment rules are followed throughout.
*
* @param aOffset returns the point after inserted content.
* @return Sets true to handled if this actually moves
* the nodes.