CefSharp icon indicating copy to clipboard operation
CefSharp copied to clipboard

WPF - IME Windows 8.1/10/11

Open ay2015 opened this issue 8 years ago • 57 comments

I use the project from official website and version '41.0.1' ,when I design a wonderful window,I have to set variable ''AllowsTransparency" to "true", “WindowStyle” to "None",I edited the ‘MainWindow.xaml’ ,set variable ''AllowsTransparency" to "true", “WindowStyle” to "None",and run. the problem: input tag from html can't use other IME,but character is Ok,how can I solve it?
Thanks for you

ay2015 avatar Sep 10 '15 02:09 ay2015

https://bitbucket.org/chromiumembedded/cef/issues/1675/inline-ime-support-nstextinput-protocol-in Seems they still working on it

TyrWang avatar Nov 16 '16 07:11 TyrWang

https://bitbucket.org/chromiumembedded/cef/issues/1675/inline-ime-support-nstextinput-protocol-in

I have created wrappers for the methods exposed see https://github.com/cefsharp/CefSharp/commit/fdd08896d741fdd9c75decc4c5632c2e95de3fe0 This takes care of the C++ step, now it's up to someone else to finish the implementation and map/forward the relevant WPF events. I know nothing about IME, I have not tested the changes, so make sure you double check they're mapped correctly. CEF includes an example of as part of https://bitbucket.org/chromiumembedded/cef/commits/f7014be

Please don't ask me questions about this as I've not used the new API methods, it's up to someone else to figure out. If you need to ask follow up questions about the CEF API do so at http://magpcss.org/ceforum/viewforum.php?f=6

amaitland avatar Dec 13 '16 21:12 amaitland

I intend to cleanup this issue, removing unnecessary comments and condensing the issue down to the relevant information for the current version. I will do this in roughly two weeks. If there are objections then I will close and lock this issue and create new issue that has only the relevant information and provide a link in this issue.

amaitland avatar Feb 09 '18 05:02 amaitland

NOTE Many of the old comments that are no longer relevant have been removed, here is a summary of the current sate of IME when using the WPF version of CefSharp.

Workaround For those that need an immediate solution then hosting the WinForms version in WPF the best option at this point in time.

Long term

CEF has added support for IME, I have exposed the relevant wrappers (untested, so minor changes may still be required)

  • PR #2103 was submitted, though won't be merged at this point as it failed review. It implemented an almost direct copy of the CEF reference implementation, much of the code is irrelevant to CefSharp and would need to be removed. The original author appears to have stopped working on the PR.
  • PR #2056 rewrote the WPF keyboard handling and subsequently opened up the option to allow for a pluggable keyboard implementation.

There are two options going forward that I see as viable

  • Take the work done in #2103 and implement it as an IWpfKeyboardHandler, a managed implementation would be preferable as it would allow more users to debug the code.
  • Investigate the possibility integrating directly into the managed WPF IME implementation. This would be the ideal solution.

If anyone is interested in taking up this task then please say so.

Please only post a comment if your interested in helping, have valuable links that would aide in the implementation. There is no need to confirm which version it's not working in, as it's not working in any version of CefSharp. Comments along the lines of Please fix this, Why hasn't this been fixed yet, will be removed.

amaitland avatar Mar 06 '18 03:03 amaitland

This is something I might be able to take on. We have customers who would benefit from this fix. Let me see whether I can set aside some time in our next release plan for this.

chris-araman avatar Mar 06 '18 19:03 chris-araman

I've created a managed keyboard handler based on #2103. It needs more testing but feel free to use it and create a pr if you want to improve it.

https://github.com/Antonyo/CefSharp/tree/IME_Support

I've tried to modify the core Cefsharp code the bare minimum, I've also modified the SimpleMainWindow as an example of use.

Antonyo avatar Dec 07 '18 01:12 Antonyo

Thanks @Antonyo 👍

Found an issue. I used Japanese IME. When I add one more tab and start typing in the Address bar, then the default IME UI shows up.

Looks like this code (OnIMESetContext) is not taking effect -

            // We handle the IME Composition Window ourselves (but let the IME Candidates

            // Window be handled by IME through DefWindowProc()), so clear the

            // ISC_SHOWUICOMPOSITIONWINDOW flag:

            lParam = (IntPtr)(lParam.ToInt64() & ~NativeIME.ISC_SHOWUICOMPOSITIONWINDOW);

            NativeIME.DefWindowProc(hwnd, msg, wParam, lParam);

bug

angshuman-agarwal avatar Dec 26 '18 15:12 angshuman-agarwal

Hey @angshuman-agarwal I mostly tested it with Japanese IME (that's the only asian language I speak) so it doesn't have to be an issue related to that language but maybe something specific to your computer, please write me an email with the details like what kind of Japanese IME you are using, MS or Google, and I will gladly help you and update the code.

Antonyo avatar Dec 27 '18 04:12 Antonyo

@Antonyo Apologies, please ignore my previous comment. I forgot to change the StartUpUri to SimpleMainWindow.xaml. I have done that now and issue is a different one.

diff

The IME Candidate Window shows up in Bottom right. Looks related to this - https://github.com/cefsharp/CefSharp/pull/2103#issuecomment-348061597

See the GIF in action please -

ime

IME Details: ime

angshuman-agarwal avatar Dec 27 '18 20:12 angshuman-agarwal

#2599 has now been resolved you should be able to pass in a Replacement range and I've made the keyboard handlers more extensible in https://github.com/cefsharp/CefSharp/commit/a1ccca77b872d8ee75d7f182d9de17be6576a9d5

These changes will be in version 71.0.0, hopefully this should allow you to use the IME implementation provided by @Antonyo without having to change CefSharp. If there are any other changes required then please submit a PR ASAP as I'll be releasing a 71.0.0-pre01 set of packages and I prefer not to make any breaking changes to a branch after the first -pre release.

amaitland avatar Dec 28 '18 03:12 amaitland

Thanks @amaitland Should this also be merged - https://github.com/Antonyo/CefSharp/commit/f39c4bd6d31d67c878367744ec9e45e5e9911bfa#diff-bfec65df46ec49f4ed79472147689599R1728 ?

@Antonyo - Do you also see issues with IME Candidate Window (for Japanese) showing up in Bottom Right of the OS as I described here - https://github.com/cefsharp/CefSharp/issues/1262#issuecomment-450226821

angshuman-agarwal avatar Dec 28 '18 08:12 angshuman-agarwal

@angshuman-agarwal that change could be merged though it's not entirely necessary because it's a simply check and invoke on the WPF UI Thread, I just changed the visibility for the sake of not repeating code in CefSharp project but in general if you're dealing with multi threading in your WPF project you should already have a function that does exactly the same.

Regarding the position of the candidate window, I am able to recreate it but I didn't have time to look into it, I hope this weekend I will be able to do it. As well as merging my branch with the latest changes.

Antonyo avatar Dec 28 '18 09:12 Antonyo

@Antonyo Agreed, thank you 👍

angshuman-agarwal avatar Dec 28 '18 10:12 angshuman-agarwal

@Antonyo Hi. Your solution has been very helpful. Thank you. However, if you press the space bar when entering Hangul, the last letter will be duplicated. Please check attached GIF korean_input

IME is Korean / Microsoft IME.

Thanks!

Lunaness avatar Feb 20 '19 07:02 Lunaness

@Antonyo Apologies, please ignore my previous comment. I forgot to change the StartUpUri to SimpleMainWindow.xaml. I have done that now and issue is a different one.

diff

The IME Candidate Window shows up in Bottom right. Looks related to this - #2103 (comment)

See the GIF in action please -

ime

IME Details: ime

Have fixed it here for Japanese - https://github.com/angshuman-agarwal/CEFSHAPRP_WPF/commit/03922c0810ff19822cf17d0b4b69cb9396345086

TODO: Chinese and Korean Handling.

Should be trivial as per CEF's implementation

angshuman-agarwal avatar Mar 24 '19 20:03 angshuman-agarwal

I've just merged #2757 which is a port of #2749

You can enable IME by the keyboard handler

browser.WpfKeyboardHandler = new WpfImeKeyboardHandler(browser);

There's potentially some changes that @angshuman-agarwal has been working on that need to be included, PR for those is welcome.

Anyone who has time please test and report back, if testing goes well then this will be included in the next release.

amaitland avatar May 04 '19 02:05 amaitland

https://github.com/cefsharp/CefSharp/blob/002edfb058ee5feafc705453ff7f868dd6bd2fa6/CefSharp.Wpf/Experimental/WpfIMEKeyboardHandler.cs#L86 is causing the web control to get focus during setup, which is not necessarily what one wants.

Should it not get its focus organically without having to set it explicitly? At least for a control where one can type the control should get it's focus automatically I think?

It also seems like it's a bit buggy with the placement sometimes, and sometimes doesn't open the IME window at all (there's an X in the Windows task bar). But it may also be down to how I'm using it inside other controls - just thought I'd share my experiences of testing it.

mol avatar May 17 '19 14:05 mol

@angshuman-agarwal looking at the keyboard handler it looks like you already implemented Korean and Chinese according to the CEF code you linked, yes?

I also notice that some of the code looks slightly different in CEF from your implementation. Did you make some changes to it in order to fix some issues or is it not supposed to be different? Just wondering, because while Japanese now seems to work well I'm still seeing some placement oddities with the other two languages.

mol avatar May 22 '19 14:05 mol

IME implementation in WPF which supports Japanese, Chinese, Korean languages.

@mol The changes merged in #2757 are based on #2749, which reports being testing on the languages listed above. It's possible that I made some minor mistakes when squashing it all into a single keyboard handler. The code from @angshuman-agarwal may differ greatly. If a major overhaul is needed then we'll need a consensus on the approach that should be taken.

@mol @angshuman-agarwal @a-marmer and anyone else interested I'm relying on people here to test and support this feature. I'm happy to include this as Experimental for now. I'll need a commitment from someone they are prepared to actively support this feature, debug any issues, answer questions. If nobody is prepared to put their hand up then I'll have to wait until someone does before I can remove the feature from the Experimental namespace.

amaitland avatar May 23 '19 10:05 amaitland

@amaitland, we (@a-marmer and I) are actively using this functionality in our product. We are testing it internally, and are releasing it to customers. Though only a small subset of our customers use the Windows IME, we intend to make improvements as necessary or report back if it seems to be working as-is.

chris-araman avatar May 24 '19 18:05 chris-araman

@amaitland I'm also using it in my product, or rather will be once we migrate to the new version (we have a zoom crashing issue I need to fix first). I also intend to make fixes and improvements as I find them, if I can, but can't commit to actively support it at the moment - at least as long as it's a small number of our customers using it.

mol avatar May 27 '19 21:05 mol

Hangul (Korean) letter won't "commit" to the input box after a letter has been "composed". (v79)

If you add the following code

if (languageCodeId == ImeNative.LANG_KOREAN)
{
    owner.GetBrowserHost().ImeSetComposition(text, underlines.ToArray(),
        new Range(int.MaxValue, int.MaxValue), new Range(compositionStart, compositionStart));
    owner.GetBrowserHost().ImeFinishComposingText(false);
}

just below the line

owner.GetBrowserHost().ImeCommitText(text, new Range(int.MaxValue, int.MaxValue), 0);

in the function OnImeComposition (WpfImeKeyboardHandler.cs) the problem will be solved. I tested against the CefSharp.Wpf.Example.SimpleMainWindow.xaml. I also tested with Japanese IME and Chinese IME to check whether any side effects occur. It worked as expected.

I am new to github and I don't know how to suggest/modify the relevant code directly, so I leave my suggestion here. Thank you.

billshinji avatar Feb 11 '20 04:02 billshinji

I forgot to mention that one should move these two lines to the top of the function (OnImeComposition) for referencing variables 'underline' and 'compositionStart':

var underlines = new List<CompositionUnderline>();
int compositionStart = 0;

And by the way, for those who try to use the IME support in the CefSharp.Wpf, plug WpfImeKeyboardHandler into your WPF CefSharp browser like this:

private ChromiumWebBrowser Browser; // or your <wpf:ChromiumWebBrowser /> in XAML
private Experimental.WpfImeKeyboardHandler imeKeyHandler; // it must be a permanent variable for the life time of the browser

and in one of your initialization code, add following lines:

imeKeyHandler = new Experimental.WpfImeKeyboardHandler(Browser);
Browser.WpfKeyboardHandler = imeKeyHandler;

billshinji avatar Feb 11 '20 09:02 billshinji

Changes are accepted in the form of pull requests. Search for GitHub pull request and you'll find instructions on how to create one.

amaitland avatar Feb 11 '20 09:02 amaitland

If you enter IME text in a textbox with a dark background in the wpf chromium browser using WpfImeKeyboardHandler, you may see the IME characters invisible due to the white background handling of the ImeHandler.

By changing the background color to transparent, the IME text is displayed regardless of the background color of the web page.

// Transparent SkColor value for background.
internal const uint ColorBKCOLOR = 0x00000000;

Please refer to the PR for more details. https://github.com/cefsharp/CefSharp/pull/3143

nyjin avatar Jun 07 '20 06:06 nyjin

By changing the background color to transparent, the IME text is displayed regardless of the background color of the web page.

Does anyone have an objection to the background colour changing from white to transparent? Are there any circumstances this would be a problem? Will this work on all operating systems?

Please comment if you have any objections/concerns.

amaitland avatar Jun 07 '20 06:06 amaitland

I have made a pull request #3163 based on @billshinji 's solution #3054 to fix Chinese IME problem. Anyone who cannot input Chinese into input box on v81.3.100 can test with it.

yeyezizhi avatar Jul 02 '20 01:07 yeyezizhi

I have made a pull request #3163 based on @billshinji 's solution #3054 to fix Chinese IME problem. Anyone who cannot input Chinese into input box on v81.3.100 can test with it.

image I try it with master,did'n work

neostfox avatar Jul 10 '20 08:07 neostfox

I have made a pull request #3163 based on @billshinji 's solution #3054 to fix Chinese IME problem. Anyone who cannot input Chinese into input box on v81.3.100 can test with it.

image I try it with master,did'n work

Have you set WpfKeyboardHandler ? You need to add following code to browser instance: imeKeyHandler = new Experimental.WpfImeKeyboardHandler(Browser); browser.WpfKeyboardHandler = imeKeyHandler;

yeyezizhi avatar Jul 14 '20 04:07 yeyezizhi

I have made a pull request #3163 based on @billshinji 's solution #3054 to fix Chinese IME problem. Anyone who cannot input Chinese into input box on v81.3.100 can test with it.

image I try it with master,did'n work

Have you set WpfKeyboardHandler ? You need to add following code to browser instance: imeKeyHandler = new Experimental.WpfImeKeyboardHandler(Browser); browser.WpfKeyboardHandler = imeKeyHandler;

It's work right now, Thanks very much.I fixed at ChromiumWebBrowser.cs line 711.

neostfox avatar Jul 16 '20 05:07 neostfox