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
--- 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.