From b2c77e5edaaf1dac2c08eb1b2dbe42bf6fb38810 Mon Sep 17 00:00:00 2001 From: FranklinDM Date: Fri, 3 Mar 2023 23:39:58 +0800 Subject: [PATCH] Issue #2135 - Bug 1356496: Don't use nsIDOM* in ConfirmSelectionInBody --- editor/libeditor/HTMLEditRules.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/editor/libeditor/HTMLEditRules.cpp b/editor/libeditor/HTMLEditRules.cpp index ac1c4ce6ff..850bbe9b5a 100644 --- a/editor/libeditor/HTMLEditRules.cpp +++ b/editor/libeditor/HTMLEditRules.cpp @@ -7986,16 +7986,20 @@ HTMLEditRules::ConfirmSelectionInBody() { // get the body NS_ENSURE_STATE(mHTMLEditor); - nsCOMPtr rootElement = do_QueryInterface(mHTMLEditor->GetRoot()); - NS_ENSURE_TRUE(rootElement, NS_ERROR_UNEXPECTED); + RefPtr rootElement = mHTMLEditor->GetRoot(); + if (NS_WARN_IF(!rootElement)) { + return NS_ERROR_UNEXPECTED; + } // get the selection NS_ENSURE_STATE(mHTMLEditor); RefPtr selection = mHTMLEditor->GetSelection(); - NS_ENSURE_STATE(selection); + if (NS_WARN_IF(!selection)) { + return NS_ERROR_UNEXPECTED; + } // get the selection start location - nsCOMPtr selNode, temp, parent; + nsCOMPtr selNode; int32_t selOffset; NS_ENSURE_STATE(mHTMLEditor); nsresult rv = @@ -8005,12 +8009,11 @@ HTMLEditRules::ConfirmSelectionInBody() return rv; } - temp = selNode; + nsINode* temp = selNode; // check that selNode is inside body - while (temp && !TextEditUtils::IsBody(temp)) { - temp->GetParentNode(getter_AddRefs(parent)); - temp = parent; + while (temp && !temp->IsHTMLElement(nsGkAtoms::body)) { + temp = temp->GetParentNode(); } // if we aren't in the body, force the issue @@ -8018,6 +8021,7 @@ HTMLEditRules::ConfirmSelectionInBody() // uncomment this to see when we get bad selections // NS_NOTREACHED("selection not in body"); selection->Collapse(rootElement, 0); + return NS_OK; } // get the selection end location @@ -8028,9 +8032,8 @@ HTMLEditRules::ConfirmSelectionInBody() temp = selNode; // check that selNode is inside body - while (temp && !TextEditUtils::IsBody(temp)) { - rv = temp->GetParentNode(getter_AddRefs(parent)); - temp = parent; + while (temp && !temp->IsHTMLElement(nsGkAtoms::body)) { + temp = temp->GetParentNode(); } // if we aren't in the body, force the issue @@ -8040,9 +8043,7 @@ HTMLEditRules::ConfirmSelectionInBody() selection->Collapse(rootElement, 0); } - // XXX This is the result of the last call of GetParentNode(), it doesn't - // make sense... - return rv; + return NS_OK; } nsresult