diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 2296e70efe..3477815ba0 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -2,13 +2,13 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. -using System.Text; using CefSharp.Internals; using CefSharp.Wpf.Rendering; using Microsoft.Win32.SafeHandles; using System; using System.Collections.Generic; using System.IO; +using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -409,7 +409,7 @@ public bool CanGoBack get { return (bool)GetValue(CanGoBackProperty); } } - public static DependencyProperty CanGoBackProperty = DependencyProperty.Register("CanGoBack", typeof (bool), typeof (ChromiumWebBrowser)); + public static DependencyProperty CanGoBackProperty = DependencyProperty.Register("CanGoBack", typeof(bool), typeof(ChromiumWebBrowser)); #endregion @@ -420,7 +420,7 @@ public bool CanGoForward get { return (bool)GetValue(CanGoForwardProperty); } } - public static DependencyProperty CanGoForwardProperty = DependencyProperty.Register("CanGoForward", typeof (bool), typeof (ChromiumWebBrowser)); + public static DependencyProperty CanGoForwardProperty = DependencyProperty.Register("CanGoForward", typeof(bool), typeof(ChromiumWebBrowser)); #endregion @@ -431,7 +431,7 @@ public bool CanReload get { return (bool)GetValue(CanReloadProperty); } } - public static DependencyProperty CanReloadProperty = DependencyProperty.Register("CanReload", typeof (bool), typeof (ChromiumWebBrowser)); + public static DependencyProperty CanReloadProperty = DependencyProperty.Register("CanReload", typeof(bool), typeof(ChromiumWebBrowser)); #endregion @@ -510,7 +510,6 @@ private static void OnIsBrowserInitializedChanged(DependencyObject d, Dependency protected virtual void OnIsBrowserInitializedChanged(bool oldValue, bool newValue) { - } #endregion IsInitialized dependency property @@ -524,7 +523,21 @@ public string Title } public static readonly DependencyProperty TitleProperty = - DependencyProperty.Register("Title", typeof(string), typeof(ChromiumWebBrowser), new PropertyMetadata(defaultValue: null)); + DependencyProperty.Register("Title", typeof(string), typeof(ChromiumWebBrowser), new PropertyMetadata(null, OnTitleChanged)); + + public event DependencyPropertyChangedEventHandler TitleChanged; + + private static void OnTitleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var owner = (ChromiumWebBrowser)d; + + var handlers = owner.TitleChanged; + + if (handlers != null) + { + handlers(owner, e); + } + } #endregion Title dependency property @@ -768,7 +781,7 @@ private static string GetLink(IDataObject data) return unicodeUrl; } } - + // Try ASCII if (data.GetDataPresent(asciiUrlDataFormatName)) { @@ -927,7 +940,7 @@ private Popup CreatePopup() private IntPtr SourceHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, ref bool handled) { - if(handled) + if (handled) { return IntPtr.Zero; } @@ -941,7 +954,6 @@ private IntPtr SourceHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam case WM.KEYUP: case WM.CHAR: case WM.IME_CHAR: - { if (!IsKeyboardFocused) { break; @@ -956,9 +968,8 @@ private IntPtr SourceHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam } handled = managedCefBrowserAdapter.SendKeyEvent(message, wParam.ToInt32(), lParam); - + break; - } } return IntPtr.Zero; @@ -1018,7 +1029,7 @@ private static CefEventFlags GetModifiers(MouseEventArgs e) if (Keyboard.IsKeyDown(Key.LeftAlt)) { - modifiers |= CefEventFlags.AltDown| CefEventFlags.IsLeft; + modifiers |= CefEventFlags.AltDown | CefEventFlags.IsLeft; } if (Keyboard.IsKeyDown(Key.RightAlt)) @@ -1135,7 +1146,7 @@ private void OnPreviewKey(KeyEventArgs e) // Hooking the Tab key like this makes the tab focusing in essence work like // KeyboardNavigation.TabNavigation="Cycle"; you will never be able to Tab out of the web browser control. // We also add the condition to allow ctrl+a to work when the web browser control is put inside listbox. - if (e.Key == Key.Tab || e.Key == Key.Home || e.Key == Key.End || e.Key == Key.Up + if (e.Key == Key.Tab || e.Key == Key.Home || e.Key == Key.End || e.Key == Key.Up || e.Key == Key.Down || e.Key == Key.Left || e.Key == Key.Right || (e.Key == Key.A && Keyboard.Modifiers == ModifierKeys.Control)) { @@ -1219,24 +1230,19 @@ private void OnMouseButton(MouseButtonEventArgs e) switch (e.ChangedButton) { case MouseButton.Left: - { mouseButtonType = MouseButtonType.Left; break; - } + case MouseButton.Middle: - { mouseButtonType = MouseButtonType.Middle; break; - } + case MouseButton.Right: - { mouseButtonType = MouseButtonType.Right; break; - } + default: - { return; - } } var modifiers = GetModifiers(e);