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 
6 #ifndef TransactionItem_h
7 #define TransactionItem_h
8 
9 #include "nsCOMPtr.h"
10 #include "nsCOMArray.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsISupportsImpl.h"
13 #include "nscore.h"
14 
15 class nsITransaction;
16 
17 namespace mozilla {
18 
19 class TransactionManager;
20 class TransactionStack;
21 
22 class TransactionItem final {
23  public:
24   explicit TransactionItem(nsITransaction* aTransaction);
25   NS_METHOD_(MozExternalRefCountType) AddRef();
26   NS_METHOD_(MozExternalRefCountType) Release();
27 
28   NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(TransactionItem)
29 
30   nsresult AddChild(TransactionItem& aTransactionItem);
31   already_AddRefed<nsITransaction> GetTransaction();
NumberOfChildren()32   size_t NumberOfChildren() const {
33     return NumberOfUndoItems() + NumberOfRedoItems();
34   }
35   nsresult GetChild(size_t aIndex, TransactionItem** aChild);
36 
37   MOZ_CAN_RUN_SCRIPT nsresult DoTransaction();
38   MOZ_CAN_RUN_SCRIPT nsresult
39   UndoTransaction(TransactionManager* aTransactionManager);
40   MOZ_CAN_RUN_SCRIPT nsresult
41   RedoTransaction(TransactionManager* aTransactionManager);
42 
GetData()43   nsCOMArray<nsISupports>& GetData() { return mData; }
44 
45  private:
46   MOZ_CAN_RUN_SCRIPT nsresult
47   UndoChildren(TransactionManager* aTransactionManager);
48   MOZ_CAN_RUN_SCRIPT nsresult
49   RedoChildren(TransactionManager* aTransactionManager);
50 
51   MOZ_CAN_RUN_SCRIPT nsresult
52   RecoverFromUndoError(TransactionManager* aTransactionManager);
53   MOZ_CAN_RUN_SCRIPT nsresult
54   RecoverFromRedoError(TransactionManager* aTransactionManager);
55 
56   size_t NumberOfUndoItems() const;
57   size_t NumberOfRedoItems() const;
58 
59   void CleanUp();
60 
61   ~TransactionItem();
62 
63   nsCycleCollectingAutoRefCnt mRefCnt;
64   NS_DECL_OWNINGTHREAD
65 
66   nsCOMArray<nsISupports> mData;
67   nsCOMPtr<nsITransaction> mTransaction;
68   TransactionStack* mUndoStack;
69   TransactionStack* mRedoStack;
70 };
71 
72 }  // namespace mozilla
73 
74 #endif  // #ifndef TransactionItem_h
75