Bug 1686495 [wpt PR 27132] - Add tests for proposed WebDriver Shadow DOM support...
[gecko.git] / editor / libeditor / InsertNodeTransaction.h
blob7a843ed589f8dcb03cafa4be4513532d4084337a
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 protected:
57 virtual ~InsertNodeTransaction() = default;
59 // The element to insert.
60 nsCOMPtr<nsIContent> mContentToInsert;
62 // The DOM point we will insert mContentToInsert.
63 EditorDOMPoint mPointToInsert;
65 // The editor for this transaction.
66 RefPtr<EditorBase> mEditorBase;
69 } // namespace mozilla
71 #endif // #ifndef InsertNodeTransaction_h