diff --git a/editor/libeditor/nsHTMLDataTransfer.cpp b/editor/libeditor/nsHTMLDataTransfer.cpp
index 93fd3836c3f5..381bba35dd20 100644
--- a/editor/libeditor/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/nsHTMLDataTransfer.cpp
@@ -629,8 +629,9 @@ nsHTMLEditor::DoInsertHTMLWithContext(const nsAString & aInputString,
// but don't cross tables
if (!nsHTMLEditUtils::IsTable(lastInsertNode))
{
- rv = GetLastEditableLeaf(lastInsertNode, address_of(selNode));
- NS_ENSURE_SUCCESS(rv, rv);
+ nsCOMPtr lastInsertNode_ = do_QueryInterface(lastInsertNode);
+ NS_ENSURE_STATE(lastInsertNode_ || !lastInsertNode);
+ selNode = GetAsDOMNode(GetLastEditableLeaf(*lastInsertNode_));
tmp = selNode;
while (tmp && (tmp != lastInsertNode))
{
diff --git a/editor/libeditor/nsHTMLEditRules.cpp b/editor/libeditor/nsHTMLEditRules.cpp
index dc070c3942f8..59449df7ea1c 100644
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -2203,16 +2203,14 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
if (aAction == nsIEditor::ePrevious)
{
NS_ENSURE_STATE(mHTMLEditor);
- res = mHTMLEditor->GetLastEditableLeaf( visNode, address_of(leafNode));
- NS_ENSURE_SUCCESS(res, res);
+ leafNode = GetAsDOMNode(mHTMLEditor->GetLastEditableLeaf(*visNode_));
leftNode = leafNode;
rightNode = startNode;
}
else
{
NS_ENSURE_STATE(mHTMLEditor);
- res = mHTMLEditor->GetFirstEditableLeaf( visNode, address_of(leafNode));
- NS_ENSURE_SUCCESS(res, res);
+ leafNode = GetAsDOMNode(mHTMLEditor->GetFirstEditableLeaf(*visNode_));
leftNode = startNode;
rightNode = leafNode;
}
diff --git a/editor/libeditor/nsHTMLEditor.cpp b/editor/libeditor/nsHTMLEditor.cpp
index 379864dfb051..55164ca83467 100644
--- a/editor/libeditor/nsHTMLEditor.cpp
+++ b/editor/libeditor/nsHTMLEditor.cpp
@@ -4188,71 +4188,37 @@ nsHTMLEditor::GetLastEditableChild(nsINode& aNode)
return child;
}
-nsresult
-nsHTMLEditor::GetFirstEditableLeaf( nsIDOMNode *aNode, nsCOMPtr *aOutFirstLeaf)
+nsIContent*
+nsHTMLEditor::GetFirstEditableLeaf(nsINode& aNode)
{
- // check parms
- nsCOMPtr node = do_QueryInterface(aNode);
- NS_ENSURE_TRUE(node && aOutFirstLeaf, NS_ERROR_NULL_POINTER);
-
- // init out parms
- *aOutFirstLeaf = aNode;
-
- // find leftmost leaf
- nsresult res = NS_OK;
- nsCOMPtr child = GetAsDOMNode(GetLeftmostChild(node));
- while (child && (!IsEditable(child) || !nsEditorUtils::IsLeafNode(child)))
- {
- nsCOMPtr tmp;
- res = GetNextHTMLNode(child, address_of(tmp));
- NS_ENSURE_SUCCESS(res, res);
- NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
-
- // only accept nodes that are descendants of aNode
- if (nsEditorUtils::IsDescendantOf(tmp, aNode))
- child = tmp;
- else
- {
- child = nullptr; // this will abort the loop
+ nsCOMPtr child = GetLeftmostChild(&aNode);
+ while (child && (!IsEditable(child) || child->HasChildren())) {
+ child = GetNextHTMLNode(child);
+
+ // Only accept nodes that are descendants of aNode
+ if (!aNode.Contains(child)) {
+ return nullptr;
}
}
-
- *aOutFirstLeaf = child;
- return res;
+
+ return child;
}
-nsresult
-nsHTMLEditor::GetLastEditableLeaf(nsIDOMNode *aNode, nsCOMPtr *aOutLastLeaf)
+nsIContent*
+nsHTMLEditor::GetLastEditableLeaf(nsINode& aNode)
{
- // check parms
- nsCOMPtr node = do_QueryInterface(aNode);
- NS_ENSURE_TRUE(node && aOutLastLeaf, NS_ERROR_NULL_POINTER);
-
- // init out parms
- *aOutLastLeaf = nullptr;
-
- // find rightmost leaf
- nsCOMPtr child = GetAsDOMNode(GetRightmostChild(node, false));
- nsresult res = NS_OK;
- while (child && (!IsEditable(child) || !nsEditorUtils::IsLeafNode(child)))
- {
- nsCOMPtr tmp;
- res = GetPriorHTMLNode(child, address_of(tmp));
- NS_ENSURE_SUCCESS(res, res);
- NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
-
- // only accept nodes that are descendants of aNode
- if (nsEditorUtils::IsDescendantOf(tmp, aNode))
- child = tmp;
- else
- {
- child = nullptr;
+ nsCOMPtr child = GetRightmostChild(&aNode, false);
+ while (child && (!IsEditable(child) || child->HasChildren())) {
+ child = GetPriorHTMLNode(child);
+
+ // Only accept nodes that are descendants of aNode
+ if (!aNode.Contains(child)) {
+ return nullptr;
}
}
-
- *aOutLastLeaf = child;
- return res;
+
+ return child;
}
diff --git a/editor/libeditor/nsHTMLEditor.h b/editor/libeditor/nsHTMLEditor.h
index 801bb6d761cd..8eda73cb0d98 100644
--- a/editor/libeditor/nsHTMLEditor.h
+++ b/editor/libeditor/nsHTMLEditor.h
@@ -715,8 +715,8 @@ protected:
nsIContent* GetFirstEditableChild(nsINode& aNode);
nsIContent* GetLastEditableChild(nsINode& aNode);
- nsresult GetFirstEditableLeaf( nsIDOMNode *aNode, nsCOMPtr *aOutFirstLeaf);
- nsresult GetLastEditableLeaf( nsIDOMNode *aNode, nsCOMPtr *aOutLastLeaf);
+ nsIContent* GetFirstEditableLeaf(nsINode& aNode);
+ nsIContent* GetLastEditableLeaf(nsINode& aNode);
nsresult GetInlinePropertyBase(nsIAtom *aProperty,
const nsAString *aAttribute,