Skip to content

Commit

Permalink
WPF - Add ability to Enable/Disable Hack for 2779
Browse files Browse the repository at this point in the history
Issue #2779
  • Loading branch information
amaitland committed Jul 27, 2019
1 parent 0d67b05 commit c912277
Showing 1 changed file with 37 additions and 23 deletions.
60 changes: 37 additions & 23 deletions CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ public class ChromiumWebBrowser : Control, IRenderWebBrowser, IWpfWebBrowser
/// </summary>
private int disposeSignaled;

/// <summary>
/// Hack to work around issue https://github.com/cefsharp/CefSharp/issues/2779
/// Enabled by default
/// </summary>
public bool EnableResizeHackForIssue2779 { get; set; }

/// <summary>
/// Gets a value indicating whether this instance is disposed.
/// </summary>
Expand Down Expand Up @@ -513,6 +519,8 @@ public ChromiumWebBrowser(string initialAddress)
[MethodImpl(MethodImplOptions.NoInlining)]
private void NoInliningConstructor()
{
EnableResizeHackForIssue2779 = true;

//Initialize CEF if it hasn't already been initialized
if (!Cef.IsInitialized)
{
Expand Down Expand Up @@ -1759,7 +1767,10 @@ private void OnWindowStateChanged(object sender, EventArgs e)
}
case WindowState.Minimized:
{
resizeHackForIssue2779Enabled = true;
if (EnableResizeHackForIssue2779)
{
resizeHackForIssue2779Enabled = true;
}

if (browser != null)
{
Expand Down Expand Up @@ -1929,7 +1940,7 @@ private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArg
TaskContinuationOptions.OnlyOnRanToCompletion,
TaskScheduler.FromCurrentSynchronizationContext());
}
else
else if (EnableResizeHackForIssue2779)
{
resizeHackForIssue2779Enabled = true;
}
Expand Down Expand Up @@ -2386,35 +2397,38 @@ private bool InternalIsBrowserInitialized()

private void ResizeHackFor2779()
{
const int delayInMs = 50;

Task.Run(async () =>
if (EnableResizeHackForIssue2779)
{
await Task.Delay(delayInMs);
const int delayInMs = 50;

if (browser != null)
Task.Run(async () =>
{
resizeHackForIssue2779Size = new Structs.Size(viewRect.Width - 1, viewRect.Height - 1);
browser.GetHost().WasResized();
}
await Task.Delay(delayInMs);
await Task.Delay(delayInMs);
if (browser != null)
{
resizeHackForIssue2779Size = new Structs.Size(viewRect.Width - 1, viewRect.Height - 1);
browser.GetHost().WasResized();
}
if (browser != null)
{
resizeHackForIssue2779Size = null;
browser.GetHost().WasResized();
}
await Task.Delay(delayInMs);
await Task.Delay(delayInMs);
if (browser != null)
{
resizeHackForIssue2779Size = null;
browser.GetHost().WasResized();
}
if (browser != null)
{
resizeHackForIssue2779Enabled = false;
await Task.Delay(delayInMs);
browser.GetHost().Invalidate(PaintElementType.View);
}
});
if (browser != null)
{
resizeHackForIssue2779Enabled = false;
browser.GetHost().Invalidate(PaintElementType.View);
}
});
}
}
}
}

0 comments on commit c912277

Please sign in to comment.