From cd322af03d3386f98875cfb099af9fe7331f4a44 Mon Sep 17 00:00:00 2001 From: amaitland Date: Mon, 21 Mar 2016 08:58:57 +1000 Subject: [PATCH] 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 --- CefSharp.Wpf/CefSharp.Wpf.csproj | 1 - CefSharp.Wpf/ChromiumWebBrowser.cs | 21 ++++++------------ CefSharp.Wpf/DisposableEventWrapper.cs | 30 -------------------------- 3 files changed, 6 insertions(+), 46 deletions(-) delete mode 100644 CefSharp.Wpf/DisposableEventWrapper.cs diff --git a/CefSharp.Wpf/CefSharp.Wpf.csproj b/CefSharp.Wpf/CefSharp.Wpf.csproj index d37a117d23..16e9a364d9 100644 --- a/CefSharp.Wpf/CefSharp.Wpf.csproj +++ b/CefSharp.Wpf/CefSharp.Wpf.csproj @@ -74,7 +74,6 @@ - diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index f45467de65..7c360040c7 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -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; @@ -23,8 +22,6 @@ namespace CefSharp.Wpf { public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrowser { - private readonly List disposables = new List(); - private HwndSource source; private HwndSourceHook sourceHook; private DispatcherTimer tooltipTimer; @@ -118,6 +115,7 @@ public ChromiumWebBrowser() Dispatcher.BeginInvoke((Action)(() => WebBrowser = this)); Loaded += OnLoaded; + SizeChanged += OnActualSizeChanged; GotKeyboardFocus += OnGotKeyboardFocus; LostKeyboardFocus += OnLostKeyboardFocus; @@ -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(); @@ -205,6 +200,7 @@ protected virtual void Dispose(bool isdisposing) // Release internal event listeners: Loaded -= OnLoaded; + SizeChanged -= OnActualSizeChanged; GotKeyboardFocus -= OnGotKeyboardFocus; LostKeyboardFocus -= OnLostKeyboardFocus; @@ -232,11 +228,6 @@ protected virtual void Dispose(bool isdisposing) managedCefBrowserAdapter = null; } - foreach (var disposable in disposables) - { - disposable.Dispose(); - } - disposables.Clear(); browserInitialized = false; UiThreadRunAsync(() => @@ -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; } @@ -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) { diff --git a/CefSharp.Wpf/DisposableEventWrapper.cs b/CefSharp.Wpf/DisposableEventWrapper.cs deleted file mode 100644 index 67cf7203f6..0000000000 --- a/CefSharp.Wpf/DisposableEventWrapper.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright © 2010-2016 The CefSharp Authors. All rights reserved. -// -// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. - -using System; -using System.ComponentModel; -using System.Windows; - -namespace CefSharp.Wpf -{ - internal class DisposableEventWrapper : IDisposable - { - public DependencyObject Source { get; private set; } - public DependencyProperty Property { get; private set; } - public EventHandler Handler { get; private set; } - - public DisposableEventWrapper(DependencyObject source, DependencyProperty property, EventHandler handler) - { - Source = source; - Property = property; - Handler = handler; - DependencyPropertyDescriptor.FromProperty(Property, Source.GetType()).AddValueChanged(Source, Handler); - } - - public void Dispose() - { - DependencyPropertyDescriptor.FromProperty(Property, Source.GetType()).RemoveValueChanged(Source, Handler); - } - } -} \ No newline at end of file