Bug 1004522 part 3 - Clean up nsWSRunObject::PrepareToDeleteRange; r=ehsan

This commit is contained in:
Aryeh Gregor 2014-05-02 15:15:26 +03:00
parent 258fa32a25
commit e062918dd9
3 changed files with 17 additions and 34 deletions

View File

@ -2039,8 +2039,11 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
NS_ENSURE_SUCCESS(res, res);
}
NS_ENSURE_STATE(mHTMLEditor);
res = nsWSRunObject::PrepareToDeleteRange(mHTMLEditor, address_of(visNode), &so, address_of(visNode), &eo);
nsCOMPtr<nsINode> visNode_(do_QueryInterface(visNode));
res = nsWSRunObject::PrepareToDeleteRange(mHTMLEditor,
address_of(visNode_), &so, address_of(visNode_), &eo);
NS_ENSURE_SUCCESS(res, res);
visNode = GetAsDOMNode(visNode_);
nsCOMPtr<nsIDOMCharacterData> nodeAsText(do_QueryInterface(visNode));
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->DeleteText(nodeAsText, std::min(so, eo), DeprecatedAbs(eo - so));
@ -2337,10 +2340,14 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
{
NS_ENSURE_STATE(mHTMLEditor);
nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor);
nsCOMPtr<nsINode> startNode_(do_QueryInterface(startNode)),
endNode_(do_QueryInterface(endNode));
res = nsWSRunObject::PrepareToDeleteRange(mHTMLEditor,
address_of(startNode), &startOffset,
address_of(endNode), &endOffset);
address_of(startNode_), &startOffset,
address_of(endNode_), &endOffset);
NS_ENSURE_SUCCESS(res, res);
startNode = GetAsDOMNode(startNode_);
endNode = GetAsDOMNode(endNode_);
}
{

View File

@ -142,34 +142,15 @@ nsWSRunObject::PrepareToDeleteRange(nsHTMLEditor* aHTMLEd,
nsCOMPtr<nsINode>* aEndNode,
int32_t* aEndOffset)
{
nsCOMPtr<nsIDOMNode> startNode(GetAsDOMNode(*aStartNode));
nsCOMPtr<nsIDOMNode> endNode(GetAsDOMNode(*aEndNode));
nsresult res =
PrepareToDeleteRange(aHTMLEd, address_of(startNode), aStartOffset,
address_of(endNode), aEndOffset);
*aStartNode = do_QueryInterface(startNode);
*aEndNode = do_QueryInterface(endNode);
return res;
}
NS_ENSURE_TRUE(aHTMLEd && aStartNode && *aStartNode && aStartOffset &&
aEndNode && *aEndNode && aEndOffset, NS_ERROR_NULL_POINTER);
nsresult
nsWSRunObject::PrepareToDeleteRange(nsHTMLEditor *aHTMLEd,
nsCOMPtr<nsIDOMNode> *aStartNode,
int32_t *aStartOffset,
nsCOMPtr<nsIDOMNode> *aEndNode,
int32_t *aEndOffset)
{
NS_ENSURE_TRUE(aStartNode && aEndNode && aStartOffset && aEndOffset &&
aHTMLEd, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsINode> startNode(do_QueryInterface(*aStartNode));
nsCOMPtr<nsINode> endNode(do_QueryInterface(*aEndNode));
NS_ENSURE_TRUE(startNode && endNode, NS_ERROR_NULL_POINTER);
nsAutoTrackDOMPoint trackerStart(aHTMLEd->mRangeUpdater, aStartNode, aStartOffset);
nsAutoTrackDOMPoint trackerStart(aHTMLEd->mRangeUpdater, aStartNode,
aStartOffset);
nsAutoTrackDOMPoint trackerEnd(aHTMLEd->mRangeUpdater, aEndNode, aEndOffset);
nsWSRunObject leftWSObj(aHTMLEd, startNode, *aStartOffset);
nsWSRunObject rightWSObj(aHTMLEd, endNode, *aEndOffset);
nsWSRunObject leftWSObj(aHTMLEd, *aStartNode, *aStartOffset);
nsWSRunObject rightWSObj(aHTMLEd, *aEndNode, *aEndOffset);
return leftWSObj.PrepareToDeleteRangePriv(&rightWSObj);
}

View File

@ -185,11 +185,6 @@ class MOZ_STACK_CLASS nsWSRunObject
int32_t* aStartOffset,
nsCOMPtr<nsINode>* aEndNode,
int32_t* aEndOffset);
static nsresult PrepareToDeleteRange(nsHTMLEditor *aHTMLEd,
nsCOMPtr<nsIDOMNode> *aStartNode,
int32_t *aStartOffset,
nsCOMPtr<nsIDOMNode> *aEndNode,
int32_t *aEndOffset);
// PrepareToDeleteNode fixes up ws before and after aNode in preperation
// for aNode to be deleted.