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/. */ 5 6 #ifndef DeleteNodeTransaction_h 7 #define DeleteNodeTransaction_h 8 9 #include "mozilla/EditTransactionBase.h" 10 #include "nsCOMPtr.h" 11 #include "nsCycleCollectionParticipant.h" 12 #include "nsIContent.h" 13 #include "nsINode.h" 14 #include "nsISupportsImpl.h" 15 #include "nscore.h" 16 17 namespace mozilla { 18 19 class EditorBase; 20 21 /** 22 * A transaction that deletes a single element 23 */ 24 class DeleteNodeTransaction final : public EditTransactionBase { 25 protected: 26 DeleteNodeTransaction(EditorBase& aEditorBase, nsIContent& aContentToDelete); 27 28 public: 29 /** 30 * Creates a delete node transaction instance. This returns nullptr if 31 * it cannot remove the node from its parent. 32 * 33 * @param aEditorBase The editor. 34 * @param aContentToDelete The node to be removed from the DOM tree. 35 */ 36 static already_AddRefed<DeleteNodeTransaction> MaybeCreate( 37 EditorBase& aEditorBase, nsIContent& aContentToDelete); 38 39 /** 40 * CanDoIt() returns true if there are enough members and can modify the 41 * parent. Otherwise, false. 42 */ 43 bool CanDoIt() const; 44 45 NS_DECL_ISUPPORTS_INHERITED 46 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteNodeTransaction, 47 EditTransactionBase) 48 49 NS_DECL_EDITTRANSACTIONBASE 50 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(DeleteNodeTransaction) 51 52 MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override; 53 GetContent()54 nsIContent* GetContent() const { return mContentToDelete; } 55 56 friend std::ostream& operator<<(std::ostream& aStream, 57 const DeleteNodeTransaction& aTransaction); 58 59 protected: 60 virtual ~DeleteNodeTransaction() = default; 61 62 // The editor for this transaction. 63 RefPtr<EditorBase> mEditorBase; 64 65 // The element to delete. 66 nsCOMPtr<nsIContent> mContentToDelete; 67 68 // Parent of node to delete. 69 nsCOMPtr<nsINode> mParentNode; 70 71 // Next sibling to remember for undo/redo purposes. 72 nsCOMPtr<nsIContent> mRefContent; 73 }; 74 75 } // namespace mozilla 76 77 #endif // #ifndef DeleteNodeTransaction_h 78