PlaceholderTransaction.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 PlaceholderTransaction_h
  6. #define PlaceholderTransaction_h
  7. #include "EditAggregateTransaction.h"
  8. #include "mozilla/EditorUtils.h"
  9. #include "mozilla/UniquePtr.h"
  10. #include "mozilla/WeakPtr.h"
  11. #include "nsIAbsorbingTransaction.h"
  12. #include "nsIDOMNode.h"
  13. #include "nsCOMPtr.h"
  14. #include "nsWeakPtr.h"
  15. #include "nsWeakReference.h"
  16. namespace mozilla {
  17. class CompositionTransaction;
  18. /**
  19. * An aggregate transaction that knows how to absorb all subsequent
  20. * transactions with the same name. This transaction does not "Do" anything.
  21. * But it absorbs other transactions via merge, and can undo/redo the
  22. * transactions it has absorbed.
  23. */
  24. class PlaceholderTransaction final
  25. : public EditAggregateTransaction
  26. , public nsIAbsorbingTransaction
  27. , public SupportsWeakPtr<PlaceholderTransaction>
  28. {
  29. public:
  30. MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PlaceholderTransaction)
  31. NS_DECL_ISUPPORTS_INHERITED
  32. PlaceholderTransaction(EditorBase& aEditorBase, nsIAtom* aName,
  33. UniquePtr<SelectionState> aSelState);
  34. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTransaction,
  35. EditAggregateTransaction)
  36. // ------------ EditAggregateTransaction -----------------------
  37. NS_DECL_EDITTRANSACTIONBASE
  38. NS_IMETHOD RedoTransaction() override;
  39. NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override;
  40. // ------------ nsIAbsorbingTransaction -----------------------
  41. NS_IMETHOD GetTxnName(nsIAtom** aName) override;
  42. NS_IMETHOD StartSelectionEquals(SelectionState* aSelState,
  43. bool* aResult) override;
  44. NS_IMETHOD EndPlaceHolderBatch() override;
  45. NS_IMETHOD ForwardEndBatchTo(
  46. nsIAbsorbingTransaction* aForwardingAddress) override;
  47. NS_IMETHOD Commit() override;
  48. NS_IMETHOD_(PlaceholderTransaction*) AsPlaceholderTransaction() override
  49. {
  50. return this;
  51. }
  52. nsresult RememberEndingSelection();
  53. protected:
  54. virtual ~PlaceholderTransaction();
  55. // Do we auto absorb any and all transaction?
  56. bool mAbsorb;
  57. nsWeakPtr mForwarding;
  58. // First IME txn in this placeholder - used for IME merging.
  59. mozilla::CompositionTransaction* mCompositionTransaction;
  60. // Do we stop auto absorbing any matching placeholder transactions?
  61. bool mCommitted;
  62. // These next two members store the state of the selection in a safe way.
  63. // Selection at the start of the transaction is stored, as is the selection
  64. // at the end. This is so that UndoTransaction() and RedoTransaction() can
  65. // restore the selection properly.
  66. // Use a pointer because this is constructed before we exist.
  67. UniquePtr<SelectionState> mStartSel;
  68. SelectionState mEndSel;
  69. // The editor for this transaction.
  70. RefPtr<EditorBase> mEditorBase;
  71. };
  72. } // namespace mozilla
  73. #endif // #ifndef PlaceholderTransaction_h