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
4/*************************************************************************
5 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
13
14#include <ROOT/RConfig.hxx>
15#include <ROOT/RLogger.hxx>
16#include <ROOT/RWebWindow.hxx>
17
18#include "TROOT.h"
19#include <string>
20
21using namespace ROOT;
22
24{
25 static ROOT::RLogChannel sLog("ROOT.WebGUI");
26 return sLog;
27}
28
29
30/** \class ROOT::RWebDisplayArgs
31\ingroup webdisplay
32
33Holds different arguments for starting browser with RWebDisplayHandle::Display() method
34
35*/
36
37///////////////////////////////////////////////////////////////////////////////////////////
38/// Default constructor.
39/// Browser kind configured from gROOT->GetWebDisplay()
40
45
46///////////////////////////////////////////////////////////////////////////////////////////
47/// Constructor.
48/// Browser kind specified as std::string.
49/// See \ref SetBrowserKind method for description of allowed parameters
50
55
56///////////////////////////////////////////////////////////////////////////////////////////
57/// Constructor.
58/// Browser kind specified as `const char *`.
59/// See \ref SetBrowserKind method for description of allowed parameters
60
65
66///////////////////////////////////////////////////////////////////////////////////////////
67/// Constructor.
68/// Let specify window width and height
69
70RWebDisplayArgs::RWebDisplayArgs(int width, int height, int x, int y, const std::string &browser)
71{
73 SetPos(x, y);
75}
76
77///////////////////////////////////////////////////////////////////////////////////////////
78/// Constructor.
79/// Let specify master window and channel (if reserved already)
80
81RWebDisplayArgs::RWebDisplayArgs(std::shared_ptr<RWebWindow> master, unsigned conndid, int channel)
82{
84}
85
86///////////////////////////////////////////////////////////////////////////////////////////
87/// Destructor.
88/// Must be defined in source code to correctly call RWebWindow destructor
89
91
92///////////////////////////////////////////////////////////////////////////////////////////
93/// Set size of web browser window as string like "800x600"
94
95bool RWebDisplayArgs::SetSizeAsStr(const std::string &str)
96{
97 auto separ = str.find("x");
98 if ((separ == std::string::npos) || (separ == 0) || (separ == str.length()-1)) return false;
99
100 int width = 0, height = 0;
101
102 try {
103 width = std::stoi(str.substr(0,separ));
104 height = std::stoi(str.substr(separ+1));
105 } catch(...) {
106 return false;
107 }
108
109 if ((width<=0) || (height<=0))
110 return false;
111
113 return true;
114}
115
116///////////////////////////////////////////////////////////////////////////////////////////
117/// Set position of web browser window as string like "100,100"
118
119bool RWebDisplayArgs::SetPosAsStr(const std::string &str)
120{
121 auto separ = str.find(",");
122 if ((separ == std::string::npos) || (separ == 0) || (separ == str.length()-1)) return false;
123
124 int x = 0, y = 0;
125
126 try {
127 x = std::stoi(str.substr(0,separ));
128 y = std::stoi(str.substr(separ+1));
129 } catch(...) {
130 return false;
131 }
132
133 if ((x < 0) || (y < 0))
134 return false;
135
136 SetPos(x, y);
137 return true;
138}
139
140///////////////////////////////////////////////////////////////////////////////////////////
141/// Set browser kind as string argument.
142///
143/// Recognized values:
144///
145/// chrome - use Google Chrome web browser
146/// firefox - use Mozilla Firefox web browser
147/// edge - use Microsoft Edge web browser (Windows only)
148/// native - either chrome/edge or firefox, only these browsers support batch (headless) mode
149/// default - default system web-browser, no batch mode
150/// cef - Chromium Embeded Framework, local display, local communication
151/// qt6 - Qt6 QWebEngineCore, local display, local communication
152/// local - either cef or qt6
153/// off - disable web display
154/// on - first try "local", then "native", then "default" (default option)
155/// server - run as web server without display (URL printed to command line; also available via e.g. RWebWindow::GetUrl)
156/// `<prog>` - any program name which will be started to open widget URL, like "/usr/bin/opera"
157
159{
160 std::string kind = _kind;
161
162 auto pos = kind.find("?");
163 if (pos == 0) {
164 SetUrlOpt(kind.substr(1));
165 kind.clear();
166 } else if (pos != std::string::npos) {
167 SetUrlOpt(kind.substr(pos+1));
168 kind.resize(pos);
169 }
170
171 pos = kind.find("size:");
172 if (pos != std::string::npos) {
173 auto epos = kind.find_first_of(" ;", pos+5);
174 if (epos == std::string::npos) epos = kind.length();
175 SetSizeAsStr(kind.substr(pos+5, epos-pos-5));
176 kind.erase(pos, epos-pos);
177 }
178
179 pos = kind.find("pos:");
180 if (pos != std::string::npos) {
181 auto epos = kind.find_first_of(" ;", pos+4);
182 if (epos == std::string::npos) epos = kind.length();
183 SetPosAsStr(kind.substr(pos+4, epos-pos-4));
184 kind.erase(pos, epos-pos);
185 }
186
187 pos = kind.rfind("headless");
188 if ((pos != std::string::npos) && (pos == kind.length() - 8)) {
189 SetHeadless(true);
190 kind.resize(pos);
191 if ((pos > 0) && (kind[pos-1] == ';')) kind.resize(pos-1);
192 }
193
194 // very special handling of qt6 which can specify pointer as a string
195 if (kind.find("qt6:") == 0) {
196 SetDriverData((void *) std::stoull(kind.substr(4)));
197 kind.resize(3);
198 }
199
200 // remove all trailing spaces
201 while ((kind.length() > 0) && (kind[kind.length()-1] == ' '))
202 kind.resize(kind.length()-1);
203
204 // remove any remaining spaces?
205 // kind.erase(remove_if(kind.begin(), kind.end(), std::isspace), kind.end());
206
207 if (kind.empty())
208 kind = gROOT->GetWebDisplay().Data();
209
210 if (kind == "local")
212 else if (kind == "native")
214 else if (kind.empty() || (kind == "on"))
216 else if ((kind == "dflt") || (kind == "default") || (kind == "browser"))
218 else if (kind == "firefox")
220 else if ((kind == "chrome") || (kind == "chromium"))
222#ifdef R__MACOSX
223 else if (kind == "safari")
225#endif
226#ifdef _MSC_VER
227 else if ((kind == "edge") || (kind == "msedge"))
229#endif
230 else if ((kind == "cef") || (kind == "cef3"))
232 else if ((kind == "qt") || (kind == "qt6"))
234 else if ((kind == "embed") || (kind == "embedded"))
236 else if (kind == "server")
238 else if (kind == "off")
240 else if (!SetSizeAsStr(kind))
241 SetCustomExec(kind);
242
243 return *this;
244}
245
246/////////////////////////////////////////////////////////////////////
247/// Returns configured browser name
248
250{
251 switch (GetBrowserKind()) {
252 case kChrome: return "chrome";
253 case kEdge: return "edge";
254 case kSafari: return "safari";
255 case kFirefox: return "firefox";
256 case kNative: return "native";
257 case kCEF: return "cef";
258 case kQt6: return "qt6";
259 case kLocal: return "local";
260 case kDefault: return "default";
261 case kServer: return "server";
262 case kEmbedded: return "embed";
263 case kOff: return "off";
264 case kOn: return "on";
265 case kCustom:
266 auto pos = fExec.find(" ");
267 return (pos == std::string::npos) ? fExec : fExec.substr(0,pos);
268 }
269
270 return "";
271}
272
273///////////////////////////////////////////////////////////////////////////////////////////
274/// Assign window, connection and channel id where other window will be embed
275
276void RWebDisplayArgs::SetMasterWindow(std::shared_ptr<RWebWindow> master, unsigned connid, int channel)
277{
279 fMaster = master;
280 fMasterConnection = connid;
281 fMasterChannel = channel;
282}
283
284///////////////////////////////////////////////////////////////////////////////////////////
285/// Append string to url options.
286/// Add "&" as separator if any options already exists
287
288void RWebDisplayArgs::AppendUrlOpt(const std::string &opt)
289{
290 if (opt.empty()) return;
291
292 if (!fUrlOpt.empty())
293 fUrlOpt.append("&");
294
295 fUrlOpt.append(opt);
296}
297
298///////////////////////////////////////////////////////////////////////////////////////////
299/// Returns full url, which is combined from URL and extra URL options.
300/// Takes into account "#" symbol in url - options are inserted before that symbol
301
303{
304 std::string url = GetUrl(), urlopt = GetUrlOpt();
305 if (url.empty() || urlopt.empty()) return url;
306
307 auto rpos = url.find("#");
308 if (rpos == std::string::npos) rpos = url.length();
309
310 if (url.find("?") != std::string::npos)
311 url.insert(rpos, "&");
312 else
313 url.insert(rpos, "?");
314 url.insert(rpos+1, urlopt);
315
316 return url;
317}
318
319///////////////////////////////////////////////////////////////////////////////////////////
320/// Configure custom web browser.
321/// Either just name of browser which can be used like "opera"
322/// or full execution string which must includes $url like "/usr/bin/opera $url"
323
324void RWebDisplayArgs::SetCustomExec(const std::string &exec)
325{
327 fExec = exec;
328}
329
330///////////////////////////////////////////////////////////////////////////////////////////
331/// Returns custom executable to start web browser
332
334{
335 if (GetBrowserKind() != kCustom)
336 return "";
337
338#ifdef R__MACOSX
339 if ((fExec == "safari") || (fExec == "Safari"))
340 return "open -a Safari";
341#endif
342
343 return fExec;
344}
345
346///////////////////////////////////////////////////////////////////////////////////////////
347/// Returns string which can be used as argument in RWebWindow::Show() method
348/// to display web window in provided Qt6 QWidget.
349///
350/// Kept for backward compatibility, use GetQtEmbedQualifier instead
351
352std::string RWebDisplayArgs::GetQt5EmbedQualifier(const void *qparent, const std::string &urlopt, unsigned qtversion)
353{
355}
356
357///////////////////////////////////////////////////////////////////////////////////////////
358/// Returns string which can be used as argument in RWebWindow::Show() method
359/// to display web window in provided Qt6 QWidget.
360///
361/// After RWebWindow is displayed created QWebEngineView can be found with the command:
362///
363/// auto view = qparent->findChild<QWebEngineView*>("RootWebView");
364
365std::string RWebDisplayArgs::GetQtEmbedQualifier(const void *qparent, const std::string &urlopt, unsigned qtversion)
366{
367 std::string where;
368 if (qtversion < 0x60000) {
369 R__LOG_ERROR(WebGUILog()) << "GetQtEmbedQualifier no longer support Qt5";
370 } else {
371 where = "qt6";
372 if (qparent) {
373 where.append(":");
374 where.append(std::to_string((uintptr_t)qparent));
375 }
376 if (!urlopt.empty()) {
377 where.append("?");
378 where.append(urlopt);
379 }
380 }
381 return where;
382}
#define R__LOG_ERROR(...)
Definition RLogger.hxx:356
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:417
A log configuration for a channel, e.g.
Definition RLogger.hxx:97
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
static std::string GetQtEmbedQualifier(const void *qparent, const std::string &urlopt="", unsigned qtversion=0x60000)
Returns string which can be used as argument in RWebWindow::Show() method to display web window in pr...
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
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
static std::string GetQt5EmbedQualifier(const void *qparent, const std::string &urlopt="", unsigned qtversion=0x60000)
Returns string which can be used as argument in RWebWindow::Show() method to display web window in pr...
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.
@ 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
ROOT::RLogChannel & WebGUILog()
Log channel for WebGUI diagnostics.