Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:49

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