1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=4:tabstop=4:
3  */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 
8 #include "nsWidgetFactory.h"
9 
10 #include "mozilla/Components.h"
11 #include "mozilla/WidgetUtils.h"
12 #include "NativeKeyBindings.h"
13 #include "nsWidgetsCID.h"
14 #include "nsAppShell.h"
15 #include "nsAppShellSingleton.h"
16 #include "nsBaseWidget.h"
17 #include "nsGtkKeyUtils.h"
18 #include "nsLookAndFeel.h"
19 #include "nsWindow.h"
20 #include "nsHTMLFormatConverter.h"
21 #include "HeadlessClipboard.h"
22 #include "IMContextWrapper.h"
23 #ifdef MOZ_X11
24 #  include "nsClipboard.h"
25 #endif
26 #include "TaskbarProgress.h"
27 #include "nsFilePicker.h"
28 #include "nsSound.h"
29 #include "nsGTKToolkit.h"
30 #include "WakeLockListener.h"
31 
32 #include "mozilla/gfx/2D.h"
33 #include "mozilla/widget/ScreenManager.h"
34 #include <gtk/gtk.h>
35 
36 using namespace mozilla;
37 using namespace mozilla::widget;
38 
39 #ifdef MOZ_X11
NS_IMPL_COMPONENT_FACTORY(nsIClipboard)40 NS_IMPL_COMPONENT_FACTORY(nsIClipboard) {
41   nsCOMPtr<nsIClipboard> inst;
42   if (gfxPlatform::IsHeadless()) {
43     inst = new HeadlessClipboard();
44   } else {
45     auto clipboard = MakeRefPtr<nsClipboard>();
46     if (NS_FAILED(clipboard->Init())) {
47       return nullptr;
48     }
49     inst = std::move(clipboard);
50   }
51 
52   return inst.forget().downcast<nsISupports>();
53 }
54 #endif
55 
nsWidgetGtk2ModuleCtor()56 nsresult nsWidgetGtk2ModuleCtor() { return nsAppShellInit(); }
57 
nsWidgetGtk2ModuleDtor()58 void nsWidgetGtk2ModuleDtor() {
59   // Shutdown all XP level widget classes.
60   WidgetUtils::Shutdown();
61 
62   NativeKeyBindings::Shutdown();
63   nsLookAndFeel::Shutdown();
64   nsFilePicker::Shutdown();
65   nsSound::Shutdown();
66   nsWindow::ReleaseGlobals();
67   IMContextWrapper::Shutdown();
68   KeymapWrapper::Shutdown();
69   nsGTKToolkit::Shutdown();
70   nsAppShellShutdown();
71 #ifdef MOZ_ENABLE_DBUS
72   WakeLockListener::Shutdown();
73 #endif
74 }
75