Bug 1460509 - part 39: Make HTMLEditRules::SplitParagraph() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: 38hfUl88xXI
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -7690,48 +7690,60 @@ HTMLEditRules::SplitParagraph(
// split para
// get ws code to adjust any ws
nsCOMPtr<nsINode> selNode = aStartOfRightNode.GetContainer();
int32_t selOffset = aStartOfRightNode.Offset();
nsresult rv =
WSRunObject::PrepareToSplitAcrossBlocks(&HTMLEditorRef(),
address_of(selNode), &selOffset);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (NS_WARN_IF(!selNode->IsContent())) {
return NS_ERROR_FAILURE;
}
// Split the paragraph.
SplitNodeResult splitDivOrPResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
aParentDivOrP,
EditorRawDOMPoint(selNode, selOffset),
SplitAtEdges::eAllowToCreateEmptyContainer);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(splitDivOrPResult.Failed())) {
return splitDivOrPResult.Rv();
}
if (NS_WARN_IF(!splitDivOrPResult.DidSplit())) {
return NS_ERROR_FAILURE;
}
// Get rid of the break, if it is visible (otherwise it may be needed to
// prevent an empty p).
if (aNextBRNode && HTMLEditorRef().IsVisibleBRElement(aNextBRNode)) {
rv = HTMLEditorRef().DeleteNodeWithTransaction(*aNextBRNode);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
// Remove ID attribute on the paragraph from the existing right node.
rv = HTMLEditorRef().RemoveAttributeWithTransaction(aParentDivOrP,
*nsGkAtoms::id);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// We need to ensure to both paragraphs visible even if they are empty.
// However, moz-<br> element isn't useful in this case because moz-<br>
// elements will be ignored by PlaintextSerializer. Additionally,
// moz-<br> will be exposed as <br> with Element.innerHTML. Therefore,
@@ -7748,22 +7760,28 @@ HTMLEditRules::SplitParagraph(
// selection to beginning of right hand para;
// look inside any containers that are up front.
nsIContent* child = HTMLEditorRef().GetLeftmostChild(&aParentDivOrP, true);
if (EditorBase::IsTextNode(child) || HTMLEditorRef().IsContainer(child)) {
EditorRawDOMPoint atStartOfChild(child, 0);
IgnoredErrorResult ignoredError;
SelectionRef().Collapse(atStartOfChild, ignoredError);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
NS_WARNING_ASSERTION(!ignoredError.Failed(),
"Failed to collapse selection at the end of the child");
} else {
EditorRawDOMPoint atChild(child);
IgnoredErrorResult ignoredError;
SelectionRef().Collapse(atChild, ignoredError);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
NS_WARNING_ASSERTION(!ignoredError.Failed(),
"Failed to collapse selection at the child");
}
return NS_OK;
}
nsresult
HTMLEditRules::ReturnInListItem(Element& aListItem,
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -392,19 +392,20 @@ protected:
* @param aStartOfRightNode The point to be start of right node after
* split. This must be descendant of
* aParentDivOrP.
* @param aNextBRNode Next <br> node if there is. Otherwise, nullptr.
* If this is not nullptr, the <br> node may be
* removed.
*/
template<typename PT, typename CT>
- nsresult SplitParagraph(Element& aParentDivOrP,
- const EditorDOMPointBase<PT, CT>& aStartOfRightNode,
- nsIContent* aBRNode);
+ MOZ_MUST_USE nsresult
+ SplitParagraph(Element& aParentDivOrP,
+ const EditorDOMPointBase<PT, CT>& aStartOfRightNode,
+ nsIContent* aBRNode);
/**
* ReturnInListItem() handles insertParagraph command (i.e., handling
* Enter key press) in a list item element.
*
* @param aListItem The list item which has the following point.
* @param aNode Typically, Selection start container, where to
* insert a break.