protected GeckoWebBrowser AddTab() { var tabPage = new TabPage(); tabPage.Text = "blank"; var browser = new GeckoWebBrowser(); browser.Dock = DockStyle.Fill; tabPage.DockPadding.Top = 25; tabPage.Dock = DockStyle.Fill; // add a handler showing how to view the DOM // browser.DocumentCompleted += (s, e) => TestQueryingOfDom(browser); // add a handler showing how to modify the DOM. // browser.DocumentCompleted += (s, e) => TestModifyingDom(browser); AddToolbarAndBrowserToTab(tabPage, browser); m_tabControl.TabPages.Add(tabPage); tabPage.Show(); m_tabControl.SelectedTab = tabPage; // Uncomment this to stop links from navigating. // browser.DomClick += StopLinksNavigating; // Demo use of ReadyStateChange. // For some special page, e.g. about:config browser.Document is null. browser.ReadyStateChange += (s, e) => this.Text = browser.Document != null ? browser.Document.ReadyState : ""; browser.DocumentTitleChanged += (s, e) => tabPage.Text = browser.DocumentTitle; browser.EnableDefaultFullscreen(); // Popup window management. browser.CreateWindow += (s, e) => { // For <a target="_blank"> and window.open() without specs(3rd param), // e.Flags == GeckoWindowFlags.All, and we load it in a new tab; // otherwise, load it in a popup window, which is maximized by default. // This simulates firefox's behavior. if (e.Flags == GeckoWindowFlags.All) { e.WebBrowser = AddTab(); } else { var wa = System.Windows.Forms.Screen.GetWorkingArea(this); e.InitialWidth = wa.Width; e.InitialHeight = wa.Height; } }; return(browser); }
private string startURL = null; // the starting URL the browser was displayed with.. #region MassiveConstructor /// <summary> /// Initializes a new instance of the <see cref="FormWebBrowserGecko"/> class. /// </summary> /// <param name="URL">The URL to show in the Gecko-based web browser control as string.</param> /// <param name="homeButton">An indicator whether to show the home button on the browser bar.</param> public FormWebBrowserGecko(string URL, bool homeButton = true) { InitializeComponent(); DBLangEngine.DBName = "lang.sqlite"; // Do the VPKSoft.LangLib == translation if (VPKSoft.LangLib.Utils.ShouldLocalize() != null) { DBLangEngine.InitalizeLanguage("vamp.Messages", VPKSoft.LangLib.Utils.ShouldLocalize(), false); return; // After localization don't do anything more. } DBLangEngine.InitalizeLanguage("vamp.Messages"); Controls.Add(browser); // add the Gecko Web Browser to the form's controls browser.Navigate(URL); startURL = URL; browser.Navigated += Browser_Navigated; // subscribe to an event to a browser URL changed.. browser.NavigationError += Browser_NavigationError; // subscribe to an event to a browser "error".. browser.CanGoBackChanged += Browser_CanGoBackwardFormardChanged; // the state if navigation backwards has changed.. browser.CanGoForwardChanged += Browser_CanGoBackwardFormardChanged; // the state if navigation forwards has changed.. m_GlobalHook = Hook.GlobalEvents(); // The Gecko Web Browser prevents the Form from getting mouse signals, so we add this (Gma.System.MouseKeyHook) event handler.. // (C): https://github.com/gmamaladze/globalmousekeyhook, MIT license m_GlobalHook.MouseMove += M_GlobalHook_MouseMove; // Add a global MouseMove event.. m_GlobalHook.MouseDown += M_GlobalHook_MouseDown; // Add a global MouseDown event.. m_GlobalHook.KeyDown += GlobalKeyDown; // Add a global KeyDown event.. lbToolTip.Text = string.Empty; // No too-tip as there is nothing to show at this time.. if (!homeButton) // if home button is disabled.. { // ..set the indices accordingly.. btnCloseBrowser.Tag = 3; btnBrowserHome.Tag = -1; } SetButtonImages(); // Set the control buttons states to match the browser's state.. browser.EnableDefaultFullscreen(); }
protected GeckoWebBrowser AddTab() { var tabPage = new TabPage(); tabPage.Text = "blank"; var browser = new GeckoWebBrowser(); browser.Dock = DockStyle.Fill; tabPage.DockPadding.Top = 25; tabPage.Dock = DockStyle.Fill; // add a handler showing how to view the DOM // browser.DocumentCompleted += (s, e) => TestQueryingOfDom(browser); // add a handler showing how to modify the DOM. // browser.DocumentCompleted += (s, e) => TestModifyingDom(browser); // add a handle to detect when user modifies a contentEditable part of the document. browser.DomInput += (sender, args) => MessageBox.Show(String.Format("User modified element {0}", (args.Target.CastToGeckoElement() as GeckoHtmlElement).OuterHtml)); AddToolbarAndBrowserToTab(tabPage, browser); m_tabControl.TabPages.Add(tabPage); tabPage.Show(); m_tabControl.SelectedTab = tabPage; // Uncomment this to stop links from navigating. // browser.DomClick += StopLinksNavigating; // Demo use of ReadyStateChange. // For some special page, e.g. about:config browser.Document is null. browser.ReadyStateChange += (s, e) => this.Text = browser.Document != null ? browser.Document.ReadyState : ""; browser.DocumentTitleChanged += (s, e) => tabPage.Text = browser.DocumentTitle; browser.EnableDefaultFullscreen(); // Popup window management. browser.CreateWindow += (s, e) => { // A naive popup blocker, demonstrating popup cancelling. Console.WriteLine("A popup is trying to show: " + e.Uri); if (e.Uri.StartsWith("http://annoying-site.com")) { e.Cancel = true; Console.WriteLine("A popup is blocked: " + e.Uri); return; } // For <a target="_blank"> and window.open() without specs(3rd param), // e.Flags == GeckoWindowFlags.All, and we load it in a new tab; // otherwise, load it in a popup window, which is maximized by default. // This simulates firefox's behavior. if (e.Flags == GeckoWindowFlags.All) { e.WebBrowser = AddTab(); } else { var wa = System.Windows.Forms.Screen.GetWorkingArea(this); e.InitialWidth = wa.Width; e.InitialHeight = wa.Height; } }; return(browser); }