Fix bug 201257 -- clean up use of nsIControllerCommandManager by editor:

Renaming nsIControllerCommandManager to nsIControllerCommandTable to reduce confusion.
Moving the immutability flag from the nsBaseCommandController to the nsControllerCommandTable.
Renaming the 'refcon' on nsIControllerContext to 'context', and giving nsIControllerContext an Init() method that optionally takes a command table.
Fixing the editor and composer module code to create pre-filled nsIControllerCommandTables as services, and the controller constructors to create singleton command tables with do_GetService.
r=brade, sr=alecf.
This commit is contained in:
sfraser%netscape.com 2003-04-10 18:44:03 +00:00
Родитель efc6ab63ef
Коммит d61e2195a4
26 изменённых файлов: 823 добавлений и 292 удалений

Просмотреть файл

Просмотреть файл

@ -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;

Просмотреть файл

@ -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__ */

Просмотреть файл

@ -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,
// 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)
{
nsresult rv;
nsCOMPtr<nsIController> controller = do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIControllerCommandTable> composerCommandTable = do_GetService(inCommandTableCID, &rv);
if (NS_FAILED(rv)) return rv;
// this guy is a singleton, so make it immutable
composerCommandTable->MakeImmutable();
nsCOMPtr<nsIControllerContext> 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;
}
// 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 sDocStateCommandsRegistered = PR_FALSE;
nsCOMPtr<nsIController> controller;
nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorDocStateCommandTableCID, getter_AddRefs(controller));
if (NS_FAILED(rv)) return rv;
nsresult rv;
nsCOMPtr<nsIControllerContext> context =
do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
if (NS_FAILED(rv))
return rv;
if (!context)
return NS_ERROR_FAILURE;
return controller->QueryInterface(aIID, aResult);
}
nsCOMPtr<nsIControllerCommandManager> composerCommandManager(
do_GetService(NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
if (!composerCommandManager)
return NS_ERROR_OUT_OF_MEMORY;
if (!sDocStateCommandsRegistered)
// 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)
{
rv = nsComposerController::RegisterEditorDocStateCommands(composerCommandManager);
if (NS_FAILED(rv))
{
return rv;
}
sDocStateCommandsRegistered = PR_TRUE;
nsCOMPtr<nsIController> controller;
nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorCommandTableCID, getter_AddRefs(controller));
if (NS_FAILED(rv)) return rv;
return controller->QueryInterface(aIID, aResult);
}
context->SetControllerCommandManager(composerCommandManager);
return context->QueryInterface(aIID, aResult);
}
NS_IMETHODIMP nsHTMLEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID,
// Constructor for a command table that is pref-filled with HTML editor commands
static nsresult
nsHTMLEditorCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static PRBool sHTMLCommandsRegistered = PR_FALSE;
nsresult rv;
nsCOMPtr<nsIControllerContext> context =
do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
if (NS_FAILED(rv))
return rv;
if (!context)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIControllerCommandTable> commandTable =
do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIControllerCommandManager> 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;
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);
}
context->SetControllerCommandManager(composerCommandManager);
return context->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<nsIControllerCommandTable> 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, },

Просмотреть файл

@ -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<nsISupports> 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<nsIController> 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);
}

Просмотреть файл

@ -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();

Просмотреть файл

@ -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;

Просмотреть файл

@ -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__ */

Просмотреть файл

@ -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<nsIControllerContext> context =
do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1",&rv);
if (NS_FAILED(rv))
return rv;
if (!context)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIController> controller = do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIControllerCommandManager> editorCommandManager(
do_GetService(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
if (!editorCommandManager)
return NS_ERROR_OUT_OF_MEMORY;
if (!commandsRegistered)
nsCOMPtr<nsIControllerCommandTable> editorCommandTable = do_GetService(kEditorCommandTableCID, &rv);
if (NS_FAILED(rv)) return rv;
// this guy is a singleton, so make it immutable
editorCommandTable->MakeImmutable();
nsCOMPtr<nsIControllerContext> 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)
{
rv = nsEditorController::RegisterEditorCommands(editorCommandManager);
if (NS_FAILED(rv))
{
return rv;
}
commandsRegistered = PR_TRUE;
nsresult rv;
nsCOMPtr<nsIControllerCommandTable> 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);
}
context->SetControllerCommandManager(editorCommandManager);
return context->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",

Просмотреть файл

@ -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,7 +211,7 @@ function SetupComposerWindowCommands()
}
//-----------------------------------------------------------------------------------
function GetComposerCommandManager()
function GetComposerCommandTable()
{
var controller;
if (gComposerJSCommandControllerID)
@ -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;
}

Просмотреть файл

@ -34,7 +34,7 @@ XPIDLSRCS = \
nsICommandParams.idl \
nsIControllerCommand.idl \
nsIControllerContext.idl \
nsIControllerCommandManager.idl \
nsIControllerCommandTable.idl \
nsPICommandUpdater.idl \
$(NULL)

Просмотреть файл

@ -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);
};

Просмотреть файл

Просмотреть файл

@ -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 <sfraser@netscape.com>
*
* 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"
%}

Просмотреть файл

@ -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);
};

Просмотреть файл

@ -44,7 +44,7 @@ CPPSRCS = \
nsCommandGroup.cpp \
nsCommandManager.cpp \
nsCommandParams.cpp \
nsControllerCommandManager.cpp \
nsControllerCommandTable.cpp \
$(NULL)

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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<nsIControllerCommandManager> mCommandManager;
PRBool mImmutableManager;
nsCOMPtr<nsIControllerCommandTable> mCommandTable;
};
#endif /* nsBaseCommandController_h_ */

Просмотреть файл

@ -189,7 +189,7 @@ nsCommandManager::IsCommandSupported(const char *aCommandName,
NS_ENSURE_ARG_POINTER(outCommandSupported);
nsCOMPtr<nsIController> 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<nsIController> controller;
nsresult rv = GetControllerForCommand(aCommandName, aTargetWindow, getter_AddRefs(controller));
GetControllerForCommand(aCommandName, aTargetWindow, getter_AddRefs(controller));
if (controller)
{
controller->IsCommandEnabled(aCommandName, &commandEnabled);

Просмотреть файл

@ -83,8 +83,8 @@ protected:
nsCOMPtr<nsISupports> mISupports;
HashEntry(PRUint8 inType, const char * inEntryName)
: mEntryType(inType)
, mEntryName(inEntryName)
: mEntryName(inEntryName)
, mEntryType(inType)
{
memset(&mData, 0, sizeof(mData));
Reset(mEntryType);

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -0,0 +1,247 @@
/* -*- 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):
* Simon Fraser <sfraser@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsString.h"
#include "nsIControllerCommand.h"
#include "nsControllerCommandTable.h"
// prototype;
nsresult
NS_NewControllerCommandTable(nsIControllerCommandTable** aResult);
// this value is used to size the hash table. Just a sensible upper bound
#define NUM_COMMANDS_BOUNDS 64
nsControllerCommandTable::nsControllerCommandTable()
: mCommandsTable(NUM_COMMANDS_BOUNDS, PR_FALSE)
, mMutable(PR_TRUE)
{
}
nsControllerCommandTable::~nsControllerCommandTable()
{
}
NS_IMPL_ISUPPORTS2(nsControllerCommandTable, nsIControllerCommandTable, nsISupportsWeakReference);
NS_IMETHODIMP
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 DEBUG
NS_WARNING("Replacing existing command -- ");
#endif
}
return NS_OK;
}
NS_IMETHODIMP
nsControllerCommandTable::UnregisterCommand(const char * aCommandName, nsIControllerCommand *aCommand)
{
NS_ENSURE_TRUE(mMutable, NS_ERROR_FAILURE);
nsCStringKey commandKey(aCommandName);
PRBool wasRemoved = mCommandsTable.Remove(&commandKey);
return wasRemoved ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsControllerCommandTable::FindCommandHandler(const char * aCommandName, nsIControllerCommand **outCommand)
{
NS_ENSURE_ARG_POINTER(outCommand);
*outCommand = NULL;
nsCStringKey commandKey(aCommandName);
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;
}
/* boolean isCommandEnabled (in wstring command); */
NS_IMETHODIMP
nsControllerCommandTable::IsCommandEnabled(const char * aCommandName, nsISupports *aCommandRefCon, PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = PR_FALSE;
// find the command
nsCOMPtr<nsIControllerCommand> commandHandler;
FindCommandHandler(aCommandName, getter_AddRefs(commandHandler));
if (!commandHandler)
{
#if DEBUG
NS_WARNING("Controller command table asked about a command that it does not handle -- ");
#endif
return NS_OK; // we don't handle this command
}
return commandHandler->IsCommandEnabled(aCommandName, aCommandRefCon, aResult);
}
NS_IMETHODIMP
nsControllerCommandTable::UpdateCommandState(const char * aCommandName, nsISupports *aCommandRefCon)
{
// find the command
nsCOMPtr<nsIControllerCommand> commandHandler;
FindCommandHandler(aCommandName, getter_AddRefs(commandHandler));
if (!commandHandler)
{
#if DEBUG
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
}
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsControllerCommandTable::SupportsCommand(const char * aCommandName, nsISupports *aCommandRefCon, PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
// XXX: need to check the readonly and disabled states
*aResult = PR_FALSE;
// find the command
nsCOMPtr<nsIControllerCommand> commandHandler;
FindCommandHandler(aCommandName, getter_AddRefs(commandHandler));
*aResult = (commandHandler.get() != nsnull);
return NS_OK;
}
/* void doCommand (in wstring command); */
NS_IMETHODIMP
nsControllerCommandTable::DoCommand(const char * aCommandName, nsISupports *aCommandRefCon)
{
// find the command
nsCOMPtr<nsIControllerCommand> commandHandler;
FindCommandHandler(aCommandName, getter_AddRefs(commandHandler));
if (!commandHandler)
{
#if DEBUG
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
}
return commandHandler->DoCommand(aCommandName, aCommandRefCon);
}
NS_IMETHODIMP
nsControllerCommandTable::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *aCommandRefCon)
{
// find the command
nsCOMPtr<nsIControllerCommand> commandHandler;
nsresult rv;
rv = FindCommandHandler(aCommandName, getter_AddRefs(commandHandler));
if (!commandHandler)
{
#if DEBUG
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
}
return commandHandler->DoCommandParams(aCommandName, aParams, aCommandRefCon);
}
NS_IMETHODIMP
nsControllerCommandTable::GetCommandState(const char *aCommandName, nsICommandParams *aParams, nsISupports *aCommandRefCon)
{
// find the command
nsCOMPtr<nsIControllerCommand> commandHandler;
nsresult rv;
rv = FindCommandHandler(aCommandName, getter_AddRefs(commandHandler));
if (!commandHandler)
{
#if DEBUG
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
}
return commandHandler->GetCommandStateParams(aCommandName, aParams, aCommandRefCon);
}
nsresult
NS_NewControllerCommandTable(nsIControllerCommandTable** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsControllerCommandTable* newCommandTable = new nsControllerCommandTable();
if (! newCommandTable)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(newCommandTable);
*aResult = newCommandTable;
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,68 @@
/* -*- 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):
* Simon Fraser <sfraser@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsControllerCommandTable_h_
#define nsControllerCommandTable_h_
#include "nsIControllerCommandTable.h"
#include "nsWeakReference.h"
#include "nsHashtable.h"
class nsIControllerCommand;
class nsControllerCommandTable : public nsIControllerCommandTable,
public nsSupportsWeakReference
{
public:
nsControllerCommandTable();
virtual ~nsControllerCommandTable();
NS_DECL_ISUPPORTS
NS_DECL_NSICONTROLLERCOMMANDTABLE
protected:
nsSupportsHashtable mCommandsTable; // hash table of nsIControllerCommands, keyed by command name
PRBool mMutable; // are we mutable?
};
#endif // nsControllerCommandTable_h_

Просмотреть файл

@ -1257,7 +1257,7 @@ nsTextControlFrame::PreDestroy(nsIPresContext* aPresContext)
nsCOMPtr<nsIControllerContext> editController = do_QueryInterface(controller);
if (editController)
{
editController->SetCommandRefCon(nsnull);
editController->SetCommandContext(nsnull);
}
}
}
@ -1807,7 +1807,7 @@ nsTextControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext,
nsCOMPtr<nsIControllerContext> editController = do_QueryInterface(controller);
if (editController)
{
editController->SetCommandRefCon(mEditor);
editController->SetCommandContext(mEditor);
found = PR_TRUE;
}
}

Просмотреть файл

@ -1257,7 +1257,7 @@ nsTextControlFrame::PreDestroy(nsIPresContext* aPresContext)
nsCOMPtr<nsIControllerContext> editController = do_QueryInterface(controller);
if (editController)
{
editController->SetCommandRefCon(nsnull);
editController->SetCommandContext(nsnull);
}
}
}
@ -1807,7 +1807,7 @@ nsTextControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext,
nsCOMPtr<nsIControllerContext> editController = do_QueryInterface(controller);
if (editController)
{
editController->SetCommandRefCon(mEditor);
editController->SetCommandContext(mEditor);
found = PR_TRUE;
}
}