Bug 1088054 part 8 - Clean up nsHTMLEditor::GetFirst/LastEditableLeaf; r=ehsan

This commit is contained in:
Aryeh Gregor 2014-11-02 14:04:13 +02:00
parent 85d56cc1f5
commit bf288c0e4c
4 changed files with 29 additions and 64 deletions

View File

@ -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<nsINode> lastInsertNode_ = do_QueryInterface(lastInsertNode);
NS_ENSURE_STATE(lastInsertNode_ || !lastInsertNode);
selNode = GetAsDOMNode(GetLastEditableLeaf(*lastInsertNode_));
tmp = selNode;
while (tmp && (tmp != lastInsertNode))
{

View File

@ -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;
}

View File

@ -4188,71 +4188,37 @@ nsHTMLEditor::GetLastEditableChild(nsINode& aNode)
return child;
}
nsresult
nsHTMLEditor::GetFirstEditableLeaf( nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aOutFirstLeaf)
nsIContent*
nsHTMLEditor::GetFirstEditableLeaf(nsINode& aNode)
{
// check parms
nsCOMPtr<nsINode> 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<nsIDOMNode> child = GetAsDOMNode(GetLeftmostChild(node));
while (child && (!IsEditable(child) || !nsEditorUtils::IsLeafNode(child)))
{
nsCOMPtr<nsIDOMNode> 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<nsIContent> 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<nsIDOMNode> *aOutLastLeaf)
nsIContent*
nsHTMLEditor::GetLastEditableLeaf(nsINode& aNode)
{
// check parms
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
NS_ENSURE_TRUE(node && aOutLastLeaf, NS_ERROR_NULL_POINTER);
// init out parms
*aOutLastLeaf = nullptr;
// find rightmost leaf
nsCOMPtr<nsIDOMNode> child = GetAsDOMNode(GetRightmostChild(node, false));
nsresult res = NS_OK;
while (child && (!IsEditable(child) || !nsEditorUtils::IsLeafNode(child)))
{
nsCOMPtr<nsIDOMNode> 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<nsIContent> 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;
}

View File

@ -715,8 +715,8 @@ protected:
nsIContent* GetFirstEditableChild(nsINode& aNode);
nsIContent* GetLastEditableChild(nsINode& aNode);
nsresult GetFirstEditableLeaf( nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aOutFirstLeaf);
nsresult GetLastEditableLeaf( nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aOutLastLeaf);
nsIContent* GetFirstEditableLeaf(nsINode& aNode);
nsIContent* GetLastEditableLeaf(nsINode& aNode);
nsresult GetInlinePropertyBase(nsIAtom *aProperty,
const nsAString *aAttribute,