diff --git a/content/xul/document/public/nsIControllerCommand.idl b/content/xul/document/public/nsIControllerCommand.idl deleted file mode 100644 index 1c03dfd46c43..000000000000 --- a/content/xul/document/public/nsIControllerCommand.idl +++ /dev/null @@ -1,180 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsISupports.idl" - -/** - * nsIControllerCommand - * - * A generic command interface. You can register an nsIControllerCommand - * with the nsIControllerCommandManager. - */ - -[scriptable, uuid(0eae9a46-1dd2-11b2-aca0-9176f05fe9db)] -interface nsIControllerCommand : nsISupports -{ - - /** - * Returns true if the command is currently enabled. An nsIControllerCommand - * can implement more than one commands; say, a group of related commands - * (e.g. delete left/delete right). Because of this, the command name is - * passed to each method. - * - * @param aCommandName the name of the command for which we want the enabled - * state. - * @param aCommandRefCon a cookie held by the nsIControllerCommandManager, - * allowing the command to get some context information. - * The contents of this cookie are implementation-defined. - */ - boolean isCommandEnabled(in string aCommandName, in nsISupports aCommandRefCon); - - /** - * Execute the name command. - * - * @param aCommandName the name of the command to execute. - * - * @param aCommandRefCon a cookie held by the nsIControllerCommandManager, - * allowing the command to get some context information. - * The contents of this cookie are implementation-defined. - */ - void doCommand(in string aCommandName, in nsISupports aCommandRefCon); - -}; - - -/** - * nsIStatefulControllerCommand - * - * An extension of the basic nsIControllerCommand interface, for commands - * that have to update state (e.g. "bold" in an editor). Note that the - * implementation of the command *must* be stateless (since a given command - * can be shared between clients of the controller command manager). State - * must be stored/update via the refCon. - */ - -[scriptable, uuid(78ad2381-1ae6-11d4-9f7e-a6d3f6dffffc)] -interface nsIStateUpdatingControllerCommand : nsISupports -{ - - /** - * Update the state of the named command. - * - * @param aCommandName the name of the command for which we want to update state. - * - * @param aCommandRefCon a cookie held by the nsIControllerCommandManager, - * allowing the command to get some context information. - * The contents of this cookie are implementation-defined. - */ - void updateCommandState(in string aCommandName, in nsISupports aCommandRefCon); -}; - - - - -/** - * nsIControllerCommandManager - * - * An interface via which a controller can maintain a series of commands, - * and efficiently dispatch commands to their respective handlers. - * - * Controllers that use an nsIControllerCommandManager should support - * nsIInterfaceRequestor, and be able to return an interface to their - * controller command manager via getInterface(). - * - */ - -[scriptable, uuid(65a2f51a-1dd2-11b2-889f-d886b255ffe7)] -interface nsIControllerCommandManager : nsISupports -{ - /** - * Register and unregister commands with the command manager. - * - * @param aCommandName the name of the command under which to register or - * unregister the given command handler. - * - * @param aCommand the handler for this command. - */ - void registerCommand(in string aCommandName, in nsIControllerCommand aCommand); - void unregisterCommand(in string aCommandName, in nsIControllerCommand aCommand); - - /** - * Find the command handler which has been registered to handle the named command. - * - * @param aCommandName the name of the command to find the handler for. - */ - nsIControllerCommand findCommandHandler(in string aCommandName); - - /** - * Get whether the named command is enabled. - * - * @param aCommandName the name of the command to test - * @param aCommandRefCon the command context data - */ - boolean isCommandEnabled(in string aCommandName, in nsISupports aCommandRefCon); - - /** - * Tell the command to udpate its state (if it is a state updating command) - * - * @param aCommandName the name of the command to update - * @param aCommandRefCon the command context data - */ - void updateCommandState(in string aCommandName, in nsISupports aCommandRefCon); - - /** - * Get whether the named command is supported. - * - * @param aCommandName the name of the command to test - * @param aCommandRefCon the command context data - */ - boolean supportsCommand(in string aCommandName, in nsISupports aCommandRefCon); - - /** - * Execute the named command. - * - * @param aCommandName the name of the command to execute - * @param aCommandRefCon the command context data - */ - void doCommand(in string aCommandName, in nsISupports aCommandRefCon); - -}; - -%{C++ -nsresult -NS_NewControllerCommandManager(nsIControllerCommandManager** aResult); - -%} diff --git a/editor/composer/src/nsComposerController.cpp b/editor/composer/src/nsComposerController.cpp index 3c82e70f5944..c94f98932d49 100644 --- a/editor/composer/src/nsComposerController.cpp +++ b/editor/composer/src/nsComposerController.cpp @@ -40,7 +40,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsIComponentManager.h" -#include "nsIControllerCommandManager.h" +#include "nsIControllerCommandTable.h" #include "nsComposerController.h" #include "nsComposerCommands.h" @@ -49,7 +49,7 @@ _cmdClass* theCmd; \ NS_NEWXPCOM(theCmd, _cmdClass); \ if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \ - rv = inCommandManager->RegisterCommand(_cmdName, \ + rv = inCommandTable->RegisterCommand(_cmdName, \ NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \ } @@ -58,15 +58,15 @@ _cmdClass* theCmd; \ NS_NEWXPCOM(theCmd, _cmdClass); \ if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \ - rv = inCommandManager->RegisterCommand(_cmdName, \ + rv = inCommandTable->RegisterCommand(_cmdName, \ NS_STATIC_CAST(nsIControllerCommand *, theCmd)); #define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName) \ - rv = inCommandManager->RegisterCommand(_cmdName, \ + rv = inCommandTable->RegisterCommand(_cmdName, \ NS_STATIC_CAST(nsIControllerCommand *, theCmd)); #define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName) \ - rv = inCommandManager->RegisterCommand(_cmdName, \ + rv = inCommandTable->RegisterCommand(_cmdName, \ NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \ } @@ -74,7 +74,7 @@ { \ _cmdClass* theCmd = new _cmdClass(_styleTag); \ if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \ - rv = inCommandManager->RegisterCommand(_cmdName, \ + rv = inCommandTable->RegisterCommand(_cmdName, \ NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \ } @@ -82,7 +82,7 @@ { \ _cmdClass* theCmd = new _cmdClass(_tagName); \ if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \ - rv = inCommandManager->RegisterCommand(_cmdName, \ + rv = inCommandTable->RegisterCommand(_cmdName, \ NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \ } @@ -90,26 +90,26 @@ // static nsresult nsComposerController::RegisterEditorDocStateCommands( - nsIControllerCommandManager *inCommandManager) + nsIControllerCommandTable *inCommandTable) { nsresult rv; // observer commands for document state - NS_REGISTER_ONE_COMMAND(nsDocumentStateCommand, "obs_documentCreated") - NS_REGISTER_ONE_COMMAND(nsDocumentStateCommand, "obs_documentWillBeDestroyed") - NS_REGISTER_ONE_COMMAND(nsDocumentStateCommand, "obs_documentLocationChanged") + NS_REGISTER_FIRST_COMMAND(nsDocumentStateCommand, "obs_documentCreated") + NS_REGISTER_NEXT_COMMAND(nsDocumentStateCommand, "obs_documentWillBeDestroyed") + NS_REGISTER_LAST_COMMAND(nsDocumentStateCommand, "obs_documentLocationChanged") // commands that may get or change state - NS_REGISTER_ONE_COMMAND(nsSetDocumentStateCommand, "cmd_setDocumentModified") - NS_REGISTER_ONE_COMMAND(nsSetDocumentStateCommand, "cmd_setDocumentUseCSS") - NS_REGISTER_ONE_COMMAND(nsSetDocumentStateCommand, "cmd_setDocumentReadOnly") + NS_REGISTER_FIRST_COMMAND(nsSetDocumentStateCommand, "cmd_setDocumentModified") + NS_REGISTER_NEXT_COMMAND(nsSetDocumentStateCommand, "cmd_setDocumentUseCSS") + NS_REGISTER_LAST_COMMAND(nsSetDocumentStateCommand, "cmd_setDocumentReadOnly") return NS_OK; } // static nsresult nsComposerController::RegisterHTMLEditorCommands( - nsIControllerCommandManager *inCommandManager) + nsIControllerCommandTable *inCommandTable) { nsresult rv; diff --git a/editor/composer/src/nsComposerController.h b/editor/composer/src/nsComposerController.h index 0b7b523f8ddd..bd4cf0ca19d0 100644 --- a/editor/composer/src/nsComposerController.h +++ b/editor/composer/src/nsComposerController.h @@ -40,7 +40,7 @@ #define nsComposerController_h__ -class nsIControllerCommandManager; +class nsIControllerCommandTable; // The plaintext editor controller is used for basic text editing and html editing @@ -58,8 +58,8 @@ class nsIControllerCommandManager; class nsComposerController { public: - static nsresult RegisterEditorDocStateCommands(nsIControllerCommandManager* inCommandManager); - static nsresult RegisterHTMLEditorCommands(nsIControllerCommandManager* inCommandManager); + static nsresult RegisterEditorDocStateCommands(nsIControllerCommandTable* inCommandTable); + static nsresult RegisterHTMLEditorCommands(nsIControllerCommandTable* inCommandTable); }; #endif /* nsComposerController_h__ */ diff --git a/editor/composer/src/nsComposerRegistration.cpp b/editor/composer/src/nsComposerRegistration.cpp index 86207eccc2ad..7f8813dfdd20 100644 --- a/editor/composer/src/nsComposerRegistration.cpp +++ b/editor/composer/src/nsComposerRegistration.cpp @@ -46,6 +46,18 @@ #include "nsEditorService.h" #include "nsComposeTxtSrvFilter.h" #include "nsIControllerContext.h" +#include "nsIControllerCommandTable.h" + +#define NS_HTMLEDITOR_COMMANDTABLE_CID \ +{ 0x7a727843, 0x6ae1, 0x11d7, { 0xa5eb, 0x00, 0x03, 0x93, 0x63, 0x65, 0x92 } } + +#define NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID \ +{ 0x800e07bc, 0x6ae1, 0x11d7, { 0x959b, 0x00, 0x03, 0x93, 0x63, 0x65, 0x92 } } + + +static NS_DEFINE_CID(kHTMLEditorCommandTableCID, NS_HTMLEDITOR_COMMANDTABLE_CID); +static NS_DEFINE_CID(kHTMLEditorDocStateCommandTableCID, NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID); + //////////////////////////////////////////////////////////////////////// // Define the contructor function for the objects @@ -85,7 +97,7 @@ nsComposeTxtSrvFilterConstructor(nsISupports *aOuter, REFNSIID aIID, return rv; } -static NS_IMETHODIMP +static nsresult nsComposeTxtSrvFilterConstructorForComposer(nsISupports *aOuter, REFNSIID aIID, void **aResult) @@ -93,7 +105,7 @@ nsComposeTxtSrvFilterConstructorForComposer(nsISupports *aOuter, return nsComposeTxtSrvFilterConstructor(aOuter, aIID, aResult, PR_FALSE); } -static NS_IMETHODIMP +static nsresult nsComposeTxtSrvFilterConstructorForMail(nsISupports *aOuter, REFNSIID aIID, void **aResult) @@ -101,71 +113,101 @@ nsComposeTxtSrvFilterConstructorForMail(nsISupports *aOuter, return nsComposeTxtSrvFilterConstructor(aOuter, aIID, aResult, PR_TRUE); } -NS_IMETHODIMP nsEditorDocStateControllerConstructor(nsISupports *aOuter, REFNSIID aIID, - void **aResult) + +// Constructor for a controller set up with a command table specified +// by the CID passed in. This function uses do_GetService to get the +// command table, so that every controller shares a single command +// table, for space-efficiency. +// +// The only reason to go via the service manager for the command table +// is that it holds onto the singleton for us, avoiding static variables here. +static nsresult +CreateControllerWithSingletonCommandTable(const nsCID& inCommandTableCID, nsIController **aResult) { - static PRBool sDocStateCommandsRegistered = PR_FALSE; + nsresult rv; + nsCOMPtr controller = do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv); + if (NS_FAILED(rv)) return rv; - nsresult rv; - nsCOMPtr context = - do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv); - if (NS_FAILED(rv)) - return rv; - if (!context) - return NS_ERROR_FAILURE; - - nsCOMPtr composerCommandManager( - do_GetService(NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CONTRACTID, &rv)); - - if (NS_FAILED(rv)) - return rv; - if (!composerCommandManager) - return NS_ERROR_OUT_OF_MEMORY; - if (!sDocStateCommandsRegistered) - { - rv = nsComposerController::RegisterEditorDocStateCommands(composerCommandManager); - if (NS_FAILED(rv)) - { - return rv; - } - sDocStateCommandsRegistered = PR_TRUE; - } + nsCOMPtr composerCommandTable = do_GetService(inCommandTableCID, &rv); + if (NS_FAILED(rv)) return rv; - context->SetControllerCommandManager(composerCommandManager); - return context->QueryInterface(aIID, aResult); + // this guy is a singleton, so make it immutable + composerCommandTable->MakeImmutable(); + + nsCOMPtr controllerContext = do_QueryInterface(controller, &rv); + if (NS_FAILED(rv)) return rv; + + rv = controllerContext->Init(composerCommandTable); + if (NS_FAILED(rv)) return rv; + + *aResult = controller; + NS_ADDREF(*aResult); + return NS_OK; } -NS_IMETHODIMP nsHTMLEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID, + +// Here we make an instance of the controller that holds doc state commands. +// We set it up with a singleton command table. +static nsresult +nsHTMLEditorDocStateControllerConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) { - static PRBool sHTMLCommandsRegistered = PR_FALSE; + nsCOMPtr controller; + nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorDocStateCommandTableCID, getter_AddRefs(controller)); + if (NS_FAILED(rv)) return rv; + return controller->QueryInterface(aIID, aResult); +} + +// Tere we make an instance of the controller that holds composer commands. +// We set it up with a singleton command table. +static nsresult +nsHTMLEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + nsCOMPtr controller; + nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorCommandTableCID, getter_AddRefs(controller)); + if (NS_FAILED(rv)) return rv; + + return controller->QueryInterface(aIID, aResult); +} + +// Constructor for a command table that is pref-filled with HTML editor commands +static nsresult +nsHTMLEditorCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID, + void **aResult) +{ nsresult rv; - nsCOMPtr context = - do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv); - if (NS_FAILED(rv)) - return rv; - if (!context) - return NS_ERROR_FAILURE; - - nsCOMPtr composerCommandManager( - do_GetService(NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - if (!composerCommandManager) - return NS_ERROR_OUT_OF_MEMORY; - if (!sHTMLCommandsRegistered) - { - rv = nsComposerController::RegisterHTMLEditorCommands(composerCommandManager); - if (NS_FAILED(rv)) - { - return rv; - } - sHTMLCommandsRegistered = PR_TRUE; - } + nsCOMPtr commandTable = + do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; - context->SetControllerCommandManager(composerCommandManager); - return context->QueryInterface(aIID, aResult); + rv = nsComposerController::RegisterHTMLEditorCommands(commandTable); + if (NS_FAILED(rv)) return rv; + + // we don't know here whether we're being created as an instance, + // or a service, so we can't become immutable + + return commandTable->QueryInterface(aIID, aResult); +} + + +// Constructor for a command table that is pref-filled with HTML editor doc state commands +static nsresult +nsHTMLEditorDocStateCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID, + void **aResult) +{ + nsresult rv; + nsCOMPtr commandTable = + do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + rv = nsComposerController::RegisterEditorDocStateCommands(commandTable); + if (NS_FAILED(rv)) return rv; + + // we don't know here whether we're being created as an instance, + // or a service, so we can't become immutable + + return commandTable->QueryInterface(aIID, aResult); } //////////////////////////////////////////////////////////////////////// @@ -174,30 +216,47 @@ NS_IMETHODIMP nsHTMLEditorControllerConstructor(nsISupports *aOuter, REFNSIID aI // class name. // static const nsModuleComponentInfo components[] = { - { "Editor DocState Controller", NS_EDITORDOCSTATECONTROLLER_CID, - "@mozilla.org/editor/editordocstatecontroller;1", - nsEditorDocStateControllerConstructor, }, + { "HTML Editor Controller", NS_HTMLEDITORCONTROLLER_CID, "@mozilla.org/editor/htmleditorcontroller;1", nsHTMLEditorControllerConstructor, }, + + { "HTML Editor DocState Controller", NS_EDITORDOCSTATECONTROLLER_CID, + "@mozilla.org/editor/editordocstatecontroller;1", + nsHTMLEditorDocStateControllerConstructor, }, + + { "HTML Editor command table", NS_HTMLEDITOR_COMMANDTABLE_CID, + "", // no point using a contract-ID + nsHTMLEditorCommandTableConstructor, }, + + { "HTML Editor doc state command table", NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID, + "", // no point using a contract-ID + nsHTMLEditorDocStateCommandTableConstructor, }, + { "Editing Session", NS_EDITINGSESSION_CID, "@mozilla.org/editor/editingsession;1", nsEditingSessionConstructor, }, + { "Editor Service", NS_EDITORSERVICE_CID, "@mozilla.org/editor/editorservice;1", nsEditorServiceConstructor,}, + { "Editor Spell Checker", NS_EDITORSPELLCHECK_CID, "@mozilla.org/editor/editorspellchecker;1", nsEditorSpellCheckConstructor,}, + { "Editor Startup Handler", NS_EDITORSERVICE_CID, "@mozilla.org/commandlinehandler/general-startup;1?type=editor", nsEditorServiceConstructor, nsEditorService::RegisterProc, nsEditorService::UnregisterProc, }, + { "Edit Startup Handler", NS_EDITORSERVICE_CID, "@mozilla.org/commandlinehandler/general-startup;1?type=edit", nsEditorServiceConstructor, }, + { "TxtSrv Filter", NS_COMPOSERTXTSRVFILTER_CID, COMPOSER_TXTSRVFILTER_CONTRACTID, nsComposeTxtSrvFilterConstructorForComposer, }, + { "TxtSrv Filter For Mail", NS_COMPOSERTXTSRVFILTER_CID, COMPOSER_TXTSRVFILTERMAIL_CONTRACTID, nsComposeTxtSrvFilterConstructorForMail, }, diff --git a/editor/composer/src/nsEditingSession.cpp b/editor/composer/src/nsEditingSession.cpp index 45288c933550..6ec427212e3c 100644 --- a/editor/composer/src/nsEditingSession.cpp +++ b/editor/composer/src/nsEditingSession.cpp @@ -430,7 +430,7 @@ nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow) // setup the HTML editor command controller if (needHTMLController) { - // The third controller takes an nsIEditor as the refCon + // The third controller takes an nsIEditor as the context rv = SetupEditorCommandController("@mozilla.org/editor/htmleditorcontroller;1", aWindow, editor, &mHTMLCommandControllerId); @@ -477,7 +477,7 @@ nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow) txnMgr->AddListener(NS_STATIC_CAST(nsITransactionListener*, stateMaintainer)); - // Set refCon on all controllers to be the editor + // Set context on all controllers to be the editor rv = SetEditorOnControllers(aWindow, editor); if (NS_FAILED(rv)) return rv; @@ -1131,18 +1131,18 @@ nsEditingSession::PrepareForEditing() SetupEditorCommandController Create a command controller, append to controllers, - get and return the controller ID, and set the refCon + get and return the controller ID, and set the context ----------------------------------------------------------------------------*/ nsresult nsEditingSession::SetupEditorCommandController( const char *aControllerClassName, nsIDOMWindow *aWindow, - nsISupports *aRefCon, + nsISupports *aContext, PRUint32 *aControllerId) { NS_ENSURE_ARG_POINTER(aControllerClassName); NS_ENSURE_ARG_POINTER(aWindow); - NS_ENSURE_ARG_POINTER(aRefCon); + NS_ENSURE_ARG_POINTER(aContext); NS_ENSURE_ARG_POINTER(aControllerId); nsresult rv; @@ -1174,8 +1174,8 @@ nsEditingSession::SetupEditorCommandController( if (NS_FAILED(rv)) return rv; } - // Set the refCon - return SetRefConOnControllerById(controllers, aRefCon, *aControllerId); + // Set the context + return SetContextOnControllerById(controllers, aContext, *aControllerId); } /*--------------------------------------------------------------------------- @@ -1202,33 +1202,33 @@ nsEditingSession::SetEditorOnControllers(nsIDOMWindow *aWindow, nsCOMPtr editorAsISupports = do_QueryInterface(aEditor); if (mBaseCommandControllerId) { - rv = SetRefConOnControllerById(controllers, editorAsISupports, + rv = SetContextOnControllerById(controllers, editorAsISupports, mBaseCommandControllerId); if (NS_FAILED(rv)) return rv; } if (mDocStateControllerId) { - rv = SetRefConOnControllerById(controllers, editorAsISupports, + rv = SetContextOnControllerById(controllers, editorAsISupports, mDocStateControllerId); if (NS_FAILED(rv)) return rv; } if (mHTMLCommandControllerId) - rv = SetRefConOnControllerById(controllers, editorAsISupports, + rv = SetContextOnControllerById(controllers, editorAsISupports, mHTMLCommandControllerId); return rv; } nsresult -nsEditingSession::SetRefConOnControllerById(nsIControllers* aControllers, - nsISupports* aRefCon, +nsEditingSession::SetContextOnControllerById(nsIControllers* aControllers, + nsISupports* aContext, PRUint32 aID) { NS_ENSURE_ARG_POINTER(aControllers); - // aRefCon can be null (when destroying editor) + // aContext can be null (when destroying editor) nsCOMPtr controller; aControllers->GetControllerById(aID, getter_AddRefs(controller)); @@ -1237,5 +1237,5 @@ nsEditingSession::SetRefConOnControllerById(nsIControllers* aControllers, do_QueryInterface(controller); if (!editorController) return NS_ERROR_FAILURE; - return editorController->SetCommandRefCon(aRefCon); + return editorController->SetCommandContext(aContext); } diff --git a/editor/composer/src/nsEditingSession.h b/editor/composer/src/nsEditingSession.h index 3c07e8777f7c..ed58a6436d6f 100644 --- a/editor/composer/src/nsEditingSession.h +++ b/editor/composer/src/nsEditingSession.h @@ -108,12 +108,12 @@ protected: nsresult SetupEditorCommandController(const char *aControllerClassName, nsIDOMWindow *aWindow, - nsISupports *aRefCon, + nsISupports *aContext, PRUint32 *aControllerId); nsresult SetEditorOnControllers(nsIDOMWindow *aWindow, nsIEditor* aEditor); - nsresult SetRefConOnControllerById(nsIControllers* aControllers, - nsISupports* aRefCon, + nsresult SetContextOnControllerById(nsIControllers* aControllers, + nsISupports* aContext, PRUint32 aID); nsresult PrepareForEditing(); diff --git a/editor/libeditor/base/nsEditorController.cpp b/editor/libeditor/base/nsEditorController.cpp index 45a83cfc9d90..5a5582c170d0 100644 --- a/editor/libeditor/base/nsEditorController.cpp +++ b/editor/libeditor/base/nsEditorController.cpp @@ -43,7 +43,7 @@ #include "nsEditorController.h" #include "nsIEditor.h" #include "nsEditorCommands.h" -#include "nsIControllerCommandManager.h" +#include "nsIControllerCommandTable.h" @@ -52,7 +52,7 @@ _cmdClass* theCmd; \ NS_NEWXPCOM(theCmd, _cmdClass); \ if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \ - rv = inCommandManager->RegisterCommand(_cmdName, \ + rv = inCommandTable->RegisterCommand(_cmdName, \ NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \ } @@ -61,21 +61,21 @@ _cmdClass* theCmd; \ NS_NEWXPCOM(theCmd, _cmdClass); \ if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \ - rv = inCommandManager->RegisterCommand(_cmdName, \ + rv = inCommandTable->RegisterCommand(_cmdName, \ NS_STATIC_CAST(nsIControllerCommand *, theCmd)); #define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName) \ - rv = inCommandManager->RegisterCommand(_cmdName, \ + rv = inCommandTable->RegisterCommand(_cmdName, \ NS_STATIC_CAST(nsIControllerCommand *, theCmd)); #define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName) \ - rv = inCommandManager->RegisterCommand(_cmdName, \ + rv = inCommandTable->RegisterCommand(_cmdName, \ NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \ } // static -nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager *inCommandManager) +nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandTable *inCommandTable) { nsresult rv; diff --git a/editor/libeditor/base/nsEditorController.h b/editor/libeditor/base/nsEditorController.h index a34161f7775d..4fe1f67895fa 100644 --- a/editor/libeditor/base/nsEditorController.h +++ b/editor/libeditor/base/nsEditorController.h @@ -42,7 +42,7 @@ #define NS_EDITORCONTROLLER_CID \ { 0x26fb965c, 0x9de6, 0x11d3, { 0xbc, 0xcc, 0x0, 0x60, 0xb0, 0xfc, 0x76, 0xbd } } -class nsIControllerCommandManager; +class nsIControllerCommandTable; // the editor controller is used for both text widgets, and basic text editing @@ -51,7 +51,7 @@ class nsIControllerCommandManager; class nsEditorController { public: - static nsresult RegisterEditorCommands(nsIControllerCommandManager* inCommandManager); + static nsresult RegisterEditorCommands(nsIControllerCommandTable* inCommandTable); }; #endif /* nsEditorController_h__ */ diff --git a/editor/libeditor/build/nsEditorRegistration.cpp b/editor/libeditor/build/nsEditorRegistration.cpp index 8f62c2a858b4..7bc60b5825c2 100644 --- a/editor/libeditor/build/nsEditorRegistration.cpp +++ b/editor/libeditor/build/nsEditorRegistration.cpp @@ -43,7 +43,9 @@ #include "nsEditor.h" // for gInstanceCount #include "nsPlaintextEditor.h" #include "nsEditorController.h" //CID +#include "nsIController.h" #include "nsIControllerContext.h" +#include "nsIControllerCommandTable.h" #include "nsIServiceManager.h" #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY @@ -52,47 +54,61 @@ #include "nsTextServicesCID.h" #endif -//////////////////////////////////////////////////////////////////////// -// Define the contructor function for the objects -// -// NOTE: This creates an instance of objects by using the default constructor -// +#define NS_EDITORCOMMANDTABLE_CID \ +{ 0x8b975b0a, 0x6ae5, 0x11d7, { 0xa44c, 0x00, 0x03, 0x93, 0x63, 0x65, 0x92 } } + +static NS_DEFINE_CID(kEditorCommandTableCID, NS_EDITORCOMMANDTABLE_CID); + NS_GENERIC_FACTORY_CONSTRUCTOR(nsPlaintextEditor) -NS_IMETHODIMP nsEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID, + +// Constructor of a controller which is set up to use, internally, a +// singleton command-table pre-filled with editor commands. +static nsresult +nsEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) { - static PRBool commandsRegistered = PR_FALSE; nsresult rv; - nsCOMPtr context = - do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1",&rv); - if (NS_FAILED(rv)) - return rv; - if (!context) - return NS_ERROR_FAILURE; - - nsCOMPtr editorCommandManager( - do_GetService(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - if (!editorCommandManager) - return NS_ERROR_OUT_OF_MEMORY; - if (!commandsRegistered) - { - rv = nsEditorController::RegisterEditorCommands(editorCommandManager); - if (NS_FAILED(rv)) - { - return rv; - } - commandsRegistered = PR_TRUE; - } + nsCOMPtr controller = do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv); + if (NS_FAILED(rv)) return rv; + nsCOMPtr editorCommandTable = do_GetService(kEditorCommandTableCID, &rv); + if (NS_FAILED(rv)) return rv; - context->SetControllerCommandManager(editorCommandManager); - return context->QueryInterface(aIID, aResult); + // this guy is a singleton, so make it immutable + editorCommandTable->MakeImmutable(); + + nsCOMPtr controllerContext = do_QueryInterface(controller, &rv); + if (NS_FAILED(rv)) return rv; + + rv = controllerContext->Init(editorCommandTable); + if (NS_FAILED(rv)) return rv; + + return controller->QueryInterface(aIID, aResult); } + +// Constructor for a command-table pref-filled with editor commands +static nsresult +nsEditorCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID, + void **aResult) +{ + nsresult rv; + nsCOMPtr commandTable = + do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + rv = nsEditorController::RegisterEditorCommands(commandTable); + if (NS_FAILED(rv)) return rv; + + // we don't know here whether we're being created as an instance, + // or a service, so we can't become immutable + + return commandTable->QueryInterface(aIID, aResult); +} + + #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextServicesDocument) #ifdef ENABLE_EDITOR_API_LOG @@ -111,6 +127,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLEditor) static const nsModuleComponentInfo components[] = { { "Text Editor", NS_TEXTEDITOR_CID, "@mozilla.org/editor/texteditor;1", nsPlaintextEditorConstructor, }, + #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY #ifdef ENABLE_EDITOR_API_LOG { "HTML Editor", NS_HTMLEDITOR_CID, @@ -120,9 +137,15 @@ static const nsModuleComponentInfo components[] = { "@mozilla.org/editor/htmleditor;1", nsHTMLEditorConstructor, }, #endif #endif + { "Editor Controller", NS_EDITORCONTROLLER_CID, "@mozilla.org/editor/editorcontroller;1", nsEditorControllerConstructor, }, + + { "Editor Command Table", NS_EDITORCOMMANDTABLE_CID, + "", // no point in using a contract ID + nsEditorCommandTableConstructor, }, + #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY { NULL, NS_TEXTSERVICESDOCUMENT_CID, "@mozilla.org/textservices/textservicesdocument;1", diff --git a/editor/ui/composer/content/ComposerCommands.js b/editor/ui/composer/content/ComposerCommands.js index ab10e7f79e98..e1d4f8fc377e 100644 --- a/editor/ui/composer/content/ComposerCommands.js +++ b/editor/ui/composer/content/ComposerCommands.js @@ -48,8 +48,8 @@ var gComposerJSCommandControllerID = 0; //----------------------------------------------------------------------------------- function SetupHTMLEditorCommands() { - var commandManager = GetComposerCommandManager(); - if (!commandManager) + var commandTable = GetComposerCommandTable(); + if (!commandTable) return; // Include everthing a text editor does @@ -57,76 +57,76 @@ function SetupHTMLEditorCommands() //dump("Registering HTML editor commands\n"); - commandManager.registerCommand("cmd_renderedHTMLEnabler", nsDummyHTMLCommand); + commandTable.registerCommand("cmd_renderedHTMLEnabler", nsDummyHTMLCommand); - commandManager.registerCommand("cmd_listProperties", nsListPropertiesCommand); - commandManager.registerCommand("cmd_pageProperties", nsPagePropertiesCommand); - commandManager.registerCommand("cmd_colorProperties", nsColorPropertiesCommand); - commandManager.registerCommand("cmd_advancedProperties", nsAdvancedPropertiesCommand); - commandManager.registerCommand("cmd_objectProperties", nsObjectPropertiesCommand); - commandManager.registerCommand("cmd_removeNamedAnchors", nsRemoveNamedAnchorsCommand); - commandManager.registerCommand("cmd_editLink", nsEditLinkCommand); + commandTable.registerCommand("cmd_listProperties", nsListPropertiesCommand); + commandTable.registerCommand("cmd_pageProperties", nsPagePropertiesCommand); + commandTable.registerCommand("cmd_colorProperties", nsColorPropertiesCommand); + commandTable.registerCommand("cmd_advancedProperties", nsAdvancedPropertiesCommand); + commandTable.registerCommand("cmd_objectProperties", nsObjectPropertiesCommand); + commandTable.registerCommand("cmd_removeNamedAnchors", nsRemoveNamedAnchorsCommand); + commandTable.registerCommand("cmd_editLink", nsEditLinkCommand); - commandManager.registerCommand("cmd_form", nsFormCommand); - commandManager.registerCommand("cmd_inputtag", nsInputTagCommand); - commandManager.registerCommand("cmd_inputimage", nsInputImageCommand); - commandManager.registerCommand("cmd_textarea", nsTextAreaCommand); - commandManager.registerCommand("cmd_select", nsSelectCommand); - commandManager.registerCommand("cmd_button", nsButtonCommand); - commandManager.registerCommand("cmd_label", nsLabelCommand); - commandManager.registerCommand("cmd_fieldset", nsFieldSetCommand); - commandManager.registerCommand("cmd_isindex", nsIsIndexCommand); - commandManager.registerCommand("cmd_image", nsImageCommand); - commandManager.registerCommand("cmd_hline", nsHLineCommand); - commandManager.registerCommand("cmd_link", nsLinkCommand); - commandManager.registerCommand("cmd_anchor", nsAnchorCommand); - commandManager.registerCommand("cmd_insertHTMLWithDialog", nsInsertHTMLWithDialogCommand); - commandManager.registerCommand("cmd_insertBreak", nsInsertBreakCommand); - commandManager.registerCommand("cmd_insertBreakAll",nsInsertBreakAllCommand); + commandTable.registerCommand("cmd_form", nsFormCommand); + commandTable.registerCommand("cmd_inputtag", nsInputTagCommand); + commandTable.registerCommand("cmd_inputimage", nsInputImageCommand); + commandTable.registerCommand("cmd_textarea", nsTextAreaCommand); + commandTable.registerCommand("cmd_select", nsSelectCommand); + commandTable.registerCommand("cmd_button", nsButtonCommand); + commandTable.registerCommand("cmd_label", nsLabelCommand); + commandTable.registerCommand("cmd_fieldset", nsFieldSetCommand); + commandTable.registerCommand("cmd_isindex", nsIsIndexCommand); + commandTable.registerCommand("cmd_image", nsImageCommand); + commandTable.registerCommand("cmd_hline", nsHLineCommand); + commandTable.registerCommand("cmd_link", nsLinkCommand); + commandTable.registerCommand("cmd_anchor", nsAnchorCommand); + commandTable.registerCommand("cmd_insertHTMLWithDialog", nsInsertHTMLWithDialogCommand); + commandTable.registerCommand("cmd_insertBreak", nsInsertBreakCommand); + commandTable.registerCommand("cmd_insertBreakAll",nsInsertBreakAllCommand); - commandManager.registerCommand("cmd_table", nsInsertOrEditTableCommand); - commandManager.registerCommand("cmd_editTable", nsEditTableCommand); - commandManager.registerCommand("cmd_SelectTable", nsSelectTableCommand); - commandManager.registerCommand("cmd_SelectRow", nsSelectTableRowCommand); - commandManager.registerCommand("cmd_SelectColumn", nsSelectTableColumnCommand); - commandManager.registerCommand("cmd_SelectCell", nsSelectTableCellCommand); - commandManager.registerCommand("cmd_SelectAllCells", nsSelectAllTableCellsCommand); - commandManager.registerCommand("cmd_InsertTable", nsInsertTableCommand); - commandManager.registerCommand("cmd_InsertRowAbove", nsInsertTableRowAboveCommand); - commandManager.registerCommand("cmd_InsertRowBelow", nsInsertTableRowBelowCommand); - commandManager.registerCommand("cmd_InsertColumnBefore", nsInsertTableColumnBeforeCommand); - commandManager.registerCommand("cmd_InsertColumnAfter", nsInsertTableColumnAfterCommand); - commandManager.registerCommand("cmd_InsertCellBefore", nsInsertTableCellBeforeCommand); - commandManager.registerCommand("cmd_InsertCellAfter", nsInsertTableCellAfterCommand); - commandManager.registerCommand("cmd_DeleteTable", nsDeleteTableCommand); - commandManager.registerCommand("cmd_DeleteRow", nsDeleteTableRowCommand); - commandManager.registerCommand("cmd_DeleteColumn", nsDeleteTableColumnCommand); - commandManager.registerCommand("cmd_DeleteCell", nsDeleteTableCellCommand); - commandManager.registerCommand("cmd_DeleteCellContents", nsDeleteTableCellContentsCommand); - commandManager.registerCommand("cmd_JoinTableCells", nsJoinTableCellsCommand); - commandManager.registerCommand("cmd_SplitTableCell", nsSplitTableCellCommand); - commandManager.registerCommand("cmd_TableOrCellColor", nsTableOrCellColorCommand); - commandManager.registerCommand("cmd_NormalizeTable", nsNormalizeTableCommand); - commandManager.registerCommand("cmd_smiley", nsSetSmiley); - commandManager.registerCommand("cmd_ConvertToTable", nsConvertToTable); + commandTable.registerCommand("cmd_table", nsInsertOrEditTableCommand); + commandTable.registerCommand("cmd_editTable", nsEditTableCommand); + commandTable.registerCommand("cmd_SelectTable", nsSelectTableCommand); + commandTable.registerCommand("cmd_SelectRow", nsSelectTableRowCommand); + commandTable.registerCommand("cmd_SelectColumn", nsSelectTableColumnCommand); + commandTable.registerCommand("cmd_SelectCell", nsSelectTableCellCommand); + commandTable.registerCommand("cmd_SelectAllCells", nsSelectAllTableCellsCommand); + commandTable.registerCommand("cmd_InsertTable", nsInsertTableCommand); + commandTable.registerCommand("cmd_InsertRowAbove", nsInsertTableRowAboveCommand); + commandTable.registerCommand("cmd_InsertRowBelow", nsInsertTableRowBelowCommand); + commandTable.registerCommand("cmd_InsertColumnBefore", nsInsertTableColumnBeforeCommand); + commandTable.registerCommand("cmd_InsertColumnAfter", nsInsertTableColumnAfterCommand); + commandTable.registerCommand("cmd_InsertCellBefore", nsInsertTableCellBeforeCommand); + commandTable.registerCommand("cmd_InsertCellAfter", nsInsertTableCellAfterCommand); + commandTable.registerCommand("cmd_DeleteTable", nsDeleteTableCommand); + commandTable.registerCommand("cmd_DeleteRow", nsDeleteTableRowCommand); + commandTable.registerCommand("cmd_DeleteColumn", nsDeleteTableColumnCommand); + commandTable.registerCommand("cmd_DeleteCell", nsDeleteTableCellCommand); + commandTable.registerCommand("cmd_DeleteCellContents", nsDeleteTableCellContentsCommand); + commandTable.registerCommand("cmd_JoinTableCells", nsJoinTableCellsCommand); + commandTable.registerCommand("cmd_SplitTableCell", nsSplitTableCellCommand); + commandTable.registerCommand("cmd_TableOrCellColor", nsTableOrCellColorCommand); + commandTable.registerCommand("cmd_NormalizeTable", nsNormalizeTableCommand); + commandTable.registerCommand("cmd_smiley", nsSetSmiley); + commandTable.registerCommand("cmd_ConvertToTable", nsConvertToTable); } function SetupTextEditorCommands() { - var commandManager = GetComposerCommandManager(); - if (!commandManager) + var commandTable = GetComposerCommandTable(); + if (!commandTable) return; //dump("Registering plain text editor commands\n"); - commandManager.registerCommand("cmd_find", nsFindCommand); - commandManager.registerCommand("cmd_findNext", new nsFindAgainCommand(false)); - commandManager.registerCommand("cmd_findPrev", new nsFindAgainCommand(true)); - commandManager.registerCommand("cmd_rewrap", nsRewrapCommand); - commandManager.registerCommand("cmd_spelling", nsSpellingCommand); - commandManager.registerCommand("cmd_validate", nsValidateCommand); - commandManager.registerCommand("cmd_checkLinks", nsCheckLinksCommand); - commandManager.registerCommand("cmd_insertChars", nsInsertCharsCommand); + commandTable.registerCommand("cmd_find", nsFindCommand); + commandTable.registerCommand("cmd_findNext", new nsFindAgainCommand(false)); + commandTable.registerCommand("cmd_findPrev", new nsFindAgainCommand(true)); + commandTable.registerCommand("cmd_rewrap", nsRewrapCommand); + commandTable.registerCommand("cmd_spelling", nsSpellingCommand); + commandTable.registerCommand("cmd_validate", nsValidateCommand); + commandTable.registerCommand("cmd_checkLinks", nsCheckLinksCommand); + commandTable.registerCommand("cmd_insertChars", nsInsertCharsCommand); } function SetupComposerWindowCommands() @@ -147,15 +147,18 @@ function SetupComposerWindowCommands() if (!windowControllers) return; - var commandManager; + var commandTable; var composerController; var editorController; try { composerController = Components.classes["@mozilla.org/embedcomp/base-command-controller;1"].createInstance(); - // Get the nsIControllerCommandManager interface we need to register commands + + editorController = composerController.QueryInterface(Components.interfaces.nsIControllerContext); + editorController.init(null); // init it without passing in a command table + + // Get the nsIControllerCommandTable interface we need to register commands var interfaceRequestor = composerController.QueryInterface(Components.interfaces.nsIInterfaceRequestor); - commandManager = interfaceRequestor.getInterface(Components.interfaces.nsIControllerCommandManager); - editorController = interfaceRequestor.QueryInterface(Components.interfaces.nsIControllerContext); + commandTable = interfaceRequestor.getInterface(Components.interfaces.nsIControllerCommandTable); } catch (e) { @@ -164,41 +167,41 @@ function SetupComposerWindowCommands() } - if (!commandManager) + if (!commandTable) { dump("Failed to get interface for nsIControllerCommandManager\n"); return; } // File-related commands - commandManager.registerCommand("cmd_open", nsOpenCommand); - commandManager.registerCommand("cmd_save", nsSaveCommand); - commandManager.registerCommand("cmd_saveAs", nsSaveAsCommand); - commandManager.registerCommand("cmd_exportToText", nsExportToTextCommand); - commandManager.registerCommand("cmd_saveAsCharset", nsSaveAsCharsetCommand); - commandManager.registerCommand("cmd_publish", nsPublishCommand); - commandManager.registerCommand("cmd_publishAs", nsPublishAsCommand); - commandManager.registerCommand("cmd_publishSettings",nsPublishSettingsCommand); - commandManager.registerCommand("cmd_revert", nsRevertCommand); - commandManager.registerCommand("cmd_openRemote", nsOpenRemoteCommand); - commandManager.registerCommand("cmd_preview", nsPreviewCommand); - commandManager.registerCommand("cmd_editSendPage", nsSendPageCommand); - commandManager.registerCommand("cmd_print", nsPrintCommand); - commandManager.registerCommand("cmd_printSetup", nsPrintSetupCommand); - commandManager.registerCommand("cmd_quit", nsQuitCommand); - commandManager.registerCommand("cmd_close", nsCloseCommand); - commandManager.registerCommand("cmd_preferences", nsPreferencesCommand); + commandTable.registerCommand("cmd_open", nsOpenCommand); + commandTable.registerCommand("cmd_save", nsSaveCommand); + commandTable.registerCommand("cmd_saveAs", nsSaveAsCommand); + commandTable.registerCommand("cmd_exportToText", nsExportToTextCommand); + commandTable.registerCommand("cmd_saveAsCharset", nsSaveAsCharsetCommand); + commandTable.registerCommand("cmd_publish", nsPublishCommand); + commandTable.registerCommand("cmd_publishAs", nsPublishAsCommand); + commandTable.registerCommand("cmd_publishSettings",nsPublishSettingsCommand); + commandTable.registerCommand("cmd_revert", nsRevertCommand); + commandTable.registerCommand("cmd_openRemote", nsOpenRemoteCommand); + commandTable.registerCommand("cmd_preview", nsPreviewCommand); + commandTable.registerCommand("cmd_editSendPage", nsSendPageCommand); + commandTable.registerCommand("cmd_print", nsPrintCommand); + commandTable.registerCommand("cmd_printSetup", nsPrintSetupCommand); + commandTable.registerCommand("cmd_quit", nsQuitCommand); + commandTable.registerCommand("cmd_close", nsCloseCommand); + commandTable.registerCommand("cmd_preferences", nsPreferencesCommand); // Edit Mode commands if (GetCurrentEditorType() == "html") { - commandManager.registerCommand("cmd_NormalMode", nsNormalModeCommand); - commandManager.registerCommand("cmd_AllTagsMode", nsAllTagsModeCommand); - commandManager.registerCommand("cmd_HTMLSourceMode", nsHTMLSourceModeCommand); - commandManager.registerCommand("cmd_PreviewMode", nsPreviewModeCommand); - commandManager.registerCommand("cmd_FinishHTMLSource", nsFinishHTMLSource); - commandManager.registerCommand("cmd_CancelHTMLSource", nsCancelHTMLSource); - commandManager.registerCommand("cmd_updateStructToolbar", nsUpdateStructToolbarCommand); + commandTable.registerCommand("cmd_NormalMode", nsNormalModeCommand); + commandTable.registerCommand("cmd_AllTagsMode", nsAllTagsModeCommand); + commandTable.registerCommand("cmd_HTMLSourceMode", nsHTMLSourceModeCommand); + commandTable.registerCommand("cmd_PreviewMode", nsPreviewModeCommand); + commandTable.registerCommand("cmd_FinishHTMLSource", nsFinishHTMLSource); + commandTable.registerCommand("cmd_CancelHTMLSource", nsCancelHTMLSource); + commandTable.registerCommand("cmd_updateStructToolbar", nsUpdateStructToolbarCommand); } windowControllers.insertControllerAt(0, editorController); @@ -208,9 +211,9 @@ function SetupComposerWindowCommands() } //----------------------------------------------------------------------------------- -function GetComposerCommandManager() +function GetComposerCommandTable() { - var controller; + var controller; if (gComposerJSCommandControllerID) { try { @@ -221,6 +224,9 @@ function GetComposerCommandManager() { //create it controller = Components.classes["@mozilla.org/embedcomp/base-command-controller;1"].createInstance(); + + var editorController = controller.QueryInterface(Components.interfaces.nsIControllerContext); + editorController.init(null); window.content.controllers.insertControllerAt(0, controller); // Store the controller ID so we can be sure to get the right one later @@ -230,7 +236,7 @@ function GetComposerCommandManager() if (controller) { var interfaceRequestor = controller.QueryInterface(Components.interfaces.nsIInterfaceRequestor); - return interfaceRequestor.getInterface(Components.interfaces.nsIControllerCommandManager); + return interfaceRequestor.getInterface(Components.interfaces.nsIControllerCommandTable); } return null; } diff --git a/embedding/components/commandhandler/public/Makefile.in b/embedding/components/commandhandler/public/Makefile.in index 370f1ef5f968..01cd806df052 100644 --- a/embedding/components/commandhandler/public/Makefile.in +++ b/embedding/components/commandhandler/public/Makefile.in @@ -34,7 +34,7 @@ XPIDLSRCS = \ nsICommandParams.idl \ nsIControllerCommand.idl \ nsIControllerContext.idl \ - nsIControllerCommandManager.idl \ + nsIControllerCommandTable.idl \ nsPICommandUpdater.idl \ $(NULL) diff --git a/embedding/components/commandhandler/public/nsIControllerCommand.idl b/embedding/components/commandhandler/public/nsIControllerCommand.idl index 394bb40022a2..d2a1639c0305 100644 --- a/embedding/components/commandhandler/public/nsIControllerCommand.idl +++ b/embedding/components/commandhandler/public/nsIControllerCommand.idl @@ -27,7 +27,7 @@ * nsIControllerCommand * * A generic command interface. You can register an nsIControllerCommand - * with the nsIControllerCommandManager. + * with the nsIControllerCommandTable. */ [scriptable, uuid(0eae9a46-1dd2-11b2-aca0-9176f05fe9db)] @@ -42,26 +42,26 @@ interface nsIControllerCommand : nsISupports * * @param aCommandName the name of the command for which we want the enabled * state. - * @param aCommandRefCon a cookie held by the nsIControllerCommandManager, + * @param aCommandContext a cookie held by the nsIControllerCommandTable, * allowing the command to get some context information. * The contents of this cookie are implementation-defined. */ - boolean isCommandEnabled(in string aCommandName, in nsISupports aCommandRefCon); + boolean isCommandEnabled(in string aCommandName, in nsISupports aCommandContext); - void getCommandStateParams(in string aCommandName, in nsICommandParams aParams, in nsISupports aCommandRefCon); + void getCommandStateParams(in string aCommandName, in nsICommandParams aParams, in nsISupports aCommandContext); /** * Execute the name command. * * @param aCommandName the name of the command to execute. * - * @param aCommandRefCon a cookie held by the nsIControllerCommandManager, + * @param aCommandContext a cookie held by the nsIControllerCommandTable, * allowing the command to get some context information. * The contents of this cookie are implementation-defined. */ - void doCommand(in string aCommandName, in nsISupports aCommandRefCon); + void doCommand(in string aCommandName, in nsISupports aCommandContext); - void doCommandParams(in string aCommandName, in nsICommandParams aParams, in nsISupports aCommandRefCon); + void doCommandParams(in string aCommandName, in nsICommandParams aParams, in nsISupports aCommandContext); }; diff --git a/embedding/components/commandhandler/public/nsIControllerCommandManager.idl b/embedding/components/commandhandler/public/nsIControllerCommandManager.idl deleted file mode 100644 index 35f03c3dbe51..000000000000 --- a/embedding/components/commandhandler/public/nsIControllerCommandManager.idl +++ /dev/null @@ -1,109 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsISupports.idl" -#include "nsIControllerCommand.idl" -#include "nsICommandParams.idl" - -/** - * nsIControllerCommandManager - * - * An interface via which a controller can maintain a series of commands, - * and efficiently dispatch commands to their respective handlers. - * - * Controllers that use an nsIControllerCommandManager should support - * nsIInterfaceRequestor, and be able to return an interface to their - * controller command manager via getInterface(). - * - */ - -[scriptable, uuid(65a2f51a-1dd2-11b2-889f-d886b255ffe7)] -interface nsIControllerCommandManager : nsISupports -{ - /** - * Register and unregister commands with the command manager. - * - * @param aCommandName the name of the command under which to register or - * unregister the given command handler. - * - * @param aCommand the handler for this command. - */ - void registerCommand(in string aCommandName, in nsIControllerCommand aCommand); - void unregisterCommand(in string aCommandName, in nsIControllerCommand aCommand); - - /** - * Find the command handler which has been registered to handle the named command. - * - * @param aCommandName the name of the command to find the handler for. - */ - nsIControllerCommand findCommandHandler(in string aCommandName); - - /** - * Get whether the named command is enabled. - * - * @param aCommandName the name of the command to test - * @param aCommandRefCon the command context data - */ - boolean isCommandEnabled(in string aCommandName, in nsISupports aCommandRefCon); - - /** - * Tell the command to udpate its state (if it is a state updating command) - * - * @param aCommandName the name of the command to update - * @param aCommandRefCon the command context data - */ - void updateCommandState(in string aCommandName, in nsISupports aCommandRefCon); - - /** - * Get whether the named command is supported. - * - * @param aCommandName the name of the command to test - * @param aCommandRefCon the command context data - */ - boolean supportsCommand(in string aCommandName, in nsISupports aCommandRefCon); - - /** - * Execute the named command. - * - * @param aCommandName the name of the command to execute - * @param aCommandRefCon the command context data - */ - void doCommand(in string aCommandName, in nsISupports aCommandRefCon); - - void doCommandParams(in string aCommandName, in nsICommandParams aParam, in nsISupports aCommandRefCon); - - void getCommandState(in string aCommandName, in nsICommandParams aParam, in nsISupports aCommandRefCon); -}; - - -// {f424fd81-cca6-11d5-a73c-dc628c6e85bc} -%{C++ -#define NS_CONTROLLERCOMMANDMANAGER_CID \ -{ 0xf424fd81, 0xcca6, 0x11d5, { 0xa7, 0x3c, 0xdc, 0x62, 0x8c, 0x6e, 0x85, 0xbc } } - -#define NS_CONTROLLERCOMMANDMANAGER_CONTRACTID \ - "@mozilla.org/embedcomp/controller-command-manager;1" -#define NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CONTRACTID \ -"@mozilla.org/embedcomp/composers-controller-command-manager;1" -#define NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CID \ -{ 0xb0e54f80, 0xc274, 0x4765, { 0x9e, 0x36, 0xd0, 0x0a, 0xcd, 0x38, 0x92, 0x9c } } -%} diff --git a/embedding/components/commandhandler/public/nsIControllerCommandTable.idl b/embedding/components/commandhandler/public/nsIControllerCommandTable.idl new file mode 100644 index 000000000000..66a05fd1ff66 --- /dev/null +++ b/embedding/components/commandhandler/public/nsIControllerCommandTable.idl @@ -0,0 +1,130 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Simon Fraser + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" +#include "nsIControllerCommand.idl" +#include "nsICommandParams.idl" + +/** + * nsIControllerCommandTable + * + * An interface via which a controller can maintain a series of commands, + * and efficiently dispatch commands to their respective handlers. + * + * Controllers that use an nsIControllerCommandTable should support + * nsIInterfaceRequestor, and be able to return an interface to their + * controller command table via getInterface(). + * + */ + +[scriptable, uuid(d1a47834-6ad4-11d7-bfad-000393636592)] +interface nsIControllerCommandTable : nsISupports +{ + /** + * Make this command table immutable, so that commands cannot + * be registered or unregistered. Some command tables are made + * mutable after command registration so that they can be + * used as singletons. + */ + void makeImmutable(); + + /** + * Register and unregister commands with the command table. + * + * @param aCommandName the name of the command under which to register or + * unregister the given command handler. + * + * @param aCommand the handler for this command. + */ + void registerCommand(in string aCommandName, in nsIControllerCommand aCommand); + void unregisterCommand(in string aCommandName, in nsIControllerCommand aCommand); + + /** + * Find the command handler which has been registered to handle the named command. + * + * @param aCommandName the name of the command to find the handler for. + */ + nsIControllerCommand findCommandHandler(in string aCommandName); + + /** + * Get whether the named command is enabled. + * + * @param aCommandName the name of the command to test + * @param aCommandRefCon the command context data + */ + boolean isCommandEnabled(in string aCommandName, in nsISupports aCommandRefCon); + + /** + * Tell the command to udpate its state (if it is a state updating command) + * + * @param aCommandName the name of the command to update + * @param aCommandRefCon the command context data + */ + void updateCommandState(in string aCommandName, in nsISupports aCommandRefCon); + + /** + * Get whether the named command is supported. + * + * @param aCommandName the name of the command to test + * @param aCommandRefCon the command context data + */ + boolean supportsCommand(in string aCommandName, in nsISupports aCommandRefCon); + + /** + * Execute the named command. + * + * @param aCommandName the name of the command to execute + * @param aCommandRefCon the command context data + */ + void doCommand(in string aCommandName, in nsISupports aCommandRefCon); + + void doCommandParams(in string aCommandName, in nsICommandParams aParam, in nsISupports aCommandRefCon); + + void getCommandState(in string aCommandName, in nsICommandParams aParam, in nsISupports aCommandRefCon); +}; + + + +%{C++ +// {670ee5da-6ad5-11d7-9950-000393636592} +#define NS_CONTROLLERCOMMANDTABLE_CID \ + {0x670ee5da, 0x6ad5, 0x11d7, \ + { 0x99, 0x50, 0x00, 0x03, 0x93, 0x63, 0x65, 0x92 }} + +#define NS_CONTROLLERCOMMANDTABLE_CONTRACTID \ + "@mozilla.org/embedcomp/controller-command-table;1" +%} diff --git a/embedding/components/commandhandler/public/nsIControllerContext.idl b/embedding/components/commandhandler/public/nsIControllerContext.idl index b94cc39474ca..87bdcd4b06a7 100644 --- a/embedding/components/commandhandler/public/nsIControllerContext.idl +++ b/embedding/components/commandhandler/public/nsIControllerContext.idl @@ -38,22 +38,32 @@ * ***** END LICENSE BLOCK ***** */ #include "nsISupports.idl" -#include "nsIControllerCommandManager.idl" +#include "nsIControllerCommandTable.idl" [scriptable, uuid(47B82B60-A36F-4167-8072-6F421151ED50)] interface nsIControllerContext : nsISupports { + /** + * Init the controller, optionally passing a controller + * command table. + * + * @param aCommandTable a command table, used internally + * by this controller. May be null, in + * which case the controller will create + * a new, empty table. + */ + void init(in nsIControllerCommandTable aCommandTable); /** - * Set the cookie that is passed to commands - * Note that the commandRefCon is *not* addreffed - * and thus it needs to outlive the controller + * Set a context on this controller, which is passed + * to commands to give them some context when they execute. + * + * @param aCommandContext the context passed to commands. + * Note that this is *not* addreffed by the + * controller, and so needs to outlive it, + * or be nulled out. */ - void setCommandRefCon(in nsISupports commandRefCon); + void setCommandContext(in nsISupports aCommandContext); - /** - * Set the command manager. This will have the effect of making the manager immutable - */ - void setControllerCommandManager(in nsIControllerCommandManager commandManager); }; diff --git a/embedding/components/commandhandler/src/Makefile.in b/embedding/components/commandhandler/src/Makefile.in index b79591bfced9..5f0b6019172d 100644 --- a/embedding/components/commandhandler/src/Makefile.in +++ b/embedding/components/commandhandler/src/Makefile.in @@ -44,7 +44,7 @@ CPPSRCS = \ nsCommandGroup.cpp \ nsCommandManager.cpp \ nsCommandParams.cpp \ - nsControllerCommandManager.cpp \ + nsControllerCommandTable.cpp \ $(NULL) diff --git a/embedding/components/commandhandler/src/nsBaseCommandController.cpp b/embedding/components/commandhandler/src/nsBaseCommandController.cpp index 9e3bc2fa4e30..49cff1178757 100644 --- a/embedding/components/commandhandler/src/nsBaseCommandController.cpp +++ b/embedding/components/commandhandler/src/nsBaseCommandController.cpp @@ -56,13 +56,8 @@ NS_INTERFACE_MAP_BEGIN(nsBaseCommandController) NS_INTERFACE_MAP_END nsBaseCommandController::nsBaseCommandController() -: mCommandRefCon(nsnull), mImmutableManager(PR_FALSE) +: mCommandContext(nsnull) { - nsresult rv; - mCommandManager = - do_CreateInstance(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv); - - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create CommandManager in nsBaseCommandController"); } nsBaseCommandController::~nsBaseCommandController() @@ -70,20 +65,22 @@ nsBaseCommandController::~nsBaseCommandController() } NS_IMETHODIMP -nsBaseCommandController::SetCommandRefCon(nsISupports *aCommandRefCon) +nsBaseCommandController::Init(nsIControllerCommandTable *aCommandTable) { - mCommandRefCon = aCommandRefCon; // no addref - return NS_OK; + nsresult rv = NS_OK; + + if (aCommandTable) + mCommandTable = aCommandTable; // owning addref + else + mCommandTable = do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv); + + return rv; } NS_IMETHODIMP -nsBaseCommandController::SetControllerCommandManager( - nsIControllerCommandManager *aCommandManager) +nsBaseCommandController::SetCommandContext(nsISupports *aCommandContext) { - if (!aCommandManager) - return NS_ERROR_NULL_POINTER; - mCommandManager = aCommandManager; - mImmutableManager = PR_TRUE; + mCommandContext = aCommandContext; // no addref return NS_OK; } @@ -94,11 +91,13 @@ nsBaseCommandController::GetInterface(const nsIID & aIID, void * *result) if (NS_SUCCEEDED(QueryInterface(aIID, result))) return NS_OK; - // Don't let users get the command manager if it's - // immutable. They may harm it in some way. - if (!mImmutableManager && mCommandManager && - aIID.Equals(NS_GET_IID(nsIControllerCommandManager))) - return mCommandManager->QueryInterface(aIID, result); + + if (aIID.Equals(NS_GET_IID(nsIControllerCommandTable))) + { + if (mCommandTable) + return mCommandTable->QueryInterface(aIID, result); + return NS_ERROR_NOT_INITIALIZED; + } return NS_NOINTERFACE; } @@ -115,7 +114,7 @@ nsBaseCommandController::IsCommandEnabled(const char *aCommand, { NS_ENSURE_ARG_POINTER(aCommand); NS_ENSURE_ARG_POINTER(aResult); - return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult); + return mCommandTable->IsCommandEnabled(aCommand, mCommandContext, aResult); } NS_IMETHODIMP @@ -123,14 +122,14 @@ nsBaseCommandController::SupportsCommand(const char *aCommand, PRBool *aResult) { NS_ENSURE_ARG_POINTER(aCommand); NS_ENSURE_ARG_POINTER(aResult); - return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult); + return mCommandTable->SupportsCommand(aCommand, mCommandContext, aResult); } NS_IMETHODIMP nsBaseCommandController::DoCommand(const char *aCommand) { NS_ENSURE_ARG_POINTER(aCommand); - return mCommandManager->DoCommand(aCommand, mCommandRefCon); + return mCommandTable->DoCommand(aCommand, mCommandContext); } NS_IMETHODIMP @@ -138,7 +137,7 @@ nsBaseCommandController::DoCommandWithParams(const char *aCommand, nsICommandParams *aParams) { NS_ENSURE_ARG_POINTER(aCommand); - return mCommandManager->DoCommandParams(aCommand, aParams, mCommandRefCon); + return mCommandTable->DoCommandParams(aCommand, aParams, mCommandContext); } NS_IMETHODIMP @@ -146,7 +145,7 @@ nsBaseCommandController::GetCommandStateWithParams(const char *aCommand, nsICommandParams *aParams) { NS_ENSURE_ARG_POINTER(aCommand); - return mCommandManager->GetCommandState(aCommand, aParams, mCommandRefCon); + return mCommandTable->GetCommandState(aCommand, aParams, mCommandContext); } NS_IMETHODIMP @@ -155,5 +154,3 @@ nsBaseCommandController::OnEvent(const char * aEventName) NS_ENSURE_ARG_POINTER(aEventName); return NS_OK; } - - diff --git a/embedding/components/commandhandler/src/nsBaseCommandController.h b/embedding/components/commandhandler/src/nsBaseCommandController.h index 8706b02624c8..af1138dcf6dd 100644 --- a/embedding/components/commandhandler/src/nsBaseCommandController.h +++ b/embedding/components/commandhandler/src/nsBaseCommandController.h @@ -48,15 +48,8 @@ #include "nsIController.h" #include "nsIControllerContext.h" -#include "nsIControllerCommand.h" -#include "nsIControllerCommandManager.h" +#include "nsIControllerCommandTable.h" #include "nsIInterfaceRequestor.h" -#include "nsIInterfaceRequestorUtils.h" - -//#include "nsHashtable.h" -//#include "nsString.h" -//#include "nsWeakPtr.h" - // The base editor controller is used for both text widgets, // and all other text and html editing @@ -87,12 +80,10 @@ public: private: - nsISupports *mCommandRefCon; + nsISupports *mCommandContext; // Our reference to the command manager - nsCOMPtr mCommandManager; - - PRBool mImmutableManager; + nsCOMPtr mCommandTable; }; #endif /* nsBaseCommandController_h_ */ diff --git a/embedding/components/commandhandler/src/nsCommandManager.cpp b/embedding/components/commandhandler/src/nsCommandManager.cpp index 2e3b16cf040d..7dcb976a3117 100644 --- a/embedding/components/commandhandler/src/nsCommandManager.cpp +++ b/embedding/components/commandhandler/src/nsCommandManager.cpp @@ -189,7 +189,7 @@ nsCommandManager::IsCommandSupported(const char *aCommandName, NS_ENSURE_ARG_POINTER(outCommandSupported); nsCOMPtr controller; - nsresult rv = GetControllerForCommand(aCommandName, aTargetWindow, getter_AddRefs(controller)); + GetControllerForCommand(aCommandName, aTargetWindow, getter_AddRefs(controller)); *outCommandSupported = (controller.get() != nsnull); return NS_OK; } @@ -206,7 +206,7 @@ nsCommandManager::IsCommandEnabled(const char *aCommandName, PRBool commandEnabled = PR_FALSE; nsCOMPtr controller; - nsresult rv = GetControllerForCommand(aCommandName, aTargetWindow, getter_AddRefs(controller)); + GetControllerForCommand(aCommandName, aTargetWindow, getter_AddRefs(controller)); if (controller) { controller->IsCommandEnabled(aCommandName, &commandEnabled); diff --git a/embedding/components/commandhandler/src/nsCommandParams.h b/embedding/components/commandhandler/src/nsCommandParams.h index 1ac3e2049479..424dd6c4d7a5 100644 --- a/embedding/components/commandhandler/src/nsCommandParams.h +++ b/embedding/components/commandhandler/src/nsCommandParams.h @@ -83,8 +83,8 @@ protected: nsCOMPtr mISupports; HashEntry(PRUint8 inType, const char * inEntryName) - : mEntryType(inType) - , mEntryName(inEntryName) + : mEntryName(inEntryName) + , mEntryType(inType) { memset(&mData, 0, sizeof(mData)); Reset(mEntryType); diff --git a/embedding/components/commandhandler/src/nsControllerCommandManager.cpp b/embedding/components/commandhandler/src/nsControllerCommandTable.cpp similarity index 66% rename from embedding/components/commandhandler/src/nsControllerCommandManager.cpp rename to embedding/components/commandhandler/src/nsControllerCommandTable.cpp index b08e3fc5b2cf..3b62b0d41178 100644 --- a/embedding/components/commandhandler/src/nsControllerCommandManager.cpp +++ b/embedding/components/commandhandler/src/nsControllerCommandTable.cpp @@ -20,7 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * + * Simon Fraser * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -37,37 +37,46 @@ * ***** END LICENSE BLOCK ***** */ #include "nsString.h" -#include "nsControllerCommandManager.h" +#include "nsIControllerCommand.h" +#include "nsControllerCommandTable.h" // prototype; nsresult -NS_NewControllerCommandManager(nsIControllerCommandManager** aResult); +NS_NewControllerCommandTable(nsIControllerCommandTable** aResult); // this value is used to size the hash table. Just a sensible upper bound #define NUM_COMMANDS_BOUNDS 64 -nsControllerCommandManager::nsControllerCommandManager() +nsControllerCommandTable::nsControllerCommandTable() : mCommandsTable(NUM_COMMANDS_BOUNDS, PR_FALSE) +, mMutable(PR_TRUE) { } -nsControllerCommandManager::~nsControllerCommandManager() +nsControllerCommandTable::~nsControllerCommandTable() { - } -NS_IMPL_ISUPPORTS2(nsControllerCommandManager, nsIControllerCommandManager, nsISupportsWeakReference); - +NS_IMPL_ISUPPORTS2(nsControllerCommandTable, nsIControllerCommandTable, nsISupportsWeakReference); NS_IMETHODIMP -nsControllerCommandManager::RegisterCommand(const char * aCommandName, nsIControllerCommand *aCommand) +nsControllerCommandTable::MakeImmutable(void) { + mMutable = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +nsControllerCommandTable::RegisterCommand(const char * aCommandName, nsIControllerCommand *aCommand) +{ + NS_ENSURE_TRUE(mMutable, NS_ERROR_FAILURE); + nsCStringKey commandKey(aCommandName); - if (mCommandsTable.Put (&commandKey, aCommand)) + if (mCommandsTable.Put(&commandKey, aCommand)) { #if DEBUG NS_WARNING("Replacing existing command -- "); @@ -78,26 +87,29 @@ nsControllerCommandManager::RegisterCommand(const char * aCommandName, nsIContro NS_IMETHODIMP -nsControllerCommandManager::UnregisterCommand(const char * aCommandName, nsIControllerCommand *aCommand) +nsControllerCommandTable::UnregisterCommand(const char * aCommandName, nsIControllerCommand *aCommand) { + NS_ENSURE_TRUE(mMutable, NS_ERROR_FAILURE); + nsCStringKey commandKey(aCommandName); - PRBool wasRemoved = mCommandsTable.Remove (&commandKey); + PRBool wasRemoved = mCommandsTable.Remove(&commandKey); return wasRemoved ? NS_OK : NS_ERROR_FAILURE; } NS_IMETHODIMP -nsControllerCommandManager::FindCommandHandler(const char * aCommandName, nsIControllerCommand **outCommand) +nsControllerCommandTable::FindCommandHandler(const char * aCommandName, nsIControllerCommand **outCommand) { NS_ENSURE_ARG_POINTER(outCommand); *outCommand = NULL; nsCStringKey commandKey(aCommandName); - nsISupports* foundCommand = mCommandsTable.Get(&commandKey); // this does the addref + nsISupports* foundCommand = mCommandsTable.Get(&commandKey); if (!foundCommand) return NS_ERROR_FAILURE; + // no need to addref since the .Get does it for us *outCommand = NS_REINTERPRET_CAST(nsIControllerCommand*, foundCommand); return NS_OK; } @@ -106,7 +118,7 @@ nsControllerCommandManager::FindCommandHandler(const char * aCommandName, nsICon /* boolean isCommandEnabled (in wstring command); */ NS_IMETHODIMP -nsControllerCommandManager::IsCommandEnabled(const char * aCommandName, nsISupports *aCommandRefCon, PRBool *aResult) +nsControllerCommandTable::IsCommandEnabled(const char * aCommandName, nsISupports *aCommandRefCon, PRBool *aResult) { NS_ENSURE_ARG_POINTER(aResult); @@ -118,7 +130,7 @@ nsControllerCommandManager::IsCommandEnabled(const char * aCommandName, nsISuppo if (!commandHandler) { #if DEBUG - NS_WARNING("Controller command manager asked about a command that it does not handle -- "); + NS_WARNING("Controller command table asked about a command that it does not handle -- "); #endif return NS_OK; // we don't handle this command } @@ -128,7 +140,7 @@ nsControllerCommandManager::IsCommandEnabled(const char * aCommandName, nsISuppo NS_IMETHODIMP -nsControllerCommandManager::UpdateCommandState(const char * aCommandName, nsISupports *aCommandRefCon) +nsControllerCommandTable::UpdateCommandState(const char * aCommandName, nsISupports *aCommandRefCon) { // find the command nsCOMPtr commandHandler; @@ -136,7 +148,7 @@ nsControllerCommandManager::UpdateCommandState(const char * aCommandName, nsISup if (!commandHandler) { #if DEBUG - NS_WARNING("Controller command manager asked to update the state of a command that it does not handle -- "); + NS_WARNING("Controller command table asked to update the state of a command that it does not handle -- "); #endif return NS_OK; // we don't handle this command } @@ -145,7 +157,7 @@ nsControllerCommandManager::UpdateCommandState(const char * aCommandName, nsISup } NS_IMETHODIMP -nsControllerCommandManager::SupportsCommand(const char * aCommandName, nsISupports *aCommandRefCon, PRBool *aResult) +nsControllerCommandTable::SupportsCommand(const char * aCommandName, nsISupports *aCommandRefCon, PRBool *aResult) { NS_ENSURE_ARG_POINTER(aResult); @@ -163,7 +175,7 @@ nsControllerCommandManager::SupportsCommand(const char * aCommandName, nsISuppor /* void doCommand (in wstring command); */ NS_IMETHODIMP -nsControllerCommandManager::DoCommand(const char * aCommandName, nsISupports *aCommandRefCon) +nsControllerCommandTable::DoCommand(const char * aCommandName, nsISupports *aCommandRefCon) { // find the command nsCOMPtr commandHandler; @@ -171,7 +183,7 @@ nsControllerCommandManager::DoCommand(const char * aCommandName, nsISupports *aC if (!commandHandler) { #if DEBUG - NS_WARNING("Controller command manager asked to do a command that it does not handle -- "); + NS_WARNING("Controller command table asked to do a command that it does not handle -- "); #endif return NS_OK; // we don't handle this command } @@ -180,7 +192,7 @@ nsControllerCommandManager::DoCommand(const char * aCommandName, nsISupports *aC } NS_IMETHODIMP -nsControllerCommandManager::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *aCommandRefCon) +nsControllerCommandTable::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *aCommandRefCon) { // find the command nsCOMPtr commandHandler; @@ -189,7 +201,7 @@ nsControllerCommandManager::DoCommandParams(const char *aCommandName, nsICommand if (!commandHandler) { #if DEBUG - NS_WARNING("Controller command manager asked to do a command that it does not handle -- "); + NS_WARNING("Controller command table asked to do a command that it does not handle -- "); #endif return NS_OK; // we don't handle this command } @@ -198,7 +210,7 @@ nsControllerCommandManager::DoCommandParams(const char *aCommandName, nsICommand NS_IMETHODIMP -nsControllerCommandManager::GetCommandState(const char *aCommandName, nsICommandParams *aParams, nsISupports *aCommandRefCon) +nsControllerCommandTable::GetCommandState(const char *aCommandName, nsICommandParams *aParams, nsISupports *aCommandRefCon) { // find the command nsCOMPtr commandHandler; @@ -207,7 +219,7 @@ nsControllerCommandManager::GetCommandState(const char *aCommandName, nsICommand if (!commandHandler) { #if DEBUG - NS_WARNING("Controller command manager asked to do a command that it does not handle -- "); + NS_WARNING("Controller command table asked to do a command that it does not handle -- "); #endif return NS_OK; // we don't handle this command } @@ -216,18 +228,18 @@ nsControllerCommandManager::GetCommandState(const char *aCommandName, nsICommand nsresult -NS_NewControllerCommandManager(nsIControllerCommandManager** aResult) +NS_NewControllerCommandTable(nsIControllerCommandTable** aResult) { NS_PRECONDITION(aResult != nsnull, "null ptr"); if (! aResult) return NS_ERROR_NULL_POINTER; - nsControllerCommandManager* newCommandManager = new nsControllerCommandManager(); - if (! newCommandManager) + nsControllerCommandTable* newCommandTable = new nsControllerCommandTable(); + if (! newCommandTable) return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(newCommandManager); - *aResult = newCommandManager; + NS_ADDREF(newCommandTable); + *aResult = newCommandTable; return NS_OK; } diff --git a/embedding/components/commandhandler/src/nsControllerCommandManager.h b/embedding/components/commandhandler/src/nsControllerCommandTable.h similarity index 78% rename from embedding/components/commandhandler/src/nsControllerCommandManager.h rename to embedding/components/commandhandler/src/nsControllerCommandTable.h index ecc2fec831a9..1bb98eea5e79 100644 --- a/embedding/components/commandhandler/src/nsControllerCommandManager.h +++ b/embedding/components/commandhandler/src/nsControllerCommandTable.h @@ -20,7 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * + * Simon Fraser * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -36,33 +36,33 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef nsControllerCommandManager_h_ -#define nsControllerCommandManager_h_ +#ifndef nsControllerCommandTable_h_ +#define nsControllerCommandTable_h_ -#include "nsIControllerCommandManager.h" -#include "nsIControllerCommand.h" +#include "nsIControllerCommandTable.h" #include "nsWeakReference.h" #include "nsHashtable.h" +class nsIControllerCommand; - -class nsControllerCommandManager : public nsIControllerCommandManager, - public nsSupportsWeakReference +class nsControllerCommandTable : public nsIControllerCommandTable, + public nsSupportsWeakReference { public: - nsControllerCommandManager(); - virtual ~nsControllerCommandManager(); + nsControllerCommandTable(); + virtual ~nsControllerCommandTable(); NS_DECL_ISUPPORTS - NS_DECL_NSICONTROLLERCOMMANDMANAGER + NS_DECL_NSICONTROLLERCOMMANDTABLE protected: nsSupportsHashtable mCommandsTable; // hash table of nsIControllerCommands, keyed by command name + PRBool mMutable; // are we mutable? }; -#endif // nsControllerCommandManager_h_ +#endif // nsControllerCommandTable_h_ diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index 45dd3d2e4f74..720be953b247 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -1257,7 +1257,7 @@ nsTextControlFrame::PreDestroy(nsIPresContext* aPresContext) nsCOMPtr editController = do_QueryInterface(controller); if (editController) { - editController->SetCommandRefCon(nsnull); + editController->SetCommandContext(nsnull); } } } @@ -1807,7 +1807,7 @@ nsTextControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, nsCOMPtr editController = do_QueryInterface(controller); if (editController) { - editController->SetCommandRefCon(mEditor); + editController->SetCommandContext(mEditor); found = PR_TRUE; } } diff --git a/layout/html/forms/src/nsTextControlFrame.cpp b/layout/html/forms/src/nsTextControlFrame.cpp index 45dd3d2e4f74..720be953b247 100644 --- a/layout/html/forms/src/nsTextControlFrame.cpp +++ b/layout/html/forms/src/nsTextControlFrame.cpp @@ -1257,7 +1257,7 @@ nsTextControlFrame::PreDestroy(nsIPresContext* aPresContext) nsCOMPtr editController = do_QueryInterface(controller); if (editController) { - editController->SetCommandRefCon(nsnull); + editController->SetCommandContext(nsnull); } } } @@ -1807,7 +1807,7 @@ nsTextControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, nsCOMPtr editController = do_QueryInterface(controller); if (editController) { - editController->SetCommandRefCon(mEditor); + editController->SetCommandContext(mEditor); found = PR_TRUE; } }