Logo ROOT  
Reference Guide
RWebDisplayArgs.cxx
Go to the documentation of this file.
1/// \file RWebDisplayArgs.cxx
2/// \ingroup WebGui ROOT7
3/// \author Sergey Linev <s.linev@gsi.de>
4/// \date 2018-10-24
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
17#include <ROOT/RWebWindow.hxx>
18#include <ROOT/RConfig.hxx>
19
20#include "TROOT.h"
21
22/** \class ROOT::Experimental::RWebDisplayArgs
23 * \ingroup webdisplay
24 *
25 * Holds different arguments for starting browser with RWebDisplayHandle::Display() method
26 */
27
28///////////////////////////////////////////////////////////////////////////////////////////
29/// Default constructor - browser kind configured from gROOT->GetWebDisplay()
30
32{
34}
35
36///////////////////////////////////////////////////////////////////////////////////////////
37/// Constructor - browser kind specified as std::string
38/// See SetBrowserKind() method for description of allowed parameters
39
41{
42 SetBrowserKind(browser);
43}
44
45///////////////////////////////////////////////////////////////////////////////////////////
46/// Constructor - browser kind specified as const char *
47/// See SetBrowserKind() method for description of allowed parameters
48
50{
51 SetBrowserKind(browser);
52}
53
54///////////////////////////////////////////////////////////////////////////////////////////
55/// Constructor - specify window width and height
56
57ROOT::Experimental::RWebDisplayArgs::RWebDisplayArgs(int width, int height, int x, int y, const std::string &browser)
58{
59 SetSize(width, height);
60 SetPos(x, y);
61 SetBrowserKind(browser);
62}
63
64///////////////////////////////////////////////////////////////////////////////////////////
65/// Constructor - specify master window and channel (if reserved already)
66
67ROOT::Experimental::RWebDisplayArgs::RWebDisplayArgs(std::shared_ptr<RWebWindow> master, int channel)
68{
69 SetMasterWindow(master, channel);
70}
71
72
73///////////////////////////////////////////////////////////////////////////////////////////
74/// Destructor
75
77{
78 // must be defined here to correctly call RWebWindow destructor
79}
80
81
82///////////////////////////////////////////////////////////////////////////////////////////
83/// Set browser kind as string argument
84/// Recognized values:
85/// chrome - use Google Chrome web browser, supports headless mode from v60, default
86/// firefox - use Mozilla Firefox browser, supports headless mode from v57
87/// native - (or empty string) either chrome or firefox, only these browsers support batch (headless) mode
88/// browser - default system web-browser, no batch mode
89/// safari - Safari browser on Mac
90/// cef - Chromium Embeded Framework, local display, local communication
91/// qt5 - Qt5 WebEngine, local display, local communication
92/// local - either cef or qt5
93/// <prog> - any program name which will be started instead of default browser, like /usr/bin/opera
94
96{
97 std::string kind = _kind;
98
99 auto pos = kind.find("?");
100 if (pos == 0) {
101 SetUrlOpt(kind.substr(1));
102 kind.clear();
103 }
104
105 if (kind.empty())
106 kind = gROOT->GetWebDisplay().Data();
107
108 if (kind == "local")
109 SetBrowserKind(kLocal);
110 else if (kind.empty() || (kind == "native"))
111 SetBrowserKind(kNative);
112 else if (kind == "firefox")
113 SetBrowserKind(kFirefox);
114 else if ((kind == "chrome") || (kind == "chromium"))
115 SetBrowserKind(kChrome);
116 else if ((kind == "cef") || (kind == "cef3"))
117 SetBrowserKind(kCEF);
118 else if ((kind == "qt") || (kind == "qt5"))
119 SetBrowserKind(kQt5);
120 else if ((kind == "embed") || (kind == "embedded"))
121 SetBrowserKind(kEmbedded);
122 else
123 SetCustomExec(kind);
124
125 return *this;
126}
127
128/////////////////////////////////////////////////////////////////////
129/// Returns configured browser name
130
132{
133 switch (GetBrowserKind()) {
134 case kChrome: return "chrome";
135 case kFirefox: return "firefox";
136 case kNative: return "native";
137 case kCEF: return "cef";
138 case kQt5: return "qt5";
139 case kLocal: return "local";
140 case kStandard: return "default";
141 case kEmbedded: return "embed";
142 case kCustom:
143 auto pos = fExec.find(" ");
144 return (pos == std::string::npos) ? fExec : fExec.substr(0,pos);
145 }
146
147 return "";
148}
149
150///////////////////////////////////////////////////////////////////////////////////////////
151/// Assign window and channel id where other window will be embed
152
153void ROOT::Experimental::RWebDisplayArgs::SetMasterWindow(std::shared_ptr<RWebWindow> master, int channel)
154{
155 SetBrowserKind(kEmbedded);
156 fMaster = master;
157 fMasterChannel = channel;
158}
159
160///////////////////////////////////////////////////////////////////////////////////////////
161/// Append string to url options
162/// Add "&" as separator if any options already exists
163
165{
166 if (opt.empty()) return;
167
168 if (!fUrlOpt.empty())
169 fUrlOpt.append("&");
170
171 fUrlOpt.append(opt);
172}
173
174///////////////////////////////////////////////////////////////////////////////////////////
175/// Returns full url, which is combined from URL and extra URL options
176/// Takes into account "#" symbol in url - options are inserted before that symbol
177
179{
180 std::string url = GetUrl(), urlopt = GetUrlOpt();
181 if (url.empty() || urlopt.empty()) return url;
182
183 auto rpos = url.find("#");
184 if (rpos == std::string::npos) rpos = url.length();
185
186 if (url.find("?") != std::string::npos)
187 url.insert(rpos, "&");
188 else
189 url.insert(rpos, "?");
190 url.insert(rpos+1, urlopt);
191
192 return url;
193}
194
195///////////////////////////////////////////////////////////////////////////////////////////
196/// Configure custom web browser
197/// Either just name of browser which can be used like "opera"
198/// or full execution string which must includes $url like "/usr/bin/opera $url"
199
201{
202 SetBrowserKind(kCustom);
203 fExec = exec;
204}
205
206///////////////////////////////////////////////////////////////////////////////////////////
207/// returns custom executable to start web browser
208
210{
211 if (GetBrowserKind() != kCustom)
212 return "";
213
214#ifdef R__MACOSX
215 if ((fExec == "safari") || (fExec == "Safari"))
216 return "open -a Safari";
217#endif
218
219 return fExec;
220}
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
#define gROOT
Definition: TROOT.h:415
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
std::string GetCustomExec() const
returns custom executable to start web browser
RWebDisplayArgs & SetBrowserKind(const std::string &kind)
Set browser kind as string argument Recognized values: chrome - use Google Chrome web browser,...
std::string GetFullUrl() const
returns window url with append options
std::string GetBrowserName() const
Returns configured browser name.
void SetCustomExec(const std::string &exec)
set custom executable to start web browser
void AppendUrlOpt(const std::string &opt)
append extra url options, add "&" as separator if required
void SetMasterWindow(std::shared_ptr< RWebWindow > master, int channel=-1)
Assign window and channel id where other window will be embed.
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