michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim:expandtab:shiftwidth=4:tabstop=4: michael@0: */ 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: #include "mozilla/ModuleUtils.h" michael@0: #include "NativeKeyBindings.h" michael@0: #include "nsWidgetsCID.h" michael@0: #include "nsAppShell.h" michael@0: #include "nsAppShellSingleton.h" michael@0: #include "nsBaseWidget.h" michael@0: #include "nsLookAndFeel.h" michael@0: #include "nsWindow.h" michael@0: #include "nsTransferable.h" michael@0: #include "nsHTMLFormatConverter.h" michael@0: #ifdef MOZ_X11 michael@0: #include "nsClipboardHelper.h" michael@0: #include "nsClipboard.h" michael@0: #include "nsDragService.h" michael@0: #endif michael@0: #include "nsColorPicker.h" michael@0: #include "nsFilePicker.h" michael@0: #include "nsSound.h" michael@0: #include "nsBidiKeyboard.h" michael@0: #include "nsScreenManagerGtk.h" michael@0: #include "nsGTKToolkit.h" michael@0: michael@0: #ifdef NS_PRINTING michael@0: #include "nsPrintOptionsGTK.h" michael@0: #include "nsPrintSession.h" michael@0: #include "nsDeviceContextSpecG.h" michael@0: #endif michael@0: michael@0: #include "mozilla/Preferences.h" michael@0: michael@0: #include "nsImageToPixbuf.h" michael@0: #include "nsPrintDialogGTK.h" michael@0: michael@0: #if defined(MOZ_X11) michael@0: #include "nsIdleServiceGTK.h" michael@0: #include "GfxInfoX11.h" michael@0: #endif michael@0: michael@0: #include "nsNativeThemeGTK.h" michael@0: michael@0: #include "nsIComponentRegistrar.h" michael@0: #include "nsComponentManagerUtils.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "mozilla/gfx/2D.h" michael@0: #include michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::widget; michael@0: michael@0: /* from nsFilePicker.js */ michael@0: #define XULFILEPICKER_CID \ michael@0: { 0x54ae32f8, 0x1dd2, 0x11b2, \ michael@0: { 0xa2, 0x09, 0xdf, 0x7c, 0x50, 0x53, 0x70, 0xf8} } michael@0: static NS_DEFINE_CID(kXULFilePickerCID, XULFILEPICKER_CID); michael@0: michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildWindow) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter) michael@0: #ifdef MOZ_X11 michael@0: NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIdleServiceGTK, nsIdleServiceGTK::GetInstance) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsClipboard, Init) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService) michael@0: #endif michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerGtk) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageToPixbuf) michael@0: michael@0: michael@0: // from nsWindow.cpp michael@0: extern bool gDisableNativeTheme; michael@0: michael@0: static nsresult michael@0: nsNativeThemeGTKConstructor(nsISupports *aOuter, REFNSIID aIID, michael@0: void **aResult) michael@0: { michael@0: nsresult rv; michael@0: nsNativeThemeGTK * inst; michael@0: michael@0: if (gDisableNativeTheme) michael@0: return NS_ERROR_NO_INTERFACE; michael@0: michael@0: *aResult = nullptr; michael@0: if (nullptr != aOuter) { michael@0: rv = NS_ERROR_NO_AGGREGATION; michael@0: return rv; michael@0: } michael@0: michael@0: inst = new nsNativeThemeGTK(); michael@0: if (nullptr == inst) { michael@0: rv = NS_ERROR_OUT_OF_MEMORY; michael@0: return rv; michael@0: } michael@0: NS_ADDREF(inst); michael@0: rv = inst->QueryInterface(aIID, aResult); michael@0: NS_RELEASE(inst); michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: #if defined(MOZ_X11) 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: #endif michael@0: michael@0: #ifdef NS_PRINTING michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecGTK) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsGTK, Init) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorGTK) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintDialogServiceGTK, Init) michael@0: #endif michael@0: michael@0: static nsresult michael@0: nsFilePickerConstructor(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: michael@0: bool allowPlatformPicker = michael@0: Preferences::GetBool("ui.allow_platform_file_picker", true); michael@0: michael@0: nsCOMPtr picker; michael@0: if (allowPlatformPicker) { michael@0: picker = new nsFilePicker; michael@0: } else { michael@0: picker = do_CreateInstance(kXULFilePickerCID); michael@0: } michael@0: michael@0: if (!picker) { michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: michael@0: return picker->QueryInterface(aIID, aResult); michael@0: } michael@0: michael@0: static nsresult michael@0: nsColorPickerConstructor(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: michael@0: nsCOMPtr picker = new nsColorPicker; michael@0: michael@0: if (!picker) { michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: michael@0: return picker->QueryInterface(aIID, aResult); 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_APPSHELL_CID); michael@0: NS_DEFINE_NAMED_CID(NS_COLORPICKER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_SOUND_CID); michael@0: NS_DEFINE_NAMED_CID(NS_TRANSFERABLE_CID); michael@0: #ifdef MOZ_X11 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_DRAGSERVICE_CID); michael@0: #endif michael@0: NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_BIDIKEYBOARD_CID); michael@0: NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_THEMERENDERER_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: NS_DEFINE_NAMED_CID(NS_PRINTDIALOGSERVICE_CID); michael@0: #endif michael@0: NS_DEFINE_NAMED_CID(NS_IMAGE_TO_PIXBUF_CID); michael@0: #if defined(MOZ_X11) michael@0: NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID); michael@0: NS_DEFINE_NAMED_CID(NS_GFXINFO_CID); michael@0: #endif michael@0: michael@0: michael@0: static const mozilla::Module::CIDEntry kWidgetCIDs[] = { michael@0: { &kNS_WINDOW_CID, false, nullptr, nsWindowConstructor }, michael@0: { &kNS_CHILD_CID, false, nullptr, nsChildWindowConstructor }, michael@0: { &kNS_APPSHELL_CID, false, nullptr, nsAppShellConstructor }, michael@0: { &kNS_COLORPICKER_CID, false, nullptr, nsColorPickerConstructor, Module::MAIN_PROCESS_ONLY }, michael@0: { &kNS_FILEPICKER_CID, false, nullptr, nsFilePickerConstructor, Module::MAIN_PROCESS_ONLY }, michael@0: { &kNS_SOUND_CID, false, nullptr, nsSoundConstructor, Module::MAIN_PROCESS_ONLY }, michael@0: { &kNS_TRANSFERABLE_CID, false, nullptr, nsTransferableConstructor }, michael@0: #ifdef MOZ_X11 michael@0: { &kNS_CLIPBOARD_CID, false, nullptr, nsClipboardConstructor, Module::MAIN_PROCESS_ONLY }, michael@0: { &kNS_CLIPBOARDHELPER_CID, false, nullptr, nsClipboardHelperConstructor }, michael@0: { &kNS_DRAGSERVICE_CID, false, nullptr, nsDragServiceConstructor, Module::MAIN_PROCESS_ONLY }, michael@0: #endif michael@0: { &kNS_HTMLFORMATCONVERTER_CID, false, nullptr, nsHTMLFormatConverterConstructor }, michael@0: { &kNS_BIDIKEYBOARD_CID, false, nullptr, nsBidiKeyboardConstructor }, michael@0: { &kNS_SCREENMANAGER_CID, false, nullptr, nsScreenManagerGtkConstructor }, michael@0: { &kNS_THEMERENDERER_CID, false, nullptr, nsNativeThemeGTKConstructor }, michael@0: #ifdef NS_PRINTING michael@0: { &kNS_PRINTSETTINGSSERVICE_CID, false, nullptr, nsPrintOptionsGTKConstructor }, michael@0: { &kNS_PRINTER_ENUMERATOR_CID, false, nullptr, nsPrinterEnumeratorGTKConstructor, 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, nsDeviceContextSpecGTKConstructor, michael@0: Module::MAIN_PROCESS_ONLY }, michael@0: { &kNS_PRINTDIALOGSERVICE_CID, false, nullptr, nsPrintDialogServiceGTKConstructor, michael@0: Module::MAIN_PROCESS_ONLY }, michael@0: #endif michael@0: { &kNS_IMAGE_TO_PIXBUF_CID, false, nullptr, nsImageToPixbufConstructor }, michael@0: #if defined(MOZ_X11) michael@0: { &kNS_IDLE_SERVICE_CID, false, nullptr, nsIdleServiceGTKConstructor }, michael@0: { &kNS_GFXINFO_CID, false, nullptr, mozilla::widget::GfxInfoConstructor }, michael@0: #endif michael@0: { nullptr } michael@0: }; michael@0: michael@0: static const mozilla::Module::ContractIDEntry kWidgetContracts[] = { michael@0: { "@mozilla.org/widget/window/gtk;1", &kNS_WINDOW_CID }, michael@0: { "@mozilla.org/widgets/child_window/gtk;1", &kNS_CHILD_CID }, michael@0: { "@mozilla.org/widget/appshell/gtk;1", &kNS_APPSHELL_CID }, michael@0: { "@mozilla.org/colorpicker;1", &kNS_COLORPICKER_CID, Module::MAIN_PROCESS_ONLY }, michael@0: { "@mozilla.org/filepicker;1", &kNS_FILEPICKER_CID, Module::MAIN_PROCESS_ONLY }, 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: #ifdef MOZ_X11 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/widget/dragservice;1", &kNS_DRAGSERVICE_CID, Module::MAIN_PROCESS_ONLY }, michael@0: #endif michael@0: { "@mozilla.org/widget/htmlformatconverter;1", &kNS_HTMLFORMATCONVERTER_CID }, michael@0: { "@mozilla.org/widget/bidikeyboard;1", &kNS_BIDIKEYBOARD_CID }, michael@0: { "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID }, michael@0: { "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID }, 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: { NS_PRINTDIALOGSERVICE_CONTRACTID, &kNS_PRINTDIALOGSERVICE_CID, michael@0: Module::MAIN_PROCESS_ONLY }, michael@0: #endif michael@0: { "@mozilla.org/widget/image-to-gdk-pixbuf;1", &kNS_IMAGE_TO_PIXBUF_CID }, michael@0: #if defined(MOZ_X11) michael@0: { "@mozilla.org/widget/idleservice;1", &kNS_IDLE_SERVICE_CID }, michael@0: { "@mozilla.org/gfx/info;1", &kNS_GFXINFO_CID }, michael@0: #endif michael@0: { nullptr } michael@0: }; michael@0: michael@0: static void michael@0: nsWidgetGtk2ModuleDtor() michael@0: { michael@0: NativeKeyBindings::Shutdown(); michael@0: nsLookAndFeel::Shutdown(); michael@0: nsFilePicker::Shutdown(); michael@0: nsSound::Shutdown(); michael@0: nsWindow::ReleaseGlobals(); michael@0: nsGTKToolkit::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: nsWidgetGtk2ModuleDtor michael@0: }; michael@0: michael@0: NSMODULE_DEFN(nsWidgetGtk2Module) = &kWidgetModule;