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"
18 * A transaction that creates a new node in the content tree.
27 class CreateElementTransaction final
: public EditTransactionBase
{
29 template <typename PT
, typename CT
>
30 CreateElementTransaction(EditorBase
& aEditorBase
, nsAtom
& aTag
,
31 const EditorDOMPointBase
<PT
, CT
>& aPointToInsert
);
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
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
,
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
; }
62 virtual ~CreateElementTransaction() = default;
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.
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