Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
29 class RWebDisplayArgs {
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  bool fHeadless{false}; ///<! is browser runs in headless mode
50  bool fStandalone{true}; ///<! indicates if browser should run isolated from other browser instances
51  THttpServer *fServer{nullptr}; ///<! http server which handle all requests
52  int fWidth{0}; ///<! custom window width, when not specified - used RWebWindow geometry
53  int fHeight{0}; ///<! custom window height, when not specified - used RWebWindow geometry
54  int fX{-1}; ///<! custom window x position, negative is default
55  int fY{-1}; ///<! custom window y position, negative is default
56  std::string fUrlOpt; ///<! extra URL options, which are append to window URL
57  std::string fExec; ///<! string to run browser, used with kCustom type
58  void *fDriverData{nullptr}; ///<! special data delivered to driver, can be used for QWebEngine
59 
60  std::shared_ptr<RWebWindow> fMaster; ///<! master window
61  int fMasterChannel{-1}; ///<! used master channel
62 
63 public:
64  RWebDisplayArgs();
65 
66  RWebDisplayArgs(const std::string &browser);
67 
68  RWebDisplayArgs(const char *browser);
69 
70  RWebDisplayArgs(int width, int height, int x = -1, int y = -1, const std::string &browser = "");
71 
72  RWebDisplayArgs(std::shared_ptr<RWebWindow> master, int channel = -1);
73 
74  virtual ~RWebDisplayArgs();
75 
76  RWebDisplayArgs &SetBrowserKind(const std::string &kind);
77  /// set browser kind, see EBrowserKind for allowed values
78  RWebDisplayArgs &SetBrowserKind(EBrowserKind kind) { fKind = kind; return *this; }
79  /// returns configured browser kind, see EBrowserKind for supported values
80  EBrowserKind GetBrowserKind() const { return fKind; }
81  std::string GetBrowserName() const;
82 
83  void SetMasterWindow(std::shared_ptr<RWebWindow> master, int channel = -1);
84 
85  /// returns true if local display like CEF or Qt5 QWebEngine should be used
86  bool IsLocalDisplay() const
87  {
88  return (GetBrowserKind() == kLocal) || (GetBrowserKind() == kCEF) || (GetBrowserKind() == kQt5);
89  }
90 
91  /// returns true if browser supports headless mode
92  bool IsSupportHeadless() const
93  {
94  return (GetBrowserKind() == kNative) || (GetBrowserKind() == kFirefox) || (GetBrowserKind() == kChrome);
95  }
96 
97  /// set window url
98  RWebDisplayArgs &SetUrl(const std::string &url) { fUrl = url; return *this; }
99  /// returns window url
100  std::string GetUrl() const { return fUrl; }
101 
102  /// Set standalone mode for running browser, default on
103  /// When disabled, normal browser window (or just tab) will be started
104  void SetStandalone(bool on = true) { fStandalone = on; }
105  /// Return true if browser should runs in standalone mode
106  bool IsStandalone() const { return fStandalone; }
107 
108  /// set window url options
109  RWebDisplayArgs &SetUrlOpt(const std::string &opt) { fUrlOpt = opt; return *this; }
110  /// returns window url options
111  std::string GetUrlOpt() const { return fUrlOpt; }
112 
113  /// append extra url options, add "&" as separator if required
114  void AppendUrlOpt(const std::string &opt);
115 
116  /// returns window url with append options
117  std::string GetFullUrl() const;
118 
119  /// set headless mode
120  void SetHeadless(bool on = true) { fHeadless = on; }
121  /// returns headless mode
122  bool IsHeadless() const { return fHeadless; }
123 
124  /// set preferable web window width
125  RWebDisplayArgs &SetWidth(int w = 0) { fWidth = w; return *this; }
126  /// set preferable web window height
127  RWebDisplayArgs &SetHeight(int h = 0) { fHeight = h; return *this; }
128  RWebDisplayArgs &SetSize(int w, int h) { fWidth = w; fHeight = h; return *this; }
129 
130  /// set preferable web window x position, negative is default
131  RWebDisplayArgs &SetX(int x = -1) { fX = x; return *this; }
132  /// set preferable web window y position, negative is default
133  RWebDisplayArgs &SetY(int y = -1) { fY = y; return *this; }
134  RWebDisplayArgs &SetPos(int x = -1, int y = -1) { fX = x; fY = y; return *this; }
135 
136  /// returns preferable web window width
137  int GetWidth() const { return fWidth; }
138  /// returns preferable web window height
139  int GetHeight() const { return fHeight; }
140  /// set preferable web window x position
141  int GetX() const { return fX; }
142  /// set preferable web window y position
143  int GetY() const { return fY; }
144 
145  /// set custom executable to start web browser
146  void SetCustomExec(const std::string &exec);
147  /// returns custom executable to start web browser
148  std::string GetCustomExec() const;
149 
150  /// set http server instance, used for window display
151  void SetHttpServer(THttpServer *serv) { fServer = serv; }
152  /// returns http server instance, used for window display
153  THttpServer *GetHttpServer() const { return fServer; }
154 
155  /// [internal] set web-driver data, used to start window
156  void SetDriverData(void *data) { fDriverData = data; }
157  /// [internal] returns web-driver data, used to start window
158  void *GetDriverData() const { return fDriverData; }
159 };
160 
161 }
162 }
163 
164 #endif