From 7eafe6211c5d152915df28224b1925e4d2c01d02 Mon Sep 17 00:00:00 2001 From: ralphmayr Date: Fri, 10 Apr 2015 06:57:16 +0200 Subject: [PATCH] Fixed #583: Handle IME input in the WPF example Reverted changes from 77b433bb69bf10fa1471697a28d6c870bb702a57 and instead exposed SendKeyEvent in the ChromiumWebBrowser to be able to move the handler for OnPreviewTextInput to the WPF example. --- .../Views/BrowserTabView.xaml.cs | 9 ++++++++ CefSharp.Wpf/ChromiumWebBrowser.cs | 22 +++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs index 916fcac4f3..13bc7f1be9 100644 --- a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs +++ b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs @@ -20,6 +20,15 @@ public BrowserTabView() browser.MenuHandler = new Handlers.MenuHandler(); browser.GeolocationHandler = new Handlers.GeolocationHandler(); browser.DownloadHandler = new DownloadHandler(); + browser.PreviewTextInput += (o, e) => + { + foreach (var character in e.Text) + { + browser.SendKeyEvent((int)WM.CHAR, character, 0); + } + + e.Handled = true; + }; CefExample.RegisterTestResources(browser); } diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 268c110dc8..409d3f8b6a 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -952,6 +952,7 @@ private IntPtr SourceHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam case WM.SYSKEYUP: case WM.KEYDOWN: case WM.KEYUP: + case WM.CHAR: case WM.IME_CHAR: if (!IsKeyboardFocused) { @@ -1157,15 +1158,6 @@ private void OnPreviewKey(KeyEventArgs e) } } - protected override void OnPreviewTextInput(TextCompositionEventArgs e) - { - for (int i = 0; i < e.Text.Length; i++) - { - managedCefBrowserAdapter.SendKeyEvent((int)WM.CHAR, (int)e.Text[i], (IntPtr) 0); - } - base.OnPreviewTextInput(e); - } - protected override void OnMouseMove(MouseEventArgs e) { var point = GetPixelPosition(e); @@ -1484,5 +1476,17 @@ public void SetZoomLevel(double zoomLevel) { managedCefBrowserAdapter.SetZoomLevel(zoomLevel); } + + /// + /// Sends a Key Event directly to the underlying Browser (CEF). + /// + /// The message + /// The wParam + /// The lParam + /// bool + public bool SendKeyEvent(int message, int wParam, int lParam) + { + return managedCefBrowserAdapter.SendKeyEvent(message, wParam, new IntPtr(lParam)); + } } }