Bug 1460509 - part 7: Make TextEditRules::DidDeleteSelection() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 11 May 2018 16:48:29 +0900
changeset 798725 848da409dcf41cd4c3e4299565b6a4a07f44a5ed
parent 798724 456816b935ea0e2bc8052cdeaba65d2186928248
child 798726 9271e9273e1af33f91eb4b0d731d022883927f21
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
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
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditRules.h
--- 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);