예제 #1
0
        public ArkDesktopBrowserControl()
        {
            #region Handler
            lifeSpanHandler = new CfxLifeSpanHandler();
            lifeSpanHandler.OnAfterCreated += LifeSpanHandler_OnAfterCreated;

            renderHandler = new CfxRenderHandler();
            //renderHandler.GetRootScreenRect += renderHandler_GetRootScreenRect;
            //renderHandler.GetScreenInfo += renderHandler_GetScreenInfo;
            //renderHandler.OnCursorChange += renderHandler_OnCursorChange;
            renderHandler.GetScreenPoint += RenderHandler_GetScreenPoint;
            renderHandler.GetViewRect    += RenderHandler_GetViewRect;
            renderHandler.OnPaint        += RenderHandler_OnPaint;

            loadHandler              = new CfxLoadHandler();
            loadHandler.OnLoadError += LoadHandler_OnLoadError;
            loadHandler.OnLoadEnd   += LoadHandler_OnLoadEnd;
            #endregion

            client = new CfxClient();
            client.GetLifeSpanHandler += (sender, e) => e.SetReturnValue(lifeSpanHandler);
            client.GetRenderHandler   += (sender, e) => e.SetReturnValue(renderHandler);
            client.GetLoadHandler     += (sender, e) => e.SetReturnValue(loadHandler);

            var settings = new CfxBrowserSettings();
            settings.BackgroundColor = new CfxColor(0, 0, 0, 0);

            var windowInfo = new CfxWindowInfo();
            windowInfo.SetAsWindowless(IntPtr.Zero);

            CfxBrowserHost.CreateBrowser(windowInfo, client, "about:blank", settings, null);
        }
        private Task <CfxBrowser> RawInit(string path)
        {
            var loadTaskCompletionSource = new TaskCompletionSource <CfxBrowser>();
            var cfxWindowInfo            = new CfxWindowInfo();

            _CfxClient = new CfxClient();

            var loadHandler = new CfxLoadHandler();

            loadHandler.OnLoadEnd += (sender, args) =>
            {
                loadTaskCompletionSource.TrySetResult(args.Browser);
            };
            _CfxClient.GetLoadHandler += (o, e) => e.SetReturnValue(loadHandler);

            var lifeSpanHandler = new CfxLifeSpanHandler();

            _CfxClient.GetLifeSpanHandler += (o, e) => e.SetReturnValue(lifeSpanHandler);

            var renderHandler = new CfxRenderHandler();

            _CfxClient.GetRenderHandler += (sender, e) => e.SetReturnValue(renderHandler);

            if (!CfxBrowserHost.CreateBrowser(cfxWindowInfo, _CfxClient, path, GetSettings(), null, null))
            {
                throw new Exception("Problem initializing CEF");
            }

            return(loadTaskCompletionSource.Task);
        }
예제 #3
0
        public CfxUiWnd()
        {
            InitializeComponent();

            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            cfxLifeSpanHandler = new CfxLifeSpanHandler();
            cfxLifeSpanHandler.OnAfterCreated += lifeSpanHandler_OnAfterCreated;

            cfxRenderHandler = new CfxRenderHandler();

            cfxRenderHandler.GetRootScreenRect += renderHandler_GetRootScreenRect;
            cfxRenderHandler.GetScreenInfo     += renderHandler_GetScreenInfo;
            cfxRenderHandler.GetScreenPoint    += renderHandler_GetScreenPoint;
            cfxRenderHandler.GetViewRect       += renderHandler_GetViewRect;
            cfxRenderHandler.OnCursorChange    += renderHandler_OnCursorChange;
            cfxRenderHandler.OnPaint           += renderHandler_OnPaint;
            //cfxRenderHandler.OnPopupShow += renderHandler_OnPopupShow;
            //cfxRenderHandler.OnPopupSize += renderHandler_OnPopupSize;
            //cfxRenderHandler.OnScrollOffsetChanged += renderHandler_OnScrollOffsetChanged;
            //cfxRenderHandler.StartDragging += renderHandler_StartDragging;
            //cfxRenderHandler.UpdateDragCursor += renderHandler_UpdateDragCursor;

            cfxLoadHandler = new CfxLoadHandler();

            cfxLoadHandler.OnLoadError += loadHandler_OnLoadError;

            cfxClient = new CfxClient();
            cfxClient.GetLifeSpanHandler += (sender, e) => e.SetReturnValue(cfxLifeSpanHandler);
            cfxClient.GetRenderHandler   += (sender, e) => e.SetReturnValue(cfxRenderHandler);
            cfxClient.GetLoadHandler     += (sender, e) => e.SetReturnValue(cfxLoadHandler);

            // Create handle now for InvokeRequired to work properly
            CreateHandle();
        }
예제 #4
0
        private void Register()
        {
            lifeSpanHandler = new CfxLifeSpanHandler();
            renderHandler   = new CfxRenderHandler();
            loadHandler     = new CfxLoadHandler();
            client          = new CfxClient();
            windowInfo      = new CfxWindowInfo();
            browserSettings = new CfxBrowserSettings {
                WindowlessFrameRate = 60
            };
            mouseEvent = new CfxMouseEvent();

            lifeSpanHandler.OnAfterCreated += (sender, args) =>
            {
                browser = args.Browser;
                Thread.Sleep(100);
            };

            renderHandler.GetViewRect += (sender, args) =>
            {
                CalculatedStyle dimensions = GetDimensions();
                args.Rect.X      = 0;
                args.Rect.Y      = 0;
                args.Rect.Width  = (int)dimensions.Width;
                args.Rect.Height = (int)dimensions.Height;
                args.SetReturnValue(true);
            };
            renderHandler.GetScreenPoint += (sender, args) =>
            {
                args.ScreenX = 0;
                args.ScreenY = 0;
                args.SetReturnValue(true);
            };

            loadHandler.OnLoadError += (sender, args) =>
            {
                if (args.ErrorCode == CfxErrorCode.Aborted)
                {
                    var url   = args.FailedUrl;
                    var frame = args.Frame;
                    ThreadPool.QueueUserWorkItem(state =>
                    {
                        Thread.Sleep(200);
                        frame.LoadUrl(url);
                    });
                }
            };

            client.GetLifeSpanHandler += (sender, args) => args.SetReturnValue(lifeSpanHandler);
            client.GetRenderHandler   += (sender, args) => args.SetReturnValue(renderHandler);
            client.GetLoadHandler     += (sender, args) => args.SetReturnValue(loadHandler);

            windowInfo.SetAsWindowless(IntPtr.Zero);

            CfxBrowserHost.CreateBrowser(windowInfo, client, URL, browserSettings, null);
        }
예제 #5
0
        public HtmlWidgetForm(string initialUrl)
        {
            FormBorderStyle = FormBorderStyle.None;

            mutex = new Mutex(false, string.Format("NanUIWidget{0}", Process.GetCurrentProcess().Id), out locked);


            lifeSpanHandler = new CfxLifeSpanHandler();
            lifeSpanHandler.OnAfterCreated += lifeSpanHandler_OnAfterCreated;

            renderHandler = new CfxRenderHandler();

            renderHandler.GetRootScreenRect += renderHandler_GetRootScreenRect;
            renderHandler.GetScreenInfo     += renderHandler_GetScreenInfo;
            renderHandler.GetScreenPoint    += renderHandler_GetScreenPoint;
            renderHandler.GetViewRect       += renderHandler_GetViewRect;
            renderHandler.OnCursorChange    += renderHandler_OnCursorChange;
            renderHandler.OnPaint           += renderHandler_OnPaint;

            //renderHandler.OnPopupShow += renderHandler_OnPopupShow;
            //renderHandler.OnPopupSize += renderHandler_OnPopupSize;
            //renderHandler.OnScrollOffsetChanged += renderHandler_OnScrollOffsetChanged;
            //renderHandler.StartDragging += renderHandler_StartDragging;
            //renderHandler.UpdateDragCursor += renderHandler_UpdateDragCursor;

            loadHandler = new CfxLoadHandler();

            loadHandler.OnLoadError += loadHandler_OnLoadError;

            client = new CfxClient();
            client.GetLifeSpanHandler += (sender, e) => e.SetReturnValue(lifeSpanHandler);
            client.GetRenderHandler   += (sender, e) => e.SetReturnValue(renderHandler);
            client.GetLoadHandler     += (sender, e) => e.SetReturnValue(loadHandler);

            var settings = new CfxBrowserSettings();

            var windowInfo = new CfxWindowInfo();

            windowInfo.SetAsWindowless(false);
            windowInfo.TransparentPaintingEnabled = true;

            CreateHandle();

            CfxBrowserHost.CreateBrowser(windowInfo, client, initialUrl, settings, null);
        }
예제 #6
0
        public ArkDesktopBrowserControl(ArkDesktop.LayeredWindow window)
        {
            #region Handler
            lifeSpanHandler = new CfxLifeSpanHandler();
            lifeSpanHandler.OnAfterCreated += LifeSpanHandler_OnAfterCreated;

            renderHandler = new CfxRenderHandler();
            //renderHandler.GetRootScreenRect += renderHandler_GetRootScreenRect;
            //renderHandler.GetScreenInfo += renderHandler_GetScreenInfo;
            //renderHandler.OnCursorChange += renderHandler_OnCursorChange;
            renderHandler.GetScreenPoint += RenderHandler_GetScreenPoint;
            renderHandler.GetViewRect    += RenderHandler_GetViewRect;
            renderHandler.OnPaint        += RenderHandler_OnPaint;

            loadHandler              = new CfxLoadHandler();
            loadHandler.OnLoadError += LoadHandler_OnLoadError;
            loadHandler.OnLoadEnd   += LoadHandler_OnLoadEnd;

            requestHandler = new CfxRequestHandler();
            requestHandler.GetResourceHandler += RequestHandler_GetResourceHandler;
            #endregion

            client = new CfxClient();
            client.GetLifeSpanHandler += (sender, e) => e.SetReturnValue(lifeSpanHandler);
            client.GetRenderHandler   += (sender, e) => e.SetReturnValue(renderHandler);
            //client.GetLoadHandler += (sender, e) => e.SetReturnValue(loadHandler);
            client.GetRequestHandler += (sender, e) => e.SetReturnValue(requestHandler);

            var settings = new CfxBrowserSettings();
            settings.BackgroundColor = new CfxColor(0, 0, 0, 0);

            var windowInfo = new CfxWindowInfo();
            windowInfo.SetAsWindowless(IntPtr.Zero);

            CfxBrowserHost.CreateBrowser(windowInfo, client, "http://www.bing.com/", settings, null);

            this.window       = window;
            window.MouseDown += Window_MouseDown;
            window.MouseUp   += Window_MouseUp;
            window.MouseMove += Window_MouseMove;
        }
        public BrowserControl()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            lifeSpanHandler = new CfxLifeSpanHandler();
            lifeSpanHandler.OnAfterCreated += lifeSpanHandler_OnAfterCreated;

            renderHandler = new CfxRenderHandler();

            renderHandler.GetRootScreenRect += renderHandler_GetRootScreenRect;
            renderHandler.GetScreenInfo     += renderHandler_GetScreenInfo;
            renderHandler.GetScreenPoint    += renderHandler_GetScreenPoint;
            renderHandler.GetViewRect       += renderHandler_GetViewRect;
            renderHandler.OnCursorChange    += renderHandler_OnCursorChange;
            renderHandler.OnPaint           += renderHandler_OnPaint;
            //renderHandler.OnPopupShow += renderHandler_OnPopupShow;
            //renderHandler.OnPopupSize += renderHandler_OnPopupSize;
            //renderHandler.OnScrollOffsetChanged += renderHandler_OnScrollOffsetChanged;
            //renderHandler.StartDragging += renderHandler_StartDragging;
            //renderHandler.UpdateDragCursor += renderHandler_UpdateDragCursor;

            loadHandler = new CfxLoadHandler();

            loadHandler.OnLoadError += loadHandler_OnLoadError;

            client = new CfxClient();
            client.GetLifeSpanHandler += (sender, e) => e.SetReturnValue(lifeSpanHandler);
            client.GetRenderHandler   += (sender, e) => e.SetReturnValue(renderHandler);
            client.GetLoadHandler     += (sender, e) => e.SetReturnValue(loadHandler);

            var settings = new CfxBrowserSettings();

            var windowInfo = new CfxWindowInfo();

            windowInfo.SetAsWindowless(false);

            // Create handle now for InvokeRequired to work properly
            CreateHandle();
            CfxBrowserHost.CreateBrowser(windowInfo, client, "about:blank", settings, null);
        }
예제 #8
0
        public ArkDesktopBrowserControl()
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            #region Handler
            lifeSpanHandler = new CfxLifeSpanHandler();
            lifeSpanHandler.OnAfterCreated += LifeSpanHandler_OnAfterCreated;

            renderHandler = new CfxRenderHandler();
            //renderHandler.GetRootScreenRect += renderHandler_GetRootScreenRect;
            //renderHandler.GetScreenInfo += renderHandler_GetScreenInfo;
            //renderHandler.OnCursorChange += renderHandler_OnCursorChange;
            renderHandler.GetScreenPoint += RenderHandler_GetScreenPoint;
            renderHandler.GetViewRect    += RenderHandler_GetViewRect;
            renderHandler.OnPaint        += RenderHandler_OnPaint;

            loadHandler              = new CfxLoadHandler();
            loadHandler.OnLoadError += LoadHandler_OnLoadError;
            #endregion

            client = new CfxClient();
            client.GetLifeSpanHandler += (sender, e) => e.SetReturnValue(lifeSpanHandler);
            client.GetRenderHandler   += (sender, e) => e.SetReturnValue(renderHandler);
            client.GetLoadHandler     += (sender, e) => e.SetReturnValue(loadHandler);

            var settings = new CfxBrowserSettings();
            settings.BackgroundColor = new CfxColor(0, 0, 0, 0);

            var windowInfo = new CfxWindowInfo();
            windowInfo.SetAsWindowless(IntPtr.Zero);

            // Create handle now for InvokeRequired to work properly
            CreateHandle();
            CfxBrowserHost.CreateBrowser(windowInfo, client, "about:blank", settings, null);
        }
        //called when data for any output pin is requested
        public void Update(int SpreadMax)
        {
            if (this.FTextureOutput[0] == null)
            {
                this.FTextureOutput[0] = new DX11Resource <DX11DynamicTexture2D>();
            }

            if (!init)
            {
                width  = DEFAULT_WIDTH;
                height = DEFAULT_HEIGHT;

                lifeSpanHandler = new CfxLifeSpanHandler();
                lifeSpanHandler.OnAfterCreated += lifeSpanHandler_OnAfterCreated;
                lifeSpanHandler.OnBeforePopup  += lifeSpanHandler_OnBeforePopup;

                renderHandler                    = new CfxRenderHandler();
                renderHandler.GetViewRect       += renderHandler_GetViewRect;
                renderHandler.GetRootScreenRect += renderHandler_GetRootScreenRect;
                renderHandler.OnPaint           += renderHandler_OnPaint;

                loadHandler                       = new CfxLoadHandler();
                loadHandler.OnLoadError          += loadHandler_OnLoadError;
                loadHandler.OnLoadingStateChange += loadHandler_OnLoadingStateChange;

                requestHandler = new CfxRequestHandler();
                requestHandler.OnBeforeBrowse       += requestHandler_OnBeforeBrowse;
                requestHandler.OnBeforeResourceLoad += requestHandler_OnBeforeResourceLoad;


                displayHandler = new CfxDisplayHandler();
                displayHandler.OnConsoleMessage += displayHandler_OnConsoleMessage;
                client = new CfxClient();
                client.GetLifeSpanHandler += (sender, e) => e.SetReturnValue(lifeSpanHandler);
                client.GetRenderHandler   += (sender, e) => e.SetReturnValue(renderHandler);
                client.GetLoadHandler     += (sender, e) => e.SetReturnValue(loadHandler);
                client.GetRequestHandler  += (sender, e) => e.SetReturnValue(requestHandler);;
                client.GetDisplayHandler  += (sender, e) => e.SetReturnValue(displayHandler);;



                settings = new CfxBrowserSettings();
                settings.WindowlessFrameRate = 60;
                settings.Webgl                       = CfxState.Enabled;
                settings.Plugins                     = CfxState.Enabled;
                settings.ApplicationCache            = CfxState.Enabled;
                settings.CaretBrowsing               = CfxState.Enabled;
                settings.Javascript                  = CfxState.Enabled;
                settings.FileAccessFromFileUrls      = CfxState.Enabled;
                settings.UniversalAccessFromFileUrls = CfxState.Enabled;
                settings.WebSecUrity                 = CfxState.Disabled;

                visitor        = new CfxStringVisitor();
                visitor.Visit += visitor_Visit;

                // set path to js
                string lpPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "livepage");


                LIVEPAGE_LOAD_FUNC =
                    File.ReadAllText(Path.Combine(lpPath, "load.js")) +
                    File.ReadAllText(Path.Combine(lpPath, "live_resource.js")) +
                    File.ReadAllText(Path.Combine(lpPath, "livepage.js"));

                LIVEPAGE_UNLOAD_FUNC = File.ReadAllText(Path.Combine(lpPath, "unload.js"));

                mouseEvent = new CfxMouseEvent();
                keyCode    = new List <int>();

                createBrowser = true;
                invalidate    = true;
                init          = true;
            }

            if (FTransparentIn.IsChanged)
            {
                createBrowser = true;
            }

            if (createBrowser)
            {
                var windowInfo = new CfxWindowInfo();
                windowInfo.SetAsWindowless(FTransparentIn[0]);
                //windowInfo.WindowlessRenderingEnabled = true;
                //windowInfo.TransparentPaintingEnabled = false;

                if (browser != null)
                {
                    browser.Host.CloseBrowser(true);
                    browser = null;
                }

                CfxBrowserHost.CreateBrowser(windowInfo, client, "", settings, null);

                createBrowser = false;
            }

            if (FMethodIn.IsChanged)
            {
                if (method == null || method.Length != FMethodIn.SliceCount)
                {
                    method = new bool[FMethodIn.SliceCount];
                }
                FResultOut.SliceCount = FMethodIn.SliceCount;
                FMethodOut.SliceCount = FMethodIn.SliceCount;
            }

            if (FLivePageIn.IsChanged)
            {
                ExecuteJavascript(FLivePageIn[0] ? LIVEPAGE_LOAD_FUNC : LIVEPAGE_UNLOAD_FUNC);
            }

            if (FZoomLevelIn.IsChanged)
            {
                zoomLevel = VMath.Map(FZoomLevelIn[0], 0, 1, 0, 10, TMapMode.Clamp);
            }

            for (int i = 0; i < FMethodOut.SliceCount; i++)
            {
                FMethodOut[i] = method[i];
                method[i]     = false;
            }

            if (browser != null)
            {
                if (FShowDevToolsIn.IsChanged && FShowDevToolsIn[0])
                {
                    CfxWindowInfo windowInfo = new CfxWindowInfo();

                    windowInfo.Style        = WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE;
                    windowInfo.ParentWindow = IntPtr.Zero;
                    windowInfo.WindowName   = "DevTools";
                    windowInfo.X            = 200;
                    windowInfo.Y            = 200;
                    windowInfo.Width        = 800;
                    windowInfo.Height       = 600;

                    browser.Host.ShowDevTools(windowInfo, new CfxClient(), new CfxBrowserSettings(), null);
                }


                // mouse
                if (FTouchIn.IsChanged && FTouchIn.SliceCount > 0)
                {
                    mouseEvent.X = (int)VMath.Map(FTouchIn[0].x, -1, 1, 0, width, TMapMode.Float);
                    mouseEvent.Y = (int)VMath.Map(FTouchIn[0].y, 1, -1, 0, height, TMapMode.Float);

                    if (!isTouch)
                    {
                        browser.Host.SendMouseClickEvent(mouseEvent, CfxMouseButtonType.Left, false, 1);
                    }
                    else
                    {
                        browser.Host.SendMouseMoveEvent(mouseEvent, false);
                    }
                    isTouch = true;
                }
                if (isTouch && FTouchIn.SliceCount == 0)
                {
                    browser.Host.SendMouseClickEvent(mouseEvent, CfxMouseButtonType.Left, true, 1);
                    isTouch = false;
                }



                // keyboard
                for (int i = 0; i < keyCode.Count; i++)
                {
                    if (!FKeyCodeIn.Contains(keyCode[i]))
                    {
                        CfxKeyEvent keyEvent = new CfxKeyEvent();

                        keyEvent.Type           = CfxKeyEventType.Keyup;
                        keyEvent.WindowsKeyCode = keyCode[i];
                        keyEvent.NativeKeyCode  = keyCode[i];

                        browser.Host.SendKeyEvent(keyEvent);

                        keyCode.RemoveAt(i);
                        i--;
                    }
                }

                if (FKeyCharIn.SliceCount > 0 && FKeyCodeIn.SliceCount > 0)
                {
                    int count = Math.Max(FKeyCharIn.SliceCount, FKeyCodeIn.SliceCount);
                    for (int i = 0; i < count; i++)
                    {
                        int code = FKeyCodeIn[i];
                        if (code >= 0 && FKeyEventTypeIn[i] != KeyNotificationKind.KeyUp && !keyCode.Contains(code))
                        {
                            CfxKeyEvent keyEvent = new CfxKeyEvent();

                            keyEvent.Type           = CfxKeyEventType.Keydown;
                            keyEvent.WindowsKeyCode = code;
                            keyEvent.NativeKeyCode  = code;

                            browser.Host.SendKeyEvent(keyEvent);
                        }

                        short ch = (short)(FKeyCharIn[i].Length > 0 ? FKeyCharIn[i][0] : 0);
                        if (ch > 0)
                        {
                            CfxKeyEvent keyEvent = new CfxKeyEvent();

                            keyEvent.Type                = CfxKeyEventType.Char;
                            keyEvent.Character           = ch;
                            keyEvent.UnmodifiedCharacter = ch;
                            keyEvent.WindowsKeyCode      = ch;
                            keyEvent.NativeKeyCode       = ch;

                            browser.Host.SendKeyEvent(keyEvent);
                        }
                    }
                }


                if (FReloadIn[0])
                {
                    browser.ReloadIgnoreCache();
                }

                if (zoomLevel != browser.Host.ZoomLevel)
                {
                    browser.Host.ZoomLevel = zoomLevel;
                }

                if (FUpdateDomIn[0])
                {
                    browser.MainFrame.GetSource(visitor);
                }

                if (isDocumentReady)
                {
                    if (FBindIn.IsChanged && FBindIn[0] && FMethodIn.SliceCount > 0)
                    {
                        BindFunctions(FObjectIn[0], FMethodIn.ToArray());
                    }

                    if (FScrollToIn.IsChanged)
                    {
                        scroll = FScrollToIn[0];

                        ExecuteJavascript(
                            string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                          @"window.scrollTo({0} *  document.body.scrollWidth, {1} * document.body.scrollHeight);",
                                          scroll.x,
                                          scroll.y
                                          )
                            );
                    }
                }

                if (FExecuteIn[0])
                {
                    ExecuteJavascript(FJavaScriptIn[0]);
                }

                if (FEvaluateJavaScriptIn[0])
                {
                    EvaluateJavascript(FJavaScriptIn[0], (value, exception) =>
                    {
                        FResultJSOut[0] = CfrV8ValueToString(value);
                    });
                }
            }


            if (FWidthIn.IsChanged || FHeightIn.IsChanged)
            {
                if (FWidthIn.SliceCount > 0 && FHeightIn.SliceCount > 0 && FWidthIn[0] > 0 && FHeightIn[0] > 0)
                {
                    lock (bLock)
                    {
                        width  = FWidthIn[0];
                        height = FHeightIn[0];

                        image        = new byte[width * height * 4];
                        isImageReady = false;
                    }

                    if (browser != null)
                    {
                        browser.Host.WasResized();
                    }

                    invalidate = true;
                }
            }

            FIsLoadingOut[0] = !isDocumentReady;

            this.Mouse    = FMouseIn[0];
            this.Keyboard = FKeyboardIn[0];

            //CfxRuntime.DoMessageLoopWork();
        }
        private void MyCtor(Control parent)
        {
            _mono       = Type.GetType("Mono.Runtime") != null;
            this.Parent = parent;

            //SetStyle(

            //    ControlStyles.ResizeRedraw
            //    | ControlStyles.FixedWidth
            //    | ControlStyles.FixedHeight
            //    | ControlStyles.StandardClick
            //    | ControlStyles.StandardDoubleClick
            //    | ControlStyles.UserMouse
            //    | ControlStyles.SupportsTransparentBackColor

            //    | ControlStyles.DoubleBuffer
            //    | ControlStyles.OptimizedDoubleBuffer

            //    | ControlStyles.Opaque
            //    , false);

            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            Console.WriteLine("can enable ime:" + this.CanEnableIme);

            this.ImeMode = ImeMode.On;


            client = new BrowserClient(this);
            //client.GetLifeSpanHandler += (sender, e) => e.SetReturnValue(lifeSpanHandler);
            //client.GetRenderHandler += (sender, e) => e.SetReturnValue(renderHandler);
            //client.GetLoadHandler += (sender, e) => e.SetReturnValue(loadHandler);
            //client.GetKeyboardHandler += (sender, e) => e.SetReturnValue(keyboardHandler);

            //lifeSpanHandler = new CfxLifeSpanHandler();
            //lifeSpanHandler.OnAfterCreated += lifeSpanHandler_OnAfterCreated;

            renderHandler = client.RenderHandler;// new CfxRenderHandler();

            renderHandler.GetRootScreenRect += renderHandler_GetRootScreenRect;
            renderHandler.GetScreenInfo     += renderHandler_GetScreenInfo;
            renderHandler.GetScreenPoint    += renderHandler_GetScreenPoint;
            renderHandler.GetViewRect       += renderHandler_GetViewRect;
            renderHandler.OnCursorChange    += renderHandler_OnCursorChange;
            renderHandler.OnPaint           += renderHandler_OnPaint;

            //renderHandler.OnPopupShow += renderHandler_OnPopupShow;
            //renderHandler.OnPopupSize += renderHandler_OnPopupSize;
            //renderHandler.OnScrollOffsetChanged += renderHandler_OnScrollOffsetChanged;
            //renderHandler.StartDragging += renderHandler_StartDragging;
            //renderHandler.UpdateDragCursor += renderHandler_UpdateDragCursor;

            loadHandler = client.LoadHandler;// new CfxLoadHandler();

            loadHandler.OnLoadError += loadHandler_OnLoadError;


            keyboardHandler = new CfxKeyboardHandler();


            keyboardHandler.OnPreKeyEvent += KeyboardHandler_OnPreKeyEvent;

            lifeSpanHandler = client.lifeSpanHandler;
            lifeSpanHandler.OnAfterCreated += lifeSpanHandler_OnAfterCreated;



            var settings = new CfxBrowserSettings();

            var windowInfo = new CfxWindowInfo();



            if (CfxRuntime.PlatformOS == CfxPlatformOS.Windows)
            {
                windowInfo.SetAsWindowless(this.Parent.Handle);
            }
            else
            {
                windowInfo.SetAsWindowless(this.Parent.Handle);
            }

            //windowInfo.SetAsWindowless(this.Parent.Handle);

            // Create handle now for InvokeRequired to work properly
            // CreateHandle();

            if (string.IsNullOrEmpty(initialUrl))
            {
                initialUrl = "about:version";
            }


            GlobalObject = new JSObject();
            GlobalObject.SetBrowser("window", this);



            // CreateHandle();
            //  CfxBrowserHost.CreateBrowser(windowInfo, client, "about:blank", settings, null);

            //Browser = CfxBrowserHost.CreateBrowserSync(windowInfo, client, initialUrl, settings, null);

            //if (!CfxBrowserHost.CreateBrowser(windowInfo, client, initialUrl, settings, null))
            //    throw new ChromiumWebBrowserException("Failed to create browser instance.");

            CfxBrowserHost.CreateBrowser(windowInfo, client, initialUrl, settings, null);
        }
예제 #11
0
        private void MyCtor(Control parent)
        {
            _mono       = Type.GetType("Mono.Runtime") != null;
            this.Parent = parent;
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            Console.WriteLine("can enable ime:" + this.CanEnableIme);

            this.ImeMode = ImeMode.On;

            lifeSpanHandler = new CfxLifeSpanHandler();
            lifeSpanHandler.OnAfterCreated += lifeSpanHandler_OnAfterCreated;

            renderHandler = new CfxRenderHandler();

            renderHandler.GetRootScreenRect += renderHandler_GetRootScreenRect;
            renderHandler.GetScreenInfo     += renderHandler_GetScreenInfo;
            renderHandler.GetScreenPoint    += renderHandler_GetScreenPoint;
            renderHandler.GetViewRect       += renderHandler_GetViewRect;
            renderHandler.OnCursorChange    += renderHandler_OnCursorChange;
            renderHandler.OnPaint           += renderHandler_OnPaint;

            //renderHandler.OnPopupShow += renderHandler_OnPopupShow;
            //renderHandler.OnPopupSize += renderHandler_OnPopupSize;
            //renderHandler.OnScrollOffsetChanged += renderHandler_OnScrollOffsetChanged;
            //renderHandler.StartDragging += renderHandler_StartDragging;
            //renderHandler.UpdateDragCursor += renderHandler_UpdateDragCursor;

            loadHandler = new CfxLoadHandler();

            loadHandler.OnLoadError += loadHandler_OnLoadError;


            keyboardHandler = new CfxKeyboardHandler();


            keyboardHandler.OnPreKeyEvent += KeyboardHandler_OnPreKeyEvent;

            client = new CfxClient();
            client.GetLifeSpanHandler += (sender, e) => e.SetReturnValue(lifeSpanHandler);
            client.GetRenderHandler   += (sender, e) => e.SetReturnValue(renderHandler);
            client.GetLoadHandler     += (sender, e) => e.SetReturnValue(loadHandler);
            client.GetKeyboardHandler += (sender, e) => e.SetReturnValue(keyboardHandler);


            var settings = new CfxBrowserSettings();

            var windowInfo = new CfxWindowInfo();

            windowInfo.SetAsWindowless(this.Parent.Handle);
            //windowInfo.SetAsWindowless(this.Parent.Handle);

            // Create handle now for InvokeRequired to work properly
            // CreateHandle();

            if (string.IsNullOrEmpty(initialUrl))
            {
                initialUrl = "about:version";
            }

            CfxBrowserHost.CreateBrowser(windowInfo, client, initialUrl, settings, null);
        }
예제 #12
0
        public BrowserControl(Control parent)
        {
            _mono       = Type.GetType("Mono.Runtime") != null;
            this.Parent = parent;
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            Console.WriteLine("can enable ime:" + this.CanEnableIme);

            this.ImeMode = ImeMode.On;

            lifeSpanHandler = new CfxLifeSpanHandler();
            lifeSpanHandler.OnAfterCreated += lifeSpanHandler_OnAfterCreated;

            renderHandler = new CfxRenderHandler();

            renderHandler.GetRootScreenRect += renderHandler_GetRootScreenRect;
            renderHandler.GetScreenInfo     += renderHandler_GetScreenInfo;
            renderHandler.GetScreenPoint    += renderHandler_GetScreenPoint;
            renderHandler.GetViewRect       += renderHandler_GetViewRect;
            renderHandler.OnCursorChange    += renderHandler_OnCursorChange;
            renderHandler.OnPaint           += renderHandler_OnPaint;

            //renderHandler.OnPopupShow += renderHandler_OnPopupShow;
            //renderHandler.OnPopupSize += renderHandler_OnPopupSize;
            //renderHandler.OnScrollOffsetChanged += renderHandler_OnScrollOffsetChanged;
            //renderHandler.StartDragging += renderHandler_StartDragging;
            //renderHandler.UpdateDragCursor += renderHandler_UpdateDragCursor;

            loadHandler = new CfxLoadHandler();

            loadHandler.OnLoadError += loadHandler_OnLoadError;


            keyboardHandler = new CfxKeyboardHandler();


            keyboardHandler.OnPreKeyEvent += KeyboardHandler_OnPreKeyEvent;

            client = new CfxClient();
            client.GetLifeSpanHandler += (sender, e) => e.SetReturnValue(lifeSpanHandler);
            client.GetRenderHandler   += (sender, e) => e.SetReturnValue(renderHandler);
            client.GetLoadHandler     += (sender, e) => e.SetReturnValue(loadHandler);
            client.GetKeyboardHandler += (sender, e) => e.SetReturnValue(keyboardHandler);

            var settings = new CfxBrowserSettings();

            var windowInfo = new CfxWindowInfo();

            windowInfo.SetAsWindowless(this.Handle);
            //windowInfo.SetAsWindowless(this.Parent.Handle);

            // Create handle now for InvokeRequired to work properly
            // CreateHandle();
            //  CfxBrowserHost.CreateBrowser(windowInfo, client, "about:blank", settings, null);

            //browser = CfxBrowserHost.CreateBrowserSync(windowInfo, client, "about:blank", settings, null);

            if (!CfxBrowserHost.CreateBrowser(windowInfo, client, "about:blank", settings, null))
            {
                throw new ChromiumWebBrowserException("Failed to create browser instance.");
            }
        }
예제 #13
0
        public void Initialize()
        {
            Settings = new CfxBrowserSettings()
            {
                WindowlessFrameRate = InitSettings.Fps,
                Webgl                       = CfxState.Enabled,
                Plugins                     = CfxState.Enabled,
                ApplicationCache            = CfxState.Enabled,
                Javascript                  = CfxState.Enabled,
                FileAccessFromFileUrls      = CfxState.Enabled,
                UniversalAccessFromFileUrls = CfxState.Enabled,
                WebSecurity                 = CfxState.Disabled
            };
            Globals.UpdateScripts();

            TextureSize = (DefaultWidth, DefaultHeight);

            LifeSpanHandler = new CfxLifeSpanHandler();
            LifeSpanHandler.OnAfterCreated += (sender, e) =>
            {
                Browser   = e.Browser;
                BrowserId = e.Browser.Identifier;
                Instances.UpdateGeneric(BrowserId, this);
                Browser.Host.WasResized();

                _browserReadyFrame = true;
                //_invalidate = true;
            };
            LifeSpanHandler.OnBeforePopup += (sender, e) =>
            {
                if (BrowserSettings.AllowPopups)
                {
                    Browser.MainFrame.LoadUrl(e.TargetUrl);
                    e.SetReturnValue(true);
                }
                else
                {
                    e.SetReturnValue(true);
                }
            };

            RenderHandler              = new CfxRenderHandler();
            RenderHandler.GetViewRect += (sender, e) =>
            {
                e.Rect.X      = 0;
                e.Rect.Y      = 0;
                e.Rect.Width  = TextureSize.w;
                e.Rect.Height = TextureSize.h;
                e.SetReturnValue(true);
            };
            RenderHandler.GetRootScreenRect += (sender, e) =>
            {
                e.Rect.X      = 0;
                e.Rect.Y      = 0;
                e.Rect.Width  = TextureSize.w;
                e.Rect.Height = TextureSize.h;
                e.SetReturnValue(true);
            };
            //RenderHandler.OnPaint += (sender, args) => _paintFrame = true;
            RenderHandler.OnAcceleratedPaint += HandleAcceleratedRenderPaint;

            LoadHandler              = new CfxLoadHandler();
            LoadHandler.OnLoadStart += (sender, e) =>
            {
                if (e.Browser.MainFrame.Url != _prevUrl)
                {
                    IsDocumentReady = false;
                }
                _prevUrl = e.Browser.MainFrame.Url;
            };
            LoadHandler.OnLoadError += (sender, e) =>
            {
                LogError(e.ErrorCode.ToString() + Environment.NewLine + "    " + e.ErrorText + Environment.NewLine + "    " + e.FailedUrl);
                LastError = e.ErrorText;
            };
            LoadHandler.OnLoadingStateChange += (sender, e) => CurrentUrl = Browser.MainFrame.Url;

            RequestHandler = new CfxRequestHandler();
            RequestHandler.CanGetCookies             += (sender, args) => { args.SetReturnValue(BrowserSettings.AllowGetCookies); };
            RequestHandler.CanSetCookie              += (sender, args) => { args.SetReturnValue(BrowserSettings.AllowSetCookies); };
            RequestHandler.OnBeforeBrowse            += HandleOnBeforeBrowse;
            RequestHandler.OnBeforeResourceLoad      += HandleBeforeResourceLoad;
            RequestHandler.OnCertificateError        += (sender, e) => LogError("Cert error: " + e.CertError.ToString());
            RequestHandler.OnPluginCrashed           += (sender, e) => LogError("Plugin Crashed: " + e.PluginPath);
            RequestHandler.OnRenderProcessTerminated += (sender, e) => LogError("Render Process Terminated: " + e.Status.ToString());

            ContextMenuHandler = new CfxContextMenuHandler();
            ContextMenuHandler.OnBeforeContextMenu += (sender, args) => args.Model.Clear();
            DisplayHandler = new CfxDisplayHandler();
            DisplayHandler.OnConsoleMessage        += HandleConsoleMessage;
            DisplayHandler.OnLoadingProgressChange += (sender, args) => Progress = args.Progress;

            Client = new CfxClient();
            Client.GetLifeSpanHandler    += (sender, e) => e.SetReturnValue(LifeSpanHandler);
            Client.GetRenderHandler      += (sender, e) => e.SetReturnValue(RenderHandler);
            Client.GetLoadHandler        += (sender, e) => e.SetReturnValue(LoadHandler);
            Client.GetRequestHandler     += (sender, e) => e.SetReturnValue(RequestHandler);
            Client.GetDisplayHandler     += (sender, e) => e.SetReturnValue(DisplayHandler);
            Client.GetContextMenuHandler += (sender, args) => args.SetReturnValue(ContextMenuHandler);
            Visitor        = new CfxStringVisitor();
            Visitor.Visit += (sender, e) =>
            {
                RootElement = HtmlToXElement(e.String);
                Dom         = new XDocument(RootElement);
            };

            CreateBrowser();
            //_invalidate = true;
        }