Bug 1772588 [wpt PR 34302] - [wpt] Add test for block-in-inline offsetParent., a...
[gecko.git] / editor / libeditor / DeleteNodeTransaction.h
blobdcae9f46cb9f15079de6c1e8a7ddf7ae9f91009a
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"
13 #include "nsCOMPtr.h"
14 #include "nsCycleCollectionParticipant.h"
15 #include "nsIContent.h"
16 #include "nsINode.h"
17 #include "nsISupportsImpl.h"
18 #include "nscore.h"
20 namespace mozilla {
22 /**
23 * A transaction that deletes a single element
25 class DeleteNodeTransaction final : public EditTransactionBase {
26 protected:
27 DeleteNodeTransaction(EditorBase& aEditorBase, nsIContent& aContentToDelete);
29 public:
30 /**
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);
40 /**
41 * CanDoIt() returns true if there are enough members and can modify the
42 * parent. Otherwise, false.
44 bool CanDoIt() const;
46 NS_DECL_ISUPPORTS_INHERITED
47 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteNodeTransaction,
48 EditTransactionBase)
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);
60 protected:
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