1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/qt/nsAppShell.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* vim:expandtab:shiftwidth=4:tabstop=4: 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "nsAppShell.h" 1.12 +#include <QGuiApplication> 1.13 +#include <unistd.h> 1.14 +#include <fcntl.h> 1.15 +#include <errno.h> 1.16 + 1.17 +#include <qabstracteventdispatcher.h> 1.18 +#include <qthread.h> 1.19 + 1.20 +#include "prenv.h" 1.21 +#include "nsQAppInstance.h" 1.22 + 1.23 +#ifdef MOZ_LOGGING 1.24 +#define FORCE_PR_LOG 1.25 +#include "prlog.h" 1.26 +#endif 1.27 + 1.28 +#ifdef PR_LOGGING 1.29 +PRLogModuleInfo *gWidgetLog = nullptr; 1.30 +PRLogModuleInfo *gWidgetFocusLog = nullptr; 1.31 +PRLogModuleInfo *gWidgetIMLog = nullptr; 1.32 +PRLogModuleInfo *gWidgetDrawLog = nullptr; 1.33 +#endif 1.34 + 1.35 +static int sPokeEvent; 1.36 + 1.37 +nsAppShell::~nsAppShell() 1.38 +{ 1.39 + nsQAppInstance::Release(); 1.40 +} 1.41 + 1.42 +nsresult 1.43 +nsAppShell::Init() 1.44 +{ 1.45 +#ifdef PR_LOGGING 1.46 + if (!gWidgetLog) 1.47 + gWidgetLog = PR_NewLogModule("Widget"); 1.48 + if (!gWidgetFocusLog) 1.49 + gWidgetFocusLog = PR_NewLogModule("WidgetFocus"); 1.50 + if (!gWidgetIMLog) 1.51 + gWidgetIMLog = PR_NewLogModule("WidgetIM"); 1.52 + if (!gWidgetDrawLog) 1.53 + gWidgetDrawLog = PR_NewLogModule("WidgetDraw"); 1.54 +#endif 1.55 + sPokeEvent = QEvent::registerEventType(); 1.56 + 1.57 + nsQAppInstance::AddRef(); 1.58 + 1.59 + return nsBaseAppShell::Init(); 1.60 +} 1.61 + 1.62 +void 1.63 +nsAppShell::ScheduleNativeEventCallback() 1.64 +{ 1.65 + QCoreApplication::postEvent(this, 1.66 + new QEvent((QEvent::Type) sPokeEvent)); 1.67 +} 1.68 + 1.69 + 1.70 +bool 1.71 +nsAppShell::ProcessNextNativeEvent(bool mayWait) 1.72 +{ 1.73 + QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents; 1.74 + 1.75 + if (mayWait) 1.76 + flags |= QEventLoop::WaitForMoreEvents; 1.77 + 1.78 + QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance(QThread::currentThread()); 1.79 + if (!dispatcher) 1.80 + return false; 1.81 + 1.82 + return dispatcher->processEvents(flags) ? true : false; 1.83 +} 1.84 + 1.85 +bool 1.86 +nsAppShell::event (QEvent *e) 1.87 +{ 1.88 + if (e->type() == sPokeEvent) { 1.89 + NativeEventCallback(); 1.90 + return true; 1.91 + } 1.92 + 1.93 + return false; 1.94 +}