Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / cocoa / nsWidgetFactory.mm
blob3126b8c225c860df2d1a9a7e15d14d58c51c8e10
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsISupports.h"
7 #include "mozilla/Components.h"
8 #include "mozilla/ModuleUtils.h"
9 #include "mozilla/WidgetUtils.h"
11 #include "nsWidgetsCID.h"
13 #include "nsChildView.h"
14 #include "nsAppShell.h"
15 #include "nsAppShellSingleton.h"
16 #include "nsFilePicker.h"
17 #include "nsColorPicker.h"
19 #include "nsClipboard.h"
20 #include "nsClipboardHelper.h"
21 #include "HeadlessClipboard.h"
22 #include "gfxPlatform.h"
23 #include "nsTransferable.h"
24 #include "nsHTMLFormatConverter.h"
25 #include "nsDragService.h"
26 #include "nsToolkit.h"
28 #include "nsLookAndFeel.h"
30 #include "nsSound.h"
31 #include "nsUserIdleServiceX.h"
32 #include "NativeKeyBindings.h"
33 #include "OSXNotificationCenter.h"
35 #include "nsDeviceContextSpecX.h"
36 #include "nsPrinterListCUPS.h"
37 #include "nsPrintSettingsServiceX.h"
38 #include "nsPrintDialogX.h"
39 #include "nsToolkitCompsCID.h"
41 #include "mozilla/widget/ScreenManager.h"
43 using namespace mozilla;
44 using namespace mozilla::widget;
46 NS_IMPL_COMPONENT_FACTORY(nsIClipboard) {
47   nsCOMPtr<nsIClipboard> inst;
48   if (gfxPlatform::IsHeadless()) {
49     inst = new HeadlessClipboard();
50   } else {
51     inst = new nsClipboard();
52   }
54   return inst.forget();
57 #define MAKE_GENERIC_CTOR(class_, iface_)    \
58   NS_IMPL_COMPONENT_FACTORY(class_) {        \
59     RefPtr inst = new class_();              \
60     return inst.forget().downcast<iface_>(); \
61   }
63 #define MAKE_GENERIC_CTOR_INIT(class_, iface_, init_) \
64   NS_IMPL_COMPONENT_FACTORY(class_) {                 \
65     RefPtr inst = new class_();                       \
66     if (NS_SUCCEEDED(inst->init_())) {                \
67       return inst.forget().downcast<iface_>();        \
68     }                                                 \
69     return nullptr;                                   \
70   }
72 #define MAKE_GENERIC_SINGLETON_CTOR(iface_, func_) \
73   NS_IMPL_COMPONENT_FACTORY(iface_) { return func_(); }
75 MAKE_GENERIC_CTOR(nsFilePicker, nsIFilePicker)
76 MAKE_GENERIC_CTOR(nsColorPicker, nsIColorPicker)
77 MAKE_GENERIC_CTOR(nsSound, nsISound)
78 MAKE_GENERIC_CTOR(nsTransferable, nsITransferable)
79 MAKE_GENERIC_CTOR(nsHTMLFormatConverter, nsIFormatConverter)
80 MAKE_GENERIC_CTOR(nsClipboardHelper, nsIClipboardHelper)
81 MAKE_GENERIC_CTOR(nsDragService, nsIDragService)
82 MAKE_GENERIC_CTOR(nsDeviceContextSpecX, nsIDeviceContextSpec)
83 MAKE_GENERIC_CTOR(nsPrinterListCUPS, nsIPrinterList)
84 MAKE_GENERIC_CTOR_INIT(nsPrintSettingsServiceX, nsIPrintSettingsService, Init)
85 MAKE_GENERIC_CTOR_INIT(nsPrintDialogServiceX, nsIPrintDialogService, Init)
86 MAKE_GENERIC_SINGLETON_CTOR(nsUserIdleServiceX, nsUserIdleServiceX::GetInstance)
87 MAKE_GENERIC_SINGLETON_CTOR(ScreenManager, ScreenManager::GetAddRefedSingleton)
88 MAKE_GENERIC_CTOR_INIT(OSXNotificationCenter, nsIAlertsService, Init)
90 #include "nsMacDockSupport.h"
91 MAKE_GENERIC_CTOR(nsMacDockSupport, nsIMacDockSupport)
93 #include "nsMacFinderProgress.h"
94 MAKE_GENERIC_CTOR(nsMacFinderProgress, nsIMacFinderProgress)
96 #include "nsMacSharingService.h"
97 MAKE_GENERIC_CTOR(nsMacSharingService, nsIMacSharingService)
99 #include "nsMacUserActivityUpdater.h"
100 MAKE_GENERIC_CTOR(nsMacUserActivityUpdater, nsIMacUserActivityUpdater)
102 #include "nsMacWebAppUtils.h"
103 MAKE_GENERIC_CTOR(nsMacWebAppUtils, nsIMacWebAppUtils)
105 #include "nsStandaloneNativeMenu.h"
106 MAKE_GENERIC_CTOR(nsStandaloneNativeMenu, nsIStandaloneNativeMenu)
108 #include "nsSystemStatusBarCocoa.h"
109 MAKE_GENERIC_CTOR(nsSystemStatusBarCocoa, nsISystemStatusBar)
111 #include "nsTouchBarUpdater.h"
112 MAKE_GENERIC_CTOR(nsTouchBarUpdater, nsITouchBarUpdater)
114 void nsWidgetCocoaModuleCtor() { nsAppShellInit(); }
116 void nsWidgetCocoaModuleDtor() {
117   // Shutdown all XP level widget classes.
118   WidgetUtils::Shutdown();
120   NativeKeyBindings::Shutdown();
121   nsLookAndFeel::Shutdown();
122   nsToolkit::Shutdown();
123   nsAppShellShutdown();