mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1489790 - Part 12: Refactor the common code out of the controller/commandtable constructor functions; r=baku
Differential Revision: https://phabricator.services.mozilla.com/D5367
This commit is contained in:
parent
1675c25fae
commit
85826ab00c
@ -181,107 +181,60 @@ nsBaseCommandController::GetSupportedCommands(uint32_t* aCount,
|
||||
return mCommandTable->GetSupportedCommands(aCount, aCommands);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIController>
|
||||
nsBaseCommandController::CreateWindowController()
|
||||
typedef already_AddRefed<nsIControllerCommandTable> (*CommandTableCreatorFn)();
|
||||
|
||||
static already_AddRefed<nsIController>
|
||||
CreateControllerWithSingletonCommandTable(CommandTableCreatorFn aCreatorFn)
|
||||
{
|
||||
nsCOMPtr<nsIController> controller = new nsBaseCommandController();
|
||||
|
||||
nsCOMPtr<nsIControllerCommandTable> windowCommandTable =
|
||||
nsControllerCommandTable::CreateWindowCommandTable();
|
||||
nsCOMPtr<nsIControllerCommandTable> commandTable = aCreatorFn();
|
||||
if (!commandTable) return nullptr;
|
||||
|
||||
// this is a singleton; make it immutable
|
||||
windowCommandTable->MakeImmutable();
|
||||
commandTable->MakeImmutable();
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
|
||||
if (NS_FAILED(rv)) return nullptr;
|
||||
|
||||
rv = controllerContext->Init(windowCommandTable);
|
||||
rv = controllerContext->Init(commandTable);
|
||||
if (NS_FAILED(rv)) return nullptr;
|
||||
|
||||
return controller.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIController>
|
||||
nsBaseCommandController::CreateWindowController()
|
||||
{
|
||||
return CreateControllerWithSingletonCommandTable(
|
||||
nsControllerCommandTable::CreateWindowCommandTable);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIController>
|
||||
nsBaseCommandController::CreateEditorController()
|
||||
{
|
||||
nsCOMPtr<nsIController> controller = new nsBaseCommandController();
|
||||
|
||||
nsCOMPtr<nsIControllerCommandTable> editorCommandTable =
|
||||
nsControllerCommandTable::CreateEditorCommandTable();
|
||||
|
||||
// this guy is a singleton, so make it immutable
|
||||
editorCommandTable->MakeImmutable();
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
|
||||
if (NS_FAILED(rv)) return nullptr;
|
||||
|
||||
rv = controllerContext->Init(editorCommandTable);
|
||||
if (NS_FAILED(rv)) return nullptr;
|
||||
|
||||
return controller.forget();
|
||||
return CreateControllerWithSingletonCommandTable(
|
||||
nsControllerCommandTable::CreateEditorCommandTable);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIController>
|
||||
nsBaseCommandController::CreateEditingController()
|
||||
{
|
||||
nsCOMPtr<nsIController> controller = new nsBaseCommandController();
|
||||
|
||||
nsCOMPtr<nsIControllerCommandTable> editingCommandTable =
|
||||
nsControllerCommandTable::CreateEditingCommandTable();
|
||||
|
||||
// this guy is a singleton, so make it immutable
|
||||
editingCommandTable->MakeImmutable();
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
|
||||
if (NS_FAILED(rv)) return nullptr;
|
||||
|
||||
rv = controllerContext->Init(editingCommandTable);
|
||||
if (NS_FAILED(rv)) return nullptr;
|
||||
|
||||
return controller.forget();
|
||||
return CreateControllerWithSingletonCommandTable(
|
||||
nsControllerCommandTable::CreateEditingCommandTable);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIController>
|
||||
nsBaseCommandController::CreateHTMLEditorController()
|
||||
{
|
||||
nsCOMPtr<nsIController> controller = new nsBaseCommandController();
|
||||
|
||||
nsCOMPtr<nsIControllerCommandTable> composerCommandTable =
|
||||
nsControllerCommandTable::CreateHTMLEditorCommandTable();
|
||||
|
||||
// this guy is a singleton, so make it immutable
|
||||
composerCommandTable->MakeImmutable();
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
rv = controllerContext->Init(composerCommandTable);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
return controller.forget();
|
||||
return CreateControllerWithSingletonCommandTable(
|
||||
nsControllerCommandTable::CreateHTMLEditorCommandTable);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIController>
|
||||
nsBaseCommandController::CreateHTMLEditorDocStateController()
|
||||
{
|
||||
nsCOMPtr<nsIController> controller = new nsBaseCommandController();
|
||||
|
||||
nsCOMPtr<nsIControllerCommandTable> composerCommandTable =
|
||||
nsControllerCommandTable::CreateHTMLEditorDocStateCommandTable();
|
||||
|
||||
// this guy is a singleton, so make it immutable
|
||||
composerCommandTable->MakeImmutable();
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
rv = controllerContext->Init(composerCommandTable);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
return controller.forget();
|
||||
return CreateControllerWithSingletonCommandTable(
|
||||
nsControllerCommandTable::CreateHTMLEditorDocStateCommandTable);
|
||||
}
|
||||
|
@ -197,14 +197,15 @@ nsControllerCommandTable::GetSupportedCommands(uint32_t* aCount,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIControllerCommandTable>
|
||||
nsControllerCommandTable::CreateEditorCommandTable()
|
||||
typedef nsresult (*CommandTableRegistrar)(nsIControllerCommandTable*);
|
||||
|
||||
static already_AddRefed<nsIControllerCommandTable>
|
||||
CreateCommandTableWithCommands(CommandTableRegistrar aRegistrar)
|
||||
{
|
||||
nsCOMPtr<nsIControllerCommandTable> commandTable =
|
||||
new nsControllerCommandTable();
|
||||
|
||||
nsresult rv = EditorController::RegisterEditorCommands(commandTable);
|
||||
nsresult rv = aRegistrar(commandTable);
|
||||
if (NS_FAILED(rv)) return nullptr;
|
||||
|
||||
// we don't know here whether we're being created as an instance,
|
||||
@ -213,67 +214,44 @@ nsControllerCommandTable::CreateEditorCommandTable()
|
||||
return commandTable.forget();
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIControllerCommandTable>
|
||||
nsControllerCommandTable::CreateEditorCommandTable()
|
||||
{
|
||||
return CreateCommandTableWithCommands(
|
||||
EditorController::RegisterEditorCommands);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIControllerCommandTable>
|
||||
nsControllerCommandTable::CreateEditingCommandTable()
|
||||
{
|
||||
nsCOMPtr<nsIControllerCommandTable> commandTable =
|
||||
new nsControllerCommandTable();
|
||||
|
||||
nsresult rv = EditorController::RegisterEditingCommands(commandTable);
|
||||
if (NS_FAILED(rv)) return nullptr;
|
||||
|
||||
// we don't know here whether we're being created as an instance,
|
||||
// or a service, so we can't become immutable
|
||||
|
||||
return commandTable.forget();
|
||||
return CreateCommandTableWithCommands(
|
||||
EditorController::RegisterEditingCommands);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIControllerCommandTable>
|
||||
nsControllerCommandTable::CreateHTMLEditorCommandTable()
|
||||
{
|
||||
nsCOMPtr<nsIControllerCommandTable> commandTable =
|
||||
new nsControllerCommandTable();
|
||||
|
||||
nsresult rv = mozilla::HTMLEditorController::RegisterHTMLEditorCommands(commandTable);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
// we don't know here whether we're being created as an instance,
|
||||
// or a service, so we can't become immutable
|
||||
|
||||
return commandTable.forget();
|
||||
return CreateCommandTableWithCommands(
|
||||
HTMLEditorController::RegisterHTMLEditorCommands);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIControllerCommandTable>
|
||||
nsControllerCommandTable::CreateHTMLEditorDocStateCommandTable()
|
||||
{
|
||||
nsCOMPtr<nsIControllerCommandTable> commandTable =
|
||||
new nsControllerCommandTable();
|
||||
|
||||
nsresult rv = mozilla::HTMLEditorController::RegisterEditorDocStateCommands(
|
||||
commandTable);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
// we don't know here whether we're being created as an instance,
|
||||
// or a service, so we can't become immutable
|
||||
|
||||
return commandTable.forget();
|
||||
return CreateCommandTableWithCommands(
|
||||
HTMLEditorController::RegisterEditorDocStateCommands);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIControllerCommandTable>
|
||||
nsControllerCommandTable::CreateWindowCommandTable()
|
||||
{
|
||||
nsCOMPtr<nsIControllerCommandTable> commandTable =
|
||||
new nsControllerCommandTable();
|
||||
|
||||
nsresult rv =
|
||||
nsWindowCommandRegistration::RegisterWindowCommands(commandTable);
|
||||
if (NS_FAILED(rv)) return nullptr;
|
||||
|
||||
return commandTable.forget();
|
||||
return CreateCommandTableWithCommands(
|
||||
nsWindowCommandRegistration::RegisterWindowCommands);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
Loading…
Reference in New Issue
Block a user