Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 #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()
35 {
36 nsQAppInstance::Release();
37 }
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();
54 nsQAppInstance::AddRef();
56 return nsBaseAppShell::Init();
57 }
59 void
60 nsAppShell::ScheduleNativeEventCallback()
61 {
62 QCoreApplication::postEvent(this,
63 new QEvent((QEvent::Type) sPokeEvent));
64 }
67 bool
68 nsAppShell::ProcessNextNativeEvent(bool mayWait)
69 {
70 QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents;
72 if (mayWait)
73 flags |= QEventLoop::WaitForMoreEvents;
75 QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance(QThread::currentThread());
76 if (!dispatcher)
77 return false;
79 return dispatcher->processEvents(flags) ? true : false;
80 }
82 bool
83 nsAppShell::event (QEvent *e)
84 {
85 if (e->type() == sPokeEvent) {
86 NativeEventCallback();
87 return true;
88 }
90 return false;
91 }