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 #include "EditAggregateTxn.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
14 EditAggregateTxn::EditAggregateTxn()
19 EditAggregateTxn::~EditAggregateTxn()
23 NS_IMPL_CYCLE_COLLECTION_INHERITED(EditAggregateTxn
, EditTxn
,
26 NS_IMPL_ADDREF_INHERITED(EditAggregateTxn
, EditTxn
)
27 NS_IMPL_RELEASE_INHERITED(EditAggregateTxn
, EditTxn
)
28 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EditAggregateTxn
)
29 NS_INTERFACE_MAP_END_INHERITING(EditTxn
)
31 NS_IMETHODIMP
EditAggregateTxn::DoTransaction(void)
33 nsresult result
=NS_OK
; // it's legal (but not very useful) to have an empty child list
34 for (uint32_t i
= 0, length
= mChildren
.Length(); i
< length
; ++i
)
36 nsITransaction
*txn
= mChildren
[i
];
37 if (!txn
) { return NS_ERROR_NULL_POINTER
; }
38 result
= txn
->DoTransaction();
39 if (NS_FAILED(result
))
45 NS_IMETHODIMP
EditAggregateTxn::UndoTransaction(void)
47 nsresult result
=NS_OK
; // it's legal (but not very useful) to have an empty child list
48 // undo goes through children backwards
49 for (uint32_t i
= mChildren
.Length(); i
-- != 0; )
51 nsITransaction
*txn
= mChildren
[i
];
52 if (!txn
) { return NS_ERROR_NULL_POINTER
; }
53 result
= txn
->UndoTransaction();
54 if (NS_FAILED(result
))
60 NS_IMETHODIMP
EditAggregateTxn::RedoTransaction(void)
62 nsresult result
=NS_OK
; // it's legal (but not very useful) to have an empty child list
63 for (uint32_t i
= 0, length
= mChildren
.Length(); i
< length
; ++i
)
65 nsITransaction
*txn
= mChildren
[i
];
66 if (!txn
) { return NS_ERROR_NULL_POINTER
; }
67 result
= txn
->RedoTransaction();
68 if (NS_FAILED(result
))
74 NS_IMETHODIMP
EditAggregateTxn::Merge(nsITransaction
*aTransaction
, bool *aDidMerge
)
76 nsresult result
=NS_OK
; // it's legal (but not very useful) to have an empty child list
79 // FIXME: Is this really intended not to loop? It looks like the code
80 // that used to be here sort of intended to loop, but didn't.
81 if (mChildren
.Length() > 0)
83 nsITransaction
*txn
= mChildren
[0];
84 if (!txn
) { return NS_ERROR_NULL_POINTER
; }
85 result
= txn
->Merge(aTransaction
, aDidMerge
);
90 NS_IMETHODIMP
EditAggregateTxn::GetTxnDescription(nsAString
& aString
)
92 aString
.AssignLiteral("EditAggregateTxn: ");
97 mName
->ToString(name
);
104 NS_IMETHODIMP
EditAggregateTxn::AppendChild(EditTxn
*aTxn
)
107 return NS_ERROR_NULL_POINTER
;
110 nsRefPtr
<EditTxn
> *slot
= mChildren
.AppendElement();
112 return NS_ERROR_OUT_OF_MEMORY
;
119 NS_IMETHODIMP
EditAggregateTxn::GetName(nsIAtom
**aName
)
127 return NS_ERROR_NULL_POINTER
;