widget/windows/nsWidgetFactory.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 #include "nsIFactory.h"
michael@0 8 #include "nsISupports.h"
michael@0 9 #include "nsdefs.h"
michael@0 10 #include "nsWidgetsCID.h"
michael@0 11 #include "nsAppShell.h"
michael@0 12 #include "nsAppShellSingleton.h"
michael@0 13 #include "mozilla/ModuleUtils.h"
michael@0 14 #include "nsIServiceManager.h"
michael@0 15 #include "nsIdleServiceWin.h"
michael@0 16 #include "nsLookAndFeel.h"
michael@0 17 #include "nsScreenManagerWin.h"
michael@0 18 #include "nsSound.h"
michael@0 19 #include "WinMouseScrollHandler.h"
michael@0 20 #include "KeyboardLayout.h"
michael@0 21 #include "GfxInfo.h"
michael@0 22 #include "nsToolkit.h"
michael@0 23
michael@0 24 // Modules that switch out based on the environment
michael@0 25 #include "nsXULAppAPI.h"
michael@0 26 // Desktop
michael@0 27 #include "nsFilePicker.h" // needs to be included before other shobjidl.h includes
michael@0 28 #include "nsColorPicker.h"
michael@0 29 #include "nsNativeThemeWin.h"
michael@0 30 #include "nsWindow.h"
michael@0 31 // Content processes
michael@0 32 #include "nsFilePickerProxy.h"
michael@0 33 // Metro
michael@0 34 #ifdef MOZ_METRO
michael@0 35 #include "winrt/MetroAppShell.h"
michael@0 36 #include "winrt/MetroWidget.h"
michael@0 37 #include "winrt/nsMetroFilePicker.h"
michael@0 38 #include "winrt/nsWinMetroUtils.h"
michael@0 39 #endif
michael@0 40
michael@0 41 // Drag & Drop, Clipboard
michael@0 42 #include "nsClipboardHelper.h"
michael@0 43 #include "nsClipboard.h"
michael@0 44 #include "nsBidiKeyboard.h"
michael@0 45 #include "nsDragService.h"
michael@0 46 #include "nsTransferable.h"
michael@0 47 #include "nsHTMLFormatConverter.h"
michael@0 48
michael@0 49 #include "WinTaskbar.h"
michael@0 50 #include "JumpListBuilder.h"
michael@0 51 #include "JumpListItem.h"
michael@0 52
michael@0 53 #ifdef NS_PRINTING
michael@0 54 #include "nsDeviceContextSpecWin.h"
michael@0 55 #include "nsPrintOptionsWin.h"
michael@0 56 #include "nsPrintSession.h"
michael@0 57 #endif
michael@0 58
michael@0 59 #include "mozilla/Module.h"
michael@0 60
michael@0 61 using namespace mozilla;
michael@0 62 using namespace mozilla::widget;
michael@0 63
michael@0 64 static nsresult
michael@0 65 WindowConstructor(nsISupports *aOuter, REFNSIID aIID,
michael@0 66 void **aResult)
michael@0 67 {
michael@0 68 *aResult = nullptr;
michael@0 69 if (aOuter != nullptr) {
michael@0 70 return NS_ERROR_NO_AGGREGATION;
michael@0 71 }
michael@0 72 nsCOMPtr<nsIWidget> widget;
michael@0 73
michael@0 74 if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) {
michael@0 75 #ifdef MOZ_METRO
michael@0 76 widget = new MetroWidget;
michael@0 77 #else
michael@0 78 NS_RUNTIMEABORT("build does not support metro.");
michael@0 79 #endif
michael@0 80 } else {
michael@0 81 widget = new nsWindow;
michael@0 82 }
michael@0 83
michael@0 84 return widget->QueryInterface(aIID, aResult);
michael@0 85 }
michael@0 86
michael@0 87 static nsresult
michael@0 88 ChildWindowConstructor(nsISupports *aOuter, REFNSIID aIID,
michael@0 89 void **aResult)
michael@0 90 {
michael@0 91 *aResult = nullptr;
michael@0 92 if (aOuter != nullptr) {
michael@0 93 return NS_ERROR_NO_AGGREGATION;
michael@0 94 }
michael@0 95 nsCOMPtr<nsIWidget> widget;
michael@0 96
michael@0 97 if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) {
michael@0 98 return NS_NOINTERFACE;
michael@0 99 } else {
michael@0 100 widget = new ChildWindow;
michael@0 101 }
michael@0 102
michael@0 103 return widget->QueryInterface(aIID, aResult);
michael@0 104 }
michael@0 105
michael@0 106 static nsresult
michael@0 107 FilePickerConstructor(nsISupports *aOuter, REFNSIID aIID,
michael@0 108 void **aResult)
michael@0 109 {
michael@0 110 *aResult = nullptr;
michael@0 111 if (aOuter != nullptr) {
michael@0 112 return NS_ERROR_NO_AGGREGATION;
michael@0 113 }
michael@0 114 nsCOMPtr<nsIFilePicker> picker;
michael@0 115
michael@0 116 if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) {
michael@0 117 #ifdef MOZ_METRO
michael@0 118 picker = new nsMetroFilePicker;
michael@0 119 #else
michael@0 120 NS_RUNTIMEABORT("build does not support metro.");
michael@0 121 #endif
michael@0 122 } else {
michael@0 123 picker = new nsFilePicker;
michael@0 124 }
michael@0 125 return picker->QueryInterface(aIID, aResult);
michael@0 126 }
michael@0 127
michael@0 128 static nsresult
michael@0 129 ColorPickerConstructor(nsISupports *aOuter, REFNSIID aIID,
michael@0 130 void **aResult)
michael@0 131 {
michael@0 132 *aResult = nullptr;
michael@0 133 if (aOuter != nullptr) {
michael@0 134 return NS_ERROR_NO_AGGREGATION;
michael@0 135 }
michael@0 136 nsCOMPtr<nsIColorPicker> picker;
michael@0 137
michael@0 138 if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) {
michael@0 139 #ifdef MOZ_METRO
michael@0 140 // TODO
michael@0 141 // picker = new nsMetroColorPicker;
michael@0 142 NS_ERROR("metro color picker isn't implemented currently");
michael@0 143 return NS_ERROR_NO_INTERFACE;
michael@0 144 #else
michael@0 145 NS_RUNTIMEABORT("build does not support metro.");
michael@0 146 #endif
michael@0 147 } else {
michael@0 148 picker = new nsColorPicker;
michael@0 149 }
michael@0 150 return picker->QueryInterface(aIID, aResult);
michael@0 151 }
michael@0 152
michael@0 153 NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerWin)
michael@0 154 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIdleServiceWin, nsIdleServiceWin::GetInstance)
michael@0 155 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
michael@0 156 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
michael@0 157 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
michael@0 158 NS_GENERIC_FACTORY_CONSTRUCTOR(WinTaskbar)
michael@0 159 NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListBuilder)
michael@0 160 NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListItem)
michael@0 161 NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListSeparator)
michael@0 162 NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListLink)
michael@0 163 NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListShortcut)
michael@0 164 NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
michael@0 165 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
michael@0 166 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
michael@0 167 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
michael@0 168 #ifdef MOZ_METRO
michael@0 169 NS_GENERIC_FACTORY_CONSTRUCTOR(nsWinMetroUtils)
michael@0 170 #endif
michael@0 171 #ifdef NS_PRINTING
michael@0 172 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsWin, Init)
michael@0 173 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorWin)
michael@0 174 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
michael@0 175 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecWin)
michael@0 176 #endif
michael@0 177
michael@0 178 namespace mozilla {
michael@0 179 namespace widget {
michael@0 180 // This constructor should really be shared with all platforms.
michael@0 181 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(GfxInfo, Init)
michael@0 182 }
michael@0 183 }
michael@0 184
michael@0 185 NS_DEFINE_NAMED_CID(NS_WINDOW_CID);
michael@0 186 NS_DEFINE_NAMED_CID(NS_CHILD_CID);
michael@0 187 NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID);
michael@0 188 NS_DEFINE_NAMED_CID(NS_COLORPICKER_CID);
michael@0 189 NS_DEFINE_NAMED_CID(NS_APPSHELL_CID);
michael@0 190 NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID);
michael@0 191 NS_DEFINE_NAMED_CID(NS_GFXINFO_CID);
michael@0 192 NS_DEFINE_NAMED_CID(NS_THEMERENDERER_CID);
michael@0 193 NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID);
michael@0 194 NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID);
michael@0 195 NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID);
michael@0 196 NS_DEFINE_NAMED_CID(NS_SOUND_CID);
michael@0 197 NS_DEFINE_NAMED_CID(NS_TRANSFERABLE_CID);
michael@0 198 NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID);
michael@0 199 NS_DEFINE_NAMED_CID(NS_WIN_TASKBAR_CID);
michael@0 200 NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTBUILDER_CID);
michael@0 201 NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTITEM_CID);
michael@0 202 NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTSEPARATOR_CID);
michael@0 203 NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTLINK_CID);
michael@0 204 NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTSHORTCUT_CID);
michael@0 205 #ifdef MOZ_METRO
michael@0 206 NS_DEFINE_NAMED_CID(NS_WIN_METROUTILS_CID);
michael@0 207 #endif
michael@0 208 NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID);
michael@0 209 NS_DEFINE_NAMED_CID(NS_BIDIKEYBOARD_CID);
michael@0 210 #ifdef NS_PRINTING
michael@0 211 NS_DEFINE_NAMED_CID(NS_PRINTSETTINGSSERVICE_CID);
michael@0 212 NS_DEFINE_NAMED_CID(NS_PRINTER_ENUMERATOR_CID);
michael@0 213 NS_DEFINE_NAMED_CID(NS_PRINTSESSION_CID);
michael@0 214 NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_SPEC_CID);
michael@0 215 #endif
michael@0 216
michael@0 217
michael@0 218 static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
michael@0 219 { &kNS_WINDOW_CID, false, nullptr, WindowConstructor },
michael@0 220 { &kNS_CHILD_CID, false, nullptr, ChildWindowConstructor },
michael@0 221 { &kNS_FILEPICKER_CID, false, nullptr, FilePickerConstructor, Module::MAIN_PROCESS_ONLY },
michael@0 222 { &kNS_COLORPICKER_CID, false, nullptr, ColorPickerConstructor, Module::MAIN_PROCESS_ONLY },
michael@0 223 { &kNS_APPSHELL_CID, false, nullptr, nsAppShellConstructor },
michael@0 224 { &kNS_SCREENMANAGER_CID, false, nullptr, nsScreenManagerWinConstructor },
michael@0 225 { &kNS_GFXINFO_CID, false, nullptr, GfxInfoConstructor },
michael@0 226 { &kNS_THEMERENDERER_CID, false, nullptr, NS_NewNativeTheme },
michael@0 227 { &kNS_IDLE_SERVICE_CID, false, nullptr, nsIdleServiceWinConstructor },
michael@0 228 { &kNS_CLIPBOARD_CID, false, nullptr, nsClipboardConstructor, Module::MAIN_PROCESS_ONLY },
michael@0 229 { &kNS_CLIPBOARDHELPER_CID, false, nullptr, nsClipboardHelperConstructor },
michael@0 230 { &kNS_SOUND_CID, false, nullptr, nsSoundConstructor, Module::MAIN_PROCESS_ONLY },
michael@0 231 { &kNS_TRANSFERABLE_CID, false, nullptr, nsTransferableConstructor },
michael@0 232 { &kNS_HTMLFORMATCONVERTER_CID, false, nullptr, nsHTMLFormatConverterConstructor },
michael@0 233 { &kNS_WIN_TASKBAR_CID, false, nullptr, WinTaskbarConstructor },
michael@0 234 { &kNS_WIN_JUMPLISTBUILDER_CID, false, nullptr, JumpListBuilderConstructor },
michael@0 235 { &kNS_WIN_JUMPLISTITEM_CID, false, nullptr, JumpListItemConstructor },
michael@0 236 { &kNS_WIN_JUMPLISTSEPARATOR_CID, false, nullptr, JumpListSeparatorConstructor },
michael@0 237 { &kNS_WIN_JUMPLISTLINK_CID, false, nullptr, JumpListLinkConstructor },
michael@0 238 { &kNS_WIN_JUMPLISTSHORTCUT_CID, false, nullptr, JumpListShortcutConstructor },
michael@0 239 { &kNS_DRAGSERVICE_CID, false, nullptr, nsDragServiceConstructor, Module::MAIN_PROCESS_ONLY },
michael@0 240 { &kNS_BIDIKEYBOARD_CID, false, nullptr, nsBidiKeyboardConstructor },
michael@0 241 #ifdef MOZ_METRO
michael@0 242 { &kNS_WIN_METROUTILS_CID, false, nullptr, nsWinMetroUtilsConstructor },
michael@0 243 #endif
michael@0 244 #ifdef NS_PRINTING
michael@0 245 { &kNS_PRINTSETTINGSSERVICE_CID, false, nullptr, nsPrintOptionsWinConstructor },
michael@0 246 { &kNS_PRINTER_ENUMERATOR_CID, false, nullptr, nsPrinterEnumeratorWinConstructor,
michael@0 247 Module::MAIN_PROCESS_ONLY },
michael@0 248 { &kNS_PRINTSESSION_CID, false, nullptr, nsPrintSessionConstructor,
michael@0 249 Module::MAIN_PROCESS_ONLY },
michael@0 250 { &kNS_DEVICE_CONTEXT_SPEC_CID, false, nullptr, nsDeviceContextSpecWinConstructor,
michael@0 251 Module::MAIN_PROCESS_ONLY },
michael@0 252 #endif
michael@0 253 { nullptr }
michael@0 254 };
michael@0 255
michael@0 256 static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
michael@0 257 { "@mozilla.org/widgets/window/win;1", &kNS_WINDOW_CID },
michael@0 258 { "@mozilla.org/widgets/child_window/win;1", &kNS_CHILD_CID },
michael@0 259 { "@mozilla.org/filepicker;1", &kNS_FILEPICKER_CID, Module::MAIN_PROCESS_ONLY },
michael@0 260 { "@mozilla.org/colorpicker;1", &kNS_COLORPICKER_CID, Module::MAIN_PROCESS_ONLY },
michael@0 261 { "@mozilla.org/widget/appshell/win;1", &kNS_APPSHELL_CID },
michael@0 262 { "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID },
michael@0 263 { "@mozilla.org/gfx/info;1", &kNS_GFXINFO_CID },
michael@0 264 { "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID },
michael@0 265 { "@mozilla.org/widget/idleservice;1", &kNS_IDLE_SERVICE_CID },
michael@0 266 { "@mozilla.org/widget/clipboard;1", &kNS_CLIPBOARD_CID, Module::MAIN_PROCESS_ONLY },
michael@0 267 { "@mozilla.org/widget/clipboardhelper;1", &kNS_CLIPBOARDHELPER_CID },
michael@0 268 { "@mozilla.org/sound;1", &kNS_SOUND_CID, Module::MAIN_PROCESS_ONLY },
michael@0 269 { "@mozilla.org/widget/transferable;1", &kNS_TRANSFERABLE_CID },
michael@0 270 { "@mozilla.org/widget/htmlformatconverter;1", &kNS_HTMLFORMATCONVERTER_CID },
michael@0 271 { "@mozilla.org/windows-taskbar;1", &kNS_WIN_TASKBAR_CID },
michael@0 272 { "@mozilla.org/windows-jumplistbuilder;1", &kNS_WIN_JUMPLISTBUILDER_CID },
michael@0 273 { "@mozilla.org/windows-jumplistitem;1", &kNS_WIN_JUMPLISTITEM_CID },
michael@0 274 { "@mozilla.org/windows-jumplistseparator;1", &kNS_WIN_JUMPLISTSEPARATOR_CID },
michael@0 275 { "@mozilla.org/windows-jumplistlink;1", &kNS_WIN_JUMPLISTLINK_CID },
michael@0 276 { "@mozilla.org/windows-jumplistshortcut;1", &kNS_WIN_JUMPLISTSHORTCUT_CID },
michael@0 277 { "@mozilla.org/widget/dragservice;1", &kNS_DRAGSERVICE_CID, Module::MAIN_PROCESS_ONLY },
michael@0 278 { "@mozilla.org/widget/bidikeyboard;1", &kNS_BIDIKEYBOARD_CID },
michael@0 279 #ifdef MOZ_METRO
michael@0 280 { "@mozilla.org/windows-metroutils;1", &kNS_WIN_METROUTILS_CID },
michael@0 281 #endif
michael@0 282 #ifdef NS_PRINTING
michael@0 283 { "@mozilla.org/gfx/printsettings-service;1", &kNS_PRINTSETTINGSSERVICE_CID },
michael@0 284 { "@mozilla.org/gfx/printerenumerator;1", &kNS_PRINTER_ENUMERATOR_CID,
michael@0 285 Module::MAIN_PROCESS_ONLY },
michael@0 286 { "@mozilla.org/gfx/printsession;1", &kNS_PRINTSESSION_CID,
michael@0 287 Module::MAIN_PROCESS_ONLY },
michael@0 288 { "@mozilla.org/gfx/devicecontextspec;1", &kNS_DEVICE_CONTEXT_SPEC_CID,
michael@0 289 Module::MAIN_PROCESS_ONLY },
michael@0 290 #endif
michael@0 291 { nullptr }
michael@0 292 };
michael@0 293
michael@0 294 static void
michael@0 295 nsWidgetWindowsModuleDtor()
michael@0 296 {
michael@0 297 KeyboardLayout::Shutdown();
michael@0 298 MouseScrollHandler::Shutdown();
michael@0 299 nsLookAndFeel::Shutdown();
michael@0 300 nsToolkit::Shutdown();
michael@0 301 nsAppShellShutdown();
michael@0 302 }
michael@0 303
michael@0 304 static const mozilla::Module kWidgetModule = {
michael@0 305 mozilla::Module::kVersion,
michael@0 306 kWidgetCIDs,
michael@0 307 kWidgetContracts,
michael@0 308 nullptr,
michael@0 309 nullptr,
michael@0 310 nsAppShellInit,
michael@0 311 nsWidgetWindowsModuleDtor
michael@0 312 };
michael@0 313
michael@0 314 NSMODULE_DEFN(nsWidgetModule) = &kWidgetModule;

mercurial