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 R__MACOSX
224 else if (kind == "safari")
226#endif
227#ifdef _MSC_VER
228 else if ((kind == "edge") || (kind == "msedge"))
230#endif
231 else if ((kind == "cef") || (kind == "cef3"))
233 else if ((kind == "qt") || (kind == "qt5"))
235 else if (kind == "qt6")
237 else if ((kind == "embed") || (kind == "embedded"))
239 else if (kind == "server")
241 else if (kind == "off")
243 else if (!SetSizeAsStr(kind))
244 SetCustomExec(kind);
245
246 return *this;
247}
248
249/////////////////////////////////////////////////////////////////////
250/// Returns configured browser name
251
253{
254 switch (GetBrowserKind()) {
255 case kChrome: return "chrome";
256 case kEdge: return "edge";
257 case kSafari: return "safari";
258 case kFirefox: return "firefox";
259 case kNative: return "native";
260 case kCEF: return "cef";
261 case kQt5: return "qt5";
262 case kQt6: return "qt6";
263 case kLocal: return "local";
264 case kDefault: return "default";
265 case kServer: return "server";
266 case kEmbedded: return "embed";
267 case kOff: return "off";
268 case kOn: return "on";
269 case kCustom:
270 auto pos = fExec.find(" ");
271 return (pos == std::string::npos) ? fExec : fExec.substr(0,pos);
272 }
273
274 return "";
275}
276
277///////////////////////////////////////////////////////////////////////////////////////////
278/// Assign window, connection and channel id where other window will be embed
279
280void RWebDisplayArgs::SetMasterWindow(std::shared_ptr<RWebWindow> master, unsigned connid, int channel)
281{
283 fMaster = master;
284 fMasterConnection = connid;
285 fMasterChannel = channel;
286}
287
288///////////////////////////////////////////////////////////////////////////////////////////
289/// Append string to url options.
290/// Add "&" as separator if any options already exists
291
292void RWebDisplayArgs::AppendUrlOpt(const std::string &opt)
293{
294 if (opt.empty()) return;
295
296 if (!fUrlOpt.empty())
297 fUrlOpt.append("&");
298
299 fUrlOpt.append(opt);
300}
301
302///////////////////////////////////////////////////////////////////////////////////////////
303/// Returns full url, which is combined from URL and extra URL options.
304/// Takes into account "#" symbol in url - options are inserted before that symbol
305
307{
308 std::string url = GetUrl(), urlopt = GetUrlOpt();
309 if (url.empty() || urlopt.empty()) return url;
310
311 auto rpos = url.find("#");
312 if (rpos == std::string::npos) rpos = url.length();
313
314 if (url.find("?") != std::string::npos)
315 url.insert(rpos, "&");
316 else
317 url.insert(rpos, "?");
318 url.insert(rpos+1, urlopt);
319
320 return url;
321}
322
323///////////////////////////////////////////////////////////////////////////////////////////
324/// Configure custom web browser.
325/// Either just name of browser which can be used like "opera"
326/// or full execution string which must includes $url like "/usr/bin/opera $url"
327
328void RWebDisplayArgs::SetCustomExec(const std::string &exec)
329{
331 fExec = exec;
332}
333
334///////////////////////////////////////////////////////////////////////////////////////////
335/// Returns custom executable to start web browser
336
338{
339 if (GetBrowserKind() != kCustom)
340 return "";
341
342#ifdef R__MACOSX
343 if ((fExec == "safari") || (fExec == "Safari"))
344 return "open -a Safari";
345#endif
346
347 return fExec;
348}
349
350///////////////////////////////////////////////////////////////////////////////////////////
351/// Returns string which can be used as argument in RWebWindow::Show() method
352/// to display web window in provided Qt5 QWidget.
353///
354/// After RWebWindow is displayed created QWebEngineView can be found with the command:
355///
356/// auto view = qparent->findChild<QWebEngineView*>("RootWebView");
357
358std::string RWebDisplayArgs::GetQt5EmbedQualifier(const void *qparent, const std::string &urlopt, unsigned qtversion)
359{
360 std::string where = (qtversion >= 0x60000) ? "qt6" : "qt5";
361 if (qparent) {
362 where.append(":");
363 where.append(std::to_string((uintptr_t) qparent));
364 }
365 if (!urlopt.empty()) {
366 where.append("?");
367 where.append(urlopt);
368 }
369 return where;
370}
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:406
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.
@ kSafari
Safari browser.
@ 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.