Bug 1460509 - part 16: Make HTMLEditRules::DidAbsolutePosition() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: BBAvHn08og4
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -10198,16 +10198,19 @@ nsresult
HTMLEditRules::DidAbsolutePosition()
{
MOZ_ASSERT(IsEditorDataAvailable());
if (!mNewBlock) {
return NS_OK;
}
nsresult rv = HTMLEditorRef().SetPositionToAbsoluteOrStatic(*mNewBlock, true);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult
HTMLEditRules::WillRemoveAbsolutePosition(bool* aCancel,
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -286,17 +286,26 @@ protected:
WillRelativeChangeZIndex(int32_t aChange, bool* aCancel, bool* aHandled);
nsresult WillMakeDefListItem(const nsAString* aBlockType, bool aEntireList,
bool* aCancel, bool* aHandled);
nsresult WillMakeBasicBlock(const nsAString& aBlockType,
bool* aCancel, bool* aHandled);
nsresult MakeBasicBlock(nsAtom& aBlockType);
nsresult DidMakeBasicBlock(RulesInfo* aInfo, nsresult aResult);
- nsresult DidAbsolutePosition();
+
+ /**
+ * Called if nobody handles the edit action to make an element absolute
+ * positioned.
+ * This method actually changes the element which is computed by
+ * WillAbsolutePosition() to absolute positioned.
+ * Therefore, this might cause destroying the HTML editor.
+ */
+ MOZ_MUST_USE nsresult DidAbsolutePosition();
+
nsresult AlignInnerBlocks(nsINode& aNode, const nsAString& aAlignType);
nsresult AlignBlockContents(nsINode& aNode, const nsAString& aAlignType);
nsresult AppendInnerFormatNodes(nsTArray<OwningNonNull<nsINode>>& aArray,
nsINode* aNode);
nsresult GetFormatString(nsINode* aNode, nsAString &outFormat);
enum class Lists { no, yes };
enum class Tables { no, yes };
void GetInnerContent(nsINode& aNode,