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