Bug 1669129 - [devtools] Enable devtools.overflow.debugging.enabled. r=jdescottes
[gecko.git] / editor / libeditor / JoinNodeTransaction.h
blobdb86b91411d92d7395d07d415f05d3fbb2c71659
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/. */
6 #ifndef JoinNodeTransaction_h
7 #define JoinNodeTransaction_h
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
15 class nsIContent;
16 class nsINode;
18 namespace mozilla {
20 class HTMLEditor;
22 /**
23 * A transaction that joins two nodes E1 (left node) and E2 (right node) into a
24 * single node E. The children of E are the children of E1 followed by the
25 * children of E2. After DoTransaction() and RedoTransaction(), E1 is removed
26 * from the content tree and E2 remains.
28 class JoinNodeTransaction final : public EditTransactionBase {
29 protected:
30 JoinNodeTransaction(HTMLEditor& aHTMLEditor, nsIContent& aLeftContent,
31 nsIContent& aRightContent);
33 public:
34 /**
35 * Creates a join node transaction. This returns nullptr if cannot join the
36 * nodes.
38 * @param aHTMLEditor The provider of core editing operations.
39 * @param aLeftContent The first of two nodes to join.
40 * @param aRightContent The second of two nodes to join.
42 static already_AddRefed<JoinNodeTransaction> MaybeCreate(
43 HTMLEditor& aHTMLEditor, nsIContent& aLeftContent,
44 nsIContent& aRightContent);
46 /**
47 * CanDoIt() returns true if there are enough members and can join or
48 * restore the nodes. Otherwise, false.
50 bool CanDoIt() const;
52 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(JoinNodeTransaction,
53 EditTransactionBase)
54 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
56 NS_DECL_EDITTRANSACTIONBASE
57 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(JoinNodeTransaction)
59 protected:
60 RefPtr<HTMLEditor> mHTMLEditor;
62 // The nodes to operate upon. After the merge, mRightContent remains and
63 // mLeftContent is removed from the content tree.
64 nsCOMPtr<nsIContent> mLeftContent;
65 nsCOMPtr<nsIContent> mRightContent;
67 // The offset into mNode where the children of mElement are split (for
68 // undo). mOffset is the index of the first child in the right node. -1
69 // means the left node had no children.
70 uint32_t mOffset;
72 // The parent node containing mLeftContent and mRightContent.
73 nsCOMPtr<nsINode> mParentNode;
76 } // namespace mozilla
78 #endif // #ifndef JoinNodeTransaction_h