michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: #include "nsIFactory.h" michael@0: #include "nsISupports.h" michael@0: #include "nsdefs.h" michael@0: #include "nsWidgetsCID.h" michael@0: #include "nsAppShell.h" michael@0: #include "nsAppShellSingleton.h" michael@0: #include "mozilla/ModuleUtils.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsIdleServiceWin.h" michael@0: #include "nsLookAndFeel.h" michael@0: #include "nsScreenManagerWin.h" michael@0: #include "nsSound.h" michael@0: #include "WinMouseScrollHandler.h" michael@0: #include "KeyboardLayout.h" michael@0: #include "GfxInfo.h" michael@0: #include "nsToolkit.h" michael@0: michael@0: // Modules that switch out based on the environment michael@0: #include "nsXULAppAPI.h" michael@0: // Desktop michael@0: #include "nsFilePicker.h" // needs to be included before other shobjidl.h includes michael@0: #include "nsColorPicker.h" michael@0: #include "nsNativeThemeWin.h" michael@0: #include "nsWindow.h" michael@0: // Content processes michael@0: #include "nsFilePickerProxy.h" michael@0: // Metro michael@0: #ifdef MOZ_METRO michael@0: #include "winrt/MetroAppShell.h" michael@0: #include "winrt/MetroWidget.h" michael@0: #include "winrt/nsMetroFilePicker.h" michael@0: #include "winrt/nsWinMetroUtils.h" michael@0: #endif michael@0: michael@0: // Drag & Drop, Clipboard michael@0: #include "nsClipboardHelper.h" michael@0: #include "nsClipboard.h" michael@0: #include "nsBidiKeyboard.h" michael@0: #include "nsDragService.h" michael@0: #include "nsTransferable.h" michael@0: #include "nsHTMLFormatConverter.h" michael@0: michael@0: #include "WinTaskbar.h" michael@0: #include "JumpListBuilder.h" michael@0: #include "JumpListItem.h" michael@0: michael@0: #ifdef NS_PRINTING michael@0: #include "nsDeviceContextSpecWin.h" michael@0: #include "nsPrintOptionsWin.h" michael@0: #include "nsPrintSession.h" michael@0: #endif michael@0: michael@0: #include "mozilla/Module.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::widget; michael@0: michael@0: static nsresult michael@0: WindowConstructor(nsISupports *aOuter, REFNSIID aIID, michael@0: void **aResult) michael@0: { michael@0: *aResult = nullptr; michael@0: if (aOuter != nullptr) { michael@0: return NS_ERROR_NO_AGGREGATION; michael@0: } michael@0: nsCOMPtr widget; michael@0: michael@0: if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { michael@0: #ifdef MOZ_METRO michael@0: widget = new MetroWidget; michael@0: #else michael@0: NS_RUNTIMEABORT("build does not support metro."); michael@0: #endif michael@0: } else { michael@0: widget = new nsWindow; michael@0: } michael@0: michael@0: return widget->QueryInterface(aIID, aResult); michael@0: } michael@0: michael@0: static nsresult michael@0: ChildWindowConstructor(nsISupports *aOuter, REFNSIID aIID, michael@0: void **aResult) michael@0: { michael@0: *aResult = nullptr; michael@0: if (aOuter != nullptr) { michael@0: return NS_ERROR_NO_AGGREGATION; michael@0: } michael@0: nsCOMPtr widget; michael@0: michael@0: if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { michael@0: return NS_NOINTERFACE; michael@0: } else { michael@0: widget = new ChildWindow; michael@0: } michael@0: michael@0: return widget->QueryInterface(aIID, aResult); michael@0: } michael@0: michael@0: static nsresult michael@0: FilePickerConstructor(nsISupports *aOuter, REFNSIID aIID, michael@0: void **aResult) michael@0: { michael@0: *aResult = nullptr; michael@0: if (aOuter != nullptr) { michael@0: return NS_ERROR_NO_AGGREGATION; michael@0: } michael@0: nsCOMPtr picker; michael@0: michael@0: if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { michael@0: #ifdef MOZ_METRO michael@0: picker = new nsMetroFilePicker; michael@0: #else michael@0: NS_RUNTIMEABORT("build does not support metro."); michael@0: #endif michael@0: } else { michael@0: picker = new nsFilePicker; michael@0: } michael@0: return picker->QueryInterface(aIID, aResult); michael@0: } michael@0: michael@0: static nsresult michael@0: ColorPickerConstructor(nsISupports *aOuter, REFNSIID aIID, michael@0: void **aResult) michael@0: { michael@0: *aResult = nullptr; michael@0: if (aOuter != nullptr) { michael@0: return NS_ERROR_NO_AGGREGATION; michael@0: } michael@0: nsCOMPtr picker; michael@0: michael@0: if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { michael@0: #ifdef MOZ_METRO michael@0: // TODO michael@0: // picker = new nsMetroColorPicker; michael@0: NS_ERROR("metro color picker isn't implemented currently"); michael@0: return NS_ERROR_NO_INTERFACE; michael@0: #else michael@0: NS_RUNTIMEABORT("build does not support metro."); michael@0: #endif michael@0: } else { michael@0: picker = new nsColorPicker; michael@0: } michael@0: return picker->QueryInterface(aIID, aResult); michael@0: } michael@0: michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerWin) michael@0: NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIdleServiceWin, nsIdleServiceWin::GetInstance) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(WinTaskbar) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListBuilder) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListItem) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListSeparator) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListLink) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListShortcut) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard) michael@0: #ifdef MOZ_METRO michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsWinMetroUtils) michael@0: #endif michael@0: #ifdef NS_PRINTING michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsWin, Init) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorWin) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecWin) michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: namespace widget { michael@0: // This constructor should really be shared with all platforms. michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(GfxInfo, Init) michael@0: } michael@0: } michael@0: michael@0: NS_DEFINE_NAMED_CID(NS_WINDOW_CID); michael@0: NS_DEFINE_NAMED_CID(NS_CHILD_CID); michael@0: NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_COLORPICKER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_APPSHELL_CID); michael@0: NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_GFXINFO_CID); michael@0: NS_DEFINE_NAMED_CID(NS_THEMERENDERER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID); michael@0: NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID); michael@0: NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_SOUND_CID); michael@0: NS_DEFINE_NAMED_CID(NS_TRANSFERABLE_CID); michael@0: NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_WIN_TASKBAR_CID); michael@0: NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTBUILDER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTITEM_CID); michael@0: NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTSEPARATOR_CID); michael@0: NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTLINK_CID); michael@0: NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTSHORTCUT_CID); michael@0: #ifdef MOZ_METRO michael@0: NS_DEFINE_NAMED_CID(NS_WIN_METROUTILS_CID); michael@0: #endif michael@0: NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID); michael@0: NS_DEFINE_NAMED_CID(NS_BIDIKEYBOARD_CID); michael@0: #ifdef NS_PRINTING michael@0: NS_DEFINE_NAMED_CID(NS_PRINTSETTINGSSERVICE_CID); michael@0: NS_DEFINE_NAMED_CID(NS_PRINTER_ENUMERATOR_CID); michael@0: NS_DEFINE_NAMED_CID(NS_PRINTSESSION_CID); michael@0: NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_SPEC_CID); michael@0: #endif michael@0: michael@0: michael@0: static const mozilla::Module::CIDEntry kWidgetCIDs[] = { michael@0: { &kNS_WINDOW_CID, false, nullptr, WindowConstructor }, michael@0: { &kNS_CHILD_CID, false, nullptr, ChildWindowConstructor }, michael@0: { &kNS_FILEPICKER_CID, false, nullptr, FilePickerConstructor, Module::MAIN_PROCESS_ONLY }, michael@0: { &kNS_COLORPICKER_CID, false, nullptr, ColorPickerConstructor, Module::MAIN_PROCESS_ONLY }, michael@0: { &kNS_APPSHELL_CID, false, nullptr, nsAppShellConstructor }, michael@0: { &kNS_SCREENMANAGER_CID, false, nullptr, nsScreenManagerWinConstructor }, michael@0: { &kNS_GFXINFO_CID, false, nullptr, GfxInfoConstructor }, michael@0: { &kNS_THEMERENDERER_CID, false, nullptr, NS_NewNativeTheme }, michael@0: { &kNS_IDLE_SERVICE_CID, false, nullptr, nsIdleServiceWinConstructor }, michael@0: { &kNS_CLIPBOARD_CID, false, nullptr, nsClipboardConstructor, Module::MAIN_PROCESS_ONLY }, michael@0: { &kNS_CLIPBOARDHELPER_CID, false, nullptr, nsClipboardHelperConstructor }, michael@0: { &kNS_SOUND_CID, false, nullptr, nsSoundConstructor, Module::MAIN_PROCESS_ONLY }, michael@0: { &kNS_TRANSFERABLE_CID, false, nullptr, nsTransferableConstructor }, michael@0: { &kNS_HTMLFORMATCONVERTER_CID, false, nullptr, nsHTMLFormatConverterConstructor }, michael@0: { &kNS_WIN_TASKBAR_CID, false, nullptr, WinTaskbarConstructor }, michael@0: { &kNS_WIN_JUMPLISTBUILDER_CID, false, nullptr, JumpListBuilderConstructor }, michael@0: { &kNS_WIN_JUMPLISTITEM_CID, false, nullptr, JumpListItemConstructor }, michael@0: { &kNS_WIN_JUMPLISTSEPARATOR_CID, false, nullptr, JumpListSeparatorConstructor }, michael@0: { &kNS_WIN_JUMPLISTLINK_CID, false, nullptr, JumpListLinkConstructor }, michael@0: { &kNS_WIN_JUMPLISTSHORTCUT_CID, false, nullptr, JumpListShortcutConstructor }, michael@0: { &kNS_DRAGSERVICE_CID, false, nullptr, nsDragServiceConstructor, Module::MAIN_PROCESS_ONLY }, michael@0: { &kNS_BIDIKEYBOARD_CID, false, nullptr, nsBidiKeyboardConstructor }, michael@0: #ifdef MOZ_METRO michael@0: { &kNS_WIN_METROUTILS_CID, false, nullptr, nsWinMetroUtilsConstructor }, michael@0: #endif michael@0: #ifdef NS_PRINTING michael@0: { &kNS_PRINTSETTINGSSERVICE_CID, false, nullptr, nsPrintOptionsWinConstructor }, michael@0: { &kNS_PRINTER_ENUMERATOR_CID, false, nullptr, nsPrinterEnumeratorWinConstructor, michael@0: Module::MAIN_PROCESS_ONLY }, michael@0: { &kNS_PRINTSESSION_CID, false, nullptr, nsPrintSessionConstructor, michael@0: Module::MAIN_PROCESS_ONLY }, michael@0: { &kNS_DEVICE_CONTEXT_SPEC_CID, false, nullptr, nsDeviceContextSpecWinConstructor, michael@0: Module::MAIN_PROCESS_ONLY }, michael@0: #endif michael@0: { nullptr } michael@0: }; michael@0: michael@0: static const mozilla::Module::ContractIDEntry kWidgetContracts[] = { michael@0: { "@mozilla.org/widgets/window/win;1", &kNS_WINDOW_CID }, michael@0: { "@mozilla.org/widgets/child_window/win;1", &kNS_CHILD_CID }, michael@0: { "@mozilla.org/filepicker;1", &kNS_FILEPICKER_CID, Module::MAIN_PROCESS_ONLY }, michael@0: { "@mozilla.org/colorpicker;1", &kNS_COLORPICKER_CID, Module::MAIN_PROCESS_ONLY }, michael@0: { "@mozilla.org/widget/appshell/win;1", &kNS_APPSHELL_CID }, michael@0: { "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID }, michael@0: { "@mozilla.org/gfx/info;1", &kNS_GFXINFO_CID }, michael@0: { "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID }, michael@0: { "@mozilla.org/widget/idleservice;1", &kNS_IDLE_SERVICE_CID }, michael@0: { "@mozilla.org/widget/clipboard;1", &kNS_CLIPBOARD_CID, Module::MAIN_PROCESS_ONLY }, michael@0: { "@mozilla.org/widget/clipboardhelper;1", &kNS_CLIPBOARDHELPER_CID }, michael@0: { "@mozilla.org/sound;1", &kNS_SOUND_CID, Module::MAIN_PROCESS_ONLY }, michael@0: { "@mozilla.org/widget/transferable;1", &kNS_TRANSFERABLE_CID }, michael@0: { "@mozilla.org/widget/htmlformatconverter;1", &kNS_HTMLFORMATCONVERTER_CID }, michael@0: { "@mozilla.org/windows-taskbar;1", &kNS_WIN_TASKBAR_CID }, michael@0: { "@mozilla.org/windows-jumplistbuilder;1", &kNS_WIN_JUMPLISTBUILDER_CID }, michael@0: { "@mozilla.org/windows-jumplistitem;1", &kNS_WIN_JUMPLISTITEM_CID }, michael@0: { "@mozilla.org/windows-jumplistseparator;1", &kNS_WIN_JUMPLISTSEPARATOR_CID }, michael@0: { "@mozilla.org/windows-jumplistlink;1", &kNS_WIN_JUMPLISTLINK_CID }, michael@0: { "@mozilla.org/windows-jumplistshortcut;1", &kNS_WIN_JUMPLISTSHORTCUT_CID }, michael@0: { "@mozilla.org/widget/dragservice;1", &kNS_DRAGSERVICE_CID, Module::MAIN_PROCESS_ONLY }, michael@0: { "@mozilla.org/widget/bidikeyboard;1", &kNS_BIDIKEYBOARD_CID }, michael@0: #ifdef MOZ_METRO michael@0: { "@mozilla.org/windows-metroutils;1", &kNS_WIN_METROUTILS_CID }, michael@0: #endif michael@0: #ifdef NS_PRINTING michael@0: { "@mozilla.org/gfx/printsettings-service;1", &kNS_PRINTSETTINGSSERVICE_CID }, michael@0: { "@mozilla.org/gfx/printerenumerator;1", &kNS_PRINTER_ENUMERATOR_CID, michael@0: Module::MAIN_PROCESS_ONLY }, michael@0: { "@mozilla.org/gfx/printsession;1", &kNS_PRINTSESSION_CID, michael@0: Module::MAIN_PROCESS_ONLY }, michael@0: { "@mozilla.org/gfx/devicecontextspec;1", &kNS_DEVICE_CONTEXT_SPEC_CID, michael@0: Module::MAIN_PROCESS_ONLY }, michael@0: #endif michael@0: { nullptr } michael@0: }; michael@0: michael@0: static void michael@0: nsWidgetWindowsModuleDtor() michael@0: { michael@0: KeyboardLayout::Shutdown(); michael@0: MouseScrollHandler::Shutdown(); michael@0: nsLookAndFeel::Shutdown(); michael@0: nsToolkit::Shutdown(); michael@0: nsAppShellShutdown(); michael@0: } michael@0: michael@0: static const mozilla::Module kWidgetModule = { michael@0: mozilla::Module::kVersion, michael@0: kWidgetCIDs, michael@0: kWidgetContracts, michael@0: nullptr, michael@0: nullptr, michael@0: nsAppShellInit, michael@0: nsWidgetWindowsModuleDtor michael@0: }; michael@0: michael@0: NSMODULE_DEFN(nsWidgetModule) = &kWidgetModule;