Skip to content

Commit cd322af

Browse files
committed
Switch to using SizeChanged event rather than being notified of changes to the ActualWidth and ActualHeight (not really sure the original reason that method was choose)
Remove no longer used DisposableEventWrapper
1 parent b1b38ac commit cd322af

File tree

3 files changed

+6
-46
lines changed

3 files changed

+6
-46
lines changed

CefSharp.Wpf/CefSharp.Wpf.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
</ItemGroup>
7575
<ItemGroup>
7676
<Compile Include="DelegateCommand.cs" />
77-
<Compile Include="DisposableEventWrapper.cs" />
7877
<Compile Include="Internals\WpfExtensions.cs" />
7978
<Compile Include="Rendering\InteropBitmapInfo.cs" />
8079
<Compile Include="IWpfWebBrowser.cs" />

CefSharp.Wpf/ChromiumWebBrowser.cs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using CefSharp.Wpf.Rendering;
88
using Microsoft.Win32.SafeHandles;
99
using System;
10-
using System.Collections.Generic;
1110
using System.Threading;
1211
using System.Threading.Tasks;
1312
using System.Windows;
@@ -23,8 +22,6 @@ namespace CefSharp.Wpf
2322
{
2423
public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrowser
2524
{
26-
private readonly List<IDisposable> disposables = new List<IDisposable>();
27-
2825
private HwndSource source;
2926
private HwndSourceHook sourceHook;
3027
private DispatcherTimer tooltipTimer;
@@ -118,6 +115,7 @@ public ChromiumWebBrowser()
118115
Dispatcher.BeginInvoke((Action)(() => WebBrowser = this));
119116

120117
Loaded += OnLoaded;
118+
SizeChanged += OnActualSizeChanged;
121119

122120
GotKeyboardFocus += OnGotKeyboardFocus;
123121
LostKeyboardFocus += OnLostKeyboardFocus;
@@ -154,9 +152,6 @@ public ChromiumWebBrowser()
154152

155153
managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true);
156154

157-
disposables.Add(new DisposableEventWrapper(this, ActualHeightProperty, OnActualSizeChanged));
158-
disposables.Add(new DisposableEventWrapper(this, ActualWidthProperty, OnActualSizeChanged));
159-
160155
ResourceHandlerFactory = new DefaultResourceHandlerFactory();
161156
BrowserSettings = new BrowserSettings();
162157

@@ -205,6 +200,7 @@ protected virtual void Dispose(bool isdisposing)
205200

206201
// Release internal event listeners:
207202
Loaded -= OnLoaded;
203+
SizeChanged -= OnActualSizeChanged;
208204
GotKeyboardFocus -= OnGotKeyboardFocus;
209205
LostKeyboardFocus -= OnLostKeyboardFocus;
210206

@@ -232,11 +228,6 @@ protected virtual void Dispose(bool isdisposing)
232228
managedCefBrowserAdapter = null;
233229
}
234230

235-
foreach (var disposable in disposables)
236-
{
237-
disposable.Dispose();
238-
}
239-
disposables.Clear();
240231

241232
browserInitialized = false;
242233
UiThreadRunAsync(() =>
@@ -890,9 +881,9 @@ private void RemoveSourceHook()
890881
}
891882
}
892883

893-
private void CreateOffscreenBrowserWhenActualSizeChanged()
884+
private void CreateOffscreenBrowserWhenActualSizeChanged(Size newSize)
894885
{
895-
if (browserCreated || System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
886+
if (browserCreated || System.ComponentModel.DesignerProperties.GetIsInDesignMode(this) || newSize.IsEmpty)
896887
{
897888
return;
898889
}
@@ -917,10 +908,10 @@ private void UiThreadRunAsync(Action action, DispatcherPriority priority = Dispa
917908
}
918909
}
919910

920-
private void OnActualSizeChanged(object sender, EventArgs e)
911+
private void OnActualSizeChanged(object sender, SizeChangedEventArgs e)
921912
{
922913
// Initialize RenderClientAdapter when WPF has calculated the actual size of current content.
923-
CreateOffscreenBrowserWhenActualSizeChanged();
914+
CreateOffscreenBrowserWhenActualSizeChanged(e.NewSize);
924915

925916
if (browser != null)
926917
{

CefSharp.Wpf/DisposableEventWrapper.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)