|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef SplitElementTxn_h__ |
|
7 #define SplitElementTxn_h__ |
|
8 |
|
9 #include "EditTxn.h" // for EditTxn, NS_DECL_EDITTXN |
|
10 #include "nsCOMPtr.h" // for nsCOMPtr |
|
11 #include "nsCycleCollectionParticipant.h" |
|
12 #include "nsIDOMNode.h" // for nsIDOMNode |
|
13 #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED |
|
14 #include "nscore.h" // for NS_IMETHOD |
|
15 |
|
16 class nsEditor; |
|
17 |
|
18 /** |
|
19 * A transaction that splits an element E into two identical nodes, E1 and E2 |
|
20 * with the children of E divided between E1 and E2. |
|
21 */ |
|
22 class SplitElementTxn : public EditTxn |
|
23 { |
|
24 public: |
|
25 /** initialize the transaction. |
|
26 * @param aEditor the provider of core editing operations |
|
27 * @param aNode the node to split |
|
28 * @param aOffset the location within aNode to do the split. |
|
29 * aOffset may refer to children of aNode, or content of aNode. |
|
30 * The left node will have child|content 0..aOffset-1. |
|
31 */ |
|
32 NS_IMETHOD Init (nsEditor *aEditor, |
|
33 nsIDOMNode *aNode, |
|
34 int32_t aOffset); |
|
35 |
|
36 SplitElementTxn(); |
|
37 |
|
38 NS_DECL_ISUPPORTS_INHERITED |
|
39 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitElementTxn, EditTxn) |
|
40 |
|
41 NS_DECL_EDITTXN |
|
42 |
|
43 NS_IMETHOD RedoTransaction(void); |
|
44 |
|
45 NS_IMETHOD GetNewNode(nsIDOMNode **aNewNode); |
|
46 |
|
47 protected: |
|
48 |
|
49 /** the element to operate upon */ |
|
50 nsCOMPtr<nsIDOMNode> mExistingRightNode; |
|
51 |
|
52 /** the offset into mElement where the children of mElement are split.<BR> |
|
53 * mOffset is the index of the first child in the right node. |
|
54 * -1 means the new node gets no children. |
|
55 */ |
|
56 int32_t mOffset; |
|
57 |
|
58 /** the element we create when splitting mElement */ |
|
59 nsCOMPtr<nsIDOMNode> mNewLeftNode; |
|
60 |
|
61 /** the parent shared by mExistingRightNode and mNewLeftNode */ |
|
62 nsCOMPtr<nsIDOMNode> mParent; |
|
63 nsEditor* mEditor; |
|
64 }; |
|
65 |
|
66 #endif |