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 EditAggregateTransaction_h
7 #define EditAggregateTransaction_h
8 
9 #include "mozilla/EditTransactionBase.h"
10 #include "mozilla/OwningNonNull.h"
11 #include "nsCOMPtr.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "nsAtom.h"
14 #include "nsISupportsImpl.h"
15 #include "nsTArray.h"
16 #include "nscore.h"
17 
18 namespace mozilla {
19 
20 /**
21  * base class for all document editing transactions that require aggregation.
22  * provides a list of child transactions.
23  */
24 class EditAggregateTransaction : public EditTransactionBase {
25  protected:
26   EditAggregateTransaction() = default;
27 
28  public:
29   /**
30    * Creates an edit aggregate transaction.  This never returns nullptr.
31    */
Create()32   static already_AddRefed<EditAggregateTransaction> Create() {
33     RefPtr<EditAggregateTransaction> transaction =
34         new EditAggregateTransaction();
35     return transaction.forget();
36   }
37 
38   NS_DECL_ISUPPORTS_INHERITED
39   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(EditAggregateTransaction,
40                                            EditTransactionBase)
41 
42   NS_DECL_EDITTRANSACTIONBASE
43 
44   MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override;
45   NS_IMETHOD Merge(nsITransaction* aOtherTransaction, bool* aDidMerge) override;
46 
47   /**
48    * Append a transaction to this aggregate.
49    */
50   NS_IMETHOD AppendChild(EditTransactionBase* aTransaction);
51 
52   /**
53    * Get the name assigned to this transaction.
54    */
55   NS_IMETHOD GetName(nsAtom** aName);
56 
ChildTransactions()57   const nsTArray<OwningNonNull<EditTransactionBase>>& ChildTransactions()
58       const {
59     return mChildren;
60   }
61 
62  protected:
63   virtual ~EditAggregateTransaction() = default;
64 
65   nsTArray<OwningNonNull<EditTransactionBase>> mChildren;
66   RefPtr<nsAtom> mName;
67 };
68 
69 }  // namespace mozilla
70 
71 #endif  // #ifndef EditAggregateTransaction_h
72