diff --git a/mozilla/editor/base/EditTxn.cpp b/mozilla/editor/base/EditTxn.cpp index a24dcb14809..a220a664dce 100644 --- a/mozilla/editor/base/EditTxn.cpp +++ b/mozilla/editor/base/EditTxn.cpp @@ -109,34 +109,45 @@ EditTxn::SplitNode(nsIDOMNode * aNode, nsIDOMNode* aNewNode, nsIDOMNode* aParent) { - nsCOMPtr resultNode; - nsresult result = aParent->InsertBefore(aNewNode, aNode, getter_AddRefs(resultNode)); - if (NS_SUCCEEDED(result)) + nsresult result; + NS_ASSERTION(((nsnull!=aNode) && + (nsnull!=aNewNode) && + (nsnull!=aParent)), + "null arg"); + if ((nsnull!=aNode) && + (nsnull!=aNewNode) && + (nsnull!=aParent)) { - // 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 resultNode; + result = aParent->InsertBefore(aNewNode, aNode, getter_AddRefs(resultNode)); + if (NS_SUCCEEDED(result)) { - nsCOMPtr childNodes; - result = aParent->GetChildNodes(getter_AddRefs(childNodes)); - if ((NS_SUCCEEDED(result)) && (childNodes)) + // 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 { - PRInt32 i=0; - for ( ; ((NS_SUCCEEDED(result)) && (i childNodes; + result = aParent->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(result)) && (childNodes)) { - nsCOMPtr childNode; - result = childNodes->Item(i, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(result)) && (childNode)) + PRInt32 i=0; + for ( ; ((NS_SUCCEEDED(result)) && (iRemoveChild(childNode, getter_AddRefs(resultNode)); - if (NS_SUCCEEDED(result)) + nsCOMPtr childNode; + result = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(result)) && (childNode)) { - result = aNewNode->AppendChild(childNode, getter_AddRefs(resultNode)); + result = aNode->RemoveChild(childNode, getter_AddRefs(resultNode)); + if (NS_SUCCEEDED(result)) + { + result = aNewNode->AppendChild(childNode, getter_AddRefs(resultNode)); + } } } - } - } + } + } } + else result = NS_ERROR_NULL_POINTER; } return result; } @@ -148,5 +159,51 @@ EditTxn::JoinNodes(nsIDOMNode * aNodeToKeep, PRBool aNodeToKeepIsFirst) { nsresult result; + NS_ASSERTION(((nsnull!=aNodeToKeep) && + (nsnull!=aNodeToJoin) && + (nsnull!=aParent)), + "null arg"); + if ((nsnull!=aNodeToKeep) && + (nsnull!=aNodeToJoin) && + (nsnull!=aParent)) + { + nsCOMPtr childNodes; + result = aNodeToJoin->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(result)) && (childNodes)) + { + PRUint32 i; + PRUint32 childCount=0; + childNodes->GetLength(&childCount); + nsCOMPtr firstNode; //only used if aNodeToKeepIsFirst is false + if (PR_FALSE==aNodeToKeepIsFirst) + { // remember the first child in aNodeToKeep, we'll insert all the children of aNodeToJoin in front of it + result = aNodeToKeep->GetFirstChild(getter_AddRefs(firstNode)); + // GetFirstChild returns nsnull firstNode if aNodeToKeep has no children, that's ok. + } + nsCOMPtr resultNode; + for (i=0; ((NS_SUCCEEDED(result)) && (i childNode; + result = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(result)) && (childNode)) + { + if (PR_TRUE==aNodeToKeepIsFirst) + { // append children of aNodeToJoin + result = aNodeToKeep->AppendChild(childNode, getter_AddRefs(resultNode)); + } + else + { // prepend children of aNodeToJoin + result = aNodeToKeep->InsertBefore(childNode, firstNode, getter_AddRefs(resultNode)); + } + } + } + if (NS_SUCCEEDED(result)) + { // delete the extra node + result = aParent->RemoveChild(aNodeToJoin, getter_AddRefs(resultNode)); + } + } + } + else + result = NS_ERROR_NULL_POINTER; return result; } \ No newline at end of file diff --git a/mozilla/editor/core/EditTxn.cpp b/mozilla/editor/core/EditTxn.cpp index a24dcb14809..a220a664dce 100644 --- a/mozilla/editor/core/EditTxn.cpp +++ b/mozilla/editor/core/EditTxn.cpp @@ -109,34 +109,45 @@ EditTxn::SplitNode(nsIDOMNode * aNode, nsIDOMNode* aNewNode, nsIDOMNode* aParent) { - nsCOMPtr resultNode; - nsresult result = aParent->InsertBefore(aNewNode, aNode, getter_AddRefs(resultNode)); - if (NS_SUCCEEDED(result)) + nsresult result; + NS_ASSERTION(((nsnull!=aNode) && + (nsnull!=aNewNode) && + (nsnull!=aParent)), + "null arg"); + if ((nsnull!=aNode) && + (nsnull!=aNewNode) && + (nsnull!=aParent)) { - // 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 resultNode; + result = aParent->InsertBefore(aNewNode, aNode, getter_AddRefs(resultNode)); + if (NS_SUCCEEDED(result)) { - nsCOMPtr childNodes; - result = aParent->GetChildNodes(getter_AddRefs(childNodes)); - if ((NS_SUCCEEDED(result)) && (childNodes)) + // 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 { - PRInt32 i=0; - for ( ; ((NS_SUCCEEDED(result)) && (i childNodes; + result = aParent->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(result)) && (childNodes)) { - nsCOMPtr childNode; - result = childNodes->Item(i, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(result)) && (childNode)) + PRInt32 i=0; + for ( ; ((NS_SUCCEEDED(result)) && (iRemoveChild(childNode, getter_AddRefs(resultNode)); - if (NS_SUCCEEDED(result)) + nsCOMPtr childNode; + result = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(result)) && (childNode)) { - result = aNewNode->AppendChild(childNode, getter_AddRefs(resultNode)); + result = aNode->RemoveChild(childNode, getter_AddRefs(resultNode)); + if (NS_SUCCEEDED(result)) + { + result = aNewNode->AppendChild(childNode, getter_AddRefs(resultNode)); + } } } - } - } + } + } } + else result = NS_ERROR_NULL_POINTER; } return result; } @@ -148,5 +159,51 @@ EditTxn::JoinNodes(nsIDOMNode * aNodeToKeep, PRBool aNodeToKeepIsFirst) { nsresult result; + NS_ASSERTION(((nsnull!=aNodeToKeep) && + (nsnull!=aNodeToJoin) && + (nsnull!=aParent)), + "null arg"); + if ((nsnull!=aNodeToKeep) && + (nsnull!=aNodeToJoin) && + (nsnull!=aParent)) + { + nsCOMPtr childNodes; + result = aNodeToJoin->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(result)) && (childNodes)) + { + PRUint32 i; + PRUint32 childCount=0; + childNodes->GetLength(&childCount); + nsCOMPtr firstNode; //only used if aNodeToKeepIsFirst is false + if (PR_FALSE==aNodeToKeepIsFirst) + { // remember the first child in aNodeToKeep, we'll insert all the children of aNodeToJoin in front of it + result = aNodeToKeep->GetFirstChild(getter_AddRefs(firstNode)); + // GetFirstChild returns nsnull firstNode if aNodeToKeep has no children, that's ok. + } + nsCOMPtr resultNode; + for (i=0; ((NS_SUCCEEDED(result)) && (i childNode; + result = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(result)) && (childNode)) + { + if (PR_TRUE==aNodeToKeepIsFirst) + { // append children of aNodeToJoin + result = aNodeToKeep->AppendChild(childNode, getter_AddRefs(resultNode)); + } + else + { // prepend children of aNodeToJoin + result = aNodeToKeep->InsertBefore(childNode, firstNode, getter_AddRefs(resultNode)); + } + } + } + if (NS_SUCCEEDED(result)) + { // delete the extra node + result = aParent->RemoveChild(aNodeToJoin, getter_AddRefs(resultNode)); + } + } + } + else + result = NS_ERROR_NULL_POINTER; return result; } \ No newline at end of file diff --git a/mozilla/editor/libeditor/base/EditTxn.cpp b/mozilla/editor/libeditor/base/EditTxn.cpp index a24dcb14809..a220a664dce 100644 --- a/mozilla/editor/libeditor/base/EditTxn.cpp +++ b/mozilla/editor/libeditor/base/EditTxn.cpp @@ -109,34 +109,45 @@ EditTxn::SplitNode(nsIDOMNode * aNode, nsIDOMNode* aNewNode, nsIDOMNode* aParent) { - nsCOMPtr resultNode; - nsresult result = aParent->InsertBefore(aNewNode, aNode, getter_AddRefs(resultNode)); - if (NS_SUCCEEDED(result)) + nsresult result; + NS_ASSERTION(((nsnull!=aNode) && + (nsnull!=aNewNode) && + (nsnull!=aParent)), + "null arg"); + if ((nsnull!=aNode) && + (nsnull!=aNewNode) && + (nsnull!=aParent)) { - // 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 resultNode; + result = aParent->InsertBefore(aNewNode, aNode, getter_AddRefs(resultNode)); + if (NS_SUCCEEDED(result)) { - nsCOMPtr childNodes; - result = aParent->GetChildNodes(getter_AddRefs(childNodes)); - if ((NS_SUCCEEDED(result)) && (childNodes)) + // 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 { - PRInt32 i=0; - for ( ; ((NS_SUCCEEDED(result)) && (i childNodes; + result = aParent->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(result)) && (childNodes)) { - nsCOMPtr childNode; - result = childNodes->Item(i, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(result)) && (childNode)) + PRInt32 i=0; + for ( ; ((NS_SUCCEEDED(result)) && (iRemoveChild(childNode, getter_AddRefs(resultNode)); - if (NS_SUCCEEDED(result)) + nsCOMPtr childNode; + result = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(result)) && (childNode)) { - result = aNewNode->AppendChild(childNode, getter_AddRefs(resultNode)); + result = aNode->RemoveChild(childNode, getter_AddRefs(resultNode)); + if (NS_SUCCEEDED(result)) + { + result = aNewNode->AppendChild(childNode, getter_AddRefs(resultNode)); + } } } - } - } + } + } } + else result = NS_ERROR_NULL_POINTER; } return result; } @@ -148,5 +159,51 @@ EditTxn::JoinNodes(nsIDOMNode * aNodeToKeep, PRBool aNodeToKeepIsFirst) { nsresult result; + NS_ASSERTION(((nsnull!=aNodeToKeep) && + (nsnull!=aNodeToJoin) && + (nsnull!=aParent)), + "null arg"); + if ((nsnull!=aNodeToKeep) && + (nsnull!=aNodeToJoin) && + (nsnull!=aParent)) + { + nsCOMPtr childNodes; + result = aNodeToJoin->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(result)) && (childNodes)) + { + PRUint32 i; + PRUint32 childCount=0; + childNodes->GetLength(&childCount); + nsCOMPtr firstNode; //only used if aNodeToKeepIsFirst is false + if (PR_FALSE==aNodeToKeepIsFirst) + { // remember the first child in aNodeToKeep, we'll insert all the children of aNodeToJoin in front of it + result = aNodeToKeep->GetFirstChild(getter_AddRefs(firstNode)); + // GetFirstChild returns nsnull firstNode if aNodeToKeep has no children, that's ok. + } + nsCOMPtr resultNode; + for (i=0; ((NS_SUCCEEDED(result)) && (i childNode; + result = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(result)) && (childNode)) + { + if (PR_TRUE==aNodeToKeepIsFirst) + { // append children of aNodeToJoin + result = aNodeToKeep->AppendChild(childNode, getter_AddRefs(resultNode)); + } + else + { // prepend children of aNodeToJoin + result = aNodeToKeep->InsertBefore(childNode, firstNode, getter_AddRefs(resultNode)); + } + } + } + if (NS_SUCCEEDED(result)) + { // delete the extra node + result = aParent->RemoveChild(aNodeToJoin, getter_AddRefs(resultNode)); + } + } + } + else + result = NS_ERROR_NULL_POINTER; return result; } \ No newline at end of file