Skip to content

Commit c912277

Browse files
committed
WPF - Add ability to Enable/Disable Hack for 2779
Issue #2779
1 parent 0d67b05 commit c912277

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

CefSharp.Wpf/ChromiumWebBrowser.cs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ public class ChromiumWebBrowser : Control, IRenderWebBrowser, IWpfWebBrowser
138138
/// </summary>
139139
private int disposeSignaled;
140140

141+
/// <summary>
142+
/// Hack to work around issue https://github.com/cefsharp/CefSharp/issues/2779
143+
/// Enabled by default
144+
/// </summary>
145+
public bool EnableResizeHackForIssue2779 { get; set; }
146+
141147
/// <summary>
142148
/// Gets a value indicating whether this instance is disposed.
143149
/// </summary>
@@ -513,6 +519,8 @@ public ChromiumWebBrowser(string initialAddress)
513519
[MethodImpl(MethodImplOptions.NoInlining)]
514520
private void NoInliningConstructor()
515521
{
522+
EnableResizeHackForIssue2779 = true;
523+
516524
//Initialize CEF if it hasn't already been initialized
517525
if (!Cef.IsInitialized)
518526
{
@@ -1759,7 +1767,10 @@ private void OnWindowStateChanged(object sender, EventArgs e)
17591767
}
17601768
case WindowState.Minimized:
17611769
{
1762-
resizeHackForIssue2779Enabled = true;
1770+
if (EnableResizeHackForIssue2779)
1771+
{
1772+
resizeHackForIssue2779Enabled = true;
1773+
}
17631774

17641775
if (browser != null)
17651776
{
@@ -1929,7 +1940,7 @@ private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArg
19291940
TaskContinuationOptions.OnlyOnRanToCompletion,
19301941
TaskScheduler.FromCurrentSynchronizationContext());
19311942
}
1932-
else
1943+
else if (EnableResizeHackForIssue2779)
19331944
{
19341945
resizeHackForIssue2779Enabled = true;
19351946
}
@@ -2386,35 +2397,38 @@ private bool InternalIsBrowserInitialized()
23862397

23872398
private void ResizeHackFor2779()
23882399
{
2389-
const int delayInMs = 50;
2390-
2391-
Task.Run(async () =>
2400+
if (EnableResizeHackForIssue2779)
23922401
{
2393-
await Task.Delay(delayInMs);
2402+
const int delayInMs = 50;
23942403

2395-
if (browser != null)
2404+
Task.Run(async () =>
23962405
{
2397-
resizeHackForIssue2779Size = new Structs.Size(viewRect.Width - 1, viewRect.Height - 1);
2398-
browser.GetHost().WasResized();
2399-
}
2406+
await Task.Delay(delayInMs);
24002407

2401-
await Task.Delay(delayInMs);
2408+
if (browser != null)
2409+
{
2410+
resizeHackForIssue2779Size = new Structs.Size(viewRect.Width - 1, viewRect.Height - 1);
2411+
browser.GetHost().WasResized();
2412+
}
24022413

2403-
if (browser != null)
2404-
{
2405-
resizeHackForIssue2779Size = null;
2406-
browser.GetHost().WasResized();
2407-
}
2414+
await Task.Delay(delayInMs);
24082415

2409-
await Task.Delay(delayInMs);
2416+
if (browser != null)
2417+
{
2418+
resizeHackForIssue2779Size = null;
2419+
browser.GetHost().WasResized();
2420+
}
24102421

2411-
if (browser != null)
2412-
{
2413-
resizeHackForIssue2779Enabled = false;
2422+
await Task.Delay(delayInMs);
24142423

2415-
browser.GetHost().Invalidate(PaintElementType.View);
2416-
}
2417-
});
2424+
if (browser != null)
2425+
{
2426+
resizeHackForIssue2779Enabled = false;
2427+
2428+
browser.GetHost().Invalidate(PaintElementType.View);
2429+
}
2430+
});
2431+
}
24182432
}
24192433
}
24202434
}

0 commit comments

Comments
 (0)