diff --git a/mozilla/content/base/public/nsContentCID.h b/mozilla/content/base/public/nsContentCID.h index 9b4dd7590d3..c9a10a2ff85 100644 --- a/mozilla/content/base/public/nsContentCID.h +++ b/mozilla/content/base/public/nsContentCID.h @@ -254,10 +254,6 @@ { 0x76e92881, 0xcddb, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } -// {508f5601-e09b-11d3-9f7e-cf931f9f173c} -#define NS_CONTROLLERCOMMANDMANAGER_CID \ -{ 0x508f5601, 0xe09b, 0x11d3, { 0x9f, 0x7e, 0xcf, 0x93, 0x1f, 0x9f, 0x17, 0x3c } } - // {BFD05264-834C-11d2-8EAC-00805F29F371} #define NS_XULSORTSERVICE_CID \ { 0xbfd05264, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x71 } } diff --git a/mozilla/content/build/nsContentCID.h b/mozilla/content/build/nsContentCID.h index 9b4dd7590d3..c9a10a2ff85 100644 --- a/mozilla/content/build/nsContentCID.h +++ b/mozilla/content/build/nsContentCID.h @@ -254,10 +254,6 @@ { 0x76e92881, 0xcddb, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } -// {508f5601-e09b-11d3-9f7e-cf931f9f173c} -#define NS_CONTROLLERCOMMANDMANAGER_CID \ -{ 0x508f5601, 0xe09b, 0x11d3, { 0x9f, 0x7e, 0xcf, 0x93, 0x1f, 0x9f, 0x17, 0x3c } } - // {BFD05264-834C-11d2-8EAC-00805F29F371} #define NS_XULSORTSERVICE_CID \ { 0xbfd05264, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x71 } } diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index c42bd04170f..d5fda1c4f83 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -43,7 +43,6 @@ #include "nsIRadioVisitor.h" #include "nsIControllers.h" -#include "nsIEditorController.h" #include "nsIFocusController.h" #include "nsPIDOMWindow.h" #include "nsIScriptGlobalObject.h" @@ -1990,17 +1989,6 @@ nsHTMLInputElement::GetControllers(nsIControllers** aResult) controller(do_CreateInstance("@mozilla.org/editor/editorcontroller;1", &rv)); if (NS_FAILED(rv)) return rv; - - nsCOMPtr - editorController = do_QueryInterface(controller, &rv); - - if (NS_FAILED(rv)) - return rv; - - rv = editorController->Init(nsnull); - if (NS_FAILED(rv)) - return rv; - mControllers->AppendController(controller); } } diff --git a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp index c8cec063f39..05efff398cf 100644 --- a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -40,7 +40,6 @@ #include "nsIDOMNSHTMLTextAreaElement.h" #include "nsITextControlElement.h" #include "nsIControllers.h" -#include "nsIEditorController.h" #include "nsContentCID.h" #include "nsCOMPtr.h" #include "nsIComponentManager.h" @@ -818,14 +817,6 @@ nsHTMLTextAreaElement::GetControllers(nsIControllers** aResult) if (NS_FAILED(rv)) return rv; - nsCOMPtr editorController = do_QueryInterface(controller, &rv); - if (NS_FAILED(rv)) - return rv; - - rv = editorController->Init(nsnull); - if (NS_FAILED(rv)) - return rv; - mControllers->AppendController(controller); } diff --git a/mozilla/content/xul/document/src/nsXULControllers.cpp b/mozilla/content/xul/document/src/nsXULControllers.cpp index b5fd353ce83..08881fe8a94 100644 --- a/mozilla/content/xul/document/src/nsXULControllers.cpp +++ b/mozilla/content/xul/document/src/nsXULControllers.cpp @@ -203,7 +203,8 @@ nsXULControllers::GetControllerAt(PRUint32 aIndex, nsIController **_retval) NS_IMETHODIMP nsXULControllers::AppendController(nsIController *controller) { - nsXULControllerData* controllerData = new nsXULControllerData(mCurControllerID++, controller); + // This assigns controller IDs starting at 1 so we can use 0 to test if an ID was obtained + nsXULControllerData* controllerData = new nsXULControllerData(++mCurControllerID, controller); if (!controllerData) return NS_ERROR_OUT_OF_MEMORY; PRBool appended = mControllers.AppendElement((void *)controllerData); NS_ASSERTION(appended, "Appending controller failed"); diff --git a/mozilla/editor/composer/public/nsIEditingSession.idl b/mozilla/editor/composer/public/nsIEditingSession.idl index d6024df7c3f..bc6021a837a 100644 --- a/mozilla/editor/composer/public/nsIEditingSession.idl +++ b/mozilla/editor/composer/public/nsIEditingSession.idl @@ -20,7 +20,9 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Simon Fraser + * Simon Fraser + * Mike Judge + * Charles Manske * * * Alternatively, the contents of this file may be used under the terms of @@ -47,32 +49,58 @@ interface nsIEditingShell; interface nsIEditingSession : nsISupports { + /** + * Error codes when we fail to create an editor + * is placed in attribute editorStatus + */ + const long eEditorOK = 0; + const long eEditorCreationInProgress = 1; + const long eEditorErrorCantEditMimeType = 2; + const long eEditorErrorFileNotFound = 3; + const long eEditorErrorCantEditFramesets = 8; + const long eEditorErrorUnknown = 9; + + /** + * Status after editor creation and document loading + * Value is one of the above error codes + */ + readonly attribute unsigned long editorStatus; /* Init the editing session, passing the window that will be the root of - the session (usually the content root frame. - */ - void init(in nsIDOMWindow aWindow); + * the session (usually the content root frame) + */ + void init(in nsIDOMWindow window); - /* Make this window editable + /** + * 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); + void makeWindowEditable(in nsIDOMWindow window, in string aEditorType, in boolean doAfterUriLoad); - /* 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. - - Use this, passing the content root window, to test if we've set up editing - for this content. - */ - boolean windowIsEditable(in nsIDOMWindow aWindow); + /** + * 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. + * + * Use this, passing the content root window, to test if we've set up editing + * for this content. + */ + boolean windowIsEditable(in nsIDOMWindow window); - /* Get the editor for this window. May return null */ - nsIEditor getEditorForWindow(in nsIDOMWindow aWindow); + /** + * Get the editor for this window. May return null + */ + nsIEditor getEditorForWindow(in nsIDOMWindow window); - /* lower level */ - void setupEditorOnWindow(in nsIDOMWindow aWindow); - void tearDownEditorOnWindow(in nsIDOMWindow aWindow); + /** + * Setup editor and related support objects + */ + void setupEditorOnWindow(in nsIDOMWindow window); + + /** + * Destroy editor and related support objects + */ + void tearDownEditorOnWindow(in nsIDOMWindow window); }; diff --git a/mozilla/editor/composer/src/Makefile.in b/mozilla/editor/composer/src/Makefile.in index 8f526c6594a..1b3a9432f2f 100644 --- a/mozilla/editor/composer/src/Makefile.in +++ b/mozilla/editor/composer/src/Makefile.in @@ -61,7 +61,6 @@ REQUIRES = xpcom \ $(NULL) CPPSRCS = \ - nsEditorShell.cpp \ nsEditorParserObserver.cpp \ nsInterfaceState.cpp \ nsComposerController.cpp \ diff --git a/mozilla/editor/composer/src/nsComposerCommands.cpp b/mozilla/editor/composer/src/nsComposerCommands.cpp index 568a07fd9ee..c3388a8e2ec 100644 --- a/mozilla/editor/composer/src/nsComposerCommands.cpp +++ b/mozilla/editor/composer/src/nsComposerCommands.cpp @@ -22,6 +22,7 @@ * Contributor(s): * Ryan Cassin * Daniel Glazman + * Charles Manske * * * Alternatively, the contents of this file may be used under the terms of @@ -41,6 +42,7 @@ #include "nsIEditor.h" #include "nsIHTMLEditor.h" +#include "nsIEditingSession.h" #include "nsIDOMElement.h" #include "nsIDOMWindowInternal.h" @@ -58,11 +60,14 @@ #include "nsCRT.h" //prototype nsresult GetListState(nsIEditor *aEditor, PRBool *aMixed, PRUnichar **tagStr); -nsresult PasteAsQuotation(nsIEditor *aEditor, PRInt32 aSelectionType); -nsresult RemoveOneProperty(nsIHTMLEditor *aEditor,const nsString& aProp, const nsString &aAttr); -nsresult RemoveTextProperty(nsIEditor *aEditor, const PRUnichar *prop, const PRUnichar *attr); -nsresult SetTextProperty(nsIEditor *aEditor, const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value); -nsresult GetListItemState(nsIEditor *aEditor, PRBool *aMixed, PRUnichar **_retval); +nsresult RemoveOneProperty(nsIHTMLEditor *aEditor,const nsString& aProp, + const nsString &aAttr); +nsresult RemoveTextProperty(nsIEditor *aEditor, const PRUnichar *prop, + const PRUnichar *attr); +nsresult SetTextProperty(nsIEditor *aEditor, const PRUnichar *prop, + const PRUnichar *attr, const PRUnichar *value); +nsresult GetListItemState(nsIEditor *aEditor, PRBool *aMixed, + PRUnichar **_retval); //defines @@ -73,7 +78,7 @@ nsresult GetListItemState(nsIEditor *aEditor, PRBool *aMixed, PRUnichar **_retva #define STATE_BEGIN "state_begin" #define STATE_END "state_end" #define STATE_MIXED "state_mixed" - +#define STATE_DATA "state_data" nsBaseComposerCommand::nsBaseComposerCommand() @@ -104,7 +109,9 @@ nsBaseStateUpdatingCommand::~nsBaseStateUpdatingCommand() NS_IMPL_ISUPPORTS_INHERITED0(nsBaseStateUpdatingCommand, nsBaseComposerCommand); NS_IMETHODIMP -nsBaseStateUpdatingCommand::IsCommandEnabled(const char *aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) +nsBaseStateUpdatingCommand::IsCommandEnabled(const char *aCommandName, + nsISupports *refCon, + PRBool *outCmdEnabled) { nsCOMPtr editor = do_QueryInterface(refCon); *outCmdEnabled = editor ? PR_TRUE : PR_FALSE; @@ -113,7 +120,8 @@ nsBaseStateUpdatingCommand::IsCommandEnabled(const char *aCommandName, nsISuppor NS_IMETHODIMP -nsBaseStateUpdatingCommand::DoCommand(const char *aCommandName, nsISupports *refCon) +nsBaseStateUpdatingCommand::DoCommand(const char *aCommandName, + nsISupports *refCon) { nsCOMPtr editor = do_QueryInterface(refCon); if (!editor) return NS_ERROR_NOT_INITIALIZED; @@ -122,7 +130,9 @@ nsBaseStateUpdatingCommand::DoCommand(const char *aCommandName, nsISupports *ref } NS_IMETHODIMP -nsBaseStateUpdatingCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsBaseStateUpdatingCommand::DoCommandParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { nsCOMPtr editor = do_QueryInterface(refCon); if (!editor) @@ -135,100 +145,43 @@ nsBaseStateUpdatingCommand::DoCommandParams(const char *aCommandName, nsICommand } NS_IMETHODIMP -nsBaseStateUpdatingCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) -{ - nsCOMPtr editor = do_QueryInterface(refCon); - nsresult rv = NS_OK; - if (editor) - { - rv = GetCurrentState(editor, mTagName, aParams); - } - return rv; -} - -#ifdef XP_MAC -#pragma mark - -#endif - -NS_IMETHODIMP -nsPasteQuotationCommand::IsCommandEnabled(const char * aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) +nsBaseStateUpdatingCommand::GetCommandStateParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { nsCOMPtr editor = do_QueryInterface(refCon); if (editor) - editor->CanPaste(nsIClipboard::kGlobalClipboard, outCmdEnabled); - else - *outCmdEnabled = PR_FALSE; + return GetCurrentState(editor, mTagName, aParams); return NS_OK; } - NS_IMETHODIMP -nsPasteQuotationCommand::DoCommand(const char *aCommandName, nsISupports *refCon) -{ - nsCOMPtr editor = do_QueryInterface(refCon); - - nsresult rv = NS_OK; - if (editor) - { - rv = PasteAsQuotation(editor,nsIClipboard::kGlobalClipboard); - } - - return rv; -} - -NS_IMETHODIMP -nsPasteQuotationCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) -{ - nsCOMPtr editor = do_QueryInterface(refCon); - - nsresult rv = NS_OK; - if (editor) - { - rv = PasteAsQuotation(editor,nsIClipboard::kGlobalClipboard); - } - - return rv; -} - -NS_IMETHODIMP -nsPasteQuotationCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) -{ - nsCOMPtr editor = do_QueryInterface(refCon); - PRBool enabled = PR_FALSE; - if (editor) - { - editor->CanPaste(nsIClipboard::kGlobalClipboard, &enabled); - aParams->SetBooleanValue(STATE_ENABLED,enabled); - } - - return NS_OK; -} - -#ifdef XP_MAC -#pragma mark - -#endif - -NS_IMETHODIMP -nsPasteNoFormattingCommand::IsCommandEnabled(const char * aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) +nsPasteNoFormattingCommand::IsCommandEnabled(const char * aCommandName, + nsISupports *refCon, + PRBool *outCmdEnabled) { NS_ENSURE_ARG_POINTER(outCmdEnabled); *outCmdEnabled = PR_FALSE; + // This command is only implemented by nsIHTMLEditor, since + // pasting in a plaintext editor automatically only supples + // "unformated" text nsCOMPtr htmlEditor(do_QueryInterface(refCon)); if (!htmlEditor) - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; nsCOMPtr editor(do_QueryInterface(htmlEditor)); if (!editor) - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_INVALID_ARG; return editor->CanPaste(nsIClipboard::kGlobalClipboard, outCmdEnabled); } NS_IMETHODIMP -nsPasteNoFormattingCommand::DoCommand(const char *aCommandName, nsISupports *refCon) +nsPasteNoFormattingCommand::DoCommand(const char *aCommandName, + nsISupports *refCon) { nsCOMPtr htmlEditor(do_QueryInterface(refCon)); if (!htmlEditor) @@ -238,7 +191,9 @@ nsPasteNoFormattingCommand::DoCommand(const char *aCommandName, nsISupports *ref } NS_IMETHODIMP -nsPasteNoFormattingCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsPasteNoFormattingCommand::DoCommandParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { nsCOMPtr htmlEditor(do_QueryInterface(refCon)); if (!htmlEditor) @@ -248,7 +203,9 @@ nsPasteNoFormattingCommand::DoCommandParams(const char *aCommandName, nsICommand } NS_IMETHODIMP -nsPasteNoFormattingCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsPasteNoFormattingCommand::GetCommandStateParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { NS_ENSURE_ARG_POINTER(aParams); nsCOMPtr htmlEditor(do_QueryInterface(refCon)); @@ -257,7 +214,7 @@ nsPasteNoFormattingCommand::GetCommandStateParams(const char *aCommandName, nsIC nsCOMPtr editor(do_QueryInterface(htmlEditor)); if (!editor) - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_INVALID_ARG; PRBool enabled = PR_FALSE; nsresult rv = editor->CanPaste(nsIClipboard::kGlobalClipboard, &enabled); @@ -275,7 +232,9 @@ nsStyleUpdatingCommand::nsStyleUpdatingCommand(const char* aTagName) } nsresult -nsStyleUpdatingCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, PRBool& outStyleSet) +nsStyleUpdatingCommand::GetCurrentState(nsIEditor *aEditor, + const char* aTagName, + PRBool& outStyleSet) { NS_ASSERTION(aEditor, "Need editor here"); nsresult rv = NS_OK; @@ -287,15 +246,21 @@ nsStyleUpdatingCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName nsCOMPtr htmlEditor = do_QueryInterface(aEditor); if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(aTagName)); - rv = htmlEditor->GetInlineProperty(styleAtom, NS_LITERAL_STRING(""), NS_LITERAL_STRING(""), &firstOfSelectionHasProp, &anyOfSelectionHasProp, &allOfSelectionHasProp); + nsCOMPtr styleAtom = do_GetAtom(aTagName); + rv = htmlEditor->GetInlineProperty(styleAtom, NS_LITERAL_STRING(""), + NS_LITERAL_STRING(""), + &firstOfSelectionHasProp, + &anyOfSelectionHasProp, + &allOfSelectionHasProp); outStyleSet = allOfSelectionHasProp; // change this to alter the behaviour return rv; } nsresult -nsStyleUpdatingCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams) +nsStyleUpdatingCommand::GetCurrentState(nsIEditor *aEditor, + const char* aTagName, + nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need editor here"); nsresult rv = NS_OK; @@ -307,12 +272,17 @@ nsStyleUpdatingCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName nsCOMPtr htmlEditor = do_QueryInterface(aEditor); if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(aTagName)); - rv = htmlEditor->GetInlineProperty(styleAtom, NS_LITERAL_STRING(""), NS_LITERAL_STRING(""), &firstOfSelectionHasProp, &anyOfSelectionHasProp, &allOfSelectionHasProp);\ - aParams->SetBooleanValue(STATE_ALL,allOfSelectionHasProp); - aParams->SetBooleanValue(STATE_BEGIN,firstOfSelectionHasProp); - aParams->SetBooleanValue(STATE_END,allOfSelectionHasProp);//not completely accurate - aParams->SetBooleanValue(STATE_MIXED,anyOfSelectionHasProp && !allOfSelectionHasProp); + nsCOMPtr styleAtom = do_GetAtom(aTagName); + rv = htmlEditor->GetInlineProperty(styleAtom, NS_LITERAL_STRING(""), + NS_LITERAL_STRING(""), + &firstOfSelectionHasProp, + &anyOfSelectionHasProp, + &allOfSelectionHasProp); + aParams->SetBooleanValue(STATE_ALL, allOfSelectionHasProp); + aParams->SetBooleanValue(STATE_BEGIN, firstOfSelectionHasProp); + aParams->SetBooleanValue(STATE_END, allOfSelectionHasProp);//not completely accurate + aParams->SetBooleanValue(STATE_MIXED, anyOfSelectionHasProp + && !allOfSelectionHasProp); return NS_OK; } @@ -325,7 +295,8 @@ nsStyleUpdatingCommand::ToggleState(nsIEditor *aEditor, const char* aTagName) PRBool styleSet; //create some params now... nsresult rv; - nsCOMPtr params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); + nsCOMPtr params = + do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); if (NS_FAILED(rv) || !params) return rv; @@ -372,7 +343,8 @@ nsListCommand::nsListCommand(const char* aTagName) } nsresult -nsListCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, PRBool& outInList) +nsListCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, + PRBool& outInList) { NS_ASSERTION(aEditor, "Need editor here"); @@ -382,15 +354,16 @@ nsListCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, PRBool& if (NS_FAILED(rv)) return rv; // Need to use mTagName???? - outInList = (0 == nsCRT::strcmp(tagStr, NS_ConvertASCIItoUCS2(mTagName).get())); - + outInList = (0 == nsCRT::strcmp(tagStr, + NS_ConvertASCIItoUCS2(mTagName).get())); if (tagStr) nsCRT::free(tagStr); return NS_OK; } nsresult -nsListCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams) +nsListCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, + nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need editor here"); @@ -400,7 +373,8 @@ nsListCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsIComm if (NS_FAILED(rv)) return rv; // Need to use mTagName???? - PRBool inList = (0 == nsCRT::strcmp(tagStr, NS_ConvertASCIItoUCS2(mTagName).get())); + PRBool inList = (0 == nsCRT::strcmp(tagStr, + NS_ConvertASCIItoUCS2(mTagName).get())); aParams->SetBooleanValue(STATE_ALL, !bMixed && inList); aParams->SetBooleanValue(STATE_MIXED, bMixed); if (tagStr) nsCRT::free(tagStr); @@ -416,8 +390,9 @@ nsListCommand::ToggleState(nsIEditor *aEditor, const char* aTagName) PRBool inList; // Need to use mTagName???? nsresult rv; - nsCOMPtr params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); - if (NS_FAILED(rv) || !params) + nsCOMPtr params = + do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); + if (NS_FAILED(rv) || !params) return rv; rv = GetCurrentState(aEditor, mTagName, params); rv = params->GetBooleanValue(STATE_ALL,&inList); @@ -444,7 +419,8 @@ nsListItemCommand::nsListItemCommand(const char* aTagName) } nsresult -nsListItemCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, PRBool& outInList) +nsListItemCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, + PRBool& outInList) { NS_ASSERTION(aEditor, "Need editor here"); @@ -453,7 +429,8 @@ nsListItemCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, PRB nsresult rv = GetListItemState(aEditor, &bMixed, &tagStr); if (NS_FAILED(rv)) return rv; - outInList = (0 == nsCRT::strcmp(tagStr, NS_ConvertASCIItoUCS2(mTagName).get())); + outInList = (0 == nsCRT::strcmp(tagStr, + NS_ConvertASCIItoUCS2(mTagName).get())); if (tagStr) nsCRT::free(tagStr); @@ -461,7 +438,8 @@ nsListItemCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, PRB } nsresult -nsListItemCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams) +nsListItemCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, + nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need editor here"); @@ -470,7 +448,8 @@ nsListItemCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsI nsresult rv = GetListItemState(aEditor,&bMixed, &tagStr); if (NS_FAILED(rv)) return rv; - PRBool inList = (0 == nsCRT::strcmp(tagStr, NS_ConvertASCIItoUCS2(mTagName).get())); + PRBool inList = + (0 == nsCRT::strcmp(tagStr, NS_ConvertASCIItoUCS2(mTagName).get())); aParams->SetBooleanValue(STATE_ALL, !bMixed && inList); aParams->SetBooleanValue(STATE_MIXED, bMixed); @@ -489,8 +468,9 @@ nsListItemCommand::ToggleState(nsIEditor *aEditor, const char* aTagName) PRBool inList; // Need to use mTagName???? nsresult rv; - nsCOMPtr params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); - if (NS_FAILED(rv) || !params) + nsCOMPtr params = + do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); + if (NS_FAILED(rv) || !params) return rv; rv = GetCurrentState(aEditor, mTagName, params); rv = params->GetBooleanValue(STATE_ALL,&inList); @@ -532,7 +512,9 @@ nsListItemCommand::ToggleState(nsIEditor *aEditor, const char* aTagName) #endif NS_IMETHODIMP -nsRemoveListCommand::IsCommandEnabled(const char * aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) +nsRemoveListCommand::IsCommandEnabled(const char * aCommandName, + nsISupports *refCon, + PRBool *outCmdEnabled) { nsCOMPtr editor = do_QueryInterface(refCon); if (editor) @@ -573,13 +555,17 @@ nsRemoveListCommand::DoCommand(const char *aCommandName, nsISupports *refCon) } NS_IMETHODIMP -nsRemoveListCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsRemoveListCommand::DoCommandParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { return DoCommand(aCommandName, refCon); } NS_IMETHODIMP -nsRemoveListCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsRemoveListCommand::GetCommandStateParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { PRBool outCmdEnabled = PR_FALSE; IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); @@ -591,7 +577,8 @@ nsRemoveListCommand::GetCommandStateParams(const char *aCommandName, nsICommandP #endif NS_IMETHODIMP -nsIndentCommand::IsCommandEnabled(const char * aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) +nsIndentCommand::IsCommandEnabled(const char * aCommandName, + nsISupports *refCon, PRBool *outCmdEnabled) { nsCOMPtr editor = do_QueryInterface(refCon); if (editor) @@ -622,7 +609,9 @@ nsIndentCommand::DoCommand(const char *aCommandName, nsISupports *refCon) } NS_IMETHODIMP -nsIndentCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsIndentCommand::DoCommandParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { nsCOMPtr editor = do_QueryInterface(refCon); @@ -638,7 +627,9 @@ nsIndentCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aPa } NS_IMETHODIMP -nsIndentCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsIndentCommand::GetCommandStateParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { PRBool outCmdEnabled = PR_FALSE; IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); @@ -649,7 +640,9 @@ nsIndentCommand::GetCommandStateParams(const char *aCommandName, nsICommandParam //OUTDENT NS_IMETHODIMP -nsOutdentCommand::IsCommandEnabled(const char * aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) +nsOutdentCommand::IsCommandEnabled(const char * aCommandName, + nsISupports *refCon, + PRBool *outCmdEnabled) { nsCOMPtr editor = do_QueryInterface(refCon); nsCOMPtr htmlEditor = do_QueryInterface(editor); @@ -685,7 +678,9 @@ nsOutdentCommand::DoCommand(const char *aCommandName, nsISupports *refCon) } NS_IMETHODIMP -nsOutdentCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsOutdentCommand::DoCommandParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { nsCOMPtr editor = do_QueryInterface(refCon); @@ -703,7 +698,9 @@ nsOutdentCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aP } NS_IMETHODIMP -nsOutdentCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsOutdentCommand::GetCommandStateParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { PRBool outCmdEnabled = PR_FALSE; IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); @@ -728,7 +725,9 @@ nsMultiStateCommand::~nsMultiStateCommand() NS_IMPL_ISUPPORTS_INHERITED0(nsMultiStateCommand, nsBaseComposerCommand); NS_IMETHODIMP -nsMultiStateCommand::IsCommandEnabled(const char * aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) +nsMultiStateCommand::IsCommandEnabled(const char * aCommandName, + nsISupports *refCon, + PRBool *outCmdEnabled) { nsCOMPtr editor = do_QueryInterface(refCon); if (editor) @@ -750,14 +749,17 @@ nsMultiStateCommand::DoCommand(const char *aCommandName, nsISupports *refCon) nsresult rv = NS_OK; #ifdef DEBUG - printf("who is calling nsMultiStateCommand::DoCommand (no implementation)? %s\n", aCommandName); + printf("who is calling nsMultiStateCommand::DoCommand \ + (no implementation)? %s\n", aCommandName); #endif return rv; } NS_IMETHODIMP -nsMultiStateCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsMultiStateCommand::DoCommandParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { nsCOMPtr editor = do_QueryInterface(refCon); @@ -777,7 +779,9 @@ nsMultiStateCommand::DoCommandParams(const char *aCommandName, nsICommandParams } NS_IMETHODIMP -nsMultiStateCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsMultiStateCommand::GetCommandStateParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { nsCOMPtr editor = do_QueryInterface(refCon); nsresult rv = NS_OK; @@ -798,7 +802,9 @@ nsParagraphStateCommand::nsParagraphStateCommand() } nsresult -nsParagraphStateCommand::GetCurrentState(nsIEditor *aEditor, nsString& outStateString, PRBool& outMixed) +nsParagraphStateCommand::GetCurrentState(nsIEditor *aEditor, + nsString& outStateString, + PRBool& outMixed) { NS_ASSERTION(aEditor, "Need an editor here"); @@ -808,7 +814,8 @@ nsParagraphStateCommand::GetCurrentState(nsIEditor *aEditor, nsString& outStateS } nsresult -nsParagraphStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) +nsParagraphStateCommand::GetCurrentState(nsIEditor *aEditor, + nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need an editor here"); @@ -849,7 +856,9 @@ nsFontFaceStateCommand::nsFontFaceStateCommand() } nsresult -nsFontFaceStateCommand::GetCurrentState(nsIEditor *aEditor, nsString& outStateString, PRBool& outMixed) +nsFontFaceStateCommand::GetCurrentState(nsIEditor *aEditor, + nsString& outStateString, + PRBool& outMixed) { NS_ASSERTION(aEditor, "Need an editor here"); @@ -860,7 +869,8 @@ nsFontFaceStateCommand::GetCurrentState(nsIEditor *aEditor, nsString& outStateSt } nsresult -nsFontFaceStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) +nsFontFaceStateCommand::GetCurrentState(nsIEditor *aEditor, + nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need an editor here"); @@ -897,7 +907,8 @@ nsFontFaceStateCommand::SetState(nsIEditor *aEditor, nsString& newState) if (newState.Equals(NS_LITERAL_STRING("tt"))) { // The old "teletype" attribute - rv = htmlEditor->SetInlineProperty(ttAtom, NS_LITERAL_STRING(""), NS_LITERAL_STRING("")); + rv = htmlEditor->SetInlineProperty(ttAtom, NS_LITERAL_STRING(""), + NS_LITERAL_STRING("")); // Clear existing font face rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("face")); } @@ -909,7 +920,8 @@ nsFontFaceStateCommand::SetState(nsIEditor *aEditor, nsString& newState) if (newState.IsEmpty() || newState.Equals(NS_LITERAL_STRING("normal"))) { rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("face")); } else { - rv = htmlEditor->SetInlineProperty(fontAtom, NS_LITERAL_STRING("face"), newState); + rv = htmlEditor->SetInlineProperty(fontAtom, NS_LITERAL_STRING("face"), + newState); } } @@ -926,7 +938,9 @@ nsFontColorStateCommand::nsFontColorStateCommand() } nsresult -nsFontColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsString& outStateString, PRBool& outMixed) +nsFontColorStateCommand::GetCurrentState(nsIEditor *aEditor, + nsString& outStateString, + PRBool& outMixed) { NS_ASSERTION(aEditor, "Need an editor here"); @@ -937,7 +951,8 @@ nsFontColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsString& outStateS } nsresult -nsFontColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) +nsFontColorStateCommand::GetCurrentState(nsIEditor *aEditor, + nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need an editor here"); @@ -973,7 +988,8 @@ nsFontColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState) if (newState.IsEmpty() || newState.Equals(NS_LITERAL_STRING("normal"))) { rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("color")); } else { - rv = htmlEditor->SetInlineProperty(fontAtom, NS_LITERAL_STRING("color"), newState); + rv = htmlEditor->SetInlineProperty(fontAtom, NS_LITERAL_STRING("color"), + newState); } return rv; @@ -989,7 +1005,9 @@ nsHighlightColorStateCommand::nsHighlightColorStateCommand() } nsresult -nsHighlightColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsString& outStateString, PRBool& outMixed) +nsHighlightColorStateCommand::GetCurrentState(nsIEditor *aEditor, + nsString& outStateString, + PRBool& outMixed) { NS_ASSERTION(aEditor, "Need an editor here"); @@ -1000,7 +1018,8 @@ nsHighlightColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsString& outS } nsresult -nsHighlightColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) +nsHighlightColorStateCommand::GetCurrentState(nsIEditor *aEditor, + nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need an editor here"); @@ -1035,14 +1054,17 @@ nsHighlightColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState) if (!newState.Length() || newState.Equals(NS_LITERAL_STRING("normal"))) { rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("bgcolor")); } else { - rv = htmlEditor->SetCSSInlineProperty(fontAtom, NS_LITERAL_STRING("bgcolor"), newState); + rv = htmlEditor->SetCSSInlineProperty(fontAtom, NS_LITERAL_STRING("bgcolor"), + newState); } return rv; } NS_IMETHODIMP -nsHighlightColorStateCommand::IsCommandEnabled(const char * aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) +nsHighlightColorStateCommand::IsCommandEnabled(const char * aCommandName, + nsISupports *refCon, + PRBool *outCmdEnabled) { nsCOMPtr editor = do_QueryInterface(refCon); nsCOMPtr htmlEditor = do_QueryInterface(editor); @@ -1067,7 +1089,9 @@ nsBackgroundColorStateCommand::nsBackgroundColorStateCommand() } nsresult -nsBackgroundColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsString& outStateString, PRBool& outMixed) +nsBackgroundColorStateCommand::GetCurrentState(nsIEditor *aEditor, + nsString& outStateString, + PRBool& outMixed) { NS_ASSERTION(aEditor, "Need an editor here"); @@ -1078,7 +1102,8 @@ nsBackgroundColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsString& out } nsresult -nsBackgroundColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) +nsBackgroundColorStateCommand::GetCurrentState(nsIEditor *aEditor, + nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need an editor here"); @@ -1119,7 +1144,8 @@ nsAlignCommand::nsAlignCommand() } nsresult -nsAlignCommand::GetCurrentState(nsIEditor *aEditor, nsString& outStateString, PRBool& outMixed) +nsAlignCommand::GetCurrentState(nsIEditor *aEditor, nsString& outStateString, + PRBool& outMixed) { NS_ASSERTION(aEditor, "Need an editor here"); @@ -1211,7 +1237,9 @@ nsAlignCommand::SetState(nsIEditor *aEditor, nsString& newState) #endif NS_IMETHODIMP -nsRemoveStylesCommand::IsCommandEnabled(const char * aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) +nsRemoveStylesCommand::IsCommandEnabled(const char * aCommandName, + nsISupports *refCon, + PRBool *outCmdEnabled) { nsCOMPtr editor = do_QueryInterface(refCon); if (editor) @@ -1228,7 +1256,8 @@ nsRemoveStylesCommand::IsCommandEnabled(const char * aCommandName, nsISupports * NS_IMETHODIMP -nsRemoveStylesCommand::DoCommand(const char *aCommandName, nsISupports *refCon) +nsRemoveStylesCommand::DoCommand(const char *aCommandName, + nsISupports *refCon) { nsCOMPtr editor = do_QueryInterface(refCon); @@ -1243,13 +1272,17 @@ nsRemoveStylesCommand::DoCommand(const char *aCommandName, nsISupports *refCon) } NS_IMETHODIMP -nsRemoveStylesCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsRemoveStylesCommand::DoCommandParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { return DoCommand(aCommandName, refCon); } NS_IMETHODIMP -nsRemoveStylesCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsRemoveStylesCommand::GetCommandStateParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { PRBool outCmdEnabled = PR_FALSE; IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); @@ -1261,7 +1294,9 @@ nsRemoveStylesCommand::GetCommandStateParams(const char *aCommandName, nsIComman #endif NS_IMETHODIMP -nsIncreaseFontSizeCommand::IsCommandEnabled(const char * aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) +nsIncreaseFontSizeCommand::IsCommandEnabled(const char * aCommandName, + nsISupports *refCon, + PRBool *outCmdEnabled) { nsCOMPtr editor = do_QueryInterface(refCon); if (editor) @@ -1277,7 +1312,8 @@ nsIncreaseFontSizeCommand::IsCommandEnabled(const char * aCommandName, nsISuppor NS_IMETHODIMP -nsIncreaseFontSizeCommand::DoCommand(const char *aCommandName, nsISupports *refCon) +nsIncreaseFontSizeCommand::DoCommand(const char *aCommandName, + nsISupports *refCon) { nsCOMPtr editor = do_QueryInterface(refCon); @@ -1291,7 +1327,9 @@ nsIncreaseFontSizeCommand::DoCommand(const char *aCommandName, nsISupports *refC } NS_IMETHODIMP -nsIncreaseFontSizeCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsIncreaseFontSizeCommand::DoCommandParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { nsCOMPtr editor = do_QueryInterface(refCon); @@ -1305,7 +1343,9 @@ nsIncreaseFontSizeCommand::DoCommandParams(const char *aCommandName, nsICommandP } NS_IMETHODIMP -nsIncreaseFontSizeCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsIncreaseFontSizeCommand::GetCommandStateParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { PRBool outCmdEnabled = PR_FALSE; IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); @@ -1317,7 +1357,9 @@ nsIncreaseFontSizeCommand::GetCommandStateParams(const char *aCommandName, nsICo #endif NS_IMETHODIMP -nsDecreaseFontSizeCommand::IsCommandEnabled(const char * aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) +nsDecreaseFontSizeCommand::IsCommandEnabled(const char * aCommandName, + nsISupports *refCon, + PRBool *outCmdEnabled) { nsCOMPtr editor = do_QueryInterface(refCon); if (editor) @@ -1333,7 +1375,8 @@ nsDecreaseFontSizeCommand::IsCommandEnabled(const char * aCommandName, nsISuppor NS_IMETHODIMP -nsDecreaseFontSizeCommand::DoCommand(const char *aCommandName, nsISupports *refCon) +nsDecreaseFontSizeCommand::DoCommand(const char *aCommandName, + nsISupports *refCon) { nsCOMPtr editor = do_QueryInterface(refCon); @@ -1347,7 +1390,9 @@ nsDecreaseFontSizeCommand::DoCommand(const char *aCommandName, nsISupports *refC } NS_IMETHODIMP -nsDecreaseFontSizeCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsDecreaseFontSizeCommand::DoCommandParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { nsCOMPtr editor = do_QueryInterface(refCon); @@ -1361,29 +1406,277 @@ nsDecreaseFontSizeCommand::DoCommandParams(const char *aCommandName, nsICommandP } NS_IMETHODIMP -nsDecreaseFontSizeCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) +nsDecreaseFontSizeCommand::GetCommandStateParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) { PRBool outCmdEnabled = PR_FALSE; IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled); } +#ifdef XP_MAC +#pragma mark - +#endif + +NS_IMETHODIMP +nsInsertHTMLCommand::IsCommandEnabled(const char * aCommandName, + nsISupports *refCon, + PRBool *outCmdEnabled) +{ + NS_ENSURE_ARG_POINTER(outCmdEnabled); + nsCOMPtr editor = do_QueryInterface(refCon); + *outCmdEnabled = editor ? PR_TRUE : PR_FALSE; + + return NS_OK; +} + + +NS_IMETHODIMP +nsInsertHTMLCommand::DoCommand(const char *aCommandName, nsISupports *refCon) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsInsertHTMLCommand::DoCommandParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) +{ + NS_ENSURE_ARG_POINTER(aParams); + NS_ENSURE_ARG_POINTER(refCon); + + nsCOMPtr editor = do_QueryInterface(refCon); + if (!editor) + return NS_ERROR_NOT_IMPLEMENTED; + + // Get HTML source string to insert from command params + nsAutoString html; + nsresult rv = aParams->GetStringValue(STATE_DATA, html); + NS_ENSURE_SUCCESS(rv, rv); + + if (!html.IsEmpty()) + return editor->InsertHTML(html); + + return NS_OK; +} + +NS_IMETHODIMP +nsInsertHTMLCommand::GetCommandStateParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) +{ + NS_ENSURE_ARG_POINTER(aParams); + NS_ENSURE_ARG_POINTER(refCon); + + PRBool outCmdEnabled = PR_FALSE; + IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); + return aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled); +} + +#ifdef XP_MAC +#pragma mark - +#endif + +/** + * Commands for document state that may be changed via doCommandParams + * As of 11/11/02, this is just "cmd_setDocumentModified" + * Note that you can use the same command class, nsSetDocumentStateCommand, + * for more than one of this type of command + * We check the input command param for different behavior + */ + +NS_IMETHODIMP +nsSetDocumentStateCommand::IsCommandEnabled(const char * aCommandName, + nsISupports *refCon, + PRBool *outCmdEnabled) +{ + NS_ENSURE_ARG_POINTER(outCmdEnabled); + nsCOMPtr editor = do_QueryInterface(refCon); + *outCmdEnabled = editor ? PR_TRUE : PR_FALSE; + + return NS_OK; +} + +NS_IMETHODIMP +nsSetDocumentStateCommand::DoCommand(const char *aCommandName, + nsISupports *refCon) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsSetDocumentStateCommand::DoCommandParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) +{ + nsCOMPtr editor = do_QueryInterface(refCon); + if (!editor) + return NS_ERROR_INVALID_ARG; + + if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified")) + { + NS_ENSURE_ARG_POINTER(aParams); + + PRBool modified; + nsresult rv = aParams->GetBooleanValue(STATE_ATTRIBUTE, &modified); + + // Should we fail if this param wasn't set? + // I'm not sure we should be that strict + if (NS_FAILED(rv)) + return NS_OK; + + if (modified) + return editor->IncrementModificationCount(1); + else + return editor->ResetModificationCount(); + + } + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsSetDocumentStateCommand::GetCommandStateParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) +{ + NS_ENSURE_ARG_POINTER(aParams); + NS_ENSURE_ARG_POINTER(refCon); + + // The base editor owns most state info + nsCOMPtr editor = do_QueryInterface(refCon); + if (!editor) + return NS_ERROR_INVALID_ARG; + + // Always get the enabled state + PRBool outCmdEnabled = PR_FALSE; + IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); + nsresult rv = aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled); + NS_ENSURE_SUCCESS(rv, rv); + + if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified")) + { + PRBool modified; + rv = editor->GetDocumentModified(&modified); + NS_ENSURE_SUCCESS(rv, rv); + + return aParams->SetBooleanValue(STATE_ATTRIBUTE, modified); + } + return NS_ERROR_NOT_IMPLEMENTED; +} + +/** + * Commands just for state notification + * As of 11/11/02, possible commands are: + * "obs_documentCreated" + * "obs_documentWillBeDestroyed" + * Note that you can use the same command class, nsDocumentStateCommand + * for these or future observer commands. + * We check the input command param for different behavior + * + * How to use: + * 1. Get the nsICommandManager for the current editor + * 2. Implement an nsIObserve object, e.g: + * + * void Observe( + * in nsISupports aSubject, // The nsICommandManager calling this Observer + * in string aTopic, // command name, e.g.:"obs_documentCreated" + * // or "obs_documentWillBeDestroyed" + in wstring aData ); // ignored (set to "command_status_changed") + * + * 3. Add the observer by: + * commandManager.addObserver(observeobject, obs_documentCreated); + * 4. In the appropriate location in editorSession, editor, or commands code, + * trigger the notification of this observer by something like: + * + * nsCOMPtr commandManager = do_GetInterface(mDocShell); + * nsCOMPtr commandUpdater = do_QueryInterface(commandManager); + * if (!commandUpdater) return NS_ERROR_FAILURE; + * commandUpdater->CommandStatusChanged(obs_documentCreated); + * + * 5. Use GetCommandStateParams() to obtain state information + * e.g., any creation state codes when creating an editor are + * supplied for "obs_documentCreated" command in the + * "state_data" param's value + * + */ + +#ifdef XP_MAC +#pragma mark - +#endif + +NS_IMETHODIMP +nsDocumentStateCommand::IsCommandEnabled(const char* aCommandName, + nsISupports *refCon, + PRBool *outCmdEnabled) +{ + NS_ENSURE_ARG_POINTER(outCmdEnabled); + // Always return false to discourage callers from using DoCommand() + *outCmdEnabled = PR_FALSE; + + return NS_OK; +} + +NS_IMETHODIMP +nsDocumentStateCommand::DoCommand(const char *aCommandName, + nsISupports *refCon) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsDocumentStateCommand::DoCommandParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsDocumentStateCommand::GetCommandStateParams(const char *aCommandName, + nsICommandParams *aParams, + nsISupports *refCon) +{ + NS_ENSURE_ARG_POINTER(aCommandName); + nsCOMPtr editingSession = do_QueryInterface(refCon); + + + if (!nsCRT::strcmp(aCommandName, "obs_documentCreated")) + { + NS_ENSURE_ARG_POINTER(aParams); + + PRUint32 editorStatus = nsIEditingSession::eEditorErrorUnknown; + if (editingSession) + { + // refCon is initially set to nsIEditingSession until editor + // is successfully created and source doc is loaded + // Embedder gets error status if this fails + // If called before startup is finished, + // status = eEditorCreationInProgress + nsresult rv = editingSession->GetEditorStatus(&editorStatus); + NS_ENSURE_SUCCESS(rv, rv); + } + else + { + // If refCon is an editor, then everything started up OK! + nsCOMPtr editor = do_QueryInterface(refCon); + if (editor) + editorStatus = nsIEditingSession::eEditorOK; + } + + // Note that if refCon is not-null, but is neither + // an nsIEditingSession or nsIEditor, we return "eEditorErrorUnknown" + aParams->SetLongValue(STATE_DATA, editorStatus); + return NS_OK; + } + + return NS_ERROR_NOT_IMPLEMENTED; +} + /****************************/ //HELPER METHODS /****************************/ -nsresult -PasteAsQuotation(nsIEditor *aEditor, PRInt32 aSelectionType) -{ - nsresult err = NS_ERROR_NOT_IMPLEMENTED; - - nsCOMPtr mailEditor = do_QueryInterface(aEditor); - if (mailEditor) - err = mailEditor->PasteAsQuotation(aSelectionType); - - return err; -} - nsresult GetListState(nsIEditor *aEditor, PRBool *aMixed, PRUnichar **_retval) { @@ -1417,14 +1710,16 @@ GetListState(nsIEditor *aEditor, PRBool *aMixed, PRUnichar **_retval) } nsresult -RemoveOneProperty(nsIHTMLEditor *aEditor,const nsString& aProp, const nsString &aAttr) +RemoveOneProperty(nsIHTMLEditor *aEditor,const nsString& aProp, + const nsString &aAttr) { nsresult err = NS_NOINTERFACE; if (!aEditor) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(aProp)); /// XXX Hack alert! Look in nsIEditProperty.h for this + /// XXX Hack alert! Look in nsIEditProperty.h for this + nsCOMPtr styleAtom = do_GetAtom(aProp); if (! styleAtom) return NS_ERROR_OUT_OF_MEMORY; @@ -1437,14 +1732,16 @@ RemoveOneProperty(nsIHTMLEditor *aEditor,const nsString& aProp, const nsString & // the name of the attribute here should be the contents of the appropriate // tag, e.g. 'b' for bold, 'i' for italics. nsresult -RemoveTextProperty(nsIEditor *aEditor, const PRUnichar *prop, const PRUnichar *attr) +RemoveTextProperty(nsIEditor *aEditor, const PRUnichar *prop, + const PRUnichar *attr) { if (!aEditor) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr editor = do_QueryInterface(aEditor); if (!editor) return NS_ERROR_NOT_INITIALIZED; - // OK, I'm really hacking now. This is just so that we can accept 'all' as input. + // OK, I'm really hacking now. This is just so that + // we can accept 'all' as input. nsAutoString allStr(prop); nsAutoString aAttr(attr); @@ -1468,7 +1765,8 @@ RemoveTextProperty(nsIEditor *aEditor, const PRUnichar *prop, const PRUnichar *a // the name of the attribute here should be the contents of the appropriate // tag, e.g. 'b' for bold, 'i' for italics. nsresult -SetTextProperty(nsIEditor *aEditor, const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value) +SetTextProperty(nsIEditor *aEditor, const PRUnichar *prop, + const PRUnichar *attr, const PRUnichar *value) { //static initialization static const PRUnichar sEmptyStr = PRUnichar('\0'); @@ -1478,7 +1776,8 @@ SetTextProperty(nsIEditor *aEditor, const PRUnichar *prop, const PRUnichar *attr if (!aEditor) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(prop)); /// XXX Hack alert! Look in nsIEditProperty.h for this + /// XXX Hack alert! Look in nsIEditProperty.h for this + nsCOMPtr styleAtom = do_GetAtom(prop); if (! styleAtom) return NS_ERROR_OUT_OF_MEMORY; diff --git a/mozilla/editor/composer/src/nsComposerCommands.h b/mozilla/editor/composer/src/nsComposerCommands.h index 2f2070b99f7..63f55a4dc14 100644 --- a/mozilla/editor/composer/src/nsComposerCommands.h +++ b/mozilla/editor/composer/src/nsComposerCommands.h @@ -20,8 +20,9 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Ryan Cassin - * Daniel Glazman + * Ryan Cassin + * Daniel Glazman + * Charles Manske * * * Alternatively, the contents of this file may be used under the terms of @@ -44,6 +45,8 @@ #include "nsIControllerCommand.h" #include "nsString.h" +class nsIEditor; + // This is a virtual base class for commands registered with the composer controller. // Note that such commands are instantiated once per composer, so can store state. // Also note that IsCommandEnabled can be called with an editor that may not @@ -70,7 +73,6 @@ public: }; - #define NS_DECL_COMPOSER_COMMAND(_cmd) \ class _cmd : public nsBaseComposerCommand \ { \ @@ -272,17 +274,16 @@ protected: // composer commands NS_DECL_COMPOSER_COMMAND(nsCloseCommand) +NS_DECL_COMPOSER_COMMAND(nsDocumentStateCommand) +NS_DECL_COMPOSER_COMMAND(nsSetDocumentStateCommand) //NS_DECL_COMPOSER_COMMAND(nsPrintingCommands) // Generic commands - // File menu NS_DECL_COMPOSER_COMMAND(nsNewCommands) // handles 'new' anything - // Edit menu -NS_DECL_COMPOSER_COMMAND(nsPasteQuotationCommand) NS_DECL_COMPOSER_COMMAND(nsPasteNoFormattingCommand) // Block transformations @@ -294,5 +295,7 @@ NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand) NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand) NS_DECL_COMPOSER_COMMAND(nsDecreaseFontSizeCommand) +// Insert content commands +NS_DECL_COMPOSER_COMMAND(nsInsertHTMLCommand) #endif // nsComposerCommands_h_ diff --git a/mozilla/editor/composer/src/nsComposerCommandsUpdater.cpp b/mozilla/editor/composer/src/nsComposerCommandsUpdater.cpp index d1fff99df04..852218a6e5e 100644 --- a/mozilla/editor/composer/src/nsComposerCommandsUpdater.cpp +++ b/mozilla/editor/composer/src/nsComposerCommandsUpdater.cpp @@ -18,14 +18,16 @@ * Rights Reserved. * * Contributor(s): - * Simon Fraser + * Simon Fraser + * Michael Judge + * Charles Manske */ - +#include "nsIDOMWindow.h" #include "nsComposerCommandsUpdater.h" #include "nsIServiceManager.h" #include "nsIDOMDocument.h" -#include "nsIDocument.h" +//#include "nsIDocument.h" #include "nsISelection.h" #include "nsIScriptGlobalObject.h" @@ -39,8 +41,8 @@ #include "nsITransactionManager.h" nsComposerCommandsUpdater::nsComposerCommandsUpdater() -: mEditor(nsnull) -, mDocShell(nsnull) +: mDOMWindow(nsnull) +, mDocShell(nsnull) , mDirtyState(eStateUninitialized) , mSelectionCollapsed(eStateUninitialized) , mFirstDoOfFirstUndo(PR_TRUE) @@ -52,7 +54,8 @@ nsComposerCommandsUpdater::~nsComposerCommandsUpdater() { } -NS_IMPL_ISUPPORTS4(nsComposerCommandsUpdater, nsISelectionListener, nsIDocumentStateListener, nsITransactionListener, nsITimerCallback); +NS_IMPL_ISUPPORTS4(nsComposerCommandsUpdater, nsISelectionListener, + nsIDocumentStateListener, nsITransactionListener, nsITimerCallback); #if 0 #pragma mark - @@ -61,6 +64,8 @@ NS_IMPL_ISUPPORTS4(nsComposerCommandsUpdater, nsISelectionListener, nsIDocumentS NS_IMETHODIMP nsComposerCommandsUpdater::NotifyDocumentCreated() { + // Trigger an nsIObserve notification that the document has been created + UpdateOneCommand("obs_documentCreated"); return NS_OK; } @@ -71,6 +76,8 @@ nsComposerCommandsUpdater::NotifyDocumentWillBeDestroyed() if (mUpdateTimer) mUpdateTimer->Cancel(); + // Trigger an nsIObserve notification that the document will be destroyed + UpdateOneCommand("obs_documentWillBeDestroyed"); return NS_OK; } @@ -83,7 +90,8 @@ nsComposerCommandsUpdater::NotifyDocumentStateChanged(PRBool aNowDirty) } NS_IMETHODIMP -nsComposerCommandsUpdater::NotifySelectionChanged(nsIDOMDocument *, nsISelection *, short) +nsComposerCommandsUpdater::NotifySelectionChanged(nsIDOMDocument *, + nsISelection *, short) { return PrimeUpdateTimer(); } @@ -92,14 +100,16 @@ nsComposerCommandsUpdater::NotifySelectionChanged(nsIDOMDocument *, nsISelection #pragma mark - #endif -NS_IMETHODIMP nsComposerCommandsUpdater::WillDo(nsITransactionManager *aManager, - nsITransaction *aTransaction, PRBool *aInterrupt) +NS_IMETHODIMP +nsComposerCommandsUpdater::WillDo(nsITransactionManager *aManager, + nsITransaction *aTransaction, PRBool *aInterrupt) { *aInterrupt = PR_FALSE; return NS_OK; } -NS_IMETHODIMP nsComposerCommandsUpdater::DidDo(nsITransactionManager *aManager, +NS_IMETHODIMP +nsComposerCommandsUpdater::DidDo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aDoResult) { // only need to update if the status of the Undo menu item changes. @@ -108,78 +118,99 @@ NS_IMETHODIMP nsComposerCommandsUpdater::DidDo(nsITransactionManager *aManager, if (undoCount == 1) { if (mFirstDoOfFirstUndo) - CallUpdateCommands(NS_LITERAL_STRING("undo")); + UpdateCommandGroup(NS_LITERAL_STRING("undo")); mFirstDoOfFirstUndo = PR_FALSE; } return NS_OK; } -NS_IMETHODIMP nsComposerCommandsUpdater::WillUndo(nsITransactionManager *aManager, - nsITransaction *aTransaction, PRBool *aInterrupt) +NS_IMETHODIMP +nsComposerCommandsUpdater::WillUndo(nsITransactionManager *aManager, + nsITransaction *aTransaction, + PRBool *aInterrupt) { *aInterrupt = PR_FALSE; return NS_OK; } -NS_IMETHODIMP nsComposerCommandsUpdater::DidUndo(nsITransactionManager *aManager, - nsITransaction *aTransaction, nsresult aUndoResult) +NS_IMETHODIMP +nsComposerCommandsUpdater::DidUndo(nsITransactionManager *aManager, + nsITransaction *aTransaction, + nsresult aUndoResult) { PRInt32 undoCount; aManager->GetNumberOfUndoItems(&undoCount); if (undoCount == 0) mFirstDoOfFirstUndo = PR_TRUE; // reset the state for the next do - CallUpdateCommands(NS_LITERAL_STRING("undo")); + UpdateCommandGroup(NS_LITERAL_STRING("undo")); return NS_OK; } -NS_IMETHODIMP nsComposerCommandsUpdater::WillRedo(nsITransactionManager *aManager, - nsITransaction *aTransaction, PRBool *aInterrupt) +NS_IMETHODIMP +nsComposerCommandsUpdater::WillRedo(nsITransactionManager *aManager, + nsITransaction *aTransaction, + PRBool *aInterrupt) { *aInterrupt = PR_FALSE; return NS_OK; } -NS_IMETHODIMP nsComposerCommandsUpdater::DidRedo(nsITransactionManager *aManager, - nsITransaction *aTransaction, nsresult aRedoResult) +NS_IMETHODIMP +nsComposerCommandsUpdater::DidRedo(nsITransactionManager *aManager, + nsITransaction *aTransaction, + nsresult aRedoResult) { - CallUpdateCommands(NS_LITERAL_STRING("undo")); + UpdateCommandGroup(NS_LITERAL_STRING("undo")); return NS_OK; } -NS_IMETHODIMP nsComposerCommandsUpdater::WillBeginBatch(nsITransactionManager *aManager, PRBool *aInterrupt) +NS_IMETHODIMP +nsComposerCommandsUpdater::WillBeginBatch(nsITransactionManager *aManager, + PRBool *aInterrupt) { *aInterrupt = PR_FALSE; return NS_OK; } -NS_IMETHODIMP nsComposerCommandsUpdater::DidBeginBatch(nsITransactionManager *aManager, nsresult aResult) +NS_IMETHODIMP +nsComposerCommandsUpdater::DidBeginBatch(nsITransactionManager *aManager, + nsresult aResult) { return NS_OK; } -NS_IMETHODIMP nsComposerCommandsUpdater::WillEndBatch(nsITransactionManager *aManager, PRBool *aInterrupt) +NS_IMETHODIMP +nsComposerCommandsUpdater::WillEndBatch(nsITransactionManager *aManager, + PRBool *aInterrupt) { *aInterrupt = PR_FALSE; return NS_OK; } -NS_IMETHODIMP nsComposerCommandsUpdater::DidEndBatch(nsITransactionManager *aManager, nsresult aResult) +NS_IMETHODIMP +nsComposerCommandsUpdater::DidEndBatch(nsITransactionManager *aManager, + nsresult aResult) { return NS_OK; } -NS_IMETHODIMP nsComposerCommandsUpdater::WillMerge(nsITransactionManager *aManager, - nsITransaction *aTopTransaction, nsITransaction *aTransactionToMerge, PRBool *aInterrupt) +NS_IMETHODIMP +nsComposerCommandsUpdater::WillMerge(nsITransactionManager *aManager, + nsITransaction *aTopTransaction, + nsITransaction *aTransactionToMerge, + PRBool *aInterrupt) { *aInterrupt = PR_FALSE; return NS_OK; } -NS_IMETHODIMP nsComposerCommandsUpdater::DidMerge(nsITransactionManager *aManager, - nsITransaction *aTopTransaction, nsITransaction *aTransactionToMerge, - PRBool aDidMerge, nsresult aMergeResult) +NS_IMETHODIMP +nsComposerCommandsUpdater::DidMerge(nsITransactionManager *aManager, + nsITransaction *aTopTransaction, + nsITransaction *aTransactionToMerge, + PRBool aDidMerge, nsresult aMergeResult) { return NS_OK; } @@ -189,9 +220,18 @@ NS_IMETHODIMP nsComposerCommandsUpdater::DidMerge(nsITransactionManager *aManage #endif nsresult -nsComposerCommandsUpdater::SetEditor(nsIEditor* aEditor) +nsComposerCommandsUpdater::Init(nsIDOMWindow* aDOMWindow) { - mEditor = aEditor; // no addreffing here + NS_ENSURE_ARG(aDOMWindow); + mDOMWindow = aDOMWindow; + + nsCOMPtr scriptObject(do_QueryInterface(aDOMWindow)); + if (scriptObject) + { + nsCOMPtr docShell; + scriptObject->GetDocShell(getter_AddRefs(docShell)); + mDocShell = docShell.get(); + } return NS_OK; } @@ -212,7 +252,7 @@ nsComposerCommandsUpdater::PrimeUpdateTimer() if (NS_FAILED(rv)) return rv; const PRUint32 kUpdateTimerDelay = 150; - return mUpdateTimer->InitWithCallback(NS_STATIC_CAST(nsITimerCallback*, this), + return mUpdateTimer->InitWithCallback(NS_STATIC_CAST(nsITimerCallback*, this), kUpdateTimerDelay, nsITimer::TYPE_ONE_SHOT); } @@ -224,11 +264,11 @@ void nsComposerCommandsUpdater::TimerCallback() PRBool isCollapsed = SelectionIsCollapsed(); if (isCollapsed != mSelectionCollapsed) { - CallUpdateCommands(NS_LITERAL_STRING("select")); + UpdateCommandGroup(NS_LITERAL_STRING("select")); mSelectionCollapsed = isCollapsed; } - CallUpdateCommands(NS_LITERAL_STRING("style")); + UpdateCommandGroup(NS_LITERAL_STRING("style")); } nsresult @@ -236,8 +276,7 @@ nsComposerCommandsUpdater::UpdateDirtyState(PRBool aNowDirty) { if (mDirtyState != aNowDirty) { - CallUpdateCommands(NS_LITERAL_STRING("save")); - + UpdateCommandGroup(NS_LITERAL_STRING("save")); mDirtyState = aNowDirty; } @@ -245,51 +284,87 @@ nsComposerCommandsUpdater::UpdateDirtyState(PRBool aNowDirty) } nsresult -nsComposerCommandsUpdater::CallUpdateCommands(const nsAString& aCommand) +nsComposerCommandsUpdater::UpdateCommandGroup(const nsAString& aCommandGroup) { - if (!mDocShell) + if (!mDocShell) return NS_ERROR_FAILURE; + + nsCOMPtr commandManager = do_GetInterface(mDocShell); + nsCOMPtr commandUpdater = do_QueryInterface(commandManager); + if (!commandUpdater) return NS_ERROR_FAILURE; + + + // This hardcoded list of commands is temporary. + // This code should use nsIControllerCommandGroup. + if (aCommandGroup.Equals(NS_LITERAL_STRING("undo"))) { - nsCOMPtr editor = do_QueryInterface(mEditor); - if (!editor) return NS_ERROR_FAILURE; - - nsCOMPtr domDoc; - editor->GetDocument(getter_AddRefs(domDoc)); - if (!domDoc) return NS_ERROR_FAILURE; - - nsCOMPtr theDoc = do_QueryInterface(domDoc); - if (!theDoc) return NS_ERROR_FAILURE; - - nsCOMPtr scriptGlobalObject; - theDoc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); - - nsCOMPtr docShell; - scriptGlobalObject->GetDocShell(getter_AddRefs(docShell)); - mDocShell = docShell.get(); + commandUpdater->CommandStatusChanged("cmd_undo"); + commandUpdater->CommandStatusChanged("cmd_redo"); } + else if (aCommandGroup.Equals(NS_LITERAL_STRING("select")) || + aCommandGroup.Equals(NS_LITERAL_STRING("style"))) + { + commandUpdater->CommandStatusChanged("cmd_bold"); + commandUpdater->CommandStatusChanged("cmd_italic"); + commandUpdater->CommandStatusChanged("cmd_underline"); + commandUpdater->CommandStatusChanged("cmd_tt"); + commandUpdater->CommandStatusChanged("cmd_strikethrough"); + commandUpdater->CommandStatusChanged("cmd_superscript"); + commandUpdater->CommandStatusChanged("cmd_subscript"); + commandUpdater->CommandStatusChanged("cmd_nobreak"); + + commandUpdater->CommandStatusChanged("cmd_em"); + commandUpdater->CommandStatusChanged("cmd_strong"); + commandUpdater->CommandStatusChanged("cmd_cite"); + commandUpdater->CommandStatusChanged("cmd_abbr"); + commandUpdater->CommandStatusChanged("cmd_acronym"); + commandUpdater->CommandStatusChanged("cmd_code"); + commandUpdater->CommandStatusChanged("cmd_samp"); + commandUpdater->CommandStatusChanged("cmd_var"); + + commandUpdater->CommandStatusChanged("cmd_increaseFont"); + commandUpdater->CommandStatusChanged("cmd_decreaseFont"); + + commandUpdater->CommandStatusChanged("cmd_paragraphState"); + commandUpdater->CommandStatusChanged("cmd_fontFace"); + commandUpdater->CommandStatusChanged("cmd_fontColor"); + commandUpdater->CommandStatusChanged("cmd_backgroundColor"); + commandUpdater->CommandStatusChanged("cmd_highlight"); + } + else if (aCommandGroup.Equals(NS_LITERAL_STRING("save"))) + { + // save commands (most are not in C++) + commandUpdater->CommandStatusChanged("cmd_setDocumentModified"); + commandUpdater->CommandStatusChanged("cmd_save"); + } + return NS_OK; +} + +nsresult +nsComposerCommandsUpdater::UpdateOneCommand(const char *aCommand) +{ if (!mDocShell) return NS_ERROR_FAILURE; nsCOMPtr commandManager = do_GetInterface(mDocShell); nsCOMPtr commandUpdater = do_QueryInterface(commandManager); if (!commandUpdater) return NS_ERROR_FAILURE; - - commandUpdater->CommandStatusChanged("cmd_bold"); - commandUpdater->CommandStatusChanged("cmd_italic"); - commandUpdater->CommandStatusChanged("cmd_underline"); - + + commandUpdater->CommandStatusChanged(aCommand); + return NS_OK; } PRBool nsComposerCommandsUpdater::SelectionIsCollapsed() { + if (!mDOMWindow) return PR_TRUE; + nsresult rv; // we don't care too much about failures here. - nsCOMPtr editor = do_QueryInterface(mEditor, &rv); if (NS_SUCCEEDED(rv)) { nsCOMPtr domSelection; - rv = editor->GetSelection(getter_AddRefs(domSelection)); + rv = mDOMWindow->GetSelection(getter_AddRefs(domSelection)); if (NS_SUCCEEDED(rv)) { PRBool selectionCollapsed = PR_FALSE; @@ -318,19 +393,13 @@ nsComposerCommandsUpdater::Notify(nsITimer *timer) #endif -nsresult NS_NewComposerCommandsUpdater(nsIEditor* aEditor, nsISelectionListener** aInstancePtrResult) +nsresult +NS_NewComposerCommandsUpdater(nsISelectionListener** aInstancePtrResult) { nsComposerCommandsUpdater* newThang = new nsComposerCommandsUpdater; if (!newThang) return NS_ERROR_OUT_OF_MEMORY; - *aInstancePtrResult = nsnull; - nsresult rv = newThang->SetEditor(aEditor); - if (NS_FAILED(rv)) - { - delete newThang; - return rv; - } - - return newThang->QueryInterface(NS_GET_IID(nsISelectionListener), (void **)aInstancePtrResult); + return newThang->QueryInterface(NS_GET_IID(nsISelectionListener), + (void **)aInstancePtrResult); } diff --git a/mozilla/editor/composer/src/nsComposerCommandsUpdater.h b/mozilla/editor/composer/src/nsComposerCommandsUpdater.h index b6f4b472fb5..65dd6484307 100644 --- a/mozilla/editor/composer/src/nsComposerCommandsUpdater.h +++ b/mozilla/editor/composer/src/nsComposerCommandsUpdater.h @@ -18,7 +18,9 @@ * Rights Reserved. * * Contributor(s): - * Simon Fraser + * Simon Fraser + * Michael Judge + * Charles Manske */ @@ -35,7 +37,6 @@ #include "nsIDocumentStateListener.h" #include "nsITransactionListener.h" -class nsIEditor; class nsIDocShell; class nsITransactionManager; @@ -80,7 +81,7 @@ public: PRBool aDidMerge, nsresult aMergeResult); - nsresult SetEditor(nsIEditor* aEditor); + nsresult Init(nsIDOMWindow* aDOMWindow); protected: @@ -92,21 +93,15 @@ protected: PRBool SelectionIsCollapsed(); nsresult UpdateDirtyState(PRBool aNowDirty); - nsresult CallUpdateCommands(const nsAString& aCommand); + nsresult UpdateOneCommand(const char* aCommand); + nsresult UpdateCommandGroup(const nsAString& aCommandGroup); nsresult PrimeUpdateTimer(); void TimerCallback(); - - - // this class should not hold references to the editor or editorShell. Doing - // so would result in cirular reference chains. - - nsIEditor* mEditor; // the HTML editor - - nsIDocShell* mDocShell; - nsCOMPtr mUpdateTimer; - + + nsIDOMWindow* mDOMWindow; // Weak reference + nsIDocShell* mDocShell; // Weak reference PRInt8 mDirtyState; PRInt8 mSelectionCollapsed; PRPackedBool mFirstDoOfFirstUndo; @@ -114,7 +109,7 @@ protected: }; -extern "C" nsresult NS_NewComposerCommandsUpdater(nsIEditor* aEditor, nsISelectionListener** aInstancePtrResult); +extern "C" nsresult NS_NewComposerCommandsUpdater(nsISelectionListener** aInstancePtrResult); #endif // nsComposerCommandsUpdater_h__ diff --git a/mozilla/editor/composer/src/nsComposerController.cpp b/mozilla/editor/composer/src/nsComposerController.cpp index 6c492fe8dee..a3739d87281 100644 --- a/mozilla/editor/composer/src/nsComposerController.cpp +++ b/mozilla/editor/composer/src/nsComposerController.cpp @@ -40,89 +40,10 @@ * ***** END LICENSE BLOCK ***** */ #include "nsIComponentManager.h" +#include "nsIControllerCommandManager.h" #include "nsComposerController.h" - -#if 0 -#include "nsIEditor.h" -#include "nsIEditorMailSupport.h" -#include "nsIFormControlFrame.h" -#include "nsISelection.h" -#include "nsIHTMLEditor.h" -#include "nsXPIDLString.h" - -#include "nsISelectionController.h" -#include "nsIDocument.h" -#include "nsIPresShell.h" - -#include "nsEditorCommands.h" -#endif - #include "nsComposerCommands.h" -NS_IMPL_ADDREF(nsComposerController) -NS_IMPL_RELEASE(nsComposerController) - -NS_INTERFACE_MAP_BEGIN(nsComposerController) - NS_INTERFACE_MAP_ENTRY(nsIController) - NS_INTERFACE_MAP_ENTRY(nsICommandController) - NS_INTERFACE_MAP_ENTRY(nsIEditorController) - NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditorController) -NS_INTERFACE_MAP_END - - -nsComposerController::nsComposerController() -{ - NS_INIT_ISUPPORTS(); -} - -nsComposerController::~nsComposerController() -{ -} - -NS_IMETHODIMP nsComposerController::Init(nsISupports *aCommandRefCon) -{ - nsresult rv; - - // get our ref to the singleton command manager - // This will create mCommandManager and register commands if not already done. - rv = GetComposerCommandManager(getter_AddRefs(mCommandManager)); - if (NS_FAILED(rv)) return rv; - - mCommandRefCon = aCommandRefCon; // no addref - - // the following (7?) lines can be removed when the JS commands are stateless and in C++ - mCommandManager = do_CreateInstance(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - // register the commands. - rv = nsComposerController::RegisterComposerCommands(mCommandManager); - if (NS_FAILED(rv)) return rv; - - return NS_OK; -} - -NS_IMETHODIMP -nsComposerController::SetCommandRefCon(nsISupports *aCommandRefCon) -{ - mCommandRefCon = aCommandRefCon; // no addref - return NS_OK; -} - -NS_IMETHODIMP -nsComposerController::GetInterface(const nsIID & aIID, void * *result) -{ - NS_ENSURE_ARG_POINTER(result); - - if (NS_SUCCEEDED(QueryInterface(aIID, result))) - return NS_OK; - - if (mCommandManager && aIID.Equals(NS_GET_IID(nsIControllerCommandManager))) - return mCommandManager->QueryInterface(aIID, result); - - return NS_NOINTERFACE; -} - #define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName) \ { \ _cmdClass* theCmd; \ @@ -159,12 +80,29 @@ nsComposerController::GetInterface(const nsIID & aIID, void * *result) // static -nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandManager *inCommandManager) +nsresult +nsComposerController::RegisterEditorDocStateCommands( + nsIControllerCommandManager *inCommandManager) +{ + nsresult rv; + + // observer commands for document state + NS_REGISTER_ONE_COMMAND(nsDocumentStateCommand, "obs_documentCreated") + NS_REGISTER_ONE_COMMAND(nsDocumentStateCommand, "obs_documentWillBeDestroyed") + + // commands that may get or change state + NS_REGISTER_ONE_COMMAND(nsSetDocumentStateCommand, "cmd_setDocumentModified") + return NS_OK; +} + +// static +nsresult +nsComposerController::RegisterHTMLEditorCommands( + nsIControllerCommandManager *inCommandManager) { nsresult rv; // Edit menu - NS_REGISTER_ONE_COMMAND(nsPasteQuotationCommand, "cmd_pasteQuote"); NS_REGISTER_ONE_COMMAND(nsPasteNoFormattingCommand, "cmd_pasteNoFormatting"); // indent/outdent @@ -211,90 +149,8 @@ nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandMana NS_REGISTER_ONE_COMMAND(nsIncreaseFontSizeCommand, "cmd_increaseFont"); NS_REGISTER_ONE_COMMAND(nsDecreaseFontSizeCommand, "cmd_decreaseFont"); + // Insert content + NS_REGISTER_ONE_COMMAND(nsInsertHTMLCommand, "cmd_insertHTML"); return NS_OK; } - -/* ======================================================================= - * nsIController - * ======================================================================= */ - -NS_IMETHODIMP -nsComposerController::IsCommandEnabled(const char * aCommand, - PRBool *aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult); -} - -NS_IMETHODIMP -nsComposerController::SupportsCommand(const char * aCommand, - PRBool *aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult); -} - -NS_IMETHODIMP -nsComposerController::DoCommand(const char *aCommand) -{ - return mCommandManager->DoCommand(aCommand, mCommandRefCon); -} - -NS_IMETHODIMP -nsComposerController::OnEvent(const char * aEventName) -{ - return NS_OK; -} - -nsWeakPtr nsComposerController::sComposerCommandManager = NULL; - -// static -nsresult nsComposerController::GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager) -{ - NS_ENSURE_ARG_POINTER(outCommandManager); - - nsCOMPtr cmdManager = do_QueryReferent(sComposerCommandManager); - if (!cmdManager) - { - nsresult rv; - cmdManager = do_CreateInstance(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - // register the commands. This just happens once per instance - rv = nsComposerController::RegisterComposerCommands(cmdManager); - if (NS_FAILED(rv)) return rv; - - // save the singleton in our static weak reference - sComposerCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv)); - if (NS_FAILED(rv)) return rv; - } - - NS_ADDREF(*outCommandManager = cmdManager); - return NS_OK; -} - - -// GetCommandStateWithParams -/* -cmd_bold,cmd_italic,cmd_underline ->state commands -state_start : true,false -state_end : true,false -state_all : true,false -state_mixed : true,false -*/ -/* void getCommandStateWithParams (in DOMString aCommandName, inout nsICommandParams aCommandParams); */ -NS_IMETHODIMP nsComposerController::GetCommandStateWithParams(const char *aCommand, nsICommandParams *aCommandParams) -{ - if (!mCommandRefCon || !mCommandManager) - return NS_ERROR_NOT_INITIALIZED; - return mCommandManager->GetCommandState(aCommand,aCommandParams,mCommandRefCon); -} - -/* void doCommandWithParams (in DOMString aCommandName, in nsICommandParams aCommandParams); */ -NS_IMETHODIMP nsComposerController::DoCommandWithParams(const char *aCommand, nsICommandParams *aCommandParams) -{ - if (!mCommandRefCon || !mCommandManager) - return NS_ERROR_NOT_INITIALIZED; - return mCommandManager->DoCommandParams(aCommand, aCommandParams,mCommandRefCon); -} diff --git a/mozilla/editor/composer/src/nsComposerController.h b/mozilla/editor/composer/src/nsComposerController.h index 523ec6f11dd..0b7b523f8dd 100644 --- a/mozilla/editor/composer/src/nsComposerController.h +++ b/mozilla/editor/composer/src/nsComposerController.h @@ -39,66 +39,27 @@ #ifndef nsComposerController_h__ #define nsComposerController_h__ -#define NS_COMPOSERCONTROLLER_CID \ -{ 0x50e95301, 0x17a8, 0x11d4, { 0x9f, 0x7e, 0xdd, 0x53, 0x0d, 0x5f, 0x05, 0x7c } } -#include "nsString.h" -#include "nsIEditorController.h" -#include "nsIController.h" -#include "nsIInterfaceRequestor.h" -#include "nsIInterfaceRequestorUtils.h" -#include "nsIControllerCommand.h" -#include "nsIControllerCommandManager.h" -#include "nsWeakPtr.h" +class nsIControllerCommandManager; -// the editor controller is used for composer only (and other HTML compose -// areas). The refCon that gets passed to its commands is an nsIEditor. -class nsComposerController : public nsIController, - public nsICommandController, - public nsIEditorController, - public nsIInterfaceRequestor +// The plaintext editor controller is used for basic text editing and html editing +// commands in composer +// The refCon that gets passed to its commands is initially nsIEditingSession, +// and after successfule editor creation it is changed to nsIEditor. +#define NS_EDITORDOCSTATECONTROLLER_CID \ + { 0x50e95301, 0x17a8, 0x11d4, { 0x9f, 0x7e, 0xdd, 0x53, 0x0d, 0x5f, 0x05, 0x7c } } + +// The HTMLEditor controller is used only for HTML editors and takes nsIEditor as refCon +#define NS_HTMLEDITORCONTROLLER_CID \ + { 0x62db0002, 0xdbb6, 0x43f4, { 0x8f, 0xb7, 0x9d, 0x25, 0x38, 0xbc, 0x57, 0x47 } } + + +class nsComposerController { public: - - nsComposerController(); - virtual ~nsComposerController(); - - // nsISupports - NS_DECL_ISUPPORTS - - // nsIController - NS_DECL_NSICONTROLLER - - /** init the controller */ - NS_IMETHOD Init(nsISupports *aCommandRefCon); - - /** Set the cookie that is passed to commands - */ - NS_IMETHOD SetCommandRefCon(nsISupports *aCommandRefCon); - - // nsIInterfaceRequestor - NS_DECL_NSIINTERFACEREQUESTOR - - //nsICommandController - NS_DECL_NSICOMMANDCONTROLLER - -protected: - - //if editor is null then look to mContent. this is for dual use of window and content - //attached controller. - nsISupports *mCommandRefCon; - - nsCOMPtr mCommandManager; // our reference to the command manager - -private: - - static nsresult GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager); - static nsresult RegisterComposerCommands(nsIControllerCommandManager* inCommandManager); - - // the singleton command manager - static nsWeakPtr sComposerCommandManager; // common composer commands - + static nsresult RegisterEditorDocStateCommands(nsIControllerCommandManager* inCommandManager); + static nsresult RegisterHTMLEditorCommands(nsIControllerCommandManager* inCommandManager); }; #endif /* nsComposerController_h__ */ diff --git a/mozilla/editor/composer/src/nsComposerRegistration.cpp b/mozilla/editor/composer/src/nsComposerRegistration.cpp index 45fab66e318..1639254d21c 100644 --- a/mozilla/editor/composer/src/nsComposerRegistration.cpp +++ b/mozilla/editor/composer/src/nsComposerRegistration.cpp @@ -20,6 +20,8 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Michael Judge + * Charles Manske * * * Alternatively, the contents of this file may be used under the terms of @@ -38,11 +40,11 @@ #include "nsIGenericFactory.h" -#include "nsEditorShell.h" // for the CID #include "nsEditingSession.h" // for the CID #include "nsComposerController.h" // for the CID #include "nsEditorSpellCheck.h" // for the CID #include "nsEditorService.h" +#include "nsIControllerContext.h" //////////////////////////////////////////////////////////////////////// // Define the contructor function for the objects @@ -50,25 +52,90 @@ // NOTE: This creates an instance of objects by using the default constructor // -NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorShell) NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditingSession) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsComposerController) NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorSpellCheck) + +NS_IMETHODIMP nsEditorDocStateControllerConstructor(nsISupports *aOuter, REFNSIID aIID, + void **aResult) +{ + static PRBool sDocStateCommandsRegistered = PR_FALSE; + + nsresult rv; + nsCOMPtr context = + do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv); + if (NS_FAILED(rv)) + return rv; + if (!context) + return NS_ERROR_FAILURE; + + nsCOMPtr composerCommandManager( + do_GetService(NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CONTRACTID, &rv)); + + if (NS_FAILED(rv)) + return rv; + if (!composerCommandManager) + return NS_ERROR_OUT_OF_MEMORY; + if (!sDocStateCommandsRegistered) + { + rv = nsComposerController::RegisterEditorDocStateCommands(composerCommandManager); + if (NS_FAILED(rv)) + { + return rv; + } + sDocStateCommandsRegistered = PR_TRUE; + } + + context->SetControllerCommandManager(composerCommandManager); + return context->QueryInterface(aIID, aResult); +} + +NS_IMETHODIMP nsHTMLEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID, + void **aResult) +{ + static PRBool sHTMLCommandsRegistered = PR_FALSE; + + nsresult rv; + nsCOMPtr context = + do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv); + if (NS_FAILED(rv)) + return rv; + if (!context) + return NS_ERROR_FAILURE; + + nsCOMPtr composerCommandManager( + do_GetService(NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CONTRACTID, &rv)); + if (NS_FAILED(rv)) + return rv; + if (!composerCommandManager) + return NS_ERROR_OUT_OF_MEMORY; + if (!sHTMLCommandsRegistered) + { + rv = nsComposerController::RegisterHTMLEditorCommands(composerCommandManager); + if (NS_FAILED(rv)) + { + return rv; + } + sHTMLCommandsRegistered = PR_TRUE; + } + + context->SetControllerCommandManager(composerCommandManager); + return context->QueryInterface(aIID, aResult); +} + //////////////////////////////////////////////////////////////////////// // Define a table of CIDs implemented by this module along with other // information like the function to create an instance, contractid, and // class name. // static const nsModuleComponentInfo components[] = { - { "Composer Controller", NS_COMPOSERCONTROLLER_CID, - "@mozilla.org/editor/composercontroller;1", - nsComposerControllerConstructor, }, - { "Editor Shell Component", NS_EDITORSHELL_CID, - "@mozilla.org/editor/editorshell;1", nsEditorShellConstructor, }, - { "Editor Shell Spell Checker", NS_EDITORSHELL_CID, - "@mozilla.org/editor/editorspellcheck;1", nsEditorShellConstructor, }, + { "Editor DocState Controller", NS_EDITORDOCSTATECONTROLLER_CID, + "@mozilla.org/editor/editordocstatecontroller;1", + nsEditorDocStateControllerConstructor, }, + { "HTML Editor Controller", NS_HTMLEDITORCONTROLLER_CID, + "@mozilla.org/editor/htmleditorcontroller;1", + nsHTMLEditorControllerConstructor, }, { "Editing Session", NS_EDITINGSESSION_CID, "@mozilla.org/editor/editingsession;1", nsEditingSessionConstructor, }, { "Editor Service", NS_EDITORSERVICE_CID, diff --git a/mozilla/editor/composer/src/nsEditingSession.cpp b/mozilla/editor/composer/src/nsEditingSession.cpp index 755316f8f3c..908593d0502 100644 --- a/mozilla/editor/composer/src/nsEditingSession.cpp +++ b/mozilla/editor/composer/src/nsEditingSession.cpp @@ -20,7 +20,9 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Simon Fraser + * Simon Fraser + * Michael Judge + * Charles Manske * * * Alternatively, the contents of this file may be used under the terms of @@ -48,15 +50,15 @@ #include "nsIChannel.h" #include "nsIWebProgress.h" +#include "nsIWebNavigation.h" #include "nsIControllers.h" #include "nsIController.h" -#include "nsIEditorController.h" +#include "nsIControllerContext.h" #include "nsIPresShell.h" #include "nsComposerCommandsUpdater.h" - #include "nsEditingSession.h" #include "nsIComponentManager.h" @@ -67,9 +69,13 @@ #include "nsISelectionController.h" #include "nsIPlaintextEditor.h" +#include "nsIDOMNSDocument.h" + +#include "nsEditorParserObserver.h" #if DEBUG -#define NOISY_DOC_LOADING 1 +#include "nsIURI.h" +//#define NOISY_DOC_LOADING 1 #endif /*--------------------------------------------------------------------------- @@ -78,7 +84,14 @@ ----------------------------------------------------------------------------*/ nsEditingSession::nsEditingSession() -: mDoneSetup(PR_FALSE), mEditorClassString(nsnull) +: mDoneSetup(PR_FALSE) +, mCanCreateEditor(PR_FALSE) +, mEditorType(nsnull) +, mEditorFlags(0) +, mEditorStatus(eEditorOK) +, mBaseCommandControllerId(0) +, mDocStateControllerId(0) +, mHTMLCommandControllerId(0) { NS_INIT_ISUPPORTS(); } @@ -90,10 +103,10 @@ nsEditingSession::nsEditingSession() ----------------------------------------------------------------------------*/ nsEditingSession::~nsEditingSession() { - NS_IF_RELEASE(mStateMaintainer); } -NS_IMPL_ISUPPORTS3(nsEditingSession, nsIEditingSession, nsIWebProgressListener, nsISupportsWeakReference) +NS_IMPL_ISUPPORTS3(nsEditingSession, nsIEditingSession, nsIWebProgressListener, + nsISupportsWeakReference) /*--------------------------------------------------------------------------- @@ -120,37 +133,26 @@ nsEditingSession::Init(nsIDOMWindow *aWindow) MakeWindowEditable aEditorType string, "html" "htmlsimple" "text" "textsimple" - void makeWindowEditable(in nsIDOMWindow aWindow, in string aEditorType, in boolean inDoAfterUriLoad); + void makeWindowEditable(in nsIDOMWindow aWindow, in string aEditorType, + in boolean aDoAfterUriLoad); ----------------------------------------------------------------------------*/ +#define DEFAULT_EDITOR_TYPE "html" + NS_IMETHODIMP -nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, const char *aEditorType, PRBool inDoAfterUriLoad) +nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, + const char *aEditorType, + PRBool aDoAfterUriLoad) { - PRBool htmlController = PR_FALSE; - mEditorClassString = nsnull; + mEditorType.Truncate(); mEditorFlags = 0; + // Tells embedder that startup is in progress + mEditorStatus = eEditorCreationInProgress; + //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; + if (!aEditorType) + aEditorType = DEFAULT_EDITOR_TYPE; + mEditorType = aEditorType; nsresult rv = PrepareForEditing(); if (NS_FAILED(rv)) return rv; @@ -160,18 +162,38 @@ nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, const char *aEditorT if (NS_FAILED(rv)) return rv; // set the flag on the docShell to say that it's editable - rv = editorDocShell->MakeEditable(inDoAfterUriLoad); + rv = editorDocShell->MakeEditable(aDoAfterUriLoad); if (NS_FAILED(rv)) return rv; - rv = SetupFrameControllers(aWindow, htmlController); + // Setup commands common to plaintext and html editors, + // including the document creation observers + // the first is an editor controller + rv = SetupEditorCommandController("@mozilla.org/editor/editorcontroller;1", + aWindow, + NS_STATIC_CAST(nsIEditingSession*, this), + &mBaseCommandControllerId); if (NS_FAILED(rv)) return rv; - if (!inDoAfterUriLoad) + // the second is an controller to monitor doc state, + // such as creation and "dirty flag" + rv = SetupEditorCommandController("@mozilla.org/editor/editordocstatecontroller;1", + aWindow, + NS_STATIC_CAST(nsIEditingSession*, this), + &mDocStateControllerId); + if (NS_FAILED(rv)) return rv; + + // aDoAfterUriLoad can be false only when making an existing window editable + if (!aDoAfterUriLoad) { rv = SetupEditorOnWindow(aWindow); - if (NS_FAILED(rv)) return rv; + + // mEditorStatus is set to the error reason + // Since this is used only when editing an existing page, + // it IS ok to destroy current editor + if (NS_FAILED(rv)) + TearDownEditorOnWindow(aWindow); } - return NS_OK; + return rv; } /*--------------------------------------------------------------------------- @@ -180,15 +202,66 @@ nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, const char *aEditorT boolean windowIsEditable (in nsIDOMWindow aWindow); ----------------------------------------------------------------------------*/ -NS_IMETHODIMP nsEditingSession::WindowIsEditable(nsIDOMWindow *aWindow, PRBool *outIsEditable) +NS_IMETHODIMP +nsEditingSession::WindowIsEditable(nsIDOMWindow *aWindow, PRBool *outIsEditable) { nsCOMPtr editorDocShell; - nsresult rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell)); + nsresult rv = GetEditorDocShellFromWindow(aWindow, + getter_AddRefs(editorDocShell)); if (NS_FAILED(rv)) return rv; return editorDocShell->GetEditable(outIsEditable); } + +// These are MIME types that are automatically parsed as "text/plain" +// and thus we can edit them as plaintext +// Note: in older versions, we attempted to convert the mimetype of +// the network channel for these and "text/xml" to "text/plain", +// but further investigation reveals that strategy doesn't work +const char* const gSupportedTextTypes[] = { + "text/plain", + "text/css", + "text/rdf", + "text/xsl", + "text/javascript", // obsolete type + "application/x-javascript", + "text/xul", // obsolete type + "application/vnd.mozilla.xul+xml", + NULL // IMPORTANT! Null must be at end +}; + +// Elements that editor cannot currently support (11/11/02), +// but hopefully we will be able to soon. +#ifndef FULL_EDITOR_HTML_SUPPORT +static eHTMLTags gWatchTags[] = +{ eHTMLTag_frameset, + eHTMLTag_iframe, + eHTMLTag_unknown +}; +#endif + + +PRBool +IsSupportedTextType(const char* aMIMEType) +{ + if (!aMIMEType) + return PR_FALSE; + + PRInt32 i = 0; + while (gSupportedTextTypes[i]) + { + if (strcmp(gSupportedTextTypes[i], aMIMEType) == 0) + { + return PR_TRUE; + } + + i ++; + } + + return PR_FALSE; +} + /*--------------------------------------------------------------------------- SetupEditorOnWindow @@ -198,82 +271,176 @@ NS_IMETHODIMP nsEditingSession::WindowIsEditable(nsIDOMWindow *aWindow, PRBool * NS_IMETHODIMP nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow) { - nsresult rv = PrepareForEditing(); - if (NS_FAILED(rv)) return rv; + nsresult rv; + //MIME CHECKING + //must get the content type + // Note: the doc gets this from the network channel during StartPageLoad, + // so we don't have to get it from there ourselves + nsCOMPtr doc; + nsCAutoString mimeCType; + + //then lets check the mime type + if (NS_SUCCEEDED(aWindow->GetDocument(getter_AddRefs(doc))) && doc) + { + nsCOMPtr nsdoc = do_QueryInterface(doc); + if (nsdoc) + { + nsAutoString mimeType; + if (NS_SUCCEEDED(nsdoc->GetContentType(mimeType))) + mimeCType = NS_ConvertUCS2toUTF8(mimeType); + + if (IsSupportedTextType(mimeCType.get())) + { + mEditorType = NS_LITERAL_CSTRING("text"); + mimeCType = "text/plain"; + } + else if (!mimeCType.Equals(NS_LITERAL_CSTRING("text/html"))) + { + // Neither an acceptable text or html type. + mEditorStatus = eEditorErrorCantEditMimeType; + + // Turn editor into HTML -- we will load blank page later + mEditorType = NS_LITERAL_CSTRING("html"); + mimeCType = NS_LITERAL_CSTRING("text/html"); + } + } + } + PRBool needHTMLController = PR_FALSE; + + const char *classString = "@mozilla.org/editor/htmleditor;1"; + if (mEditorType.Equals(NS_LITERAL_CSTRING("textmail"))) + { + mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask | + nsIPlaintextEditor::eEditorEnableWrapHackMask | + nsIPlaintextEditor::eEditorMailMask; + } + else if (mEditorType.Equals(NS_LITERAL_CSTRING("text"))) + { + mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask | + nsIPlaintextEditor::eEditorEnableWrapHackMask; + } + else if (mEditorType.Equals(NS_LITERAL_CSTRING("htmlmail"))) + { + if (mimeCType.Equals(NS_LITERAL_CSTRING("text/html"))) + { + needHTMLController = PR_TRUE; + mEditorFlags = nsIPlaintextEditor::eEditorMailMask; + } + else //set the flags back to textplain. + mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask | + nsIPlaintextEditor::eEditorEnableWrapHackMask; + } + else // Defaulted to html + { + needHTMLController = PR_TRUE; + } + + // make the UI state maintainer + nsComposerCommandsUpdater *stateMaintainer; + NS_NEWXPCOM(stateMaintainer, nsComposerCommandsUpdater); + mStateMaintainer = NS_STATIC_CAST(nsISelectionListener*, stateMaintainer); + + if (!mStateMaintainer) return NS_ERROR_OUT_OF_MEMORY; + + // now init the state maintainer + // This allows notification of error state + // even if we don't create an editor + rv = stateMaintainer->Init(aWindow); + if (NS_FAILED(rv)) return rv; + + if (mEditorStatus != eEditorCreationInProgress) + { + // We had an earlier error -- force notification of document creation + nsCOMPtr docListener = + do_QueryInterface(mStateMaintainer); + if (docListener) + docListener->NotifyDocumentCreated(); + + return NS_ERROR_FAILURE; + } + + // Create editor and do other things + // only if we haven't found some error above, nsCOMPtr docShell; rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); if (NS_FAILED(rv)) return rv; - - nsCOMPtr editorDocShell(do_QueryInterface(docShell, &rv)); + + nsCOMPtr editorDocShell = do_QueryInterface(docShell, &rv); if (NS_FAILED(rv)) return rv; - - nsCOMPtr editor(do_CreateInstance(mEditorClassString, &rv)); + + nsCOMPtr editor = do_CreateInstance(classString, &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; - + + // setup the HTML editor command controller + if (needHTMLController) + { + // The third controller takes an nsIEditor as the refCon + rv = SetupEditorCommandController("@mozilla.org/editor/htmleditorcontroller;1", + aWindow, editor, + &mHTMLCommandControllerId); + if (NS_FAILED(rv)) return rv; + } + + // Set mimetype on editor + rv = editor->SetContentsMIMEType(mimeCType.get()); + if (NS_FAILED(rv)) return rv; + nsCOMPtr presShell; rv = docShell->GetPresShell(getter_AddRefs(presShell)); if (NS_FAILED(rv)) return rv; if (!presShell) return NS_ERROR_FAILURE; - + nsCOMPtr contentViewer; rv = docShell->GetContentViewer(getter_AddRefs(contentViewer)); if (NS_FAILED(rv)) return rv; if (!contentViewer) return NS_ERROR_FAILURE; - + nsCOMPtr domDoc; rv = contentViewer->GetDOMDocument(getter_AddRefs(domDoc)); if (NS_FAILED(rv)) return rv; if (!domDoc) return NS_ERROR_FAILURE; - + + // Set up as a doc state listener + // Important! We must have this to broadcast the "obs_documentCreated" message + rv = editor->AddDocumentStateListener( + NS_STATIC_CAST(nsIDocumentStateListener*, stateMaintainer)); + if (NS_FAILED(rv)) return rv; + nsCOMPtr selCon = do_QueryInterface(presShell); - - rv = editor->Init(domDoc, presShell, nsnull /* root content */, selCon, mEditorFlags); - if (NS_FAILED(rv)) return rv; - - rv = editor->PostCreate(); + rv = editor->Init(domDoc, presShell, nsnull /* root content */, + selCon, mEditorFlags); if (NS_FAILED(rv)) return rv; - // set the editor on the controller - rv = SetEditorOnControllers(aWindow, editor); - if (NS_FAILED(rv)) return rv; - - // make the UI state maintainer - NS_NEWXPCOM(mStateMaintainer, nsComposerCommandsUpdater); - if (!mStateMaintainer) return NS_ERROR_OUT_OF_MEMORY; - mStateMaintainer->AddRef(); // the owning reference - - // now init the state maintainer - // XXX this needs to swap out editors - rv = mStateMaintainer->SetEditor(editor); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr selection; - editor->GetSelection(getter_AddRefs(selection)); + nsCOMPtr selection; + editor->GetSelection(getter_AddRefs(selection)); nsCOMPtr selPriv = do_QueryInterface(selection); - if (!selPriv) return NS_ERROR_FAILURE; + if (!selPriv) return NS_ERROR_FAILURE; - rv = selPriv->AddSelectionListener(mStateMaintainer); + rv = selPriv->AddSelectionListener(stateMaintainer); if (NS_FAILED(rv)) return rv; - // and set it up as a doc state listener - rv = editor->AddDocumentStateListener(NS_STATIC_CAST(nsIDocumentStateListener*, mStateMaintainer)); - if (NS_FAILED(rv)) return rv; - // and as a transaction listener nsCOMPtr txnMgr; editor->GetTransactionManager(getter_AddRefs(txnMgr)); if (txnMgr) - { - txnMgr->AddListener(NS_STATIC_CAST(nsITransactionListener*, mStateMaintainer)); - } - - return NS_OK; -} + txnMgr->AddListener(NS_STATIC_CAST(nsITransactionListener*, + stateMaintainer)); + // Set refCon on all controllers to be the editor + rv = SetEditorOnControllers(aWindow, editor); + if (NS_FAILED(rv)) return rv; + + // Everything went fine! + mEditorStatus = eEditorOK; + + + // This will trigger documentCreation notification + return editor->PostCreate(); +} /*--------------------------------------------------------------------------- @@ -286,19 +453,49 @@ nsEditingSession::TearDownEditorOnWindow(nsIDOMWindow *aWindow) { nsresult rv; - // null out the editor on the controller - rv = SetEditorOnControllers(aWindow, nsnull); - if (NS_FAILED(rv)) return rv; + if (mStateMaintainer) + { + nsCOMPtr editor; + rv = GetEditorForWindow(aWindow, getter_AddRefs(editor)); + if (editor) + { + // Remove all the listeners + nsCOMPtr selection; + editor->GetSelection(getter_AddRefs(selection)); + nsCOMPtr selPriv = do_QueryInterface(selection); + if (!selPriv) return NS_ERROR_FAILURE; + + nsCOMPtr listener = + do_QueryInterface(mStateMaintainer); + rv = selPriv->RemoveSelectionListener(listener); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr docListener = + do_QueryInterface(mStateMaintainer); + rv = editor->RemoveDocumentStateListener(docListener); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr txnMgr; + editor->GetTransactionManager(getter_AddRefs(txnMgr)); + if (txnMgr) + { + nsCOMPtr transactionListener = + do_QueryInterface(mStateMaintainer); + txnMgr->RemoveListener(transactionListener); + } + + // null out the editor on the controllers + rv = SetEditorOnControllers(aWindow, nsnull); + if (NS_FAILED(rv)) return rv; + } + } nsCOMPtr editorDocShell; rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell)); if (NS_FAILED(rv)) return rv; // null out the editor on the docShell - rv = editorDocShell->SetEditor(nsnull); - if (NS_FAILED(rv)) return rv; - - return NS_OK; + return editorDocShell->SetEditor(nsnull); } /*--------------------------------------------------------------------------- @@ -308,10 +505,12 @@ nsEditingSession::TearDownEditorOnWindow(nsIDOMWindow *aWindow) nsIEditor getEditorForFrame (in nsIDOMWindow aWindow); ----------------------------------------------------------------------------*/ NS_IMETHODIMP -nsEditingSession::GetEditorForWindow(nsIDOMWindow *aWindow, nsIEditor **outEditor) +nsEditingSession::GetEditorForWindow(nsIDOMWindow *aWindow, + nsIEditor **outEditor) { nsCOMPtr editorDocShell; - nsresult rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell)); + nsresult rv = GetEditorDocShellFromWindow(aWindow, + getter_AddRefs(editorDocShell)); if (NS_FAILED(rv)) return rv; return editorDocShell->GetEditor(outEditor); @@ -327,24 +526,64 @@ nsEditingSession::GetEditorForWindow(nsIDOMWindow *aWindow, nsIEditor **outEdito ----------------------------------------------------------------------------*/ NS_IMETHODIMP -nsEditingSession::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus) +nsEditingSession::OnStateChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRUint32 aStateFlags, nsresult aStatus) { + +#ifdef NOISY_DOC_LOADING + nsCOMPtr channel(do_QueryInterface(aRequest)); + if (channel) + { + nsCAutoString contentType; + channel->GetContentType(contentType); + if (!contentType.IsEmpty()) + printf(" ++++++ MIMETYPE = %s", contentType.get()); + } +#endif + // // A Request has started... // if (aStateFlags & nsIWebProgressListener::STATE_START) { +#ifdef NOISY_DOC_LOADING + { + nsCOMPtr channel(do_QueryInterface(aRequest)); + if (channel) + { + nsCOMPtr uri; + channel->GetURI(getter_AddRefs(uri)); + if (uri) + { + nsXPIDLCString spec; + uri->GetSpec(spec); + printf(" **** STATE_START: CHANNEL URI=%s, flags=%x\n",spec.get(), aStateFlags); + } + } + else + printf(" STATE_START: NO CHANNEL flags=%x\n", aStateFlags); + } +#endif // Page level notification... if (aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) { - StartPageLoad(aWebProgress); + nsCOMPtr channel(do_QueryInterface(aRequest)); + StartPageLoad(channel); +#ifdef NOISY_DOC_LOADING + printf("STATE_START & STATE_IS_NETWORK flags=%x\n", aStateFlags); +#endif } // Document level notification... if (aStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT) { + mCanCreateEditor = PR_TRUE; if (NotifyingCurrentDocument(aWebProgress)) (void)StartDocumentLoad(aWebProgress); +#ifdef NOISY_DOC_LOADING + printf("STATE_START & STATE_IS_DOCUMENT flags=%x\n", aStateFlags); +#endif } } // @@ -373,21 +612,50 @@ nsEditingSession::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aReque else if (aStateFlags & nsIWebProgressListener::STATE_STOP) { +#ifdef NOISY_DOC_LOADING + { + nsCOMPtr channel(do_QueryInterface(aRequest)); + if (channel) + { + nsCOMPtr uri; + channel->GetURI(getter_AddRefs(uri)); + if (uri) + { + nsXPIDLCString spec; + uri->GetSpec(spec); + printf(" **** STATE_STOP: CHANNEL URI=%s, flags=%x\n",spec.get(), aStateFlags); + } + } + else + printf(" STATE_STOP: NO CHANNEL flags=%x\n", aStateFlags); + } +#endif // Document level notification... if (aStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT) { if (NotifyingCurrentDocument(aWebProgress)) { - nsCOMPtr channel(do_QueryInterface(aRequest)); - (void)EndDocumentLoad(aWebProgress, channel, aStatus); + // Ignore STOP messages we get before we received a START + if (mCanCreateEditor) + { + mCanCreateEditor = PR_FALSE; + nsCOMPtr channel = do_QueryInterface(aRequest); + nsresult rv = EndDocumentLoad(aWebProgress, channel, aStatus); +#ifdef NOISY_DOC_LOADING + printf("STATE_STOP & STATE_IS_DOCUMENT flags=%x\n", aStateFlags); +#endif + } } } // Page level notification... if (aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) { - nsCOMPtr channel(do_QueryInterface(aRequest)); + nsCOMPtr channel = do_QueryInterface(aRequest); (void)EndPageLoad(aWebProgress, channel, aStatus); +#ifdef NOISY_DOC_LOADING + printf("STATE_STOP & STATE_IS_NETWORK flags=%x\n", aStateFlags); +#endif } } @@ -400,7 +668,12 @@ nsEditingSession::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aReque ----------------------------------------------------------------------------*/ NS_IMETHODIMP -nsEditingSession::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) +nsEditingSession::OnProgressChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 aCurSelfProgress, + PRInt32 aMaxSelfProgress, + PRInt32 aCurTotalProgress, + PRInt32 aMaxTotalProgress) { NS_NOTREACHED("notification excluded in AddProgressListener(...)"); return NS_OK; @@ -412,7 +685,8 @@ nsEditingSession::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRe ----------------------------------------------------------------------------*/ NS_IMETHODIMP -nsEditingSession::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location) +nsEditingSession::OnLocationChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, nsIURI *location) { NS_NOTREACHED("notification excluded in AddProgressListener(...)"); return NS_OK; @@ -424,7 +698,10 @@ nsEditingSession::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRe ----------------------------------------------------------------------------*/ NS_IMETHODIMP -nsEditingSession::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage) +nsEditingSession::OnStatusChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + nsresult aStatus, + const PRUnichar *aMessage) { NS_NOTREACHED("notification excluded in AddProgressListener(...)"); return NS_OK; @@ -436,7 +713,8 @@ nsEditingSession::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequ ----------------------------------------------------------------------------*/ NS_IMETHODIMP -nsEditingSession::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) +nsEditingSession::OnSecurityChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, PRUint32 state) { NS_NOTREACHED("notification excluded in AddProgressListener(...)"); return NS_OK; @@ -461,6 +739,22 @@ nsEditingSession::NotifyingCurrentDocument(nsIWebProgress *aWebProgress) } +/*--------------------------------------------------------------------------- + + GetEditorStatus + + Called during GetCommandStateParams("obs_documentCreated"...) + to determine if editor was created and document + was loaded successfully +----------------------------------------------------------------------------*/ +NS_IMETHODIMP +nsEditingSession::GetEditorStatus(PRUint32 *aStatus) +{ + NS_ENSURE_ARG_POINTER(aStatus); + *aStatus = mEditorStatus; + return NS_OK; +} + /*--------------------------------------------------------------------------- StartDocumentLoad @@ -474,7 +768,7 @@ nsEditingSession::StartDocumentLoad(nsIWebProgress *aWebProgress) printf("Editing session StartDocumentLoad\n"); #endif - NS_ENSURE_ARG(aWebProgress); + NS_ENSURE_ARG_POINTER(aWebProgress); // If we have an editor here, then we got a reload after making the editor. // We need to blow it away and make a new one at the end of the load. @@ -486,6 +780,7 @@ nsEditingSession::StartDocumentLoad(nsIWebProgress *aWebProgress) nsresult rv = TearDownEditorOnWindow(domWindow); } + mEditorStatus = eEditorCreationInProgress; return NS_OK; } @@ -496,25 +791,32 @@ nsEditingSession::StartDocumentLoad(nsIWebProgress *aWebProgress) Called on end of load in a single frame ----------------------------------------------------------------------------*/ nsresult -nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress, nsIChannel* aChannel, nsresult aStatus) +nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress, + nsIChannel* aChannel, nsresult aStatus) { - NS_ENSURE_ARG(aWebProgress); + NS_ENSURE_ARG_POINTER(aWebProgress); #ifdef NOISY_DOC_LOADING printf("Editing shell EndDocumentLoad\n"); #endif - // we want to call the base class EndDocumentLoad, but avoid some of the stuff + // We want to call the base class EndDocumentLoad, but avoid some of the stuff // that nsWebShell does (need to refactor). // OK, time to make an editor on this document nsCOMPtr domWindow; aWebProgress->GetDOMWindow(getter_AddRefs(domWindow)); + // Set the error state -- we will create an editor + // anyway and load empty doc later + if (aStatus == NS_ERROR_FILE_NOT_FOUND) + mEditorStatus = eEditorErrorFileNotFound; + nsCOMPtr docShell; nsresult rv = GetDocShellFromWindow(domWindow, getter_AddRefs(docShell)); if (NS_FAILED(rv)) return rv; // better error handling? - nsCOMPtr editorDocShell(do_QueryInterface(docShell)); + nsCOMPtr editorDocShell = do_QueryInterface(docShell); + // did someone set the flag to make this shell editable? if (editorDocShell) { @@ -523,14 +825,44 @@ nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress, nsIChannel* aCha if (makeEditable) { - nsresult rv = SetupEditorOnWindow(domWindow); + rv = SetupEditorOnWindow(domWindow); + if (NS_FAILED(rv)) + { + // If we had an error, setup timer to load a blank page later + if (mLoadBlankDocTimer) + { + // Must cancel previous timer? + mLoadBlankDocTimer->Cancel(); + mLoadBlankDocTimer = NULL; + } + + mLoadBlankDocTimer = do_CreateInstance("@mozilla.org/timer;1", &rv); + if (NS_FAILED(rv)) return rv; + + mEditorStatus = eEditorCreationInProgress; + mLoadBlankDocTimer->InitWithFuncCallback(nsEditingSession::TimerCallback, + (void*)docShell, + 10, nsITimer::TYPE_ONE_SHOT); + } } } - - return NS_OK; + return rv; } +void +nsEditingSession::TimerCallback(nsITimer* aTimer, void* aClosure) +{ + nsCOMPtr docShell = (nsIDocShell*)aClosure; + if (docShell) + { + nsCOMPtr webNav(do_QueryInterface(docShell)); + if (webNav) + webNav->LoadURI(NS_LITERAL_STRING("about:blank").get(), + 0, nsnull, nsnull, nsnull); + } +} + /*--------------------------------------------------------------------------- StartPageLoad @@ -538,8 +870,11 @@ nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress, nsIChannel* aCha Called on start load of the entire page (incl. subframes) ----------------------------------------------------------------------------*/ nsresult -nsEditingSession::StartPageLoad(nsIWebProgress *aWebProgress) +nsEditingSession::StartPageLoad(nsIChannel *aChannel) { +#ifdef NOISY_DOC_LOADING + printf("======= StartPageLoad ========\n"); +#endif return NS_OK; } @@ -550,8 +885,14 @@ nsEditingSession::StartPageLoad(nsIWebProgress *aWebProgress) Called on end load of the entire page (incl. subframes) ----------------------------------------------------------------------------*/ nsresult -nsEditingSession::EndPageLoad(nsIWebProgress *aWebProgress, nsIChannel* aChannel, nsresult aStatus) +nsEditingSession::EndPageLoad(nsIWebProgress *aWebProgress, + nsIChannel* aChannel, nsresult aStatus) { + // Set the error state -- we will create an editor anyway + // and load empty doc later + if (aStatus == NS_ERROR_FILE_NOT_FOUND) + mEditorStatus = eEditorErrorFileNotFound; + return NS_OK; } @@ -568,9 +909,10 @@ nsEditingSession::EndPageLoad(nsIWebProgress *aWebProgress, nsIChannel* aChannel is returned. ----------------------------------------------------------------------------*/ nsresult -nsEditingSession::GetDocShellFromWindow(nsIDOMWindow *inWindow, nsIDocShell** outDocShell) +nsEditingSession::GetDocShellFromWindow(nsIDOMWindow *aWindow, + nsIDocShell** outDocShell) { - nsCOMPtr scriptGO(do_QueryInterface(inWindow)); + nsCOMPtr scriptGO = do_QueryInterface(aWindow); if (!scriptGO) return NS_ERROR_FAILURE; nsresult rv = scriptGO->GetDocShell(outDocShell); @@ -587,13 +929,15 @@ nsEditingSession::GetDocShellFromWindow(nsIDOMWindow *inWindow, nsIDocShell** ou is returned. ----------------------------------------------------------------------------*/ nsresult -nsEditingSession::GetEditorDocShellFromWindow(nsIDOMWindow *inWindow, nsIEditorDocShell** outDocShell) +nsEditingSession::GetEditorDocShellFromWindow(nsIDOMWindow *aWindow, + nsIEditorDocShell** outDocShell) { nsCOMPtr docShell; - nsresult rv = GetDocShellFromWindow(inWindow, getter_AddRefs(docShell)); + nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); if (NS_FAILED(rv)) return rv; - return docShell->QueryInterface(NS_GET_IID(nsIEditorDocShell), (void **)outDocShell); + return docShell->QueryInterface(NS_GET_IID(nsIEditorDocShell), + (void **)outDocShell); } /*--------------------------------------------------------------------------- @@ -620,56 +964,57 @@ nsEditingSession::PrepareForEditing() nsCOMPtr webProgress = do_GetInterface(docShell); if (!webProgress) return NS_ERROR_FAILURE; - nsresult rv = webProgress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_ALL); - if (NS_FAILED(rv)) return rv; - - return NS_OK; + return webProgress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_ALL); } - /*--------------------------------------------------------------------------- - SetupFrameControllers + SetupEditorCommandController - Set up the controller for this frame. + Create a command controller, append to controllers, + get and return the controller ID, and set the refCon ----------------------------------------------------------------------------*/ nsresult -nsEditingSession::SetupFrameControllers(nsIDOMWindow *inWindow, PRBool aSetupComposerController) +nsEditingSession::SetupEditorCommandController(const char *aControllerClassName, + nsIDOMWindow *aWindow, + nsISupports *aRefCon, + PRUint32 *aControllerId) { + NS_ENSURE_ARG_POINTER(aControllerClassName); + NS_ENSURE_ARG_POINTER(aWindow); + NS_ENSURE_ARG_POINTER(aRefCon); + NS_ENSURE_ARG_POINTER(aControllerId); + nsresult rv; - - nsCOMPtr domWindowInt(do_QueryInterface(inWindow, &rv)); + nsCOMPtr domWindowInt = do_QueryInterface(aWindow, &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr controllers; rv = domWindowInt->GetControllers(getter_AddRefs(controllers)); if (NS_FAILED(rv)) return rv; - // the first is an editor controller, and takes an nsIEditor as the refCon - nsCOMPtr controller(do_CreateInstance("@mozilla.org/editor/editorcontroller;1", &rv)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr editorController(do_QueryInterface(controller)); - rv = editorController->Init(nsnull); // we set the editor later when we have one - if (NS_FAILED(rv)) return rv; - - rv = controllers->InsertControllerAt(0, controller); - if (NS_FAILED(rv)) return rv; - - if (aSetupComposerController) + // We only have to create each singleton controller once + // We know this has happened once we have a controllerId value + if (!*aControllerId) { - // the second is an composer controller, and also takes an nsIEditor as the refCon - controller = do_CreateInstance("@mozilla.org/editor/composercontroller;1", &rv); + nsresult rv; + nsCOMPtr controller; + controller = do_CreateInstance(aControllerClassName, &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); + // We must insert at head of the list to be sure our + // controller is found before other implementations + // (e.g., not-implemented versions by browser) + rv = controllers->InsertControllerAt(0,controller); if (NS_FAILED(rv)) return rv; - } - return NS_OK; + + // Remember the ID for the controller + rv = controllers->GetControllerId(controller, aControllerId); + if (NS_FAILED(rv)) return rv; + } + + // Set the refCon + return SetRefConOnControllerById(controllers, aRefCon, *aControllerId); } /*--------------------------------------------------------------------------- @@ -679,39 +1024,56 @@ nsEditingSession::SetupFrameControllers(nsIDOMWindow *inWindow, PRBool aSetupCom Set the editor on the controller(s) for this window ----------------------------------------------------------------------------*/ nsresult -nsEditingSession::SetEditorOnControllers(nsIDOMWindow *inWindow, nsIEditor* inEditor) +nsEditingSession::SetEditorOnControllers(nsIDOMWindow *aWindow, + nsIEditor* aEditor) { nsresult rv; // set the editor on the controller - nsCOMPtr domWindowInt(do_QueryInterface(inWindow, &rv)); + nsCOMPtr domWindowInt = do_QueryInterface(aWindow, &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr controllers; rv = domWindowInt->GetControllers(getter_AddRefs(controllers)); if (NS_FAILED(rv)) return rv; - // find the editor controllers by QIing each one. This sucks. - // Controllers need to have IDs of some kind. - PRUint32 numControllers; - rv = controllers->GetControllerCount(&numControllers); - if (NS_FAILED(rv)) return rv; - - for (PRUint32 i = 0; i < numControllers; i ++) + nsCOMPtr editorAsISupports = do_QueryInterface(aEditor); + if (mBaseCommandControllerId) { - nsCOMPtr thisController; - controllers->GetControllerAt(i, getter_AddRefs(thisController)); - - nsCOMPtr editorController(do_QueryInterface(thisController)); // ok with nil controller - if (editorController) - { - rv = editorController->SetCommandRefCon(inEditor); - if (NS_FAILED(rv)) break; - } + rv = SetRefConOnControllerById(controllers, editorAsISupports, + mBaseCommandControllerId); + if (NS_FAILED(rv)) return rv; } - if (NS_FAILED(rv)) return rv; - return NS_OK; + if (mDocStateControllerId) + { + rv = SetRefConOnControllerById(controllers, editorAsISupports, + mDocStateControllerId); + if (NS_FAILED(rv)) return rv; + } + + if (mHTMLCommandControllerId) + rv = SetRefConOnControllerById(controllers, editorAsISupports, + mHTMLCommandControllerId); + + return rv; } +nsresult +nsEditingSession::SetRefConOnControllerById(nsIControllers* aControllers, + nsISupports* aRefCon, + PRUint32 aID) +{ + NS_ENSURE_ARG_POINTER(aControllers); + // aRefCon can be null (when destroying editor) + nsCOMPtr controller; + aControllers->GetControllerById(aID, getter_AddRefs(controller)); + + // ok with nil controller + nsCOMPtr editorController = + do_QueryInterface(controller); + if (!editorController) return NS_ERROR_FAILURE; + + return editorController->SetCommandRefCon(aRefCon); +} diff --git a/mozilla/editor/composer/src/nsEditingSession.h b/mozilla/editor/composer/src/nsEditingSession.h index a94490050df..14e6b8c9f5d 100644 --- a/mozilla/editor/composer/src/nsEditingSession.h +++ b/mozilla/editor/composer/src/nsEditingSession.h @@ -46,6 +46,11 @@ #endif #include "nsIEditor.h" +#include "nsITimer.h" + +#ifndef __gen_nsIControllers_h__ +#include "nsIControllers.h" +#endif #ifndef __gen_nsIDocShell_h__ #include "nsIDocShell.h" @@ -59,7 +64,7 @@ #include "nsIEditingSession.h" #endif - +#include "nsString.h" #define NS_EDITINGSESSION_CID \ { 0xbc26ff01, 0xf2bd, 0x11d4, { 0xa7, 0x3c, 0xe5, 0xa4, 0xb5, 0xa8, 0xbd, 0xfc } } @@ -67,6 +72,12 @@ class nsIWebProgress; class nsIEditorDocShell; +class nsIChannel; + +#ifndef FULL_EDITOR_HTML_SUPPORT +class nsEditorParserObserver; +#endif + class nsComposerCommandsUpdater; @@ -88,33 +99,60 @@ public: // nsIEditingSession NS_DECL_NSIEDITINGSESSION - protected: - nsresult GetDocShellFromWindow(nsIDOMWindow *inWindow, nsIDocShell** outDocShell); - nsresult GetEditorDocShellFromWindow(nsIDOMWindow *inWindow, nsIEditorDocShell** outDocShell); - nsresult SetupFrameControllers(nsIDOMWindow *inWindow, PRBool aSetupComposerController); + nsresult GetDocShellFromWindow(nsIDOMWindow *aWindow, + nsIDocShell** outDocShell); + nsresult GetEditorDocShellFromWindow(nsIDOMWindow *aWindow, + nsIEditorDocShell** outDocShell); - nsresult SetEditorOnControllers(nsIDOMWindow *inWindow, nsIEditor* inEditor); + nsresult SetupEditorCommandController(const char *aControllerClassName, + nsIDOMWindow *aWindow, + nsISupports *aRefCon, + PRUint32 *aControllerId); + nsresult SetEditorOnControllers(nsIDOMWindow *aWindow, + nsIEditor* aEditor); + nsresult SetRefConOnControllerById(nsIControllers* aControllers, + nsISupports* aRefCon, + PRUint32 aID); nsresult PrepareForEditing(); + + static void TimerCallback(nsITimer *aTimer, void *aClosure); + nsCOMPtr mLoadBlankDocTimer; // progress load stuff nsresult StartDocumentLoad(nsIWebProgress *aWebProgress); - nsresult EndDocumentLoad(nsIWebProgress *aWebProgress, nsIChannel* aChannel, nsresult aStatus); - nsresult StartPageLoad(nsIWebProgress *aWebProgress); - nsresult EndPageLoad(nsIWebProgress *aWebProgress, nsIChannel* aChannel, nsresult aStatus); + nsresult EndDocumentLoad(nsIWebProgress *aWebProgress, + nsIChannel* aChannel, nsresult aStatus); + nsresult StartPageLoad(nsIChannel *aChannel); + nsresult EndPageLoad(nsIWebProgress *aWebProgress, + nsIChannel* aChannel, nsresult aStatus); PRBool NotifyingCurrentDocument(nsIWebProgress *aWebProgress); protected: - nsWeakPtr mEditingShell; // weak ptr back to our editing (web) shell. It owns us. - PRBool mDoneSetup; // have we prepared for editing yet? + nsWeakPtr mEditingShell;// weak ptr to the editing (web) shell that owns us + 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 + // Used to prevent double creation of editor because nsIWebProgressListener + // receives a STATE_STOP notification before the STATE_START + // for our document, so we wait for the STATE_START, then STATE_STOP + // before creating an editor + PRBool mCanCreateEditor; + + // THE REMAINING MEMBER VARIABLES WILL BECOME A SET WHEN WE EDIT + // MORE THAN ONE EDITOR PER EDITING SESSION + nsCOMPtr mStateMaintainer; // we hold the owning ref to this + + // Save the editor type so we can create the editor after loading uri + nsCString mEditorType; PRUint32 mEditorFlags; + PRUint32 mEditorStatus; + PRUint32 mBaseCommandControllerId; + PRUint32 mDocStateControllerId; + PRUint32 mHTMLCommandControllerId; }; diff --git a/mozilla/editor/libeditor/base/nsEditorController.cpp b/mozilla/editor/libeditor/base/nsEditorController.cpp index b61a3641702..45a83cfc9d9 100644 --- a/mozilla/editor/libeditor/base/nsEditorController.cpp +++ b/mozilla/editor/libeditor/base/nsEditorController.cpp @@ -42,62 +42,10 @@ #include "nsIComponentManager.h" #include "nsEditorController.h" #include "nsIEditor.h" - #include "nsEditorCommands.h" +#include "nsIControllerCommandManager.h" -NS_IMPL_ADDREF(nsEditorController) -NS_IMPL_RELEASE(nsEditorController) - -NS_INTERFACE_MAP_BEGIN(nsEditorController) - NS_INTERFACE_MAP_ENTRY(nsIController) - NS_INTERFACE_MAP_ENTRY(nsICommandController) - NS_INTERFACE_MAP_ENTRY(nsIEditorController) - NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditorController) -NS_INTERFACE_MAP_END - -nsEditorController::nsEditorController() -: mCommandRefCon(nsnull) -{ - NS_INIT_ISUPPORTS(); -} - -nsEditorController::~nsEditorController() -{ -} - -NS_IMETHODIMP nsEditorController::Init(nsISupports *aCommandRefCon) -{ - nsresult rv; - - // get our ref to the singleton command manager - rv = GetEditorCommandManager(getter_AddRefs(mCommandManager)); - if (NS_FAILED(rv)) return rv; - - mCommandRefCon = aCommandRefCon; // no addref - return NS_OK; -} - -NS_IMETHODIMP nsEditorController::SetCommandRefCon(nsISupports *aCommandRefCon) -{ - mCommandRefCon = aCommandRefCon; // no addref - return NS_OK; -} - -NS_IMETHODIMP nsEditorController::GetInterface(const nsIID & aIID, void * *result) -{ - NS_ENSURE_ARG_POINTER(result); - - if (NS_SUCCEEDED(QueryInterface(aIID, result))) - return NS_OK; - - if (mCommandManager && aIID.Equals(NS_GET_IID(nsIControllerCommandManager))) - return mCommandManager->QueryInterface(aIID, result); - - return NS_NOINTERFACE; -} - #define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName) \ { \ @@ -184,70 +132,12 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectPageUp"); NS_REGISTER_LAST_COMMAND(nsSelectionMoveCommands, "cmd_selectPageDown"); - return NS_OK; -} + // Insert content + NS_REGISTER_ONE_COMMAND(nsInsertPlaintextCommand, "cmd_insertText"); + NS_REGISTER_ONE_COMMAND(nsPasteQuotationCommand, "cmd_pasteQuote"); -/* ======================================================================= - * nsIController - * ======================================================================= */ -NS_IMETHODIMP nsEditorController::IsCommandEnabled(const char *aCommand, PRBool *aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult); -} - -NS_IMETHODIMP nsEditorController::SupportsCommand(const char *aCommand, PRBool *aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult); -} - -NS_IMETHODIMP nsEditorController::DoCommand(const char *aCommand) -{ - return mCommandManager->DoCommand(aCommand, mCommandRefCon); -} - -NS_IMETHODIMP nsEditorController::DoCommandWithParams(const char *aCommand, nsICommandParams *aParams) -{ - return mCommandManager->DoCommandParams(aCommand, aParams, mCommandRefCon); -} - -NS_IMETHODIMP nsEditorController::GetCommandStateWithParams(const char *aCommand, nsICommandParams *aParams) -{ - return mCommandManager->GetCommandState(aCommand, aParams, mCommandRefCon); -} - -NS_IMETHODIMP nsEditorController::OnEvent(const char * aEventName) -{ return NS_OK; } -nsWeakPtr nsEditorController::sEditorCommandManager = NULL; - -// static -nsresult nsEditorController::GetEditorCommandManager(nsIControllerCommandManager* *outCommandManager) -{ - NS_ENSURE_ARG_POINTER(outCommandManager); - - nsCOMPtr cmdManager = do_QueryReferent(sEditorCommandManager); - if (!cmdManager) - { - nsresult rv; - cmdManager = do_CreateInstance(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - // register the commands. This just happens once per instance - rv = nsEditorController::RegisterEditorCommands(cmdManager); - if (NS_FAILED(rv)) return rv; - - // save the singleton in our static weak reference - sEditorCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv)); - if (NS_FAILED(rv)) return rv; - } - - NS_ADDREF(*outCommandManager = cmdManager); - return NS_OK; -} - diff --git a/mozilla/editor/libeditor/base/nsEditorController.h b/mozilla/editor/libeditor/base/nsEditorController.h index 833be005f07..a34161f7775 100644 --- a/mozilla/editor/libeditor/base/nsEditorController.h +++ b/mozilla/editor/libeditor/base/nsEditorController.h @@ -42,69 +42,16 @@ #define NS_EDITORCONTROLLER_CID \ { 0x26fb965c, 0x9de6, 0x11d3, { 0xbc, 0xcc, 0x0, 0x60, 0xb0, 0xfc, 0x76, 0xbd } } - -#include "nsIController.h" -#include "nsIEditorController.h" -#include "nsIControllerCommand.h" -#include "nsIControllerCommandManager.h" -#include "nsIInterfaceRequestor.h" -#include "nsIInterfaceRequestorUtils.h" - -#include "nsHashtable.h" -#include "nsString.h" -#include "nsWeakPtr.h" - -class nsIEditor; +class nsIControllerCommandManager; // the editor controller is used for both text widgets, and basic text editing // commands in composer. The refCon that gets passed to its commands is an nsIEditor. -class nsEditorController : public nsIController, - public nsIEditorController, - public nsIInterfaceRequestor, - public nsICommandController +class nsEditorController { public: - - nsEditorController(); - virtual ~nsEditorController(); - - // nsISupports - NS_DECL_ISUPPORTS - - // nsIController - NS_DECL_NSICONTROLLER - - // nsICommandController - NS_DECL_NSICOMMANDCONTROLLER - - /** init the controller */ - NS_IMETHOD Init(nsISupports *aCommandRefCon); - - /** Set the cookie that is passed to commands - */ - NS_IMETHOD SetCommandRefCon(nsISupports *aCommandRefCon); - - // nsIInterfaceRequestor - NS_DECL_NSIINTERFACEREQUESTOR - -protected: - - //if editor is null then look to mContent. this is for dual use of window and content - //attached controller. - nsISupports *mCommandRefCon; - - nsCOMPtr mCommandManager; // our reference to the command manager - -private: - - static nsresult GetEditorCommandManager(nsIControllerCommandManager* *outCommandManager); static nsresult RegisterEditorCommands(nsIControllerCommandManager* inCommandManager); - - // the singleton command manager - static nsWeakPtr sEditorCommandManager; // common editor (i.e. text widget) commands - }; #endif /* nsEditorController_h__ */ diff --git a/mozilla/editor/libeditor/build/nsEditorRegistration.cpp b/mozilla/editor/libeditor/build/nsEditorRegistration.cpp index c957ef95998..83e76ddab90 100644 --- a/mozilla/editor/libeditor/build/nsEditorRegistration.cpp +++ b/mozilla/editor/libeditor/build/nsEditorRegistration.cpp @@ -20,6 +20,8 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Michael Judge + * Charles Manske * * * Alternatively, the contents of this file may be used under the terms of @@ -47,6 +49,9 @@ #include "nsTextServicesDocument.h" #include "nsTextServicesCID.h" +#include "nsIControllerContext.h" + +#include "nsIServiceManager.h" //////////////////////////////////////////////////////////////////////// // Define the contructor function for the objects @@ -55,9 +60,42 @@ // NS_GENERIC_FACTORY_CONSTRUCTOR(nsPlaintextEditor) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorController) NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextServicesDocument) + +NS_IMETHODIMP nsEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID, + void **aResult) +{ + static PRBool commandsRegistered = PR_FALSE; + nsresult rv; + nsCOMPtr context = + do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1",&rv); + if (NS_FAILED(rv)) + return rv; + if (!context) + return NS_ERROR_FAILURE; + + nsCOMPtr editorCommandManager( + do_GetService(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv)); + if (NS_FAILED(rv)) + return rv; + if (!editorCommandManager) + return NS_ERROR_OUT_OF_MEMORY; + if (!commandsRegistered) + { + rv = nsEditorController::RegisterEditorCommands(editorCommandManager); + if (NS_FAILED(rv)) + { + return rv; + } + commandsRegistered = PR_TRUE; + } + + + context->SetControllerCommandManager(editorCommandManager); + return context->QueryInterface(aIID, aResult); +} + #ifdef ENABLE_EDITOR_API_LOG #include "nsHTMLEditorLog.h" NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLEditorLog) diff --git a/mozilla/embedding/components/build/macbuild/EmbedComponents.xml b/mozilla/embedding/components/build/macbuild/EmbedComponents.xml index a958bfa266c..6815cf547bb 100644 --- a/mozilla/embedding/components/build/macbuild/EmbedComponents.xml +++ b/mozilla/embedding/components/build/macbuild/EmbedComponents.xml @@ -1115,6 +1115,13 @@ Text Debug + + Name + nsBaseCommandController.cpp + MacOS + Text + Debug + Name nsPrintDialogExtension.r @@ -1244,6 +1251,11 @@ nsControllerCommandManager.cpp MacOS + + Name + nsBaseCommandController.cpp + MacOS + Name nsPrintDialogExtension.r @@ -2313,6 +2325,13 @@ Text Debug + + Name + nsBaseCommandController.cpp + MacOS + Text + Debug + Name nsPrintDialogExtension.r @@ -2442,6 +2461,11 @@ nsControllerCommandManager.cpp MacOS + + Name + nsBaseCommandController.cpp + MacOS + Name nsPrintDialogExtension.r @@ -2498,6 +2522,12 @@ nsControllerCommandManager.cpp MacOS + + EmbedComponentsDebug.shlb + Name + nsBaseCommandController.cpp + MacOS + WindowWatcher diff --git a/mozilla/embedding/components/build/macbuild/EmbedComponentsIDL.xml b/mozilla/embedding/components/build/macbuild/EmbedComponentsIDL.xml index 817b8978148..1ffb6cd55ec 100644 --- a/mozilla/embedding/components/build/macbuild/EmbedComponentsIDL.xml +++ b/mozilla/embedding/components/build/macbuild/EmbedComponentsIDL.xml @@ -828,6 +828,13 @@ Text + + Name + nsIControllerContext.idl + MacOS + Text + + Name nsIControllerCommand.idl @@ -928,6 +935,11 @@ nsPICommandUpdater.idl MacOS + + Name + nsIControllerContext.idl + MacOS + Name nsIControllerCommand.idl @@ -1725,6 +1737,13 @@ Text + + Name + nsIControllerContext.idl + MacOS + Text + + Name nsIControllerCommand.idl @@ -1825,6 +1844,11 @@ nsPICommandUpdater.idl MacOS + + Name + nsIControllerContext.idl + MacOS + Name nsIControllerCommand.idl @@ -1945,6 +1969,12 @@ nsPICommandUpdater.idl MacOS + + headers + Name + nsIControllerContext.idl + MacOS + headers Name diff --git a/mozilla/embedding/components/build/nsModule.cpp b/mozilla/embedding/components/build/nsModule.cpp index 26498c62ea0..3fbeebed29d 100644 --- a/mozilla/embedding/components/build/nsModule.cpp +++ b/mozilla/embedding/components/build/nsModule.cpp @@ -50,6 +50,7 @@ #include "nsCommandParams.h" #include "nsCommandGroup.h" #include "nsPrintingPromptService.h" +#include "nsBaseCommandController.h" NS_GENERIC_FACTORY_CONSTRUCTOR(nsDialogParamBlock) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPromptService, Init) @@ -64,6 +65,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsCommandManager) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCommandParams, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsControllerCommandGroup) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintingPromptService, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsBaseCommandController) static const nsModuleComponentInfo gComponents[] = { @@ -76,9 +78,11 @@ static const nsModuleComponentInfo gComponents[] = { { NS_APPSTARTUPNOTIFIER_CLASSNAME, NS_APPSTARTUPNOTIFIER_CID, NS_APPSTARTUPNOTIFIER_CONTRACTID, nsAppStartupNotifierConstructor }, { "WebBrowserPersist Component", NS_WEBBROWSERPERSIST_CID, NS_WEBBROWSERPERSIST_CONTRACTID, nsWebBrowserPersistConstructor }, { "Controller Command Manager", NS_CONTROLLERCOMMANDMANAGER_CID, NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, nsControllerCommandManagerConstructor }, + { "Composers Controller Command Manager", NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CID, NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CONTRACTID, nsControllerCommandManagerConstructor }, { "Command Manager", NS_COMMAND_MANAGER_CID, NS_COMMAND_MANAGER_CONTRACTID, nsCommandManagerConstructor }, { "Command Params", NS_COMMAND_PARAMS_CID, NS_COMMAND_PARAMS_CONTRACTID, nsCommandParamsConstructor }, { "Command Group", NS_CONTROLLER_COMMAND_GROUP_CID, NS_CONTROLLER_COMMAND_GROUP_CONTRACTID, nsControllerCommandGroupConstructor }, + { "Base Command Controller", NS_BASECOMMANDCONTROLLER_CID, NS_BASECOMMANDCONTROLLER_CONTRACTID, nsBaseCommandControllerConstructor }, { "Printing Prompt Service", NS_PRINTINGPROMPTSERVICE_CID, NS_PRINTINGPROMPTSERVICE_CONTRACTID, nsPrintingPromptServiceConstructor } }; diff --git a/mozilla/embedding/components/commandhandler/public/MANIFEST_IDL b/mozilla/embedding/components/commandhandler/public/MANIFEST_IDL index 8cf29d04e42..48a189419a2 100644 --- a/mozilla/embedding/components/commandhandler/public/MANIFEST_IDL +++ b/mozilla/embedding/components/commandhandler/public/MANIFEST_IDL @@ -2,4 +2,5 @@ nsICommandManager.idl nsPICommandUpdater.idl nsICommandParams.idl nsIControllerCommand.idl -nsIControllerCommandManager.idl \ No newline at end of file +nsIControllerContext.idl +nsIControllerCommandManager.idl diff --git a/mozilla/embedding/components/commandhandler/public/Makefile.in b/mozilla/embedding/components/commandhandler/public/Makefile.in index 5fc8a7f0b08..370f1ef5f96 100644 --- a/mozilla/embedding/components/commandhandler/public/Makefile.in +++ b/mozilla/embedding/components/commandhandler/public/Makefile.in @@ -33,6 +33,7 @@ XPIDLSRCS = \ nsICommandManager.idl \ nsICommandParams.idl \ nsIControllerCommand.idl \ + nsIControllerContext.idl \ nsIControllerCommandManager.idl \ nsPICommandUpdater.idl \ $(NULL) diff --git a/mozilla/embedding/components/commandhandler/public/nsICommandManager.idl b/mozilla/embedding/components/commandhandler/public/nsICommandManager.idl index 01cfaaf4007..508c7e550c5 100644 --- a/mozilla/embedding/components/commandhandler/public/nsICommandManager.idl +++ b/mozilla/embedding/components/commandhandler/public/nsICommandManager.idl @@ -135,8 +135,8 @@ interface nsICommandManager : nsISupports Arguments to observers "Observe" method are as follows: void Observe( in nsISupports aSubject, // The nsICommandManager calling this Observer - in string aTopic, // Unused - in wstring aDummy ); // Name of the command + in string aTopic, // Name of the command + in wstring aDummy ); // unused */ diff --git a/mozilla/embedding/components/commandhandler/public/nsIControllerCommandManager.idl b/mozilla/embedding/components/commandhandler/public/nsIControllerCommandManager.idl index ce2a6e553a8..35f03c3dbe5 100644 --- a/mozilla/embedding/components/commandhandler/public/nsIControllerCommandManager.idl +++ b/mozilla/embedding/components/commandhandler/public/nsIControllerCommandManager.idl @@ -102,4 +102,8 @@ interface nsIControllerCommandManager : nsISupports #define NS_CONTROLLERCOMMANDMANAGER_CONTRACTID \ "@mozilla.org/embedcomp/controller-command-manager;1" +#define NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CONTRACTID \ +"@mozilla.org/embedcomp/composers-controller-command-manager;1" +#define NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CID \ +{ 0xb0e54f80, 0xc274, 0x4765, { 0x9e, 0x36, 0xd0, 0x0a, 0xcd, 0x38, 0x92, 0x9c } } %} diff --git a/mozilla/embedding/components/commandhandler/public/nsIControllerContext.idl b/mozilla/embedding/components/commandhandler/public/nsIControllerContext.idl new file mode 100644 index 00000000000..b94cc39474c --- /dev/null +++ b/mozilla/embedding/components/commandhandler/public/nsIControllerContext.idl @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Michael Judge + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" +#include "nsIControllerCommandManager.idl" + +[scriptable, uuid(47B82B60-A36F-4167-8072-6F421151ED50)] +interface nsIControllerContext : nsISupports +{ + + + /** + * Set the cookie that is passed to commands + * Note that the commandRefCon is *not* addreffed + * and thus it needs to outlive the controller + */ + void setCommandRefCon(in nsISupports commandRefCon); + + /** + * Set the command manager. This will have the effect of making the manager immutable + */ + void setControllerCommandManager(in nsIControllerCommandManager commandManager); +}; diff --git a/mozilla/embedding/components/commandhandler/src/Makefile.in b/mozilla/embedding/components/commandhandler/src/Makefile.in index ab91edc3665..b79591bfced 100644 --- a/mozilla/embedding/components/commandhandler/src/Makefile.in +++ b/mozilla/embedding/components/commandhandler/src/Makefile.in @@ -40,6 +40,7 @@ REQUIRES = string \ LIBRARY_NAME = commandhandler_s CPPSRCS = \ + nsBaseCommandController.cpp \ nsCommandGroup.cpp \ nsCommandManager.cpp \ nsCommandParams.cpp \ diff --git a/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.cpp b/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.cpp new file mode 100644 index 00000000000..752d88d6e01 --- /dev/null +++ b/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.cpp @@ -0,0 +1,160 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsString.h" +#include "nsIComponentManager.h" +#include "nsBaseCommandController.h" + +#include "nsHashtable.h" +#include "nsString.h" +#include "nsWeakPtr.h" + +NS_IMPL_ADDREF(nsBaseCommandController) +NS_IMPL_RELEASE(nsBaseCommandController) + +NS_INTERFACE_MAP_BEGIN(nsBaseCommandController) + NS_INTERFACE_MAP_ENTRY(nsIController) + NS_INTERFACE_MAP_ENTRY(nsICommandController) + NS_INTERFACE_MAP_ENTRY(nsIControllerContext) + NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIControllerContext) +NS_INTERFACE_MAP_END + +nsBaseCommandController::nsBaseCommandController() +: mCommandRefCon(nsnull), mImmutableManager(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); + nsresult rv; + mCommandManager = + do_CreateInstance(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv); + + NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create CommandManager in nsBaseCommandController"); +} + +nsBaseCommandController::~nsBaseCommandController() +{ +} + +NS_IMETHODIMP +nsBaseCommandController::SetCommandRefCon(nsISupports *aCommandRefCon) +{ + mCommandRefCon = aCommandRefCon; // no addref + return NS_OK; +} + +NS_IMETHODIMP +nsBaseCommandController::SetControllerCommandManager( + nsIControllerCommandManager *aCommandManager) +{ + if (!aCommandManager) + return NS_ERROR_NULL_POINTER; + mCommandManager = aCommandManager; + mImmutableManager = PR_TRUE; + return NS_OK; +} + +NS_IMETHODIMP +nsBaseCommandController::GetInterface(const nsIID & aIID, void * *result) +{ + NS_ENSURE_ARG_POINTER(result); + + if (NS_SUCCEEDED(QueryInterface(aIID, result))) + return NS_OK; + // Don't let users get the command manager if it's + // immutable. They may harm it in some way. + if (!mImmutableManager && mCommandManager && + aIID.Equals(NS_GET_IID(nsIControllerCommandManager))) + return mCommandManager->QueryInterface(aIID, result); + + return NS_NOINTERFACE; +} + + + +/* ======================================================================= + * nsIController + * ======================================================================= */ + +NS_IMETHODIMP +nsBaseCommandController::IsCommandEnabled(const char *aCommand, + PRBool *aResult) +{ + NS_ENSURE_ARG_POINTER(aCommand); + NS_ENSURE_ARG_POINTER(aResult); + return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult); +} + +NS_IMETHODIMP +nsBaseCommandController::SupportsCommand(const char *aCommand, PRBool *aResult) +{ + NS_ENSURE_ARG_POINTER(aCommand); + NS_ENSURE_ARG_POINTER(aResult); + return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult); +} + +NS_IMETHODIMP +nsBaseCommandController::DoCommand(const char *aCommand) +{ + NS_ENSURE_ARG_POINTER(aCommand); + return mCommandManager->DoCommand(aCommand, mCommandRefCon); +} + +NS_IMETHODIMP +nsBaseCommandController::DoCommandWithParams(const char *aCommand, + nsICommandParams *aParams) +{ + NS_ENSURE_ARG_POINTER(aCommand); + return mCommandManager->DoCommandParams(aCommand, aParams, mCommandRefCon); +} + +NS_IMETHODIMP +nsBaseCommandController::GetCommandStateWithParams(const char *aCommand, + nsICommandParams *aParams) +{ + NS_ENSURE_ARG_POINTER(aCommand); + return mCommandManager->GetCommandState(aCommand, aParams, mCommandRefCon); +} + +NS_IMETHODIMP +nsBaseCommandController::OnEvent(const char * aEventName) +{ + NS_ENSURE_ARG_POINTER(aEventName); + return NS_OK; +} + + diff --git a/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.h b/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.h new file mode 100644 index 00000000000..8706b02624c --- /dev/null +++ b/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.h @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Michael Judge + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsBaseCommandController_h__ +#define nsBaseCommandController_h__ + +#define NS_BASECOMMANDCONTROLLER_CID \ +{ 0xbf88b48c, 0xfd8e, 0x40b4, { 0xba, 0x36, 0xc7, 0xc3, 0xad, 0x6d, 0x8a, 0xc9 } } +#define NS_BASECOMMANDCONTROLLER_CONTRACTID \ + "@mozilla.org/embedcomp/base-command-controller;1" + + +#include "nsIController.h" +#include "nsIControllerContext.h" +#include "nsIControllerCommand.h" +#include "nsIControllerCommandManager.h" +#include "nsIInterfaceRequestor.h" +#include "nsIInterfaceRequestorUtils.h" + +//#include "nsHashtable.h" +//#include "nsString.h" +//#include "nsWeakPtr.h" + + +// The base editor controller is used for both text widgets, +// and all other text and html editing +class nsBaseCommandController : public nsIController, + public nsIControllerContext, + public nsIInterfaceRequestor, + public nsICommandController +{ +public: + + nsBaseCommandController(); + virtual ~nsBaseCommandController(); + + // nsISupports + NS_DECL_ISUPPORTS + + // nsIController + NS_DECL_NSICONTROLLER + + // nsICommandController + NS_DECL_NSICOMMANDCONTROLLER + + //nsIControllerContext + NS_DECL_NSICONTROLLERCONTEXT + + // nsIInterfaceRequestor + NS_DECL_NSIINTERFACEREQUESTOR + +private: + + nsISupports *mCommandRefCon; + + // Our reference to the command manager + nsCOMPtr mCommandManager; + + PRBool mImmutableManager; +}; + +#endif /* nsBaseCommandController_h_ */ + diff --git a/mozilla/embedding/components/commandhandler/src/nsControllerCommandManager.h b/mozilla/embedding/components/commandhandler/src/nsControllerCommandManager.h index d9e6fd133c8..ecc2fec831a 100644 --- a/mozilla/embedding/components/commandhandler/src/nsControllerCommandManager.h +++ b/mozilla/embedding/components/commandhandler/src/nsControllerCommandManager.h @@ -62,8 +62,6 @@ public: protected: nsSupportsHashtable mCommandsTable; // hash table of nsIControllerCommands, keyed by command name - - }; diff --git a/mozilla/layout/forms/nsTextControlFrame.cpp b/mozilla/layout/forms/nsTextControlFrame.cpp index 23a4d05e536..1698a87d80c 100644 --- a/mozilla/layout/forms/nsTextControlFrame.cpp +++ b/mozilla/layout/forms/nsTextControlFrame.cpp @@ -55,7 +55,7 @@ #include "nsISelectionPrivate.h" #include "nsIController.h" #include "nsIControllers.h" -#include "nsIEditorController.h" +#include "nsIControllerContext.h" #include "nsIElementFactory.h" #include "nsIHTMLContent.h" #include "nsIEditorIMESupport.h" @@ -1412,7 +1412,7 @@ nsTextControlFrame::PreDestroy(nsIPresContext* aPresContext) rv = controllers->GetControllerAt(i, getter_AddRefs(controller)); if (NS_SUCCEEDED(rv) && controller) { - nsCOMPtr editController = do_QueryInterface(controller); + nsCOMPtr editController = do_QueryInterface(controller); if (editController) { editController->SetCommandRefCon(nsnull); @@ -1978,7 +1978,7 @@ nsTextControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, rv = controllers->GetControllerAt(i, getter_AddRefs(controller)); if (NS_SUCCEEDED(rv) && controller) { - nsCOMPtr editController = do_QueryInterface(controller); + nsCOMPtr editController = do_QueryInterface(controller); if (editController) { editController->SetCommandRefCon(mEditor); diff --git a/mozilla/layout/html/forms/src/Makefile.in b/mozilla/layout/html/forms/src/Makefile.in index e264758f168..f3e94523244 100644 --- a/mozilla/layout/html/forms/src/Makefile.in +++ b/mozilla/layout/html/forms/src/Makefile.in @@ -50,6 +50,7 @@ REQUIRES = xpcom \ accessibility \ xpconnect \ unicharutil \ + commandhandler \ $(NULL) CPPSRCS = \ diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp index 23a4d05e536..1698a87d80c 100644 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp @@ -55,7 +55,7 @@ #include "nsISelectionPrivate.h" #include "nsIController.h" #include "nsIControllers.h" -#include "nsIEditorController.h" +#include "nsIControllerContext.h" #include "nsIElementFactory.h" #include "nsIHTMLContent.h" #include "nsIEditorIMESupport.h" @@ -1412,7 +1412,7 @@ nsTextControlFrame::PreDestroy(nsIPresContext* aPresContext) rv = controllers->GetControllerAt(i, getter_AddRefs(controller)); if (NS_SUCCEEDED(rv) && controller) { - nsCOMPtr editController = do_QueryInterface(controller); + nsCOMPtr editController = do_QueryInterface(controller); if (editController) { editController->SetCommandRefCon(nsnull); @@ -1978,7 +1978,7 @@ nsTextControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, rv = controllers->GetControllerAt(i, getter_AddRefs(controller)); if (NS_SUCCEEDED(rv) && controller) { - nsCOMPtr editController = do_QueryInterface(controller); + nsCOMPtr editController = do_QueryInterface(controller); if (editController) { editController->SetCommandRefCon(mEditor); diff --git a/mozilla/layout/html/tests/table/images/adforce_imgis_com.html b/mozilla/layout/html/tests/table/images/adforce_imgis_com.html index ca70aebe2ad..3076258ef75 100644 Binary files a/mozilla/layout/html/tests/table/images/adforce_imgis_com.html and b/mozilla/layout/html/tests/table/images/adforce_imgis_com.html differ