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 DeleteNodeTransaction_h
7 #define DeleteNodeTransaction_h
9 #include "EditTransactionBase.h"
11 #include "EditorForwards.h"
14 #include "nsCycleCollectionParticipant.h"
15 #include "nsIContent.h"
17 #include "nsISupportsImpl.h"
23 * A transaction that deletes a single element
25 class DeleteNodeTransaction final
: public EditTransactionBase
{
27 DeleteNodeTransaction(EditorBase
& aEditorBase
, nsIContent
& aContentToDelete
);
31 * Creates a delete node transaction instance. This returns nullptr if
32 * it cannot remove the node from its parent.
34 * @param aEditorBase The editor.
35 * @param aContentToDelete The node to be removed from the DOM tree.
37 static already_AddRefed
<DeleteNodeTransaction
> MaybeCreate(
38 EditorBase
& aEditorBase
, nsIContent
& aContentToDelete
);
41 * CanDoIt() returns true if there are enough members and can modify the
42 * parent. Otherwise, false.
46 NS_DECL_ISUPPORTS_INHERITED
47 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteNodeTransaction
,
50 NS_DECL_EDITTRANSACTIONBASE
51 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(DeleteNodeTransaction
)
53 MOZ_CAN_RUN_SCRIPT NS_IMETHOD
RedoTransaction() override
;
55 nsIContent
* GetContent() const { return mContentToDelete
; }
57 friend std::ostream
& operator<<(std::ostream
& aStream
,
58 const DeleteNodeTransaction
& aTransaction
);
61 virtual ~DeleteNodeTransaction() = default;
63 // The editor for this transaction.
64 RefPtr
<EditorBase
> mEditorBase
;
66 // The element to delete.
67 nsCOMPtr
<nsIContent
> mContentToDelete
;
69 // Parent of node to delete.
70 nsCOMPtr
<nsINode
> mParentNode
;
72 // Next sibling to remember for undo/redo purposes.
73 nsCOMPtr
<nsIContent
> mRefContent
;
76 } // namespace mozilla
78 #endif // #ifndef DeleteNodeTransaction_h