Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RWebDisplayArgs.cxx
Go to the documentation of this file.
1// Author: Sergey Linev <s.linev@gsi.de>
2// Date: 2018-10-24
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
14
15#include <ROOT/RConfig.hxx>
16#include <ROOT/RLogger.hxx>
17#include <ROOT/RWebWindow.hxx>
18
19#include "TROOT.h"
20#include <string>
21
22using namespace ROOT;
23
25{
26 static ROOT::Experimental::RLogChannel sLog("ROOT.WebGUI");
27 return sLog;
28}
29
30
31/** \class ROOT::RWebDisplayArgs
32\ingroup webdisplay
33
34Holds different arguments for starting browser with RWebDisplayHandle::Display() method
35
36*/
37
38///////////////////////////////////////////////////////////////////////////////////////////
39/// Default constructor.
40/// Browser kind configured from gROOT->GetWebDisplay()
41
43{
45}
46
47///////////////////////////////////////////////////////////////////////////////////////////
48/// Constructor.
49/// Browser kind specified as std::string.
50/// See \ref SetBrowserKind method for description of allowed parameters
51
52RWebDisplayArgs::RWebDisplayArgs(const std::string &browser)
53{
54 SetBrowserKind(browser);
55}
56
57///////////////////////////////////////////////////////////////////////////////////////////
58/// Constructor.
59/// Browser kind specified as `const char *`.
60/// See \ref SetBrowserKind method for description of allowed parameters
61
63{
64 SetBrowserKind(browser);
65}
66
67///////////////////////////////////////////////////////////////////////////////////////////
68/// Constructor.
69/// Let specify window width and height
70
71RWebDisplayArgs::RWebDisplayArgs(int width, int height, int x, int y, const std::string &browser)
72{
74 SetPos(x, y);
75 SetBrowserKind(browser);
76}
77
78///////////////////////////////////////////////////////////////////////////////////////////
79/// Constructor.
80/// Let specify master window and channel (if reserved already)
81
82RWebDisplayArgs::RWebDisplayArgs(std::shared_ptr<RWebWindow> master, unsigned conndid, int channel)
83{
84 SetMasterWindow(master, conndid, channel);
85}
86
87///////////////////////////////////////////////////////////////////////////////////////////
88/// Destructor.
89/// Must be defined in source code to correctly call RWebWindow destructor
90
92
93///////////////////////////////////////////////////////////////////////////////////////////
94/// Set size of web browser window as string like "800x600"
95
96bool RWebDisplayArgs::SetSizeAsStr(const std::string &str)
97{
98 auto separ = str.find("x");
99 if ((separ == std::string::npos) || (separ == 0) || (separ == str.length()-1)) return false;
100
101 int width = 0, height = 0;
102
103 try {
104 width = std::stoi(str.substr(0,separ));
105 height = std::stoi(str.substr(separ+1));
106 } catch(...) {
107 return false;
108 }
109
110 if ((width<=0) || (height<=0))
111 return false;
112
114 return true;
115}
116
117///////////////////////////////////////////////////////////////////////////////////////////
118/// Set position of web browser window as string like "100,100"
119
120bool RWebDisplayArgs::SetPosAsStr(const std::string &str)
121{
122 auto separ = str.find(",");
123 if ((separ == std::string::npos) || (separ == 0) || (separ == str.length()-1)) return false;
124
125 int x = 0, y = 0;
126
127 try {
128 x = std::stoi(str.substr(0,separ));
129 y = std::stoi(str.substr(separ+1));
130 } catch(...) {
131 return false;
132 }
133
134 if ((x < 0) || (y < 0))
135 return false;
136
137 SetPos(x, y);
138 return true;
139}
140
141///////////////////////////////////////////////////////////////////////////////////////////
142/// Set browser kind as string argument.
143///
144/// Recognized values:
145///
146/// chrome - use Google Chrome web browser
147/// firefox - use Mozilla Firefox web browser
148/// edge - use Microsoft Edge web browser (Windows only)
149/// native - either chrome/edge or firefox, only these browsers support batch (headless) mode
150/// default - default system web-browser, no batch mode
151/// cef - Chromium Embeded Framework, local display, local communication
152/// qt5 - Qt5 QWebEngine, local display, local communication
153/// qt6 - Qt6 QWebEngineCore, local display, local communication
154/// local - either cef or qt5 or qt6
155/// off - disable web display
156/// on - first try "local", then "native", then "default" (default option)
157/// `<prog>` - any program name which will be started to open widget URL, like "/usr/bin/opera"
158
160{
161 std::string kind = _kind;
162
163 auto pos = kind.find("?");
164 if (pos == 0) {
165 SetUrlOpt(kind.substr(1));
166 kind.clear();
167 } else if (pos != std::string::npos) {
168 SetUrlOpt(kind.substr(pos+1));
169 kind.resize(pos);
170 }
171
172 pos = kind.find("size:");
173 if (pos != std::string::npos) {
174 auto epos = kind.find_first_of(" ;", pos+5);
175 if (epos == std::string::npos) epos = kind.length();
176 SetSizeAsStr(kind.substr(pos+5, epos-pos-5));
177 kind.erase(pos, epos-pos);
178 }
179
180 pos = kind.find("pos:");
181 if (pos != std::string::npos) {
182 auto epos = kind.find_first_of(" ;", pos+4);
183 if (epos == std::string::npos) epos = kind.length();
184 SetPosAsStr(kind.substr(pos+4, epos-pos-4));
185 kind.erase(pos, epos-pos);
186 }
187
188 pos = kind.rfind("headless");
189 if ((pos != std::string::npos) && (pos == kind.length() - 8)) {
190 SetHeadless(true);
191 kind.resize(pos);
192 if ((pos > 0) && (kind[pos-1] == ';')) kind.resize(pos-1);
193 }
194
195 // very special handling of qt5/qt6 which can specify pointer as a string
196 if ((kind.find("qt5:") == 0) || (kind.find("qt6:") == 0)) {
197 SetDriverData((void *) std::stoull(kind.substr(4)));
198 kind.resize(3);
199 }
200
201 // remove all trailing spaces
202 while ((kind.length() > 0) && (kind[kind.length()-1] == ' '))
203 kind.resize(kind.length()-1);
204
205 // remove any remaining spaces?
206 // kind.erase(remove_if(kind.begin(), kind.end(), std::isspace), kind.end());
207
208 if (kind.empty())
209 kind = gROOT->GetWebDisplay().Data();
210
211 if (kind == "local")
213 else if (kind == "native")
215 else if (kind.empty() || (kind == "on"))
217 else if ((kind == "dflt") || (kind == "default") || (kind == "browser"))
219 else if (kind == "firefox")
221 else if ((kind == "chrome") || (kind == "chromium"))
223#ifdef _MSC_VER
224 else if ((kind == "edge") || (kind == "msedge"))
226#endif
227 else if ((kind == "cef") || (kind == "cef3"))
229 else if ((kind == "qt") || (kind == "qt5"))
231 else if (kind == "qt6")
233 else if ((kind == "embed") || (kind == "embedded"))
235 else if (kind == "server")
237 else if (kind == "off")
239 else if (!SetSizeAsStr(kind))
240 SetCustomExec(kind);
241
242 return *this;
243}
244
245/////////////////////////////////////////////////////////////////////
246/// Returns configured browser name
247
249{
250 switch (GetBrowserKind()) {
251 case kChrome: return "chrome";
252 case kEdge: return "edge";
253 case kFirefox: return "firefox";
254 case kNative: return "native";
255 case kCEF: return "cef";
256 case kQt5: return "qt5";
257 case kQt6: return "qt6";
258 case kLocal: return "local";
259 case kDefault: return "default";
260 case kServer: return "server";
261 case kEmbedded: return "embed";
262 case kOff: return "off";
263 case kOn: return "on";
264 case kCustom:
265 auto pos = fExec.find(" ");
266 return (pos == std::string::npos) ? fExec : fExec.substr(0,pos);
267 }
268
269 return "";
270}
271
272///////////////////////////////////////////////////////////////////////////////////////////
273/// Assign window, connection and channel id where other window will be embed
274
275void RWebDisplayArgs::SetMasterWindow(std::shared_ptr<RWebWindow> master, unsigned connid, int channel)
276{
278 fMaster = master;
279 fMasterConnection = connid;
280 fMasterChannel = channel;
281}
282
283///////////////////////////////////////////////////////////////////////////////////////////
284/// Append string to url options.
285/// Add "&" as separator if any options already exists
286
287void RWebDisplayArgs::AppendUrlOpt(const std::string &opt)
288{
289 if (opt.empty()) return;
290
291 if (!fUrlOpt.empty())
292 fUrlOpt.append("&");
293
294 fUrlOpt.append(opt);
295}
296
297///////////////////////////////////////////////////////////////////////////////////////////
298/// Returns full url, which is combined from URL and extra URL options.
299/// Takes into account "#" symbol in url - options are inserted before that symbol
300
302{
303 std::string url = GetUrl(), urlopt = GetUrlOpt();
304 if (url.empty() || urlopt.empty()) return url;
305
306 auto rpos = url.find("#");
307 if (rpos == std::string::npos) rpos = url.length();
308
309 if (url.find("?") != std::string::npos)
310 url.insert(rpos, "&");
311 else
312 url.insert(rpos, "?");
313 url.insert(rpos+1, urlopt);
314
315 return url;
316}
317
318///////////////////////////////////////////////////////////////////////////////////////////
319/// Configure custom web browser.
320/// Either just name of browser which can be used like "opera"
321/// or full execution string which must includes $url like "/usr/bin/opera $url"
322
323void RWebDisplayArgs::SetCustomExec(const std::string &exec)
324{
326 fExec = exec;
327}
328
329///////////////////////////////////////////////////////////////////////////////////////////
330/// Returns custom executable to start web browser
331
333{
334 if (GetBrowserKind() != kCustom)
335 return "";
336
337#ifdef R__MACOSX
338 if ((fExec == "safari") || (fExec == "Safari"))
339 return "open -a Safari";
340#endif
341
342 return fExec;
343}
344
345///////////////////////////////////////////////////////////////////////////////////////////
346/// Returns string which can be used as argument in RWebWindow::Show() method
347/// to display web window in provided Qt5 QWidget.
348///
349/// After RWebWindow is displayed created QWebEngineView can be found with the command:
350///
351/// auto view = qparent->findChild<QWebEngineView*>("RootWebView");
352
353std::string RWebDisplayArgs::GetQt5EmbedQualifier(const void *qparent, const std::string &urlopt, unsigned qtversion)
354{
355 std::string where = (qtversion >= 0x60000) ? "qt6" : "qt5";
356 if (qparent) {
357 where.append(":");
358 where.append(std::to_string((uintptr_t) qparent));
359 }
360 if (!urlopt.empty()) {
361 where.append("?");
362 where.append(urlopt);
363 }
364 return where;
365}
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
#define gROOT
Definition TROOT.h:407
A log configuration for a channel, e.g.
Definition RLogger.hxx:101
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
std::string GetBrowserName() const
Returns configured browser name.
virtual ~RWebDisplayArgs()
Destructor.
EBrowserKind GetBrowserKind() const
returns configured browser kind, see EBrowserKind for supported values
RWebDisplayArgs & SetUrlOpt(const std::string &opt)
set window url options
bool SetPosAsStr(const std::string &str)
Set position of web browser window as string like "100,100".
std::string fExec
! string to run browser, used with kCustom type
RWebDisplayArgs & SetSize(int w, int h)
set preferable web window width and height
std::string fUrlOpt
! extra URL options, which are append to window URL
const std::string & GetUrl() const
returns window url
void SetCustomExec(const std::string &exec)
set custom executable to start web browser
void SetMasterWindow(std::shared_ptr< RWebWindow > master, unsigned connid=0, int channel=-1)
Assign window, connection and channel id where other window will be embed.
void AppendUrlOpt(const std::string &opt)
append extra url options, add "&" as separator if required
std::string GetFullUrl() const
returns window url with append options
RWebDisplayArgs & SetBrowserKind(const std::string &kind)
Set browser kind as string argument.
std::string GetCustomExec() const
returns custom executable to start web browser
unsigned fMasterConnection
! used master connection
static std::string GetQt5EmbedQualifier(const void *qparent, const std::string &urlopt="", unsigned qtversion=0x50000)
Returns string which can be used as argument in RWebWindow::Show() method to display web window in pr...
RWebDisplayArgs & SetPos(int x=-1, int y=-1)
set preferable web window x and y position, negative is default
int fMasterChannel
! used master channel
void SetDriverData(void *data)
[internal] set web-driver data, used to start window
std::shared_ptr< RWebWindow > fMaster
! master window
const std::string & GetUrlOpt() const
returns window url options
bool SetSizeAsStr(const std::string &str)
Set size of web browser window as string like "800x600".
@ kOn
web display enable, first try use embed displays like Qt or CEF, then native browsers and at the end ...
@ kDefault
default system web browser, can not be used in batch mode
@ kFirefox
Mozilla Firefox browser.
@ kNative
either Chrome or Firefox - both support major functionality
@ kLocal
either CEF or Qt5 - both runs on local display without real http server
@ kServer
indicates that ROOT runs as server and just printouts window URL, browser should be started by the us...
@ kOff
disable web display, do not start any browser
@ kEmbedded
window will be embedded into other, no extra browser need to be started
@ kCEF
Chromium Embedded Framework - local display with CEF libs.
@ kQt5
Qt5 QWebEngine libraries - Chromium code packed in qt5.
@ kQt6
Qt6 QWebEngine libraries - Chromium code packed in qt6.
@ kCustom
custom web browser, execution string should be provided
@ kChrome
Google Chrome browser.
@ kEdge
Microsoft Edge browser (Windows only)
void SetHeadless(bool on=true)
set headless mode
RWebDisplayArgs()
Default constructor.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
ROOT::Experimental::RLogChannel & WebGUILog()
Log channel for WebGUI diagnostics.