зеркало из https://github.com/mozilla/gecko-dev.git
Bug 761299 - Cleanup DeleteRangeTxn::CreateTxnsToDeleteBetween; r=ehsan
This commit is contained in:
Родитель
54fa2b7140
Коммит
0f088b5526
|
@ -96,8 +96,7 @@ NS_IMETHODIMP DeleteRangeTxn::Init(nsIEditor *aEditor,
|
|||
MOZ_ASSERT(end);
|
||||
NS_ASSERTION(mEndOffset <= PRInt32(end->Length()), "bad end offset");
|
||||
|
||||
if (gNoisy)
|
||||
{
|
||||
if (gNoisy) {
|
||||
printf ("DeleteRange: %d of %p to %d of %p\n",
|
||||
mStartOffset, (void *)mStartParent, mEndOffset, (void *)mEndParent);
|
||||
}
|
||||
|
@ -201,50 +200,40 @@ DeleteRangeTxn::CreateTxnsToDeleteBetween(nsIDOMNode *aStartParent,
|
|||
PRUint32 aStartOffset,
|
||||
PRUint32 aEndOffset)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
// see what kind of node we have
|
||||
nsCOMPtr<nsIDOMCharacterData> textNode = do_QueryInterface(aStartParent);
|
||||
if (textNode)
|
||||
{ // if the node is a text node, then delete text content
|
||||
if (textNode) {
|
||||
// if the node is a text node, then delete text content
|
||||
nsRefPtr<DeleteTextTxn> txn = new DeleteTextTxn();
|
||||
NS_ENSURE_TRUE(txn, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
PRInt32 numToDel;
|
||||
if (aStartOffset==aEndOffset)
|
||||
numToDel = 1;
|
||||
else
|
||||
numToDel = aEndOffset-aStartOffset;
|
||||
result = txn->Init(mEditor, textNode, aStartOffset, numToDel, mRangeUpdater);
|
||||
|
||||
nsresult rv = txn->Init(mEditor, textNode, aStartOffset, numToDel, mRangeUpdater);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
AppendChild(txn);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsINode> startParent = do_QueryInterface(aStartParent);
|
||||
NS_ENSURE_STATE(startParent);
|
||||
NS_ASSERTION(aEndOffset <= startParent->GetChildCount(), "bad aEndOffset");
|
||||
|
||||
nsCOMPtr<nsIContent> child = startParent->GetChildAt(aStartOffset);
|
||||
NS_ENSURE_STATE(child);
|
||||
|
||||
nsresult result = NS_OK;
|
||||
for (PRUint32 i = aStartOffset; i < aEndOffset; ++i) {
|
||||
nsRefPtr<DeleteElementTxn> txn = new DeleteElementTxn();
|
||||
result = txn->Init(mEditor, child->AsDOMNode(), mRangeUpdater);
|
||||
if (NS_SUCCEEDED(result))
|
||||
AppendChild(txn);
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIDOMNodeList> children;
|
||||
result = aStartParent->GetChildNodes(getter_AddRefs(children));
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
NS_ENSURE_TRUE(children, NS_ERROR_NULL_POINTER);
|
||||
|
||||
#ifdef DEBUG
|
||||
PRUint32 childCount;
|
||||
children->GetLength(&childCount);
|
||||
NS_ASSERTION(aEndOffset<=childCount, "bad aEndOffset");
|
||||
#endif
|
||||
PRUint32 i;
|
||||
for (i=aStartOffset; i<aEndOffset; i++)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
result = children->Item(i, getter_AddRefs(child));
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
NS_ENSURE_TRUE(child, NS_ERROR_NULL_POINTER);
|
||||
|
||||
nsRefPtr<DeleteElementTxn> txn = new DeleteElementTxn();
|
||||
NS_ENSURE_TRUE(txn, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
result = txn->Init(mEditor, child, mRangeUpdater);
|
||||
if (NS_SUCCEEDED(result))
|
||||
AppendChild(txn);
|
||||
}
|
||||
child = child->GetNextSibling();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче