Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:32:16

0001 // Author: Sergey Linev <s.linev@gsi.de>
0002 // Date: 2018-10-24
0003 // Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0004 
0005 /*************************************************************************
0006  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.               *
0007  * All rights reserved.                                                  *
0008  *                                                                       *
0009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0011  *************************************************************************/
0012 
0013 #ifndef ROOT7_RWebDisplayArgs
0014 #define ROOT7_RWebDisplayArgs
0015 
0016 #include <string>
0017 #include <memory>
0018 
0019 class THttpServer;
0020 
0021 namespace ROOT {
0022 
0023 class RLogChannel;
0024 
0025 /// Log channel for WebGUI diagnostics.
0026 ROOT::RLogChannel &WebGUILog();
0027 
0028 class RWebWindow;
0029 
0030 class RWebDisplayArgs {
0031 
0032 friend class RWebWindow;
0033 
0034 public:
0035    enum EBrowserKind {
0036       kChrome,   ///< Google Chrome browser
0037       kEdge,     ///< Microsoft Edge browser (Windows only)
0038       kSafari,   ///< Safari browser
0039       kFirefox,  ///< Mozilla Firefox browser
0040       kNative,   ///< either Chrome or Firefox - both support major functionality
0041       kCEF,      ///< Chromium Embedded Framework - local display with CEF libs
0042       kQt6,      ///< Qt6 QWebEngine libraries - Chromium code packed in qt6
0043       kLocal,    ///< either CEF or Qt5 - both runs on local display without real http server
0044       kDefault,  ///< default system web browser, can not be used in batch mode
0045       kServer,   ///< indicates that ROOT runs as server and just printouts window URL, browser should be started by the user
0046       kEmbedded, ///< window will be embedded into other, no extra browser need to be started
0047       kOff,      ///< disable web display, do not start any browser
0048       kOn,       ///< web display enable, first try use embed displays like Qt or CEF, then native browsers and at the end default system browser
0049       kCustom    ///< custom web browser, execution string should be provided
0050    };
0051 
0052 protected:
0053    EBrowserKind fKind{kNative};   ///<! id of web browser used for display
0054    std::string fUrl;              ///<! URL to display
0055    std::string fExtraArgs;        ///<! extra arguments which will be append to exec string
0056    std::string fPageContent;      ///<! HTML page content
0057    std::string fRedirectOutput;   ///<! filename where browser output should be redirected
0058    std::string fWidgetKind;       ///<! widget kind, used to identify that will be displayed in the web window
0059    bool fBatchMode{false};        ///<! is browser runs in batch mode
0060    bool fHeadless{false};         ///<! is browser runs in headless mode
0061    bool fStandalone{true};        ///<! indicates if browser should run isolated from other browser instances
0062    THttpServer *fServer{nullptr}; ///<! http server which handle all requests
0063    int fWidth{0};                 ///<! custom window width, when not specified - used RWebWindow geometry
0064    int fHeight{0};                ///<! custom window height, when not specified - used RWebWindow geometry
0065    int fX{-1};                    ///<! custom window x position, negative is default
0066    int fY{-1};                    ///<! custom window y position, negative is default
0067    std::string fUrlOpt;           ///<! extra URL options, which are append to window URL
0068    std::string fExec;             ///<! string to run browser, used with kCustom type
0069    void *fDriverData{nullptr};    ///<! special data delivered to driver, can be used for QWebEngine
0070 
0071    std::shared_ptr<RWebWindow> fMaster; ///<!  master window
0072    unsigned fMasterConnection{0};       ///<!  used master connection
0073    int fMasterChannel{-1};              ///<!  used master channel
0074 
0075    bool SetSizeAsStr(const std::string &str);
0076    bool SetPosAsStr(const std::string &str);
0077 
0078 public:
0079    RWebDisplayArgs();
0080 
0081    RWebDisplayArgs(const std::string &browser);
0082 
0083    RWebDisplayArgs(const char *browser);
0084 
0085    RWebDisplayArgs(int width, int height, int x = -1, int y = -1, const std::string &browser = "");
0086 
0087    RWebDisplayArgs(std::shared_ptr<RWebWindow> master, unsigned conndid = 0, int channel = -1);
0088 
0089    virtual ~RWebDisplayArgs();
0090 
0091    RWebDisplayArgs &SetBrowserKind(const std::string &kind);
0092    /// set browser kind, see EBrowserKind for allowed values
0093    RWebDisplayArgs &SetBrowserKind(EBrowserKind kind) { fKind = kind; return *this; }
0094    /// returns configured browser kind, see EBrowserKind for supported values
0095    EBrowserKind GetBrowserKind() const { return fKind; }
0096    std::string GetBrowserName() const;
0097 
0098    void SetMasterWindow(std::shared_ptr<RWebWindow> master, unsigned connid = 0, int channel = -1);
0099 
0100    /// returns true if interactive browser window supposed to be started
0101    bool IsInteractiveBrowser() const
0102    {
0103       return !IsHeadless() &&
0104              ((GetBrowserKind() == kOn) || (GetBrowserKind() == kNative) || (GetBrowserKind() == kChrome) ||
0105               (GetBrowserKind() == kEdge) || (GetBrowserKind() == kSafari) || (GetBrowserKind() == kFirefox) ||
0106               (GetBrowserKind() == kDefault) || (GetBrowserKind() == kCustom));
0107    }
0108 
0109    /// returns true if local display like CEF or Qt5 QWebEngine should be used
0110    bool IsLocalDisplay() const
0111    {
0112       return (GetBrowserKind() == kLocal) || (GetBrowserKind() == kCEF) || (GetBrowserKind() == kQt6);
0113    }
0114 
0115    /// returns true if browser supports headless mode
0116    bool IsSupportHeadless() const
0117    {
0118       return (GetBrowserKind() == kNative) || (GetBrowserKind() == kDefault) || (GetBrowserKind() == kOn) ||
0119              (GetBrowserKind() == kChrome) || (GetBrowserKind() == kEdge) || (GetBrowserKind() == kFirefox) ||
0120              (GetBrowserKind() == kCEF) || (GetBrowserKind() == kQt6);
0121    }
0122 
0123    /// set window url
0124    RWebDisplayArgs &SetUrl(const std::string &url) { fUrl = url; return *this; }
0125    /// returns window url
0126    const std::string &GetUrl() const { return fUrl; }
0127 
0128    /// set widget kind
0129    RWebDisplayArgs &SetWidgetKind(const std::string &kind) { fWidgetKind = kind; return *this; }
0130    /// returns widget kind
0131    const std::string &GetWidgetKind() const { return fWidgetKind; }
0132 
0133    /// set window url
0134    RWebDisplayArgs &SetPageContent(const std::string &cont) { fPageContent = cont; return *this; }
0135    /// returns window url
0136    const std::string &GetPageContent() const { return fPageContent; }
0137 
0138    /// Set standalone mode for running browser, default on
0139    /// When disabled, normal browser window (or just tab) will be started
0140    void SetStandalone(bool on = true) { fStandalone = on; }
0141    /// Return true if browser should runs in standalone mode
0142    bool IsStandalone() const { return fStandalone; }
0143 
0144    /// set window url options
0145    RWebDisplayArgs &SetUrlOpt(const std::string &opt) { fUrlOpt = opt; return *this; }
0146    /// returns window url options
0147    const std::string &GetUrlOpt() const { return fUrlOpt; }
0148 
0149    /// append extra url options, add "&" as separator if required
0150    void AppendUrlOpt(const std::string &opt);
0151 
0152    /// returns window url with append options
0153    std::string GetFullUrl() const;
0154 
0155    /// set batch mode
0156    void SetBatchMode(bool on = true) { fBatchMode = on; }
0157    /// returns batch mode
0158    bool IsBatchMode() const { return fBatchMode; }
0159 
0160    /// set headless mode
0161    void SetHeadless(bool on = true) { fHeadless = on; }
0162    /// returns headless mode
0163    bool IsHeadless() const { return fHeadless; }
0164 
0165    /// set preferable web window width
0166    RWebDisplayArgs &SetWidth(int w = 0) { fWidth = w; return *this; }
0167    /// set preferable web window height
0168    RWebDisplayArgs &SetHeight(int h = 0) { fHeight = h; return *this; }
0169    /// set preferable web window width and height
0170    RWebDisplayArgs &SetSize(int w, int h) { fWidth = w; fHeight = h; return *this; }
0171 
0172    /// set preferable web window x position, negative is default
0173    RWebDisplayArgs &SetX(int x = -1) { fX = x; return *this; }
0174    /// set preferable web window y position, negative is default
0175    RWebDisplayArgs &SetY(int y = -1) { fY = y; return *this; }
0176    /// set preferable web window x and y position, negative is default
0177    RWebDisplayArgs &SetPos(int x = -1, int y = -1) { fX = x; fY = y; return *this; }
0178 
0179    /// returns preferable web window width
0180    int GetWidth() const { return fWidth; }
0181    /// returns preferable web window height
0182    int GetHeight() const { return fHeight; }
0183    /// set preferable web window x position
0184    int GetX() const { return fX; }
0185    /// set preferable web window y position
0186    int GetY() const { return fY; }
0187 
0188    /// set extra command line arguments for starting web browser command
0189    void SetExtraArgs(const std::string &args) { fExtraArgs = args; }
0190    /// get extra command line arguments for starting web browser command
0191    const std::string &GetExtraArgs() const { return fExtraArgs; }
0192 
0193    /// specify file name to which web browser output should be redirected
0194    void SetRedirectOutput(const std::string &fname = "") { fRedirectOutput = fname; }
0195    /// get file name to which web browser output should be redirected
0196    const std::string &GetRedirectOutput() const { return fRedirectOutput; }
0197 
0198    /// set custom executable to start web browser
0199    void SetCustomExec(const std::string &exec);
0200    /// returns custom executable to start web browser
0201    std::string GetCustomExec() const;
0202 
0203    /// set http server instance, used for window display
0204    void SetHttpServer(THttpServer *serv) { fServer = serv; }
0205    /// returns http server instance, used for window display
0206    THttpServer *GetHttpServer() const { return fServer; }
0207 
0208    /// [internal] set web-driver data, used to start window
0209    void SetDriverData(void *data) { fDriverData = data; }
0210    /// [internal] returns web-driver data, used to start window
0211    void *GetDriverData() const { return fDriverData; }
0212 
0213    static std::string GetQt5EmbedQualifier(const void *qparent, const std::string &urlopt = "", unsigned qtversion = 0x60000);
0214 
0215    static std::string GetQtEmbedQualifier(const void *qparent, const std::string &urlopt = "", unsigned qtversion = 0x60000);
0216 
0217 };
0218 
0219 } // namespace ROOT
0220 
0221 #endif