IME for Mac CEF3 off screen rendering

Made a cool mod to CEF that you'd like to share with others? Discuss CEF modifications here, and view modifications that others have made.

IME for Mac CEF3 off screen rendering

Postby mihait » Thu Feb 21, 2013 11:02 am

After applying the CEF3 mac off screen rendering patch, I've noticed IME input is not available.
After some research, I've found a few possible ways of adding this feature which I'd like to discuss before jumping into an implementation.

In general, enabling IME for Mac implies having a NSView in the responder hierarchy that conforms to the NSTextInputClient protocol. For example, IME is enabled on both
Chromium and CEF3 on screen rendering through a NSView owned by the RenderWidgetHostViewMac class called RenderWidgetHostViewCocoa which implements the NSTextInputClient protocol.

In other words, for enabling IME, we have to port the RenderWidgetHostViewCocoa implementation in one of the views included in the off screen rendering responder chain.
After doing some investigation, these are the options I've found:

The first option is to add another NSView in libcef, owned by the CefRenderWidgetHostViewOSR class, which would implement the NSTextInputClient protocol.
A major advantage is the fact that any client application will have IME enabled without any additional development effort. Unfortunately, this solution implies adding a NSView in an off screen rendering model, which perhaps isn't such a good idea.

Another potential solution implies implementing the NSTextInputClient protocol in CefClient, in the OSRTest_mac view. This comes with the advantage of not adding another NSView in the off screen rendering model, however, it implies that every embedding application should implement this protocol and copy most of the code in the CefClient view. Also, another problem consists of the API's that the content module should expose for compositing and editing text, API's which should be available to the NSTextInputClient protocol methods.

The final solution I've found is to implement the NSTextInputClient corresponding methods in CefRenderWidgetHostViewOSR as C++ methods. Then, each embedding application, including CefClient would add the protocol methods in the NSView used for displaying the rendered content and call the corresponding CefRenderWidgetHostViewOSR methods. For example, in the NSView - (BOOL)hasMarkedText selector, the embedder would call the bool CefRenderWidgetHostViewOSR::hasMarkedText method. This method has the advantage of not exposing any extra content methods, however, it still implies that the embedder should do some work for enabling IME.

I probably think the third option is the best we have considering the circumstances, but I'd like your opinion on this matter, perhaps we might find a more suitable way of adding this feature.
mihait
Newbie
 
Posts: 8
Joined: Thu Feb 21, 2013 8:37 am

Re: IME for Mac CEF3 off screen rendering

Postby magreenblatt » Fri Feb 22, 2013 11:10 am

I think the final solution is a good place to start. We might also want to put these methods in a new interface (CefTextInputClient?) retrievable via CefBrowserHost instead of hanging them on CefBrowserHost directly.
magreenblatt
Site Admin
 
Posts: 9838
Joined: Fri May 29, 2009 6:57 pm

Re: IME for Mac CEF3 off screen rendering

Postby mihait » Wed Feb 27, 2013 1:49 am

Apparently, there's another, better approach on adding IME support: Since the 10.6 sdk, each NSView can hold a NSTextInputContext (http://developer.apple.com/library/mac/ ... rence.html) object. This class can use a remote NSTextInputClient implementation which is not tied to the NSView.

In other words, we could implemement and expose in libcef something like TextInputClientOSRMac : id <NSTextInputClient>.
From this point, an embedder who wants IME enabled should:
* create a NSTextInputContext object and initialize it with TextInputClientOSRMac, via the - (id)initWithClient:(id <NSTextInputClient>)theClient method.
* implement the the NSView - (NSTextInputContext *)inputContext method to return the NSTextInputContext mentioned above
* Handle keyEvents in a way similar to this:
[[self inputContext] handleEvent];

I've tested this approach in a minimal application and IME works just fine.
I'll start the libcef id <NSTextInputClient> implementation using this approach, as it's a lot cleaner than any of the previous solutions.
Last edited by mihait on Thu Feb 28, 2013 4:17 am, edited 1 time in total.
mihait
Newbie
 
Posts: 8
Joined: Thu Feb 21, 2013 8:37 am

Re: IME for Mac CEF3 off screen rendering

Postby magreenblatt » Wed Feb 27, 2013 10:19 am

Sounds good.
magreenblatt
Site Admin
 
Posts: 9838
Joined: Fri May 29, 2009 6:57 pm

Re: IME for Mac CEF3 off screen rendering

Postby mihait » Tue Mar 12, 2013 2:27 pm

I've just finished this feature, I've been able to use the NSTextInputContext as described.
After OSR gets pushed on Mac, I will create an issue for this, perform the necessary cleanup and attach the patch.
mihait
Newbie
 
Posts: 8
Joined: Thu Feb 21, 2013 8:37 am


Return to Modifications Forum

Who is online

Users browsing this forum: No registered users and 2 guests