Bug 1712849 [wpt PR 29110] - Keep 3D points in a quad coplanar when clamping them...
[gecko.git] / editor / libeditor / JoinNodeTransaction.h
blob300b4b7e2d9957d5e8599b9af3da20dc56ef55f0
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 MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override;
61 friend std::ostream& operator<<(std::ostream& aStream,
62 const JoinNodeTransaction& aTransaction);
64 protected:
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.
75 uint32_t mOffset;
77 // The parent node containing mLeftContent and mRightContent.
78 nsCOMPtr<nsINode> mParentNode;
81 } // namespace mozilla
83 #endif // #ifndef JoinNodeTransaction_h