diff --git a/editor/base/CreateElementTxn.cpp b/editor/base/CreateElementTxn.cpp index f761b116145..bcb91f3c82c 100644 --- a/editor/base/CreateElementTxn.cpp +++ b/editor/base/CreateElementTxn.cpp @@ -44,6 +44,7 @@ CreateElementTxn::~CreateElementTxn() { NS_IF_RELEASE(mDoc); NS_IF_RELEASE(mParent); + NS_IF_RELEASE(mNewNode); } nsresult CreateElementTxn::Do(void) @@ -59,7 +60,8 @@ nsresult CreateElementTxn::Do(void) if (CreateElementTxn::eAppend==mOffsetInParent) { result = mParent->AppendChild(mNewNode, &resultNode); - //XXX: do we need to do anything with resultNode? release a refcount? + if ((NS_SUCCEEDED(result)) && (nsnull!=resultNode)) + NS_RELEASE(resultNode); // this object already holds a ref from CreateElement } else { @@ -71,7 +73,8 @@ nsresult CreateElementTxn::Do(void) if ((NS_SUCCEEDED(result)) && (nsnull!=mRefNode)) { result = mParent->InsertBefore(mNewNode, mRefNode, &resultNode); - //XXX: do we need to do anything with resultNode? release a refcount? + if ((NS_SUCCEEDED(result)) && (nsnull!=resultNode)) + NS_RELEASE(resultNode); // this object already holds a ref from CreateElement } } } @@ -81,13 +84,20 @@ nsresult CreateElementTxn::Do(void) nsresult CreateElementTxn::Undo(void) { - return NS_OK;//(mParent->InsertData(mOffset, mDeletedText)); + nsIDOMNode *resultNode=nsnull; + nsresult result = mParent->RemoveChild(mNewNode, &resultNode); + if ((NS_SUCCEEDED(result)) && (nsnull!=resultNode)) + NS_RELEASE(resultNode); + return result; } nsresult CreateElementTxn::Redo(void) { nsIDOMNode *resultNode=nsnull; - return (mParent->InsertBefore(mNewNode, mRefNode, &resultNode)); + nsresult result = mParent->InsertBefore(mNewNode, mRefNode, &resultNode); + if ((NS_SUCCEEDED(result)) && (nsnull!=resultNode)) + NS_RELEASE(resultNode); + return result; } nsresult CreateElementTxn::GetIsTransient(PRBool *aIsTransient) diff --git a/editor/base/editorInterfaces.cpp b/editor/base/editorInterfaces.cpp index f766b6447ca..ac3bff35689 100644 --- a/editor/base/editorInterfaces.cpp +++ b/editor/base/editorInterfaces.cpp @@ -294,7 +294,7 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces nsString attribute("src"); nsString value("resource:/res/samples/raptor.jpg"); - nsString imgTag("IMG"); + nsString imgTag("HR"); nsString bodyTag("BODY"); nsCOMPtr currentNode; result = mEditor->GetFirstNodeOfType(nsnull, bodyTag, getter_AddRefs(currentNode)); @@ -309,8 +309,8 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces mEditor->ExecuteTransaction(txn); } } - - /* for building a composite transaction */ +/* + //for building a composite transaction... nsCOMPtr element; if (NS_SUCCEEDED(mEditor->GetFirstNodeOfType(nsnull, imgTag, getter_AddRefs(currentNode)))) { @@ -321,6 +321,7 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces mEditor->ExecuteTransaction(txn); } } +*/ } aProcessed=PR_TRUE; break; diff --git a/editor/core/CreateElementTxn.cpp b/editor/core/CreateElementTxn.cpp index f761b116145..bcb91f3c82c 100644 --- a/editor/core/CreateElementTxn.cpp +++ b/editor/core/CreateElementTxn.cpp @@ -44,6 +44,7 @@ CreateElementTxn::~CreateElementTxn() { NS_IF_RELEASE(mDoc); NS_IF_RELEASE(mParent); + NS_IF_RELEASE(mNewNode); } nsresult CreateElementTxn::Do(void) @@ -59,7 +60,8 @@ nsresult CreateElementTxn::Do(void) if (CreateElementTxn::eAppend==mOffsetInParent) { result = mParent->AppendChild(mNewNode, &resultNode); - //XXX: do we need to do anything with resultNode? release a refcount? + if ((NS_SUCCEEDED(result)) && (nsnull!=resultNode)) + NS_RELEASE(resultNode); // this object already holds a ref from CreateElement } else { @@ -71,7 +73,8 @@ nsresult CreateElementTxn::Do(void) if ((NS_SUCCEEDED(result)) && (nsnull!=mRefNode)) { result = mParent->InsertBefore(mNewNode, mRefNode, &resultNode); - //XXX: do we need to do anything with resultNode? release a refcount? + if ((NS_SUCCEEDED(result)) && (nsnull!=resultNode)) + NS_RELEASE(resultNode); // this object already holds a ref from CreateElement } } } @@ -81,13 +84,20 @@ nsresult CreateElementTxn::Do(void) nsresult CreateElementTxn::Undo(void) { - return NS_OK;//(mParent->InsertData(mOffset, mDeletedText)); + nsIDOMNode *resultNode=nsnull; + nsresult result = mParent->RemoveChild(mNewNode, &resultNode); + if ((NS_SUCCEEDED(result)) && (nsnull!=resultNode)) + NS_RELEASE(resultNode); + return result; } nsresult CreateElementTxn::Redo(void) { nsIDOMNode *resultNode=nsnull; - return (mParent->InsertBefore(mNewNode, mRefNode, &resultNode)); + nsresult result = mParent->InsertBefore(mNewNode, mRefNode, &resultNode); + if ((NS_SUCCEEDED(result)) && (nsnull!=resultNode)) + NS_RELEASE(resultNode); + return result; } nsresult CreateElementTxn::GetIsTransient(PRBool *aIsTransient) diff --git a/editor/core/editorInterfaces.cpp b/editor/core/editorInterfaces.cpp index f766b6447ca..ac3bff35689 100644 --- a/editor/core/editorInterfaces.cpp +++ b/editor/core/editorInterfaces.cpp @@ -294,7 +294,7 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces nsString attribute("src"); nsString value("resource:/res/samples/raptor.jpg"); - nsString imgTag("IMG"); + nsString imgTag("HR"); nsString bodyTag("BODY"); nsCOMPtr currentNode; result = mEditor->GetFirstNodeOfType(nsnull, bodyTag, getter_AddRefs(currentNode)); @@ -309,8 +309,8 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces mEditor->ExecuteTransaction(txn); } } - - /* for building a composite transaction */ +/* + //for building a composite transaction... nsCOMPtr element; if (NS_SUCCEEDED(mEditor->GetFirstNodeOfType(nsnull, imgTag, getter_AddRefs(currentNode)))) { @@ -321,6 +321,7 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces mEditor->ExecuteTransaction(txn); } } +*/ } aProcessed=PR_TRUE; break; diff --git a/editor/libeditor/base/CreateElementTxn.cpp b/editor/libeditor/base/CreateElementTxn.cpp index f761b116145..bcb91f3c82c 100644 --- a/editor/libeditor/base/CreateElementTxn.cpp +++ b/editor/libeditor/base/CreateElementTxn.cpp @@ -44,6 +44,7 @@ CreateElementTxn::~CreateElementTxn() { NS_IF_RELEASE(mDoc); NS_IF_RELEASE(mParent); + NS_IF_RELEASE(mNewNode); } nsresult CreateElementTxn::Do(void) @@ -59,7 +60,8 @@ nsresult CreateElementTxn::Do(void) if (CreateElementTxn::eAppend==mOffsetInParent) { result = mParent->AppendChild(mNewNode, &resultNode); - //XXX: do we need to do anything with resultNode? release a refcount? + if ((NS_SUCCEEDED(result)) && (nsnull!=resultNode)) + NS_RELEASE(resultNode); // this object already holds a ref from CreateElement } else { @@ -71,7 +73,8 @@ nsresult CreateElementTxn::Do(void) if ((NS_SUCCEEDED(result)) && (nsnull!=mRefNode)) { result = mParent->InsertBefore(mNewNode, mRefNode, &resultNode); - //XXX: do we need to do anything with resultNode? release a refcount? + if ((NS_SUCCEEDED(result)) && (nsnull!=resultNode)) + NS_RELEASE(resultNode); // this object already holds a ref from CreateElement } } } @@ -81,13 +84,20 @@ nsresult CreateElementTxn::Do(void) nsresult CreateElementTxn::Undo(void) { - return NS_OK;//(mParent->InsertData(mOffset, mDeletedText)); + nsIDOMNode *resultNode=nsnull; + nsresult result = mParent->RemoveChild(mNewNode, &resultNode); + if ((NS_SUCCEEDED(result)) && (nsnull!=resultNode)) + NS_RELEASE(resultNode); + return result; } nsresult CreateElementTxn::Redo(void) { nsIDOMNode *resultNode=nsnull; - return (mParent->InsertBefore(mNewNode, mRefNode, &resultNode)); + nsresult result = mParent->InsertBefore(mNewNode, mRefNode, &resultNode); + if ((NS_SUCCEEDED(result)) && (nsnull!=resultNode)) + NS_RELEASE(resultNode); + return result; } nsresult CreateElementTxn::GetIsTransient(PRBool *aIsTransient)