Esempio n. 1
0
        public void NewTab(string url)
        {
            var state = new WebBrowserState();

            var tabPage = new TabPage(url);

            var navBox = new WebNavigationBox();
            navBox.Parent = tabPage;
            navBox.Dock = DockStyle.Top;
            navBox.Visible = true;
            navBox.HomeUrl = _application.HomeUrl;

            var browserCtl = new CefWebBrowser();
            browserCtl.Parent = tabPage;
            browserCtl.Dock = DockStyle.Fill;
            browserCtl.BringToFront();

            var browser = browserCtl.WebBrowser;
            browser.StartUrl = url;

            navBox.Attach(browser);

            browser.TitleChanged += (s, e) =>
                {
                    state.Title = e.Title;
                    _pUIThread.Post((_state) => { UpdateTitle(e.Title); }, null);
                };

            browser.AddressChanged += (s, e) =>
                {
                    state.Title = e.Address;
                    _pUIThread.Post((_state) => { navBox.Address = e.Address; }, null);
                };

            browser.TargetUrlChanged += (s, e) =>
                {
                    state.TargetUrl = e.TargetUrl;
                    // TODO: show targeturl in status bar
                    // _pUIThread.Post((_state) => { UpdateTargetUrl(e.TargetUrl); }, null);
                };

            browser.LoadingStateChanged += (s, e) =>
                {
                    _pUIThread.Post((_state) =>
                        {
                            navBox.CanGoBack = e.CanGoBack;
                            navBox.CanGoForward = e.CanGoForward;
                            navBox.Loading = e.Loading;
                        }, null);
                };

            _tabs.TabPages.Add(tabPage);
            _tabs.SelectedTab = tabPage;
        }