Skip to content

Commit

Permalink
Fixed cefsharp#583: Handle IME input in the WPF example
Browse files Browse the repository at this point in the history
Reverted changes from 77b433b and
instead exposed SendKeyEvent in the ChromiumWebBrowser to be able to
move the handler for OnPreviewTextInput to the WPF example.
  • Loading branch information
ralphmayr committed Apr 10, 2015
1 parent 23b96b8 commit 7eafe62
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
9 changes: 9 additions & 0 deletions CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
22 changes: 13 additions & 9 deletions CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1484,5 +1476,17 @@ public void SetZoomLevel(double zoomLevel)
{
managedCefBrowserAdapter.SetZoomLevel(zoomLevel);
}

/// <summary>
/// Sends a Key Event directly to the underlying Browser (CEF).
/// </summary>
/// <param name="message">The message</param>
/// <param name="wParam">The wParam</param>
/// <param name="lParam">The lParam</param>
/// <returns>bool</returns>
public bool SendKeyEvent(int message, int wParam, int lParam)
{
return managedCefBrowserAdapter.SendKeyEvent(message, wParam, new IntPtr(lParam));
}
}
}

0 comments on commit 7eafe62

Please sign in to comment.