Bumping manifests a=b2g-bump
[gecko.git] / editor / libeditor / EditAggregateTxn.cpp
blob2a790a3df903265dca9979174f44b5c507ca6613
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"
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
14 EditAggregateTxn::EditAggregateTxn()
15 : EditTxn()
19 EditAggregateTxn::~EditAggregateTxn()
23 NS_IMPL_CYCLE_COLLECTION_INHERITED(EditAggregateTxn, EditTxn,
24 mChildren)
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))
40 break;
42 return 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))
55 break;
57 return 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))
69 break;
71 return 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
77 if (aDidMerge)
78 *aDidMerge = false;
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);
87 return result;
90 NS_IMETHODIMP EditAggregateTxn::GetTxnDescription(nsAString& aString)
92 aString.AssignLiteral("EditAggregateTxn: ");
94 if (mName)
96 nsAutoString name;
97 mName->ToString(name);
98 aString += name;
101 return NS_OK;
104 NS_IMETHODIMP EditAggregateTxn::AppendChild(EditTxn *aTxn)
106 if (!aTxn) {
107 return NS_ERROR_NULL_POINTER;
110 nsRefPtr<EditTxn> *slot = mChildren.AppendElement();
111 if (!slot) {
112 return NS_ERROR_OUT_OF_MEMORY;
115 *slot = aTxn;
116 return NS_OK;
119 NS_IMETHODIMP EditAggregateTxn::GetName(nsIAtom **aName)
121 if (aName && mName)
123 *aName = mName;
124 NS_ADDREF(*aName);
125 return NS_OK;
127 return NS_ERROR_NULL_POINTER;