Ejemplo n.º 1
0
        protected void InitializeChromium(string initialUrl)
        {
            if (string.IsNullOrEmpty(initialUrl))
            {
                this.browser = new ChromiumBrowser();
            }
            else
            {
                this.browser = new ChromiumBrowser(initialUrl);
            }
            this.browser.Dock = System.Windows.Forms.DockStyle.Fill;
            this.browser.RemoteCallbackInvokeMode = JSInvokeMode.Inherit;
            this.Controls.Add(this.browser);

            BrowserHandle = browser.Handle;

            browser.BrowserCreated += (sender, args) =>
            {
                AttachInterceptorToChromiumBrowser();
            };


            LifeSpanHandler.OnBeforePopup += (sender, args) =>
            {
            };

            DragHandler.OnDraggableRegionsChanged += (sender, args) =>
            {
                var regions = args.Regions;

                if (regions.Length > 0)
                {
                    foreach (var region in regions)
                    {
                        var rect = new Rectangle(region.Bounds.X, region.Bounds.Y, region.Bounds.Width, region.Bounds.Height);

                        if (draggableRegion == null)
                        {
                            draggableRegion = new Region(rect);
                        }
                        else
                        {
                            if (region.Draggable)
                            {
                                draggableRegion.Union(rect);
                            }
                            else
                            {
                                draggableRegion.Exclude(rect);
                            }
                        }
                    }
                }
            };

            DragHandler.OnDragEnter += (s, e) =>
            {
                // 禁止往窗口上拖东西
                e.SetReturnValue(true);
            };

            LoadHandler.OnLoadEnd += (sender, args) =>
            {
                args.Frame.ExecuteJavaScript(JS_WINDOW_SYSTEM_COMMAND_NOTIFY, null, 0);
                HideInitialSplash();
            };

            LoadHandler.OnLoadError += (sender, args) =>
            {
                args.Frame.ExecuteJavaScript(JS_WINDOW_SYSTEM_COMMAND_NOTIFY, null, 0);
                HideInitialSplash();
            };

            GlobalObject.Add("NanUI", new JsHostWindowObject(this));
        }