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
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/
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
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Pierre Phaneuf <pp@ludusdesign.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 #include "nsHTMLEditorLog.h"
41 #include "nsEditorTxnLog.h"
42 #include "nsPIEditorTransaction.h"
45 #define UNLOCK_LOG(doc)
48 nsEditorTxnLog::nsEditorTxnLog(nsHTMLEditorLog
*aEditorLog
)
53 mEditorLog
= aEditorLog
;
56 nsEditorTxnLog::~nsEditorTxnLog()
60 // #define DEBUG_EDITOR_TXN_LOG_REFCNT 1
62 #ifdef DEBUG_EDITOR_TXN_LOG_REFCNT
64 nsrefcnt
nsEditorTxnLog::AddRef(void)
69 nsrefcnt
nsEditorTxnLog::Release(void)
71 NS_PRECONDITION(0 != mRefCnt
, "dup release");
81 NS_IMPL_ADDREF(nsEditorTxnLog
)
82 NS_IMPL_RELEASE(nsEditorTxnLog
)
86 NS_IMPL_QUERY_INTERFACE1(nsEditorTxnLog
, nsITransactionListener
)
89 nsEditorTxnLog::WillDo(nsITransactionManager
*aTxMgr
, nsITransaction
*aTransaction
, PRBool
*aInterrupt
)
93 PrintIndent(mIndentLevel
++);
95 WriteTransaction(aTransaction
);
105 nsEditorTxnLog::DidDo(nsITransactionManager
*aTxMgr
, nsITransaction
*aTransaction
, nsresult aDoResult
)
109 PrintIndent(--mIndentLevel
);
111 WriteTransaction(aTransaction
);
123 nsEditorTxnLog::WillUndo(nsITransactionManager
*aTxMgr
, nsITransaction
*aTransaction
, PRBool
*aInterrupt
)
127 PrintIndent(mIndentLevel
++);
132 WriteTransaction(aTransaction
);
136 Write("WillUndoBatch\n");
146 nsEditorTxnLog::DidUndo(nsITransactionManager
*aTxMgr
, nsITransaction
*aTransaction
, nsresult aUndoResult
)
150 PrintIndent(--mIndentLevel
);
155 WriteTransaction(aTransaction
);
157 WriteInt(aUndoResult
);
162 Write("EndUndoBatch (");
163 WriteInt(aUndoResult
);
175 nsEditorTxnLog::WillRedo(nsITransactionManager
*aTxMgr
, nsITransaction
*aTransaction
, PRBool
*aInterrupt
)
179 PrintIndent(mIndentLevel
++);
184 WriteTransaction(aTransaction
);
188 Write("WillRedoBatch\n");
198 nsEditorTxnLog::DidRedo(nsITransactionManager
*aTxMgr
, nsITransaction
*aTransaction
, nsresult aRedoResult
)
202 PrintIndent(--mIndentLevel
);
207 WriteTransaction(aTransaction
);
209 WriteInt(aRedoResult
);
214 Write("DidRedoBatch (");
215 WriteInt(aRedoResult
);
227 nsEditorTxnLog::WillBeginBatch(nsITransactionManager
*aTxMgr
, PRBool
*aInterrupt
)
231 PrintIndent(mIndentLevel
);
232 Write("WillBeginBatch: ");
233 WriteInt(mBatchCount
);
243 nsEditorTxnLog::DidBeginBatch(nsITransactionManager
*aTxMgr
, nsresult aResult
)
247 PrintIndent(mIndentLevel
++);
248 Write("DidBeginBatch: ");
249 WriteInt(mBatchCount
++);
261 nsEditorTxnLog::WillEndBatch(nsITransactionManager
*aTxMgr
, PRBool
*aInterrupt
)
265 PrintIndent(--mIndentLevel
);
266 Write("WillEndBatch: ");
267 WriteInt(--mBatchCount
);
277 nsEditorTxnLog::DidEndBatch(nsITransactionManager
*aTxMgr
, nsresult aResult
)
281 PrintIndent(mIndentLevel
);
282 Write("DidEndBatch: ");
283 WriteInt(mBatchCount
);
295 nsEditorTxnLog::WillMerge(nsITransactionManager
*aTxMgr
, nsITransaction
*aTopTransaction
, nsITransaction
*aTransaction
, PRBool
*aInterrupt
)
299 PrintIndent(mIndentLevel
);
300 Write("WillMerge: ");
301 WriteTransaction(aTopTransaction
);
303 WriteTransaction(aTransaction
);
313 nsEditorTxnLog::DidMerge(nsITransactionManager
*aTxMgr
, nsITransaction
*aTopTransaction
, nsITransaction
*aTransaction
, PRBool aDidMerge
, nsresult aMergeResult
)
317 PrintIndent(mIndentLevel
);
319 WriteTransaction(aTopTransaction
);
321 WriteTransaction(aTransaction
);
323 Write(aDidMerge
? "TRUE" : "FALSE");
325 WriteInt(aMergeResult
);
335 nsEditorTxnLog::WriteTransaction(nsITransaction
*aTransaction
)
339 nsCOMPtr
<nsPIEditorTransaction
> txn
= do_QueryInterface(aTransaction
);
341 txn
->GetTxnDescription(str
);
343 str
.AssignLiteral("<NULL>");
346 return Write(NS_LossyConvertUTF16toASCII(str
).get());
350 nsEditorTxnLog::PrintIndent(PRInt32 aIndentLevel
)
356 for (i
= 0; i
< aIndentLevel
; i
++)
363 nsEditorTxnLog::Write(const char *aBuffer
)
366 return NS_ERROR_NULL_POINTER
;
369 mEditorLog
->Write(aBuffer
);
372 PRInt32 len
= strlen(aBuffer
);
374 fwrite(aBuffer
, 1, len
, stdout
);
381 nsEditorTxnLog::WriteInt(PRInt32 aInt
)
384 mEditorLog
->WriteInt(aInt
);
392 nsEditorTxnLog::Flush()
394 nsresult result
= NS_OK
;
396 #ifdef SLOWS_THINGS_WAY_DOWN
399 result
= mEditorLog
->Flush();
403 #endif // SLOWS_THINGS_WAY_DOWN