diff --git a/mozilla/editor/base/EditTxn.cpp b/mozilla/editor/base/EditTxn.cpp index f27751239fe..a24dcb14809 100644 --- a/mozilla/editor/base/EditTxn.cpp +++ b/mozilla/editor/base/EditTxn.cpp @@ -17,6 +17,9 @@ */ #include "EditTxn.h" +#include "nsCOMPtr.h" +#include "nsIDOMNode.h" +#include "nsIDOMNodeList.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kITransactionIID, NS_ITRANSACTION_IID); @@ -96,3 +99,54 @@ EditTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr) *aInstancePtr = 0; return NS_NOINTERFACE; } + + +/* =============================== Static helper methods ================================== */ + +nsresult +EditTxn::SplitNode(nsIDOMNode * aNode, + PRInt32 aOffset, + nsIDOMNode* aNewNode, + nsIDOMNode* aParent) +{ + nsCOMPtr resultNode; + nsresult result = aParent->InsertBefore(aNewNode, aNode, getter_AddRefs(resultNode)); + if (NS_SUCCEEDED(result)) + { + // split the children between the 2 nodes + // at this point, nNode has all the children + if (0<=aOffset) // don't bother unless we're going to move at least one child + { + nsCOMPtr childNodes; + result = aParent->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(result)) && (childNodes)) + { + PRInt32 i=0; + for ( ; ((NS_SUCCEEDED(result)) && (i childNode; + result = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(result)) && (childNode)) + { + result = aNode->RemoveChild(childNode, getter_AddRefs(resultNode)); + if (NS_SUCCEEDED(result)) + { + result = aNewNode->AppendChild(childNode, getter_AddRefs(resultNode)); + } + } + } + } + } + } + return result; +} + +nsresult +EditTxn::JoinNodes(nsIDOMNode * aNodeToKeep, + nsIDOMNode * aNodeToJoin, + nsIDOMNode * aParent, + PRBool aNodeToKeepIsFirst) +{ + nsresult result; + return result; +} \ No newline at end of file diff --git a/mozilla/editor/base/EditTxn.h b/mozilla/editor/base/EditTxn.h index af6e4224081..ac0201f0412 100644 --- a/mozilla/editor/base/EditTxn.h +++ b/mozilla/editor/base/EditTxn.h @@ -22,6 +22,8 @@ #include "nsITransaction.h" class nsEditor; +class nsIDOMNode; + /** * base class for all document editing transactions. * provides access to the nsEditor that created this transaction. @@ -50,6 +52,19 @@ public: virtual nsresult GetRedoString(nsString **aString); + // helper static methods. maybe move these into editor class. + + /** */ + static nsresult SplitNode(nsIDOMNode * aNode, + PRInt32 aOffset, + nsIDOMNode * aNewNode, + nsIDOMNode * aParent); + + static nsresult EditTxn::JoinNodes(nsIDOMNode * aNodeToKeep, + nsIDOMNode * aNodeToJoin, + nsIDOMNode * aParent, + PRBool aNodeToKeepIsFirst); + protected: nsEditor *mEditor; diff --git a/mozilla/editor/base/SplitElementTxn.cpp b/mozilla/editor/base/SplitElementTxn.cpp index a0ab3288fcd..ee040d801dc 100644 --- a/mozilla/editor/base/SplitElementTxn.cpp +++ b/mozilla/editor/base/SplitElementTxn.cpp @@ -20,7 +20,6 @@ #include "editor.h" #include "nsIDOMNode.h" #include "nsIDOMNodeList.h" -#include "nsIDOMDocument.h" #include "nsIDOMElement.h" // note that aEditor is not refcounted @@ -56,35 +55,7 @@ nsresult SplitElementTxn::Do(void) // insert the new node if ((NS_SUCCEEDED(result)) && (nsnull!=mParent)) { - nsCOMPtr resultNode; - result = mParent->InsertBefore(mNewNode, mNode, getter_AddRefs(resultNode)); - if (NS_SUCCEEDED(result)) - { - // split the children between the 2 nodes - // at this point, nNode has all the children - if (0<=mOffset) // don't bother unless we're going to move at least one child - { - nsCOMPtr childNodes; - result = mParent->GetChildNodes(getter_AddRefs(childNodes)); - if ((NS_SUCCEEDED(result)) && (childNodes)) - { - PRUint32 i=0; - for ( ; ((NS_SUCCEEDED(result)) && (i childNode; - result = childNodes->Item(i, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(result)) && (childNode)) - { - result = mNode->RemoveChild(childNode, getter_AddRefs(resultNode)); - if (NS_SUCCEEDED(result)) - { - result = mNewNode->AppendChild(childNode, getter_AddRefs(resultNode)); - } - } - } - } - } - } + result = EditTxn::SplitNode(mNode, mOffset, mNewNode, mParent); } } return result; @@ -92,12 +63,15 @@ nsresult SplitElementTxn::Do(void) nsresult SplitElementTxn::Undo(void) { - return NS_OK; + // this assumes Do inserted the new node in front of the prior existing node + nsresult result = EditTxn::JoinNodes(mNode, mNewNode, mParent, PR_FALSE); + return result; } nsresult SplitElementTxn::Redo(void) { - return NS_OK; + nsresult result = EditTxn::SplitNode(mNode, mOffset, mNewNode, mParent); + return result; } nsresult SplitElementTxn::GetIsTransient(PRBool *aIsTransient) diff --git a/mozilla/editor/core/EditTxn.cpp b/mozilla/editor/core/EditTxn.cpp index f27751239fe..a24dcb14809 100644 --- a/mozilla/editor/core/EditTxn.cpp +++ b/mozilla/editor/core/EditTxn.cpp @@ -17,6 +17,9 @@ */ #include "EditTxn.h" +#include "nsCOMPtr.h" +#include "nsIDOMNode.h" +#include "nsIDOMNodeList.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kITransactionIID, NS_ITRANSACTION_IID); @@ -96,3 +99,54 @@ EditTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr) *aInstancePtr = 0; return NS_NOINTERFACE; } + + +/* =============================== Static helper methods ================================== */ + +nsresult +EditTxn::SplitNode(nsIDOMNode * aNode, + PRInt32 aOffset, + nsIDOMNode* aNewNode, + nsIDOMNode* aParent) +{ + nsCOMPtr resultNode; + nsresult result = aParent->InsertBefore(aNewNode, aNode, getter_AddRefs(resultNode)); + if (NS_SUCCEEDED(result)) + { + // split the children between the 2 nodes + // at this point, nNode has all the children + if (0<=aOffset) // don't bother unless we're going to move at least one child + { + nsCOMPtr childNodes; + result = aParent->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(result)) && (childNodes)) + { + PRInt32 i=0; + for ( ; ((NS_SUCCEEDED(result)) && (i childNode; + result = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(result)) && (childNode)) + { + result = aNode->RemoveChild(childNode, getter_AddRefs(resultNode)); + if (NS_SUCCEEDED(result)) + { + result = aNewNode->AppendChild(childNode, getter_AddRefs(resultNode)); + } + } + } + } + } + } + return result; +} + +nsresult +EditTxn::JoinNodes(nsIDOMNode * aNodeToKeep, + nsIDOMNode * aNodeToJoin, + nsIDOMNode * aParent, + PRBool aNodeToKeepIsFirst) +{ + nsresult result; + return result; +} \ No newline at end of file diff --git a/mozilla/editor/core/EditTxn.h b/mozilla/editor/core/EditTxn.h index af6e4224081..ac0201f0412 100644 --- a/mozilla/editor/core/EditTxn.h +++ b/mozilla/editor/core/EditTxn.h @@ -22,6 +22,8 @@ #include "nsITransaction.h" class nsEditor; +class nsIDOMNode; + /** * base class for all document editing transactions. * provides access to the nsEditor that created this transaction. @@ -50,6 +52,19 @@ public: virtual nsresult GetRedoString(nsString **aString); + // helper static methods. maybe move these into editor class. + + /** */ + static nsresult SplitNode(nsIDOMNode * aNode, + PRInt32 aOffset, + nsIDOMNode * aNewNode, + nsIDOMNode * aParent); + + static nsresult EditTxn::JoinNodes(nsIDOMNode * aNodeToKeep, + nsIDOMNode * aNodeToJoin, + nsIDOMNode * aParent, + PRBool aNodeToKeepIsFirst); + protected: nsEditor *mEditor; diff --git a/mozilla/editor/core/SplitElementTxn.cpp b/mozilla/editor/core/SplitElementTxn.cpp index a0ab3288fcd..ee040d801dc 100644 --- a/mozilla/editor/core/SplitElementTxn.cpp +++ b/mozilla/editor/core/SplitElementTxn.cpp @@ -20,7 +20,6 @@ #include "editor.h" #include "nsIDOMNode.h" #include "nsIDOMNodeList.h" -#include "nsIDOMDocument.h" #include "nsIDOMElement.h" // note that aEditor is not refcounted @@ -56,35 +55,7 @@ nsresult SplitElementTxn::Do(void) // insert the new node if ((NS_SUCCEEDED(result)) && (nsnull!=mParent)) { - nsCOMPtr resultNode; - result = mParent->InsertBefore(mNewNode, mNode, getter_AddRefs(resultNode)); - if (NS_SUCCEEDED(result)) - { - // split the children between the 2 nodes - // at this point, nNode has all the children - if (0<=mOffset) // don't bother unless we're going to move at least one child - { - nsCOMPtr childNodes; - result = mParent->GetChildNodes(getter_AddRefs(childNodes)); - if ((NS_SUCCEEDED(result)) && (childNodes)) - { - PRUint32 i=0; - for ( ; ((NS_SUCCEEDED(result)) && (i childNode; - result = childNodes->Item(i, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(result)) && (childNode)) - { - result = mNode->RemoveChild(childNode, getter_AddRefs(resultNode)); - if (NS_SUCCEEDED(result)) - { - result = mNewNode->AppendChild(childNode, getter_AddRefs(resultNode)); - } - } - } - } - } - } + result = EditTxn::SplitNode(mNode, mOffset, mNewNode, mParent); } } return result; @@ -92,12 +63,15 @@ nsresult SplitElementTxn::Do(void) nsresult SplitElementTxn::Undo(void) { - return NS_OK; + // this assumes Do inserted the new node in front of the prior existing node + nsresult result = EditTxn::JoinNodes(mNode, mNewNode, mParent, PR_FALSE); + return result; } nsresult SplitElementTxn::Redo(void) { - return NS_OK; + nsresult result = EditTxn::SplitNode(mNode, mOffset, mNewNode, mParent); + return result; } nsresult SplitElementTxn::GetIsTransient(PRBool *aIsTransient) diff --git a/mozilla/editor/libeditor/base/EditTxn.cpp b/mozilla/editor/libeditor/base/EditTxn.cpp index f27751239fe..a24dcb14809 100644 --- a/mozilla/editor/libeditor/base/EditTxn.cpp +++ b/mozilla/editor/libeditor/base/EditTxn.cpp @@ -17,6 +17,9 @@ */ #include "EditTxn.h" +#include "nsCOMPtr.h" +#include "nsIDOMNode.h" +#include "nsIDOMNodeList.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kITransactionIID, NS_ITRANSACTION_IID); @@ -96,3 +99,54 @@ EditTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr) *aInstancePtr = 0; return NS_NOINTERFACE; } + + +/* =============================== Static helper methods ================================== */ + +nsresult +EditTxn::SplitNode(nsIDOMNode * aNode, + PRInt32 aOffset, + nsIDOMNode* aNewNode, + nsIDOMNode* aParent) +{ + nsCOMPtr resultNode; + nsresult result = aParent->InsertBefore(aNewNode, aNode, getter_AddRefs(resultNode)); + if (NS_SUCCEEDED(result)) + { + // split the children between the 2 nodes + // at this point, nNode has all the children + if (0<=aOffset) // don't bother unless we're going to move at least one child + { + nsCOMPtr childNodes; + result = aParent->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(result)) && (childNodes)) + { + PRInt32 i=0; + for ( ; ((NS_SUCCEEDED(result)) && (i childNode; + result = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(result)) && (childNode)) + { + result = aNode->RemoveChild(childNode, getter_AddRefs(resultNode)); + if (NS_SUCCEEDED(result)) + { + result = aNewNode->AppendChild(childNode, getter_AddRefs(resultNode)); + } + } + } + } + } + } + return result; +} + +nsresult +EditTxn::JoinNodes(nsIDOMNode * aNodeToKeep, + nsIDOMNode * aNodeToJoin, + nsIDOMNode * aParent, + PRBool aNodeToKeepIsFirst) +{ + nsresult result; + return result; +} \ No newline at end of file diff --git a/mozilla/editor/libeditor/base/EditTxn.h b/mozilla/editor/libeditor/base/EditTxn.h index af6e4224081..ac0201f0412 100644 --- a/mozilla/editor/libeditor/base/EditTxn.h +++ b/mozilla/editor/libeditor/base/EditTxn.h @@ -22,6 +22,8 @@ #include "nsITransaction.h" class nsEditor; +class nsIDOMNode; + /** * base class for all document editing transactions. * provides access to the nsEditor that created this transaction. @@ -50,6 +52,19 @@ public: virtual nsresult GetRedoString(nsString **aString); + // helper static methods. maybe move these into editor class. + + /** */ + static nsresult SplitNode(nsIDOMNode * aNode, + PRInt32 aOffset, + nsIDOMNode * aNewNode, + nsIDOMNode * aParent); + + static nsresult EditTxn::JoinNodes(nsIDOMNode * aNodeToKeep, + nsIDOMNode * aNodeToJoin, + nsIDOMNode * aParent, + PRBool aNodeToKeepIsFirst); + protected: nsEditor *mEditor; diff --git a/mozilla/editor/libeditor/base/SplitElementTxn.cpp b/mozilla/editor/libeditor/base/SplitElementTxn.cpp index a0ab3288fcd..ee040d801dc 100644 --- a/mozilla/editor/libeditor/base/SplitElementTxn.cpp +++ b/mozilla/editor/libeditor/base/SplitElementTxn.cpp @@ -20,7 +20,6 @@ #include "editor.h" #include "nsIDOMNode.h" #include "nsIDOMNodeList.h" -#include "nsIDOMDocument.h" #include "nsIDOMElement.h" // note that aEditor is not refcounted @@ -56,35 +55,7 @@ nsresult SplitElementTxn::Do(void) // insert the new node if ((NS_SUCCEEDED(result)) && (nsnull!=mParent)) { - nsCOMPtr resultNode; - result = mParent->InsertBefore(mNewNode, mNode, getter_AddRefs(resultNode)); - if (NS_SUCCEEDED(result)) - { - // split the children between the 2 nodes - // at this point, nNode has all the children - if (0<=mOffset) // don't bother unless we're going to move at least one child - { - nsCOMPtr childNodes; - result = mParent->GetChildNodes(getter_AddRefs(childNodes)); - if ((NS_SUCCEEDED(result)) && (childNodes)) - { - PRUint32 i=0; - for ( ; ((NS_SUCCEEDED(result)) && (i childNode; - result = childNodes->Item(i, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(result)) && (childNode)) - { - result = mNode->RemoveChild(childNode, getter_AddRefs(resultNode)); - if (NS_SUCCEEDED(result)) - { - result = mNewNode->AppendChild(childNode, getter_AddRefs(resultNode)); - } - } - } - } - } - } + result = EditTxn::SplitNode(mNode, mOffset, mNewNode, mParent); } } return result; @@ -92,12 +63,15 @@ nsresult SplitElementTxn::Do(void) nsresult SplitElementTxn::Undo(void) { - return NS_OK; + // this assumes Do inserted the new node in front of the prior existing node + nsresult result = EditTxn::JoinNodes(mNode, mNewNode, mParent, PR_FALSE); + return result; } nsresult SplitElementTxn::Redo(void) { - return NS_OK; + nsresult result = EditTxn::SplitNode(mNode, mOffset, mNewNode, mParent); + return result; } nsresult SplitElementTxn::GetIsTransient(PRBool *aIsTransient)