Bug 1540963 - Make nsIControllerCommandTable builtinclass and make its users use nsControllerCommandTable directly r=bzbarsky
`nsIControllerCommandTable` isn't implemented with JS even in comm-central nor BlueGriffon. Therefore, we can make it a builtinclass. Additionally, it's inherited only by nsControllerCommandTable. So, all users in C++ can treat the concrete class directly. Differential Revision: https://phabricator.services.mozilla.com/D25727
This commit is contained in:
@@ -29,7 +29,7 @@ nsBaseCommandController::~nsBaseCommandController() {}
|
||||
NS_IMETHODIMP
|
||||
nsBaseCommandController::Init(nsIControllerCommandTable* aCommandTable) {
|
||||
if (aCommandTable) {
|
||||
mCommandTable = aCommandTable;
|
||||
mCommandTable = aCommandTable->AsControllerCommandTable();
|
||||
} else {
|
||||
mCommandTable = new nsControllerCommandTable();
|
||||
}
|
||||
@@ -67,7 +67,10 @@ nsBaseCommandController::GetInterface(const nsIID& aIID, void** aResult) {
|
||||
|
||||
if (aIID.Equals(NS_GET_IID(nsIControllerCommandTable))) {
|
||||
if (mCommandTable) {
|
||||
return mCommandTable->QueryInterface(aIID, aResult);
|
||||
*aResult =
|
||||
do_AddRef(static_cast<nsIControllerCommandTable*>(mCommandTable))
|
||||
.take();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
@@ -118,7 +121,7 @@ nsBaseCommandController::DoCommand(const char* aCommand) {
|
||||
if (!context) {
|
||||
context = do_QueryReferent(mCommandContextWeakPtr);
|
||||
}
|
||||
nsCOMPtr<nsIControllerCommandTable> commandTable(mCommandTable);
|
||||
RefPtr<nsControllerCommandTable> commandTable(mCommandTable);
|
||||
return commandTable->DoCommand(aCommand, context);
|
||||
}
|
||||
|
||||
@@ -132,7 +135,7 @@ nsBaseCommandController::DoCommandWithParams(const char* aCommand,
|
||||
if (!context) {
|
||||
context = do_QueryReferent(mCommandContextWeakPtr);
|
||||
}
|
||||
nsCOMPtr<nsIControllerCommandTable> commandTable(mCommandTable);
|
||||
RefPtr<nsControllerCommandTable> commandTable(mCommandTable);
|
||||
return commandTable->DoCommandParams(aCommand, aParams, context);
|
||||
}
|
||||
|
||||
@@ -164,54 +167,54 @@ nsBaseCommandController::GetSupportedCommands(uint32_t* aCount,
|
||||
return mCommandTable->GetSupportedCommands(aCount, aCommands);
|
||||
}
|
||||
|
||||
typedef already_AddRefed<nsIControllerCommandTable> (*CommandTableCreatorFn)();
|
||||
typedef already_AddRefed<nsControllerCommandTable> (*CommandTableCreatorFn)();
|
||||
|
||||
static already_AddRefed<nsIController>
|
||||
static already_AddRefed<nsBaseCommandController>
|
||||
CreateControllerWithSingletonCommandTable(CommandTableCreatorFn aCreatorFn) {
|
||||
nsCOMPtr<nsIController> controller = new nsBaseCommandController();
|
||||
RefPtr<nsBaseCommandController> commandController =
|
||||
new nsBaseCommandController();
|
||||
|
||||
nsCOMPtr<nsIControllerCommandTable> commandTable = aCreatorFn();
|
||||
if (!commandTable) return nullptr;
|
||||
RefPtr<nsControllerCommandTable> commandTable = aCreatorFn();
|
||||
if (!commandTable) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// this is a singleton; make it immutable
|
||||
commandTable->MakeImmutable();
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIControllerContext> controllerContext =
|
||||
do_QueryInterface(controller, &rv);
|
||||
if (NS_FAILED(rv)) return nullptr;
|
||||
nsresult rv = commandController->Init(commandTable);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rv = controllerContext->Init(commandTable);
|
||||
if (NS_FAILED(rv)) return nullptr;
|
||||
|
||||
return controller.forget();
|
||||
return commandController.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIController>
|
||||
already_AddRefed<nsBaseCommandController>
|
||||
nsBaseCommandController::CreateWindowController() {
|
||||
return CreateControllerWithSingletonCommandTable(
|
||||
nsControllerCommandTable::CreateWindowCommandTable);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIController>
|
||||
already_AddRefed<nsBaseCommandController>
|
||||
nsBaseCommandController::CreateEditorController() {
|
||||
return CreateControllerWithSingletonCommandTable(
|
||||
nsControllerCommandTable::CreateEditorCommandTable);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIController>
|
||||
already_AddRefed<nsBaseCommandController>
|
||||
nsBaseCommandController::CreateEditingController() {
|
||||
return CreateControllerWithSingletonCommandTable(
|
||||
nsControllerCommandTable::CreateEditingCommandTable);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIController>
|
||||
already_AddRefed<nsBaseCommandController>
|
||||
nsBaseCommandController::CreateHTMLEditorController() {
|
||||
return CreateControllerWithSingletonCommandTable(
|
||||
nsControllerCommandTable::CreateHTMLEditorCommandTable);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIController>
|
||||
already_AddRefed<nsBaseCommandController>
|
||||
nsBaseCommandController::CreateHTMLEditorDocStateController() {
|
||||
return CreateControllerWithSingletonCommandTable(
|
||||
nsControllerCommandTable::CreateHTMLEditorDocStateCommandTable);
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
|
||||
#include "nsIController.h"
|
||||
#include "nsIControllerContext.h"
|
||||
#include "nsIControllerCommandTable.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIWeakReferenceUtils.h"
|
||||
|
||||
class nsControllerCommandTable;
|
||||
|
||||
// The base editor controller is used for both text widgets, and all other text
|
||||
// and html editing
|
||||
class nsBaseCommandController : public nsIController,
|
||||
@@ -28,11 +29,12 @@ class nsBaseCommandController : public nsIController,
|
||||
NS_DECL_NSICONTROLLERCONTEXT
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
|
||||
static already_AddRefed<nsIController> CreateWindowController();
|
||||
static already_AddRefed<nsIController> CreateEditorController();
|
||||
static already_AddRefed<nsIController> CreateEditingController();
|
||||
static already_AddRefed<nsIController> CreateHTMLEditorController();
|
||||
static already_AddRefed<nsIController> CreateHTMLEditorDocStateController();
|
||||
static already_AddRefed<nsBaseCommandController> CreateWindowController();
|
||||
static already_AddRefed<nsBaseCommandController> CreateEditorController();
|
||||
static already_AddRefed<nsBaseCommandController> CreateEditingController();
|
||||
static already_AddRefed<nsBaseCommandController> CreateHTMLEditorController();
|
||||
static already_AddRefed<nsBaseCommandController>
|
||||
CreateHTMLEditorDocStateController();
|
||||
|
||||
protected:
|
||||
virtual ~nsBaseCommandController();
|
||||
@@ -42,7 +44,7 @@ class nsBaseCommandController : public nsIController,
|
||||
nsISupports* mCommandContextRawPtr;
|
||||
|
||||
// Our reference to the command manager
|
||||
nsCOMPtr<nsIControllerCommandTable> mCommandTable;
|
||||
RefPtr<nsControllerCommandTable> mCommandTable;
|
||||
};
|
||||
|
||||
#endif /* nsBaseCommandController_h_ */
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
#include "mozilla/EditorController.h"
|
||||
#include "mozilla/HTMLEditorController.h"
|
||||
|
||||
nsresult NS_NewControllerCommandTable(nsIControllerCommandTable** aResult);
|
||||
|
||||
// this value is used to size the hash table. Just a sensible upper bound
|
||||
#define NUM_COMMANDS_LENGTH 32
|
||||
|
||||
@@ -186,11 +184,11 @@ nsControllerCommandTable::GetSupportedCommands(uint32_t* aCount,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
typedef nsresult (*CommandTableRegistrar)(nsIControllerCommandTable*);
|
||||
typedef nsresult (*CommandTableRegistrar)(nsControllerCommandTable*);
|
||||
|
||||
static already_AddRefed<nsIControllerCommandTable>
|
||||
static already_AddRefed<nsControllerCommandTable>
|
||||
CreateCommandTableWithCommands(CommandTableRegistrar aRegistrar) {
|
||||
nsCOMPtr<nsIControllerCommandTable> commandTable =
|
||||
RefPtr<nsControllerCommandTable> commandTable =
|
||||
new nsControllerCommandTable();
|
||||
|
||||
nsresult rv = aRegistrar(commandTable);
|
||||
@@ -203,48 +201,36 @@ CreateCommandTableWithCommands(CommandTableRegistrar aRegistrar) {
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIControllerCommandTable>
|
||||
already_AddRefed<nsControllerCommandTable>
|
||||
nsControllerCommandTable::CreateEditorCommandTable() {
|
||||
return CreateCommandTableWithCommands(
|
||||
EditorController::RegisterEditorCommands);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIControllerCommandTable>
|
||||
already_AddRefed<nsControllerCommandTable>
|
||||
nsControllerCommandTable::CreateEditingCommandTable() {
|
||||
return CreateCommandTableWithCommands(
|
||||
EditorController::RegisterEditingCommands);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIControllerCommandTable>
|
||||
already_AddRefed<nsControllerCommandTable>
|
||||
nsControllerCommandTable::CreateHTMLEditorCommandTable() {
|
||||
return CreateCommandTableWithCommands(
|
||||
HTMLEditorController::RegisterHTMLEditorCommands);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIControllerCommandTable>
|
||||
already_AddRefed<nsControllerCommandTable>
|
||||
nsControllerCommandTable::CreateHTMLEditorDocStateCommandTable() {
|
||||
return CreateCommandTableWithCommands(
|
||||
HTMLEditorController::RegisterEditorDocStateCommands);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIControllerCommandTable>
|
||||
already_AddRefed<nsControllerCommandTable>
|
||||
nsControllerCommandTable::CreateWindowCommandTable() {
|
||||
return CreateCommandTableWithCommands(
|
||||
nsWindowCommandRegistration::RegisterWindowCommands);
|
||||
}
|
||||
|
||||
nsresult NS_NewControllerCommandTable(nsIControllerCommandTable** aResult) {
|
||||
MOZ_ASSERT(aResult != nullptr, "null ptr");
|
||||
if (!aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
nsControllerCommandTable* newCommandTable = new nsControllerCommandTable();
|
||||
NS_ADDREF(newCommandTable);
|
||||
*aResult = newCommandTable;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -21,14 +21,13 @@ class nsControllerCommandTable final : public nsIControllerCommandTable,
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICONTROLLERCOMMANDTABLE
|
||||
|
||||
static already_AddRefed<nsIControllerCommandTable> CreateEditorCommandTable();
|
||||
static already_AddRefed<nsIControllerCommandTable>
|
||||
CreateEditingCommandTable();
|
||||
static already_AddRefed<nsIControllerCommandTable>
|
||||
static already_AddRefed<nsControllerCommandTable> CreateEditorCommandTable();
|
||||
static already_AddRefed<nsControllerCommandTable> CreateEditingCommandTable();
|
||||
static already_AddRefed<nsControllerCommandTable>
|
||||
CreateHTMLEditorCommandTable();
|
||||
static already_AddRefed<nsIControllerCommandTable>
|
||||
static already_AddRefed<nsControllerCommandTable>
|
||||
CreateHTMLEditorDocStateCommandTable();
|
||||
static already_AddRefed<nsIControllerCommandTable> CreateWindowCommandTable();
|
||||
static already_AddRefed<nsControllerCommandTable> CreateWindowCommandTable();
|
||||
|
||||
protected:
|
||||
virtual ~nsControllerCommandTable();
|
||||
@@ -40,4 +39,14 @@ class nsControllerCommandTable final : public nsIControllerCommandTable,
|
||||
bool mMutable;
|
||||
};
|
||||
|
||||
nsControllerCommandTable*
|
||||
nsIControllerCommandTable::AsControllerCommandTable() {
|
||||
return static_cast<nsControllerCommandTable*>(this);
|
||||
}
|
||||
|
||||
const nsControllerCommandTable*
|
||||
nsIControllerCommandTable::AsControllerCommandTable() const {
|
||||
return static_cast<const nsControllerCommandTable*>(this);
|
||||
}
|
||||
|
||||
#endif // nsControllerCommandTable_h_
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "nsIControllerCommand.idl"
|
||||
#include "nsICommandParams.idl"
|
||||
|
||||
%{C++
|
||||
class nsControllerCommandTable;
|
||||
%}
|
||||
|
||||
/**
|
||||
* nsIControllerCommandTable
|
||||
*
|
||||
@@ -18,7 +22,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
[scriptable, uuid(c847f90e-b8f3-49db-a4df-8867831f2800)]
|
||||
[scriptable, builtinclass, uuid(c847f90e-b8f3-49db-a4df-8867831f2800)]
|
||||
interface nsIControllerCommandTable : nsISupports
|
||||
{
|
||||
/**
|
||||
@@ -87,5 +91,14 @@ interface nsIControllerCommandTable : nsISupports
|
||||
|
||||
void getSupportedCommands(out unsigned long count,
|
||||
[array, size_is(count), retval] out string commands);
|
||||
|
||||
%{C++
|
||||
/**
|
||||
* In order to avoid circular dependency issues, these methods are defined
|
||||
* in nsControllerCommandTable.h. Consumers need to #include that header.
|
||||
*/
|
||||
inline nsControllerCommandTable* AsControllerCommandTable();
|
||||
inline const nsControllerCommandTable* AsControllerCommandTable() const;
|
||||
%}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user