1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998-1999
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "EditAggregateTxn.h"
39 : #include "nsCOMPtr.h"
40 :
41 0 : EditAggregateTxn::EditAggregateTxn()
42 0 : : EditTxn()
43 : {
44 0 : }
45 1464 : NS_IMPL_CYCLE_COLLECTION_CLASS(EditAggregateTxn)
46 :
47 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(EditAggregateTxn, EditTxn)
48 0 : tmp->mChildren.Clear();
49 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
50 :
51 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(EditAggregateTxn, EditTxn)
52 0 : for (PRUint32 i = 0; i < tmp->mChildren.Length(); ++i) {
53 0 : NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mChildren[i]");
54 0 : cb.NoteXPCOMChild(static_cast<nsITransaction*>(tmp->mChildren[i]));
55 : }
56 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
57 :
58 0 : NS_IMPL_ADDREF_INHERITED(EditAggregateTxn, EditTxn)
59 0 : NS_IMPL_RELEASE_INHERITED(EditAggregateTxn, EditTxn)
60 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EditAggregateTxn)
61 0 : NS_INTERFACE_MAP_END_INHERITING(EditTxn)
62 :
63 0 : NS_IMETHODIMP EditAggregateTxn::DoTransaction(void)
64 : {
65 0 : nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
66 0 : for (PRUint32 i = 0, length = mChildren.Length(); i < length; ++i)
67 : {
68 0 : nsITransaction *txn = mChildren[i];
69 0 : if (!txn) { return NS_ERROR_NULL_POINTER; }
70 0 : result = txn->DoTransaction();
71 0 : if (NS_FAILED(result))
72 0 : break;
73 : }
74 0 : return result;
75 : }
76 :
77 0 : NS_IMETHODIMP EditAggregateTxn::UndoTransaction(void)
78 : {
79 0 : nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
80 : // undo goes through children backwards
81 0 : for (PRUint32 i = mChildren.Length(); i-- != 0; )
82 : {
83 0 : nsITransaction *txn = mChildren[i];
84 0 : if (!txn) { return NS_ERROR_NULL_POINTER; }
85 0 : result = txn->UndoTransaction();
86 0 : if (NS_FAILED(result))
87 0 : break;
88 : }
89 0 : return result;
90 : }
91 :
92 0 : NS_IMETHODIMP EditAggregateTxn::RedoTransaction(void)
93 : {
94 0 : nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
95 0 : for (PRUint32 i = 0, length = mChildren.Length(); i < length; ++i)
96 : {
97 0 : nsITransaction *txn = mChildren[i];
98 0 : if (!txn) { return NS_ERROR_NULL_POINTER; }
99 0 : result = txn->RedoTransaction();
100 0 : if (NS_FAILED(result))
101 0 : break;
102 : }
103 0 : return result;
104 : }
105 :
106 0 : NS_IMETHODIMP EditAggregateTxn::Merge(nsITransaction *aTransaction, bool *aDidMerge)
107 : {
108 0 : nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
109 0 : if (aDidMerge)
110 0 : *aDidMerge = false;
111 : // FIXME: Is this really intended not to loop? It looks like the code
112 : // that used to be here sort of intended to loop, but didn't.
113 0 : if (mChildren.Length() > 0)
114 : {
115 0 : nsITransaction *txn = mChildren[0];
116 0 : if (!txn) { return NS_ERROR_NULL_POINTER; }
117 0 : result = txn->Merge(aTransaction, aDidMerge);
118 : }
119 0 : return result;
120 : }
121 :
122 0 : NS_IMETHODIMP EditAggregateTxn::GetTxnDescription(nsAString& aString)
123 : {
124 0 : aString.AssignLiteral("EditAggregateTxn: ");
125 :
126 0 : if (mName)
127 : {
128 0 : nsAutoString name;
129 0 : mName->ToString(name);
130 0 : aString += name;
131 : }
132 :
133 0 : return NS_OK;
134 : }
135 :
136 0 : NS_IMETHODIMP EditAggregateTxn::AppendChild(EditTxn *aTxn)
137 : {
138 0 : if (!aTxn) {
139 0 : return NS_ERROR_NULL_POINTER;
140 : }
141 :
142 0 : nsRefPtr<EditTxn> *slot = mChildren.AppendElement();
143 0 : if (!slot) {
144 0 : return NS_ERROR_OUT_OF_MEMORY;
145 : }
146 :
147 0 : *slot = aTxn;
148 0 : return NS_OK;
149 : }
150 :
151 0 : NS_IMETHODIMP EditAggregateTxn::GetName(nsIAtom **aName)
152 : {
153 0 : if (aName && mName)
154 : {
155 0 : *aName = mName;
156 0 : NS_ADDREF(*aName);
157 0 : return NS_OK;
158 : }
159 0 : return NS_ERROR_NULL_POINTER;
160 4392 : }
|