From 7447103b436798db81f00c40a9ab272465baee31 Mon Sep 17 00:00:00 2001 From: "mjudge%netscape.com" Date: Wed, 9 Oct 2002 02:10:22 +0000 Subject: [PATCH] 135774 r=cmanske sr=jag --- editor/composer/public/nsIEditingSession.idl | 8 ++- editor/composer/src/nsEditingSession.cpp | 66 ++++++++++++++------ editor/composer/src/nsEditingSession.h | 5 +- 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/editor/composer/public/nsIEditingSession.idl b/editor/composer/public/nsIEditingSession.idl index cdf6351938f..d6024df7c3f 100644 --- a/editor/composer/public/nsIEditingSession.idl +++ b/editor/composer/public/nsIEditingSession.idl @@ -44,6 +44,7 @@ interface nsIEditor; interface nsIEditingShell; [scriptable, uuid(D3B0AA04-F221-11D4-A73C-EAA4BAA8B4FC)] + interface nsIEditingSession : nsISupports { @@ -52,8 +53,11 @@ interface nsIEditingSession : nsISupports */ void init(in nsIDOMWindow aWindow); - /* Make this window editable */ - void makeWindowEditable(in nsIDOMWindow aWindow, in boolean inDoAfterUriLoad); + /* Make this window editable + * @param aWindow nsIDOMWindow, the window the embedder needs to make editable + * @param aEditorType string, "html" "htmlsimple" "text" "textsimple" + */ + void makeWindowEditable(in nsIDOMWindow aWindow, in string aEditorType, in boolean inDoAfterUriLoad); /* Test whether a specific window has had its editable flag set; it may have an editor now, or will get one after the uri load. diff --git a/editor/composer/src/nsEditingSession.cpp b/editor/composer/src/nsEditingSession.cpp index 52fa87251d3..755316f8f3c 100644 --- a/editor/composer/src/nsEditingSession.cpp +++ b/editor/composer/src/nsEditingSession.cpp @@ -65,6 +65,7 @@ #include "nsIContentViewer.h" #include "nsISelectionController.h" +#include "nsIPlaintextEditor.h" #if DEBUG @@ -77,7 +78,7 @@ ----------------------------------------------------------------------------*/ nsEditingSession::nsEditingSession() -: mDoneSetup(PR_FALSE) +: mDoneSetup(PR_FALSE), mEditorClassString(nsnull) { NS_INIT_ISUPPORTS(); } @@ -118,11 +119,39 @@ nsEditingSession::Init(nsIDOMWindow *aWindow) MakeWindowEditable - void makeWindowEditable (in nsIDOMWindow aWindow, in boolean inDoAfterUriLoad); + aEditorType string, "html" "htmlsimple" "text" "textsimple" + void makeWindowEditable(in nsIDOMWindow aWindow, in string aEditorType, in boolean inDoAfterUriLoad); ----------------------------------------------------------------------------*/ NS_IMETHODIMP -nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, PRBool inDoAfterUriLoad) +nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, const char *aEditorType, PRBool inDoAfterUriLoad) { + PRBool htmlController = PR_FALSE; + mEditorClassString = nsnull; + mEditorFlags = 0; + + //temporary to set editor type here. we will need different classes soon. + mEditorClassString = "@mozilla.org/editor/htmleditor;1"; + + if (!strcmp(aEditorType, "textmail")) + { + mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask | nsIPlaintextEditor::eEditorEnableWrapHackMask | nsIPlaintextEditor::eEditorMailMask; + } + else if (!strcmp(aEditorType, "text")) + { + mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask | nsIPlaintextEditor::eEditorEnableWrapHackMask; + } + else if (!strcmp(aEditorType, "htmlmail")) + { + htmlController = PR_TRUE; + mEditorFlags = nsIPlaintextEditor::eEditorMailMask; + } + else //if (!strcmp(aEditorType, "html")) or null is defaulted to html + { + htmlController = PR_TRUE; + } + if (!mEditorClassString) + return NS_ERROR_INVALID_ARG; + nsresult rv = PrepareForEditing(); if (NS_FAILED(rv)) return rv; @@ -134,16 +163,14 @@ nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, PRBool inDoAfterUriL rv = editorDocShell->MakeEditable(inDoAfterUriLoad); if (NS_FAILED(rv)) return rv; - rv = SetupFrameControllers(aWindow); + rv = SetupFrameControllers(aWindow, htmlController); if (NS_FAILED(rv)) return rv; - // make an editor immediately if (!inDoAfterUriLoad) { rv = SetupEditorOnWindow(aWindow); if (NS_FAILED(rv)) return rv; } - return NS_OK; } @@ -181,9 +208,8 @@ nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow) nsCOMPtr editorDocShell(do_QueryInterface(docShell, &rv)); if (NS_FAILED(rv)) return rv; - nsCOMPtr editor(do_CreateInstance("@mozilla.org/editor/htmleditor;1", &rv)); + nsCOMPtr editor(do_CreateInstance(mEditorClassString, &rv)); if (NS_FAILED(rv)) return rv; - // set the editor on the docShell. The docShell now owns it. rv = editorDocShell->SetEditor(editor); if (NS_FAILED(rv)) return rv; @@ -205,7 +231,7 @@ nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow) nsCOMPtr selCon = do_QueryInterface(presShell); - rv = editor->Init(domDoc, presShell, nsnull /* root content */, selCon, 0); + rv = editor->Init(domDoc, presShell, nsnull /* root content */, selCon, mEditorFlags); if (NS_FAILED(rv)) return rv; rv = editor->PostCreate(); @@ -608,7 +634,7 @@ nsEditingSession::PrepareForEditing() Set up the controller for this frame. ----------------------------------------------------------------------------*/ nsresult -nsEditingSession::SetupFrameControllers(nsIDOMWindow *inWindow) +nsEditingSession::SetupFrameControllers(nsIDOMWindow *inWindow, PRBool aSetupComposerController) { nsresult rv; @@ -630,17 +656,19 @@ nsEditingSession::SetupFrameControllers(nsIDOMWindow *inWindow) rv = controllers->InsertControllerAt(0, controller); if (NS_FAILED(rv)) return rv; - // the second is an composer controller, and also takes an nsIEditor as the refCon - controller = do_CreateInstance("@mozilla.org/editor/composercontroller;1", &rv); - if (NS_FAILED(rv)) return rv; + if (aSetupComposerController) + { + // the second is an composer controller, and also takes an nsIEditor as the refCon + controller = do_CreateInstance("@mozilla.org/editor/composercontroller;1", &rv); + if (NS_FAILED(rv)) return rv; - nsCOMPtr composerController(do_QueryInterface(controller)); - rv = composerController->Init(nsnull); // we set the editor later when we have one - if (NS_FAILED(rv)) return rv; - - rv = controllers->InsertControllerAt(1, controller); - if (NS_FAILED(rv)) return rv; + nsCOMPtr composerController(do_QueryInterface(controller)); + rv = composerController->Init(nsnull); // we set the editor later when we have one + if (NS_FAILED(rv)) return rv; + rv = controllers->InsertControllerAt(1, controller); + if (NS_FAILED(rv)) return rv; + } return NS_OK; } diff --git a/editor/composer/src/nsEditingSession.h b/editor/composer/src/nsEditingSession.h index d5c36e25662..a94490050df 100644 --- a/editor/composer/src/nsEditingSession.h +++ b/editor/composer/src/nsEditingSession.h @@ -93,7 +93,7 @@ protected: nsresult GetDocShellFromWindow(nsIDOMWindow *inWindow, nsIDocShell** outDocShell); nsresult GetEditorDocShellFromWindow(nsIDOMWindow *inWindow, nsIEditorDocShell** outDocShell); - nsresult SetupFrameControllers(nsIDOMWindow *inWindow); + nsresult SetupFrameControllers(nsIDOMWindow *inWindow, PRBool aSetupComposerController); nsresult SetEditorOnControllers(nsIDOMWindow *inWindow, nsIEditor* inEditor); @@ -113,7 +113,8 @@ protected: PRBool mDoneSetup; // have we prepared for editing yet? nsComposerCommandsUpdater *mStateMaintainer; // we hold the owning ref to this. - + const char * mEditorClassString; //we need this to hold onto the type for invoking editor after loading uri + PRUint32 mEditorFlags; };