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. git-svn-id: svn://10.0.0.236/trunk@140988 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
* 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
|
||||
@@ -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<nsIControllerCommand> 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<nsIControllerCommand> 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<nsIControllerCommand> 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<nsIControllerCommand> 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;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
* 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
|
||||
@@ -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_
|
||||
Reference in New Issue
Block a user