Bug 1073336 part 5 - Add AnimationPlayerCollection::PlayerUpdated; r=dbaron
[gecko.git] / widget / qt / nsAppShell.cpp
blobdb835236a16be747561445a280c5de825a1fd991
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 <QGuiApplication>
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 #include "prlog.h"
22 #endif
24 #ifdef PR_LOGGING
25 PRLogModuleInfo *gWidgetLog = nullptr;
26 PRLogModuleInfo *gWidgetFocusLog = nullptr;
27 PRLogModuleInfo *gWidgetIMLog = nullptr;
28 PRLogModuleInfo *gWidgetDrawLog = nullptr;
29 #endif
31 static int sPokeEvent;
33 nsAppShell::~nsAppShell()
35 nsQAppInstance::Release();
38 nsresult
39 nsAppShell::Init()
41 #ifdef PR_LOGGING
42 if (!gWidgetLog)
43 gWidgetLog = PR_NewLogModule("Widget");
44 if (!gWidgetFocusLog)
45 gWidgetFocusLog = PR_NewLogModule("WidgetFocus");
46 if (!gWidgetIMLog)
47 gWidgetIMLog = PR_NewLogModule("WidgetIM");
48 if (!gWidgetDrawLog)
49 gWidgetDrawLog = PR_NewLogModule("WidgetDraw");
50 #endif
51 sPokeEvent = QEvent::registerEventType();
53 nsQAppInstance::AddRef();
55 return nsBaseAppShell::Init();
58 void
59 nsAppShell::ScheduleNativeEventCallback()
61 QCoreApplication::postEvent(this,
62 new QEvent((QEvent::Type) sPokeEvent));
66 bool
67 nsAppShell::ProcessNextNativeEvent(bool mayWait)
69 QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents;
71 if (mayWait)
72 flags |= QEventLoop::WaitForMoreEvents;
74 QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance(QThread::currentThread());
75 if (!dispatcher)
76 return false;
78 return dispatcher->processEvents(flags) ? true : false;
81 bool
82 nsAppShell::event (QEvent *e)
84 if (e->type() == sPokeEvent) {
85 NativeEventCallback();
86 return true;
89 return false;