From aacbb20c68448db0a13d8a52edfd010b8022bd69 Mon Sep 17 00:00:00 2001 From: "mjudge%netscape.com" Date: Fri, 28 Apr 2000 06:20:36 +0000 Subject: [PATCH] massive change to stop the editor fromknowing about nsIPresShell or nsIDocument git-svn-id: svn://10.0.0.236/trunk@67485 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/IMETextTxn.cpp | 12 ++++---- mozilla/editor/base/IMETextTxn.h | 8 ++--- mozilla/editor/base/InsertTextTxn.cpp | 1 - mozilla/editor/base/nsEditor.cpp | 21 ++++++++------ mozilla/editor/base/nsEditor.h | 5 +++- .../editor/base/nsEditorEventListeners.cpp | 29 ++----------------- mozilla/editor/base/nsEditorShell.cpp | 9 +++--- mozilla/editor/base/nsHTMLEditor.cpp | 4 +-- mozilla/editor/base/nsHTMLEditor.h | 2 +- mozilla/editor/base/nsHTMLEditorLog.cpp | 1 - mozilla/editor/composer/src/nsEditorShell.cpp | 9 +++--- mozilla/editor/libeditor/base/IMETextTxn.cpp | 12 ++++---- mozilla/editor/libeditor/base/IMETextTxn.h | 8 ++--- .../editor/libeditor/base/InsertTextTxn.cpp | 1 - mozilla/editor/libeditor/base/nsEditor.cpp | 21 ++++++++------ mozilla/editor/libeditor/base/nsEditor.h | 5 +++- .../editor/libeditor/html/nsHTMLEditor.cpp | 4 +-- mozilla/editor/libeditor/html/nsHTMLEditor.h | 2 +- .../editor/libeditor/html/nsHTMLEditorLog.cpp | 1 - .../libeditor/text/nsEditorEventListeners.cpp | 29 ++----------------- mozilla/editor/public/nsIEditor.h | 2 +- 21 files changed, 73 insertions(+), 113 deletions(-) diff --git a/mozilla/editor/base/IMETextTxn.cpp b/mozilla/editor/base/IMETextTxn.cpp index 1f899068bcd..36584629cae 100644 --- a/mozilla/editor/base/IMETextTxn.cpp +++ b/mozilla/editor/base/IMETextTxn.cpp @@ -67,7 +67,7 @@ NS_IMETHODIMP IMETextTxn::Init(nsIDOMCharacterData *aElement, PRUint32 aReplaceLength, nsIPrivateTextRangeList *aTextRangeList, const nsString &aStringToInsert, - nsWeakPtr aPresShellWeak) + nsWeakPtr aSelConWeak) { NS_ASSERTION(aElement, "illegal value- null ptr- aElement"); NS_ASSERTION(aTextRangeList, "illegal value- null ptr - aTextRangeList"); @@ -77,7 +77,7 @@ NS_IMETHODIMP IMETextTxn::Init(nsIDOMCharacterData *aElement, mOffset = aOffset; mReplaceLength = aReplaceLength; mStringToInsert = aStringToInsert; - mPresShellWeak = aPresShellWeak; + mSelConWeak = aSelConWeak; mRangeList = do_QueryInterface(aTextRangeList); mFixed = PR_FALSE; return NS_OK; @@ -90,8 +90,8 @@ NS_IMETHODIMP IMETextTxn::Do(void) printf("Do IME Text element = %p replace = %d len = %d\n", mElement.get(), mReplaceLength, mStringToInsert.Length()); #endif - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mSelConWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; // advance caret: This requires the presentation shell to get the selection. nsresult result = NS_OK; @@ -113,7 +113,7 @@ NS_IMETHODIMP IMETextTxn::Undo(void) printf("Undo IME Text element = %p\n", mElement.get()); #endif - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + nsCOMPtr selCon = do_QueryReferent(mSelConWeak); if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsresult result; @@ -309,7 +309,7 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void) // // run through the text range list, if any // - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + nsCOMPtr selCon = do_QueryReferent(mSelConWeak); if (!selCon) return NS_ERROR_NOT_INITIALIZED; result = mRangeList->GetLength(&textRangeListLength); diff --git a/mozilla/editor/base/IMETextTxn.h b/mozilla/editor/base/IMETextTxn.h index b56fe48f9ec..04e3cbafbbd 100644 --- a/mozilla/editor/base/IMETextTxn.h +++ b/mozilla/editor/base/IMETextTxn.h @@ -59,14 +59,14 @@ public: * @param aOffset the location in aElement to do the insertion * @param aReplaceLength the length of text to replace (0= no replacement) * @param aString the new text to insert - * @param aPresShell used to get and set the selection + * @param aSelCon used to get and set the selection */ NS_IMETHOD Init(nsIDOMCharacterData *aElement, PRUint32 aOffset, PRUint32 aReplaceLength, nsIPrivateTextRangeList* aTextRangeList, const nsString& aString, - nsWeakPtr aPresShell); + nsWeakPtr aSelCon); private: @@ -120,8 +120,8 @@ protected: /** the range list **/ nsCOMPtr mRangeList; - /** the presentation shell, which we'll need to get the selection */ - nsWeakPtr mPresShellWeak; // use a weak reference + /** the selection controller, which we'll need to get the selection */ + nsWeakPtr mSelConWeak; // use a weak reference PRBool mFixed; diff --git a/mozilla/editor/base/InsertTextTxn.cpp b/mozilla/editor/base/InsertTextTxn.cpp index 993f22e445e..1a60556dcff 100644 --- a/mozilla/editor/base/InsertTextTxn.cpp +++ b/mozilla/editor/base/InsertTextTxn.cpp @@ -24,7 +24,6 @@ #include "nsEditor.h" #include "nsIDOMCharacterData.h" #include "nsIDOMSelection.h" -#include "nsIPresShell.h" #include "EditAggregateTxn.h" static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID); diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index cfce5e8cbb7..6e52d4b11c3 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -825,8 +825,9 @@ NS_IMPL_QUERY_INTERFACE3(nsEditor, nsIEditor, nsIEditorIMESupport, nsISupportsWe #pragma mark - #endif + NS_IMETHODIMP -nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell, PRUint32 aFlags) +nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell, nsISelectionController *aSelCon, PRUint32 aFlags) { NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg"); if ((nsnull==aDoc) || (nsnull==aPresShell)) @@ -835,6 +836,7 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell, PRUint32 aFlags) mFlags = aFlags; mDocWeak = getter_AddRefs( NS_GetWeakReference(aDoc) ); // weak reference to doc mPresShellWeak = getter_AddRefs( NS_GetWeakReference(aPresShell) ); // weak reference to pres shell + mSelConWeak = getter_AddRefs( NS_GetWeakReference(aSelCon) ); // weak reference to selectioncontroller nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; @@ -914,7 +916,8 @@ nsEditor::GetDocument(nsIDOMDocument **aDoc) if (!mDocWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr doc = do_QueryReferent(mDocWeak); if (!doc) return NS_ERROR_NOT_INITIALIZED; - return doc->QueryInterface(NS_GET_IID(nsIDOMDocument), (void **)aDoc); + NS_ADDREF(*aDoc = doc); + return NS_OK; } @@ -939,9 +942,9 @@ nsEditor::GetSelectionController(nsISelectionController **aSel) if (!aSel) return NS_ERROR_NULL_POINTER; *aSel = nsnull; // init out param - NS_PRECONDITION(mPresShellWeak, "bad state, null mPresShellWeak"); - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + NS_PRECONDITION(mSelConWeak, "bad state, null mSelConWeak"); + if (!mSelConWeak) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mSelConWeak); if (!selCon) return NS_ERROR_NOT_INITIALIZED; NS_ADDREF(*aSel = selCon); return NS_OK; @@ -955,8 +958,8 @@ nsEditor::GetSelection(nsIDOMSelection **aSelection) if (!aSelection) return NS_ERROR_NULL_POINTER; *aSelection = nsnull; - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr selcon = do_QueryReferent(mPresShellWeak); + if (!mSelConWeak) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selcon = do_QueryReferent(mSelConWeak); if (!selcon) return NS_ERROR_NOT_INITIALIZED; nsresult result = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection); // does an addref return result; @@ -4928,7 +4931,7 @@ nsresult nsEditor::EndUpdateViewBatch() mViewManager->EndUpdateViewBatch(NS_VMREFRESH_IMMEDIATE); #endif nsCOMPtr presShell; - nsresult rv = GetPresShell(getter_AddRefs(presShell)); + rv = GetPresShell(getter_AddRefs(presShell)); if (NS_SUCCEEDED(rv) && presShell) presShell->EndReflowBatching(PR_TRUE); } @@ -5197,7 +5200,7 @@ nsEditor::CreateTxnForIMEText(const nsString & aStringToInsert, result = TransactionFactory::GetNewTransaction(IMETextTxn::GetCID(), (EditTxn **)aTxn); if (nsnull!=*aTxn) { - result = (*aTxn)->Init(mIMETextNode,mIMETextOffset,mIMEBufferLength,mIMETextRangeList,aStringToInsert,mPresShellWeak); + result = (*aTxn)->Init(mIMETextNode,mIMETextOffset,mIMEBufferLength,mIMETextRangeList,aStringToInsert,mSelConWeak); } else { result = NS_ERROR_OUT_OF_MEMORY; diff --git a/mozilla/editor/base/nsEditor.h b/mozilla/editor/base/nsEditor.h index 4b5d20f9bb1..ddf12e66c7f 100644 --- a/mozilla/editor/base/nsEditor.h +++ b/mozilla/editor/base/nsEditor.h @@ -70,6 +70,8 @@ class IMETextTxn; class AddStyleSheetTxn; class RemoveStyleSheetTxn; class nsFileSpec; +class nsISelectionController; + /*************************************************************************** * class for recording selection info. stores selection as collection of @@ -187,7 +189,7 @@ public: NS_DECL_ISUPPORTS /* ------------ nsIEditor methods -------------- */ - NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, PRUint32 aFlags); + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, nsISelectionController *aSelCon, PRUint32 aFlags); NS_IMETHOD PostCreate(); NS_IMETHOD GetFlags(PRUint32 *aFlags) = 0; NS_IMETHOD SetFlags(PRUint32 aFlags) = 0; @@ -725,6 +727,7 @@ protected: PRUint32 mFlags; // behavior flags. See nsIHTMLEditor.h for the flags we use. nsWeakPtr mPresShellWeak; // weak reference to the nsIPresShell + nsWeakPtr mSelConWeak; // weak reference to the nsISelectionController nsIViewManager *mViewManager; PRInt32 mUpdateCount; nsCOMPtr mTxnMgr; diff --git a/mozilla/editor/base/nsEditorEventListeners.cpp b/mozilla/editor/base/nsEditorEventListeners.cpp index a9685174f13..9432e43e5cb 100644 --- a/mozilla/editor/base/nsEditorEventListeners.cpp +++ b/mozilla/editor/base/nsEditorEventListeners.cpp @@ -477,12 +477,6 @@ nsTextEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent) if (!editor) { return NS_OK; } - // get the document - nsCOMPtrdomDoc; - editor->GetDocument(getter_AddRefs(domDoc)); - if (!domDoc) { return NS_OK; } - nsCOMPtrdoc = do_QueryInterface(domDoc); - if (!doc) { return NS_OK; } PRUint16 button = 0; mouseEvent->GetButton(&button); @@ -1083,16 +1077,7 @@ nsTextEditorFocusListener::Focus(nsIDOMEvent* aEvent) selCon->SetCaretEnabled(PR_TRUE); } - nsCOMPtrdomDoc; - editor->GetDocument(getter_AddRefs(domDoc)); - if (domDoc) - { - nsCOMPtrdoc = do_QueryInterface(domDoc); - if (doc) - { - doc->SetDisplaySelection(nsIDocument::SELECTION_ON); - } - } + selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); #ifdef USE_HACK_REPAINT // begin hack repaint nsCOMPtr viewmgr; @@ -1131,17 +1116,7 @@ nsTextEditorFocusListener::Blur(nsIDOMEvent* aEvent) if (selCon) { selCon->SetCaretEnabled(PR_FALSE); - - nsCOMPtrdomDoc; - editor->GetDocument(getter_AddRefs(domDoc)); - if (domDoc) - { - nsCOMPtrdoc = do_QueryInterface(domDoc); - if (doc) - { - doc->SetDisplaySelection(nsIDocument::SELECTION_DISABLED); - } - } + selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED); #ifdef USE_HACK_REPAINT // begin hack repaint nsCOMPtr viewmgr; diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index 0b9b1c6f7b7..2dea300809e 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -602,22 +602,23 @@ nsEditorShell::InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell) err = nsComponentManager::CreateInstance(kHTMLEditorCID, nsnull, NS_GET_IID(nsIEditor), getter_AddRefs(editor)); if(!editor) err = NS_ERROR_OUT_OF_MEMORY; - + nsCOMPtr selCon = do_QueryInterface(aPresShell); + if (NS_SUCCEEDED(err)) { if (mEditorTypeString.EqualsWithConversion("text")) { - err = editor->Init(aDoc, aPresShell, nsIHTMLEditor::eEditorPlaintextMask); + err = editor->Init(aDoc, aPresShell, selCon, nsIHTMLEditor::eEditorPlaintextMask); mEditorType = ePlainTextEditorType; } else if (mEditorTypeString.EqualsWithConversion("html") || mEditorTypeString.IsEmpty()) // empty string default to HTML editor { - err = editor->Init(aDoc, aPresShell, 0); + err = editor->Init(aDoc, aPresShell, selCon, 0); mEditorType = eHTMLTextEditorType; } else if (mEditorTypeString.EqualsWithConversion("htmlmail")) // HTML editor with special mail rules { - err = editor->Init(aDoc, aPresShell, nsIHTMLEditor::eEditorMailMask); + err = editor->Init(aDoc, aPresShell, selCon, nsIHTMLEditor::eEditorMailMask); mEditorType = eHTMLTextEditorType; } else diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index 2e33c879dd0..67e7fae0284 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -380,7 +380,7 @@ NS_IMETHODIMP nsHTMLEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc, - nsIPresShell *aPresShell, PRUint32 aFlags) + nsIPresShell *aPresShell, nsISelectionController *aSelCon, PRUint32 aFlags) { NS_PRECONDITION(aDoc && aPresShell, "bad arg"); if (!aDoc || !aPresShell) @@ -388,7 +388,7 @@ NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsresult result = NS_ERROR_NULL_POINTER; // Init the base editor - result = nsEditor::Init(aDoc, aPresShell, aFlags); + result = nsEditor::Init(aDoc, aPresShell, aSelCon, aFlags); if (NS_FAILED(result)) { return result; } nsCOMPtr bodyElement; diff --git a/mozilla/editor/base/nsHTMLEditor.h b/mozilla/editor/base/nsHTMLEditor.h index 85379b31f1d..4f2187ab52c 100644 --- a/mozilla/editor/base/nsHTMLEditor.h +++ b/mozilla/editor/base/nsHTMLEditor.h @@ -242,7 +242,7 @@ public: /* ------------ Overrides of nsEditor interface methods -------------- */ /** prepare the editor for use */ - NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, PRUint32 aFlags); + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, nsISelectionController *aSelCon, PRUint32 aFlags); NS_IMETHOD SetDocumentCharacterSet(const PRUnichar* characterSet); diff --git a/mozilla/editor/base/nsHTMLEditorLog.cpp b/mozilla/editor/base/nsHTMLEditorLog.cpp index f6e5d3b9ba7..2b1a7386654 100644 --- a/mozilla/editor/base/nsHTMLEditorLog.cpp +++ b/mozilla/editor/base/nsHTMLEditorLog.cpp @@ -22,7 +22,6 @@ */ #include -#include "nsIPresShell.h" #include "nsIDOMElement.h" #include "nsIDOMAttr.h" #include "nsIDOMNode.h" diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 0b9b1c6f7b7..2dea300809e 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -602,22 +602,23 @@ nsEditorShell::InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell) err = nsComponentManager::CreateInstance(kHTMLEditorCID, nsnull, NS_GET_IID(nsIEditor), getter_AddRefs(editor)); if(!editor) err = NS_ERROR_OUT_OF_MEMORY; - + nsCOMPtr selCon = do_QueryInterface(aPresShell); + if (NS_SUCCEEDED(err)) { if (mEditorTypeString.EqualsWithConversion("text")) { - err = editor->Init(aDoc, aPresShell, nsIHTMLEditor::eEditorPlaintextMask); + err = editor->Init(aDoc, aPresShell, selCon, nsIHTMLEditor::eEditorPlaintextMask); mEditorType = ePlainTextEditorType; } else if (mEditorTypeString.EqualsWithConversion("html") || mEditorTypeString.IsEmpty()) // empty string default to HTML editor { - err = editor->Init(aDoc, aPresShell, 0); + err = editor->Init(aDoc, aPresShell, selCon, 0); mEditorType = eHTMLTextEditorType; } else if (mEditorTypeString.EqualsWithConversion("htmlmail")) // HTML editor with special mail rules { - err = editor->Init(aDoc, aPresShell, nsIHTMLEditor::eEditorMailMask); + err = editor->Init(aDoc, aPresShell, selCon, nsIHTMLEditor::eEditorMailMask); mEditorType = eHTMLTextEditorType; } else diff --git a/mozilla/editor/libeditor/base/IMETextTxn.cpp b/mozilla/editor/libeditor/base/IMETextTxn.cpp index 1f899068bcd..36584629cae 100644 --- a/mozilla/editor/libeditor/base/IMETextTxn.cpp +++ b/mozilla/editor/libeditor/base/IMETextTxn.cpp @@ -67,7 +67,7 @@ NS_IMETHODIMP IMETextTxn::Init(nsIDOMCharacterData *aElement, PRUint32 aReplaceLength, nsIPrivateTextRangeList *aTextRangeList, const nsString &aStringToInsert, - nsWeakPtr aPresShellWeak) + nsWeakPtr aSelConWeak) { NS_ASSERTION(aElement, "illegal value- null ptr- aElement"); NS_ASSERTION(aTextRangeList, "illegal value- null ptr - aTextRangeList"); @@ -77,7 +77,7 @@ NS_IMETHODIMP IMETextTxn::Init(nsIDOMCharacterData *aElement, mOffset = aOffset; mReplaceLength = aReplaceLength; mStringToInsert = aStringToInsert; - mPresShellWeak = aPresShellWeak; + mSelConWeak = aSelConWeak; mRangeList = do_QueryInterface(aTextRangeList); mFixed = PR_FALSE; return NS_OK; @@ -90,8 +90,8 @@ NS_IMETHODIMP IMETextTxn::Do(void) printf("Do IME Text element = %p replace = %d len = %d\n", mElement.get(), mReplaceLength, mStringToInsert.Length()); #endif - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mSelConWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; // advance caret: This requires the presentation shell to get the selection. nsresult result = NS_OK; @@ -113,7 +113,7 @@ NS_IMETHODIMP IMETextTxn::Undo(void) printf("Undo IME Text element = %p\n", mElement.get()); #endif - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + nsCOMPtr selCon = do_QueryReferent(mSelConWeak); if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsresult result; @@ -309,7 +309,7 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void) // // run through the text range list, if any // - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + nsCOMPtr selCon = do_QueryReferent(mSelConWeak); if (!selCon) return NS_ERROR_NOT_INITIALIZED; result = mRangeList->GetLength(&textRangeListLength); diff --git a/mozilla/editor/libeditor/base/IMETextTxn.h b/mozilla/editor/libeditor/base/IMETextTxn.h index b56fe48f9ec..04e3cbafbbd 100644 --- a/mozilla/editor/libeditor/base/IMETextTxn.h +++ b/mozilla/editor/libeditor/base/IMETextTxn.h @@ -59,14 +59,14 @@ public: * @param aOffset the location in aElement to do the insertion * @param aReplaceLength the length of text to replace (0= no replacement) * @param aString the new text to insert - * @param aPresShell used to get and set the selection + * @param aSelCon used to get and set the selection */ NS_IMETHOD Init(nsIDOMCharacterData *aElement, PRUint32 aOffset, PRUint32 aReplaceLength, nsIPrivateTextRangeList* aTextRangeList, const nsString& aString, - nsWeakPtr aPresShell); + nsWeakPtr aSelCon); private: @@ -120,8 +120,8 @@ protected: /** the range list **/ nsCOMPtr mRangeList; - /** the presentation shell, which we'll need to get the selection */ - nsWeakPtr mPresShellWeak; // use a weak reference + /** the selection controller, which we'll need to get the selection */ + nsWeakPtr mSelConWeak; // use a weak reference PRBool mFixed; diff --git a/mozilla/editor/libeditor/base/InsertTextTxn.cpp b/mozilla/editor/libeditor/base/InsertTextTxn.cpp index 993f22e445e..1a60556dcff 100644 --- a/mozilla/editor/libeditor/base/InsertTextTxn.cpp +++ b/mozilla/editor/libeditor/base/InsertTextTxn.cpp @@ -24,7 +24,6 @@ #include "nsEditor.h" #include "nsIDOMCharacterData.h" #include "nsIDOMSelection.h" -#include "nsIPresShell.h" #include "EditAggregateTxn.h" static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID); diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index cfce5e8cbb7..6e52d4b11c3 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -825,8 +825,9 @@ NS_IMPL_QUERY_INTERFACE3(nsEditor, nsIEditor, nsIEditorIMESupport, nsISupportsWe #pragma mark - #endif + NS_IMETHODIMP -nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell, PRUint32 aFlags) +nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell, nsISelectionController *aSelCon, PRUint32 aFlags) { NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg"); if ((nsnull==aDoc) || (nsnull==aPresShell)) @@ -835,6 +836,7 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell, PRUint32 aFlags) mFlags = aFlags; mDocWeak = getter_AddRefs( NS_GetWeakReference(aDoc) ); // weak reference to doc mPresShellWeak = getter_AddRefs( NS_GetWeakReference(aPresShell) ); // weak reference to pres shell + mSelConWeak = getter_AddRefs( NS_GetWeakReference(aSelCon) ); // weak reference to selectioncontroller nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; @@ -914,7 +916,8 @@ nsEditor::GetDocument(nsIDOMDocument **aDoc) if (!mDocWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr doc = do_QueryReferent(mDocWeak); if (!doc) return NS_ERROR_NOT_INITIALIZED; - return doc->QueryInterface(NS_GET_IID(nsIDOMDocument), (void **)aDoc); + NS_ADDREF(*aDoc = doc); + return NS_OK; } @@ -939,9 +942,9 @@ nsEditor::GetSelectionController(nsISelectionController **aSel) if (!aSel) return NS_ERROR_NULL_POINTER; *aSel = nsnull; // init out param - NS_PRECONDITION(mPresShellWeak, "bad state, null mPresShellWeak"); - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + NS_PRECONDITION(mSelConWeak, "bad state, null mSelConWeak"); + if (!mSelConWeak) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mSelConWeak); if (!selCon) return NS_ERROR_NOT_INITIALIZED; NS_ADDREF(*aSel = selCon); return NS_OK; @@ -955,8 +958,8 @@ nsEditor::GetSelection(nsIDOMSelection **aSelection) if (!aSelection) return NS_ERROR_NULL_POINTER; *aSelection = nsnull; - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr selcon = do_QueryReferent(mPresShellWeak); + if (!mSelConWeak) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selcon = do_QueryReferent(mSelConWeak); if (!selcon) return NS_ERROR_NOT_INITIALIZED; nsresult result = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection); // does an addref return result; @@ -4928,7 +4931,7 @@ nsresult nsEditor::EndUpdateViewBatch() mViewManager->EndUpdateViewBatch(NS_VMREFRESH_IMMEDIATE); #endif nsCOMPtr presShell; - nsresult rv = GetPresShell(getter_AddRefs(presShell)); + rv = GetPresShell(getter_AddRefs(presShell)); if (NS_SUCCEEDED(rv) && presShell) presShell->EndReflowBatching(PR_TRUE); } @@ -5197,7 +5200,7 @@ nsEditor::CreateTxnForIMEText(const nsString & aStringToInsert, result = TransactionFactory::GetNewTransaction(IMETextTxn::GetCID(), (EditTxn **)aTxn); if (nsnull!=*aTxn) { - result = (*aTxn)->Init(mIMETextNode,mIMETextOffset,mIMEBufferLength,mIMETextRangeList,aStringToInsert,mPresShellWeak); + result = (*aTxn)->Init(mIMETextNode,mIMETextOffset,mIMEBufferLength,mIMETextRangeList,aStringToInsert,mSelConWeak); } else { result = NS_ERROR_OUT_OF_MEMORY; diff --git a/mozilla/editor/libeditor/base/nsEditor.h b/mozilla/editor/libeditor/base/nsEditor.h index 4b5d20f9bb1..ddf12e66c7f 100644 --- a/mozilla/editor/libeditor/base/nsEditor.h +++ b/mozilla/editor/libeditor/base/nsEditor.h @@ -70,6 +70,8 @@ class IMETextTxn; class AddStyleSheetTxn; class RemoveStyleSheetTxn; class nsFileSpec; +class nsISelectionController; + /*************************************************************************** * class for recording selection info. stores selection as collection of @@ -187,7 +189,7 @@ public: NS_DECL_ISUPPORTS /* ------------ nsIEditor methods -------------- */ - NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, PRUint32 aFlags); + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, nsISelectionController *aSelCon, PRUint32 aFlags); NS_IMETHOD PostCreate(); NS_IMETHOD GetFlags(PRUint32 *aFlags) = 0; NS_IMETHOD SetFlags(PRUint32 aFlags) = 0; @@ -725,6 +727,7 @@ protected: PRUint32 mFlags; // behavior flags. See nsIHTMLEditor.h for the flags we use. nsWeakPtr mPresShellWeak; // weak reference to the nsIPresShell + nsWeakPtr mSelConWeak; // weak reference to the nsISelectionController nsIViewManager *mViewManager; PRInt32 mUpdateCount; nsCOMPtr mTxnMgr; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index 2e33c879dd0..67e7fae0284 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -380,7 +380,7 @@ NS_IMETHODIMP nsHTMLEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc, - nsIPresShell *aPresShell, PRUint32 aFlags) + nsIPresShell *aPresShell, nsISelectionController *aSelCon, PRUint32 aFlags) { NS_PRECONDITION(aDoc && aPresShell, "bad arg"); if (!aDoc || !aPresShell) @@ -388,7 +388,7 @@ NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsresult result = NS_ERROR_NULL_POINTER; // Init the base editor - result = nsEditor::Init(aDoc, aPresShell, aFlags); + result = nsEditor::Init(aDoc, aPresShell, aSelCon, aFlags); if (NS_FAILED(result)) { return result; } nsCOMPtr bodyElement; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h index 85379b31f1d..4f2187ab52c 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h @@ -242,7 +242,7 @@ public: /* ------------ Overrides of nsEditor interface methods -------------- */ /** prepare the editor for use */ - NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, PRUint32 aFlags); + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, nsISelectionController *aSelCon, PRUint32 aFlags); NS_IMETHOD SetDocumentCharacterSet(const PRUnichar* characterSet); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditorLog.cpp b/mozilla/editor/libeditor/html/nsHTMLEditorLog.cpp index f6e5d3b9ba7..2b1a7386654 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditorLog.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditorLog.cpp @@ -22,7 +22,6 @@ */ #include -#include "nsIPresShell.h" #include "nsIDOMElement.h" #include "nsIDOMAttr.h" #include "nsIDOMNode.h" diff --git a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp index a9685174f13..9432e43e5cb 100644 --- a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp @@ -477,12 +477,6 @@ nsTextEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent) if (!editor) { return NS_OK; } - // get the document - nsCOMPtrdomDoc; - editor->GetDocument(getter_AddRefs(domDoc)); - if (!domDoc) { return NS_OK; } - nsCOMPtrdoc = do_QueryInterface(domDoc); - if (!doc) { return NS_OK; } PRUint16 button = 0; mouseEvent->GetButton(&button); @@ -1083,16 +1077,7 @@ nsTextEditorFocusListener::Focus(nsIDOMEvent* aEvent) selCon->SetCaretEnabled(PR_TRUE); } - nsCOMPtrdomDoc; - editor->GetDocument(getter_AddRefs(domDoc)); - if (domDoc) - { - nsCOMPtrdoc = do_QueryInterface(domDoc); - if (doc) - { - doc->SetDisplaySelection(nsIDocument::SELECTION_ON); - } - } + selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); #ifdef USE_HACK_REPAINT // begin hack repaint nsCOMPtr viewmgr; @@ -1131,17 +1116,7 @@ nsTextEditorFocusListener::Blur(nsIDOMEvent* aEvent) if (selCon) { selCon->SetCaretEnabled(PR_FALSE); - - nsCOMPtrdomDoc; - editor->GetDocument(getter_AddRefs(domDoc)); - if (domDoc) - { - nsCOMPtrdoc = do_QueryInterface(domDoc); - if (doc) - { - doc->SetDisplaySelection(nsIDocument::SELECTION_DISABLED); - } - } + selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED); #ifdef USE_HACK_REPAINT // begin hack repaint nsCOMPtr viewmgr; diff --git a/mozilla/editor/public/nsIEditor.h b/mozilla/editor/public/nsIEditor.h index 2058400594f..baabc8692c7 100644 --- a/mozilla/editor/public/nsIEditor.h +++ b/mozilla/editor/public/nsIEditor.h @@ -72,7 +72,7 @@ public: * linked to a single pres shell. * @param aFlags A bitmask of flags for specifying the behavior of the editor. */ - NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, PRUint32 aFlags)=0; + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, nsISelectionController *aSelCon, PRUint32 aFlags)=0; /** * PostCreate should be called after Init, and is the time that the editor tells