Bug 1460509 - part 15: Make HTMLEditRules::WillRemoveAbsolutePosition() 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 19:32:00 +0900
changeset 798733 b5fa0e2d42cb8d904b483d27b74088e97a2e6aa5
parent 798732 7276770b8cf7ecdf9c322e5153aa6bbadb9bf228
child 798734 f0d8798b6529323b8a7837f135715823de4d7b52
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 15: Make HTMLEditRules::WillRemoveAbsolutePosition() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato MozReview-Commit-ID: DXzdtPQ01lo
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -10227,21 +10227,31 @@ HTMLEditRules::WillRemoveAbsolutePositio
   *aHandled = true;
 
   RefPtr<Element> element =
     HTMLEditorRef().GetAbsolutelyPositionedSelectionContainer();
   if (NS_WARN_IF(!element)) {
     return NS_ERROR_FAILURE;
   }
 
-  AutoSelectionRestorer selectionRestorer(&SelectionRef(), &HTMLEditorRef());
-
-  nsresult rv = HTMLEditorRef().SetPositionToAbsoluteOrStatic(*element, false);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+  {
+    AutoSelectionRestorer selectionRestorer(&SelectionRef(), &HTMLEditorRef());
+
+    nsresult rv = HTMLEditorRef().SetPositionToAbsoluteOrStatic(*element, false);
+    if (NS_WARN_IF(!CanHandleEditAction())) {
+      return NS_ERROR_EDITOR_DESTROYED;
+    }
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+  }
+
+  // Restoring Selection might cause destroying the HTML editor.
+  if (NS_WARN_IF(!CanHandleEditAction())) {
+    return NS_ERROR_EDITOR_DESTROYED;
   }
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::WillRelativeChangeZIndex(int32_t aChange,
                                         bool* aCancel,
                                         bool* aHandled)
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -254,17 +254,28 @@ protected:
   nsresult WillRemoveList(bool aOrdered, bool* aCancel, bool* aHandled);
   nsresult WillIndent(bool* aCancel, bool* aHandled);
   nsresult WillCSSIndent(bool* aCancel, bool* aHandled);
   nsresult WillHTMLIndent(bool* aCancel, bool* aHandled);
   nsresult WillOutdent(bool* aCancel, bool* aHandled);
   nsresult WillAlign(const nsAString& aAlignType,
                      bool* aCancel, bool* aHandled);
   nsresult WillAbsolutePosition(bool* aCancel, bool* aHandled);
-  nsresult WillRemoveAbsolutePosition(bool* aCancel, bool* aHandled);
+
+  /**
+   * Called before changing absolute positioned element to static positioned.
+   * This method actually changes the position property of nearest absolute
+   * positioned element.  Therefore, this might cause destroying the HTML
+   * editor.
+   *
+   * @param aCancel             Returns true if the operation is canceled.
+   * @param aHandled            Returns true if the edit action is handled.
+   */
+  MOZ_MUST_USE nsresult
+  WillRemoveAbsolutePosition(bool* aCancel, bool* aHandled);
 
   /**
    * Called before changing z-index.
    * This method actually changes z-index of nearest absolute positioned
    * element relatively.  Therefore, this might cause destroying the HTML
    * editor.
    *
    * @param aChange             Amount to change z-index.