From e1c3f451abfa436e52a64c6bbcd93678336c8775 Mon Sep 17 00:00:00 2001 From: "sfraser%netscape.com" Date: Mon, 1 May 2000 21:49:52 +0000 Subject: [PATCH] Fixes for bugs 34503 and 34504 -- split the editor controller into editor and composer controllers, and make commands for lots of editor functions. git-svn-id: svn://10.0.0.236/trunk@67740 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/content/src/nsHTMLInputElement.cpp | 12 +- .../content/src/nsHTMLTextAreaElement.cpp | 13 +- mozilla/editor/base/nsEditorCommands.cpp | 9 +- mozilla/editor/base/nsEditorCommands.h | 34 +- mozilla/editor/base/nsEditorController.cpp | 315 ++++++------ mozilla/editor/base/nsEditorController.h | 77 ++- mozilla/editor/base/nsEditorRegistration.cpp | 5 +- mozilla/editor/base/nsEditorShell.cpp | 198 +++++--- mozilla/editor/base/nsEditorShell.h | 12 +- mozilla/editor/base/nsHTMLEditor.cpp | 2 +- mozilla/editor/base/nsInterfaceState.cpp | 91 +++- mozilla/editor/base/nsInterfaceState.h | 9 +- mozilla/editor/composer/src/nsEditorShell.cpp | 198 +++++--- mozilla/editor/composer/src/nsEditorShell.h | 12 +- .../editor/composer/src/nsInterfaceState.cpp | 91 +++- .../editor/composer/src/nsInterfaceState.h | 9 +- mozilla/editor/idl/nsIEditorShell.idl | 17 +- .../libeditor/base/nsEditorCommands.cpp | 9 +- .../editor/libeditor/base/nsEditorCommands.h | 34 +- .../libeditor/base/nsEditorController.cpp | 315 ++++++------ .../libeditor/base/nsEditorController.h | 77 ++- .../libeditor/build/nsEditorRegistration.cpp | 5 +- .../editor/libeditor/html/nsHTMLEditor.cpp | 2 +- mozilla/editor/public/nsIEditorController.h | 16 +- .../ui/composer/content/EditorCommands.js | 480 +++++++----------- .../composer/content/EditorCommandsDebug.js | 2 +- mozilla/editor/ui/composer/content/editor.xul | 15 +- .../ui/composer/content/editorOverlay.xul | 427 +++++++++------- .../html/content/src/nsHTMLInputElement.cpp | 12 +- .../content/src/nsHTMLTextAreaElement.cpp | 13 +- .../html/forms/src/nsGfxTextControlFrame.cpp | 17 +- 31 files changed, 1416 insertions(+), 1112 deletions(-) diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index 54b3c2b961f..3996c577cb2 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -1132,18 +1132,12 @@ nsHTMLInputElement::GetControllers(nsIControllers** aResult) NS_ERROR_FAILURE); if (!mControllers) { return NS_ERROR_NULL_POINTER; } - nsCOMPtr controller; - NS_ENSURE_SUCCESS ( - nsComponentManager::CreateInstance("component://netscape/editor/editorcontroller", - nsnull, - NS_GET_IID(nsIController), - getter_AddRefs(controller)), - NS_ERROR_FAILURE); - if (!controller) { return NS_ERROR_NULL_POINTER; } nsresult rv; + nsCOMPtr controller = do_CreateInstance("component://netscape/editor/editorcontroller", &rv); + if (NS_FAILED(rv)) return rv; nsCOMPtr editorController = do_QueryInterface(controller, &rv); if (NS_FAILED(rv)) return rv; - rv = editorController->Init(); + 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 9f87e0983c6..0dd86122736 100644 --- a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -605,19 +605,12 @@ nsHTMLTextAreaElement::GetControllers(nsIControllers** aResult) NS_ERROR_FAILURE); if (!mControllers) { return NS_ERROR_NULL_POINTER; } - nsCOMPtr controller; - NS_ENSURE_SUCCESS ( - nsComponentManager::CreateInstance("component://netscape/editor/editorcontroller", - nsnull, - NS_GET_IID(nsIController), - getter_AddRefs(controller)), - NS_ERROR_FAILURE); - - if (!controller) { return NS_ERROR_NULL_POINTER; } nsresult rv; + nsCOMPtr controller = do_CreateInstance("component://netscape/editor/editorcontroller", &rv); + if (NS_FAILED(rv)) return rv; nsCOMPtr editorController = do_QueryInterface(controller, &rv); if (NS_FAILED(rv)) return rv; - rv = editorController->Init(); + rv = editorController->Init(nsnull); if (NS_FAILED(rv)) return rv; mControllers->AppendController(controller); diff --git a/mozilla/editor/base/nsEditorCommands.cpp b/mozilla/editor/base/nsEditorCommands.cpp index 2a623f6dff2..c4db3ecb12a 100644 --- a/mozilla/editor/base/nsEditorCommands.cpp +++ b/mozilla/editor/base/nsEditorCommands.cpp @@ -38,13 +38,12 @@ nsBaseCommand::nsBaseCommand() NS_INIT_REFCNT(); } - -nsBaseCommand::~nsBaseCommand() -{ -} - NS_IMPL_ISUPPORTS(nsBaseCommand, NS_GET_IID(nsIControllerCommand)); +#ifdef XP_MAC +#pragma mark - +#endif + NS_IMETHODIMP nsUndoCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled) diff --git a/mozilla/editor/base/nsEditorCommands.h b/mozilla/editor/base/nsEditorCommands.h index 497b1da716f..95cd5c15059 100644 --- a/mozilla/editor/base/nsEditorCommands.h +++ b/mozilla/editor/base/nsEditorCommands.h @@ -34,7 +34,7 @@ class nsBaseCommand : public nsIControllerCommand public: nsBaseCommand(); - virtual ~nsBaseCommand(); + virtual ~nsBaseCommand() {} NS_DECL_ISUPPORTS @@ -44,13 +44,16 @@ public: }; -#define NS_DECL_EDITOR_COMMAND(_cmd) \ -class _cmd : public nsBaseCommand \ -{ \ -public: \ - NS_DECL_NSICONTROLLERCOMMAND \ +#define NS_DECL_EDITOR_COMMAND(_cmd) \ +class _cmd : public nsBaseCommand \ +{ \ +public: \ + NS_DECL_NSICONTROLLERCOMMAND \ }; + + +// basic editor commands NS_DECL_EDITOR_COMMAND(nsUndoCommand) NS_DECL_EDITOR_COMMAND(nsRedoCommand) @@ -63,4 +66,23 @@ NS_DECL_EDITOR_COMMAND(nsSelectAllCommand) NS_DECL_EDITOR_COMMAND(nsSelectionMoveCommands) + +#if 0 +// template for new command +NS_IMETHODIMP +nsFooCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsFooCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +#endif + #endif // nsIEditorCommand_h_ diff --git a/mozilla/editor/base/nsEditorController.cpp b/mozilla/editor/base/nsEditorController.cpp index 5b9e2ce5bac..9f5ab309c8f 100644 --- a/mozilla/editor/base/nsEditorController.cpp +++ b/mozilla/editor/base/nsEditorController.cpp @@ -24,6 +24,7 @@ #include "nsIComponentManager.h" #include "nsEditorController.h" #include "nsIEditor.h" +#include "nsIEditorShell.h" #include "nsIEditorMailSupport.h" #include "nsIFormControlFrame.h" #include "nsIDOMSelection.h" @@ -36,7 +37,7 @@ #include "nsIPresShell.h" #include "nsEditorCommands.h" - +#include "nsComposerCommands.h" #define kMaxStackCommandNameLength 128 @@ -47,31 +48,49 @@ NS_IMPL_RELEASE(nsEditorController) NS_INTERFACE_MAP_BEGIN(nsEditorController) NS_INTERFACE_MAP_ENTRY(nsIController) NS_INTERFACE_MAP_ENTRY(nsIEditorController) + NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditorController) NS_INTERFACE_MAP_END nsEditorController::nsEditorController() -: mContent(NULL) -, mEditor(NULL) +: mCommandRefCon(nsnull) { NS_INIT_REFCNT(); } nsEditorController::~nsEditorController() { - // if the singleton command manger has a refcount of 1 at this point, we need to - // set it to null } -NS_IMETHODIMP nsEditorController::Init() +NS_IMETHODIMP nsEditorController::Init(nsISupports *aCommandRefCon) { nsresult rv; // get our ref to the singleton command manager - rv = GetCommandManager(getter_AddRefs(mCommandManager)); + 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; - return rv; + if (mCommandManager && aIID.Equals(NS_GET_IID(nsIControllerCommandManager))) + return mCommandManager->QueryInterface(aIID, result); + + return NS_NOINTERFACE; } @@ -100,6 +119,8 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager nsresult rv; // now register all our commands + // These are commands that will be used in text widgets, and in composer + NS_REGISTER_ONE_COMMAND(nsUndoCommand, "cmd_undo"); NS_REGISTER_ONE_COMMAND(nsRedoCommand, "cmd_redo"); @@ -107,8 +128,7 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager NS_REGISTER_ONE_COMMAND(nsCopyCommand, "cmd_copy"); NS_REGISTER_ONE_COMMAND(nsSelectAllCommand, "cmd_selectAll"); - NS_REGISTER_FIRST_COMMAND(nsPasteCommand, "cmd_paste"); - NS_REGISTER_LAST_COMMAND(nsPasteCommand, "cmd_pasteQuote"); + NS_REGISTER_ONE_COMMAND(nsPasteCommand, "cmd_paste"); NS_REGISTER_FIRST_COMMAND(nsDeleteCommand, "cmd_delete"); NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteCharBackward"); @@ -166,106 +186,23 @@ nsresult nsEditorController::RegisterOneCommand(const PRUnichar* aCommandName, return inCommandManager->RegisterCommand(aCommandName, editorCommand); // this is the owning ref } - -NS_IMETHODIMP nsEditorController::SetContent(nsIHTMLContent *aContent) -{ - // indiscriminately sets mContent, no ref counting here - mContent = aContent; - return NS_OK; -} - -NS_IMETHODIMP nsEditorController::SetEditor(nsIEditor *aEditor) -{ - // null editors are allowed - mEditor = aEditor; - return NS_OK; -} - - /* ======================================================================= * nsIController * ======================================================================= */ NS_IMETHODIMP nsEditorController::IsCommandEnabled(const PRUnichar *aCommand, PRBool *aResult) { - NS_ENSURE_ARG_POINTER(aCommand); - NS_ENSURE_ARG_POINTER(aResult); - - *aResult = PR_FALSE; - - nsCOMPtr editor; - NS_ENSURE_SUCCESS(GetEditor(getter_AddRefs(editor)), NS_ERROR_FAILURE); - // a null editor is a legal state - if (!editor) - return NS_OK; // just say we don't handle the command - - if (!mCommandManager) - { - NS_ASSERTION(0, "No command handler!"); - return NS_ERROR_UNEXPECTED; - } - - // find the command - nsCOMPtr commandHandler; - mCommandManager->FindCommandHandler(aCommand, getter_AddRefs(commandHandler)); - - if (!commandHandler) - { -#if DEBUG - nsCAutoString msg("EditorController asked about a command that it does not handle -- "); - msg.AppendWithConversion(aCommand); - NS_WARNING(msg); -#endif - return NS_OK; // we don't handle this command - } - - return commandHandler->IsCommandEnabled(aCommand, editor, aResult); + return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult); } NS_IMETHODIMP nsEditorController::SupportsCommand(const PRUnichar *aCommand, PRBool *aResult) { - NS_ENSURE_ARG_POINTER(aCommand); - NS_ENSURE_ARG_POINTER(aResult); - - // XXX: need to check the readonly and disabled states - - *aResult = PR_FALSE; - - // find the command - nsCOMPtr commandHandler; - mCommandManager->FindCommandHandler(aCommand, getter_AddRefs(commandHandler)); - - *aResult = (commandHandler.get() != NULL); - return NS_OK; + return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult); } NS_IMETHODIMP nsEditorController::DoCommand(const PRUnichar *aCommand) { - NS_ENSURE_ARG_POINTER(aCommand); - nsCOMPtr editor; - nsCOMPtr selCont; - NS_ENSURE_SUCCESS(GetEditor(getter_AddRefs(editor)), NS_ERROR_FAILURE); - if (!editor) - { // Q: What does it mean if there is no editor? - // A: It means we've never had focus, so we can't do anything - return NS_OK; - } - - // find the command - nsCOMPtr commandHandler; - mCommandManager->FindCommandHandler(aCommand, getter_AddRefs(commandHandler)); - - if (!commandHandler) - { -#if DEBUG - nsCAutoString msg("EditorController asked to do a command that it does not handle -- "); - msg.AppendWithConversion(aCommand); - NS_WARNING(msg); -#endif - return NS_OK; // we don't handle this command - } - - return commandHandler->DoCommand(aCommand, editor); + return mCommandManager->DoCommand(aCommand, mCommandRefCon); } NS_IMETHODIMP nsEditorController::OnEvent(const PRUnichar *aEventName) @@ -275,52 +212,6 @@ NS_IMETHODIMP nsEditorController::OnEvent(const PRUnichar *aEventName) return NS_OK; } - -NS_IMETHODIMP nsEditorController::GetEditor(nsIEditor ** aEditor) -{ - NS_ENSURE_ARG_POINTER(aEditor); - if (mEditor) - { - *aEditor = mEditor; - NS_ADDREF(*aEditor); - return NS_OK; - } - return NS_OK; -} - -NS_IMETHODIMP nsEditorController::GetSelectionController(nsISelectionController ** aSelCon) -{ - nsCOMPtreditor; - nsresult result = GetEditor(getter_AddRefs(editor)); - if (NS_FAILED(result) || !editor) - return result ? result : NS_ERROR_FAILURE; - - return editor->GetSelectionController(aSelCon); -} - -NS_IMETHODIMP nsEditorController::GetFrame(nsIGfxTextControlFrame **aFrame) -{ - NS_ENSURE_ARG_POINTER(aFrame); - //DEPRICATED. WILL REMOVE LATER -/* - *aFrame = nsnull; - NS_ENSURE_STATE(mContent); - - nsIFormControlFrame *frame = nsnull; - NS_ENSURE_SUCCESS( - nsGenericHTMLElement::GetPrimaryFrame(mContent, frame), - NS_ERROR_FAILURE - ); - if (!frame) { return NS_ERROR_FAILURE; } - - NS_ENSURE_SUCCESS( - frame->QueryInterface(NS_GET_IID(nsIGfxTextControlFrame), (void**)aFrame), - NS_ERROR_FAILURE - ); - */ - return NS_OK; -} - PRBool nsEditorController::IsEnabled() { return PR_TRUE; // XXX: need to implement this @@ -331,18 +222,15 @@ PRBool nsEditorController::IsEnabled() */ } -#ifdef XP_MAC -#pragma mark - -#endif -nsWeakPtr nsEditorController::sCommandManager = NULL; +nsWeakPtr nsEditorController::sEditorCommandManager = NULL; // static -nsresult nsEditorController::GetCommandManager(nsIControllerCommandManager* *outCommandManager) +nsresult nsEditorController::GetEditorCommandManager(nsIControllerCommandManager* *outCommandManager) { NS_ENSURE_ARG_POINTER(outCommandManager); - nsCOMPtr cmdManager = do_QueryReferent(sCommandManager); + nsCOMPtr cmdManager = do_QueryReferent(sEditorCommandManager); if (!cmdManager) { nsresult rv; @@ -354,7 +242,7 @@ nsresult nsEditorController::GetCommandManager(nsIControllerCommandManager* *out if (NS_FAILED(rv)) return rv; // save the singleton in our static weak reference - sCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv)); + sEditorCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv)); if (NS_FAILED(rv)) return rv; } @@ -363,3 +251,132 @@ nsresult nsEditorController::GetCommandManager(nsIControllerCommandManager* *out } + +#ifdef XP_MAC +#pragma mark - +#endif + +nsComposerController::nsComposerController() +{ +} + +nsComposerController::~nsComposerController() +{ +} + +NS_IMETHODIMP nsComposerController::Init(nsISupports *aCommandRefCon) +{ + nsresult rv; + + rv = nsEditorController::Init(aCommandRefCon); + if (NS_FAILED(rv)) return rv; + + // get our ref to the singleton command manager + rv = GetComposerCommandManager(getter_AddRefs(mCommandManager)); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + +#define NS_REGISTER_STYLE_COMMAND(_cmdClass, _cmdName, _styleTag) \ + { \ + _cmdClass* theCmd = new _cmdClass(_styleTag); \ + rv = RegisterOneCommand(NS_ConvertASCIItoUCS2(_cmdName).GetUnicode(), inCommandManager, theCmd); \ + } + + +// static +nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandManager *inCommandManager) +{ + nsresult rv; + + // These are composer-only commands + + // File menu + NS_REGISTER_ONE_COMMAND(nsSaveCommand, "cmd_save"); + NS_REGISTER_ONE_COMMAND(nsSaveAsCommand, "cmd_saveAs"); + NS_REGISTER_ONE_COMMAND(nsCloseCommand, "cmd_close"); + + NS_REGISTER_FIRST_COMMAND(nsPrintingCommands, "cmd_print"); + NS_REGISTER_NEXT_COMMAND(nsPrintingCommands, "cmd_printSetup"); + NS_REGISTER_LAST_COMMAND(nsPrintingCommands, "cmd_printPreview"); + + // Edit menu + NS_REGISTER_ONE_COMMAND(nsPasteQuotationCommand, "cmd_pasteQuote"); + + // indent/outdent + NS_REGISTER_ONE_COMMAND(nsIndentCommand, "cmd_indent"); + NS_REGISTER_ONE_COMMAND(nsOutdentCommand, "cmd_outdent"); + + // Styles + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_bold", "b"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_italic", "i"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_underline", "u"); + + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strikethrough", "strike"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_superscript", "sup"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_subscript", "sub"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_nobreak", "nobr"); + + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_em", "em"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strong", "strong"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_cite", "cite"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_abbr", "abbr"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_acronym", "acronym"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_code", "code"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_samp", "samp"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_var", "var"); + + // lists + NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol"); + NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul"); + + // format stuff + NS_REGISTER_ONE_COMMAND(nsParagraphStateCommand, "cmd_paragraphState"); + NS_REGISTER_ONE_COMMAND(nsAlignCommand, "cmd_align"); + NS_REGISTER_ONE_COMMAND(nsRemoveStylesCommand, "cmd_removeStyles"); + NS_REGISTER_ONE_COMMAND(nsIncreaseFontSizeCommand, "cmd_increaseFont"); + NS_REGISTER_ONE_COMMAND(nsDecreaseFontSizeCommand, "cmd_decreaseFont"); + + return NS_OK; +} + + +nsWeakPtr nsComposerController::sComposerCommandManager = NULL; + +nsresult nsComposerController::GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager) +{ + NS_ENSURE_ARG_POINTER(outCommandManager); + +/* + nsCOMPtr cmdManager = do_QueryReferent(sComposerCommandManager); + if (!cmdManager) + { + nsresult rv; + cmdManager = do_CreateInstance("component://netscape/rdf/controller-command-manager", &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; + } +*/ + // always make a new one + nsresult rv; + nsCOMPtr cmdManager; + cmdManager = do_CreateInstance("component://netscape/rdf/controller-command-manager", &rv); + if (NS_FAILED(rv)) return rv; + + // register the commands. + rv = nsComposerController::RegisterComposerCommands(cmdManager); + if (NS_FAILED(rv)) return rv; + + NS_ADDREF(*outCommandManager = cmdManager); + return NS_OK; +} + + diff --git a/mozilla/editor/base/nsEditorController.h b/mozilla/editor/base/nsEditorController.h index d2b6eff42c0..09412862636 100644 --- a/mozilla/editor/base/nsEditorController.h +++ b/mozilla/editor/base/nsEditorController.h @@ -23,23 +23,30 @@ #define NS_EDITORCONTROLLER_CID \ { 0x26fb965c, 0x9de6, 0x11d3, { 0xbc, 0xcc, 0x0, 0x60, 0xb0, 0xfc, 0x76, 0xbd } } +#define NS_COMPOSERCONTROLLER_CID \ +{ 0x50e95301, 0x17a8, 0x11d4, { 0x9f, 0x7e, 0xdd, 0x53, 0x0d, 0x5f, 0x05, 0x7c } } + + #include "nsIController.h" #include "nsIEditorController.h" #include "nsIControllerCommand.h" +#include "nsIInterfaceRequestor.h" #include "nsHashtable.h" #include "nsString.h" #include "nsWeakPtr.h" -class nsIHTMLContent; -class nsIGfxTextControlFrame; class nsIEditor; -class nsISelectionController; +class nsIEditorShell; class nsBaseCommand; +// 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 nsIEditorController, + public nsIInterfaceRequestor { public: @@ -53,48 +60,68 @@ public: NS_DECL_NSICONTROLLER /** init the controller */ - NS_IMETHOD Init(); - - /** set the content for this controller instance */ - NS_IMETHOD SetContent(nsIHTMLContent *aContent); - - /** set the editor for this controller. Mutually exclusive with setContent*/ - NS_IMETHOD SetEditor(nsIEditor *aEditor); + NS_IMETHOD Init(nsISupports *aCommandRefCon); + /** Set the cookie that is passed to commands + */ + NS_IMETHOD SetCommandRefCon(nsISupports *aCommandRefCon); + // nsIInterfaceRequestor + NS_DECL_NSIINTERFACEREQUESTOR + protected: - /** fetch the primary frame associated with mContent */ - NS_IMETHOD GetFrame(nsIGfxTextControlFrame **aFrame); - - /** fetch the editor associated with mContent */ - NS_IMETHOD GetEditor(nsIEditor ** aEditor); - - NS_IMETHOD GetSelectionController(nsISelectionController ** aSelCon); /** return PR_TRUE if the editor associated with mContent is enabled */ - PRBool IsEnabled(); + PRBool IsEnabled(); /* register a command */ nsresult RegisterEditorCommand(nsBaseCommand* aCommand); protected: - nsIHTMLContent* mContent; // weak reference, the content object owns this object - //if editor is null then look to mContent. this is for dual use of window and content //attached controller. - nsIEditor *mEditor; + nsISupports *mCommandRefCon; nsCOMPtr mCommandManager; // our reference to the command manager +protected: + + static nsresult RegisterOneCommand(const PRUnichar* aCommandName, nsIControllerCommandManager *inCommandManager, nsBaseCommand* aCommand); + private: - static nsresult GetCommandManager(nsIControllerCommandManager* *outCommandManager); + static nsresult GetEditorCommandManager(nsIControllerCommandManager* *outCommandManager); static nsresult RegisterEditorCommands(nsIControllerCommandManager* inCommandManager); - static nsresult RegisterOneCommand(const PRUnichar* aCommandName, nsIControllerCommandManager *inCommandManager, nsBaseCommand* aCommand); // the singleton command manager - static nsWeakPtr sCommandManager; + static nsWeakPtr sEditorCommandManager; // common editor (i.e. text widget) commands }; + + + +// the editor controller is used for composer only (and other HTML compose +// areas). The refCon that gets passed to its commands is an nsIEditorShell. + +class nsComposerController : public nsEditorController +{ +public: + + nsComposerController(); + virtual ~nsComposerController(); + + /** init the controller */ + NS_IMETHOD Init(nsISupports *aCommandRefCon); + +protected: + +private: + + static nsresult GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager); + static nsresult RegisterComposerCommands(nsIControllerCommandManager* inCommandManager); + + // the singleton command manager + static nsWeakPtr sComposerCommandManager; // composer-specific commands (lots of them) +}; diff --git a/mozilla/editor/base/nsEditorRegistration.cpp b/mozilla/editor/base/nsEditorRegistration.cpp index 241a8b038ed..46c79b16a65 100644 --- a/mozilla/editor/base/nsEditorRegistration.cpp +++ b/mozilla/editor/base/nsEditorRegistration.cpp @@ -36,6 +36,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorShell) NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorController) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsComposerController) NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorService) #ifdef ENABLE_EDITOR_API_LOG @@ -58,8 +59,10 @@ static nsModuleComponentInfo components[] = { { "HTML Editor", NS_HTMLEDITOR_CID, "component://netscape/editor/htmleditor", nsHTMLEditorConstructor, }, #endif - { "Editor Shell Controller", NS_EDITORCONTROLLER_CID, + { "Editor Controller", NS_EDITORCONTROLLER_CID, "component://netscape/editor/editorcontroller", nsEditorControllerConstructor, }, + { "Composer Controller", NS_COMPOSERCONTROLLER_CID, + "component://netscape/editor/composercontroller", nsComposerControllerConstructor, }, { "Editor Shell Component", NS_EDITORSHELL_CID, "component://netscape/editor/editorshell", nsEditorShellConstructor, }, { "Editor Shell Spell Checker", NS_EDITORSHELL_CID, diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index 2dea300809e..8066c1b42f1 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -215,10 +215,11 @@ GetTreeOwner(nsIDocShell* aDocShell, nsIBaseWindow** aBaseWindow) ///////////////////////////////////////////////////////////////////////// nsEditorShell::nsEditorShell() -: mToolbarWindow(nsnull) -, mContentWindow(nsnull) -, mParserObserver(nsnull) +: mParserObserver(nsnull) , mStateMaintainer(nsnull) +, mWebShellWindow(nsnull) +, mContentWindow(nsnull) +, mEditorController(nsnull) , mDocShell(nsnull) , mContentAreaDocShell(nsnull) , mCloseWindowWhenLoaded(PR_FALSE) @@ -295,13 +296,14 @@ nsEditorShell::Init() // XXX: why are we returning NS_OK here rather than res? // is it ok to fail to get a string bundle? if so, it should be documented. + return NS_OK; } nsresult nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUrl) { - if (!mContentAreaDocShell) + if (!mContentAreaDocShell || !mContentWindow) return NS_ERROR_NOT_INITIALIZED; if (mEditor) @@ -322,6 +324,13 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr NS_IF_RELEASE(mStateMaintainer); } } + + // clear this editor out of the controller + if (mEditorController) + { + mEditorController->SetCommandRefCon(nsnull); + } + mEditorType = eUninitializedEditorType; mEditor = 0; // clear out the nsCOMPtr @@ -394,29 +403,12 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr { txnMgr->AddListener(NS_STATIC_CAST(nsITransactionListener*, mStateMaintainer)); } - - if (NS_SUCCEEDED(rv) && mContentWindow) + + // set the editor in the editor controller + if (mEditorController) { - nsCOMPtr controller; - nsCOMPtr controllers; - rv = nsComponentManager::CreateInstance("component://netscape/editor/editorcontroller", - nsnull, - NS_GET_IID(nsIController), - getter_AddRefs(controller)); - if (NS_SUCCEEDED(rv) && controller) - { - rv = mContentWindow->GetControllers(getter_AddRefs(controllers)); - if (NS_SUCCEEDED(rv) && controllers) - { - nsCOMPtr editorController = do_QueryInterface(controller); - rv = editorController->Init(); - if (NS_FAILED(rv)) return rv; - - editorController->SetEditor(editor);//weak link - - rv = controllers->InsertControllerAt(0, controller); - } - } + nsCOMPtr editorAsISupports = do_QueryInterface(editor); + mEditorController->SetCommandRefCon(editorAsISupports); } // now all the listeners are set up, we can call PostCreate @@ -488,18 +480,6 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr return NS_OK; } -NS_IMETHODIMP -nsEditorShell::SetToolbarWindow(nsIDOMWindow* aWin) -{ - NS_PRECONDITION(aWin != nsnull, "null ptr"); - if (!aWin) - return NS_ERROR_NULL_POINTER; - - mToolbarWindow = aWin; - - return NS_OK; -} - NS_IMETHODIMP nsEditorShell::SetContentWindow(nsIDOMWindow* aWin) { @@ -520,7 +500,52 @@ nsEditorShell::SetContentWindow(nsIDOMWindow* aWin) return NS_ERROR_FAILURE; mContentAreaDocShell = docShell; // dont AddRef - return docShell->SetDocLoaderObserver((nsIDocumentLoaderObserver *)this); + rv = docShell->SetDocLoaderObserver((nsIDocumentLoaderObserver *)this); + if (NS_FAILED(rv)) return rv; + + // we make two controllers + nsCOMPtr controllers; + rv = mContentWindow->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("component://netscape/editor/editorcontroller", &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; + + mEditorController = editorController; // temp weak link, so we can get it and set the editor later + + rv = controllers->InsertControllerAt(0, controller); + if (NS_FAILED(rv)) return rv; + } + + { + // the first is a composer controller, and takes an nsIEditorShell as the refCon + nsCOMPtr controller = do_CreateInstance("component://netscape/editor/composercontroller", &rv); + if (NS_FAILED(rv)) return rv; + nsCOMPtr editorController = do_QueryInterface(controller); + + nsCOMPtr shellAsISupports = do_QueryInterface((nsIEditorShell*)this); + rv = editorController->Init(shellAsISupports); + if (NS_FAILED(rv)) return rv; + + rv = controllers->InsertControllerAt(1, controller); + if (NS_FAILED(rv)) return rv; + } + + return NS_OK; +} + + +NS_IMETHODIMP +nsEditorShell::GetContentWindow(nsIDOMWindow * *aContentWindow) +{ + NS_ENSURE_ARG_POINTER(aContentWindow); + NS_IF_ADDREF(*aContentWindow = mContentWindow); + return NS_OK; } @@ -531,6 +556,8 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin) if (!aWin) return NS_ERROR_NULL_POINTER; + mWebShellWindow = aWin; // no addref + nsCOMPtr globalObj( do_QueryInterface(aWin) ); if (!globalObj) { return NS_ERROR_FAILURE; @@ -544,7 +571,6 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin) return NS_ERROR_NOT_INITIALIZED; mDocShell = docShell; - //NS_ADDREF(mWebShell); /* #ifdef APP_DEBUG @@ -562,6 +588,14 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin) return rv; } +NS_IMETHODIMP +nsEditorShell::GetWebShellWindow(nsIDOMWindow * *aWebShellWindow) +{ + NS_ENSURE_ARG_POINTER(aWebShellWindow); + NS_IF_ADDREF(*aWebShellWindow = mWebShellWindow); + return NS_OK; +} + // tell the appcore what type of editor to instantiate // this must be called before the editor has been instantiated, // otherwise, an error is returned. @@ -672,14 +706,34 @@ nsEditorShell::DoEditorMode(nsIDocShell *aDocShell) NS_IMETHODIMP -nsEditorShell::UpdateInterfaceState(void) +nsEditorShell::UpdateInterfaceState(const PRUnichar *tagToUpdate) { if (!mStateMaintainer) return NS_ERROR_NOT_INITIALIZED; - return mStateMaintainer->ForceUpdate(); + return mStateMaintainer->ForceUpdate(tagToUpdate); } +NS_IMETHODIMP +nsEditorShell::SetCommandStateData(const PRUnichar *commandName, void * stateData) +{ + if (!mStateMaintainer) + return NS_ERROR_NOT_INITIALIZED; + + nsSubsumeStr commandStr((PRUnichar *)commandName, PR_FALSE); + return mStateMaintainer->SetCommandStateData(commandStr, stateData); +} + +NS_IMETHODIMP +nsEditorShell::GetCommandStateData(const PRUnichar *commandName, void * *outStateData) +{ + if (!mStateMaintainer) + return NS_ERROR_NOT_INITIALIZED; + + nsSubsumeStr commandStr((PRUnichar *)commandName, PR_FALSE); + return mStateMaintainer->GetCommandStateData(commandStr, outStateData); +} + // Deletion routines nsresult nsEditorShell::ScrollSelectionIntoView() @@ -768,7 +822,7 @@ nsEditorShell::SetAttribute(nsIDOMElement *element, const PRUnichar *attr, const nsAutoString valueStr(value); result = editor->SetAttribute(element, attributeStr, valueStr); } - UpdateInterfaceState(); + UpdateInterfaceState(nsnull); return result; } @@ -784,7 +838,7 @@ nsEditorShell::RemoveAttribute(nsIDOMElement *element, const PRUnichar *attr) nsAutoString attributeStr(attr); result = editor->RemoveAttribute(element, attributeStr); } - UpdateInterfaceState(); + UpdateInterfaceState(nsnull); return result; } @@ -793,16 +847,10 @@ nsEditorShell::RemoveAttribute(nsIDOMElement *element, const PRUnichar *attr) NS_IMETHODIMP nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value) { - nsIAtom *styleAtom = nsnull; nsresult err = NS_NOINTERFACE; - styleAtom = NS_NewAtom(prop); /// XXX Hack alert! Look in nsIEditProperty.h for this - - if (! styleAtom) - return NS_ERROR_OUT_OF_MEMORY; - - // addref it while we're using it - NS_ADDREF(styleAtom); + nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(prop)); /// XXX Hack alert! Look in nsIEditProperty.h for this + if (! styleAtom) return NS_ERROR_OUT_OF_MEMORY; nsAutoString attributeStr(attr); nsAutoString valueStr(value); @@ -817,8 +865,8 @@ nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, con default: err = NS_ERROR_NOT_IMPLEMENTED; } - UpdateInterfaceState(); - NS_RELEASE(styleAtom); + + UpdateInterfaceState(prop); return err; } @@ -827,16 +875,10 @@ nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, con nsresult nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr) { - nsIAtom *styleAtom = nsnull; nsresult err = NS_NOINTERFACE; - styleAtom = NS_NewAtom(aProp); /// XXX Hack alert! Look in nsIEditProperty.h for this - - if (! styleAtom) - return NS_ERROR_OUT_OF_MEMORY; - - // addref it while we're using it - NS_ADDREF(styleAtom); + nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(aProp)); /// XXX Hack alert! Look in nsIEditProperty.h for this + if (! styleAtom) return NS_ERROR_OUT_OF_MEMORY; switch (mEditorType) { @@ -849,8 +891,7 @@ nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr) err = NS_ERROR_NOT_IMPLEMENTED; } - UpdateInterfaceState(); - NS_RELEASE(styleAtom); + UpdateInterfaceState(aProp.GetUnicode()); return err; } @@ -1520,7 +1561,7 @@ nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval) } else { // File was saved successfully *_retval = PR_TRUE; - + // Update window title to show possibly different filename if (mustShowFileDialog) UpdateWindowTitle(); @@ -1545,12 +1586,12 @@ nsEditorShell::CloseWindow( PRBool *_retval ) // Don't close the window if there was an error saving file or // user canceled an action along the way if (NS_SUCCEEDED(rv) && *_retval) - { + { nsCOMPtr baseWindow; GetTreeOwner(mDocShell, getter_AddRefs(baseWindow)); NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE); baseWindow->Destroy(); - } + } return rv; } @@ -2911,6 +2952,29 @@ nsEditorShell::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty) return NS_NOINTERFACE; } + +NS_IMETHODIMP +nsEditorShell::GetDocumentEditable(PRBool *aDocumentEditable) +{ + *aDocumentEditable = PR_FALSE; // default return value + nsCOMPtr editor = do_QueryInterface(mEditor); + if (!editor) return NS_OK; + + PRUint32 editorFlags; + editor->GetFlags(&editorFlags); + + if (editorFlags & nsIHTMLEditor::eEditorReadonlyMask) + return NS_OK; + + nsCOMPtr doc; + editor->GetDocument(getter_AddRefs(doc)); + if (!doc) return NS_OK; + + *aDocumentEditable = PR_TRUE; + return NS_OK; +} + + NS_IMETHODIMP nsEditorShell::GetDocumentLength(PRInt32 *aDocumentLength) { diff --git a/mozilla/editor/base/nsEditorShell.h b/mozilla/editor/base/nsEditorShell.h index 4fd0bc37906..92e96452ba6 100644 --- a/mozilla/editor/base/nsEditorShell.h +++ b/mozilla/editor/base/nsEditorShell.h @@ -30,6 +30,7 @@ #include "nsISupports.h" #include "nsIEditorShell.h" +#include "nsIEditorController.h" #include "nsIDocumentLoaderObserver.h" #include "nsIDOMSelectionListener.h" #include "nsIPrompt.h" @@ -157,13 +158,14 @@ class nsEditorShell : public nsIEditorShell, nsCOMPtr mAllTagsModeStyleSheet; nsCOMPtr mParagraphMarksStyleSheet; - nsIDOMWindow *mToolbarWindow; // weak reference - nsIDOMWindow *mContentWindow; // weak reference + nsIDOMWindow *mWebShellWindow; // weak reference + nsIDOMWindow *mContentWindow; // weak reference - nsEditorParserObserver* mParserObserver; // we hold the owning ref to this. - nsInterfaceState* mStateMaintainer; // we hold the owning ref to this. + nsEditorParserObserver *mParserObserver; // we hold the owning ref to this. + nsInterfaceState *mStateMaintainer; // we hold the owning ref to this. - nsIDocShell *mDocShell; // weak reference + nsIEditorController *mEditorController; // temporary weak ref to the editor controller + nsIDocShell *mDocShell; // weak reference // The webshell that contains the document being edited. // Don't assume that webshell directly contains the document being edited; diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index f29f6489c90..daf5e9c57fe 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -1779,7 +1779,7 @@ NS_IMETHODIMP nsHTMLEditor::GetInlineProperty(nsIAtom *aProperty, iter->Init(range); nsCOMPtr content; - result = iter->CurrentNode(getter_AddRefs(content)); + iter->CurrentNode(getter_AddRefs(content)); while (NS_ENUMERATOR_FALSE == iter->IsDone()) { //if (gNoisy) { printf(" checking node %p\n", content.get()); } diff --git a/mozilla/editor/base/nsInterfaceState.cpp b/mozilla/editor/base/nsInterfaceState.cpp index d920c303218..ca715716533 100644 --- a/mozilla/editor/base/nsInterfaceState.cpp +++ b/mozilla/editor/base/nsInterfaceState.cpp @@ -35,7 +35,6 @@ #include "nsIDOMElement.h" #include "nsIDOMSelection.h" #include "nsIDOMAttr.h" -#include "nsIDOMXULCommandDispatcher.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" #include "nsITimer.h" @@ -46,6 +45,33 @@ #include "nsInterfaceState.h" + +/* +static PRBool StringHashDestroyFunc(nsHashKey *aKey, void *aData, void* closure) +{ + nsString* stringData = NS_REINTERPRET_CAST(nsString*, aData); + delete stringData; + return PR_FALSE; +} + +static void* StringHashCloneElementFunc(nsHashKey *aKey, void *aData, void* closure) +{ + nsString* stringData = NS_REINTERPRET_CAST(nsString*, aData); + if (stringData) + { + nsString* newString = new nsString(*stringData); + return newString; + } + + return nsnull; +} + +*/ + +#ifdef XP_MAC +#pragma mark - +#endif + nsInterfaceState::nsInterfaceState() : mEditor(nsnull) , mChromeDoc(nsnull) @@ -261,7 +287,8 @@ void nsInterfaceState::TimerCallback() mSelectionCollapsed = isCollapsed; } - (void)ForceUpdate(); + // (void)ForceUpdate(); + CallUpdateCommands(NS_ConvertASCIItoUCS2("style")); } @@ -291,42 +318,44 @@ nsresult nsInterfaceState::CallUpdateCommands(const nsString& aCommand) } NS_IMETHODIMP -nsInterfaceState::ForceUpdate() +nsInterfaceState::ForceUpdate(const PRUnichar *tagToUpdate) { + PRBool updateEverything = !tagToUpdate || !*tagToUpdate; + +#if 0 + // This code is obsolete now that commanders are doing the work nsresult rv; - - // we don't really care if any of these fail. - + // update bold - if (mUpdateBold) + if (mUpdateBold && (updateEverything || nsAutoString("b").Equals(tagToUpdate))) { - rv = UpdateTextState("b", "Editor:Bold", "bold", mBoldState); + rv = UpdateTextState("b", "cmd_bold", "bold", mBoldState); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); } // update italic - if (mUpdateItalics) + if (mUpdateItalics && (updateEverything || nsAutoString("i").Equals(tagToUpdate))) { - rv = UpdateTextState("i", "Editor:Italic", "italic", mItalicState); + rv = UpdateTextState("i", "cmd_italic", "italic", mItalicState); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); } // update underline - if (mUpdateUnderline) + if (mUpdateUnderline && (updateEverything || nsAutoString("u").Equals(tagToUpdate))) { - rv = UpdateTextState("u", "Editor:Underline", "underline", mUnderlineState); + rv = UpdateTextState("u", "cmd_underline", "underline", mUnderlineState); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); } // update the paragraph format popup - if (mUpdateParagraph) + if (mUpdateParagraph && (updateEverything || nsAutoString("format").Equals(tagToUpdate))) { rv = UpdateParagraphState("Editor:Paragraph:Format", "format"); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); } // udpate the font face - if (mUpdateFont) + if (mUpdateFont && (updateEverything || nsAutoString("font").Equals(tagToUpdate))) { rv = UpdateFontFace("Editor:Font:Face", "font"); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); @@ -335,15 +364,42 @@ nsInterfaceState::ForceUpdate() // TODO: FINISH FONT FACE AND ADD FONT SIZE ("Editor:Font:Size", "fontsize", mFontSize) // update the list buttons - if (mUpdateList) + if (mUpdateList && (updateEverything || + nsAutoString("ol").Equals(tagToUpdate) || + nsAutoString("ul").Equals(tagToUpdate))) { rv = UpdateListState("Editor:Paragraph:ListType"); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); } +#endif return NS_OK; } + +NS_IMETHODIMP +nsInterfaceState::SetCommandStateData(const nsString& commandName, void* stateData) +{ + nsStringKey commandKey(commandName); + mCommandStateTable.Put(&commandKey, stateData); + return NS_OK; +} + + +NS_IMETHODIMP +nsInterfaceState::GetCommandStateData(const nsString& commandName, void* *outStateData) +{ + nsStringKey commandKey(commandName); + + // sucks that we have to do two hash lookups + if (!mCommandStateTable.Exists(&commandKey)) + return NS_ERROR_UNEXPECTED; + + *outStateData = mCommandStateTable.Get(&commandKey); + return NS_OK; +} + + PRBool nsInterfaceState::SelectionIsCollapsed() { @@ -573,10 +629,7 @@ nsInterfaceState::UpdateDirtyState(PRBool aNowDirty) { if (mDirtyState != aNowDirty) { - nsresult rv; // = SetNodeAttribute("Editor:Save", "disabled", aNowDirty ? "true" : "false"); - - rv = SetNodeAttribute("Editor:Save", "disabled", NS_ConvertASCIItoUCS2(aNowDirty ? "false" : "true")); - if (NS_FAILED(rv)) return rv; + CallUpdateCommands(NS_ConvertASCIItoUCS2("save")); mDirtyState = aNowDirty; } diff --git a/mozilla/editor/base/nsInterfaceState.h b/mozilla/editor/base/nsInterfaceState.h index fa57893641d..4727553ea74 100644 --- a/mozilla/editor/base/nsInterfaceState.h +++ b/mozilla/editor/base/nsInterfaceState.h @@ -32,6 +32,8 @@ #include "nsITimer.h" #include "nsITimerCallback.h" +#include "nsHashTable.h" + class nsIHTMLEditor; class nsIDOMXULDocument; @@ -54,11 +56,14 @@ public: // force an update of the UI. At some point, we could pass flags // here to target certain things for updating. - NS_IMETHOD ForceUpdate(); + NS_IMETHOD ForceUpdate(const PRUnichar *tagToUpdate); // nsIDOMSelectionListener interface NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *aDoc, nsIDOMSelection *aSel, short aReason); + NS_IMETHOD SetCommandStateData(const nsString& commandName, void* stateData); + NS_IMETHOD GetCommandStateData(const nsString& commandName, void* *outStateData); + NS_DECL_NSIDOCUMENTSTATELISTENER // nsITimerCallback interfaces @@ -128,6 +133,8 @@ protected: PRPackedBool mUpdateItalics; PRPackedBool mUpdateUnderline; + nsHashtable mCommandStateTable; + // current state PRInt8 mBoldState; PRInt8 mItalicState; diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 2dea300809e..8066c1b42f1 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -215,10 +215,11 @@ GetTreeOwner(nsIDocShell* aDocShell, nsIBaseWindow** aBaseWindow) ///////////////////////////////////////////////////////////////////////// nsEditorShell::nsEditorShell() -: mToolbarWindow(nsnull) -, mContentWindow(nsnull) -, mParserObserver(nsnull) +: mParserObserver(nsnull) , mStateMaintainer(nsnull) +, mWebShellWindow(nsnull) +, mContentWindow(nsnull) +, mEditorController(nsnull) , mDocShell(nsnull) , mContentAreaDocShell(nsnull) , mCloseWindowWhenLoaded(PR_FALSE) @@ -295,13 +296,14 @@ nsEditorShell::Init() // XXX: why are we returning NS_OK here rather than res? // is it ok to fail to get a string bundle? if so, it should be documented. + return NS_OK; } nsresult nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUrl) { - if (!mContentAreaDocShell) + if (!mContentAreaDocShell || !mContentWindow) return NS_ERROR_NOT_INITIALIZED; if (mEditor) @@ -322,6 +324,13 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr NS_IF_RELEASE(mStateMaintainer); } } + + // clear this editor out of the controller + if (mEditorController) + { + mEditorController->SetCommandRefCon(nsnull); + } + mEditorType = eUninitializedEditorType; mEditor = 0; // clear out the nsCOMPtr @@ -394,29 +403,12 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr { txnMgr->AddListener(NS_STATIC_CAST(nsITransactionListener*, mStateMaintainer)); } - - if (NS_SUCCEEDED(rv) && mContentWindow) + + // set the editor in the editor controller + if (mEditorController) { - nsCOMPtr controller; - nsCOMPtr controllers; - rv = nsComponentManager::CreateInstance("component://netscape/editor/editorcontroller", - nsnull, - NS_GET_IID(nsIController), - getter_AddRefs(controller)); - if (NS_SUCCEEDED(rv) && controller) - { - rv = mContentWindow->GetControllers(getter_AddRefs(controllers)); - if (NS_SUCCEEDED(rv) && controllers) - { - nsCOMPtr editorController = do_QueryInterface(controller); - rv = editorController->Init(); - if (NS_FAILED(rv)) return rv; - - editorController->SetEditor(editor);//weak link - - rv = controllers->InsertControllerAt(0, controller); - } - } + nsCOMPtr editorAsISupports = do_QueryInterface(editor); + mEditorController->SetCommandRefCon(editorAsISupports); } // now all the listeners are set up, we can call PostCreate @@ -488,18 +480,6 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr return NS_OK; } -NS_IMETHODIMP -nsEditorShell::SetToolbarWindow(nsIDOMWindow* aWin) -{ - NS_PRECONDITION(aWin != nsnull, "null ptr"); - if (!aWin) - return NS_ERROR_NULL_POINTER; - - mToolbarWindow = aWin; - - return NS_OK; -} - NS_IMETHODIMP nsEditorShell::SetContentWindow(nsIDOMWindow* aWin) { @@ -520,7 +500,52 @@ nsEditorShell::SetContentWindow(nsIDOMWindow* aWin) return NS_ERROR_FAILURE; mContentAreaDocShell = docShell; // dont AddRef - return docShell->SetDocLoaderObserver((nsIDocumentLoaderObserver *)this); + rv = docShell->SetDocLoaderObserver((nsIDocumentLoaderObserver *)this); + if (NS_FAILED(rv)) return rv; + + // we make two controllers + nsCOMPtr controllers; + rv = mContentWindow->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("component://netscape/editor/editorcontroller", &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; + + mEditorController = editorController; // temp weak link, so we can get it and set the editor later + + rv = controllers->InsertControllerAt(0, controller); + if (NS_FAILED(rv)) return rv; + } + + { + // the first is a composer controller, and takes an nsIEditorShell as the refCon + nsCOMPtr controller = do_CreateInstance("component://netscape/editor/composercontroller", &rv); + if (NS_FAILED(rv)) return rv; + nsCOMPtr editorController = do_QueryInterface(controller); + + nsCOMPtr shellAsISupports = do_QueryInterface((nsIEditorShell*)this); + rv = editorController->Init(shellAsISupports); + if (NS_FAILED(rv)) return rv; + + rv = controllers->InsertControllerAt(1, controller); + if (NS_FAILED(rv)) return rv; + } + + return NS_OK; +} + + +NS_IMETHODIMP +nsEditorShell::GetContentWindow(nsIDOMWindow * *aContentWindow) +{ + NS_ENSURE_ARG_POINTER(aContentWindow); + NS_IF_ADDREF(*aContentWindow = mContentWindow); + return NS_OK; } @@ -531,6 +556,8 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin) if (!aWin) return NS_ERROR_NULL_POINTER; + mWebShellWindow = aWin; // no addref + nsCOMPtr globalObj( do_QueryInterface(aWin) ); if (!globalObj) { return NS_ERROR_FAILURE; @@ -544,7 +571,6 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin) return NS_ERROR_NOT_INITIALIZED; mDocShell = docShell; - //NS_ADDREF(mWebShell); /* #ifdef APP_DEBUG @@ -562,6 +588,14 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin) return rv; } +NS_IMETHODIMP +nsEditorShell::GetWebShellWindow(nsIDOMWindow * *aWebShellWindow) +{ + NS_ENSURE_ARG_POINTER(aWebShellWindow); + NS_IF_ADDREF(*aWebShellWindow = mWebShellWindow); + return NS_OK; +} + // tell the appcore what type of editor to instantiate // this must be called before the editor has been instantiated, // otherwise, an error is returned. @@ -672,14 +706,34 @@ nsEditorShell::DoEditorMode(nsIDocShell *aDocShell) NS_IMETHODIMP -nsEditorShell::UpdateInterfaceState(void) +nsEditorShell::UpdateInterfaceState(const PRUnichar *tagToUpdate) { if (!mStateMaintainer) return NS_ERROR_NOT_INITIALIZED; - return mStateMaintainer->ForceUpdate(); + return mStateMaintainer->ForceUpdate(tagToUpdate); } +NS_IMETHODIMP +nsEditorShell::SetCommandStateData(const PRUnichar *commandName, void * stateData) +{ + if (!mStateMaintainer) + return NS_ERROR_NOT_INITIALIZED; + + nsSubsumeStr commandStr((PRUnichar *)commandName, PR_FALSE); + return mStateMaintainer->SetCommandStateData(commandStr, stateData); +} + +NS_IMETHODIMP +nsEditorShell::GetCommandStateData(const PRUnichar *commandName, void * *outStateData) +{ + if (!mStateMaintainer) + return NS_ERROR_NOT_INITIALIZED; + + nsSubsumeStr commandStr((PRUnichar *)commandName, PR_FALSE); + return mStateMaintainer->GetCommandStateData(commandStr, outStateData); +} + // Deletion routines nsresult nsEditorShell::ScrollSelectionIntoView() @@ -768,7 +822,7 @@ nsEditorShell::SetAttribute(nsIDOMElement *element, const PRUnichar *attr, const nsAutoString valueStr(value); result = editor->SetAttribute(element, attributeStr, valueStr); } - UpdateInterfaceState(); + UpdateInterfaceState(nsnull); return result; } @@ -784,7 +838,7 @@ nsEditorShell::RemoveAttribute(nsIDOMElement *element, const PRUnichar *attr) nsAutoString attributeStr(attr); result = editor->RemoveAttribute(element, attributeStr); } - UpdateInterfaceState(); + UpdateInterfaceState(nsnull); return result; } @@ -793,16 +847,10 @@ nsEditorShell::RemoveAttribute(nsIDOMElement *element, const PRUnichar *attr) NS_IMETHODIMP nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value) { - nsIAtom *styleAtom = nsnull; nsresult err = NS_NOINTERFACE; - styleAtom = NS_NewAtom(prop); /// XXX Hack alert! Look in nsIEditProperty.h for this - - if (! styleAtom) - return NS_ERROR_OUT_OF_MEMORY; - - // addref it while we're using it - NS_ADDREF(styleAtom); + nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(prop)); /// XXX Hack alert! Look in nsIEditProperty.h for this + if (! styleAtom) return NS_ERROR_OUT_OF_MEMORY; nsAutoString attributeStr(attr); nsAutoString valueStr(value); @@ -817,8 +865,8 @@ nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, con default: err = NS_ERROR_NOT_IMPLEMENTED; } - UpdateInterfaceState(); - NS_RELEASE(styleAtom); + + UpdateInterfaceState(prop); return err; } @@ -827,16 +875,10 @@ nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, con nsresult nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr) { - nsIAtom *styleAtom = nsnull; nsresult err = NS_NOINTERFACE; - styleAtom = NS_NewAtom(aProp); /// XXX Hack alert! Look in nsIEditProperty.h for this - - if (! styleAtom) - return NS_ERROR_OUT_OF_MEMORY; - - // addref it while we're using it - NS_ADDREF(styleAtom); + nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(aProp)); /// XXX Hack alert! Look in nsIEditProperty.h for this + if (! styleAtom) return NS_ERROR_OUT_OF_MEMORY; switch (mEditorType) { @@ -849,8 +891,7 @@ nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr) err = NS_ERROR_NOT_IMPLEMENTED; } - UpdateInterfaceState(); - NS_RELEASE(styleAtom); + UpdateInterfaceState(aProp.GetUnicode()); return err; } @@ -1520,7 +1561,7 @@ nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval) } else { // File was saved successfully *_retval = PR_TRUE; - + // Update window title to show possibly different filename if (mustShowFileDialog) UpdateWindowTitle(); @@ -1545,12 +1586,12 @@ nsEditorShell::CloseWindow( PRBool *_retval ) // Don't close the window if there was an error saving file or // user canceled an action along the way if (NS_SUCCEEDED(rv) && *_retval) - { + { nsCOMPtr baseWindow; GetTreeOwner(mDocShell, getter_AddRefs(baseWindow)); NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE); baseWindow->Destroy(); - } + } return rv; } @@ -2911,6 +2952,29 @@ nsEditorShell::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty) return NS_NOINTERFACE; } + +NS_IMETHODIMP +nsEditorShell::GetDocumentEditable(PRBool *aDocumentEditable) +{ + *aDocumentEditable = PR_FALSE; // default return value + nsCOMPtr editor = do_QueryInterface(mEditor); + if (!editor) return NS_OK; + + PRUint32 editorFlags; + editor->GetFlags(&editorFlags); + + if (editorFlags & nsIHTMLEditor::eEditorReadonlyMask) + return NS_OK; + + nsCOMPtr doc; + editor->GetDocument(getter_AddRefs(doc)); + if (!doc) return NS_OK; + + *aDocumentEditable = PR_TRUE; + return NS_OK; +} + + NS_IMETHODIMP nsEditorShell::GetDocumentLength(PRInt32 *aDocumentLength) { diff --git a/mozilla/editor/composer/src/nsEditorShell.h b/mozilla/editor/composer/src/nsEditorShell.h index 4fd0bc37906..92e96452ba6 100644 --- a/mozilla/editor/composer/src/nsEditorShell.h +++ b/mozilla/editor/composer/src/nsEditorShell.h @@ -30,6 +30,7 @@ #include "nsISupports.h" #include "nsIEditorShell.h" +#include "nsIEditorController.h" #include "nsIDocumentLoaderObserver.h" #include "nsIDOMSelectionListener.h" #include "nsIPrompt.h" @@ -157,13 +158,14 @@ class nsEditorShell : public nsIEditorShell, nsCOMPtr mAllTagsModeStyleSheet; nsCOMPtr mParagraphMarksStyleSheet; - nsIDOMWindow *mToolbarWindow; // weak reference - nsIDOMWindow *mContentWindow; // weak reference + nsIDOMWindow *mWebShellWindow; // weak reference + nsIDOMWindow *mContentWindow; // weak reference - nsEditorParserObserver* mParserObserver; // we hold the owning ref to this. - nsInterfaceState* mStateMaintainer; // we hold the owning ref to this. + nsEditorParserObserver *mParserObserver; // we hold the owning ref to this. + nsInterfaceState *mStateMaintainer; // we hold the owning ref to this. - nsIDocShell *mDocShell; // weak reference + nsIEditorController *mEditorController; // temporary weak ref to the editor controller + nsIDocShell *mDocShell; // weak reference // The webshell that contains the document being edited. // Don't assume that webshell directly contains the document being edited; diff --git a/mozilla/editor/composer/src/nsInterfaceState.cpp b/mozilla/editor/composer/src/nsInterfaceState.cpp index d920c303218..ca715716533 100644 --- a/mozilla/editor/composer/src/nsInterfaceState.cpp +++ b/mozilla/editor/composer/src/nsInterfaceState.cpp @@ -35,7 +35,6 @@ #include "nsIDOMElement.h" #include "nsIDOMSelection.h" #include "nsIDOMAttr.h" -#include "nsIDOMXULCommandDispatcher.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" #include "nsITimer.h" @@ -46,6 +45,33 @@ #include "nsInterfaceState.h" + +/* +static PRBool StringHashDestroyFunc(nsHashKey *aKey, void *aData, void* closure) +{ + nsString* stringData = NS_REINTERPRET_CAST(nsString*, aData); + delete stringData; + return PR_FALSE; +} + +static void* StringHashCloneElementFunc(nsHashKey *aKey, void *aData, void* closure) +{ + nsString* stringData = NS_REINTERPRET_CAST(nsString*, aData); + if (stringData) + { + nsString* newString = new nsString(*stringData); + return newString; + } + + return nsnull; +} + +*/ + +#ifdef XP_MAC +#pragma mark - +#endif + nsInterfaceState::nsInterfaceState() : mEditor(nsnull) , mChromeDoc(nsnull) @@ -261,7 +287,8 @@ void nsInterfaceState::TimerCallback() mSelectionCollapsed = isCollapsed; } - (void)ForceUpdate(); + // (void)ForceUpdate(); + CallUpdateCommands(NS_ConvertASCIItoUCS2("style")); } @@ -291,42 +318,44 @@ nsresult nsInterfaceState::CallUpdateCommands(const nsString& aCommand) } NS_IMETHODIMP -nsInterfaceState::ForceUpdate() +nsInterfaceState::ForceUpdate(const PRUnichar *tagToUpdate) { + PRBool updateEverything = !tagToUpdate || !*tagToUpdate; + +#if 0 + // This code is obsolete now that commanders are doing the work nsresult rv; - - // we don't really care if any of these fail. - + // update bold - if (mUpdateBold) + if (mUpdateBold && (updateEverything || nsAutoString("b").Equals(tagToUpdate))) { - rv = UpdateTextState("b", "Editor:Bold", "bold", mBoldState); + rv = UpdateTextState("b", "cmd_bold", "bold", mBoldState); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); } // update italic - if (mUpdateItalics) + if (mUpdateItalics && (updateEverything || nsAutoString("i").Equals(tagToUpdate))) { - rv = UpdateTextState("i", "Editor:Italic", "italic", mItalicState); + rv = UpdateTextState("i", "cmd_italic", "italic", mItalicState); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); } // update underline - if (mUpdateUnderline) + if (mUpdateUnderline && (updateEverything || nsAutoString("u").Equals(tagToUpdate))) { - rv = UpdateTextState("u", "Editor:Underline", "underline", mUnderlineState); + rv = UpdateTextState("u", "cmd_underline", "underline", mUnderlineState); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); } // update the paragraph format popup - if (mUpdateParagraph) + if (mUpdateParagraph && (updateEverything || nsAutoString("format").Equals(tagToUpdate))) { rv = UpdateParagraphState("Editor:Paragraph:Format", "format"); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); } // udpate the font face - if (mUpdateFont) + if (mUpdateFont && (updateEverything || nsAutoString("font").Equals(tagToUpdate))) { rv = UpdateFontFace("Editor:Font:Face", "font"); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); @@ -335,15 +364,42 @@ nsInterfaceState::ForceUpdate() // TODO: FINISH FONT FACE AND ADD FONT SIZE ("Editor:Font:Size", "fontsize", mFontSize) // update the list buttons - if (mUpdateList) + if (mUpdateList && (updateEverything || + nsAutoString("ol").Equals(tagToUpdate) || + nsAutoString("ul").Equals(tagToUpdate))) { rv = UpdateListState("Editor:Paragraph:ListType"); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); } +#endif return NS_OK; } + +NS_IMETHODIMP +nsInterfaceState::SetCommandStateData(const nsString& commandName, void* stateData) +{ + nsStringKey commandKey(commandName); + mCommandStateTable.Put(&commandKey, stateData); + return NS_OK; +} + + +NS_IMETHODIMP +nsInterfaceState::GetCommandStateData(const nsString& commandName, void* *outStateData) +{ + nsStringKey commandKey(commandName); + + // sucks that we have to do two hash lookups + if (!mCommandStateTable.Exists(&commandKey)) + return NS_ERROR_UNEXPECTED; + + *outStateData = mCommandStateTable.Get(&commandKey); + return NS_OK; +} + + PRBool nsInterfaceState::SelectionIsCollapsed() { @@ -573,10 +629,7 @@ nsInterfaceState::UpdateDirtyState(PRBool aNowDirty) { if (mDirtyState != aNowDirty) { - nsresult rv; // = SetNodeAttribute("Editor:Save", "disabled", aNowDirty ? "true" : "false"); - - rv = SetNodeAttribute("Editor:Save", "disabled", NS_ConvertASCIItoUCS2(aNowDirty ? "false" : "true")); - if (NS_FAILED(rv)) return rv; + CallUpdateCommands(NS_ConvertASCIItoUCS2("save")); mDirtyState = aNowDirty; } diff --git a/mozilla/editor/composer/src/nsInterfaceState.h b/mozilla/editor/composer/src/nsInterfaceState.h index fa57893641d..4727553ea74 100644 --- a/mozilla/editor/composer/src/nsInterfaceState.h +++ b/mozilla/editor/composer/src/nsInterfaceState.h @@ -32,6 +32,8 @@ #include "nsITimer.h" #include "nsITimerCallback.h" +#include "nsHashTable.h" + class nsIHTMLEditor; class nsIDOMXULDocument; @@ -54,11 +56,14 @@ public: // force an update of the UI. At some point, we could pass flags // here to target certain things for updating. - NS_IMETHOD ForceUpdate(); + NS_IMETHOD ForceUpdate(const PRUnichar *tagToUpdate); // nsIDOMSelectionListener interface NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *aDoc, nsIDOMSelection *aSel, short aReason); + NS_IMETHOD SetCommandStateData(const nsString& commandName, void* stateData); + NS_IMETHOD GetCommandStateData(const nsString& commandName, void* *outStateData); + NS_DECL_NSIDOCUMENTSTATELISTENER // nsITimerCallback interfaces @@ -128,6 +133,8 @@ protected: PRPackedBool mUpdateItalics; PRPackedBool mUpdateUnderline; + nsHashtable mCommandStateTable; + // current state PRInt8 mBoldState; PRInt8 mItalicState; diff --git a/mozilla/editor/idl/nsIEditorShell.idl b/mozilla/editor/idl/nsIEditorShell.idl index e6c49557589..cff84799a7e 100644 --- a/mozilla/editor/idl/nsIEditorShell.idl +++ b/mozilla/editor/idl/nsIEditorShell.idl @@ -47,6 +47,9 @@ interface nsIEditorShell : nsISupports readonly attribute nsIDOMSelection editorSelection; readonly attribute nsISelectionController selectionController; + attribute nsIDOMWindow webShellWindow; + attribute nsIDOMWindow contentWindow; + [noscript] readonly attribute nsIEditor editor; %{C++ @@ -64,15 +67,13 @@ interface nsIEditorShell : nsISupports %} readonly attribute boolean documentModified; readonly attribute boolean documentIsEmpty; + readonly attribute boolean documentEditable; // do we have a doc and editor yet? readonly attribute long documentLength; attribute long wrapColumn; /* Setup */ void SetEditorType(in wstring editorType); - void SetToolbarWindow(in nsIDOMWindow win); - void SetContentWindow(in nsIDOMWindow win); - void SetWebShellWindow(in nsIDOMWindow win); void LoadUrl(in wstring url); /* Set the value of the tag in the <head> of a document @@ -158,9 +159,15 @@ interface nsIEditorShell : nsISupports /* General Utilities */ - /* UI updating */ - void UpdateInterfaceState(); + /* UI updating + * tagToUpdate can be null or "" to update everything + */ + void UpdateInterfaceState(in wstring tagToUpdate); + /* Used to associate state with a command */ + [noscript] void SetCommandStateData(in wstring commandName, in voidStar stateData); + [noscript] voidStar GetCommandStateData(in wstring commandName); + /* Get string from the Editor's localized string bundle */ wstring GetString(in wstring name); diff --git a/mozilla/editor/libeditor/base/nsEditorCommands.cpp b/mozilla/editor/libeditor/base/nsEditorCommands.cpp index 2a623f6dff2..c4db3ecb12a 100644 --- a/mozilla/editor/libeditor/base/nsEditorCommands.cpp +++ b/mozilla/editor/libeditor/base/nsEditorCommands.cpp @@ -38,13 +38,12 @@ nsBaseCommand::nsBaseCommand() NS_INIT_REFCNT(); } - -nsBaseCommand::~nsBaseCommand() -{ -} - NS_IMPL_ISUPPORTS(nsBaseCommand, NS_GET_IID(nsIControllerCommand)); +#ifdef XP_MAC +#pragma mark - +#endif + NS_IMETHODIMP nsUndoCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled) diff --git a/mozilla/editor/libeditor/base/nsEditorCommands.h b/mozilla/editor/libeditor/base/nsEditorCommands.h index 497b1da716f..95cd5c15059 100644 --- a/mozilla/editor/libeditor/base/nsEditorCommands.h +++ b/mozilla/editor/libeditor/base/nsEditorCommands.h @@ -34,7 +34,7 @@ class nsBaseCommand : public nsIControllerCommand public: nsBaseCommand(); - virtual ~nsBaseCommand(); + virtual ~nsBaseCommand() {} NS_DECL_ISUPPORTS @@ -44,13 +44,16 @@ public: }; -#define NS_DECL_EDITOR_COMMAND(_cmd) \ -class _cmd : public nsBaseCommand \ -{ \ -public: \ - NS_DECL_NSICONTROLLERCOMMAND \ +#define NS_DECL_EDITOR_COMMAND(_cmd) \ +class _cmd : public nsBaseCommand \ +{ \ +public: \ + NS_DECL_NSICONTROLLERCOMMAND \ }; + + +// basic editor commands NS_DECL_EDITOR_COMMAND(nsUndoCommand) NS_DECL_EDITOR_COMMAND(nsRedoCommand) @@ -63,4 +66,23 @@ NS_DECL_EDITOR_COMMAND(nsSelectAllCommand) NS_DECL_EDITOR_COMMAND(nsSelectionMoveCommands) + +#if 0 +// template for new command +NS_IMETHODIMP +nsFooCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsFooCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +#endif + #endif // nsIEditorCommand_h_ diff --git a/mozilla/editor/libeditor/base/nsEditorController.cpp b/mozilla/editor/libeditor/base/nsEditorController.cpp index 5b9e2ce5bac..9f5ab309c8f 100644 --- a/mozilla/editor/libeditor/base/nsEditorController.cpp +++ b/mozilla/editor/libeditor/base/nsEditorController.cpp @@ -24,6 +24,7 @@ #include "nsIComponentManager.h" #include "nsEditorController.h" #include "nsIEditor.h" +#include "nsIEditorShell.h" #include "nsIEditorMailSupport.h" #include "nsIFormControlFrame.h" #include "nsIDOMSelection.h" @@ -36,7 +37,7 @@ #include "nsIPresShell.h" #include "nsEditorCommands.h" - +#include "nsComposerCommands.h" #define kMaxStackCommandNameLength 128 @@ -47,31 +48,49 @@ NS_IMPL_RELEASE(nsEditorController) NS_INTERFACE_MAP_BEGIN(nsEditorController) NS_INTERFACE_MAP_ENTRY(nsIController) NS_INTERFACE_MAP_ENTRY(nsIEditorController) + NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditorController) NS_INTERFACE_MAP_END nsEditorController::nsEditorController() -: mContent(NULL) -, mEditor(NULL) +: mCommandRefCon(nsnull) { NS_INIT_REFCNT(); } nsEditorController::~nsEditorController() { - // if the singleton command manger has a refcount of 1 at this point, we need to - // set it to null } -NS_IMETHODIMP nsEditorController::Init() +NS_IMETHODIMP nsEditorController::Init(nsISupports *aCommandRefCon) { nsresult rv; // get our ref to the singleton command manager - rv = GetCommandManager(getter_AddRefs(mCommandManager)); + 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; - return rv; + if (mCommandManager && aIID.Equals(NS_GET_IID(nsIControllerCommandManager))) + return mCommandManager->QueryInterface(aIID, result); + + return NS_NOINTERFACE; } @@ -100,6 +119,8 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager nsresult rv; // now register all our commands + // These are commands that will be used in text widgets, and in composer + NS_REGISTER_ONE_COMMAND(nsUndoCommand, "cmd_undo"); NS_REGISTER_ONE_COMMAND(nsRedoCommand, "cmd_redo"); @@ -107,8 +128,7 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager NS_REGISTER_ONE_COMMAND(nsCopyCommand, "cmd_copy"); NS_REGISTER_ONE_COMMAND(nsSelectAllCommand, "cmd_selectAll"); - NS_REGISTER_FIRST_COMMAND(nsPasteCommand, "cmd_paste"); - NS_REGISTER_LAST_COMMAND(nsPasteCommand, "cmd_pasteQuote"); + NS_REGISTER_ONE_COMMAND(nsPasteCommand, "cmd_paste"); NS_REGISTER_FIRST_COMMAND(nsDeleteCommand, "cmd_delete"); NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteCharBackward"); @@ -166,106 +186,23 @@ nsresult nsEditorController::RegisterOneCommand(const PRUnichar* aCommandName, return inCommandManager->RegisterCommand(aCommandName, editorCommand); // this is the owning ref } - -NS_IMETHODIMP nsEditorController::SetContent(nsIHTMLContent *aContent) -{ - // indiscriminately sets mContent, no ref counting here - mContent = aContent; - return NS_OK; -} - -NS_IMETHODIMP nsEditorController::SetEditor(nsIEditor *aEditor) -{ - // null editors are allowed - mEditor = aEditor; - return NS_OK; -} - - /* ======================================================================= * nsIController * ======================================================================= */ NS_IMETHODIMP nsEditorController::IsCommandEnabled(const PRUnichar *aCommand, PRBool *aResult) { - NS_ENSURE_ARG_POINTER(aCommand); - NS_ENSURE_ARG_POINTER(aResult); - - *aResult = PR_FALSE; - - nsCOMPtr<nsIEditor> editor; - NS_ENSURE_SUCCESS(GetEditor(getter_AddRefs(editor)), NS_ERROR_FAILURE); - // a null editor is a legal state - if (!editor) - return NS_OK; // just say we don't handle the command - - if (!mCommandManager) - { - NS_ASSERTION(0, "No command handler!"); - return NS_ERROR_UNEXPECTED; - } - - // find the command - nsCOMPtr<nsIControllerCommand> commandHandler; - mCommandManager->FindCommandHandler(aCommand, getter_AddRefs(commandHandler)); - - if (!commandHandler) - { -#if DEBUG - nsCAutoString msg("EditorController asked about a command that it does not handle -- "); - msg.AppendWithConversion(aCommand); - NS_WARNING(msg); -#endif - return NS_OK; // we don't handle this command - } - - return commandHandler->IsCommandEnabled(aCommand, editor, aResult); + return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult); } NS_IMETHODIMP nsEditorController::SupportsCommand(const PRUnichar *aCommand, PRBool *aResult) { - NS_ENSURE_ARG_POINTER(aCommand); - NS_ENSURE_ARG_POINTER(aResult); - - // XXX: need to check the readonly and disabled states - - *aResult = PR_FALSE; - - // find the command - nsCOMPtr<nsIControllerCommand> commandHandler; - mCommandManager->FindCommandHandler(aCommand, getter_AddRefs(commandHandler)); - - *aResult = (commandHandler.get() != NULL); - return NS_OK; + return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult); } NS_IMETHODIMP nsEditorController::DoCommand(const PRUnichar *aCommand) { - NS_ENSURE_ARG_POINTER(aCommand); - nsCOMPtr<nsIEditor> editor; - nsCOMPtr<nsISelectionController> selCont; - NS_ENSURE_SUCCESS(GetEditor(getter_AddRefs(editor)), NS_ERROR_FAILURE); - if (!editor) - { // Q: What does it mean if there is no editor? - // A: It means we've never had focus, so we can't do anything - return NS_OK; - } - - // find the command - nsCOMPtr<nsIControllerCommand> commandHandler; - mCommandManager->FindCommandHandler(aCommand, getter_AddRefs(commandHandler)); - - if (!commandHandler) - { -#if DEBUG - nsCAutoString msg("EditorController asked to do a command that it does not handle -- "); - msg.AppendWithConversion(aCommand); - NS_WARNING(msg); -#endif - return NS_OK; // we don't handle this command - } - - return commandHandler->DoCommand(aCommand, editor); + return mCommandManager->DoCommand(aCommand, mCommandRefCon); } NS_IMETHODIMP nsEditorController::OnEvent(const PRUnichar *aEventName) @@ -275,52 +212,6 @@ NS_IMETHODIMP nsEditorController::OnEvent(const PRUnichar *aEventName) return NS_OK; } - -NS_IMETHODIMP nsEditorController::GetEditor(nsIEditor ** aEditor) -{ - NS_ENSURE_ARG_POINTER(aEditor); - if (mEditor) - { - *aEditor = mEditor; - NS_ADDREF(*aEditor); - return NS_OK; - } - return NS_OK; -} - -NS_IMETHODIMP nsEditorController::GetSelectionController(nsISelectionController ** aSelCon) -{ - nsCOMPtr<nsIEditor>editor; - nsresult result = GetEditor(getter_AddRefs(editor)); - if (NS_FAILED(result) || !editor) - return result ? result : NS_ERROR_FAILURE; - - return editor->GetSelectionController(aSelCon); -} - -NS_IMETHODIMP nsEditorController::GetFrame(nsIGfxTextControlFrame **aFrame) -{ - NS_ENSURE_ARG_POINTER(aFrame); - //DEPRICATED. WILL REMOVE LATER -/* - *aFrame = nsnull; - NS_ENSURE_STATE(mContent); - - nsIFormControlFrame *frame = nsnull; - NS_ENSURE_SUCCESS( - nsGenericHTMLElement::GetPrimaryFrame(mContent, frame), - NS_ERROR_FAILURE - ); - if (!frame) { return NS_ERROR_FAILURE; } - - NS_ENSURE_SUCCESS( - frame->QueryInterface(NS_GET_IID(nsIGfxTextControlFrame), (void**)aFrame), - NS_ERROR_FAILURE - ); - */ - return NS_OK; -} - PRBool nsEditorController::IsEnabled() { return PR_TRUE; // XXX: need to implement this @@ -331,18 +222,15 @@ PRBool nsEditorController::IsEnabled() */ } -#ifdef XP_MAC -#pragma mark - -#endif -nsWeakPtr nsEditorController::sCommandManager = NULL; +nsWeakPtr nsEditorController::sEditorCommandManager = NULL; // static -nsresult nsEditorController::GetCommandManager(nsIControllerCommandManager* *outCommandManager) +nsresult nsEditorController::GetEditorCommandManager(nsIControllerCommandManager* *outCommandManager) { NS_ENSURE_ARG_POINTER(outCommandManager); - nsCOMPtr<nsIControllerCommandManager> cmdManager = do_QueryReferent(sCommandManager); + nsCOMPtr<nsIControllerCommandManager> cmdManager = do_QueryReferent(sEditorCommandManager); if (!cmdManager) { nsresult rv; @@ -354,7 +242,7 @@ nsresult nsEditorController::GetCommandManager(nsIControllerCommandManager* *out if (NS_FAILED(rv)) return rv; // save the singleton in our static weak reference - sCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv)); + sEditorCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv)); if (NS_FAILED(rv)) return rv; } @@ -363,3 +251,132 @@ nsresult nsEditorController::GetCommandManager(nsIControllerCommandManager* *out } + +#ifdef XP_MAC +#pragma mark - +#endif + +nsComposerController::nsComposerController() +{ +} + +nsComposerController::~nsComposerController() +{ +} + +NS_IMETHODIMP nsComposerController::Init(nsISupports *aCommandRefCon) +{ + nsresult rv; + + rv = nsEditorController::Init(aCommandRefCon); + if (NS_FAILED(rv)) return rv; + + // get our ref to the singleton command manager + rv = GetComposerCommandManager(getter_AddRefs(mCommandManager)); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + +#define NS_REGISTER_STYLE_COMMAND(_cmdClass, _cmdName, _styleTag) \ + { \ + _cmdClass* theCmd = new _cmdClass(_styleTag); \ + rv = RegisterOneCommand(NS_ConvertASCIItoUCS2(_cmdName).GetUnicode(), inCommandManager, theCmd); \ + } + + +// static +nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandManager *inCommandManager) +{ + nsresult rv; + + // These are composer-only commands + + // File menu + NS_REGISTER_ONE_COMMAND(nsSaveCommand, "cmd_save"); + NS_REGISTER_ONE_COMMAND(nsSaveAsCommand, "cmd_saveAs"); + NS_REGISTER_ONE_COMMAND(nsCloseCommand, "cmd_close"); + + NS_REGISTER_FIRST_COMMAND(nsPrintingCommands, "cmd_print"); + NS_REGISTER_NEXT_COMMAND(nsPrintingCommands, "cmd_printSetup"); + NS_REGISTER_LAST_COMMAND(nsPrintingCommands, "cmd_printPreview"); + + // Edit menu + NS_REGISTER_ONE_COMMAND(nsPasteQuotationCommand, "cmd_pasteQuote"); + + // indent/outdent + NS_REGISTER_ONE_COMMAND(nsIndentCommand, "cmd_indent"); + NS_REGISTER_ONE_COMMAND(nsOutdentCommand, "cmd_outdent"); + + // Styles + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_bold", "b"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_italic", "i"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_underline", "u"); + + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strikethrough", "strike"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_superscript", "sup"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_subscript", "sub"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_nobreak", "nobr"); + + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_em", "em"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strong", "strong"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_cite", "cite"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_abbr", "abbr"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_acronym", "acronym"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_code", "code"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_samp", "samp"); + NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_var", "var"); + + // lists + NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol"); + NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul"); + + // format stuff + NS_REGISTER_ONE_COMMAND(nsParagraphStateCommand, "cmd_paragraphState"); + NS_REGISTER_ONE_COMMAND(nsAlignCommand, "cmd_align"); + NS_REGISTER_ONE_COMMAND(nsRemoveStylesCommand, "cmd_removeStyles"); + NS_REGISTER_ONE_COMMAND(nsIncreaseFontSizeCommand, "cmd_increaseFont"); + NS_REGISTER_ONE_COMMAND(nsDecreaseFontSizeCommand, "cmd_decreaseFont"); + + return NS_OK; +} + + +nsWeakPtr nsComposerController::sComposerCommandManager = NULL; + +nsresult nsComposerController::GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager) +{ + NS_ENSURE_ARG_POINTER(outCommandManager); + +/* + nsCOMPtr<nsIControllerCommandManager> cmdManager = do_QueryReferent(sComposerCommandManager); + if (!cmdManager) + { + nsresult rv; + cmdManager = do_CreateInstance("component://netscape/rdf/controller-command-manager", &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; + } +*/ + // always make a new one + nsresult rv; + nsCOMPtr<nsIControllerCommandManager> cmdManager; + cmdManager = do_CreateInstance("component://netscape/rdf/controller-command-manager", &rv); + if (NS_FAILED(rv)) return rv; + + // register the commands. + rv = nsComposerController::RegisterComposerCommands(cmdManager); + 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 d2b6eff42c0..09412862636 100644 --- a/mozilla/editor/libeditor/base/nsEditorController.h +++ b/mozilla/editor/libeditor/base/nsEditorController.h @@ -23,23 +23,30 @@ #define NS_EDITORCONTROLLER_CID \ { 0x26fb965c, 0x9de6, 0x11d3, { 0xbc, 0xcc, 0x0, 0x60, 0xb0, 0xfc, 0x76, 0xbd } } +#define NS_COMPOSERCONTROLLER_CID \ +{ 0x50e95301, 0x17a8, 0x11d4, { 0x9f, 0x7e, 0xdd, 0x53, 0x0d, 0x5f, 0x05, 0x7c } } + + #include "nsIController.h" #include "nsIEditorController.h" #include "nsIControllerCommand.h" +#include "nsIInterfaceRequestor.h" #include "nsHashtable.h" #include "nsString.h" #include "nsWeakPtr.h" -class nsIHTMLContent; -class nsIGfxTextControlFrame; class nsIEditor; -class nsISelectionController; +class nsIEditorShell; class nsBaseCommand; +// 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 nsIEditorController, + public nsIInterfaceRequestor { public: @@ -53,48 +60,68 @@ public: NS_DECL_NSICONTROLLER /** init the controller */ - NS_IMETHOD Init(); - - /** set the content for this controller instance */ - NS_IMETHOD SetContent(nsIHTMLContent *aContent); - - /** set the editor for this controller. Mutually exclusive with setContent*/ - NS_IMETHOD SetEditor(nsIEditor *aEditor); + NS_IMETHOD Init(nsISupports *aCommandRefCon); + /** Set the cookie that is passed to commands + */ + NS_IMETHOD SetCommandRefCon(nsISupports *aCommandRefCon); + // nsIInterfaceRequestor + NS_DECL_NSIINTERFACEREQUESTOR + protected: - /** fetch the primary frame associated with mContent */ - NS_IMETHOD GetFrame(nsIGfxTextControlFrame **aFrame); - - /** fetch the editor associated with mContent */ - NS_IMETHOD GetEditor(nsIEditor ** aEditor); - - NS_IMETHOD GetSelectionController(nsISelectionController ** aSelCon); /** return PR_TRUE if the editor associated with mContent is enabled */ - PRBool IsEnabled(); + PRBool IsEnabled(); /* register a command */ nsresult RegisterEditorCommand(nsBaseCommand* aCommand); protected: - nsIHTMLContent* mContent; // weak reference, the content object owns this object - //if editor is null then look to mContent. this is for dual use of window and content //attached controller. - nsIEditor *mEditor; + nsISupports *mCommandRefCon; nsCOMPtr<nsIControllerCommandManager> mCommandManager; // our reference to the command manager +protected: + + static nsresult RegisterOneCommand(const PRUnichar* aCommandName, nsIControllerCommandManager *inCommandManager, nsBaseCommand* aCommand); + private: - static nsresult GetCommandManager(nsIControllerCommandManager* *outCommandManager); + static nsresult GetEditorCommandManager(nsIControllerCommandManager* *outCommandManager); static nsresult RegisterEditorCommands(nsIControllerCommandManager* inCommandManager); - static nsresult RegisterOneCommand(const PRUnichar* aCommandName, nsIControllerCommandManager *inCommandManager, nsBaseCommand* aCommand); // the singleton command manager - static nsWeakPtr sCommandManager; + static nsWeakPtr sEditorCommandManager; // common editor (i.e. text widget) commands }; + + + +// the editor controller is used for composer only (and other HTML compose +// areas). The refCon that gets passed to its commands is an nsIEditorShell. + +class nsComposerController : public nsEditorController +{ +public: + + nsComposerController(); + virtual ~nsComposerController(); + + /** init the controller */ + NS_IMETHOD Init(nsISupports *aCommandRefCon); + +protected: + +private: + + static nsresult GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager); + static nsresult RegisterComposerCommands(nsIControllerCommandManager* inCommandManager); + + // the singleton command manager + static nsWeakPtr sComposerCommandManager; // composer-specific commands (lots of them) +}; diff --git a/mozilla/editor/libeditor/build/nsEditorRegistration.cpp b/mozilla/editor/libeditor/build/nsEditorRegistration.cpp index 241a8b038ed..46c79b16a65 100644 --- a/mozilla/editor/libeditor/build/nsEditorRegistration.cpp +++ b/mozilla/editor/libeditor/build/nsEditorRegistration.cpp @@ -36,6 +36,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorShell) NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorController) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsComposerController) NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorService) #ifdef ENABLE_EDITOR_API_LOG @@ -58,8 +59,10 @@ static nsModuleComponentInfo components[] = { { "HTML Editor", NS_HTMLEDITOR_CID, "component://netscape/editor/htmleditor", nsHTMLEditorConstructor, }, #endif - { "Editor Shell Controller", NS_EDITORCONTROLLER_CID, + { "Editor Controller", NS_EDITORCONTROLLER_CID, "component://netscape/editor/editorcontroller", nsEditorControllerConstructor, }, + { "Composer Controller", NS_COMPOSERCONTROLLER_CID, + "component://netscape/editor/composercontroller", nsComposerControllerConstructor, }, { "Editor Shell Component", NS_EDITORSHELL_CID, "component://netscape/editor/editorshell", nsEditorShellConstructor, }, { "Editor Shell Spell Checker", NS_EDITORSHELL_CID, diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index f29f6489c90..daf5e9c57fe 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -1779,7 +1779,7 @@ NS_IMETHODIMP nsHTMLEditor::GetInlineProperty(nsIAtom *aProperty, iter->Init(range); nsCOMPtr<nsIContent> content; - result = iter->CurrentNode(getter_AddRefs(content)); + iter->CurrentNode(getter_AddRefs(content)); while (NS_ENUMERATOR_FALSE == iter->IsDone()) { //if (gNoisy) { printf(" checking node %p\n", content.get()); } diff --git a/mozilla/editor/public/nsIEditorController.h b/mozilla/editor/public/nsIEditorController.h index 41184d50a02..869d0b4c6e0 100644 --- a/mozilla/editor/public/nsIEditorController.h +++ b/mozilla/editor/public/nsIEditorController.h @@ -30,22 +30,22 @@ { 0x99, 0x33, 0x0, 0x10, 0x83, 0x1, 0x23, 0x3c }} -class nsIHTMLContent; class nsIEditor; +class nsCString; class nsIEditorController : public nsISupports { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IEDITORCONTROLLER_IID) - /** init the controller */ - NS_IMETHOD Init() = 0; + /** init the controller + * aCommandRefCon = a cookie that is passed to commands + */ + NS_IMETHOD Init(nsISupports *aCommandRefCon) = 0; - /** set the content for this controller instance */ - NS_IMETHOD SetContent(nsIHTMLContent *aContent) = 0; - - /** set the editor for this controller. Mutually exclusive with setContent*/ - NS_IMETHOD SetEditor(nsIEditor *aEditor) = 0; + /** Set the cookie that is passed to commands + */ + NS_IMETHOD SetCommandRefCon(nsISupports *aCommandRefCon) = 0; }; diff --git a/mozilla/editor/ui/composer/content/EditorCommands.js b/mozilla/editor/ui/composer/content/EditorCommands.js index 1efd4e04704..8f8c6b0970c 100644 --- a/mozilla/editor/ui/composer/content/EditorCommands.js +++ b/mozilla/editor/ui/composer/content/EditorCommands.js @@ -45,7 +45,7 @@ var gStyleTags = { }; const nsIFilePicker = Components.interfaces.nsIFilePicker; - + function EditorOnLoad() { // See if argument was passed. @@ -82,7 +82,7 @@ function TextEditorOnLoad() function PageIsEmptyAndUntouched() { - return (editorShell.documentIsEmpty == true) && (docWasModified == false); + return (editorShell != null) && (editorShell.documentIsEmpty == true) && (docWasModified == false); } // This is called when the real editor document is created, @@ -91,10 +91,14 @@ var DocumentStateListener = { NotifyDocumentCreated: function() { + // Call EditorSetDefaultPrefs first so it gets the default author before initing toolbars EditorSetDefaultPrefs(); - // Call EditorSetDefaultPrefs first - // so it gets the default author before initing toolbars EditorInitToolbars(); + + // udpate menu items now that we have an editor to play with + //dump("Updating 'create' commands\n"); + content.focus(); + window.updateCommands("create"); }, NotifyDocumentWillBeDestroyed: function() {}, @@ -104,6 +108,10 @@ var DocumentStateListener = another document is opened */ if (isNowDirty) docWasModified = true; + + // hack! Should not need this, but there is some controller bug that this + // works around. + window.updateCommands("create"); } }; @@ -115,11 +123,17 @@ function EditorStartup(editorType, editorElement) editorShell = editorElement.editorShell; editorShell.Init(); - editorShell.SetWebShellWindow(window); - editorShell.SetToolbarWindow(window) editorShell.SetEditorType(editorType); - editorShell.SetContentWindow(contentWindow); + editorShell.webShellWindow = window; + editorShell.contentWindow = contentWindow; + + // hide UI that we don't have components for + HideInapplicableUIElements(); + + // set up JS-implemented commands + SetupControllerCommands(); + // add a listener to be called when document is really done loading editorShell.RegisterDocumentStateListener( DocumentStateListener ); @@ -132,6 +146,8 @@ function EditorStartup(editorType, editorElement) // This still doesn't work! // It works after using a toolbar button, however! contentWindow.focus(); + // call updateCommands to disable while we're loading the page + window.updateCommands("create"); } @@ -140,6 +156,11 @@ function _EditorNotImplemented() dump("Function not implemented\n"); } +function _EditorObsolete() +{ + dump("Function is obsolete\n"); +} + function EditorShutdown() { dump("In EditorShutdown..\n"); @@ -278,56 +299,12 @@ function FindAndSelectEditorWindowWithURL(urlToMatch) function EditorOpen() { - dump("In EditorOpen..\n"); - - var fp = Components.classes["component://mozilla/filepicker"].createInstance(nsIFilePicker); - fp.init(window, editorShell.GetString("OpenHTMLFile"), nsIFilePicker.modeOpen); - - // While we include "All", include filters that prefer HTML and Text files - fp.setFilters(nsIFilePicker.filterText | nsIFilePicker.filterHTML | nsIFilePicker.filterAll); - - /* doesn't handle *.shtml files */ - try { - fp.show(); - /* need to handle cancel (uncaught exception at present) */ - } - catch (ex) { - dump("filePicker.chooseInputFile threw an exception\n"); - } - - /* check for already open window and activate it... - * note that we have to test the native path length - * since fileURL.spec will be "file:///" if no filename picked (Cancel button used) - */ - if (fp.file && fp.file.path.length > 0) { - - var found = FindAndSelectEditorWindowWithURL(fp.fileURL.spec); - if (!found) - { - // if the existing window is untouched, just load there - if (PageIsEmptyAndUntouched()) - { - editorShell.LoadUrl(fp.fileURL.spec); - } - else - { - /* open new window */ - window.openDialog("chrome://editor/content", - "_blank", - "chrome,dialog=no,all", - fp.fileURL.spec); - } - } - } + return _EditorObsolete(); } function EditorOpenRemote() { - /* The last parameter is the current browser window. - Use 0 and the default checkbox will be to load into an editor - and loading into existing browser option is removed - */ - window.openDialog( "chrome://navigator/content/openLocation.xul", "_blank", "chrome,modal", 0); + return _EditorObsolete(); } // used by openLocation. see navigator.js for additional notes. @@ -357,29 +334,32 @@ function EditorSaveDocument(doSaveAs, doSaveCopy) function EditorSave() { - dump("In EditorSave...\n"); - EditorSaveDocument(false, false) - contentWindow.focus(); + return _EditorObsolete(); } function EditorSaveAs() { - EditorSaveDocument(true, false); - contentWindow.focus(); + return _EditorObsolete(); } - function EditorPrint() { - dump("In EditorPrint..\n"); - editorShell.Print(); - contentWindow.focus(); + return _EditorObsolete(); +} + +function EditorPrintSetup() +{ + return _EditorObsolete(); +} + +function EditorPrintPreview() +{ + return _EditorObsolete(); } function EditorClose() { - dump("In EditorClose...\n"); - return editorShell.CloseWindow(); + return _EditorObsolete(); } // Check for changes to document and allow saving before closing @@ -438,18 +418,12 @@ function EditorSelectAll() function EditorFind() { - editorShell.Find(); - contentWindow.focus(); + return _EditorObsolete(); } function EditorFindNext() { - editorShell.FindNext(); -} - -function EditorShowClipboard() -{ - dump("EditorShowClipboard not implemented\n"); + return _EditorObsolete(); } // --------------------------- View menu --------------------------- @@ -497,6 +471,15 @@ function EditorSetTextProperty(property, attribute, value) contentWindow.focus(); } +/* +function EditorSelectParagraphFormat(commandID, select) +{ + content.focus(); // required hack for now + + if (select.selectedIndex != -1) + EditorSetParagraphFormat(commandID, gParagraphTagNames[select.selectedIndex]); +} +*/ function onParagraphFormatChange() { @@ -509,7 +492,7 @@ function onParagraphFormatChange() var format = select.getAttribute("format"); if ( format == "mixed") { -dump("Mixed paragraph format *******\n"); +//dump("Mixed paragraph format *******\n"); // No single type selected newIndex = -1; } @@ -529,10 +512,14 @@ dump("Mixed paragraph format *******\n"); } } -function EditorSetParagraphFormat(paraFormat) +function EditorSetParagraphFormat(commandID, paraFormat) { - editorShell.SetParagraphFormat(paraFormat); - contentWindow.focus(); + // editorShell.SetParagraphFormat(paraFormat); + var commandNode = document.getElementById(commandID); + dump("Saving para format state " + paraFormat + "\n"); + commandNode.setAttribute("state", paraFormat); + window.content.focus(); // needed for command dispatch to work + goDoCommand(commandID); } @@ -569,7 +556,7 @@ function onFontFaceChange() function EditorSetFontFace(fontFace) { - if( fontFace == "tt") { + if (fontFace == "tt") { // The old "teletype" attribute editorShell.SetTextProperty("tt", "", ""); // Clear existing font face @@ -584,14 +571,14 @@ function EditorSetFontFace(fontFace) editorShell.SetTextProperty("font", "face", fontFace); } } -dump("Setting focus to content window...\n"); +//dump("Setting focus to content window...\n"); contentWindow.focus(); } function EditorSelectFontSize() { var select = document.getElementById("FontSizeSelect"); -dump("EditorSelectFontSize: "+gFontSizeNames[select.selectedIndex]+"\n"); +//dump("EditorSelectFontSize: "+gFontSizeNames[select.selectedIndex]+"\n"); if (select) { if (select.selectedIndex == -1) @@ -679,20 +666,18 @@ function EditorSetFontSize(size) function EditorIncreaseFontSize() { - editorShell.IncreaseFontSize(); - contentWindow.focus(); + return _EditorObsolete(); } function EditorDecreaseFontSize() { - editorShell.DecreaseFontSize(); - contentWindow.focus(); + return _EditorObsolete(); } function EditorSelectTextColor(ColorPickerID, ColorWellID) { var color = getColorAndSetColorWell(ColorPickerID, ColorWellID); -dump("EditorSelectTextColor: "+color+"\n"); +// dump("EditorSelectTextColor: "+color+"\n"); // Close appropriate menupopup var menupopup; @@ -771,8 +756,7 @@ function EditorApplyStyle(tagName) function EditorRemoveStyle(tagName) { - editorShell.RemoveTextProperty(tagName, ""); - contentWindow.focus(); + return _EditorObsolete(); } function EditorToggleStyle(styleName) @@ -825,17 +809,17 @@ function GetSelectedElementOrParentCell() function EditorObjectProperties() { var element = GetSelectedElementOrParentCell(); - dump("EditorObjectProperties: element="+element+"\n"); + // dump("EditorObjectProperties: element="+element+"\n"); if (element) { - dump("TagName="+element.nodeName+"\n"); + // dump("TagName="+element.nodeName+"\n"); switch (element.nodeName) { case 'IMG': - EditorInsertOrEditImage(); + goDoCommand("cmd_image"); break; case 'HR': - EditorInsertOrEditHLine(); + goDoCommand("cmd_hline"); break; case 'TABLE': EditorInsertOrEditTable(false); @@ -845,188 +829,81 @@ function EditorObjectProperties() break; case 'A': if(element.href) - EditorInsertOrEditLink(); + goDoCommand("cmd_link"); else if (element.name) - EditorInsertOrEditNamedAnchor(); + goDoCommand("cmd_anchor"); break; } } else { // We get a partially-selected link if asked for specifically element = editorShell.GetSelectedElement("href"); if (element) - EditorInsertOrEditLink(); + goDoCommand("cmd_link"); } } function EditorListProperties() { - window.openDialog("chrome://editor/content/EdListProps.xul","_blank", "chrome,close,titlebar,modal"); - contentWindow.focus(); + return _EditorObsolete(); } function EditorPageProperties() { - window.openDialog("chrome://editor/content/EdPageProps.xul","_blank", "chrome,close,titlebar,modal,resizable", ""); - contentWindow.focus(); + return _EditorObsolete(); } function EditorColorProperties() { - window.openDialog("chrome://editor/content/EdColorProps.xul","_blank", "chrome,close,titlebar,modal", ""); - contentWindow.focus(); + return _EditorObsolete(); } // --------------------------- Dialogs --------------------------- function EditorInsertHTML() { - // Resizing doesn't work! - window.openDialog("chrome://editor/content/EdInsSrc.xul","_blank", "chrome,close,titlebar,modal,resizable"); - contentWindow.focus(); + return _EditorObsolete(); } function EditorInsertOrEditLink() { - window.openDialog("chrome://editor/content/EdLinkProps.xul","_blank", "chrome,close,titlebar,modal"); - contentWindow.focus(); + return _EditorObsolete(); } function EditorInsertOrEditImage() { - window.openDialog("chrome://editor/content/EdImageProps.xul","_blank", "chrome,close,titlebar,modal"); - contentWindow.focus(); + return _EditorObsolete(); } function EditorInsertOrEditHLine() { - // Inserting an HLine is different in that we don't use properties dialog - // unless we are editing an existing line's attributes - // We get the last-used attributes from the prefs and insert immediately - - tagName = "hr"; - hLine = editorShell.GetSelectedElement(tagName); - - if (hLine) { - dump("HLine was found -- opening dialog...!\n"); - - // We only open the dialog for an existing HRule - window.openDialog("chrome://editor/content/EdHLineProps.xul", "_blank", "chrome,close,titlebar,modal"); - } else { - hLine = editorShell.CreateElementWithDefaults(tagName); - - if (hLine) { - // We change the default attributes to those saved in the user prefs - var prefs = Components.classes['component://netscape/preferences']; - if (prefs) { - prefs = prefs.getService(); - } - if (prefs) { - prefs = prefs.QueryInterface(Components.interfaces.nsIPref); - } - if (prefs) { - dump(" We found the Prefs Service\n"); - var percent; - var height; - var shading; - var ud = "undefined"; - - try { - var align = prefs.GetIntPref("editor.hrule.align"); - dump("Align pref: "+align+"\n"); - if (align == 0 ) { - hLine.setAttribute("align", "left"); - } else if (align == 2) { - hLine.setAttribute("align", "right"); - } else { - // Default is center - hLine.setAttribute("align", "center"); - } - - var width = prefs.GetIntPref("editor.hrule.width"); - var percent = prefs.GetBoolPref("editor.hrule.width_percent"); - dump("Width pref: "+width+", percent:"+percent+"\n"); - if (percent) - width = width +"%"; - - hLine.setAttribute("width", width); - - var height = prefs.GetIntPref("editor.hrule.height"); - dump("Size pref: "+height+"\n"); - hLine.setAttribute("size", String(height)); - - var shading = prefs.GetBoolPref("editor.hrule.shading"); - dump("Shading pref:"+shading+"\n"); - if (shading) { - hLine.removeAttribute("noshade"); - } else { - hLine.setAttribute("noshade", ""); - } - } - catch (ex) { - dump("failed to get HLine prefs\n"); - } - } - try { - editorShell.InsertElementAtSelection(hLine, true); - } catch (e) { - dump("Exception occured in InsertElementAtSelection\n"); - } - } - } - contentWindow.focus(); -} + return _EditorObsolete();} function EditorInsertChars() { - window.openDialog("chrome://editor/content/EdInsertChars.xul", "_blank", "chrome,close,titlebar", ""); - contentWindow.focus(); + return _EditorObsolete(); } function EditorInsertOrEditNamedAnchor() { - window.openDialog("chrome://editor/content/EdNamedAnchorProps.xul", "_blank", "chrome,close,titlebar,modal", ""); - contentWindow.focus(); + return _EditorObsolete(); } function EditorIndent(indent) { - dump(indent+"\n"); - editorShell.Indent(indent); - contentWindow.focus(); + return _EditorObsolete(); } function EditorMakeOrChangeList(listType) { - // check the observer node, - // which is the appropriate button - var theButton = document.getElementById(listType + "Button"); - - if (theButton) - { - var buttonFormat = theButton.getAttribute("format"); - var isOn = (listType == buttonFormat); - - if (isOn == 1) - { - editorShell.RemoveList(listType); - } - else - { - editorShell.MakeOrChangeList(listType); - } - - contentWindow.focus(); - } - else - { - dump("No button found for the " + listType + " style\n"); - } + return _EditorObsolete(); } -function EditorAlign(align) +function EditorAlign(commandID, alignType) { - editorShell.Align(align); - contentWindow.focus(); + var commandNode = document.getElementById(commandID); + // dump("Saving para format state " + alignType + "\n"); + commandNode.setAttribute("state", alignType); + goDoCommand(commandID); } function EditorSetDisplayMode(mode) @@ -1043,11 +920,6 @@ function EditorSetDisplayMode(mode) contentWindow.focus(); } -function EditorEditHTML() -{ - dump("EditorEditHTML NOT IMPLEMENTED\n"); -} - function EditorToggleParagraphMarks() { var menuItem = document.getElementById("viewParagraphMarks"); @@ -1071,78 +943,12 @@ function EditorToggleParagraphMarks() function EditorPreview() { - if (!editorShell.CheckAndSaveDocument(editorShell.GetString("BeforePreview"))) - return; - - fileurl = ""; - try { - fileurl = window.content.location; - } catch (e) { - return; - } - - // CheckAndSave doesn't tell us if the user said "Don't Save", - // so make sure we have a url: - if (fileurl != "" && fileurl != "about:blank") { - window.openDialog(getBrowserURL(), - "EditorPreview", - "chrome,all,dialog=no", - fileurl ); - } -} - -function EditorPrintSetup() -{ - // Old code? Browser no longer is doing this - //window.openDialog("resource:/res/samples/printsetup.html", "_blank", "chrome,close,titlebar", ""); - _EditorNotImplemented(); - contentWindow.focus(); -} - -function EditorPrintPreview() -{ - _EditorNotImplemented(); - contentWindow.focus(); + return _EditorObsolete(); } function CheckSpelling() { - var spellChecker = editorShell.QueryInterface(Components.interfaces.nsIEditorSpellCheck); - if (spellChecker) - { - dump("Check Spelling starting...\n"); - // Start the spell checker module. Return is first misspelled word - try { - firstMisspelledWord = spellChecker.StartSpellChecking(); - } - catch(ex) { - dump("*** Exception error: StartSpellChecking\n"); - return; - } - if( firstMisspelledWord == "") - { - try { - spellChecker.CloseSpellChecking(); - } - catch(ex) { - dump("*** Exception error: CloseSpellChecking\n"); - return; - } - // No misspelled word - tell user - editorShell.AlertWithTitle(editorShell.GetString("CheckSpelling"), editorShell.GetString("NoMisspelledWord")); - } else { - // Set spellChecker variable on window - window.spellChecker = spellChecker; - try { - window.openDialog("chrome://editor/content/EdSpellCheck.xul", "_blank", "chrome,close,titlebar,modal", "", firstMisspelledWord); - } - catch(ex) { - dump("*** Exception error: SpellChecker Dialog Closing\n"); - return; - } - } - } - contentWindow.focus(); + return _EditorObsolete(); } function SetBackColorString(xulElementID) @@ -1499,23 +1305,56 @@ function EditorSetSelectionFromOffsets(selRanges) function EditorExit() { - dump("Exiting in EditorExit\n"); - // This is in globalOverlay.js - goQuitApplication(); + return _EditorObsolete(); } + +//-------------------------------------------------------------------- +function initFontStyleMenu(menuPopup) +{ + for (var i = 0; i < menuPopup.childNodes.length; i++) + { + var menuItem = menuPopup.childNodes[i]; + var theStyle = menuItem.getAttribute("state"); + if (theStyle) + { + menuItem.setAttribute("checked", theStyle); + } + } +} + +//-------------------------------------------------------------------- +function onButtonUpdate(button, commmandID) +{ + var commandNode = document.getElementById(commmandID); + var state = commandNode.getAttribute("state"); + + button.setAttribute("toggled", state); +} + + // --------------------------- Status calls --------------------------- function onStyleChange(theStyle) { + dump("in onStyleChange with " + theStyle + "\n"); + + var broadcaster = document.getElementById("cmd_" + theStyle); + var isOn = broadcaster.getAttribute("state"); + + // PrintObject(broadcaster); + var theButton = document.getElementById(theStyle + "Button"); if (theButton) { - var isOn = theButton.getAttribute(theStyle); - if (isOn == "true") { - theButton.setAttribute("toggled", 1); - } else { - theButton.setAttribute("toggled", 0); - } + // dump("setting button to " + isOn + "\n"); + theButton.setAttribute("toggled", (isOn == "true") ? 1 : 0); + } + + var theMenuItem = document.getElementById(theStyle + "MenuItem"); + if (theMenuItem) + { + // dump("setting menuitem to " + isOn + "\n"); + theMenuItem.setAttribute("checked", isOn); } } @@ -1540,11 +1379,11 @@ function onListFormatChange(listType) var theButton = document.getElementById(listType + "Button"); if (theButton) { - var listFormat = theButton.getAttribute("format"); - if (listFormat == listType) { - theButton.setAttribute("toggled", 1); + var isOn = theButton.getAttribute(listType); + if (isOn == "true") { + theButton.setAttribute("toggled", "true"); } else { - theButton.setAttribute("toggled", 0); + theButton.setAttribute("toggled", "false"); } } } @@ -1558,7 +1397,6 @@ function getColorAndSetColorWell(ColorPickerID, ColorWellID) var colorPicker = document.getElementById(ColorPickerID); if (colorPicker) { -dump("ColorPicker found\n"); // Extract color from colorPicker and assign to colorWell. var color = colorPicker.getAttribute('color'); dump("setColor to: "+color+"\n"); @@ -1704,3 +1542,39 @@ function EditorDeleteTableCellContents() contentWindow.focus(); } +var gHaveSpellChecker = false; +var gSoughtSpellChecker = false; + +//----------------------------------------------------------------------------------- +function IsSpellCheckerInstalled() +{ + return true; // fix me when kin checks in + + if (gSoughtSpellChecker) + return gHaveSpellChecker; + + var spellcheckerClass = Components.classes["org.mozilla.spellchecker.1"]; + gHaveSpellChecker = (spellcheckerClass != null); + gSoughtSpellChecker = true; + return gHaveSpellChecker; +} + +//----------------------------------------------------------------------------------- +function HideInapplicableUIElements() +{ + // if no spell checker, remove spell checker ui + if (!IsSpellCheckerInstalled()) + { + dump("Hiding spell checker items\n"); + + var spellingButton = document.getElementById("spellingButton"); + if (spellingButton) + spellingButton.setAttribute("hidden", "true"); + + var spellingMenuItem = document.getElementById("menu_checkspelling"); + if (spellingMenuItem) + spellingMenuItem.setAttribute("hidden", "true"); + } + +} + diff --git a/mozilla/editor/ui/composer/content/EditorCommandsDebug.js b/mozilla/editor/ui/composer/content/EditorCommandsDebug.js index 86d85929a1c..ca79e6a9095 100644 --- a/mozilla/editor/ui/composer/content/EditorCommandsDebug.js +++ b/mozilla/editor/ui/composer/content/EditorCommandsDebug.js @@ -29,7 +29,7 @@ function EditorGetText() if (editorShell) { dump("Getting text\n"); var outputText = editorShell.GetContentsAs("text/plain", 2); - dump(outputText + "\n"); + dump("<<" + outputText + ">>\n"); } } diff --git a/mozilla/editor/ui/composer/content/editor.xul b/mozilla/editor/ui/composer/content/editor.xul index 6fba1122c27..ad92181a370 100644 --- a/mozilla/editor/ui/composer/content/editor.xul +++ b/mozilla/editor/ui/composer/content/editor.xul @@ -48,14 +48,21 @@ persist="screenX screenY width height" > - <script language="JavaScript" src="chrome://editor/content/EditorCommands.js"/> - <script language="JavaScript" src="chrome://editor/content/EditorCommandsDebug.js"/> - <script language="javascript" src="chrome://global/content/strres.js"/> + <html:script language="JavaScript" src="chrome://editor/content/EditorCommands.js"/> + <html:script language="JavaScript" src="chrome://editor/content/ComposerCommands.js"/> + <!-- fix mailnews and AIM --> + <html:script language="JavaScript" src="chrome://editor/content/EditorCommandsDebug.js"/> + <html:script language="javascript" src="chrome://global/content/strres.js"/> <commands id="commands"> <commandset id="globalEditMenuItems"/> <commandset id="selectEditMenuItems"/> <commandset id="undoEditMenuItems"/> + + <commandset id="composerMenuItems"/> + <commandset id="composerEditMenuItems"/> + <commandset id="composerSaveMenuItems"/> + <commandset id="composerStyleMenuItems"/> </commands> <!-- Use this when we abandon the default startup page --> @@ -67,7 +74,7 @@ <broadcaster id="dialog.start" ready="false"/> <observes element="dialog.start" attribute="ready" onbroadcast="EditorStartup('html')"/> - <!-- broadcaster nodes are appended here from the overlays --> + <!-- command nodes are appended here from the overlays --> <broadcasterset id="broadcasterset"> <broadcaster id="Editor:Throbber" busy="false"/> </broadcasterset> diff --git a/mozilla/editor/ui/composer/content/editorOverlay.xul b/mozilla/editor/ui/composer/content/editorOverlay.xul index d117a316c30..c5b9031ce69 100644 --- a/mozilla/editor/ui/composer/content/editorOverlay.xul +++ b/mozilla/editor/ui/composer/content/editorOverlay.xul @@ -40,12 +40,12 @@ <key id="key_newMessage"/> <key id="key_newBlankPage"/> - <key id="openeditorkb" xulkey="true" key="&fileopen.keybinding;" observes="Editor:Open" /> - <key id="openremoteeditorkb" xulkey="true" key="&fileopenremote.keybinding;" onkeypress="EditorOpenRemote()" /> - <key id="savekb" xulkey="true" key="&filesave.keybinding;" observes="Editor:Save"/> - <key id="closekb" xulkey="true" key="&fileclose.keybinding;" observes="Editor:Close" /> - <key id="printkb" xulkey="true" key="&fileprint.keybinding;" observes="Editor:Print" /> - <key id="exitkb" xulkey="true" key="&fileexit.keybinding;" observes="Editor:Exit" /> + <key id="openeditorkb" xulkey="true" key="&fileopen.keybinding;" observes="cmd_open" /> + <key id="openremoteeditorkb" xulkey="true" key="&fileopenremote.keybinding;" observes="cmd_openRemote" /> + <key id="savekb" xulkey="true" key="&filesave.keybinding;" observes="cmd_save"/> + <key id="closekb" xulkey="true" key="&fileclose.keybinding;" observes="cmd_close" /> + <key id="printkb" xulkey="true" key="&fileprint.keybinding;" observes="cmd_print" /> + <key id="exitkb" xulkey="true" key="&fileexit.keybinding;" observes="cmd_quit" /> <key id="key_undo"/> <key id="key_redo"/> @@ -55,99 +55,165 @@ <key id="pastequotationkb" xulkey="true" shift="true" key="&editpaste.keybinding;" observes="cmd_pasteQuote" /> <key id="key_delete"/> <key id="key_selectAll"/> - <key id="findkb" xulkey="true" key="&editfind.keybinding;" observes="cmd_find" /> + <key id="findkb" xulkey="true" key="&editfind.keybinding;" observes="cmd_find" /> <key id="findnextkb" xulkey="true" key="&editfindnext.keybinding;" observes="cmd_findNext" /> - <key id="checkspellingkb" xulkey="true" key="&editcheckspelling.keybinding;" observes="cmd_checkSpelling" /> + <key id="checkspellingkb" xulkey="true" key="&editcheckspelling.keybinding;" observes="cmd_spelling" /> <key id="key_preferences"/> - <key id="boldkb" xulkey="true" key="&stylebold.keybinding;" observes="Editor:Bold"/> - <key id="italickb" xulkey="true" key="&styleitalic.keybinding;" observes="Editor:Italic"/> + <key id="boldkb" xulkey="true" key="&stylebold.keybinding;" observes="cmd_bold"/> + <key id="italickb" xulkey="true" key="&styleitalic.keybinding;" observes="cmd_italic"/> <key id="underlinekb" xulkey="true" key="&styleunderline.keybinding;" onkeypress="EditorToggleStyle('underline')"/> <!-- these should come from tasksOverlay.xul --> <key id="navigatortaskkb" xulkey="true" key="1" onkeypress="Navigator()" /> - <key id="messengerkb" xulkey="true" key="2" onkeypress="Messenger()" /> - <key id="composerkb" xulkey="true" key="3" onkeypress="Composer()" /> - <key id="calendarkb" xulkey="true" key="4" onkeypress="Calendar()" /> + <key id="messengerkb" xulkey="true" key="2" onkeypress="Messenger()" /> + <key id="composerkb" xulkey="true" key="3" onkeypress="Composer()" /> + <key id="calendarkb" xulkey="true" key="4" onkeypress="Calendar()" /> - <key id="increaseindentkb" xulkey="true" key="&formatindent.keybinding;" onkeypress="EditorIndent('indent')" /> - <key id="decreaseindentkb" xulkey="true" key="&formatoutdent.keybinding;" onkeypress="EditorIndent('outdent')" /> + <key id="increaseindentkb" xulkey="true" key="&formatindent.keybinding;" observes="cmd_indent" /> + <key id="decreaseindentkb" xulkey="true" key="&formatoutdent.keybinding;" observes="cmd_outdent" /> - <key id="removestyleskb" shift="true" xulkey="true" key="&formatremovestyles.keybinding;" onkeypress="EditorRemoveStyle('all')" /> - <key id="decreasefontsizekb" shift="true" xulkey="true" key="&decreaseFontSize.keybinding;" onkeypress="EditorDecreaseFontSize()" /> - <key id="increasefontsizekb" shift="true" xulkey="true" key="&increaseFontSize.keybinding;" onkeypress="EditorIncreaseFontSize()" /> + <key id="removestyleskb" shift="true" xulkey="true" key="&formatremovestyles.keybinding;" observes="cmd_removeStyles" /> + <key id="decreasefontsizekb" shift="true" xulkey="true" key="&decreaseFontSize.keybinding;" observes="cmd_decreaseFont" /> + <key id="increasefontsizekb" shift="true" xulkey="true" key="&increaseFontSize.keybinding;" observes="cmd_increaseFont" /> </keyset> - <broadcasterset id="broadcasterset"> - <!-- Complete broadcasters located in globalOverlay.xul --> - <!-- File Menu --> - <broadcaster id="cmd_newNavigator"/> - <broadcaster id="cmd_newMessage"/> - <broadcaster id="cmd_newCard"/> - <broadcaster id="cmd_newEditor"/> - <broadcaster id="cmd_newEditorTemplate"/> - <broadcaster id="cmd_newEditorDraft"/> - <broadcaster id="cmd_sendPage"/> + <!-- commands updated when the editor gets created --> + <commandset id="composerMenuItems" + commandupdater="true" + events="create" + oncommandupdate="goUpdateComposerMenuItems(this)" + > + <command id="cmd_newNavigator"/> + <command id="cmd_newMessage"/> + <command id="cmd_newCard"/> + <command id="cmd_newEditor"/> + <command id="cmd_newEditorTemplate"/> + <command id="cmd_newEditorDraft"/> + <command id="cmd_sendPage"/> - <!-- Edit Menu --> - <broadcaster id="cmd_undo"/> - <broadcaster id="cmd_redo"/> - <broadcaster id="cmd_cut"/> - <broadcaster id="cmd_copy"/> - <broadcaster id="cmd_paste"/> + <command id="cmd_open" oncommand="goDoCommand('cmd_open')"/> + <command id="cmd_openRemote" value="&openremoteCmd.label;" oncommand="goDoCommand('cmd_openRemote')"/> + <command id="cmd_close" value="&closeCmd.label;" oncommand="goDoCommand('cmd_close')"/> - <broadcaster id="cmd_delete"/> - <broadcaster id="cmd_selectAll"/> - <broadcaster id="cmd_preferences"/> + <command id="cmd_save" value="&saveCmd.label;" oncommand="goDoCommand('cmd_save')"/> + <command id="cmd_saveAs" value="&saveAsCmd.label;" oncommand="goDoCommand('cmd_saveAs')"/> - <broadcaster id="cmd_find" value="&findCmd.label;" oncommand="EditorFind()"/> - <broadcaster id="cmd_findNext" value="&findAgainCmd.label;" oncommand="EditorFindNext()"/> - <broadcaster id="cmd_checkSpelling" value="&checkSpellingCmd.label;" oncommand="CheckSpelling()"/> - <broadcaster id="cmd_pasteQuote" value="&pasteAsQuotationCmd.label;" oncommand="goDoCommand('cmd_pasteQuote')"/> - - - <!-- Formatting-related commands --> - <broadcaster id="Editor:Bold" bold="false" oncommand="EditorToggleStyle('bold')"/> - <broadcaster id="Editor:Italic" italic="false" oncommand="EditorToggleStyle('italic')"/> - <broadcaster id="Editor:Underline" underline="false" oncommand="EditorToggleStyle('underline')"/> + <command id="cmd_printSetup" value="&printSetupCmd.label;" oncommand="goDoCommand('cmd_printSetup')"/> + <command id="cmd_printPreview" value="&printPreviewCmd.label;" oncommand="goDoCommand('cmd_printPreview')"/> + <command id="cmd_print" oncommand="goDoCommand('cmd_print')"/> + + <command id="cmd_quit" value="&exitCmd.label;" oncommand="goQuitApplication()"/> + + <!-- view menu --> + <command id="cmd_viewCompToolbar" oncommand="goToggleToolbar('EditToolbar','cmd_viewCompToolbar');" checked="true"/> + <command id="cmd_viewFormatToolbar" oncommand="goToggleToolbar('FormatToolbar','cmd_viewFormatToolbar');" checked="true"/> + <command id="cmd_viewEditModeToolbar" oncommand="goToggleToolbar('EditModeToolbar','cmd_viewEditModeToolbar');" checked="true"/> + <command id="cmd_viewtaskbar" oncommand="goToggleToolbar('taskbar','cmd_viewtaskbar');" checked="true"/> + + <!-- format menu --> + <command id="cmd_listProperties" oncommand="goDoCommand('cmd_listProperties')"/> + <command id="cmd_pageProperties" oncommand="goDoCommand('cmd_pageProperties')"/> + <command id="cmd_colorProperties" oncommand="goDoCommand('cmd_colorProperties')"/> + + <command id="cmd_link" value="&insertLinkCmd.label;" oncommand="goDoCommand('cmd_link')"/> + <command id="cmd_anchor" value="&insertAnchorCmd.label;" oncommand="goDoCommand('cmd_anchor')"/> + <command id="cmd_insertChars" value="&insertCharsCmd.label;" oncommand="goDoCommand('cmd_insertChars')"/> + <command id="cmd_image" value="&insertImageCmd.label;" oncommand="goDoCommand('cmd_image')"/> + <command id="cmd_hline" value="&insertHLineCmd.label;" oncommand="goDoCommand('cmd_hline')"/> + <command id="cmd_table" value="&insertTableCmd.label;" oncommand="goDoCommand('cmd_table')"/> + <command id="cmd_editTable" oncommand="goDoCommand('cmd_editTable')"/> + <command id="cmd_insertHTML" value="&HTMLSourceCmd.label;" oncommand="goDoCommand('cmd_insertHTML')"/> + <command id="cmd_editHTML" value="&HTMLSourceCmd.label;" oncommand="goDoCommand('cmd_editHTML')"/> + <command id="cmd_insertBreak" value="&insertLineBreakCmd.label;" oncommand="goDoCommand('cmd_insertBreak')"/> + <command id="cmd_insertBreakAll" value="&insertBreakBelowImagesCmd.label;" oncommand="goDoCommand('cmd_insertBreakAll')"/> + + </commandset> - <broadcaster id="Editor:Paragraph:Format" format=""/> - <broadcaster id="Editor:Paragraph:ListType" format=""/> - <broadcaster id="Editor:Font:Face" face=""/> - <broadcaster id="Editor:Font:Size" fontsize=""/> + <commandset id="composerSaveMenuItems" + commandupdater="true" + events="create, save" + oncommandupdate="goUpdateComposerMenuItems(this)" + > + <command id="cmd_save" value="&saveCmd.label;" oncommand="goDoCommand('cmd_save')"/> + <command id="cmd_saveAs" value="&saveAsCmd.label;" oncommand="goDoCommand('cmd_saveAs')"/> - <!-- Command Broadcaster nodes --> - <!-- Don't set value on items whose text should be different for different observers --> - <broadcaster id="Editor:Open" oncommand="EditorOpen()"/> - <broadcaster id="Editor:Save" value="&saveCmd.label;" oncommand="EditorSave()" disabled="true"/> - <broadcaster id="Editor:SaveAs" value="&saveAsCmd.label;" oncommand="EditorSaveAs()"/> - <broadcaster id="Editor:Preview" oncommand="EditorPreview()"/> - <broadcaster id="Editor:Close" value="&closeCmd.label;" oncommand="EditorClose()"/> - <broadcaster id="Editor:PrintSetup" value="&printSetupCmd.label;" oncommand="EditorPrintSetup()" disabled="true"/> - <broadcaster id="Editor:PrintPreview" value="&printPreviewCmd.label;" oncommand="EditorPrintPreview()" disabled="true"/> - <broadcaster id="Editor:Print" oncommand="EditorPrint()"/> - <broadcaster id="Editor:Exit" value="&exitCmd.label;" oncommand="goQuitApplication()"/> + <command id="cmd_preview" oncommand="goDoCommand('cmd_preview')"/> + </commandset> + + + <!-- edit menu commands. These get updated by code in globalOverlay.js --> + <commandset id="composerEditMenuItems" + commandupdater="true" + events="create" + oncommandupdate="goUpdateComposerMenuItems(this)" + > + <command id="cmd_undo"/> + <command id="cmd_redo"/> + <command id="cmd_cut"/> + <command id="cmd_copy"/> + <command id="cmd_paste"/> + <command id="cmd_delete"/> + <command id="cmd_selectAll"/> + + <command id="cmd_preferences"/> + + <command id="cmd_find" value="&findCmd.label;" oncommand="goDoCommand('cmd_find')"/> + <command id="cmd_findNext" value="&findAgainCmd.label;" oncommand="goDoCommand('cmd_findNext')"/> + <command id="cmd_spelling" value="&checkSpellingCmd.label;" oncommand="goDoCommand('cmd_spelling')"/> + <command id="cmd_pasteQuote" value="&pasteAsQuotationCmd.label;" oncommand="goDoCommand('cmd_pasteQuote')"/> + + </commandset> + + <!-- style related commands that update on creation, and on selection change --> + <commandset id="composerStyleMenuItems" + commandupdater="true" + events="create, style" + oncommandupdate="goUpdateComposerMenuItems(this)" + > + <command id="cmd_bold" state="false" oncommand="goDoCommand('cmd_bold')"/> + <command id="cmd_italic" state="false" oncommand="goDoCommand('cmd_italic')"/> + <command id="cmd_underline" state="false" oncommand="goDoCommand('cmd_underline')"/> + + <command id="cmd_strikethrough" state="false" oncommand="goDoCommand('cmd_strikethrough')"/> + <command id="cmd_superscript" state="false" oncommand="goDoCommand('cmd_superscript')"/> + <command id="cmd_subscript" state="false" oncommand="goDoCommand('cmd_subscript')"/> + <command id="cmd_nobreak" state="false" oncommand="goDoCommand('cmd_nobreak')"/> + + <command id="cmd_em" state="false" oncommand="goDoCommand('cmd_em')"/> + <command id="cmd_strong" state="false" oncommand="goDoCommand('cmd_strong')"/> + <command id="cmd_cite" state="false" oncommand="goDoCommand('cmd_cite')"/> + <command id="cmd_abbr" state="false" oncommand="goDoCommand('cmd_abbr')"/> + <command id="cmd_acronym" state="false" oncommand="goDoCommand('cmd_acronym')"/> + <command id="cmd_code" state="false" oncommand="goDoCommand('cmd_code')"/> + <command id="cmd_samp" state="false" oncommand="goDoCommand('cmd_samp')"/> + <command id="cmd_var" state="false" oncommand="goDoCommand('cmd_var')"/> + + <command id="cmd_ul" state="false" oncommand="goDoCommand('cmd_ul')"/> + <command id="cmd_ol" state="false" oncommand="goDoCommand('cmd_ol')"/> + + <command id="cmd_indent" oncommand="goDoCommand('cmd_indent')"/> + <command id="cmd_outdent" oncommand="goDoCommand('cmd_outdent')"/> + + <!-- the state attribute gets filled with the paragraph format before the command is exectued --> + <command id="cmd_paragraphState" state="" oncommand="goDoCommand('cmd_paragraphState')"/> + <command id="cmd_align" state="" oncommand="goDoCommand('cmd_align')"/> - <!-- need to toggle the menu item text through style --> - <broadcaster id="cmd_viewCompToolbar" oncommand="goToggleToolbar('EditToolbar','cmd_viewCompToolbar');" checked="true"/> - <broadcaster id="cmd_viewFormatToolbar" oncommand="goToggleToolbar('FormatToolbar','cmd_viewFormatToolbar');" checked="true"/> - <broadcaster id="cmd_viewEditModeToolbar" oncommand="goToggleToolbar('EditModeToolbar','cmd_viewEditModeToolbar');" checked="true"/> - <broadcaster id="cmd_viewtaskbar" oncommand="goToggleToolbar('taskbar','cmd_viewtaskbar');" checked="true"/> + <command id="cmd_increaseFont" oncommand="goDoCommand('cmd_increaseFont')"/> + <command id="cmd_decreaseFont" oncommand="goDoCommand('cmd_decreaseFont')"/> + + <command id="cmd_removeStyles" oncommand="goDoCommand('cmd_removeStyles')"/> + </commandset> - <broadcaster id="Editor:InsertLink" value="&insertLinkCmd.label;" oncommand="EditorInsertOrEditLink()"/> - <broadcaster id="Editor:InsertAnchor" value="&insertAnchorCmd.label;" oncommand="EditorInsertOrEditNamedAnchor()"/> - <broadcaster id="Editor:InsertChars" value="&insertCharsCmd.label;" oncommand="EditorInsertChars()"/> - <broadcaster id="Editor:InsertImage" value="&insertImageCmd.label;" oncommand="EditorInsertOrEditImage()"/> - <broadcaster id="Editor:InsertHLine" value="&insertHLineCmd.label;" oncommand="EditorInsertOrEditHLine()"/> - <broadcaster id="Editor:InsertTable" value="&insertTableCmd.label;" oncommand="EditorInsertTable()"/> - <broadcaster id="Editor:InsertHTML" value="&HTMLSourceCmd.label;" oncommand="EditorInsertHTML()"/> - <broadcaster id="Editor:EditHTML" value="&HTMLSourceCmd.label;" oncommand="EditorEditHTML()"/> - <broadcaster id="Editor:InsertBreak" value="&insertLineBreakCmd.label;" oncommand="_EditorNotImplemented()" disabled="true"/> - <broadcaster id="Editor:InsertBreakAll" value="&insertBreakBelowImagesCmd.label;" oncommand="_EditorNotImplemented()" disabled="true"/> - <broadcaster id="cmd_preferences"/> + + <broadcasterset id="broadcasterset"> + <!-- Obsolete; these will go away --> + + <command id="Editor:Font:Face" face=""/> + <command id="Editor:Font:Size" fontsize=""/> </broadcasterset> <!-- Editor menu items --> @@ -168,22 +234,22 @@ <menuitem id="menu_newCard" observes="cmd_newCard"/> </menupopup> </menu> - <menuitem accesskey="&fileopenremote.accesskey;" value="&openremoteCmd.label;" key="openremoteeditorkb" oncommand="EditorOpenRemote()"/> - <menuitem accesskey="&fileopen.accesskey;" key="openeditorkb" observes="Editor:Open" value="&openFileCmd.label;"/> + <menuitem accesskey="&fileopenremote.accesskey;" key="openremoteeditorkb" observes="cmd_openRemote"/> + <menuitem accesskey="&fileopen.accesskey;" key="openeditorkb" observes="cmd_open" value="&openFileCmd.label;"/> <menuseparator /> - <menuitem accesskey="&fileclose.accesskey;" key="closekb" observes="Editor:Close"/> - <menuitem accesskey="&filesave.accesskey;" key="savekb" observes="Editor:Save"/> - <menuitem accesskey="&filesaveas.accesskey;" observes="Editor:SaveAs"/> + <menuitem accesskey="&fileclose.accesskey;" key="closekb" observes="cmd_close"/> + <menuitem accesskey="&filesave.accesskey;" key="savekb" observes="cmd_save"/> + <menuitem accesskey="&filesaveas.accesskey;" observes="cmd_saveAs"/> <menuseparator /> <!-- FRAME, LINK should go here, but nav must put them in global files --> <menuitem id="menu_sendPage" observes="cmd_sendPage"/> - <menuitem accesskey="&filepreview.accesskey;" observes="Editor:Preview" value="&previewCmd.label;"/> + <menuitem accesskey="&filepreview.accesskey;" observes="cmd_preview" value="&previewCmd.label;"/> <menuseparator /> - <menuitem accesskey="&fileprintsetup.accesskey;" observes="Editor:PrintSetup" /> - <menuitem accesskey="&fileprintpreview.accesskey;" observes="Editor:PrintPreview"/> - <menuitem accesskey="&fileprint.accesskey;" key="printkb" observes="Editor:Print" value="&printCmd.label;"/> + <menuitem accesskey="&fileprintsetup.accesskey;" observes="cmd_printSetup" /> + <menuitem accesskey="&fileprintpreview.accesskey;" observes="cmd_printPreview"/> + <menuitem accesskey="&fileprint.accesskey;" key="printkb" observes="cmd_print" value="&printCmd.label;"/> <menuseparator /> - <menuitem accesskey="&fileexit.accesskey;" key="exitkb" observes="Editor:Exit"/> + <menuitem accesskey="&fileexit.accesskey;" key="exitkb" observes="cmd_quit"/> </menupopup> </menu> @@ -203,11 +269,11 @@ <menuitem id="menu_find" accesskey="&editfind.accesskey;" key="findkb" observes="cmd_find"/> <menuitem id="menu_findnext" accesskey="&editfindnext.accesskey;" key="findnextkb" observes="cmd_findNext"/> <menuseparator class="hide-in-IM" /> - <menuitem id="menu_checkspelling" accesskey="&editcheckspelling.accesskey;" key="checkspellingkb" observes="cmd_checkSpelling"/> + <menuitem id="menu_checkspelling" accesskey="&editcheckspelling.accesskey;" key="checkspellingkb" observes="cmd_spelling"/> <menuseparator class="hide-in-IM"/> - <menuitem class="hide-in-IM" id="menu_editHTML" accesskey="&HTMLsource.accesskey;" observes="Editor:EditHTML"/> + <menuitem class="hide-in-IM" id="menu_editHTML" accesskey="&HTMLsource.accesskey;" observes="cmd_editHTML"/> <menuseparator/> - <menuitem id="menu_preferences" oncommand="goPreferences('navigator.xul', 'chrome://communicator/content/pref/pref-composer.xul','editor')"/> + <menuitem id="menu_preferences" observes="cmd_preferences"/> </menupopup> </menu> @@ -315,16 +381,16 @@ <!-- Insert menu --> <menu id="insertMenu" value="&insertMenu.label;" accesskey="&insertmenu.accesskey;"> <menupopup> - <menuitem accesskey="&insertlink.accesskey;" observes="Editor:InsertLink"/> - <menuitem accesskey="&insertanchor.accesskey;" observes="Editor:InsertAnchor"/> - <menuitem accesskey="&insertimage.accesskey;" observes="Editor:InsertImage"/> - <menuitem accesskey="&inserthline.accesskey;" observes="Editor:InsertHLine"/> - <menuitem accesskey="&inserttable.accesskey;" observes="Editor:InsertTable"/> - <menuitem accesskey="&HTMLsource.accesskey;" key="inserthtmlkb" observes="Editor:InsertHTML"/> - <menuitem accesskey="&insertchars.accesskey;" observes="Editor:InsertChars"/> + <menuitem accesskey="&insertlink.accesskey;" observes="cmd_link"/> + <menuitem accesskey="&insertanchor.accesskey;" observes="cmd_anchor"/> + <menuitem accesskey="&insertimage.accesskey;" observes="cmd_image"/> + <menuitem accesskey="&inserthline.accesskey;" observes="cmd_hline"/> + <menuitem accesskey="&inserttable.accesskey;" observes="cmd_table"/> + <menuitem accesskey="&HTMLsource.accesskey;" key="inserthtmlkb" observes="cmd_insertHTML"/> + <menuitem accesskey="&insertchars.accesskey;" observes="cmd_insertChars"/> <menuseparator /> - <menuitem accesskey="&insertlinebreak.accesskey;" disabled="true" observes="Editor:InsertBreak"/> - <menuitem accesskey="&insertbreak.accesskey;" disabled="true" observes="Editor:InsertBreakAll"/> + <menuitem accesskey="&insertlinebreak.accesskey;" disabled="true" observes="cmd_insertBreak"/> + <menuitem accesskey="&insertbreak.accesskey;" disabled="true" observes="cmd_insertBreakAll"/> </menupopup> </menu> @@ -348,8 +414,8 @@ accesskey="&formatsizemenu.accesskey;" position="2"> <menupopup> - <menuitem value="&decreaseFontSize.label;" accesskey="&decreasefontsize.accesskey;" oncommand="EditorDecreaseFontSize()" key="decreasefontsizekb"/> - <menuitem value="&increaseFontSize.label;" accesskey="&increasefontsize.accesskey;" oncommand="EditorIncreaseFontSize()" key="increasefontsizekb"/> + <menuitem value="&decreaseFontSize.label;" accesskey="&decreasefontsize.accesskey;" observes="cmd_decreaseFont" key="decreasefontsizekb"/> + <menuitem value="&increaseFontSize.label;" accesskey="&increasefontsize.accesskey;" observes="cmd_increaseFont" key="increasefontsizekb"/> <menuseparator/> <menuitem value="&size-xx-smallCmd.label;" accesskey="&size-xx-small.accesskey;" oncommand="EditorSetFontSize('xx-small')"/> <menuitem value="&size-x-smallCmd.label;" accesskey="&size-x-small.accesskey;" oncommand="EditorSetFontSize('x-small')"/> @@ -365,23 +431,23 @@ <menu id="fontStyleMenu" value="&fontStyleMenu.label;" accesskey="&formatstylemenu.accesskey;" position="3"> - <menupopup> - <menuitem value="&styleBoldCmd.label;" accesskey="&stylebold.accesskey;" key="boldkb" observes="Editor:Bold"/> - <menuitem value="&styleItalicCmd.label;" accesskey="&styleitalic.accesskey;" key="italickb" observes="Editor:Italic"/> - <menuitem value="&styleUnderlineCmd.label;" accesskey="&styleunderline.accesskey;" key="underlinekb" observes="Editor:Underline"/> - <menuitem value="&styleStrikeThruCmd.label;" accesskey="&stylestrikethru.accesskey;" oncommand="EditorApplyStyle('strike')"/> - <menuitem value="&styleSuperscriptCmd.label;" accesskey="&stylesuperscript.accesskey;" oncommand="EditorApplyStyle('sup')"/> - <menuitem value="&styleSubscriptCmd.label;" accesskey="&stylesubscript.accesskey;" oncommand="EditorApplyStyle('sub')"/> - <menuitem value="&styleNonbreakingCmd.label;" accesskey="&stylenonbreaking.accesskey;" oncommand="EditorApplyStyle('nobr')"/> + <menupopup oncreate="initFontStyleMenu(this)" oncommand="goDoCommand(event.target.observes)"> + <menuitem value="&styleBoldCmd.label;" accesskey="&stylebold.accesskey;" observes="cmd_bold" key="boldkb"/> + <menuitem value="&styleItalicCmd.label;" accesskey="&styleitalic.accesskey;" observes="cmd_italic" key="italickb" /> + <menuitem value="&styleUnderlineCmd.label;" accesskey="&styleunderline.accesskey;" observes="cmd_underline" key="underlinekb"/> + <menuitem value="&styleStrikeThruCmd.label;" accesskey="&stylestrikethru.accesskey;" observes="cmd_strikethrough"/> + <menuitem value="&styleSuperscriptCmd.label;" accesskey="&stylesuperscript.accesskey;" observes="cmd_superscript"/> + <menuitem value="&styleSubscriptCmd.label;" accesskey="&stylesubscript.accesskey;" observes="cmd_subscript"/> + <menuitem value="&styleNonbreakingCmd.label;" accesskey="&stylenonbreaking.accesskey;" observes="cmd_nobreak"/> <menuseparator/> - <menuitem value="&styleEm.label;" accesskey="&styleEm.accesskey;" oncommand="EditorApplyStyle('em')"/> - <menuitem value="&styleStrong.label;" accesskey="&styleStrong.accesskey;" oncommand="EditorApplyStyle('strong')"/> - <menuitem value="&styleCite.label;" accesskey="&styleCite.accesskey;" oncommand="EditorApplyStyle('cite')"/> - <menuitem value="&styleAbbr.label;" accesskey="&styleAbbr.accesskey;" oncommand="EditorApplyStyle('abbr')"/> - <menuitem value="&styleAcronym.label;" accesskey="&styleAcronym.accesskey;" oncommand="EditorApplyStyle('acronym')"/> - <menuitem value="&styleCode.label;" accesskey="&styleCode.accesskey;" oncommand="EditorApplyStyle('code')"/> - <menuitem value="&styleSamp.label;" accesskey="&styleSamp.accesskey;" oncommand="EditorApplyStyle('samp')"/> - <menuitem value="&styleVar.label;" accesskey="&styleVar.accesskey;" oncommand="EditorApplyStyle('var')"/> + <menuitem value="&styleEm.label;" accesskey="&styleEm.accesskey;" observes="cmd_em"/> + <menuitem value="&styleStrong.label;" accesskey="&styleStrong.accesskey;" observes="cmd_strong"/> + <menuitem value="&styleCite.label;" accesskey="&styleCite.accesskey;" observes="cmd_cite"/> + <menuitem value="&styleAbbr.label;" accesskey="&styleAbbr.accesskey;" observes="cmd_abbr"/> + <menuitem value="&styleAcronym.label;" accesskey="&styleAcronym.accesskey;" observes="cmd_acronym"/> + <menuitem value="&styleCode.label;" accesskey="&styleCode.accesskey;" observes="cmd_code"/> + <menuitem value="&styleSamp.label;" accesskey="&styleSamp.accesskey;" observes="cmd_samp"/> + <menuitem value="&styleVar.label;" accesskey="&styleVar.accesskey;" observes="cmd_var"/> </menupopup> </menu> @@ -450,7 +516,7 @@ <menuitem id="removeAllStylesMenuitem" value="&removeAllStylesCmd.label;" accesskey="&formatremovestyles.accesskey;" key="removestyleskb" - oncommand="EditorRemoveStyle('all')" position="6"/> + oncommand="goDoCommand('cmd_removeStyles')" position="6"/> <menuitem id="removeLinksMenuitem" value="&removeLinksCmd.label;" accesskey="&formatremovelinks.accesskey;" oncommand="EditorRemoveLinks()" position="7"/> @@ -460,7 +526,7 @@ <menu id="headingMenu" value="&headingMenu.label;" accesskey="&formatheadingmenu.accesskey;" position="9"> - <menupopup oncommand="EditorSetParagraphFormat(event.target.data)"> + <menupopup oncommand="EditorSetParagraphFormat('cmd_paragraphState', event.target.data)"> <menuitem value="&normalCmd.label;" accesskey="&normal.accesskey;" data=""/> <menuitem value="&heading1Cmd.label;" accesskey="&heading1.accesskey;" data="H1"/> <menuitem value="&heading2Cmd.label;" accesskey="&heading2.accesskey;" data="H2"/> @@ -475,7 +541,7 @@ <menu id="paragraphMenu" value="¶graphMenu.label;" accesskey="&formatparagraphmenu.accesskey;" position="10"> - <menupopup oncommand="EditorSetParagraphFormat(event.target.data)"> + <menupopup oncommand="EditorSetParagraphFormat('cmd_paragraphState', event.target.data)"> <menuitem value="&normalCmd.label;" accesskey="&normal.accesskey;" data=""/> <menuitem value="¶graphParagraphCmd.label;" accesskey="¶graphparagraph.accesskey;" data="P"/> <menuitem value="¶graphBlockquoteCmd.label;" accesskey="¶graphblockquote.accesskey;" data="BLOCKQUOTE"/> @@ -487,33 +553,22 @@ </menu> <!-- List Style (opens dialog) --> - <menuitem id="listProps" value="&listProps.label;" - accesskey="&formatlistmenu.accesskey;" - oncommand="EditorListProperties()" - position="11"/> - <menu id="alignMenu" value="&alignMenu.label;" - accesskey="&formatalignmenu.accesskey;" - position="12"> + <menuitem id="listProps" value="&listProps.label;" accesskey="&formatlistmenu.accesskey;" position="11" observes="cmd_listProperties"/> + <menu id="alignMenu" value="&alignMenu.label;" accesskey="&formatalignmenu.accesskey;" position="12"> <!-- Align submenu --> - <menupopup> - <menuitem value="&alignLeft.label;" accesskey="&alignleft.accesskey;" oncommand="EditorAlign('left')"/> - <menuitem value="&alignCenter.label;" accesskey="&aligncenter.accesskey;" oncommand="EditorAlign('center')"/> - <menuitem value="&alignRight.label;" accesskey="&alignright.accesskey;" oncommand="EditorAlign('right')"/> - <menuitem value="&alignJustify.label;" accesskey="&alignjustify.accesskey;" oncommand="EditorAlign('justify')"/> + <menupopup oncommand="EditorAlign('cmd_align', event.target.getAttribute('data'))"> + <menuitem value="&alignLeft.label;" accesskey="&alignleft.accesskey;" data="left"/> + <menuitem value="&alignCenter.label;" accesskey="&aligncenter.accesskey;" data="center"/> + <menuitem value="&alignRight.label;" accesskey="&alignright.accesskey;" data="right"/> + <menuitem value="&alignJustify.label;" accesskey="&alignjustify.accesskey;" data="justify"/> </menupopup> </menu> <menuseparator position="13"/> - <menuitem id="increaseIndent" value="&increaseIndent.label;" - accesskey="&increaseindent.accesskey;" - key="increaseindentkb" - oncommand="EditorIndent('indent')" - position="14"/> - <menuitem id="decreaseIndent" value="&decreaseIndent.label;" - accesskey="&decreaseindent.accesskey;" - key="decreaseindentkb" - oncommand="EditorIndent('outdent')" - position="15"/> + <menuitem id="increaseIndent" value="&increaseIndent.label;" accesskey="&increaseindent.accesskey;" key="increaseindentkb" + observes="cmd_indent" position="14"/> + <menuitem id="decreaseIndent" value="&decreaseIndent.label;" accesskey="&decreaseindent.accesskey;" key="decreaseindentkb" + observes="cmd_outdent" position="15"/> <menuseparator position="16"/> <!-- Merge Table Menu and separator in Messenger Composer here --> <!-- Merge property items here --> @@ -525,10 +580,10 @@ oncommand="EditorObjectProperties()"/> <menuitem id="pageProperties" value="&pageProperties.label;" accesskey="&pageproperties.accesskey;" - oncommand="EditorPageProperties()"/> + oncommand="goDoCommand('cmd_pageProperties')"/> <menuitem id="colorsAndBackground" value="&colorsAndBackground.label;" accesskey="&colorsandbackground.accesskey;" - oncommand="EditorColorProperties()"/> + oncommand="goDoCommand('cmd_colorProperties')"/> <menu id="tableMenu" value="&tableMenu.label;" accesskey="&tablemenu.accesskey;"> <menupopup> @@ -544,7 +599,7 @@ </menu> <menu id="tableInsertMenu" value="&tableInsertMenu.label;" accesskey="&tableinsertmenu.accesskey;"> <menupopup> - <menuitem value="&insertTableCmd.label;" accesskey="&tabletable.accesskey;" oncommand="EditorInsertTable()"/> + <menuitem value="&insertTableCmd.label;" accesskey="&tabletable.accesskey;" oncommand="EditorInsertTable()"/> <menuseparator /> <menuitem value="&tableRowAbove.label;" accesskey="&tablerow.accesskey;" oncommand="EditorInsertTableRow(false)"/> <menuitem value="&tableRowBelow.label;" accesskey="&tablerowbelow.accesskey;" oncommand="EditorInsertTableRow(true)"/> @@ -567,7 +622,7 @@ <menuseparator /> <menuitem id="tableFixupMenuitem" value="&tableFixup.label;" accesskey="&tablefixup.accesskey;" oncommand="EditorNormalizeTable()"/> <menuitem id="tableJoinCellsMenuitem" value="&tableJoinCells.label;" accesskey="&tablejoin.accesskey;" oncommand="EditorJoinTableCells()" disabled="true"/> - <menuitem id="tablePropertiesMenuitem" value="&tableProperties.label;" accesskey="&properties.accesskey;" oncommand="EditorInsertOrEditTable(false)"/> + <menuitem id="tablePropertiesMenuitem" value="&tableProperties.label;" accesskey="&properties.accesskey;" observes="cmd_editTable"/> </menupopup> </menu> @@ -587,59 +642,59 @@ </popup> <menupopup id="AlignmentPopup"> - <menuitem oncommand="EditorAlign('left')"> + <menuitem oncommand="EditorAlign('cmd_align', 'left')"> <button class="borderless" id="text-align-left" align="left" value="&alignLeft.label;"/> </menuitem> - <menuitem oncommand="EditorAlign('center')"> + <menuitem oncommand="EditorAlign('cmd_align', 'center')"> <button class="borderless" id="text-align-center" align="left" value="&alignCenter.label;"/> </menuitem> - <menuitem oncommand="EditorAlign('right')"> + <menuitem oncommand="EditorAlign('cmd_align', 'right')"> <button class="borderless" id="text-align-right" align="left" value="&alignRight.label;"/> </menuitem> - <menuitem oncommand="EditorAlign('justify')"> + <menuitem oncommand="EditorAlign('cmd_align', 'justify')"> <button class="borderless" id="text-align-justify" align="left" value="&alignJustify.label;"/> </menuitem> </menupopup> <!-- InsertPopup is used by messengercompose.xul --> <menupopup id="InsertPopup"> - <menuitem oncommand="EditorInsertOrEditLink()"> + <menuitem oncommand="goDoCommand('cmd_link')"> <button class="borderless" id="linkButton-dark" darkcolor="true" align="left" value="&linkToolbarCmd.label;"/> </menuitem> - <menuitem oncommand="EditorInsertOrEditNamedAnchor()"> + <menuitem oncommand="goDoCommand('cmd_anchor')"> <button class="borderless" id="namedAnchorButton-dark" align="left" value="&anchorToolbarCmd.label;"/> </menuitem> - <menuitem oncommand="EditorInsertOrEditImage()"> + <menuitem oncommand="goDoCommand('cmd_image')"> <button class="borderless" id="imageButton-dark" align="left" value="&imageToolbarCmd.label;"/> </menuitem> - <menuitem oncommand="EditorInsertOrEditHLine()"> + <menuitem oncommand="goDoCommand('cmd_hline')"> <button class="borderless" id="hlineButton-dark" align="left" value="&hruleToolbarCmd.label;"/> </menuitem> - <menuitem oncommand="EditorInsertOrEditTable(true)"> + <menuitem oncommand="goDoCommand('cmd_table')"> <button class="borderless" id="tableButton-dark" align="left" value="&tableToolbarCmd.label;"/> </menuitem> </menupopup> <!-- Editor toolbar items --> <!-- note that we override the submenu item label "Blank Window" with "New" used for the menu --> - <button class="button-toolbar-2 top" id="newButton" observes="cmd_newEditor" value="&newMenu.label;" /> - <button class="button-toolbar-2 top" id="openButton" observes="Editor:Open" value="&openToolbarCmd.label;"/> - <button class="button-toolbar-2 top" id="saveButton" observes="Editor:Save"/> - <button class="button-toolbar-2 top" id="previewButton" observes="Editor:Preview" value="&previewToolbarCmd.label;"/> - <button class="button-toolbar-2 top" id="printButton" observes="Editor:Print" value="&printToolbarCmd.label;"/> - <button class="button-toolbar-2 top" id="findButton" observes="cmd_find" value="&findToolbarCmd.label;"/> - <button class="button-toolbar-2 top" id="spellingButton" value="&spellToolbarCmd.label;" oncommand="CheckSpelling()"/> + <button class="button-toolbar-2 top" id="newButton" value="&newMenu.label;" observes="cmd_newEditor"/> + <button class="button-toolbar-2 top" id="openButton" value="&openToolbarCmd.label;" observes="cmd_open"/> + <button class="button-toolbar-2 top" id="saveButton" observes="cmd_save"/> + <button class="button-toolbar-2 top" id="previewButton" value="&previewToolbarCmd.label;" observes="cmd_preview"/> + <button class="button-toolbar-2 top" id="printButton" value="&printToolbarCmd.label;" observes="cmd_print"/> + <button class="button-toolbar-2 top" id="findButton" value="&findToolbarCmd.label;" observes="cmd_find"/> + <button class="button-toolbar-2 top" id="spellingButton" value="&spellToolbarCmd.label;" observes="cmd_spelling"/> - <button class="button-toolbar-2 top" id="imageButton" value="&imageToolbarCmd.label;" oncommand="EditorInsertOrEditImage()"/> - <button class="button-toolbar-2 top" id="hlineButton" value="&hruleToolbarCmd.label;" oncommand="EditorInsertOrEditHLine()"/> - <button class="button-toolbar-2 top" id="tableButton" value="&tableToolbarCmd.label;" oncommand="EditorInsertOrEditTable(true)"/> - <button class="button-toolbar-2 top" id="linkButton" value="&linkToolbarCmd.label;" oncommand="EditorInsertOrEditLink()"/> - <button class="button-toolbar-2 top" id="namedAnchorButton" value="&anchorToolbarCmd.label;" oncommand="EditorInsertOrEditNamedAnchor()"/> + <button class="button-toolbar-2 top" id="imageButton" value="&imageToolbarCmd.label;" observes="cmd_image"/> + <button class="button-toolbar-2 top" id="hlineButton" value="&hruleToolbarCmd.label;" observes="cmd_hline"/> + <button class="button-toolbar-2 top" id="tableButton" value="&tableToolbarCmd.label;" observes="cmd_table"/> + <button class="button-toolbar-2 top" id="linkButton" value="&linkToolbarCmd.label;" observes="cmd_link"/> + <button class="button-toolbar-2 top" id="namedAnchorButton" value="&anchorToolbarCmd.label;" observes="cmd_anchor"/> <!-- Formatting toolbar items. "data" are HTML tagnames, don't translate --> <menulist id="ParagraphSelect"> - <observes element="Editor:Paragraph:Format" attribute="format" onbroadcast="onParagraphFormatChange()"/> - <menupopup oncommand="EditorSetParagraphFormat(event.target.data)"> + <observes element="cmd_paragraphState" attribute="state" onbroadcast="onParagraphFormatChange()"/> + <menupopup oncommand="EditorSetParagraphFormat('cmd_paragraphState', event.target.data)"> <menuitem value="&normalCmd.label;" data=""/> <menuitem value="¶graphParagraphCmd.label;" data="P"/> <menuitem value="&heading1Cmd.label;" data="H1"/> @@ -688,30 +743,30 @@ <text id="TextColorPopupButton" popup="TextColorPopup"/> </stack> - <button class="button-toolbar" id="DecreaseFontSizeButton" oncommand="EditorDecreaseFontSize()"/> - <button class="button-toolbar" id="IncreaseFontSizeButton" oncommand="EditorIncreaseFontSize()"/> + <button class="button-toolbar" id="DecreaseFontSizeButton" observes="cmd_decreaseFont"/> + <button class="button-toolbar" id="IncreaseFontSizeButton" observes="cmd_increaseFont"/> - <button class="button-toolbar" id="boldButton" align="center" oncommand="EditorToggleStyle('bold')"> - <observes element="Editor:Bold" attribute="bold" onbroadcast="onStyleChange('bold')"/> + <button class="button-toolbar" id="boldButton" oncommand="goDoCommand('cmd_bold')"> + <observes element="cmd_bold" attribute="state" onbroadcast="onButtonUpdate(this.parentNode, 'cmd_bold')"/> </button> - <button class="button-toolbar" id="italicButton" align="center" oncommand="EditorToggleStyle('italic')"> - <observes element="Editor:Italic" attribute="italic" onbroadcast="onStyleChange('italic')"/> + <button class="button-toolbar" id="italicButton" align="center" oncommand="goDoCommand('cmd_italic')"> + <observes element="cmd_italic" attribute="state" onbroadcast="onButtonUpdate(this.parentNode, 'cmd_italic')"/> </button> - <button class="button-toolbar" id="underlineButton" align="center" oncommand="EditorToggleStyle('underline')"> - <observes element="Editor:Underline" attribute="underline" onbroadcast="onStyleChange('underline')"/> + <button class="button-toolbar" id="underlineButton" align="center" oncommand="goDoCommand('cmd_underline')"> + <observes element="cmd_underline" attribute="state" onbroadcast="onButtonUpdate(this.parentNode, 'cmd_underline')"/> </button> - <button class="button-toolbar" id="ulButton" oncommand="EditorMakeOrChangeList('ul')"> - <observes element="Editor:Paragraph:ListType" attribute="format" onbroadcast="onListFormatChange('ul')"/> + <button class="button-toolbar" id="ulButton" oncommand="goDoCommand('cmd_ul')"> + <observes element="cmd_ul" attribute="state" onbroadcast="onButtonUpdate(this.parentNode, 'cmd_ul')"/> </button> - <button class="button-toolbar" id="olButton" oncommand="EditorMakeOrChangeList('ol')"> - <observes element="Editor:Paragraph:ListType" attribute="format" onbroadcast="onListFormatChange('ol')"/> + <button class="button-toolbar" id="olButton" oncommand="goDoCommand('cmd_ol')"> + <observes element="cmd_ol" attribute="state" onbroadcast="onButtonUpdate(this.parentNode, 'cmd_ol')"/> </button> - <button class="button-toolbar format" id="outdentButton" oncommand="EditorIndent('outdent')"/> - <button class="button-toolbar format" id="indentButton" oncommand="EditorIndent('indent')"/> - <button class="button-toolbar format popup" id="AlignPopupButton"/> + <button class="button-toolbar format" id="outdentButton" observes="cmd_outdent"/> + <button class="button-toolbar format" id="indentButton" observes="cmd_indent"/> + <button class="button-toolbar format popup" id="AlignPopupButton" disabled="true"/> <!-- Edit Mode toolbar --> <text id="NormalModeButton" class="EditModeButton" selected="1" value="&normalMode.label;" onclick="EditorSetDisplayMode(1)"/> @@ -726,7 +781,7 @@ <!-- Paste as quotation is used by mail compose, but in composer it has to go in the debug menu --> - <menuitem id="menu_pasteQuote" value="&pasteAsQuotationCmd.label;" accesskey="&editpastequotation.accesskey;" oncommand="EditorPasteAsQuotation()"/> + <menuitem id="menu_pasteQuote" value="&pasteAsQuotationCmd.label;" accesskey="&editpastequotation.accesskey;" oncommand="goDoCommand('cmd_pasteQote')"/> <!-- DEBUG only --> <menu id="debugMenu" value="&debugMenu.label;"> diff --git a/mozilla/layout/html/content/src/nsHTMLInputElement.cpp b/mozilla/layout/html/content/src/nsHTMLInputElement.cpp index 54b3c2b961f..3996c577cb2 100644 --- a/mozilla/layout/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLInputElement.cpp @@ -1132,18 +1132,12 @@ nsHTMLInputElement::GetControllers(nsIControllers** aResult) NS_ERROR_FAILURE); if (!mControllers) { return NS_ERROR_NULL_POINTER; } - nsCOMPtr<nsIController> controller; - NS_ENSURE_SUCCESS ( - nsComponentManager::CreateInstance("component://netscape/editor/editorcontroller", - nsnull, - NS_GET_IID(nsIController), - getter_AddRefs(controller)), - NS_ERROR_FAILURE); - if (!controller) { return NS_ERROR_NULL_POINTER; } nsresult rv; + nsCOMPtr<nsIController> controller = do_CreateInstance("component://netscape/editor/editorcontroller", &rv); + if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIEditorController> editorController = do_QueryInterface(controller, &rv); if (NS_FAILED(rv)) return rv; - rv = editorController->Init(); + rv = editorController->Init(nsnull); if (NS_FAILED(rv)) return rv; mControllers->AppendController(controller); } diff --git a/mozilla/layout/html/content/src/nsHTMLTextAreaElement.cpp b/mozilla/layout/html/content/src/nsHTMLTextAreaElement.cpp index 9f87e0983c6..0dd86122736 100644 --- a/mozilla/layout/html/content/src/nsHTMLTextAreaElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLTextAreaElement.cpp @@ -605,19 +605,12 @@ nsHTMLTextAreaElement::GetControllers(nsIControllers** aResult) NS_ERROR_FAILURE); if (!mControllers) { return NS_ERROR_NULL_POINTER; } - nsCOMPtr<nsIController> controller; - NS_ENSURE_SUCCESS ( - nsComponentManager::CreateInstance("component://netscape/editor/editorcontroller", - nsnull, - NS_GET_IID(nsIController), - getter_AddRefs(controller)), - NS_ERROR_FAILURE); - - if (!controller) { return NS_ERROR_NULL_POINTER; } nsresult rv; + nsCOMPtr<nsIController> controller = do_CreateInstance("component://netscape/editor/editorcontroller", &rv); + if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIEditorController> editorController = do_QueryInterface(controller, &rv); if (NS_FAILED(rv)) return rv; - rv = editorController->Init(); + rv = editorController->Init(nsnull); if (NS_FAILED(rv)) return rv; mControllers->AppendController(controller); diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp index 5a8af7992d0..99f40ef5cca 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp @@ -348,7 +348,7 @@ nsGfxTextControlFrame::~nsGfxTextControlFrame() nsCOMPtr<nsIEditorController> editController = do_QueryInterface(controller); if (editController) { - editController->SetEditor(nsnull); + editController->SetCommandRefCon(nsnull); found = PR_TRUE; } } @@ -1287,6 +1287,7 @@ nsGfxTextControlFrame::CreateSubDoc(nsRect *aSizeOfSubdocContainer) inputElement->GetControllers(getter_AddRefs(controllers)); else return rv = NS_ERROR_FAILURE; + if (NS_SUCCEEDED(rv)) { PRUint32 count; @@ -1301,7 +1302,7 @@ nsGfxTextControlFrame::CreateSubDoc(nsRect *aSizeOfSubdocContainer) nsCOMPtr<nsIEditorController> editController = do_QueryInterface(controller); if (editController) { - editController->SetEditor(mEditor); + editController->SetCommandRefCon(mEditor); found = PR_TRUE; } } @@ -3029,24 +3030,22 @@ nsGfxTextControlFrame::InstallEditor() if (NS_FAILED(result)) { return result; } // check to see if mContent has focus, and if so tell the docshell. - nsIEventStateManager *manager; - result = mFramePresContext->GetEventStateManager(&manager); + nsCOMPtr<nsIEventStateManager> manager; + result = mFramePresContext->GetEventStateManager(getter_AddRefs(manager)); if (NS_FAILED(result)) { return result; } if (!manager) { return NS_ERROR_NULL_POINTER; } - nsIContent *focusContent=nsnull; - result = manager->GetFocusedContent(&focusContent); + nsCOMPtr<nsIContent> focusContent; + result = manager->GetFocusedContent(getter_AddRefs(focusContent)); if (NS_FAILED(result)) { return result; } if (focusContent) { - if (mContent==focusContent) + if (mContent == focusContent.get()) { // XXX DocShell redesign work SetFocus(); } - NS_RELEASE(focusContent); } - NS_RELEASE(manager); } mCreatingViewer = PR_FALSE; return result;