13#include <QApplication>
14#include <QWebEngineView>
15#include <qtwebengineglobal.h>
16#include <QWebEngineDownloadItem>
19#include <QWebEngineSettings>
20#include <QWebEngineProfile>
23#if QT_VERSION >= 0x050C00
24#include <QWebEngineUrlScheme>
56 QApplication::sendPostedEvents();
57 QApplication::processEvents();
62namespace Experimental {
75 QApplication *
qapp{
nullptr};
79 std::unique_ptr<RootUrlSchemeHandler>
fHandler;
98 if (!
qapp && !QApplication::instance()) {
106 QtWebEngine::initialize();
108 #if QT_VERSION >= 0x050C00
109 QWebEngineUrlScheme scheme(
"rootscheme");
110 scheme.setSyntax(QWebEngineUrlScheme::Syntax::HostAndPort);
111 scheme.setDefaultPort(2345);
112 scheme.setFlags(QWebEngineUrlScheme::SecureScheme);
113 QWebEngineUrlScheme::registerScheme(scheme);
127 fTimer = std::make_unique<TQt5Timer>(interval,
kTRUE);
132 QString fullurl = QString(args.
GetFullUrl().c_str());
137 fHandler = std::make_unique<RootUrlSchemeHandler>();
138 QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(
"rootscheme",
fHandler.get());
139 QWebEngineProfile::defaultProfile()->connect(QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested,
140 [](QWebEngineDownloadItem *item) { item->accept(); });
148 auto handle = std::make_unique<RQt5WebDisplayHandle>(fullurl.toLatin1().constData());
153 if (!qparent) handle->fView = view;
154 view->load(QUrl(fullurl));
158 int tmout_sec = 30, expired = tmout_sec * 100;
159 bool load_finished =
false, did_try =
false, get_content =
false, is_error =
false;
160 std::string content, pdffile;
165 QObject::connect(view, &RootWebView::loadFinished, [&load_finished, &is_error](
bool is_ok) {
166 load_finished =
true; is_error = !is_ok;
169 #if QT_VERSION >= 0x050900
170 if (!pdffile.empty())
171 QObject::connect(view->page(), &RootWebPage::pdfPrintingFinished, [&expired, &is_error](
const QString &,
bool is_ok) {
172 expired = 0; is_error = !is_ok;
177 if (page_content.empty())
178 view->load(QUrl(fullurl));
180 view->setHtml(QString::fromUtf8(page_content.data(), page_content.size()), QUrl(
"file:///batch_page.html"));
183 while ((--expired > 0) && !get_content && !is_error) {
187 QApplication::sendPostedEvents();
188 QApplication::processEvents();
190 if (load_finished && !did_try) {
193 if (pdffile.empty()) {
194 view->page()->toHtml([&get_content, &content](
const QString& res) {
196 content = res.toLatin1().constData();
199 view->page()->printToPdf(QString::fromUtf8(pdffile.data(), pdffile.size()));
200 #if QT_VERSION < 0x050900
210 handle->SetContent(content);
215 for (expired=0;expired<100;++expired) {
216 QApplication::sendPostedEvents();
217 QApplication::processEvents();
243 GetMap().emplace(
"qt5", std::make_unique<Qt5Creator>());
#define R__LOG_ERROR(...)
R__EXTERN TApplication * gApplication
R__EXTERN TSystem * gSystem
QApplication * qapp
created QApplication
std::unique_ptr< TQt5Timer > fTimer
timer to process ROOT events
char * qargv[2]
arg values
int fCounter
counter used to number handlers
std::unique_ptr< RWebDisplayHandle > Display(const RWebDisplayArgs &args) override
std::unique_ptr< RootUrlSchemeHandler > fHandler
specialized handler
RootWebView * fView
pointer on widget, need to release when handle is destroyed
virtual ~RQt5WebDisplayHandle()
RQt5WebDisplayHandle(const std::string &url)
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
bool IsHeadless() const
returns headless mode
int GetHeight() const
returns preferable web window height
const std::string & GetExtraArgs() const
get extra command line arguments for starting web browser command
std::string GetFullUrl() const
returns window url with append options
THttpServer * GetHttpServer() const
returns http server instance, used for window display
const std::string & GetPageContent() const
returns window url
void * GetDriverData() const
[internal] returns web-driver data, used to start window
int GetY() const
set preferable web window y position
int GetX() const
set preferable web window x position
int GetWidth() const
returns preferable web window width
Handle of created web-based display Depending from type of web display, holds handle of started brows...
static std::map< std::string, std::unique_ptr< Creator > > & GetMap()
Static holder of registered creators of web displays.
static std::unique_ptr< Creator > & FindCreator(const std::string &name, const std::string &libname="")
Search for specific browser creator If not found, try to add one.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
TQt5Timer(Long_t milliSec, Bool_t mode)
void Timeout() override
timeout handler used to process all qt5 events in main ROOT thread
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Handles synchronous and a-synchronous timer events.
struct ROOT::Experimental::RQt5CreatorReg newRQt5CreatorReg
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
ROOT::Experimental::RLogChannel & QtWebDisplayLog()