diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index b87f2be8c2af..34db5b1a37b2 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -3385,28 +3385,13 @@ nsEditor::FindNode(nsINode *aCurrentNode, return FindNode(candidate, aGoForward, aEditableNode, bNoBlockCrossing); } -already_AddRefed -nsEditor::GetRightmostChild(nsIDOMNode *aCurrentNode, +nsIDOMNode* +nsEditor::GetRightmostChild(nsIDOMNode* aCurrentNode, bool bNoBlockCrossing) { - NS_ENSURE_TRUE(aCurrentNode, nullptr); - nsCOMPtr resultNode, temp = aCurrentNode; - bool hasChildren; - aCurrentNode->HasChildNodes(&hasChildren); - while (hasChildren) { - temp->GetLastChild(getter_AddRefs(resultNode)); - if (resultNode) { - if (bNoBlockCrossing && IsBlockNode(resultNode)) { - return resultNode.forget(); - } - resultNode->HasChildNodes(&hasChildren); - temp = resultNode; - } else { - hasChildren = false; - } - } - - return resultNode.forget(); + nsCOMPtr currentNode = do_QueryInterface(aCurrentNode); + nsIContent* result = GetRightmostChild(currentNode, bNoBlockCrossing); + return result ? result->AsDOMNode() : nullptr; } nsIContent* @@ -3457,28 +3442,13 @@ nsEditor::GetLeftmostChild(nsINode *aCurrentNode, return nullptr; } -already_AddRefed -nsEditor::GetLeftmostChild(nsIDOMNode *aCurrentNode, +nsIDOMNode* +nsEditor::GetLeftmostChild(nsIDOMNode* aCurrentNode, bool bNoBlockCrossing) { - NS_ENSURE_TRUE(aCurrentNode, nullptr); - nsCOMPtr resultNode, temp = aCurrentNode; - bool hasChildren; - aCurrentNode->HasChildNodes(&hasChildren); - while (hasChildren) { - temp->GetFirstChild(getter_AddRefs(resultNode)); - if (resultNode) { - if (bNoBlockCrossing && IsBlockNode(resultNode)) { - return resultNode.forget(); - } - resultNode->HasChildNodes(&hasChildren); - temp = resultNode; - } else { - hasChildren = false; - } - } - - return resultNode.forget(); + nsCOMPtr currentNode = do_QueryInterface(aCurrentNode); + nsIContent* result = GetLeftmostChild(currentNode, bNoBlockCrossing); + return result ? result->AsDOMNode() : nullptr; } bool diff --git a/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index 4ef6eaa14e03..49f082526106 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/editor/libeditor/base/nsEditor.h @@ -539,8 +539,8 @@ public: * Get the rightmost child of aCurrentNode; * return nullptr if aCurrentNode has no children. */ - already_AddRefed GetRightmostChild(nsIDOMNode *aCurrentNode, - bool bNoBlockCrossing = false); + nsIDOMNode* GetRightmostChild(nsIDOMNode* aCurrentNode, + bool bNoBlockCrossing = false); nsIContent* GetRightmostChild(nsINode *aCurrentNode, bool bNoBlockCrossing = false); @@ -548,8 +548,8 @@ public: * Get the leftmost child of aCurrentNode; * return nullptr if aCurrentNode has no children. */ - already_AddRefed GetLeftmostChild(nsIDOMNode *aCurrentNode, - bool bNoBlockCrossing = false); + nsIDOMNode* GetLeftmostChild(nsIDOMNode* aCurrentNode, + bool bNoBlockCrossing = false); nsIContent* GetLeftmostChild(nsINode *aCurrentNode, bool bNoBlockCrossing = false);