diff --git a/editor/libeditor/HTMLEditRules.cpp b/editor/libeditor/HTMLEditRules.cpp
index a42b61bb1ac2..204fdb7553d1 100644
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -10232,11 +10232,21 @@ HTMLEditRules::WillRemoveAbsolutePosition(bool* aCancel,
return NS_ERROR_FAILURE;
}
- AutoSelectionRestorer selectionRestorer(&SelectionRef(), &HTMLEditorRef());
+ {
+ AutoSelectionRestorer selectionRestorer(&SelectionRef(), &HTMLEditorRef());
- nsresult rv = HTMLEditorRef().SetPositionToAbsoluteOrStatic(*element, false);
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return rv;
+ 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;
}
diff --git a/editor/libeditor/HTMLEditRules.h b/editor/libeditor/HTMLEditRules.h
index 09a4a27d6957..612526069f1a 100644
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -259,7 +259,18 @@ protected:
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.