Bug 1884032 [wpt PR 44942] - [css-color] add missing colorscheme-aware tests, a=testonly
[gecko.git] / editor / txmgr / TransactionManager.h
blobcdabc83c908d11a5ba8428b08cd5a90839ec571c
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/EditorForwards.h"
10 #include "mozilla/TransactionStack.h"
12 #include "nsCOMArray.h"
13 #include "nsCOMPtr.h"
14 #include "nsCycleCollectionParticipant.h"
15 #include "nsISupportsImpl.h"
16 #include "nsITransactionManager.h"
17 #include "nsWeakReference.h"
18 #include "nscore.h"
20 class nsITransaction;
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 MOZ_CAN_RUN_SCRIPT nsresult Undo();
39 MOZ_CAN_RUN_SCRIPT 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 void Attach(HTMLEditor& aHTMLEditor);
58 void Detach(const HTMLEditor& aHTMLEditor);
60 MOZ_CAN_RUN_SCRIPT void DidDoNotify(nsITransaction& aTransaction,
61 nsresult aDoResult);
62 MOZ_CAN_RUN_SCRIPT void DidUndoNotify(nsITransaction& aTransaction,
63 nsresult aUndoResult);
64 MOZ_CAN_RUN_SCRIPT void DidRedoNotify(nsITransaction& aTransaction,
65 nsresult aRedoResult);
67 /**
68 * Exposing non-virtual methods of nsITransactionManager methods.
70 MOZ_CAN_RUN_SCRIPT nsresult BeginBatchInternal(nsISupports* aData);
71 nsresult EndBatchInternal(bool aAllowEmpty);
73 private:
74 virtual ~TransactionManager() = default;
76 MOZ_CAN_RUN_SCRIPT nsresult BeginTransaction(nsITransaction* aTransaction,
77 nsISupports* aData);
78 nsresult EndTransaction(bool aAllowEmpty);
80 int32_t mMaxTransactionCount;
81 TransactionStack mDoStack;
82 TransactionStack mUndoStack;
83 TransactionStack mRedoStack;
84 RefPtr<HTMLEditor> mHTMLEditor;
87 } // namespace mozilla
89 mozilla::TransactionManager* nsITransactionManager::AsTransactionManager() {
90 return static_cast<mozilla::TransactionManager*>(this);
93 #endif // #ifndef mozilla_TransactionManager_h