Open ay2015 opened 9 years ago
https://bitbucket.org/chromiumembedded/cef/issues/1675/inline-ime-support-nstextinput-protocol-in Seems they still working on it
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
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.
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
IWpfKeyboardHandler
, a managed implementation would be preferable as it would allow more users to debug the code.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.
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.
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.
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);
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 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.
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 Details:
Replacement
range and I've made the keyboard handlers more extensible in https://github.com/cefsharp/CefSharp/commit/a1ccca77b872d8ee75d7f182d9de17be6576a9d5These 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.
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 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 Agreed, thank you 👍
@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
IME is Korean / Microsoft IME.
Thanks!
@Antonyo Apologies, please ignore my previous comment. I forgot to change the
StartUpUri
toSimpleMainWindow.xaml
. I have done that now and issue is a different one.The
IME Candidate Window
shows up in Bottom right. Looks related to this - #2103 (comment)See the GIF in action please -
IME Details:
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
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.
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.
@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.
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, 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.
@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.
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.
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;
Changes are accepted in the form of pull requests. Search for GitHub pull request and you'll find instructions on how to create one.
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
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.
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.
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.
I try it with master,did'n work
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.
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;
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.
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.
I fixed at ChromiumWebBrowser.cs line 711.
@neostfox The WpfImeKeyboardHandler
still requires more testing and is intentionally not enabled by default. Anyone wishing to enable IME
can do so by using the following.
browser.WpfKeyboardHandler = new CefSharp.Wpf.Experimental.WpfImeKeyboardHandler(browser);
Anyone using the IME
keyboard handler in WPF
please report your findings. As I don't use IME
I am relying on feedback from users that will determine when it's enabled by default.
I've been using WpfImeKeyboardHandler in my project since last February and I don't find any issues so far. Users (about 20 - 30) of my project have been using it on their work environment heavily and they also haven't reported any issues with regard to the IME to me since I applied the 'experimental' handler. I think it's safe to remove the 'experimental' tag from this feature now :-) How do you guys think?
@amaitland @billshinji When WpfImeKeyboardHandler is used, we are not able to input space with Japanese IME mode like Hiragana/Katakana. Have you observed it, or any workaround for that? To input space, we need to change the IME mode to "Alphanumeric", hit space, then come back to Hiragana/Katakana mode for typing next word.
@karthikeyancdm I noticed the issue. Entering the space will trigger conversion while a set of hiragana is being typed. But it seems that prevents from inserting the space itself otherwise. I will investigate the problem and check if there is any solution to that. (I have downloaded the master files but I am currently having trouble building it :-)
Thank you, @billshinji Please let me know the build number which has the fix for #3455, so that I can test it out.
It is merged into the master so I expect you can test it on the next release (v89) if everything goes all right. Or you can download the master code files right now and build yourself. :-)
Hi @billshinji While testing this we found few issues which are listed below, it will be very helpful for us if you could fix those issues. Would you please help to fix them? Please.
Issue 1: When Japanese IME is used, the cursor position shifts before the first character when "space" is pressed to select words from dictionary. For e.g. set the Japanese IME to "Hiragana" and input "nihongo", then press "space", please observe that cursor moves before the string "日本語", cursor is expected to be placed after the string "日本語".
Issue 2: When cursor is placed before the string "日本語", try to move the cursor by pressing "right arrow key", the cursor is not moving to right.
Issue 3: If the "password field", we expect IME to be disabled, but IME is not getting disabled. So the characters we input in the password field are not correct (i.e. Hiragana is selected in the IME), because the IME converts the password characters to Japanese scripts and those characters are visible while typing password.
Some of these IME issues are noted while using Korean IME as well. Please let me know if you need more information on this regard.
@karthikeyancdm I will look into the problems and see if I can help :-)
@billshinji Could you help with the above problems with Japanese IME? Many thanks in advance!
I have noticed the symptoms but I am in the middle of developing an important project at work. It should be done by the end of June. I hope I can spare some time before the middle of June though. NOT that I can fix those issues, :-) but I will try!
@karthikeyancdm I've been digging the issue almost for a week now but frankly I am having a hard time struggling with Windows' IME APIs (called IMM). The subject is fairly new to me so I think it's better to 'learn' some basics of the API set first ... While I am doing these crazy trial-and-error things, I hope someone who is expert of IME may help resolve this issue for good. :-) Anyway I'll let you know if I manage to resolve the issues out of pure luck ... Thank you.
I couldn't find any official documentation regarding the usage of the GCS_CURSORPOS but it seems like at least in WPF MS is ignoring that value and positioning at the end of the string if the neither the character before nor after the specified cursor position is a new character (by considering the attributes of the composition as gotten here). In the case of space the string is being replaced/changed. Technically they are setting their _caretOffset to -1 but elsewhere they are interpreting that as the end. So you could probably change where the IMEHandler gets the attributes and make a similar change?
browser.WpfKeyboardHandler = new CefSharp.Wpf.Experimental.WpfImeKeyboardHandler(browser);
Hi, I have used WpfImeKeyboardHandler in my project, I found if I invoke browser.reload(), my IME cannot switch between Chinese and English, Can you help me fix it?
browser.WpfKeyboardHandler = new CefSharp.Wpf.Experimental.WpfImeKeyboardHandler(browser);
Hi. I am a Korean user. I set the handler and it worked perfectly. Thanks for your efforts.
@nameofSEOKWONHONG Thanks for the feedback.
I was thinking we could default to the WpfImeKeyboardHandler
when IME
is detected in WPF
.
Can anyone confirm the following works? Or if someone has a better suggestion please provide a code example.
if (InputMethod.Current.ImeState == InputMethodState.On)
{
browser.WpfKeyboardHandler = new CefSharp.Wpf.Experimental.WpfImeKeyboardHandler(browser);
}
The ImeState could change while the control has focus. If it matters I use the WpfImeKeyboardHandler always - set during construction - and haven't come across any issues with using it other than bugs in the IME handling. Which reminds me I found another issue and will submit a PR for it when I have some time.
Thanks for the feedback. The intention would be to use the IME keyboard handler if appropriate for the current user (hope that makes sense)
CefSharp.WinForms.NETCore Version="102.0.100"
_webView = new ChromiumWebBrowser("www.baidu.com")
_webView.Load("www.baidu.com")
But also lose focus after minimize restore
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