From 83ea67799132dcbcfb83121a0967e5933f009656 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 6 Jun 2012 09:41:30 +0200 Subject: [PATCH] Bug 761296 - Cleanup InsertElementTxn::DoTransaction; r=ehsan --- editor/libeditor/base/InsertElementTxn.cpp | 25 ++++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/editor/libeditor/base/InsertElementTxn.cpp b/editor/libeditor/base/InsertElementTxn.cpp index 88361713e92..0f3b08e248f 100644 --- a/editor/libeditor/base/InsertElementTxn.cpp +++ b/editor/libeditor/base/InsertElementTxn.cpp @@ -75,26 +75,23 @@ NS_IMETHODIMP InsertElementTxn::DoTransaction(void) NS_ENSURE_TRUE(mNode && mParent, NS_ERROR_NOT_INITIALIZED); - nsCOMPtr childNodes; - nsresult result = mParent->GetChildNodes(getter_AddRefs(childNodes)); - NS_ENSURE_SUCCESS(result, result); - nsCOMPtrrefNode; - if (childNodes) - { - PRUint32 count; - childNodes->GetLength(&count); - if (mOffset>(PRInt32)count) mOffset = count; + nsCOMPtr parent = do_QueryInterface(mParent); + NS_ENSURE_STATE(parent); + + PRUint32 count = parent->GetChildCount(); + if (mOffset > PRInt32(count) || mOffset == -1) { // -1 is sentinel value meaning "append at end" - if (mOffset == -1) mOffset = count; - result = childNodes->Item(mOffset, getter_AddRefs(refNode)); - NS_ENSURE_SUCCESS(result, result); - // note, it's ok for mRefNode to be null. that means append + mOffset = count; } + nsIContent* refContent = parent->GetChildAt(mOffset); + // note, it's ok for refNode to be null. that means append + nsCOMPtr refNode = refContent ? refContent->AsDOMNode() : nsnull; + mEditor->MarkNodeDirty(mNode); nsCOMPtr resultNode; - result = mParent->InsertBefore(mNode, refNode, getter_AddRefs(resultNode)); + nsresult result = mParent->InsertBefore(mNode, refNode, getter_AddRefs(resultNode)); NS_ENSURE_SUCCESS(result, result); NS_ENSURE_TRUE(resultNode, NS_ERROR_NULL_POINTER);