Bug 1712849 [wpt PR 29110] - Keep 3D points in a quad coplanar when clamping them...
[gecko.git] / editor / libeditor / InsertNodeTransaction.h
blob7dbb3d7b8bd6e6268a3af0f1482a9b9c2ba8da64
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 InsertNodeTransaction_h
7 #define InsertNodeTransaction_h
9 #include "mozilla/EditTransactionBase.h" // for EditTransactionBase, etc.
10 #include "mozilla/EditorDOMPoint.h" // for EditorDOMPoint
11 #include "nsCOMPtr.h" // for nsCOMPtr
12 #include "nsCycleCollectionParticipant.h"
13 #include "nsIContent.h" // for nsIContent
14 #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED
16 namespace mozilla {
18 class EditorBase;
20 /**
21 * A transaction that inserts a single element
23 class InsertNodeTransaction final : public EditTransactionBase {
24 protected:
25 template <typename PT, typename CT>
26 InsertNodeTransaction(EditorBase& aEditorBase, nsIContent& aContentToInsert,
27 const EditorDOMPointBase<PT, CT>& aPointToInsert);
29 public:
30 /**
31 * Create a transaction for inserting aContentToInsert before the child
32 * at aPointToInsert.
34 * @param aEditorBase The editor which manages the transaction.
35 * @param aContentToInsert The node to be inserted.
36 * @param aPointToInsert The insertion point of aContentToInsert.
37 * If this refers end of the container, the
38 * transaction will append the node to the
39 * container. Otherwise, will insert the node
40 * before child node referred by this.
41 * @return A InsertNodeTranaction which was initialized
42 * with the arguments.
44 template <typename PT, typename CT>
45 static already_AddRefed<InsertNodeTransaction> Create(
46 EditorBase& aEditorBase, nsIContent& aContentToInsert,
47 const EditorDOMPointBase<PT, CT>& aPointToInsert);
49 NS_DECL_ISUPPORTS_INHERITED
50 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InsertNodeTransaction,
51 EditTransactionBase)
53 NS_DECL_EDITTRANSACTIONBASE
54 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(InsertNodeTransaction)
56 MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override;
58 friend std::ostream& operator<<(std::ostream& aStream,
59 const InsertNodeTransaction& aTransaction);
61 protected:
62 virtual ~InsertNodeTransaction() = default;
64 // The element to insert.
65 nsCOMPtr<nsIContent> mContentToInsert;
67 // The DOM point we will insert mContentToInsert.
68 EditorDOMPoint mPointToInsert;
70 // The editor for this transaction.
71 RefPtr<EditorBase> mEditorBase;
74 } // namespace mozilla
76 #endif // #ifndef InsertNodeTransaction_h