1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set ts=4 et sw=4 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <QApplication>
#include "nsQAppInstance.h"
#include <QtOpenGL/QGLWidget>
#include <QThread>
#if defined MOZ_ENABLE_MEEGOTOUCH
#include <MScene>
#endif
#include "moziqwidget.h"
#include "mozqwidgetfast.h"
#include "nsFastStartupQt.h"
#include "nsXPCOMGlue.h"
#include "nsXULAppAPI.h"
static nsFastStartup* sFastStartup = NULL;
void
GeckoThread::run()
{
Q_EMIT symbolsLoadingFinished(mFunc(mExecPath));
}
void
nsFastStartup::symbolsLoadingFinished(bool preloaded)
{
mSymbolsLoaded = preloaded;
if (mWidgetPainted && mSymbolsLoaded) {
mLoop.quit();
}
}
void nsFastStartup::painted()
{
mWidgetPainted = true;
if (mWidgetPainted && mSymbolsLoaded) {
mLoop.quit();
}
}
MozGraphicsView*
nsFastStartup::GetStartupGraphicsView(QWidget* parentWidget, IMozQWidget* aTopChild)
{
MozGraphicsView* view = NULL;
if (sFastStartup && sFastStartup->mGraphicsView) {
view = sFastStartup->mGraphicsView;
} else {
view = new MozGraphicsView(parentWidget);
Qt::WindowFlags flags = Qt::Widget;
view->setWindowFlags(flags);
#if MOZ_PLATFORM_MAEMO == 6
view->setViewport(new QGLWidget());
#endif
}
view->SetTopLevel(aTopChild, parentWidget);
return view;
}
nsFastStartup*
nsFastStartup::GetSingleton()
{
return sFastStartup;
}
nsFastStartup::nsFastStartup()
: mGraphicsView(0)
, mFakeWidget(0)
, mSymbolsLoaded(false)
, mWidgetPainted(false)
, mThread(0)
{
sFastStartup = this;
}
nsFastStartup::~nsFastStartup()
{
nsQAppInstance::Release();
sFastStartup = 0;
}
void
nsFastStartup::RemoveFakeLayout()
{
if (mFakeWidget && mGraphicsView) {
mGraphicsView->scene()->removeItem(mFakeWidget);
mFakeWidget->deleteLater();
mFakeWidget = 0;
// Forget GraphicsView, ownership moved to nsIWidget
mGraphicsView = 0;
}
}
bool
nsFastStartup::CreateFastStartup(int& argc, char ** argv,
const char* execPath,
GeckoLoaderFunc aFunc)
{
gArgc = argc;
gArgv = argv;
// Create main QApplication instance
nsQAppInstance::AddRef(argc, argv, true);
// Create symbols loading thread
mThread = new GeckoThread();
// Setup thread loading finished callbacks
connect(mThread, SIGNAL(symbolsLoadingFinished(bool)),
this, SLOT(symbolsLoadingFinished(bool)));
mThread->SetLoader(aFunc, execPath);
// Create Static UI widget and view
IMozQWidget* fakeWidget = new MozQWidgetFast(NULL, NULL);
mGraphicsView = GetStartupGraphicsView(NULL, fakeWidget);
mFakeWidget = fakeWidget;
mThread->start();
#ifdef MOZ_PLATFORM_MAEMO
mGraphicsView->showFullScreen();
#else
mGraphicsView->showNormal();
#endif
// Start native loop in order to get view opened and painted once
// Will block CreateFastStartup function and
// exit when symbols are loaded and Static UI shown
mLoop.exec();
return true;
}
|