Line data Source code
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 JoinNodeTransaction_h
7 : #define JoinNodeTransaction_h
8 :
9 : #include "mozilla/EditTransactionBase.h" // for EditTransactionBase, etc.
10 : #include "nsCOMPtr.h" // for nsCOMPtr
11 : #include "nsCycleCollectionParticipant.h"
12 : #include "nsID.h" // for REFNSIID
13 : #include "nscore.h" // for NS_IMETHOD
14 :
15 : class nsINode;
16 :
17 : namespace mozilla {
18 :
19 : class EditorBase;
20 :
21 : /**
22 : * A transaction that joins two nodes E1 (left node) and E2 (right node) into a
23 : * single node E. The children of E are the children of E1 followed by the
24 : * children of E2. After DoTransaction() and RedoTransaction(), E1 is removed
25 : * from the content tree and E2 remains.
26 : */
27 0 : class JoinNodeTransaction final : public EditTransactionBase
28 : {
29 : public:
30 : /**
31 : * @param aEditorBase The provider of core editing operations.
32 : * @param aLeftNode The first of two nodes to join.
33 : * @param aRightNode The second of two nodes to join.
34 : */
35 : JoinNodeTransaction(EditorBase& aEditorBase,
36 : nsINode& aLeftNode, nsINode& aRightNode);
37 :
38 : /**
39 : * CanDoIt() returns true if there are enough members and can join or
40 : * restore the nodes. Otherwise, false.
41 : */
42 : bool CanDoIt() const;
43 :
44 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(JoinNodeTransaction,
45 : EditTransactionBase)
46 : NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
47 :
48 : NS_DECL_EDITTRANSACTIONBASE
49 :
50 : protected:
51 : RefPtr<EditorBase> mEditorBase;
52 :
53 : // The nodes to operate upon. After the merge, mRightNode remains and
54 : // mLeftNode is removed from the content tree.
55 : nsCOMPtr<nsINode> mLeftNode;
56 : nsCOMPtr<nsINode> mRightNode;
57 :
58 : // The offset into mNode where the children of mElement are split (for
59 : // undo). mOffset is the index of the first child in the right node. -1
60 : // means the left node had no children.
61 : uint32_t mOffset;
62 :
63 : // The parent node containing mLeftNode and mRightNode.
64 : nsCOMPtr<nsINode> mParent;
65 : };
66 :
67 : } // namespace mozilla
68 :
69 : #endif // #ifndef JoinNodeTransaction_h
|