Logo ROOT   master
Reference Guide
RWebDisplayArgs.hxx
Go to the documentation of this file.
1 /// \file ROOT/RWebDisplayArgs.hxx
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 
16 #ifndef ROOT7_RWebDisplayArgs
17 #define ROOT7_RWebDisplayArgs
18 
19 #include <string>
20 #include <memory>
21 
22 class THttpServer;
23 
24 namespace ROOT {
25 namespace Experimental {
26 
27 class RWebWindow;
28 
30 
31 friend class RWebWindow;
32 
33 public:
34  enum EBrowserKind {
35  kChrome, ///< Google Chrome browser
36  kFirefox, ///< Mozilla Firefox browser
37  kNative, ///< either Chrome or Firefox - both support major functionality
38  kCEF, ///< Chromium Embedded Framework - local display with CEF libs
39  kQt5, ///< QWebEngine libraries - Chrome code packed in qt5
40  kLocal, ///< either CEF or Qt5 - both runs on local display without real http server
41  kStandard, ///< standard system web browser, not recognized by ROOT, without batch mode
42  kEmbedded, ///< window will be embedded into other, no extra browser need to be started
43  kCustom ///< custom web browser, execution string should be provided
44  };
45 
46 protected:
47  EBrowserKind fKind{kNative}; ///<! id of web browser used for display
48  std::string fUrl; ///<! URL to display
49  std::string fExtraArgs; ///<! extra arguments which will be append to exec string
50  std::string fRedirectOutput; ///<! filename where browser output should be redirected
51  bool fHeadless{false}; ///<! is browser runs in headless mode
52  bool fStandalone{true}; ///<! indicates if browser should run isolated from other browser instances
53  THttpServer *fServer{nullptr}; ///<! http server which handle all requests
54  int fWidth{0}; ///<! custom window width, when not specified - used RWebWindow geometry
55  int fHeight{0}; ///<! custom window height, when not specified - used RWebWindow geometry
56  int fX{-1}; ///<! custom window x position, negative is default
57  int fY{-1}; ///<! custom window y position, negative is default
58  std::string fUrlOpt; ///<! extra URL options, which are append to window URL
59  std::string fExec; ///<! string to run browser, used with kCustom type
60  void *fDriverData{nullptr}; ///<! special data delivered to driver, can be used for QWebEngine
61 
62  std::shared_ptr<RWebWindow> fMaster; ///<! master window
63  int fMasterChannel{-1}; ///<! used master channel
64 
65  bool SetSizeAsStr(const std::string &str);
66  bool SetPosAsStr(const std::string &str);
67 
68 public:
70 
71  RWebDisplayArgs(const std::string &browser);
72 
73  RWebDisplayArgs(const char *browser);
74 
75  RWebDisplayArgs(int width, int height, int x = -1, int y = -1, const std::string &browser = "");
76 
77  RWebDisplayArgs(std::shared_ptr<RWebWindow> master, int channel = -1);
78 
79  virtual ~RWebDisplayArgs();
80 
81  RWebDisplayArgs &SetBrowserKind(const std::string &kind);
82  /// set browser kind, see EBrowserKind for allowed values
83  RWebDisplayArgs &SetBrowserKind(EBrowserKind kind) { fKind = kind; return *this; }
84  /// returns configured browser kind, see EBrowserKind for supported values
85  EBrowserKind GetBrowserKind() const { return fKind; }
86  std::string GetBrowserName() const;
87 
88  void SetMasterWindow(std::shared_ptr<RWebWindow> master, int channel = -1);
89 
90  /// returns true if local display like CEF or Qt5 QWebEngine should be used
91  bool IsLocalDisplay() const
92  {
93  return (GetBrowserKind() == kLocal) || (GetBrowserKind() == kCEF) || (GetBrowserKind() == kQt5);
94  }
95 
96  /// returns true if browser supports headless mode
97  bool IsSupportHeadless() const
98  {
99  return (GetBrowserKind() == kNative) || (GetBrowserKind() == kFirefox) || (GetBrowserKind() == kChrome);
100  }
101 
102  /// set window url
103  RWebDisplayArgs &SetUrl(const std::string &url) { fUrl = url; return *this; }
104  /// returns window url
105  std::string GetUrl() const { return fUrl; }
106 
107  /// Set standalone mode for running browser, default on
108  /// When disabled, normal browser window (or just tab) will be started
109  void SetStandalone(bool on = true) { fStandalone = on; }
110  /// Return true if browser should runs in standalone mode
111  bool IsStandalone() const { return fStandalone; }
112 
113  /// set window url options
114  RWebDisplayArgs &SetUrlOpt(const std::string &opt) { fUrlOpt = opt; return *this; }
115  /// returns window url options
116  std::string GetUrlOpt() const { return fUrlOpt; }
117 
118  /// append extra url options, add "&" as separator if required
119  void AppendUrlOpt(const std::string &opt);
120 
121  /// returns window url with append options
122  std::string GetFullUrl() const;
123 
124  /// set headless mode
125  void SetHeadless(bool on = true) { fHeadless = on; }
126  /// returns headless mode
127  bool IsHeadless() const { return fHeadless; }
128 
129  /// set preferable web window width
130  RWebDisplayArgs &SetWidth(int w = 0) { fWidth = w; return *this; }
131  /// set preferable web window height
132  RWebDisplayArgs &SetHeight(int h = 0) { fHeight = h; return *this; }
133  RWebDisplayArgs &SetSize(int w, int h) { fWidth = w; fHeight = h; return *this; }
134 
135  /// set preferable web window x position, negative is default
136  RWebDisplayArgs &SetX(int x = -1) { fX = x; return *this; }
137  /// set preferable web window y position, negative is default
138  RWebDisplayArgs &SetY(int y = -1) { fY = y; return *this; }
139  RWebDisplayArgs &SetPos(int x = -1, int y = -1) { fX = x; fY = y; return *this; }
140 
141  /// returns preferable web window width
142  int GetWidth() const { return fWidth; }
143  /// returns preferable web window height
144  int GetHeight() const { return fHeight; }
145  /// set preferable web window x position
146  int GetX() const { return fX; }
147  /// set preferable web window y position
148  int GetY() const { return fY; }
149 
150  void SetExtraArgs(const std::string &args) { fExtraArgs = args; }
151  const std::string &GetExtraArgs() const { return fExtraArgs; }
152 
153  void SetRedirectOutput(const std::string &fname = "") { fRedirectOutput = fname; }
154  const std::string &GetRedirectOutput() const { return fRedirectOutput; }
155 
156  /// set custom executable to start web browser
157  void SetCustomExec(const std::string &exec);
158  /// returns custom executable to start web browser
159  std::string GetCustomExec() const;
160 
161  /// set http server instance, used for window display
162  void SetHttpServer(THttpServer *serv) { fServer = serv; }
163  /// returns http server instance, used for window display
164  THttpServer *GetHttpServer() const { return fServer; }
165 
166  /// [internal] set web-driver data, used to start window
167  void SetDriverData(void *data) { fDriverData = data; }
168  /// [internal] returns web-driver data, used to start window
169  void *GetDriverData() const { return fDriverData; }
170 };
171 
172 }
173 }
174 
175 #endif
bool fStandalone
! indicates if browser should run isolated from other browser instances
RWebDisplayArgs & SetSize(int w, int h)
void SetHttpServer(THttpServer *serv)
set http server instance, used for window display
int GetWidth() const
returns preferable web window width
void SetStandalone(bool on=true)
Set standalone mode for running browser, default on When disabled, normal browser window (or just tab...
RWebDisplayArgs & SetWidth(int w=0)
set preferable web window width
Returns the available number of logical cores.
Definition: StringConv.hxx:21
THttpServer * fServer
! http server which handle all requests
RWebDisplayArgs & SetBrowserKind(const std::string &kind)
Set browser kind as string argument Recognized values: chrome - use Google Chrome web browser...
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
void SetDriverData(void *data)
[internal] set web-driver data, used to start window
const std::string & GetExtraArgs() const
RWebDisplayArgs & SetY(int y=-1)
set preferable web window y position, negative is default
either CEF or Qt5 - both runs on local display without real http server
void SetRedirectOutput(const std::string &fname="")
std::shared_ptr< RWebWindow > fMaster
! master window
void * fDriverData
! special data delivered to driver, can be used for QWebEngine
int GetX() const
set preferable web window x position
QWebEngine libraries - Chrome code packed in qt5.
bool IsHeadless() const
returns headless mode
int fWidth
! custom window width, when not specified - used RWebWindow geometry
virtual ~RWebDisplayArgs()
Destructor.
std::string GetCustomExec() const
returns custom executable to start web browser
bool IsStandalone() const
Return true if browser should runs in standalone mode.
void SetMasterWindow(std::shared_ptr< RWebWindow > master, int channel=-1)
Assign window and channel id where other window will be embed.
int fX
! custom window x position, negative is default
Double_t x[n]
Definition: legend1.C:17
THttpServer * GetHttpServer() const
returns http server instance, used for window display
std::string fUrl
! URL to display
std::string fUrlOpt
! extra URL options, which are append to window URL
int fY
! custom window y position, negative is default
bool fHeadless
! is browser runs in headless mode
void SetHeadless(bool on=true)
set headless mode
std::string fExtraArgs
! extra arguments which will be append to exec string
RWebDisplayArgs()
Default constructor - browser kind configured from gROOT->GetWebDisplay()
int fMasterChannel
! used master channel
EBrowserKind fKind
! id of web browser used for display
std::string fExec
! string to run browser, used with kCustom type
window will be embedded into other, no extra browser need to be started
Represents web window, which can be shown in web browser or any other supported environment.
Definition: RWebWindow.hxx:56
int GetHeight() const
returns preferable web window height
bool SetPosAsStr(const std::string &str)
Set position of web browser window as string like "100,100".
std::string GetUrlOpt() const
returns window url options
RWebDisplayArgs & SetUrl(const std::string &url)
set window url
either Chrome or Firefox - both support major functionality
void AppendUrlOpt(const std::string &opt)
append extra url options, add "&" as separator if required
#define h(i)
Definition: RSha256.hxx:106
void SetCustomExec(const std::string &exec)
set custom executable to start web browser
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:120
int fHeight
! custom window height, when not specified - used RWebWindow geometry
std::string GetUrl() const
returns window url
std::string GetFullUrl() const
returns window url with append options
bool IsLocalDisplay() const
returns true if local display like CEF or Qt5 QWebEngine should be used
void * GetDriverData() const
[internal] returns web-driver data, used to start window
Double_t y[n]
Definition: legend1.C:17
custom web browser, execution string should be provided
RWebDisplayArgs & SetHeight(int h=0)
set preferable web window height
const std::string & GetRedirectOutput() const
void SetExtraArgs(const std::string &args)
bool SetSizeAsStr(const std::string &str)
Set size of web browser window as string like "800x600".
RWebDisplayArgs & SetPos(int x=-1, int y=-1)
EBrowserKind GetBrowserKind() const
returns configured browser kind, see EBrowserKind for supported values
Chromium Embedded Framework - local display with CEF libs.
int GetY() const
set preferable web window y position
std::string fRedirectOutput
! filename where browser output should be redirected
RWebDisplayArgs & SetUrlOpt(const std::string &opt)
set window url options
RWebDisplayArgs & SetBrowserKind(EBrowserKind kind)
set browser kind, see EBrowserKind for allowed values
RWebDisplayArgs & SetX(int x=-1)
set preferable web window x position, negative is default
bool IsSupportHeadless() const
returns true if browser supports headless mode
std::string GetBrowserName() const
Returns configured browser name.
standard system web browser, not recognized by ROOT, without batch mode