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
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
{
30 JoinNodeTransaction(HTMLEditor
& aHTMLEditor
, nsIContent
& aLeftContent
,
31 nsIContent
& aRightContent
);
35 * Creates a join node transaction. This returns nullptr if cannot join the
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
);
47 * CanDoIt() returns true if there are enough members and can join or
48 * restore the nodes. Otherwise, false.
52 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(JoinNodeTransaction
,
54 NS_IMETHOD
QueryInterface(REFNSIID aIID
, void** aInstancePtr
) override
;
56 NS_DECL_EDITTRANSACTIONBASE
57 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(JoinNodeTransaction
)
59 MOZ_CAN_RUN_SCRIPT NS_IMETHOD
RedoTransaction() override
;
61 friend std::ostream
& operator<<(std::ostream
& aStream
,
62 const JoinNodeTransaction
& aTransaction
);
65 RefPtr
<HTMLEditor
> mHTMLEditor
;
67 // The nodes to operate upon. After the merge, mRightContent remains and
68 // mLeftContent is removed from the content tree.
69 nsCOMPtr
<nsIContent
> mLeftContent
;
70 nsCOMPtr
<nsIContent
> mRightContent
;
72 // The offset into mNode where the children of mElement are split (for
73 // undo). mOffset is the index of the first child in the right node. -1
74 // means the left node had no children.
77 // The parent node containing mLeftContent and mRightContent.
78 nsCOMPtr
<nsINode
> mParentNode
;
81 } // namespace mozilla
83 #endif // #ifndef JoinNodeTransaction_h