Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / editor / libeditor / InsertNodeTransaction.h
blob671b3a7c1b1628ecd92cf7b0b1cd1a71e53c35ea
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 "EditTransactionBase.h" // for EditTransactionBase, etc.
11 #include "EditorDOMPoint.h" // for EditorDOMPoint
12 #include "EditorForwards.h"
14 #include "nsCOMPtr.h" // for nsCOMPtr
15 #include "nsCycleCollectionParticipant.h"
16 #include "nsIContent.h" // for nsIContent
17 #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED
19 namespace mozilla {
21 class EditorBase;
23 /**
24 * A transaction that inserts a single element
26 class InsertNodeTransaction final : public EditTransactionBase {
27 protected:
28 template <typename PT, typename CT>
29 InsertNodeTransaction(EditorBase& aEditorBase, nsIContent& aContentToInsert,
30 const EditorDOMPointBase<PT, CT>& aPointToInsert);
32 public:
33 /**
34 * Create a transaction for inserting aContentToInsert before the child
35 * at aPointToInsert.
37 * @param aEditorBase The editor which manages the transaction.
38 * @param aContentToInsert The node to be inserted.
39 * @param aPointToInsert The insertion point of aContentToInsert.
40 * If this refers end of the container, the
41 * transaction will append the node to the
42 * container. Otherwise, will insert the node
43 * before child node referred by this.
44 * @return A InsertNodeTranaction which was initialized
45 * with the arguments.
47 template <typename PT, typename CT>
48 static already_AddRefed<InsertNodeTransaction> Create(
49 EditorBase& aEditorBase, nsIContent& aContentToInsert,
50 const EditorDOMPointBase<PT, CT>& aPointToInsert);
52 NS_DECL_ISUPPORTS_INHERITED
53 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InsertNodeTransaction,
54 EditTransactionBase)
56 NS_DECL_EDITTRANSACTIONBASE
57 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(InsertNodeTransaction)
59 MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override;
61 /**
62 * SuggestPointToPutCaret() suggests a point after doing or redoing the
63 * transaction.
65 template <typename EditorDOMPointType>
66 EditorDOMPointType SuggestPointToPutCaret() const {
67 if (MOZ_UNLIKELY(!mPointToInsert.IsSet() || !mContentToInsert)) {
68 return EditorDOMPointType();
70 return EditorDOMPointType::After(mContentToInsert);
73 friend std::ostream& operator<<(std::ostream& aStream,
74 const InsertNodeTransaction& aTransaction);
76 protected:
77 virtual ~InsertNodeTransaction() = default;
79 // The element to insert.
80 nsCOMPtr<nsIContent> mContentToInsert;
82 // The DOM point we will insert mContentToInsert.
83 EditorDOMPoint mPointToInsert;
85 // The editor for this transaction.
86 RefPtr<EditorBase> mEditorBase;
89 } // namespace mozilla
91 #endif // #ifndef InsertNodeTransaction_h