Bug 798413 - Tests for export signature from MAR files. r=bsmith
[gecko.git] / widget / qt / nsAppShell.cpp
blob6af35b0a458d1c8f941d0cd98dacefc261f7dd07
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/. */
8 #include "nsAppShell.h"
9 #include <qapplication.h>
10 #include <unistd.h>
11 #include <fcntl.h>
12 #include <errno.h>
14 #include <qabstracteventdispatcher.h>
15 #include <qthread.h>
17 #include "prenv.h"
18 #include "nsQAppInstance.h"
20 #ifdef MOZ_LOGGING
21 #define FORCE_PR_LOG
22 #include "prlog.h"
23 #endif
25 #ifdef PR_LOGGING
26 PRLogModuleInfo *gWidgetLog = nullptr;
27 PRLogModuleInfo *gWidgetFocusLog = nullptr;
28 PRLogModuleInfo *gWidgetIMLog = nullptr;
29 PRLogModuleInfo *gWidgetDrawLog = nullptr;
30 #endif
32 static int sPokeEvent;
34 nsAppShell::~nsAppShell()
36 nsQAppInstance::Release();
39 nsresult
40 nsAppShell::Init()
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 #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
53 sPokeEvent = QEvent::registerEventType();
54 #else
55 sPokeEvent = QEvent::User+5000;
56 #endif
58 nsQAppInstance::AddRef();
60 return nsBaseAppShell::Init();
63 void
64 nsAppShell::ScheduleNativeEventCallback()
66 QCoreApplication::postEvent(this,
67 new QEvent((QEvent::Type) sPokeEvent));
71 bool
72 nsAppShell::ProcessNextNativeEvent(bool mayWait)
74 QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents;
76 if (mayWait)
77 flags |= QEventLoop::WaitForMoreEvents;
79 QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance(QThread::currentThread());
80 if (!dispatcher)
81 return false;
83 return dispatcher->processEvents(flags) ? true : false;
86 bool
87 nsAppShell::event (QEvent *e)
89 if (e->type() == sPokeEvent) {
90 NativeEventCallback();
91 return true;
94 return false;