|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
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 "nsAppShell.h" |
|
9 #include <QGuiApplication> |
|
10 #include <unistd.h> |
|
11 #include <fcntl.h> |
|
12 #include <errno.h> |
|
13 |
|
14 #include <qabstracteventdispatcher.h> |
|
15 #include <qthread.h> |
|
16 |
|
17 #include "prenv.h" |
|
18 #include "nsQAppInstance.h" |
|
19 |
|
20 #ifdef MOZ_LOGGING |
|
21 #define FORCE_PR_LOG |
|
22 #include "prlog.h" |
|
23 #endif |
|
24 |
|
25 #ifdef PR_LOGGING |
|
26 PRLogModuleInfo *gWidgetLog = nullptr; |
|
27 PRLogModuleInfo *gWidgetFocusLog = nullptr; |
|
28 PRLogModuleInfo *gWidgetIMLog = nullptr; |
|
29 PRLogModuleInfo *gWidgetDrawLog = nullptr; |
|
30 #endif |
|
31 |
|
32 static int sPokeEvent; |
|
33 |
|
34 nsAppShell::~nsAppShell() |
|
35 { |
|
36 nsQAppInstance::Release(); |
|
37 } |
|
38 |
|
39 nsresult |
|
40 nsAppShell::Init() |
|
41 { |
|
42 #ifdef PR_LOGGING |
|
43 if (!gWidgetLog) |
|
44 gWidgetLog = PR_NewLogModule("Widget"); |
|
45 if (!gWidgetFocusLog) |
|
46 gWidgetFocusLog = PR_NewLogModule("WidgetFocus"); |
|
47 if (!gWidgetIMLog) |
|
48 gWidgetIMLog = PR_NewLogModule("WidgetIM"); |
|
49 if (!gWidgetDrawLog) |
|
50 gWidgetDrawLog = PR_NewLogModule("WidgetDraw"); |
|
51 #endif |
|
52 sPokeEvent = QEvent::registerEventType(); |
|
53 |
|
54 nsQAppInstance::AddRef(); |
|
55 |
|
56 return nsBaseAppShell::Init(); |
|
57 } |
|
58 |
|
59 void |
|
60 nsAppShell::ScheduleNativeEventCallback() |
|
61 { |
|
62 QCoreApplication::postEvent(this, |
|
63 new QEvent((QEvent::Type) sPokeEvent)); |
|
64 } |
|
65 |
|
66 |
|
67 bool |
|
68 nsAppShell::ProcessNextNativeEvent(bool mayWait) |
|
69 { |
|
70 QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents; |
|
71 |
|
72 if (mayWait) |
|
73 flags |= QEventLoop::WaitForMoreEvents; |
|
74 |
|
75 QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance(QThread::currentThread()); |
|
76 if (!dispatcher) |
|
77 return false; |
|
78 |
|
79 return dispatcher->processEvents(flags) ? true : false; |
|
80 } |
|
81 |
|
82 bool |
|
83 nsAppShell::event (QEvent *e) |
|
84 { |
|
85 if (e->type() == sPokeEvent) { |
|
86 NativeEventCallback(); |
|
87 return true; |
|
88 } |
|
89 |
|
90 return false; |
|
91 } |