DeleteTextTransaction.h 2.2 KB

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