From d03b3983a0c7e6e337577c2fcb22fe6ed4e8cb86 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Thu, 23 Feb 2012 22:47:37 +0200 Subject: [PATCH] Bug 730013 - don't addref/release nsTransactionManager so much to prevent it to end up to the purple buffer, r=ehsan --- content/html/content/src/nsTextEditorState.cpp | 8 ++------ editor/idl/nsIEditor.idl | 12 +++++++++++- editor/libeditor/base/nsEditor.cpp | 13 +++++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/content/html/content/src/nsTextEditorState.cpp b/content/html/content/src/nsTextEditorState.cpp index 2eb62ab716f..2f79c1a78aa 100644 --- a/content/html/content/src/nsTextEditorState.cpp +++ b/content/html/content/src/nsTextEditorState.cpp @@ -849,15 +849,11 @@ nsTextInputListener::EditAction() nsCOMPtr editor; frame->GetEditor(getter_AddRefs(editor)); - nsCOMPtr manager; - editor->GetTransactionManager(getter_AddRefs(manager)); - NS_ENSURE_TRUE(manager, NS_ERROR_FAILURE); - // Get the number of undo / redo items PRInt32 numUndoItems = 0; PRInt32 numRedoItems = 0; - manager->GetNumberOfUndoItems(&numUndoItems); - manager->GetNumberOfRedoItems(&numRedoItems); + editor->GetNumberOfUndoItems(&numUndoItems); + editor->GetNumberOfRedoItems(&numRedoItems); if ((numUndoItems && !mHadUndoItems) || (!numUndoItems && mHadUndoItems) || (numRedoItems && !mHadRedoItems) || (!numRedoItems && mHadRedoItems)) { // Modify the menu if undo or redo items are different diff --git a/editor/idl/nsIEditor.idl b/editor/idl/nsIEditor.idl index 052592a7f74..d4a9c91c431 100644 --- a/editor/idl/nsIEditor.idl +++ b/editor/idl/nsIEditor.idl @@ -55,7 +55,7 @@ interface nsIEditActionListener; interface nsIInlineSpellChecker; interface nsITransferable; -[scriptable, uuid(94479B76-7FD7-47D3-BB1E-5B77846339D2)] +[scriptable, uuid(656005d2-d900-4839-81bf-6274a3c38537)] interface nsIEditor : nsISupports { @@ -205,6 +205,16 @@ interface nsIEditor : nsISupports */ void enableUndo(in boolean enable); + /** + * The number of items on the undo stack. + */ + readonly attribute long numberOfUndoItems; + + /** + * The number of items on the redo stack. + */ + readonly attribute long numberOfRedoItems; + /** undo reverses the effects of the last Do operation, * if Undo is enabled in the editor. * It is provided here so clients need no knowledge of whether diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 197c9f2b000..8f06173bb64 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -750,6 +750,19 @@ nsEditor::EnableUndo(bool aEnable) return NS_OK; } +NS_IMETHODIMP +nsEditor::GetNumberOfUndoItems(PRInt32* aNumItems) +{ + *aNumItems = 0; + return mTxnMgr ? mTxnMgr->GetNumberOfUndoItems(aNumItems) : NS_OK; +} + +NS_IMETHODIMP +nsEditor::GetNumberOfRedoItems(PRInt32* aNumItems) +{ + *aNumItems = 0; + return mTxnMgr ? mTxnMgr->GetNumberOfRedoItems(aNumItems) : NS_OK; +} NS_IMETHODIMP nsEditor::GetTransactionManager(nsITransactionManager* *aTxnManager)