Logo ROOT  
Reference Guide
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.
40/// Browser kind configured from gROOT->GetWebDisplay()
41
42RWebDisplayArgs::RWebDisplayArgs()
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, int channel)
83{
84 SetMasterWindow(master, 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, supports headless mode from v60, default
147/// firefox - use Mozilla Firefox browser, supports headless mode from v57
148/// native - (or empty string) either chrome or firefox, only these browsers support batch (headless) mode
149/// browser - default system web-browser, no batch mode
150/// safari - Safari browser on Mac
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/// `<prog>` - any program name which will be started instead of default browser, like /usr/bin/opera
156
158{
159 std::string kind = _kind;
160
161 auto pos = kind.find("?");
162 if (pos == 0) {
163 SetUrlOpt(kind.substr(1));
164 kind.clear();
165 } else if (pos != std::string::npos) {
166 SetUrlOpt(kind.substr(pos+1));
167 kind.resize(pos);
168 }
169
170 pos = kind.find("size:");
171 if (pos != std::string::npos) {
172 auto epos = kind.find_first_of(" ;", pos+5);
173 if (epos == std::string::npos) epos = kind.length();
174 SetSizeAsStr(kind.substr(pos+5, epos-pos-5));
175 kind.erase(pos, epos-pos);
176 }
177
178 pos = kind.find("pos:");
179 if (pos != std::string::npos) {
180 auto epos = kind.find_first_of(" ;", pos+4);
181 if (epos == std::string::npos) epos = kind.length();
182 SetPosAsStr(kind.substr(pos+4, epos-pos-4));
183 kind.erase(pos, epos-pos);
184 }
185
186 pos = kind.rfind("headless");
187 if ((pos != std::string::npos) && (pos == kind.length() - 8)) {
188 SetHeadless(true);
189 kind.resize(pos);
190 if ((pos > 0) && (kind[pos-1] == ';')) kind.resize(pos-1);
191 }
192
193 // very special handling of qt5/qt6 which can specify pointer as a string
194 if ((kind.find("qt5:") == 0) || (kind.find("qt6:") == 0)) {
195 SetDriverData((void *) std::stoull(kind.substr(4)));
196 kind.resize(3);
197 }
198
199 // remove all trailing spaces
200 while ((kind.length() > 0) && (kind[kind.length()-1] == ' '))
201 kind.resize(kind.length()-1);
202
203 // remove any remaining spaces?
204 // kind.erase(remove_if(kind.begin(), kind.end(), std::isspace), kind.end());
205
206 if (kind.empty())
207 kind = gROOT->GetWebDisplay().Data();
208
209 if (kind == "local")
211 else if (kind.empty() || (kind == "native"))
213 else if (kind == "firefox")
215 else if ((kind == "chrome") || (kind == "chromium"))
217 else if ((kind == "cef") || (kind == "cef3"))
219 else if ((kind == "qt") || (kind == "qt5"))
221 else if (kind == "qt6")
223 else if ((kind == "embed") || (kind == "embedded"))
225 else if ((kind == "dflt") || (kind == "default") || (kind == "browser"))
227 else if (kind == "server")
229 else if (kind == "off")
231 else if (!SetSizeAsStr(kind))
232 SetCustomExec(kind);
233
234 return *this;
235}
236
237/////////////////////////////////////////////////////////////////////
238/// Returns configured browser name
239
241{
242 switch (GetBrowserKind()) {
243 case kChrome: return "chrome";
244 case kFirefox: return "firefox";
245 case kNative: return "native";
246 case kCEF: return "cef";
247 case kQt5: return "qt5";
248 case kQt6: return "qt6";
249 case kLocal: return "local";
250 case kStandard: return "default";
251 case kServer: return "server";
252 case kEmbedded: return "embed";
253 case kOff: return "off";
254 case kCustom:
255 auto pos = fExec.find(" ");
256 return (pos == std::string::npos) ? fExec : fExec.substr(0,pos);
257 }
258
259 return "";
260}
261
262///////////////////////////////////////////////////////////////////////////////////////////
263/// Assign window and channel id where other window will be embed
264
265void RWebDisplayArgs::SetMasterWindow(std::shared_ptr<RWebWindow> master, int channel)
266{
268 fMaster = master;
269 fMasterChannel = channel;
270}
271
272///////////////////////////////////////////////////////////////////////////////////////////
273/// Append string to url options.
274/// Add "&" as separator if any options already exists
275
276void RWebDisplayArgs::AppendUrlOpt(const std::string &opt)
277{
278 if (opt.empty()) return;
279
280 if (!fUrlOpt.empty())
281 fUrlOpt.append("&");
282
283 fUrlOpt.append(opt);
284}
285
286///////////////////////////////////////////////////////////////////////////////////////////
287/// Returns full url, which is combined from URL and extra URL options.
288/// Takes into account "#" symbol in url - options are inserted before that symbol
289
291{
292 std::string url = GetUrl(), urlopt = GetUrlOpt();
293 if (url.empty() || urlopt.empty()) return url;
294
295 auto rpos = url.find("#");
296 if (rpos == std::string::npos) rpos = url.length();
297
298 if (url.find("?") != std::string::npos)
299 url.insert(rpos, "&");
300 else
301 url.insert(rpos, "?");
302 url.insert(rpos+1, urlopt);
303
304 return url;
305}
306
307///////////////////////////////////////////////////////////////////////////////////////////
308/// Configure custom web browser.
309/// Either just name of browser which can be used like "opera"
310/// or full execution string which must includes $url like "/usr/bin/opera $url"
311
312void RWebDisplayArgs::SetCustomExec(const std::string &exec)
313{
315 fExec = exec;
316}
317
318///////////////////////////////////////////////////////////////////////////////////////////
319/// Returns custom executable to start web browser
320
322{
323 if (GetBrowserKind() != kCustom)
324 return "";
325
326#ifdef R__MACOSX
327 if ((fExec == "safari") || (fExec == "Safari"))
328 return "open -a Safari";
329#endif
330
331 return fExec;
332}
333
334///////////////////////////////////////////////////////////////////////////////////////////
335/// Returns string which can be used as argument in RWebWindow::Show() method
336/// to display web window in provided QWidget.
337///
338/// After RWebWindow is displayed created QWebEngineView can be found with the command:
339///
340/// auto view = qparent->findChild<QWebEngineView*>("RootWebView");
341
342std::string RWebDisplayArgs::GetQt5EmbedQualifier(const void *qparent, const std::string &urlopt)
343{
344 std::string where = "qt5";
345 if (qparent) {
346 where.append(":");
347 where.append(std::to_string((uintptr_t) qparent));
348 }
349 if (!urlopt.empty()) {
350 where.append("?");
351 where.append(urlopt);
352 }
353 return where;
354}
355
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: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.
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.
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
@ 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
@ kStandard
default system web browser, can not be used in 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".
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
RLogChannel & WebGUILog()
Log channel for WebGUI diagnostics.