Skip to content

Commit

Permalink
Merge 58e4604 into 335c884
Browse files Browse the repository at this point in the history
  • Loading branch information
a-marmer authored Apr 26, 2019
2 parents 335c884 + 58e4604 commit 5f38407
Show file tree
Hide file tree
Showing 10 changed files with 832 additions and 72 deletions.
166 changes: 109 additions & 57 deletions CefSharp.Core/Internals/CefBrowserHostWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,58 @@ void CefBrowserHostWrapper::ImeCommitText(String^ text, Nullable<Range> replacem
_browserHost->ImeCommitText(StringUtils::ToNative(text), repRange, relativeCursorPos);
}


void CefBrowserHostWrapper::ImeSetComposition(String^ text, cli::array<CompositionUnderline>^ underlines, Nullable<Range> selectionRange)
{
ThrowIfDisposed();

std::vector<CefCompositionUnderline> underlinesVector = std::vector<CefCompositionUnderline>();
CefRange range;

if (underlines != nullptr && underlines->Length > 0)
{
for each (CompositionUnderline underline in underlines)
{
auto c = CefCompositionUnderline();
c.range = CefRange(underline.Range.From, underline.Range.To);
c.color = underline.Color;
c.background_color = underline.BackgroundColor;
c.thick = (int)underline.Thick;
underlinesVector.push_back(c);
}
}

if (selectionRange.HasValue)
{
range = CefRange(selectionRange.Value.From, selectionRange.Value.To);
}

//Replacement Range is Mac OSX only
_browserHost->ImeSetComposition(StringUtils::ToNative(text), underlinesVector, CefRange(UINT32_MAX, UINT32_MAX), range);
}


void CefBrowserHostWrapper::ImeSetComposition(const CefString& text, const std::vector<CefCompositionUnderline>& underlines, const CefRange& replacement_range, const CefRange& selection_range)
{
ThrowIfDisposed();
_browserHost->ImeSetComposition(text, underlines, replacement_range, selection_range);
}


void CefBrowserHostWrapper::ImeCommitText(String^ text)
{
ThrowIfDisposed();

//Range and cursor position are Mac OSX only
_browserHost->ImeCommitText(StringUtils::ToNative(text), CefRange(UINT32_MAX, UINT32_MAX), 0);
}

void CefBrowserHostWrapper::ImeCommitText(const CefString& text, const CefRange& replacement_range, int relative_cursor_pos)
{
ThrowIfDisposed();
_browserHost->ImeCommitText(text, replacement_range, relative_cursor_pos);
}

void CefBrowserHostWrapper::ImeFinishComposingText(bool keepSelection)
{
ThrowIfDisposed();
Expand Down Expand Up @@ -606,66 +658,66 @@ int CefBrowserHostWrapper::GetCefKeyboardModifiers(WPARAM wparam, LPARAM lparam)

switch (wparam)
{
case VK_RETURN:
if ((lparam >> 16) & KF_EXTENDED)
case VK_RETURN:
if ((lparam >> 16) & KF_EXTENDED)
modifiers |= EVENTFLAG_IS_KEY_PAD;
break;
case VK_INSERT:
case VK_DELETE:
case VK_HOME:
case VK_END:
case VK_PRIOR:
case VK_NEXT:
case VK_UP:
case VK_DOWN:
case VK_LEFT:
case VK_RIGHT:
if (!((lparam >> 16) & KF_EXTENDED))
modifiers |= EVENTFLAG_IS_KEY_PAD;
break;
case VK_NUMLOCK:
case VK_NUMPAD0:
case VK_NUMPAD1:
case VK_NUMPAD2:
case VK_NUMPAD3:
case VK_NUMPAD4:
case VK_NUMPAD5:
case VK_NUMPAD6:
case VK_NUMPAD7:
case VK_NUMPAD8:
case VK_NUMPAD9:
case VK_DIVIDE:
case VK_MULTIPLY:
case VK_SUBTRACT:
case VK_ADD:
case VK_DECIMAL:
case VK_CLEAR:
modifiers |= EVENTFLAG_IS_KEY_PAD;
break;
case VK_INSERT:
case VK_DELETE:
case VK_HOME:
case VK_END:
case VK_PRIOR:
case VK_NEXT:
case VK_UP:
case VK_DOWN:
case VK_LEFT:
case VK_RIGHT:
if (!((lparam >> 16) & KF_EXTENDED))
modifiers |= EVENTFLAG_IS_KEY_PAD;
break;
case VK_NUMLOCK:
case VK_NUMPAD0:
case VK_NUMPAD1:
case VK_NUMPAD2:
case VK_NUMPAD3:
case VK_NUMPAD4:
case VK_NUMPAD5:
case VK_NUMPAD6:
case VK_NUMPAD7:
case VK_NUMPAD8:
case VK_NUMPAD9:
case VK_DIVIDE:
case VK_MULTIPLY:
case VK_SUBTRACT:
case VK_ADD:
case VK_DECIMAL:
case VK_CLEAR:
modifiers |= EVENTFLAG_IS_KEY_PAD;
break;
case VK_SHIFT:
if (IsKeyDown(VK_LSHIFT))
modifiers |= EVENTFLAG_IS_LEFT;
else if (IsKeyDown(VK_RSHIFT))
modifiers |= EVENTFLAG_IS_RIGHT;
break;
case VK_CONTROL:
if (IsKeyDown(VK_LCONTROL))
modifiers |= EVENTFLAG_IS_LEFT;
else if (IsKeyDown(VK_RCONTROL))
modifiers |= EVENTFLAG_IS_RIGHT;
break;
case VK_MENU:
if (IsKeyDown(VK_LMENU))
break;
case VK_SHIFT:
if (IsKeyDown(VK_LSHIFT))
modifiers |= EVENTFLAG_IS_LEFT;
else if (IsKeyDown(VK_RSHIFT))
modifiers |= EVENTFLAG_IS_RIGHT;
break;
case VK_CONTROL:
if (IsKeyDown(VK_LCONTROL))
modifiers |= EVENTFLAG_IS_LEFT;
else if (IsKeyDown(VK_RCONTROL))
modifiers |= EVENTFLAG_IS_RIGHT;
break;
case VK_MENU:
if (IsKeyDown(VK_LMENU))
modifiers |= EVENTFLAG_IS_LEFT;
else if (IsKeyDown(VK_RMENU))
modifiers |= EVENTFLAG_IS_RIGHT;
break;
case VK_LWIN:
modifiers |= EVENTFLAG_IS_LEFT;
else if (IsKeyDown(VK_RMENU))
break;
case VK_RWIN:
modifiers |= EVENTFLAG_IS_RIGHT;
break;
case VK_LWIN:
modifiers |= EVENTFLAG_IS_LEFT;
break;
case VK_RWIN:
modifiers |= EVENTFLAG_IS_RIGHT;
break;
break;
}
return modifiers;
}
6 changes: 6 additions & 0 deletions CefSharp.Core/Internals/CefBrowserHostWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ namespace CefSharp
bool get();
}

virtual void ImeSetComposition(String^ text, cli::array<CompositionUnderline>^ underlines, Nullable<Range> selectionRange);
virtual void ImeSetComposition(const CefString& text, const std::vector<CefCompositionUnderline>& underlines, const CefRange& replacement_range, const CefRange& selection_range);
virtual void ImeCommitText(String^ text);
virtual void ImeCommitText(const CefString& text, const CefRange& replacement_range, int relative_cursor_pos);


virtual void ImeSetComposition(String^ text, cli::array<CompositionUnderline>^ underlines, Nullable<Range> replacementRange, Nullable<Range> selectionRange);
virtual void ImeCommitText(String^ text, Nullable<Range> replacementRange, int relativeCursorPos);
virtual void ImeFinishComposingText(bool keepSelection);
Expand Down
5 changes: 0 additions & 5 deletions CefSharp.Example/Filters/FindReplaceResponseFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ public class FindReplaceResponseFilter : IResponseFilter
/// </summary>
private List<byte> overflow = new List<byte>();

/// <summary>
/// Number of times the the string was found/replaced.
/// </summary>
private long replaceCount;

public FindReplaceResponseFilter(string find, string replacement)
{
findString = find;
Expand Down
1 change: 0 additions & 1 deletion CefSharp.WinForms.Example/BrowserTabUserControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ private void SetupMessageInterceptor()
{
const int WM_MOUSEACTIVATE = 0x0021;
const int WM_NCLBUTTONDOWN = 0x00A1;
const int WM_LBUTTONDOWN = 0x0201;
const int WM_DESTROY = 0x0002;

// Render process switch happened, need to find the new handle
Expand Down
4 changes: 3 additions & 1 deletion CefSharp.Wpf/CefSharp.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CefSettings.cs" />
<Compile Include="Experimental\ChromiumWebBrowserWithTouchSupport.cs" />
<Compile Include="IME\IMEHandler.cs" />
<Compile Include="IME\NativeIME.cs" />
<Compile Include="Experimental\ChromiumWebBrowserWithTouchSupport.cs" />
<Compile Include="Internals\DragOperationMaskExtensions.cs" />
<Compile Include="Internals\MonitorInfo.cs" />
<Compile Include="Internals\MonitorInfoEx.cs" />
Expand Down
60 changes: 55 additions & 5 deletions CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -11,13 +13,15 @@
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;
using CefSharp.Enums;
using CefSharp.Internals;
using CefSharp.Structs;
using CefSharp.Wpf.Internals;
using CefSharp.Wpf.Rendering;
using Microsoft.Win32.SafeHandles;
using CefSharp.Wpf.IME;
using CursorType = CefSharp.Enums.CursorType;
using Point = System.Windows.Point;
using Rect = CefSharp.Structs.Rect;
Expand Down Expand Up @@ -703,10 +707,10 @@ private void InternalDispose(bool disposing)
Cef.RemoveDisposable(this);
}

/// <summary>
/// Gets the ScreenInfo - currently used to get the DPI scale factor.
/// </summary>
/// <returns>ScreenInfo containing the current DPI scale factor</returns>
/// <summary>
/// Gets the ScreenInfo - currently used to get the DPI scale factor.
/// </summary>
/// <returns>ScreenInfo containing the current DPI scale factor</returns>
ScreenInfo? IRenderWebBrowser.GetScreenInfo()
{
return GetScreenInfo();
Expand Down Expand Up @@ -960,7 +964,47 @@ void IRenderWebBrowser.OnCursorChange(IntPtr handle, CursorType type, CursorInfo

void IRenderWebBrowser.OnImeCompositionRangeChanged(Range selectedRange, Rect[] characterBounds)
{
OnImeCompositionRangeChanged(selectedRange, characterBounds);
Visual GetParentWindow()
{
var current = VisualTreeHelper.GetParent(this);
while (current != null && !(current is Window))
{
current = VisualTreeHelper.GetParent(current);
}

return current as Window;
}

var imeKeyboardHandler = WpfKeyboardHandler as WpfKeyboardHandler;
if (imeKeyboardHandler.IsActive)
{
var screenInfo = GetScreenInfo();
var scaleFactor = screenInfo.HasValue ? screenInfo.Value.DeviceScaleFactor : 1.0f;

UiThreadRunSync(() =>
{
var parentWindow = GetParentWindow();
Point pnt = parentWindow.PointToScreen(new Point(0, 0));

if (parentWindow != null)
{
var point = TransformToAncestor(parentWindow).Transform(new Point(0, 0));

var rects = new List<Structs.Rect>();

foreach (var item in characterBounds)
{
rects.Add(new Structs.Rect(
(int)((point.X + item.X) * scaleFactor),
(int)((point.Y + item.Y) * scaleFactor),
(int)(item.Width * scaleFactor),
(int)(item.Height * scaleFactor)));
}

imeKeyboardHandler.ChangeCompositionRange(selectedRange, rects);
}
});
}
}

/// <summary>
Expand Down Expand Up @@ -2140,6 +2184,12 @@ protected override void OnMouseWheel(MouseWheelEventArgs e)
/// This event data reports details about the mouse button that was pressed and the handled state.</param>
protected override void OnMouseDown(MouseButtonEventArgs e)
{
var wpfKeyboardHandler = WpfKeyboardHandler as WpfKeyboardHandler;
if (wpfKeyboardHandler != null)
{
wpfKeyboardHandler.CloseIMEComposition();
}

Focus();
OnMouseButton(e);

Expand Down
Loading

0 comments on commit 5f38407

Please sign in to comment.