Bug 1460509 - part 12: Make TextEditRules::WillInsertBreak() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: Ia5MJ465Hdf
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -465,16 +465,19 @@ TextEditRules::WillInsertBreak(bool* aCa
}
*aCancel = false;
// if the selection isn't collapsed, delete it.
if (!SelectionRef().IsCollapsed()) {
rv = TextEditorRef().DeleteSelectionAsAction(nsIEditor::eNone,
nsIEditor::eStrip);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
WillInsert(aCancel);
// initialize out param
// we want to ignore result of WillInsert()
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -145,17 +145,28 @@ protected:
* @param aMaxLength The maximum string length which the editor
* allows to set.
*/
MOZ_MUST_USE nsresult
WillInsertText(EditAction aAction, bool* aCancel, bool* aHandled,
const nsAString* inString, nsAString* outString,
int32_t aMaxLength);
- nsresult WillInsertBreak(bool* aCancel, bool* aHandled, int32_t aMaxLength);
+ /**
+ * Called before inserting a line break into the editor.
+ * This method removes selected text if selection isn't collapsed.
+ * Therefore, this might cause destroying the editor.
+ *
+ * @param aCancel Returns true if the operation is canceled.
+ * @param aHandled Returns true if the edit action is handled.
+ * @param aMaxLength The maximum string length which the editor
+ * allows to set.
+ */
+ MOZ_MUST_USE nsresult
+ WillInsertBreak(bool* aCancel, bool* aHandled, int32_t aMaxLength);
/**
* Called before setting text to the text editor.
* This method may actually set text to it. Therefore, this might cause
* destroying the text editor.
*
* @param aCancel Returns true if the operation is canceled.
* @param aHandled Returns true if the edit action is handled.