Bug 1460509 - part 6: Make TextEditRules::RemoveRedundantTrailingBR() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: HpFo0SiTBWJ
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -1352,16 +1352,19 @@ TextEditRules::RemoveRedundantTrailingBR
RefPtr<Element> childElement = child->AsElement();
if (!TextEditUtils::IsMozBR(childElement)) {
return NS_OK;
}
// Rather than deleting this node from the DOM tree we should instead
// morph this br into the bogus node
childElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::type, true);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
// set mBogusNode to be this <br>
mBogusNode = childElement;
// give it the bogus node attribute
childElement->SetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom,
kMOZEditorBogusNodeValue, false);
return NS_OK;
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -174,17 +174,17 @@ protected:
nsAString* aOutText,
uint32_t aFlags,
bool* aOutCancel,
bool* aHandled);
/**
* Check for and replace a redundant trailing break.
*/
- nsresult RemoveRedundantTrailingBR();
+ MOZ_MUST_USE nsresult RemoveRedundantTrailingBR();
/**
* Creates a trailing break in the text doc if there is not one already.
*/
MOZ_MUST_USE nsresult CreateTrailingBRIfNeeded();
/**
* Creates a bogus <br> node if the root element has no editable content.