-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WPF - Black browser in TabControl/When Hidden
Hack for issue #2779
- Loading branch information
Showing
1 changed file
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,9 @@ public class ChromiumWebBrowser : Control, IRenderWebBrowser, IWpfWebBrowser | |
/// </summary> | ||
private static bool DesignMode; | ||
|
||
private bool resizeHackForIssue2779Enabled; | ||
private CefSharp.Structs.Size? resizeHackForIssue2779Size; | ||
|
||
/// <summary> | ||
/// The value for disposal, if it's 1 (one) then this instance is either disposed | ||
/// or in the process of getting disposed | ||
|
@@ -743,7 +746,7 @@ private void InternalDispose(bool disposing) | |
|
||
var screenInfo = new ScreenInfo | ||
{ | ||
DeviceScaleFactor = (float)DpiScaleFactor, | ||
DeviceScaleFactor = DpiScaleFactor, | ||
Rect = rect, | ||
AvailableRect = availableRect | ||
}; | ||
|
@@ -768,7 +771,14 @@ Rect IRenderWebBrowser.GetViewRect() | |
/// <returns>View Rectangle</returns> | ||
protected virtual Rect GetViewRect() | ||
{ | ||
return viewRect; | ||
if (resizeHackForIssue2779Size == null) | ||
{ | ||
return viewRect; | ||
} | ||
|
||
var size = resizeHackForIssue2779Size.Value; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
amaitland
Author
Member
|
||
|
||
return new Rect(0, 0, size.Width, size.Height); | ||
} | ||
|
||
bool IRenderWebBrowser.GetScreenPoint(int viewX, int viewY, out int screenX, out int screenY) | ||
|
@@ -910,6 +920,11 @@ void IRenderWebBrowser.OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buf | |
/// <param name="height">height</param> | ||
protected virtual void OnPaint(bool isPopup, Rect dirtyRect, IntPtr buffer, int width, int height) | ||
{ | ||
if (resizeHackForIssue2779Enabled) | ||
{ | ||
return; | ||
} | ||
|
||
var paint = Paint; | ||
if (paint != null) | ||
{ | ||
|
@@ -1737,10 +1752,15 @@ private void OnWindowStateChanged(object sender, EventArgs e) | |
{ | ||
browser.GetHost().WasHidden(false); | ||
} | ||
|
||
ResizeHackFor2779(); | ||
|
||
break; | ||
} | ||
case WindowState.Minimized: | ||
{ | ||
resizeHackForIssue2779Enabled = true; | ||
|
||
if (browser != null) | ||
{ | ||
browser.GetHost().WasHidden(true); | ||
|
@@ -1892,6 +1912,8 @@ private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArg | |
|
||
if (isVisible) | ||
{ | ||
ResizeHackFor2779(); | ||
|
||
//Fix for #1778 - When browser becomes visible we update the zoom level | ||
//browsers of the same origin will share the same zoomlevel and | ||
//we need to track the update, so our ZoomLevelProperty works | ||
|
@@ -1907,6 +1929,10 @@ private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArg | |
TaskContinuationOptions.OnlyOnRanToCompletion, | ||
TaskScheduler.FromCurrentSynchronizationContext()); | ||
} | ||
else | ||
{ | ||
resizeHackForIssue2779Enabled = true; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -2357,5 +2383,38 @@ private bool InternalIsBrowserInitialized() | |
// Volatile.Read would likely use a memory barrier which I believe is unnecessary in this scenario | ||
return Interlocked.CompareExchange(ref browserInitialized, 0, 0) == 1; | ||
} | ||
|
||
private void ResizeHackFor2779() | ||
{ | ||
const int delayInMs = 50; | ||
|
||
Task.Run(async () => | ||
{ | ||
await Task.Delay(delayInMs); | ||
if (browser != null) | ||
{ | ||
resizeHackForIssue2779Size = new Structs.Size(viewRect.Width - 1, viewRect.Height - 1); | ||
browser.GetHost().WasResized(); | ||
} | ||
await Task.Delay(delayInMs); | ||
if (browser != null) | ||
{ | ||
resizeHackForIssue2779Size = null; | ||
browser.GetHost().WasResized(); | ||
} | ||
await Task.Delay(delayInMs); | ||
if (browser != null) | ||
{ | ||
resizeHackForIssue2779Enabled = false; | ||
browser.GetHost().Invalidate(PaintElementType.View); | ||
} | ||
}); | ||
} | ||
} | ||
} |
@amaitland I have reports that resizeHackForIssue2779Size.Value can be null here, resulting in:
So it must have changed between the check and usage. It might be related to our reuse of the browsers so I don't know if I should create a pull request, but in Mailbird I'm going to set a local variable to resizeHackForIssue2779Size and then use that for checking and the value.