Skip to content

Commit

Permalink
Remove experimental option #1 from WinForms LifeSpanHandler example -…
Browse files Browse the repository at this point in the history
… should use SetAsChild method instead (I know the example is incomplete, contributions welcome).

newBrowser should only be used in WPF/OffScreen
  • Loading branch information
amaitland committed Apr 18, 2017
1 parent 06da5d2 commit c138ba2
Showing 1 changed file with 10 additions and 56 deletions.
66 changes: 10 additions & 56 deletions CefSharp.WinForms.Example/Handlers/LifeSpanHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,21 @@ public class LifeSpanHandler : ILifeSpanHandler
{
bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
{
//Set newBrowser to null unless your attempting to host the popup in a new instance of ChromiumWebBrowser
// Set newBrowser to null unless your attempting to host the popup in a new instance of ChromiumWebBrowser
// This should only be used in WPF/OffScreen
newBrowser = null;

return false; //Return true to cancel the popup creation

//EXPERIMENTAL OPTION #1: Demonstrates using a new instance of ChromiumWebBrowser to host the popup.
//var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

//ChromiumWebBrowser chromiumBrowser = null;

//var windowX = windowInfo.X;
//var windowY = windowInfo.Y;
//var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width;
//var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height;

//chromiumWebBrowser.Invoke(new Action(() =>
//{
// var owner = chromiumWebBrowser.FindForm();
// chromiumBrowser = new ChromiumWebBrowser(targetUrl)
// {
// LifeSpanHandler = this
// };

// //NOTE: This is important and must be called before the handle is created
// chromiumBrowser.SetAsPopup();

// //Ask nicely for the control to create it's underlying handle as we'll need to
// //pass it to IWindowInfo.SetAsChild
// chromiumBrowser.CreateControl();

// var popup = new Form
// {
// Left = windowX,
// Top = windowY,
// Width = windowWidth,
// Height = windowHeight,
// Text = targetFrameName
// };

// owner.AddOwnedForm(popup);

// popup.Controls.Add(new Label { Text = "CefSharp Custom Popup" });
// popup.Controls.Add(chromiumBrowser);

// popup.Show();

// var rect = chromiumBrowser.ClientRectangle;

// //This is key, need to tell the Browser which handle will it's parent
// //You maybe able to pass in 0 values for left, top, right and bottom though it's safest to provide them
// windowInfo.SetAsChild(chromiumBrowser.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom);
//}));

//newBrowser = chromiumBrowser;

//return false;

//EXPERIMENTAL OPTION #2: Use IWindowInfo.SetAsChild to specify the parent handle
//NOTE: Window resize not yet handled - it should be possible to get the
// Hosting the popup in your own control/window
// Use IWindowInfo.SetAsChild to specify the parent handle
// NOTE: Window resize not yet handled - you need to get the
// IBrowserHost from the newly created IBrowser instance that represents the popup
// Then subscribe to window resize notifications and call NotifyMoveOrResizeStarted
// Then subscribe to window resize notifications and call NotifyMoveOrResizeStarted().
// Also any chances in width/height you need to call SetWindowPos on the browsers HWND
// Use NativeMethodWrapper.SetWindowPosition to achieve this - you can get the HWND using
// IBrowserHost method

//var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

//var windowX = windowInfo.X;
Expand Down

0 comments on commit c138ba2

Please sign in to comment.