Bug 1686495 [wpt PR 27132] - Add tests for proposed WebDriver Shadow DOM support...
[gecko.git] / editor / libeditor / CreateElementTransaction.h
blobfc87f500b1dcf4bc957bcc945074ec7c224d25e6
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 CreateElementTransaction_h
7 #define CreateElementTransaction_h
9 #include "mozilla/EditorDOMPoint.h"
10 #include "mozilla/EditTransactionBase.h"
11 #include "mozilla/RefPtr.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "nsISupportsImpl.h"
15 class nsAtom;
17 /**
18 * A transaction that creates a new node in the content tree.
20 namespace mozilla {
21 namespace dom {
22 class Element;
25 class EditorBase;
27 class CreateElementTransaction final : public EditTransactionBase {
28 protected:
29 template <typename PT, typename CT>
30 CreateElementTransaction(EditorBase& aEditorBase, nsAtom& aTag,
31 const EditorDOMPointBase<PT, CT>& aPointToInsert);
33 public:
34 /**
35 * Create a transaction for creating a new child node of the container of
36 * aPointToInsert of type aTag.
38 * @param aEditorBase The editor which manages the transaction.
39 * @param aTag The tag (P, HR, TABLE, etc.) for the new element.
40 * @param aPointToInsert The new node will be inserted before the child at
41 * aPointToInsert. If this refers end of the container
42 * or after, the new node will be appended to the
43 * container.
45 template <typename PT, typename CT>
46 static already_AddRefed<CreateElementTransaction> Create(
47 EditorBase& aEditorBase, nsAtom& aTag,
48 const EditorDOMPointBase<PT, CT>& aPointToInsert);
50 NS_DECL_ISUPPORTS_INHERITED
51 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CreateElementTransaction,
52 EditTransactionBase)
54 NS_DECL_EDITTRANSACTIONBASE
55 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(CreateElementTransaction)
57 MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override;
59 dom::Element* GetNewElement() const { return mNewElement; }
61 protected:
62 virtual ~CreateElementTransaction() = default;
64 /**
65 * InsertNewNode() inserts mNewNode before the child node at mPointToInsert.
67 MOZ_CAN_RUN_SCRIPT void InsertNewNode(ErrorResult& aError);
69 // The document into which the new node will be inserted.
70 RefPtr<EditorBase> mEditorBase;
72 // The tag (mapping to object type) for the new element.
73 RefPtr<nsAtom> mTag;
75 // The DOM point we will insert mNewNode.
76 EditorDOMPoint mPointToInsert;
78 // The new node to insert.
79 RefPtr<dom::Element> mNewElement;
82 } // namespace mozilla
84 #endif // #ifndef CreateElementTransaction_h