michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim:expandtab:shiftwidth=4:tabstop=4: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsAppShell.h" michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "prenv.h" michael@0: #include "nsQAppInstance.h" michael@0: michael@0: #ifdef MOZ_LOGGING michael@0: #define FORCE_PR_LOG michael@0: #include "prlog.h" michael@0: #endif michael@0: michael@0: #ifdef PR_LOGGING michael@0: PRLogModuleInfo *gWidgetLog = nullptr; michael@0: PRLogModuleInfo *gWidgetFocusLog = nullptr; michael@0: PRLogModuleInfo *gWidgetIMLog = nullptr; michael@0: PRLogModuleInfo *gWidgetDrawLog = nullptr; michael@0: #endif michael@0: michael@0: static int sPokeEvent; michael@0: michael@0: nsAppShell::~nsAppShell() michael@0: { michael@0: nsQAppInstance::Release(); michael@0: } michael@0: michael@0: nsresult michael@0: nsAppShell::Init() michael@0: { michael@0: #ifdef PR_LOGGING michael@0: if (!gWidgetLog) michael@0: gWidgetLog = PR_NewLogModule("Widget"); michael@0: if (!gWidgetFocusLog) michael@0: gWidgetFocusLog = PR_NewLogModule("WidgetFocus"); michael@0: if (!gWidgetIMLog) michael@0: gWidgetIMLog = PR_NewLogModule("WidgetIM"); michael@0: if (!gWidgetDrawLog) michael@0: gWidgetDrawLog = PR_NewLogModule("WidgetDraw"); michael@0: #endif michael@0: sPokeEvent = QEvent::registerEventType(); michael@0: michael@0: nsQAppInstance::AddRef(); michael@0: michael@0: return nsBaseAppShell::Init(); michael@0: } michael@0: michael@0: void michael@0: nsAppShell::ScheduleNativeEventCallback() michael@0: { michael@0: QCoreApplication::postEvent(this, michael@0: new QEvent((QEvent::Type) sPokeEvent)); michael@0: } michael@0: michael@0: michael@0: bool michael@0: nsAppShell::ProcessNextNativeEvent(bool mayWait) michael@0: { michael@0: QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents; michael@0: michael@0: if (mayWait) michael@0: flags |= QEventLoop::WaitForMoreEvents; michael@0: michael@0: QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance(QThread::currentThread()); michael@0: if (!dispatcher) michael@0: return false; michael@0: michael@0: return dispatcher->processEvents(flags) ? true : false; michael@0: } michael@0: michael@0: bool michael@0: nsAppShell::event (QEvent *e) michael@0: { michael@0: if (e->type() == sPokeEvent) { michael@0: NativeEventCallback(); michael@0: return true; michael@0: } michael@0: michael@0: return false; michael@0: }