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::Experimental;
23
25{
26 static RLogChannel sLog("ROOT.WebGUI");
27 return sLog;
28}
29
30
31/** \class ROOT::Experimental::RWebDisplayArgs
32\ingroup webdisplay
33
34Holds different arguments for starting browser with RWebDisplayHandle::Display() method
35
36*/
37
38///////////////////////////////////////////////////////////////////////////////////////////
39/// Default constructor - browser kind configured from gROOT->GetWebDisplay()
40
42{
44}
45
46///////////////////////////////////////////////////////////////////////////////////////////
47/// Constructor - browser kind specified as std::string
48/// See SetBrowserKind() method for description of allowed parameters
49
50RWebDisplayArgs::RWebDisplayArgs(const std::string &browser)
51{
52 SetBrowserKind(browser);
53}
54
55///////////////////////////////////////////////////////////////////////////////////////////
56/// Constructor - browser kind specified as const char *
57/// See \ref SetBrowserKind method for description of allowed parameters
58
60{
61 SetBrowserKind(browser);
62}
63
64///////////////////////////////////////////////////////////////////////////////////////////
65/// Constructor - specify window width and height
66
67RWebDisplayArgs::RWebDisplayArgs(int width, int height, int x, int y, const std::string &browser)
68{
69 SetSize(width, height);
70 SetPos(x, y);
71 SetBrowserKind(browser);
72}
73
74///////////////////////////////////////////////////////////////////////////////////////////
75/// Constructor - specify master window and channel (if reserved already)
76
77RWebDisplayArgs::RWebDisplayArgs(std::shared_ptr<RWebWindow> master, int channel)
78{
79 SetMasterWindow(master, channel);
80}
81
82///////////////////////////////////////////////////////////////////////////////////////////
83/// Destructor
84/// must be defined in source code to correctly call RWebWindow destructor
85
87
88///////////////////////////////////////////////////////////////////////////////////////////
89/// Set size of web browser window as string like "800x600"
90
91bool RWebDisplayArgs::SetSizeAsStr(const std::string &str)
92{
93 auto separ = str.find("x");
94 if ((separ == std::string::npos) || (separ == 0) || (separ == str.length()-1)) return false;
95
96 int width = 0, height = 0;
97
98 try {
99 width = std::stoi(str.substr(0,separ));
100 height = std::stoi(str.substr(separ+1));
101 } catch(...) {
102 return false;
103 }
104
105 if ((width<=0) || (height<=0))
106 return false;
107
108 SetSize(width, height);
109 return true;
110}
111
112///////////////////////////////////////////////////////////////////////////////////////////
113/// Set position of web browser window as string like "100,100"
114
115bool RWebDisplayArgs::SetPosAsStr(const std::string &str)
116{
117 auto separ = str.find(",");
118 if ((separ == std::string::npos) || (separ == 0) || (separ == str.length()-1)) return false;
119
120 int x = 0, y = 0;
121
122 try {
123 x = std::stoi(str.substr(0,separ));
124 y = std::stoi(str.substr(separ+1));
125 } catch(...) {
126 return false;
127 }
128
129 if ((x<0) || (y<0))
130 return false;
131
132 SetPos(x, y);
133 return true;
134}
135
136///////////////////////////////////////////////////////////////////////////////////////////
137/// Set browser kind as string argument
138/// Recognized values:
139/// chrome - use Google Chrome web browser, supports headless mode from v60, default
140/// firefox - use Mozilla Firefox browser, supports headless mode from v57
141/// native - (or empty string) either chrome or firefox, only these browsers support batch (headless) mode
142/// browser - default system web-browser, no batch mode
143/// safari - Safari browser on Mac
144/// cef - Chromium Embeded Framework, local display, local communication
145/// qt5 - Qt5 QWebEngine, local display, local communication
146/// qt6 - Qt6 QWebEngineCore, local display, local communication
147/// local - either cef or qt5 or qt6
148/// <prog> - any program name which will be started instead of default browser, like /usr/bin/opera
149
151{
152 std::string kind = _kind;
153
154 auto pos = kind.find("?");
155 if (pos == 0) {
156 SetUrlOpt(kind.substr(1));
157 kind.clear();
158 } else if (pos != std::string::npos) {
159 SetUrlOpt(kind.substr(pos+1));
160 kind.resize(pos);
161 }
162
163 pos = kind.find("size:");
164 if (pos != std::string::npos) {
165 auto epos = kind.find_first_of(" ;", pos+5);
166 if (epos == std::string::npos) epos = kind.length();
167 SetSizeAsStr(kind.substr(pos+5, epos-pos-5));
168 kind.erase(pos, epos-pos);
169 }
170
171 pos = kind.find("pos:");
172 if (pos != std::string::npos) {
173 auto epos = kind.find_first_of(" ;", pos+4);
174 if (epos == std::string::npos) epos = kind.length();
175 SetPosAsStr(kind.substr(pos+4, epos-pos-4));
176 kind.erase(pos, epos-pos);
177 }
178
179 pos = kind.rfind("headless");
180 if ((pos != std::string::npos) && (pos == kind.length() - 8)) {
181 SetHeadless(true);
182 kind.resize(pos);
183 if ((pos > 0) && (kind[pos-1] == ';')) kind.resize(pos-1);
184 }
185
186 // very special handling of qt5/qt6 which can specify pointer as a string
187 if ((kind.find("qt5:") == 0) || (kind.find("qt6:") == 0)) {
188 SetDriverData((void *) std::stoull(kind.substr(4)));
189 kind.resize(3);
190 }
191
192 // remove all trailing spaces
193 while ((kind.length() > 0) && (kind[kind.length()-1] == ' '))
194 kind.resize(kind.length()-1);
195
196 // remove any remaining spaces?
197 // kind.erase(remove_if(kind.begin(), kind.end(), std::isspace), kind.end());
198
199 if (kind.empty())
200 kind = gROOT->GetWebDisplay().Data();
201
202 if (kind == "local")
204 else if (kind.empty() || (kind == "native"))
206 else if (kind == "firefox")
208 else if ((kind == "chrome") || (kind == "chromium"))
210 else if ((kind == "cef") || (kind == "cef3"))
212 else if ((kind == "qt") || (kind == "qt5"))
214 else if (kind == "qt6")
216 else if ((kind == "embed") || (kind == "embedded"))
218 else if (kind == "off")
220 else if (!SetSizeAsStr(kind))
221 SetCustomExec(kind);
222
223 return *this;
224}
225
226/////////////////////////////////////////////////////////////////////
227/// Returns configured browser name
228
230{
231 switch (GetBrowserKind()) {
232 case kChrome: return "chrome";
233 case kFirefox: return "firefox";
234 case kNative: return "native";
235 case kCEF: return "cef";
236 case kQt5: return "qt5";
237 case kQt6: return "qt6";
238 case kLocal: return "local";
239 case kStandard: return "default";
240 case kEmbedded: return "embed";
241 case kOff: return "off";
242 case kCustom:
243 auto pos = fExec.find(" ");
244 return (pos == std::string::npos) ? fExec : fExec.substr(0,pos);
245 }
246
247 return "";
248}
249
250///////////////////////////////////////////////////////////////////////////////////////////
251/// Assign window and channel id where other window will be embed
252
253void RWebDisplayArgs::SetMasterWindow(std::shared_ptr<RWebWindow> master, int channel)
254{
256 fMaster = master;
257 fMasterChannel = channel;
258}
259
260///////////////////////////////////////////////////////////////////////////////////////////
261/// Append string to url options
262/// Add "&" as separator if any options already exists
263
264void RWebDisplayArgs::AppendUrlOpt(const std::string &opt)
265{
266 if (opt.empty()) return;
267
268 if (!fUrlOpt.empty())
269 fUrlOpt.append("&");
270
271 fUrlOpt.append(opt);
272}
273
274///////////////////////////////////////////////////////////////////////////////////////////
275/// Returns full url, which is combined from URL and extra URL options
276/// Takes into account "#" symbol in url - options are inserted before that symbol
277
279{
280 std::string url = GetUrl(), urlopt = GetUrlOpt();
281 if (url.empty() || urlopt.empty()) return url;
282
283 auto rpos = url.find("#");
284 if (rpos == std::string::npos) rpos = url.length();
285
286 if (url.find("?") != std::string::npos)
287 url.insert(rpos, "&");
288 else
289 url.insert(rpos, "?");
290 url.insert(rpos+1, urlopt);
291
292 return url;
293}
294
295///////////////////////////////////////////////////////////////////////////////////////////
296/// Configure custom web browser
297/// Either just name of browser which can be used like "opera"
298/// or full execution string which must includes $url like "/usr/bin/opera $url"
299
300void RWebDisplayArgs::SetCustomExec(const std::string &exec)
301{
303 fExec = exec;
304}
305
306///////////////////////////////////////////////////////////////////////////////////////////
307/// returns custom executable to start web browser
308
310{
311 if (GetBrowserKind() != kCustom)
312 return "";
313
314#ifdef R__MACOSX
315 if ((fExec == "safari") || (fExec == "Safari"))
316 return "open -a Safari";
317#endif
318
319 return fExec;
320}
321
322///////////////////////////////////////////////////////////////////////////////////////////
323/// returns string which can be used as argument in RWebWindow::Show() method
324/// to display web window in provided QWidget
325/// After RWebWindow is displayed created QWebEngineView can be found with the command:
326/// auto view = qparent->findChild<QWebEngineView*>("RootWebView");
327
328std::string RWebDisplayArgs::GetQt5EmbedQualifier(const void *qparent, const std::string &urlopt)
329{
330 std::string where = "qt5";
331 if (qparent) {
332 where.append(":");
333 where.append(std::to_string((uintptr_t) qparent));
334 }
335 if (!urlopt.empty()) {
336 where.append("?");
337 where.append(urlopt);
338 }
339 return where;
340}
341
include TDocParser_001 C image html pict1_TDocParser_001 png width
#define gROOT
Definition TROOT.h:404
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 must be defined in source code to correctly call RWebWindow destructor.
const std::string & GetUrlOpt() const
returns window url options
bool SetPosAsStr(const std::string &str)
Set position of web browser window as string like "100,100".
RWebDisplayArgs & SetPos(int x=-1, int y=-1)
set preferable web window x and y position, negative is default
static std::string GetQt5EmbedQualifier(const void *qparent, const std::string &urlopt="")
returns string which can be used as argument in RWebWindow::Show() method to display web window in pr...
void SetHeadless(bool on=true)
set headless mode
int fMasterChannel
! used master channel
void SetMasterWindow(std::shared_ptr< RWebWindow > master, int channel=-1)
Assign window and channel id where other window will be embed.
EBrowserKind GetBrowserKind() const
returns configured browser kind, see EBrowserKind for supported values
void SetCustomExec(const std::string &exec)
set custom executable to start web browser
std::shared_ptr< RWebWindow > fMaster
! master window
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 Recognized values: chrome - use Google Chrome web browser,...
std::string fExec
! string to run browser, used with kCustom type
std::string GetCustomExec() const
returns custom executable to start web browser
std::string fUrlOpt
! extra URL options, which are append to window URL
@ kFirefox
Mozilla Firefox browser.
@ kCEF
Chromium Embedded Framework - local display with CEF libs.
@ kQt6
Qt6 QWebEngine libraries - Chromium code packed in qt6.
@ kCustom
custom web browser, execution string should be provided
@ kNative
either Chrome or Firefox - both support major functionality
@ kEmbedded
window will be embedded into other, no extra browser need to be started
@ kLocal
either CEF or Qt5 - both runs on local display without real http server
@ kOff
disable web display, do not start any browser
@ kStandard
standard system web browser, not recognized by ROOT, without batch mode
@ kQt5
Qt5 QWebEngine libraries - Chromium code packed in qt5.
RWebDisplayArgs & SetUrlOpt(const std::string &opt)
set window url options
void SetDriverData(void *data)
[internal] set web-driver data, used to start window
RWebDisplayArgs & SetSize(int w, int h)
set preferable web window width and height
const std::string & GetUrl() const
returns window url
bool SetSizeAsStr(const std::string &str)
Set size of web browser window as string like "800x600".
RWebDisplayArgs()
Default constructor - browser kind configured from gROOT->GetWebDisplay()
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
RLogChannel & WebGUILog()
Log channel for WebGUI diagnostics.