Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinForms - Add LifeSpanHandler implementation capable of hosting popups as Tabs/Controls #3529

Merged
merged 9 commits into from
Jun 4, 2021

Conversation

amaitland
Copy link
Member

@amaitland amaitland commented Apr 29, 2021

Summary:
Opening popups as Tabs is a fairly common scenario and requires extra plumbing currently.
This adds a LifeSpanHandler capable of hosting popups as Tabs/Sub Controls.

Changes:

  • Update Example
  • Remove PopupAsChildHelper and example LifeSpanHandler
  • Examples always opens popups as tabs now.
  • Added CefSharp.WinForms.Handler.LifeSpanHandler
  • Added ShowDevToolsDocked to simplify docking DevTools

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Updated documentation

Checklist:

  • Tested the code(if applicable)
  • Commented my code
  • Changed the documentation(if applicable)
  • New files have a license disclaimer
  • The formatting is consistent with the project (project supports .editorconfig)

@amaitland
Copy link
Member Author

amaitland commented Apr 29, 2021

Example of the new API:

browser.LifeSpanHandler = CefSharp.WinForms.Handler.LifeSpanHandler
	.Create()
	.OnPopupCreated((ctrl, targetUrl) =>
	{
		//Add popup to new parent control e.g. Tab
		parent.Controls.Add(ctrl);
	})
	.OnPopupDestroyed((ctrl, popupBrowser) =>
	{
		//If browser is disposed or the handle has been released then we don't
		//need to remove the tab (likely removed from menu)
		if (!ctrl.IsDisposed && ctrl.IsHandleCreated)
		{
			parent.Controls.Remove(ctrl);
		}
	}).Build(); 

@amaitland amaitland added this to the 91.1.x milestone Apr 29, 2021
@AppVeyorBot
Copy link

Copy link
Member Author

@amaitland amaitland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor tweaks required.

CefSharp.WinForms/CefSharp.WinForms.csproj Outdated Show resolved Hide resolved
CefSharp.WinForms/Handler/LifeSpanHandler.cs Show resolved Hide resolved
CefSharp.WinForms/Internals/ChromiumHostControl.cs Outdated Show resolved Hide resolved
CefSharp.WinForms/Handler/LifeSpanHandler.cs Outdated Show resolved Hide resolved
CefSharp.WinForms/Handler/LifeSpanHandler.cs Outdated Show resolved Hide resolved
CefSharp.WinForms/WebBrowserExtensions.cs Outdated Show resolved Hide resolved
@AppVeyorBot
Copy link

@amaitland amaitland force-pushed the winforms/popuplifespanhandler branch from 6986557 to 4a331bc Compare April 30, 2021 01:40
@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@amaitland
Copy link
Member Author

Consider switching from Action to strongly typed delegates. Change the fluent method names.

@amaitland amaitland marked this pull request as ready for review June 4, 2021 04:07
amaitland and others added 9 commits June 4, 2021 14:40
…ps as Tabs/Child controls in WinForms

- Update Example
- Remove PopupAsChildHelper and example LifeSpanHandler
- Examples always opens popups as tabs now.
Co-authored-by: campersau <buchholz.bastian@googlemail.com>
Co-authored-by: campersau <buchholz.bastian@googlemail.com>
- Rename OnPopupCreated to RegisterPopupCreated
- Rename OnPopupDestroyed to RegisterPopupDestroyed
- Improve xml doc and comments
- Make ParentFormMessageInterceptor public
- Make ChromiumHostControl public, move into CefSharp.WinForms.Host namespace
  Rather than having the class in the CefSharp.WinForms namespace and potentially
  confuse users, move into it's own namespace.
- Code cleanup
- Improve comments
@amaitland amaitland force-pushed the winforms/popuplifespanhandler branch from 676386e to e82331f Compare June 4, 2021 04:47
@amaitland amaitland merged commit 3dc37b2 into cefsharp:master Jun 4, 2021
amaitland added a commit that referenced this pull request Jun 4, 2021
…ps as Tabs/Controls (#3529)

* WinForms - Add LifeSpanHandler implementation capable of hosting popups  as Tabs/Child controls in WinForms

- Update Example
- Remove PopupAsChildHelper and example LifeSpanHandler
- Examples always opens popups as tabs now.
- Improve xml doc and comments
- Make ParentFormMessageInterceptor public
- Make ChromiumHostControl public, move into CefSharp.WinForms.Host namespace
  Rather than having the class in the CefSharp.WinForms namespace and potentially
  confuse users, move into it's own namespace.
- Clarify ShowDevToolsDocked needs to be used with the new WinForms lifespan handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants