Bug 1004522 part 4 - Clean up nsWSRunObject::PrepareToDeleteNode; r=ehsan

This commit is contained in:
Aryeh Gregor 2014-05-02 15:15:26 +03:00
parent 1ec5f91a58
commit 0c5889a95f
3 changed files with 17 additions and 16 deletions

View File

@ -2127,7 +2127,8 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
// Delete the <br>
NS_ENSURE_STATE(mHTMLEditor);
res = nsWSRunObject::PrepareToDeleteNode(mHTMLEditor, otherNode);
nsCOMPtr<nsIContent> otherContent(do_QueryInterface(otherNode));
res = nsWSRunObject::PrepareToDeleteNode(mHTMLEditor, otherContent);
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->DeleteNode(otherNode);
@ -2141,7 +2142,8 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
// found break or image, or hr.
NS_ENSURE_STATE(mHTMLEditor);
res = nsWSRunObject::PrepareToDeleteNode(mHTMLEditor, visNode);
nsCOMPtr<nsIContent> visContent(do_QueryInterface(visNode));
res = nsWSRunObject::PrepareToDeleteNode(mHTMLEditor, visContent);
NS_ENSURE_SUCCESS(res, res);
// remember sibling to visnode, if any
nsCOMPtr<nsIDOMNode> sibling, stepbrother;

View File

@ -155,19 +155,18 @@ nsWSRunObject::PrepareToDeleteRange(nsHTMLEditor* aHTMLEd,
return leftWSObj.PrepareToDeleteRangePriv(&rightWSObj);
}
nsresult
nsWSRunObject::PrepareToDeleteNode(nsHTMLEditor *aHTMLEd,
nsIDOMNode *aNode)
nsresult
nsWSRunObject::PrepareToDeleteNode(nsHTMLEditor* aHTMLEd,
nsIContent* aContent)
{
nsCOMPtr<nsINode> node(do_QueryInterface(aNode));
NS_ENSURE_TRUE(node && aHTMLEd, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsINode> parent = node->GetParentNode();
NS_ENSURE_TRUE(aContent && aHTMLEd, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsINode> parent = aContent->GetParentNode();
NS_ENSURE_STATE(parent);
int32_t offset = parent->IndexOf(node);
int32_t offset = parent->IndexOf(aContent);
nsWSRunObject leftWSObj(aHTMLEd, parent, offset);
nsWSRunObject rightWSObj(aHTMLEd, parent, offset+1);
nsWSRunObject rightWSObj(aHTMLEd, parent, offset + 1);
return leftWSObj.PrepareToDeleteRangePriv(&rightWSObj);
}

View File

@ -186,11 +186,11 @@ class MOZ_STACK_CLASS nsWSRunObject
nsCOMPtr<nsINode>* aEndNode,
int32_t* aEndOffset);
// PrepareToDeleteNode fixes up ws before and after aNode in preperation
// for aNode to be deleted.
// example of fixup: trailingws before aNode needs to be removed.
static nsresult PrepareToDeleteNode(nsHTMLEditor *aHTMLEd,
nsIDOMNode *aNode);
// PrepareToDeleteNode fixes up ws before and after aContent in preparation
// for aContent to be deleted. Example of fixup: trailingws before
// aContent needs to be removed.
static nsresult PrepareToDeleteNode(nsHTMLEditor *aHTMLEd,
nsIContent* aContent);
// PrepareToSplitAcrossBlocks fixes up ws before and after
// {aSplitNode,aSplitOffset} in preperation for a block