Bug 1460509 - part 72: Mark HTMLEditRules::WillRemoveList() as MOZ_MUST_USE since it may return NS_ERROR_EDITOR_DESTROYED r?m_kato
Additionally, it creates AutoSelectionRestorer. So, this patch adds
CanHandleEditAction() check after its caller since even if it returns
NS_OK, the editor might have been gone.
MozReview-Commit-ID: BgIbpHFFPE1
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -715,18 +715,27 @@ HTMLEditRules::WillDoAction(Selection* a
case EditAction::setAbsolutePosition:
return WillAbsolutePosition(aCancel, aHandled);
case EditAction::removeAbsolutePosition:
return WillRemoveAbsolutePosition(aCancel, aHandled);
case EditAction::align:
return WillAlign(*aInfo->alignType, aCancel, aHandled);
case EditAction::makeBasicBlock:
return WillMakeBasicBlock(*aInfo->blockType, aCancel, aHandled);
- case EditAction::removeList:
- return WillRemoveList(aInfo->bOrdered, aCancel, aHandled);
+ case EditAction::removeList: {
+ nsresult rv = WillRemoveList(aCancel, aHandled);
+ if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED) ||
+ NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
+ return NS_OK;
+ }
case EditAction::makeDefListItem:
return WillMakeDefListItem(aInfo->blockType,
aInfo->entireList, aCancel, aHandled);
case EditAction::insertElement: {
nsresult rv = WillInsert(aCancel);
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return NS_ERROR_EDITOR_DESTROYED;
}
@@ -4228,20 +4237,18 @@ HTMLEditRules::WillMakeList(const nsAStr
return rv;
}
}
}
return NS_OK;
}
-
nsresult
-HTMLEditRules::WillRemoveList(bool aOrdered,
- bool* aCancel,
+HTMLEditRules::WillRemoveList(bool* aCancel,
bool* aHandled)
{
MOZ_ASSERT(IsEditorDataAvailable());
if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
return NS_ERROR_INVALID_ARG;
}
// initialize out param
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -321,17 +321,26 @@ protected:
int32_t* aInOutDestOffset);
nsresult DeleteNonTableElements(nsINode* aNode);
nsresult WillMakeList(const nsAString* aListType,
bool aEntireList,
const nsAString* aBulletType,
bool* aCancel, bool* aHandled,
const nsAString* aItemType = nullptr);
- nsresult WillRemoveList(bool aOrdered, bool* aCancel, bool* aHandled);
+
+ /**
+ * Called before removing a list element. This method actually removes
+ * list elements and list item elements at Selection. And move contents
+ * in them where the removed list was.
+ *
+ * @param aCancel Returns true if the operation is canceled.
+ * @param aHandled Returns true if the edit action is handled.
+ */
+ MOZ_MUST_USE nsresult WillRemoveList(bool* aCancel, bool* aHandled);
/**
* Called before indenting around Selection. This method actually tries to
* indent the contents.
*
* @param aCancel Returns true if the operation is canceled.
* @param aHandled Returns true if the edit action is handled.
*/