Skip to content

Commit 8f89271

Browse files
committed
Rename CreateOffscreenBrowserWhenActualSizeChanged to CreateOffscreenBrowser
Make CreateOffscreenBrowser protected virtual to allow for customisation (it's not something I think you should in general be doing, so I'm not going to make it easy to do so, need to subclass `ChromiumWebBrowser`, then override CreateOffscreenBrowser, making it a NOOP then create a method that calls base.CreateOffscreenBrowser(size)).
1 parent 105bdf3 commit 8f89271

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

CefSharp.Wpf/ChromiumWebBrowser.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,11 +881,20 @@ private void RemoveSourceHook()
881881
}
882882
}
883883

884-
private void CreateOffscreenBrowserWhenActualSizeChanged(Size newSize)
884+
/// <summary>
885+
/// Create the underlying Browser instance, can be overriden to defer control creation
886+
/// The browser will only be created when size > Size(0,0). If you specify a posative
887+
/// size then the browser will be created, if the ActualWidth and ActualHeight
888+
/// properties are in relatity still 0 then you'll likely end up with a browser that
889+
/// won't render.
890+
/// </summary>
891+
/// <param name="size">size of the current control, must be greater than Size(0, 0)</param>
892+
/// <returns>bool to indicate if browser was created. If the browser has already been created then this will return false.</returns>
893+
protected virtual bool CreateOffscreenBrowser(Size size)
885894
{
886-
if (browserCreated || System.ComponentModel.DesignerProperties.GetIsInDesignMode(this) || newSize.IsEmpty)
895+
if (browserCreated || System.ComponentModel.DesignerProperties.GetIsInDesignMode(this) || size.IsEmpty || size.Equals(new Size(0, 0)))
887896
{
888-
return;
897+
return false;
889898
}
890899

891900
var webBrowserInternal = this as IWebBrowserInternal;
@@ -894,6 +903,8 @@ private void CreateOffscreenBrowserWhenActualSizeChanged(Size newSize)
894903
managedCefBrowserAdapter.CreateOffscreenBrowser(source == null ? IntPtr.Zero : source.Handle, BrowserSettings, RequestContext, Address);
895904
}
896905
browserCreated = true;
906+
907+
return true;
897908
}
898909

899910
private void UiThreadRunAsync(Action action, DispatcherPriority priority = DispatcherPriority.DataBind)
@@ -911,7 +922,7 @@ private void UiThreadRunAsync(Action action, DispatcherPriority priority = Dispa
911922
private void OnActualSizeChanged(object sender, SizeChangedEventArgs e)
912923
{
913924
// Initialize RenderClientAdapter when WPF has calculated the actual size of current content.
914-
CreateOffscreenBrowserWhenActualSizeChanged(e.NewSize);
925+
CreateOffscreenBrowser(e.NewSize);
915926

916927
if (browser != null)
917928
{

0 commit comments

Comments
 (0)