Bug 1460509 - part 7: Make TextEditRules::DidDeleteSelection() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
And also this patch removes unnecessary arguments from the method.
MozReview-Commit-ID: UKscK4vFVX
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -3702,17 +3702,17 @@ HTMLEditRules::DidDeleteSelection(nsIEdi
SelectionRef().Collapse(EditorRawDOMPoint(brElement), error);
NS_WARNING_ASSERTION(!error.Failed(),
"Failed to collapse selection at the new <br> element");
}
}
}
// call through to base class
- return TextEditRules::DidDeleteSelection(aDir, aResult);
+ return TextEditRules::DidDeleteSelection();
}
nsresult
HTMLEditRules::WillMakeList(const nsAString* aListType,
bool aEntireList,
const nsAString* aBulletType,
bool* aCancel,
bool* aHandled,
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -372,17 +372,17 @@ TextEditRules::DidDoAction(Selection* aS
AutoSafeEditorData setData(*this, *mTextEditor, *aSelection);
// don't let any txns in here move the selection around behind our back.
// Note that this won't prevent explicit selection setting from working.
AutoTransactionsConserveSelection dontChangeMySelection(&TextEditorRef());
switch (aInfo->action) {
case EditAction::deleteSelection:
- return DidDeleteSelection(aInfo->collapsedAction, aResult);
+ return DidDeleteSelection();
case EditAction::undo:
return DidUndo(aResult);
case EditAction::redo:
return DidRedo(aResult);
default:
// Don't fail on transactions we don't handle here!
return NS_OK;
}
@@ -1076,33 +1076,35 @@ TextEditRules::WillDeleteSelection(nsIEd
}
*aHandled = true;
ASSERT_PASSWORD_LENGTHS_EQUAL()
return NS_OK;
}
nsresult
-TextEditRules::DidDeleteSelection(nsIEditor::EDirection aCollapsedAction,
- nsresult aResult)
+TextEditRules::DidDeleteSelection()
{
MOZ_ASSERT(IsEditorDataAvailable());
EditorRawDOMPoint selectionStartPoint(
EditorBase::GetStartPoint(&SelectionRef()));
if (NS_WARN_IF(!selectionStartPoint.IsSet())) {
return NS_ERROR_FAILURE;
}
// Delete empty text nodes at selection.
if (selectionStartPoint.IsInTextNode() &&
!selectionStartPoint.GetContainer()->Length()) {
nsresult rv =
TextEditorRef().DeleteNodeWithTransaction(
*selectionStartPoint.GetContainer());
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
if (mDidExplicitlySetInterline) {
return NS_OK;
}
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -144,18 +144,22 @@ protected:
const nsAString* inString,
int32_t aMaxLength);
void WillInsert(bool* aCancel);
nsresult WillDeleteSelection(nsIEditor::EDirection aCollapsedAction,
bool* aCancel,
bool* aHandled);
- nsresult DidDeleteSelection(nsIEditor::EDirection aCollapsedAction,
- nsresult aResult);
+ /**
+ * Called after deleted selected content.
+ * This method may remove empty text node and makes guarantee that caret
+ * is never at left of <br> element.
+ */
+ MOZ_MUST_USE nsresult DidDeleteSelection();
nsresult WillSetTextProperty(bool* aCancel, bool* aHandled);
nsresult WillRemoveTextProperty(bool* aCancel, bool* aHandled);
nsresult WillUndo(bool* aCancel, bool* aHandled);
nsresult DidUndo(nsresult aResult);