diff --git a/mozilla/editor/base/Makefile.in b/mozilla/editor/base/Makefile.in index da9e93458be..1d1b2e1f80a 100644 --- a/mozilla/editor/base/Makefile.in +++ b/mozilla/editor/base/Makefile.in @@ -33,6 +33,7 @@ CPPSRCS = \ InsertTextTxn.cpp \ DeleteTextTxn.cpp \ CreateElementTxn.cpp \ + SplitElementTxn.cpp \ $(NULL) MODULE = editor diff --git a/mozilla/editor/base/SplitElementTxn.cpp b/mozilla/editor/base/SplitElementTxn.cpp new file mode 100644 index 00000000000..a0ab3288fcd --- /dev/null +++ b/mozilla/editor/base/SplitElementTxn.cpp @@ -0,0 +1,136 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "SplitElementTxn.h" +#include "editor.h" +#include "nsIDOMNode.h" +#include "nsIDOMNodeList.h" +#include "nsIDOMDocument.h" +#include "nsIDOMElement.h" + +// note that aEditor is not refcounted +SplitElementTxn::SplitElementTxn(nsEditor *aEditor, + nsIDOMNode *aNode, + PRInt32 aOffset) + : EditTxn(aEditor) +{ + mNode = aNode; + NS_ADDREF(mNode); + mOffset = aOffset; + mNewNode = nsnull; + mParent = nsnull; +} + +SplitElementTxn::~SplitElementTxn() +{ + NS_IF_RELEASE(mNode); + NS_IF_RELEASE(mNewNode); + NS_IF_RELEASE(mParent); +} + +nsresult SplitElementTxn::Do(void) +{ + // create a new node + nsresult result = mNode->CloneNode(PR_FALSE, &mNewNode); + NS_ASSERTION(((NS_SUCCEEDED(result)) && (nsnull!=mNewNode)), "could not create element."); + + if ((NS_SUCCEEDED(result)) && (nsnull!=mNewNode)) + { + // get the parent node + result = mNode->GetParentNode(&mParent); + // 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)); + } + } + } + } + } + } + } + } + return result; +} + +nsresult SplitElementTxn::Undo(void) +{ + return NS_OK; +} + +nsresult SplitElementTxn::Redo(void) +{ + return NS_OK; +} + +nsresult SplitElementTxn::GetIsTransient(PRBool *aIsTransient) +{ + if (nsnull!=aIsTransient) + *aIsTransient = PR_FALSE; + return NS_OK; +} + +nsresult SplitElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction) +{ + return NS_OK; +} + +nsresult SplitElementTxn::Write(nsIOutputStream *aOutputStream) +{ + return NS_OK; +} + +nsresult SplitElementTxn::GetUndoString(nsString **aString) +{ + if (nsnull!=aString) + { + **aString="Join Element"; + } + return NS_OK; +} + +nsresult SplitElementTxn::GetRedoString(nsString **aString) +{ + if (nsnull!=aString) + { + **aString="Split Element"; + } + return NS_OK; +} diff --git a/mozilla/editor/base/SplitElementTxn.h b/mozilla/editor/base/SplitElementTxn.h new file mode 100644 index 00000000000..8fb19df1fb6 --- /dev/null +++ b/mozilla/editor/base/SplitElementTxn.h @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef SplitElementTxn_h__ +#define SplitElementTxn_h__ + +#include "EditTxn.h" + +class nsIDOMNode; +class nsIDOMElement; +class nsIDOMDocument; + +/** + * A transaction that splits an element E into two identical nodes, E1 and E2 + * with the children of E divided between E1 and E2. + */ +class SplitElementTxn : public EditTxn +{ +public: + + SplitElementTxn(nsEditor *aEditor, + nsIDOMNode *aNode, + PRInt32 aOffset); + + virtual ~SplitElementTxn(); + + virtual nsresult Do(void); + + virtual nsresult Undo(void); + + virtual nsresult Redo(void); + + virtual nsresult GetIsTransient(PRBool *aIsTransient); + + virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction); + + virtual nsresult Write(nsIOutputStream *aOutputStream); + + virtual nsresult GetUndoString(nsString **aString); + + virtual nsresult GetRedoString(nsString **aString); + +protected: + + /** the element to operate upon */ + nsIDOMNode *mNode; + + /** the offset into mElement where the children of mElement are split.
+ * mOffset is the index of the last child in the left node. + * -1 means the new node gets no children. + */ + PRInt32 mOffset; + + /** the element we create when splitting mElement */ + nsIDOMNode *mNewNode; + nsIDOMNode *mParent; + +}; + +#endif diff --git a/mozilla/editor/base/editorInterfaces.cpp b/mozilla/editor/base/editorInterfaces.cpp index 8e002e24739..c3a037af361 100644 --- a/mozilla/editor/base/editorInterfaces.cpp +++ b/mozilla/editor/base/editorInterfaces.cpp @@ -22,6 +22,7 @@ #include "InsertTextTxn.h" #include "DeleteTextTxn.h" #include "CreateElementTxn.h" +#include "SplitElementTxn.h" #include "nsIDOMDocument.h" #include "nsIDOMElement.h" @@ -247,7 +248,7 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces // XXX: please please please get these mappings from an external source! switch (keyCode) { - // hard-coded undo + // XXX: hard-coded undo case nsIDOMEvent::VK_Z: if (PR_TRUE==ctrlKey) { @@ -257,7 +258,7 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces aProcessed=PR_TRUE; break; - // hard-coded redo + // XXX: hard-coded redo case nsIDOMEvent::VK_Y: if (PR_TRUE==ctrlKey) { @@ -267,6 +268,27 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces aProcessed=PR_TRUE; break; + // hard-coded split node test: works on first

in the document + case nsIDOMEvent::VK_S: + { + nsString pTag("P"); + nsCOMPtr currentNode; + nsCOMPtr element; + if (NS_SUCCEEDED(mEditor->GetFirstNodeOfType(nsnull, pTag, getter_AddRefs(currentNode)))) + { + SplitElementTxn *txn; + if (PR_FALSE==isShift) // split the element so there are 0 children in the first half + txn = new SplitElementTxn(mEditor, currentNode, -1); + else // split the element so there are 0 children in the first half + txn = new SplitElementTxn(mEditor, currentNode, 1); + mEditor->ExecuteTransaction(txn); + } + } + aProcessed=PR_TRUE; + break; + + + //XXX: test for change and remove attribute, hard-coded to be width on first table in doc case nsIDOMEvent::VK_TAB: { //XXX: should be from a factory diff --git a/mozilla/editor/base/makefile.win b/mozilla/editor/base/makefile.win index 4abcc9606e7..df301fd471b 100644 --- a/mozilla/editor/base/makefile.win +++ b/mozilla/editor/base/makefile.win @@ -29,6 +29,7 @@ CPPSRCS = \ InsertTextTxn.cpp \ DeleteTextTxn.cpp \ CreateElementTxn.cpp \ + SplitElementTxn.cpp \ $(NULL) CPP_OBJS = \ @@ -40,6 +41,7 @@ CPP_OBJS = \ .\$(OBJDIR)\InsertTextTxn.obj \ .\$(OBJDIR)\DeleteTextTxn.obj \ .\$(OBJDIR)\CreateElementTxn.obj \ + .\$(OBJDIR)\SplitElementTxn.obj \ $(NULL) MODULE=editor diff --git a/mozilla/editor/core/Makefile.in b/mozilla/editor/core/Makefile.in index da9e93458be..1d1b2e1f80a 100644 --- a/mozilla/editor/core/Makefile.in +++ b/mozilla/editor/core/Makefile.in @@ -33,6 +33,7 @@ CPPSRCS = \ InsertTextTxn.cpp \ DeleteTextTxn.cpp \ CreateElementTxn.cpp \ + SplitElementTxn.cpp \ $(NULL) MODULE = editor diff --git a/mozilla/editor/core/SplitElementTxn.cpp b/mozilla/editor/core/SplitElementTxn.cpp new file mode 100644 index 00000000000..a0ab3288fcd --- /dev/null +++ b/mozilla/editor/core/SplitElementTxn.cpp @@ -0,0 +1,136 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "SplitElementTxn.h" +#include "editor.h" +#include "nsIDOMNode.h" +#include "nsIDOMNodeList.h" +#include "nsIDOMDocument.h" +#include "nsIDOMElement.h" + +// note that aEditor is not refcounted +SplitElementTxn::SplitElementTxn(nsEditor *aEditor, + nsIDOMNode *aNode, + PRInt32 aOffset) + : EditTxn(aEditor) +{ + mNode = aNode; + NS_ADDREF(mNode); + mOffset = aOffset; + mNewNode = nsnull; + mParent = nsnull; +} + +SplitElementTxn::~SplitElementTxn() +{ + NS_IF_RELEASE(mNode); + NS_IF_RELEASE(mNewNode); + NS_IF_RELEASE(mParent); +} + +nsresult SplitElementTxn::Do(void) +{ + // create a new node + nsresult result = mNode->CloneNode(PR_FALSE, &mNewNode); + NS_ASSERTION(((NS_SUCCEEDED(result)) && (nsnull!=mNewNode)), "could not create element."); + + if ((NS_SUCCEEDED(result)) && (nsnull!=mNewNode)) + { + // get the parent node + result = mNode->GetParentNode(&mParent); + // 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)); + } + } + } + } + } + } + } + } + return result; +} + +nsresult SplitElementTxn::Undo(void) +{ + return NS_OK; +} + +nsresult SplitElementTxn::Redo(void) +{ + return NS_OK; +} + +nsresult SplitElementTxn::GetIsTransient(PRBool *aIsTransient) +{ + if (nsnull!=aIsTransient) + *aIsTransient = PR_FALSE; + return NS_OK; +} + +nsresult SplitElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction) +{ + return NS_OK; +} + +nsresult SplitElementTxn::Write(nsIOutputStream *aOutputStream) +{ + return NS_OK; +} + +nsresult SplitElementTxn::GetUndoString(nsString **aString) +{ + if (nsnull!=aString) + { + **aString="Join Element"; + } + return NS_OK; +} + +nsresult SplitElementTxn::GetRedoString(nsString **aString) +{ + if (nsnull!=aString) + { + **aString="Split Element"; + } + return NS_OK; +} diff --git a/mozilla/editor/core/SplitElementTxn.h b/mozilla/editor/core/SplitElementTxn.h new file mode 100644 index 00000000000..8fb19df1fb6 --- /dev/null +++ b/mozilla/editor/core/SplitElementTxn.h @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef SplitElementTxn_h__ +#define SplitElementTxn_h__ + +#include "EditTxn.h" + +class nsIDOMNode; +class nsIDOMElement; +class nsIDOMDocument; + +/** + * A transaction that splits an element E into two identical nodes, E1 and E2 + * with the children of E divided between E1 and E2. + */ +class SplitElementTxn : public EditTxn +{ +public: + + SplitElementTxn(nsEditor *aEditor, + nsIDOMNode *aNode, + PRInt32 aOffset); + + virtual ~SplitElementTxn(); + + virtual nsresult Do(void); + + virtual nsresult Undo(void); + + virtual nsresult Redo(void); + + virtual nsresult GetIsTransient(PRBool *aIsTransient); + + virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction); + + virtual nsresult Write(nsIOutputStream *aOutputStream); + + virtual nsresult GetUndoString(nsString **aString); + + virtual nsresult GetRedoString(nsString **aString); + +protected: + + /** the element to operate upon */ + nsIDOMNode *mNode; + + /** the offset into mElement where the children of mElement are split.
+ * mOffset is the index of the last child in the left node. + * -1 means the new node gets no children. + */ + PRInt32 mOffset; + + /** the element we create when splitting mElement */ + nsIDOMNode *mNewNode; + nsIDOMNode *mParent; + +}; + +#endif diff --git a/mozilla/editor/core/editorInterfaces.cpp b/mozilla/editor/core/editorInterfaces.cpp index 8e002e24739..c3a037af361 100644 --- a/mozilla/editor/core/editorInterfaces.cpp +++ b/mozilla/editor/core/editorInterfaces.cpp @@ -22,6 +22,7 @@ #include "InsertTextTxn.h" #include "DeleteTextTxn.h" #include "CreateElementTxn.h" +#include "SplitElementTxn.h" #include "nsIDOMDocument.h" #include "nsIDOMElement.h" @@ -247,7 +248,7 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces // XXX: please please please get these mappings from an external source! switch (keyCode) { - // hard-coded undo + // XXX: hard-coded undo case nsIDOMEvent::VK_Z: if (PR_TRUE==ctrlKey) { @@ -257,7 +258,7 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces aProcessed=PR_TRUE; break; - // hard-coded redo + // XXX: hard-coded redo case nsIDOMEvent::VK_Y: if (PR_TRUE==ctrlKey) { @@ -267,6 +268,27 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces aProcessed=PR_TRUE; break; + // hard-coded split node test: works on first

in the document + case nsIDOMEvent::VK_S: + { + nsString pTag("P"); + nsCOMPtr currentNode; + nsCOMPtr element; + if (NS_SUCCEEDED(mEditor->GetFirstNodeOfType(nsnull, pTag, getter_AddRefs(currentNode)))) + { + SplitElementTxn *txn; + if (PR_FALSE==isShift) // split the element so there are 0 children in the first half + txn = new SplitElementTxn(mEditor, currentNode, -1); + else // split the element so there are 0 children in the first half + txn = new SplitElementTxn(mEditor, currentNode, 1); + mEditor->ExecuteTransaction(txn); + } + } + aProcessed=PR_TRUE; + break; + + + //XXX: test for change and remove attribute, hard-coded to be width on first table in doc case nsIDOMEvent::VK_TAB: { //XXX: should be from a factory diff --git a/mozilla/editor/core/makefile.win b/mozilla/editor/core/makefile.win index 4abcc9606e7..df301fd471b 100644 --- a/mozilla/editor/core/makefile.win +++ b/mozilla/editor/core/makefile.win @@ -29,6 +29,7 @@ CPPSRCS = \ InsertTextTxn.cpp \ DeleteTextTxn.cpp \ CreateElementTxn.cpp \ + SplitElementTxn.cpp \ $(NULL) CPP_OBJS = \ @@ -40,6 +41,7 @@ CPP_OBJS = \ .\$(OBJDIR)\InsertTextTxn.obj \ .\$(OBJDIR)\DeleteTextTxn.obj \ .\$(OBJDIR)\CreateElementTxn.obj \ + .\$(OBJDIR)\SplitElementTxn.obj \ $(NULL) MODULE=editor diff --git a/mozilla/editor/libeditor/base/SplitElementTxn.cpp b/mozilla/editor/libeditor/base/SplitElementTxn.cpp new file mode 100644 index 00000000000..a0ab3288fcd --- /dev/null +++ b/mozilla/editor/libeditor/base/SplitElementTxn.cpp @@ -0,0 +1,136 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "SplitElementTxn.h" +#include "editor.h" +#include "nsIDOMNode.h" +#include "nsIDOMNodeList.h" +#include "nsIDOMDocument.h" +#include "nsIDOMElement.h" + +// note that aEditor is not refcounted +SplitElementTxn::SplitElementTxn(nsEditor *aEditor, + nsIDOMNode *aNode, + PRInt32 aOffset) + : EditTxn(aEditor) +{ + mNode = aNode; + NS_ADDREF(mNode); + mOffset = aOffset; + mNewNode = nsnull; + mParent = nsnull; +} + +SplitElementTxn::~SplitElementTxn() +{ + NS_IF_RELEASE(mNode); + NS_IF_RELEASE(mNewNode); + NS_IF_RELEASE(mParent); +} + +nsresult SplitElementTxn::Do(void) +{ + // create a new node + nsresult result = mNode->CloneNode(PR_FALSE, &mNewNode); + NS_ASSERTION(((NS_SUCCEEDED(result)) && (nsnull!=mNewNode)), "could not create element."); + + if ((NS_SUCCEEDED(result)) && (nsnull!=mNewNode)) + { + // get the parent node + result = mNode->GetParentNode(&mParent); + // 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)); + } + } + } + } + } + } + } + } + return result; +} + +nsresult SplitElementTxn::Undo(void) +{ + return NS_OK; +} + +nsresult SplitElementTxn::Redo(void) +{ + return NS_OK; +} + +nsresult SplitElementTxn::GetIsTransient(PRBool *aIsTransient) +{ + if (nsnull!=aIsTransient) + *aIsTransient = PR_FALSE; + return NS_OK; +} + +nsresult SplitElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction) +{ + return NS_OK; +} + +nsresult SplitElementTxn::Write(nsIOutputStream *aOutputStream) +{ + return NS_OK; +} + +nsresult SplitElementTxn::GetUndoString(nsString **aString) +{ + if (nsnull!=aString) + { + **aString="Join Element"; + } + return NS_OK; +} + +nsresult SplitElementTxn::GetRedoString(nsString **aString) +{ + if (nsnull!=aString) + { + **aString="Split Element"; + } + return NS_OK; +} diff --git a/mozilla/editor/libeditor/base/SplitElementTxn.h b/mozilla/editor/libeditor/base/SplitElementTxn.h new file mode 100644 index 00000000000..8fb19df1fb6 --- /dev/null +++ b/mozilla/editor/libeditor/base/SplitElementTxn.h @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef SplitElementTxn_h__ +#define SplitElementTxn_h__ + +#include "EditTxn.h" + +class nsIDOMNode; +class nsIDOMElement; +class nsIDOMDocument; + +/** + * A transaction that splits an element E into two identical nodes, E1 and E2 + * with the children of E divided between E1 and E2. + */ +class SplitElementTxn : public EditTxn +{ +public: + + SplitElementTxn(nsEditor *aEditor, + nsIDOMNode *aNode, + PRInt32 aOffset); + + virtual ~SplitElementTxn(); + + virtual nsresult Do(void); + + virtual nsresult Undo(void); + + virtual nsresult Redo(void); + + virtual nsresult GetIsTransient(PRBool *aIsTransient); + + virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction); + + virtual nsresult Write(nsIOutputStream *aOutputStream); + + virtual nsresult GetUndoString(nsString **aString); + + virtual nsresult GetRedoString(nsString **aString); + +protected: + + /** the element to operate upon */ + nsIDOMNode *mNode; + + /** the offset into mElement where the children of mElement are split.
+ * mOffset is the index of the last child in the left node. + * -1 means the new node gets no children. + */ + PRInt32 mOffset; + + /** the element we create when splitting mElement */ + nsIDOMNode *mNewNode; + nsIDOMNode *mParent; + +}; + +#endif