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 mozilla_TransactionManager_h
7 #define mozilla_TransactionManager_h
9 #include "mozilla/TransactionStack.h"
11 #include "nsCOMArray.h"
13 #include "nsCycleCollectionParticipant.h"
14 #include "nsISupportsImpl.h"
15 #include "nsITransactionManager.h"
16 #include "nsWeakReference.h"
20 class nsITransactionListener
;
24 class TransactionManager final
: public nsITransactionManager
,
25 public nsSupportsWeakReference
{
27 explicit TransactionManager(int32_t aMaxTransactionCount
= -1);
29 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
30 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(TransactionManager
,
31 nsITransactionManager
)
33 NS_DECL_NSITRANSACTIONMANAGER
35 already_AddRefed
<nsITransaction
> PeekUndoStack();
36 already_AddRefed
<nsITransaction
> PeekRedoStack();
41 size_t NumberOfUndoItems() const { return mUndoStack
.GetSize(); }
42 size_t NumberOfRedoItems() const { return mRedoStack
.GetSize(); }
44 int32_t NumberOfMaximumTransactions() const { return mMaxTransactionCount
; }
46 bool EnableUndoRedo(int32_t aMaxTransactionCount
= -1);
47 bool DisableUndoRedo() { return EnableUndoRedo(0); }
48 bool ClearUndoRedo() {
49 if (NS_WARN_IF(!mDoStack
.IsEmpty())) {
57 bool AddTransactionListener(nsITransactionListener
& aListener
) {
58 // XXX Shouldn't we check if aListener has already been in mListeners?
59 return mListeners
.AppendObject(&aListener
);
61 bool RemoveTransactionListener(nsITransactionListener
& aListener
) {
62 return mListeners
.RemoveObject(&aListener
);
65 nsresult
WillDoNotify(nsITransaction
* aTransaction
, bool* aInterrupt
);
66 nsresult
DidDoNotify(nsITransaction
* aTransaction
, nsresult aExecuteResult
);
67 nsresult
WillUndoNotify(nsITransaction
* aTransaction
, bool* aInterrupt
);
68 nsresult
DidUndoNotify(nsITransaction
* aTransaction
, nsresult aUndoResult
);
69 nsresult
WillRedoNotify(nsITransaction
* aTransaction
, bool* aInterrupt
);
70 nsresult
DidRedoNotify(nsITransaction
* aTransaction
, nsresult aRedoResult
);
71 nsresult
WillBeginBatchNotify(bool* aInterrupt
);
72 nsresult
DidBeginBatchNotify(nsresult aResult
);
73 nsresult
WillEndBatchNotify(bool* aInterrupt
);
74 nsresult
DidEndBatchNotify(nsresult aResult
);
75 nsresult
WillMergeNotify(nsITransaction
* aTop
, nsITransaction
* aTransaction
,
77 nsresult
DidMergeNotify(nsITransaction
* aTop
, nsITransaction
* aTransaction
,
78 bool aDidMerge
, nsresult aMergeResult
);
81 * Exposing non-virtual methods of nsITransactionManager methods.
83 nsresult
BeginBatchInternal(nsISupports
* aData
);
84 nsresult
EndBatchInternal(bool aAllowEmpty
);
87 virtual ~TransactionManager() = default;
89 nsresult
BeginTransaction(nsITransaction
* aTransaction
, nsISupports
* aData
);
90 nsresult
EndTransaction(bool aAllowEmpty
);
92 int32_t mMaxTransactionCount
;
93 TransactionStack mDoStack
;
94 TransactionStack mUndoStack
;
95 TransactionStack mRedoStack
;
96 nsCOMArray
<nsITransactionListener
> mListeners
;
99 } // namespace mozilla
101 mozilla::TransactionManager
* nsITransactionManager::AsTransactionManager() {
102 return static_cast<mozilla::TransactionManager
*>(this);
105 #endif // #ifndef mozilla_TransactionManager_h