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 "DeleteContentTransactionBase.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 DeleteContentTransactionBase
{
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
,
48 DeleteContentTransactionBase
)
50 NS_DECL_EDITTRANSACTIONBASE
51 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(DeleteNodeTransaction
)
53 MOZ_CAN_RUN_SCRIPT NS_IMETHOD
RedoTransaction() final
;
55 EditorDOMPoint
SuggestPointToPutCaret() const final
;
57 nsIContent
* GetContent() const { return mContentToDelete
; }
59 friend std::ostream
& operator<<(std::ostream
& aStream
,
60 const DeleteNodeTransaction
& aTransaction
);
63 virtual ~DeleteNodeTransaction() = default;
65 // The element to delete.
66 nsCOMPtr
<nsIContent
> mContentToDelete
;
68 // Parent of node to delete.
69 nsCOMPtr
<nsINode
> mParentNode
;
71 // Next sibling to remember for undo/redo purposes.
72 nsCOMPtr
<nsIContent
> mRefContent
;
75 } // namespace mozilla
77 #endif // #ifndef DeleteNodeTransaction_h