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

--HG--
extra : rebase_source : 2075312aad4062341272f95df2f19975c1b3779b
This commit is contained in:
Masayuki Nakano 2018-05-17 23:21:52 +09:00
parent 1f5ce6791d
commit 0f41ff01e6
2 changed files with 24 additions and 6 deletions

View File

@ -772,7 +772,7 @@ HTMLEditRules::DidDoAction(Selection* aSelection,
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:
@ -3815,8 +3815,7 @@ HTMLEditRules::DeleteNonTableElements(nsINode* aNode)
}
nsresult
HTMLEditRules::DidDeleteSelection(nsIEditor::EDirection aDir,
nsresult aResult)
HTMLEditRules::DidDeleteSelection()
{
MOZ_ASSERT(IsEditorDataAvailable());
@ -3838,6 +3837,9 @@ HTMLEditRules::DidDeleteSelection(nsIEditor::EDirection aDir,
{
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;
}
@ -3846,11 +3848,17 @@ HTMLEditRules::DidDeleteSelection(nsIEditor::EDirection aDir,
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");
}
@ -3858,7 +3866,11 @@ HTMLEditRules::DidDeleteSelection(nsIEditor::EDirection aDir,
}
// 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

View File

@ -219,8 +219,14 @@ protected:
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();
/**