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 DeleteTextTransaction_h 7 #define DeleteTextTransaction_h 8 9 #include "mozilla/EditTransactionBase.h" 10 #include "nsCOMPtr.h" 11 #include "nsCycleCollectionParticipant.h" 12 #include "nsGenericDOMDataNode.h" 13 #include "nsID.h" 14 #include "nsString.h" 15 #include "nscore.h" 16 17 namespace mozilla { 18 19 class EditorBase; 20 class RangeUpdater; 21 22 /** 23 * A transaction that removes text from a content node. 24 */ 25 class DeleteTextTransaction final : public EditTransactionBase 26 { 27 public: 28 /** 29 * Initialize the transaction. 30 * @param aEditorBase The provider of basic editing operations. 31 * @param aElement The content node to remove text from. 32 * @param aOffset The location in aElement to begin the deletion. 33 * @param aNumCharsToDelete The number of characters to delete. Not the 34 * number of bytes! 35 */ 36 DeleteTextTransaction(EditorBase& aEditorBase, 37 nsGenericDOMDataNode& aCharData, 38 uint32_t aOffset, 39 uint32_t aNumCharsToDelete, 40 RangeUpdater* aRangeUpdater); 41 42 nsresult Init(); 43 44 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteTextTransaction, 45 EditTransactionBase) 46 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override; 47 48 NS_DECL_EDITTRANSACTIONBASE 49 GetOffset()50 uint32_t GetOffset() { return mOffset; } 51 GetNumCharsToDelete()52 uint32_t GetNumCharsToDelete() { return mNumCharsToDelete; } 53 54 protected: 55 // The provider of basic editing operations. 56 EditorBase& mEditorBase; 57 58 // The CharacterData node to operate upon. 59 RefPtr<nsGenericDOMDataNode> mCharData; 60 61 // The offset into mCharData where the deletion is to take place. 62 uint32_t mOffset; 63 64 // The number of characters to delete. 65 uint32_t mNumCharsToDelete; 66 67 // The text that was deleted. 68 nsString mDeletedText; 69 70 // Range updater object. 71 RangeUpdater* mRangeUpdater; 72 }; 73 74 } // namespace mozilla 75 76 #endif // #ifndef DeleteTextTransaction_h 77