Bug 1460509 - part 74: Make HTMLEditRules::DidDeleteSelection() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: E3LGBAbaw7N
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -767,17 +767,17 @@ HTMLEditRules::DidDoAction(Selection* aS
AutoSafeEditorData setData(*this, *mHTMLEditor, *aSelection);
switch (aInfo->action) {
case EditAction::insertText:
case EditAction::insertBreak:
case EditAction::insertIMEText:
return NS_OK;
case EditAction::deleteSelection:
- return DidDeleteSelection(aInfo->collapsedAction, aResult);
+ return DidDeleteSelection();
case EditAction::makeBasicBlock:
case EditAction::indent:
case EditAction::outdent:
case EditAction::align:
return DidMakeBasicBlock();
case EditAction::setAbsolutePosition: {
nsresult rv = DidMakeBasicBlock();
if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -3810,18 +3810,17 @@ HTMLEditRules::DeleteNonTableElements(ns
for (const auto& child: childList) {
nsresult rv = DeleteNonTableElements(child);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
nsresult
-HTMLEditRules::DidDeleteSelection(nsIEditor::EDirection aDir,
- nsresult aResult)
+HTMLEditRules::DidDeleteSelection()
{
MOZ_ASSERT(IsEditorDataAvailable());
// find where we are
EditorDOMPoint atStartOfSelection(EditorBase::GetStartPoint(&SelectionRef()));
if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
return NS_ERROR_FAILURE;
}
@@ -3833,37 +3832,50 @@ HTMLEditRules::DidDeleteSelection(nsIEdi
bool isEmpty = true, seenBR = false;
HTMLEditorRef().IsEmptyNodeImpl(citeNode, &isEmpty, true, true, false,
&seenBR);
if (isEmpty) {
EditorDOMPoint atCiteNode(citeNode);
{
AutoEditorDOMPointChildInvalidator lockOffset(atCiteNode);
nsresult rv = HTMLEditorRef().DeleteNodeWithTransaction(*citeNode);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
if (atCiteNode.IsSet() && seenBR) {
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(SelectionRef(),
atCiteNode);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
IgnoredErrorResult error;
SelectionRef().Collapse(EditorRawDOMPoint(brElement), error);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
NS_WARNING_ASSERTION(!error.Failed(),
"Failed to collapse selection at the new <br> element");
}
}
}
// call through to base class
- return TextEditRules::DidDeleteSelection();
+ nsresult rv = TextEditRules::DidDeleteSelection();
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
+ return NS_OK;
}
nsresult
HTMLEditRules::WillMakeList(const nsAString* aListType,
bool aEntireList,
const nsAString* aBulletType,
bool* aCancel,
bool* aHandled,
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -214,18 +214,24 @@ protected:
* @param aHandled Returns true if succeeded to split mail-cite
* elements.
*/
MOZ_MUST_USE nsresult SplitMailCites(bool* aHandled);
nsresult WillDeleteSelection(nsIEditor::EDirection aAction,
nsIEditor::EStripWrappers aStripWrappers,
bool* aCancel, bool* aHandled);
- nsresult DidDeleteSelection(nsIEditor::EDirection aDir,
- nsresult aResult);
+
+ /**
+ * Called after deleting selected content.
+ * This method removes unnecessary empty nodes and/or inserts <br> if
+ * necessary.
+ */
+ MOZ_MUST_USE nsresult DidDeleteSelection();
+
nsresult InsertBRIfNeeded();
/**
* CanContainParagraph() returns true if aElement can have a <p> element as
* its child or its descendant.
*/
bool CanContainParagraph(Element& aElement) const;