示例#1
0
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            if (this.DesignMode)
            {
                if (!this.handleCreatedHandled)
                {
                    this.Paint += new PaintEventHandler(this.DesignModePaint);
                }
            }
            else
            {
                if (this.handleCreatedHandled)
                {
                    throw new InvalidOperationException("Handle already created.");
                }

                // TODO: fix when browser still creating, but control already disposed
                // it can be done via setting client to detached state, and onaftercreated
                // force browser to be closed.

                var windowInfo = new CefWindowInfo();
                windowInfo.SetAsChild(this.Handle, 0, 0, this.Width, this.Height);

                this.core.Create(windowInfo);

                windowInfo.Dispose();
            }

            this.handleCreatedHandled = true;
        }
        protected override void OnRealized()
        {
            base.OnRealized();

            Console.WriteLine("OnRealized2");

            this.core          = new CefWebBrowserCore(this, new CefBrowserSettings(), "http://google.com");
            this.core.Created += HandleCoreCreated;
            this.ChildVisible  = true;

            var windowInfo = new CefWindowInfo();

#if WINDOWS
#error WINDOWS is not supported currently.
            // TODO: Win32
            // windowInfo.SetAsChild(
            //    gdk_win32_drawable_get_handle(this.GdkWindow.Handle), this.x, this.y, this.width, this.height
            //    );
#elif LINUX
            windowInfo.SetAsChild(
                this.Raw
                );
#else
#error OS not supported.
#endif

            this.core.Create(windowInfo);
            windowInfo.Dispose();
        }
        public IDisposable GetDeveloperToolsControl(CefPoint element, CefWindowInfo info = null, CefBrowserSettings settings = null)
        {
            if (_browser != null)
            {
                var ctl = new DevToolsWebBrowser();

                ctl.Disposed += (sender, args) =>
                {
                    if (_browser != null)
                    {
                        _browser.GetHost().CloseDevTools();
                    }
                };

                ctl.CreateControl();

                if (info == null)
                {
                    info        = CefWindowInfo.Create();
                    info.Width  = (int)ActualWidth;
                    info.Height = (int)ActualHeight;
                }
                if (ctl.ParentHandle != IntPtr.Zero)
                {
                    info.SetAsChild(ctl.ParentHandle, new CefRectangle(0, 0, info.Width, info.Height));
                }

                if (settings == null)
                {
                    settings = new CefBrowserSettings();
                }

                if (element.X > int.MinValue && element.Y > int.MinValue)
                {
                    _browser.GetHost().ShowDevTools(info, ctl.Client, settings, element);
                }
                else
                {
                    var defaultCefPoint = new CefPoint(0, 0);
                    _browser.GetHost().ShowDevTools(info, ctl.Client, settings, defaultCefPoint);
                }

                return(ctl);
            }

            return(null);
        }
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            if (DesignMode)
            {
                // if (!_handleCreated) Paint += PaintInDesignMode;
            }
            else
            {
                _windowInfo = CefWindowInfo.Create();
                _windowInfo.SetAsChild(Handle, new CefRectangle {
                    X = 0, Y = 0, Width = _initialWidth, Height = _initialHeight
                });
                WebAppLogger.Log(WebAppLogLevel.Info, $"WindowInfo: ({_initialWidth},{_initialHeight})");
                _core.Create(_windowInfo);
            }

            _handleCreated = true;
        }
        private void CreateBrowser()
        {
            CefWindowInfo windowInfo = CefWindowInfo.Create();

            windowInfo.SetAsChild(Handle, new CefRectangle {
                X = 0, Y = 0, Width = Width, Height = Height
            });
            if (client == null)
            {
                client = new ClientBrowser(this);
            }
            var settings = new CefBrowserSettings()
            {
            };

            settings.AcceleratedCompositing = CefState.Enabled;
            settings.ApplicationCache       = CefState.Enabled;
            settings.AuthorAndUserStyles    = CefState.Enabled;
            settings.CaretBrowsing          = CefState.Enabled;
            settings.Databases = CefState.Enabled;
            settings.FileAccessFromFileUrls     = CefState.Enabled;
            settings.ImageLoading               = CefState.Enabled;
            settings.ImageShrinkStandaloneToFit = CefState.Enabled;
            settings.Java       = CefState.Enabled;
            settings.JavaScript = CefState.Enabled;;
            settings.JavaScriptAccessClipboard = CefState.Enabled;
            settings.JavaScriptCloseWindows    = CefState.Enabled;
            settings.JavaScriptDomPaste        = CefState.Enabled;;
            settings.JavaScriptOpenWindows     = CefState.Enabled;
            settings.LocalStorage   = CefState.Enabled;;
            settings.Plugins        = CefState.Enabled;;
            settings.RemoteFonts    = CefState.Enabled;
            settings.TabToLinks     = CefState.Enabled;;
            settings.TextAreaResize = CefState.Enabled;
            settings.UniversalAccessFromFileUrls = CefState.Enabled;
            settings.WebGL       = CefState.Enabled;
            settings.WebSecurity = CefState.Enabled;

            CefBrowserHost.CreateBrowser(windowInfo, client, settings, browserSettings.DefaultUrl);
        }
示例#6
0
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            if (this.DesignMode)
            {
                if (!this.handleCreatedHandled)
                {
                    this.Paint += new PaintEventHandler(this.DesignModePaint);
                }
            }
            else
            {
                if (this.handleCreatedHandled)
                {
                    throw new InvalidOperationException("Handle already created.");
                }

                // TODO: fix when browser still creating, but control already disposed
                // it can be done via setting client to detached state, and onaftercreated
                // force browser to be closed.

                var windowInfo = new CefWindowInfo();
            #if WINDOWS
                windowInfo.SetAsChild(this.Handle, 0, 0, this.Width, this.Height);
            #else
            #error Only windows supported.
            #endif
                this.core.Create(windowInfo);

                windowInfo.Dispose();
            }

            this.handleCreatedHandled = true;
        }