Line data Source code
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 : #include "EditAggregateTransaction.h"
7 : #include "nsAString.h"
8 : #include "nsCOMPtr.h" // for nsCOMPtr
9 : #include "nsError.h" // for NS_OK, etc.
10 : #include "nsISupportsUtils.h" // for NS_ADDREF
11 : #include "nsITransaction.h" // for nsITransaction
12 : #include "nsString.h" // for nsAutoString
13 :
14 : namespace mozilla {
15 :
16 1 : EditAggregateTransaction::EditAggregateTransaction()
17 : {
18 1 : }
19 :
20 1 : EditAggregateTransaction::~EditAggregateTransaction()
21 : {
22 1 : }
23 :
24 0 : NS_IMPL_CYCLE_COLLECTION_INHERITED(EditAggregateTransaction,
25 : EditTransactionBase,
26 : mChildren)
27 :
28 6 : NS_IMPL_ADDREF_INHERITED(EditAggregateTransaction, EditTransactionBase)
29 6 : NS_IMPL_RELEASE_INHERITED(EditAggregateTransaction, EditTransactionBase)
30 2 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EditAggregateTransaction)
31 2 : NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
32 :
33 : NS_IMETHODIMP
34 0 : EditAggregateTransaction::DoTransaction()
35 : {
36 : // FYI: It's legal (but not very useful) to have an empty child list.
37 0 : for (uint32_t i = 0, length = mChildren.Length(); i < length; ++i) {
38 0 : nsITransaction *txn = mChildren[i];
39 0 : if (!txn) {
40 0 : return NS_ERROR_NULL_POINTER;
41 : }
42 0 : nsresult rv = txn->DoTransaction();
43 0 : if (NS_FAILED(rv)) {
44 0 : return rv;
45 : }
46 : }
47 0 : return NS_OK;
48 : }
49 :
50 : NS_IMETHODIMP
51 0 : EditAggregateTransaction::UndoTransaction()
52 : {
53 : // FYI: It's legal (but not very useful) to have an empty child list.
54 : // Undo goes through children backwards.
55 0 : for (uint32_t i = mChildren.Length(); i--; ) {
56 0 : nsITransaction *txn = mChildren[i];
57 0 : if (!txn) {
58 0 : return NS_ERROR_NULL_POINTER;
59 : }
60 0 : nsresult rv = txn->UndoTransaction();
61 0 : if (NS_FAILED(rv)) {
62 0 : return rv;
63 : }
64 : }
65 0 : return NS_OK;
66 : }
67 :
68 : NS_IMETHODIMP
69 0 : EditAggregateTransaction::RedoTransaction()
70 : {
71 : // It's legal (but not very useful) to have an empty child list.
72 0 : for (uint32_t i = 0, length = mChildren.Length(); i < length; ++i) {
73 0 : nsITransaction *txn = mChildren[i];
74 0 : if (!txn) {
75 0 : return NS_ERROR_NULL_POINTER;
76 : }
77 0 : nsresult rv = txn->RedoTransaction();
78 0 : if (NS_FAILED(rv)) {
79 0 : return rv;
80 : }
81 : }
82 0 : return NS_OK;
83 : }
84 :
85 : NS_IMETHODIMP
86 0 : EditAggregateTransaction::Merge(nsITransaction* aTransaction,
87 : bool* aDidMerge)
88 : {
89 0 : if (aDidMerge) {
90 0 : *aDidMerge = false;
91 : }
92 0 : if (mChildren.IsEmpty()) {
93 0 : return NS_OK;
94 : }
95 : // FIXME: Is this really intended not to loop? It looks like the code
96 : // that used to be here sort of intended to loop, but didn't.
97 0 : nsITransaction *txn = mChildren[0];
98 0 : if (!txn) {
99 0 : return NS_ERROR_NULL_POINTER;
100 : }
101 0 : return txn->Merge(aTransaction, aDidMerge);
102 : }
103 :
104 : NS_IMETHODIMP
105 0 : EditAggregateTransaction::GetTxnDescription(nsAString& aString)
106 : {
107 0 : aString.AssignLiteral("EditAggregateTransaction: ");
108 :
109 0 : if (mName) {
110 0 : nsAutoString name;
111 0 : mName->ToString(name);
112 0 : aString += name;
113 : }
114 :
115 0 : return NS_OK;
116 : }
117 :
118 : NS_IMETHODIMP
119 0 : EditAggregateTransaction::AppendChild(EditTransactionBase* aTransaction)
120 : {
121 0 : if (!aTransaction) {
122 0 : return NS_ERROR_NULL_POINTER;
123 : }
124 :
125 0 : RefPtr<EditTransactionBase>* slot = mChildren.AppendElement();
126 0 : if (!slot) {
127 0 : return NS_ERROR_OUT_OF_MEMORY;
128 : }
129 :
130 0 : *slot = aTransaction;
131 0 : return NS_OK;
132 : }
133 :
134 : NS_IMETHODIMP
135 0 : EditAggregateTransaction::GetName(nsIAtom** aName)
136 : {
137 0 : if (aName && mName) {
138 0 : *aName = mName;
139 0 : NS_ADDREF(*aName);
140 0 : return NS_OK;
141 : }
142 0 : return NS_ERROR_NULL_POINTER;
143 : }
144 :
145 : } // namespace mozilla
|