Bug 1468402 - Part 3: Add test for subgrids in the grid list. r=pbro
[gecko.git] / editor / txmgr / TransactionManager.h
blob6c85de3b6e85fc42eda31f235871a59ac7772c41
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"
12 #include "nsCOMPtr.h"
13 #include "nsCycleCollectionParticipant.h"
14 #include "nsISupportsImpl.h"
15 #include "nsITransactionManager.h"
16 #include "nsWeakReference.h"
17 #include "nscore.h"
19 class nsITransaction;
20 class nsITransactionListener;
22 namespace mozilla {
24 class TransactionManager final : public nsITransactionManager,
25 public nsSupportsWeakReference {
26 public:
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();
38 nsresult Undo();
39 nsresult Redo();
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())) {
50 return false;
52 mUndoStack.Clear();
53 mRedoStack.Clear();
54 return true;
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,
76 bool* aInterrupt);
77 nsresult DidMergeNotify(nsITransaction* aTop, nsITransaction* aTransaction,
78 bool aDidMerge, nsresult aMergeResult);
80 /**
81 * Exposing non-virtual methods of nsITransactionManager methods.
83 nsresult BeginBatchInternal(nsISupports* aData);
84 nsresult EndBatchInternal(bool aAllowEmpty);
86 private:
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