private void newTabToolStripMenuItem_Click(object sender, EventArgs e) { if (this.DockPanel != null) { WebDocument doc = new WebDocument(); doc.Show(this.DockPanel); } }
internal WebDocument OpenTab(Uri url = null, string title = null) { // - A tab with no url specified, will open WebCore.HomeURL. // - A tab with a predefined title, will not display a toolbar // and address-box. This is used to display fixed web content // such as the Help Contents. WebDocument doc = url == null ? new WebDocument() : String.IsNullOrEmpty(title) ? new WebDocument(url) : new WebDocument(url, title); doc.Show(dockPanel); return(doc); }
private void dockPanel_ActiveDocumentChanged(object sender, EventArgs e) { foreach (WebDocument doc in dockPanel.Documents) { // We pause WebControl rendering for documents // that are currently not visible. doc.IsRendering = (doc == dockPanel.ActiveDocument); } if (dockPanel.ActiveDocument != null) { WebDocument doc = (WebDocument)dockPanel.ActiveDocument; this.Text = String.Format("{0} - {1}", Application.ProductName, doc.Text); doc.Focus(); } else { this.Text = Application.ProductName; } }
// Common handler of all ShowCreatedWebView events. internal static void OnShowNewView(object sender, ShowCreatedWebViewEventArgs e) { IWebView view = sender as IWebView; if (view == null) { return; } if (!view.IsLive) { return; } MainForm mainForm = Application.OpenForms.OfType <MainForm>().FirstOrDefault(); if (mainForm == null) { return; } // Treat popups differently. If IsPopup is true, the event is always // the result of 'window.open' (IsWindowOpen is also true, so no need to check it). // Our application does not recognize user defined, non-standard specs. // Therefore child views opened with non-standard specs, will not be presented as // popups but as regular new windows (still wrapping the child view however -- see below). if (e.IsPopup && !e.IsUserSpecsOnly) { // JSWindowOpenSpecs.InitialPosition indicates screen coordinates. Rectangle screenRect = e.Specs.InitialPosition.ToRectangle(); // Set the created native view as the underlying view of the // WebControl. This will maintain the relationship between // the parent view and the child, usually required when the new view // is the result of 'window.open' (JS can access the parent window through // 'window.opener'; the parent window can manipulate the child through the 'window' // object returned from the 'window.open' call). WebDocument newWindow = new WebDocument(e.NewViewInstance) { ShowInTaskbar = false, ClientSize = screenRect.Size != Size.Empty ? screenRect.Size : new Size(640, 480) }; // If the caller has not indicated a valid size for the new popup window, // let it be opened with the default size specified at design time. if ((screenRect.Width > 0) && (screenRect.Height > 0)) { // Assign the indicated size. newWindow.Width = screenRect.Width; newWindow.Height = screenRect.Height; } // Show the window. newWindow.Show(); // If the caller has not indicated a valid position for the new popup window, // let it be opened in the default position specified at design time. if (screenRect.Location != Point.Empty) { // Move it to the specified coordinates. newWindow.DesktopLocation = screenRect.Location; } } else if (e.IsWindowOpen || e.IsPost) { // No specs or only non-standard specs were specified, but the event is still // the result of 'window.open' or of an HTML form with target="_blank" and method="post". // We will open a normal window but we will still wrap the new native child view, // maintaining its relationship with the parent window. WebDocument doc = new WebDocument(e.NewViewInstance); mainForm.OpenTab(doc); } else { // The event is not the result of 'window.open' or of an HTML form with target="_blank" // and method="post"., therefore it's most probably the result of a link with target='_blank'. // We will not be wrapping the created view; we let the WebControl hosted in ChildWindow // create its own underlying view. Setting Cancel to true tells the core to destroy the // created child view. // // Why don't we always wrap the native view passed to ShowCreatedWebView? // // - In order to maintain the relationship with their parent view, // child views execute and render under the same process (awesomium_process) // as their parent view. If for any reason this child process crashes, // all views related to it will be affected. When maintaining a parent-child // relationship is not important, we prefer taking advantage of the isolated process // architecture of Awesomium and let each view be rendered in a separate process. e.Cancel = true; // Note that we only explicitly navigate to the target URL, when a new view is // about to be created, not when we wrap the created child view. This is because // navigation to the target URL (if any), is already queued on created child views. // We must not interrupt this navigation as we would still be breaking the parent-child // relationship. WebDocument doc = new WebDocument(e.TargetURL); mainForm.OpenTab(doc); } }
internal void OpenTab(WebDocument doc) { doc.Show(dockPanel); }