From bc681240534d5e7e166bcc49e06c6675c6615638 Mon Sep 17 00:00:00 2001 From: "Robert Sayre ext:(%2C%20L.%20David%20Baron%20%3Cdbaron%40dbaron.org%3E)" Date: Fri, 8 May 2009 21:59:25 -0700 Subject: [PATCH] Add the editor to cycle collection. (Bug 423233) r+sr=peterv --- editor/libeditor/base/nsEditor.cpp | 51 ++++++++++++++++++++- editor/libeditor/base/nsEditor.h | 5 +- editor/libeditor/html/nsHTMLEditRules.cpp | 2 +- editor/libeditor/html/nsHTMLEditRules.h | 2 +- editor/libeditor/text/nsPlaintextEditor.cpp | 14 +++++- editor/libeditor/text/nsPlaintextEditor.h | 2 + editor/libeditor/text/nsTextEditRules.cpp | 9 +++- editor/libeditor/text/nsTextEditRules.h | 3 +- 8 files changed, 80 insertions(+), 8 deletions(-) diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 255e093b1d72..748b6181b9e0 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -167,8 +167,55 @@ nsEditor::~nsEditor() NS_IF_RELEASE(mViewManager); } -NS_IMPL_ISUPPORTS5(nsEditor, nsIEditor, nsIEditorIMESupport, - nsISupportsWeakReference, nsIPhonetic, nsIMutationObserver) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsEditor) + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsEditor) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRootElement) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mInlineSpellChecker) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTxnMgr) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mIMETextRangeList) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mIMETextNode) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mActionListeners) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mEditorObservers) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mDocStateListeners) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mEventTarget) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mKeyListenerP) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mMouseListenerP) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTextListenerP) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCompositionListenerP) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDragListenerP) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFocusListenerP) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsEditor) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRootElement) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mInlineSpellChecker) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTxnMgr) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mIMETextRangeList) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mIMETextNode) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mActionListeners) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mEditorObservers) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mDocStateListeners) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEventTarget) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mKeyListenerP) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mMouseListenerP) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTextListenerP) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCompositionListenerP) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDragListenerP) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFocusListenerP) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsEditor) + NS_INTERFACE_MAP_ENTRY(nsIMutationObserver) + NS_INTERFACE_MAP_ENTRY(nsIPhonetic) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY(nsIEditorIMESupport) + NS_INTERFACE_MAP_ENTRY(nsIEditor) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditor) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsEditor, nsIEditor) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsEditor, nsIEditor) #ifdef XP_MAC #pragma mark - diff --git a/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index 955f4f912615..973590ceee9c 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/editor/libeditor/base/nsEditor.h @@ -65,6 +65,7 @@ #include "nsPIDOMEventTarget.h" #include "nsStubMutationObserver.h" #include "nsIViewManager.h" +#include "nsCycleCollectionParticipant.h" class nsIDOMCharacterData; class nsIDOMRange; @@ -138,7 +139,9 @@ public: //Interfaces for addref and release and queryinterface //NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsEditor - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsEditor, + nsIEditor) /* ------------ utility methods -------------- */ NS_IMETHOD GetPresShell(nsIPresShell **aPS); diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index 947e71c8ed8b..526f3386be57 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -239,7 +239,7 @@ nsHTMLEditRules::~nsHTMLEditRules() NS_IMPL_ADDREF_INHERITED(nsHTMLEditRules, nsTextEditRules) NS_IMPL_RELEASE_INHERITED(nsHTMLEditRules, nsTextEditRules) -NS_IMPL_QUERY_INTERFACE3(nsHTMLEditRules, nsIHTMLEditRules, nsIEditRules, nsIEditActionListener) +NS_IMPL_QUERY_INTERFACE_INHERITED2(nsHTMLEditRules, nsTextEditRules, nsIHTMLEditRules, nsIEditActionListener) /******************************************************** diff --git a/editor/libeditor/html/nsHTMLEditRules.h b/editor/libeditor/html/nsHTMLEditRules.h index 2c5adce16fa4..ae442a0aa916 100644 --- a/editor/libeditor/html/nsHTMLEditRules.h +++ b/editor/libeditor/html/nsHTMLEditRules.h @@ -75,7 +75,7 @@ struct StyleCache : public PropItem #define SIZE_STYLE_TABLE 19 -class nsHTMLEditRules : public nsIHTMLEditRules, public nsTextEditRules, public nsIEditActionListener +class nsHTMLEditRules : public nsTextEditRules, public nsIHTMLEditRules, public nsIEditActionListener { public: diff --git a/editor/libeditor/text/nsPlaintextEditor.cpp b/editor/libeditor/text/nsPlaintextEditor.cpp index 84eb1dbbbf41..a8f2ea8df6b7 100644 --- a/editor/libeditor/text/nsPlaintextEditor.cpp +++ b/editor/libeditor/text/nsPlaintextEditor.cpp @@ -120,10 +120,22 @@ nsPlaintextEditor::~nsPlaintextEditor() mRules->DetachEditor(); } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsPlaintextEditor) + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsPlaintextEditor, nsEditor) + if (tmp->mRules) + tmp->mRules->DetachEditor(); + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRules) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsPlaintextEditor, nsEditor) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRules) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsPlaintextEditor, nsEditor) NS_IMPL_RELEASE_INHERITED(nsPlaintextEditor, nsEditor) -NS_INTERFACE_MAP_BEGIN(nsPlaintextEditor) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsPlaintextEditor) NS_INTERFACE_MAP_ENTRY(nsIPlaintextEditor) NS_INTERFACE_MAP_ENTRY(nsIEditorMailSupport) NS_INTERFACE_MAP_END_INHERITING(nsEditor) diff --git a/editor/libeditor/text/nsPlaintextEditor.h b/editor/libeditor/text/nsPlaintextEditor.h index a37f9865bc9e..03faf0a9906d 100644 --- a/editor/libeditor/text/nsPlaintextEditor.h +++ b/editor/libeditor/text/nsPlaintextEditor.h @@ -49,6 +49,7 @@ #include "nsIDOMEventListener.h" #include "nsEditRules.h" +#include "nsCycleCollectionParticipant.h" class nsITransferable; class nsIDocumentEncoder; @@ -68,6 +69,7 @@ public: // NOTE macro used is for classes that inherit from // another class. Only the base class should use NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsPlaintextEditor, nsEditor) /* below used by TypedText() */ enum { diff --git a/editor/libeditor/text/nsTextEditRules.cpp b/editor/libeditor/text/nsTextEditRules.cpp index 15f6f8f05359..846a6ebd17ed 100644 --- a/editor/libeditor/text/nsTextEditRules.cpp +++ b/editor/libeditor/text/nsTextEditRules.cpp @@ -114,8 +114,15 @@ nsTextEditRules::~nsTextEditRules() * XPCOM Cruft ********************************************************/ -NS_IMPL_ISUPPORTS1(nsTextEditRules, nsIEditRules) +NS_IMPL_CYCLE_COLLECTION_2(nsTextEditRules, mBogusNode, mCachedSelectionNode) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsTextEditRules) + NS_INTERFACE_MAP_ENTRY(nsIEditRules) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditRules) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTextEditRules) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTextEditRules) /******************************************************** * Public methods diff --git a/editor/libeditor/text/nsTextEditRules.h b/editor/libeditor/text/nsTextEditRules.h index a4a16de61332..43dd0f3e7ea5 100644 --- a/editor/libeditor/text/nsTextEditRules.h +++ b/editor/libeditor/text/nsTextEditRules.h @@ -59,7 +59,8 @@ class nsTextEditRules : public nsIEditRules { public: - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS(nsTextEditRules) nsTextEditRules(); virtual ~nsTextEditRules();