Skip to content

Commit

Permalink
Switch to using SizeChanged event rather than being notified of chang…
Browse files Browse the repository at this point in the history
…es to the ActualWidth and ActualHeight (not really sure the original reason that method was choose)

Remove no longer used DisposableEventWrapper
  • Loading branch information
amaitland committed Mar 20, 2016
1 parent b1b38ac commit cd322af
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 46 deletions.
1 change: 0 additions & 1 deletion CefSharp.Wpf/CefSharp.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DelegateCommand.cs" />
<Compile Include="DisposableEventWrapper.cs" />
<Compile Include="Internals\WpfExtensions.cs" />
<Compile Include="Rendering\InteropBitmapInfo.cs" />
<Compile Include="IWpfWebBrowser.cs" />
Expand Down
21 changes: 6 additions & 15 deletions CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using CefSharp.Wpf.Rendering;
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -23,8 +22,6 @@ namespace CefSharp.Wpf
{
public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrowser
{
private readonly List<IDisposable> disposables = new List<IDisposable>();

private HwndSource source;
private HwndSourceHook sourceHook;
private DispatcherTimer tooltipTimer;
Expand Down Expand Up @@ -118,6 +115,7 @@ public ChromiumWebBrowser()
Dispatcher.BeginInvoke((Action)(() => WebBrowser = this));

Loaded += OnLoaded;
SizeChanged += OnActualSizeChanged;

GotKeyboardFocus += OnGotKeyboardFocus;
LostKeyboardFocus += OnLostKeyboardFocus;
Expand Down Expand Up @@ -154,9 +152,6 @@ public ChromiumWebBrowser()

managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true);

disposables.Add(new DisposableEventWrapper(this, ActualHeightProperty, OnActualSizeChanged));
disposables.Add(new DisposableEventWrapper(this, ActualWidthProperty, OnActualSizeChanged));

ResourceHandlerFactory = new DefaultResourceHandlerFactory();
BrowserSettings = new BrowserSettings();

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

// Release internal event listeners:
Loaded -= OnLoaded;
SizeChanged -= OnActualSizeChanged;
GotKeyboardFocus -= OnGotKeyboardFocus;
LostKeyboardFocus -= OnLostKeyboardFocus;

Expand Down Expand Up @@ -232,11 +228,6 @@ protected virtual void Dispose(bool isdisposing)
managedCefBrowserAdapter = null;
}

foreach (var disposable in disposables)
{
disposable.Dispose();
}
disposables.Clear();

browserInitialized = false;
UiThreadRunAsync(() =>
Expand Down Expand Up @@ -890,9 +881,9 @@ private void RemoveSourceHook()
}
}

private void CreateOffscreenBrowserWhenActualSizeChanged()
private void CreateOffscreenBrowserWhenActualSizeChanged(Size newSize)
{
if (browserCreated || System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
if (browserCreated || System.ComponentModel.DesignerProperties.GetIsInDesignMode(this) || newSize.IsEmpty)
{
return;
}
Expand All @@ -917,10 +908,10 @@ private void UiThreadRunAsync(Action action, DispatcherPriority priority = Dispa
}
}

private void OnActualSizeChanged(object sender, EventArgs e)
private void OnActualSizeChanged(object sender, SizeChangedEventArgs e)
{
// Initialize RenderClientAdapter when WPF has calculated the actual size of current content.
CreateOffscreenBrowserWhenActualSizeChanged();
CreateOffscreenBrowserWhenActualSizeChanged(e.NewSize);

if (browser != null)
{
Expand Down
30 changes: 0 additions & 30 deletions CefSharp.Wpf/DisposableEventWrapper.cs

This file was deleted.

0 comments on commit cd322af

Please sign in to comment.