diff --git a/editor/libeditor/base/nsEditRules.h b/editor/libeditor/base/nsEditRules.h index 472008b06b16..8965f8f04c0c 100644 --- a/editor/libeditor/base/nsEditRules.h +++ b/editor/libeditor/base/nsEditRules.h @@ -38,10 +38,10 @@ #ifndef nsEditRules_h__ #define nsEditRules_h__ +// 783223c9-153a-4e01-8422-39a3afe469da #define NS_IEDITRULES_IID \ -{ /* a6cf911d-15b3-11d2-932e-00805f8add32 */ \ -0xa6cf911d, 0x15b3, 0x11d2, \ -{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } +{ 0x783223c9, 0x153a, 0x4e01, \ + { 0x84, 0x22, 0x39, 0xa3, 0xaf, 0xe4, 0x69, 0xda } } class nsPlaintextEditor; class nsISelection; @@ -73,6 +73,7 @@ public: //NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsIEditRules NS_IMETHOD Init(nsPlaintextEditor *aEditor, PRUint32 aFlags)=0; + NS_IMETHOD DetachEditor()=0; NS_IMETHOD BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection)=0; NS_IMETHOD AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection)=0; NS_IMETHOD WillDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, PRBool *aCancel, PRBool *aHandled)=0; diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index 83bf7a63d54d..947e71c8ed8b 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -225,11 +225,12 @@ mDocChangeRange(nsnull) nsHTMLEditRules::~nsHTMLEditRules() { // remove ourselves as a listener to edit actions - // In the normal case, we have already been removed by - // ~nsHTMLEditor, in which case we will get an error here + // In some cases, we have already been removed by + // ~nsHTMLEditor, in which case we will get a null pointer here // which we ignore. But this allows us to add the ability to // switch rule sets on the fly if we want. - mHTMLEditor->RemoveEditActionListener(this); + if (mHTMLEditor) + mHTMLEditor->RemoveEditActionListener(this); } /******************************************************** @@ -302,6 +303,12 @@ nsHTMLEditRules::Init(nsPlaintextEditor *aEditor, PRUint32 aFlags) return res; } +NS_IMETHODIMP +nsHTMLEditRules::DetachEditor() +{ + mHTMLEditor = nsnull; + return nsTextEditRules::DetachEditor(); +} NS_IMETHODIMP nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection) diff --git a/editor/libeditor/html/nsHTMLEditRules.h b/editor/libeditor/html/nsHTMLEditRules.h index 818cb28ac8b4..2c5adce16fa4 100644 --- a/editor/libeditor/html/nsHTMLEditRules.h +++ b/editor/libeditor/html/nsHTMLEditRules.h @@ -87,6 +87,7 @@ public: // nsIEditRules methods NS_IMETHOD Init(nsPlaintextEditor *aEditor, PRUint32 aFlags); + NS_IMETHOD DetachEditor(); NS_IMETHOD BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection); NS_IMETHOD AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection); NS_IMETHOD WillDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, PRBool *aCancel, PRBool *aHandled); diff --git a/editor/libeditor/text/nsPlaintextEditor.cpp b/editor/libeditor/text/nsPlaintextEditor.cpp index 7270afad9e60..84eb1dbbbf41 100644 --- a/editor/libeditor/text/nsPlaintextEditor.cpp +++ b/editor/libeditor/text/nsPlaintextEditor.cpp @@ -115,6 +115,9 @@ nsPlaintextEditor::~nsPlaintextEditor() // Remove event listeners. Note that if we had an HTML editor, // it installed its own instead of these RemoveEventListeners(); + + if (mRules) + mRules->DetachEditor(); } NS_IMPL_ADDREF_INHERITED(nsPlaintextEditor, nsEditor) diff --git a/editor/libeditor/text/nsTextEditRules.cpp b/editor/libeditor/text/nsTextEditRules.cpp index 54fdc347f26f..15f6f8f05359 100644 --- a/editor/libeditor/text/nsTextEditRules.cpp +++ b/editor/libeditor/text/nsTextEditRules.cpp @@ -182,6 +182,13 @@ nsTextEditRules::Init(nsPlaintextEditor *aEditor, PRUint32 aFlags) return res; } +NS_IMETHODIMP +nsTextEditRules::DetachEditor() +{ + mEditor = nsnull; + return NS_OK; +} + NS_IMETHODIMP nsTextEditRules::GetFlags(PRUint32 *aFlags) { diff --git a/editor/libeditor/text/nsTextEditRules.h b/editor/libeditor/text/nsTextEditRules.h index 7e467d2e928f..a4a16de61332 100644 --- a/editor/libeditor/text/nsTextEditRules.h +++ b/editor/libeditor/text/nsTextEditRules.h @@ -66,6 +66,7 @@ public: // nsIEditRules methods NS_IMETHOD Init(nsPlaintextEditor *aEditor, PRUint32 aFlags); + NS_IMETHOD DetachEditor(); NS_IMETHOD BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection); NS_IMETHOD AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection); NS_IMETHOD WillDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, PRBool *aCancel, PRBool *aHandled);