Page 1 of 2

API for getting an event when to open a virtual keyboard

PostPosted: Fri Feb 22, 2019 6:32 am
by riku
I'm using CEF in a multi-user multi-touch environment where you can have multiple browsers open, and several people interacting with them at the same time. We use OSR mode and have our custom on-screen keyboard - and obviously we can have several keyboards open at the same time as well.

I would like to know when to open and close these virtual keyboard, and also what kind of keyboard to open (standard, numeric, email, decimal etc).

Previously (with CEF 2883) I did this by patching CEF and adding a new callback for this, but I used some Chromium API that is now gone, so I need to redo this for 3683. I have now test code that uses content::TextInputManager::Observer::OnUpdateTextInputStateCalled to find out when to open the keyboard, and what kind of keyboard is requested. I also added virtual void CefRenderHandler::OnVirtualKeyboardRequested(CefRefPtr<CefBrowser> browser, CefTextInputMode mode) where the text input mode is practically just ui::TextInputMode.

Does this approach make sense? Is there already some way of doing this that I just didn't find? Is CefRenderHandler the correct place to add this? I'm planning on adding this just for off-screen rendering mode, most likely it won't be so useful for windowed rendering when you most likely can just use some system virtual keyboard.

Should I just open a pull request for this? I think I can trivially add a unit test for this.

Re: API for getting an event when to open a virtual keyboard

PostPosted: Fri Feb 22, 2019 10:52 am
by magreenblatt
I wonder if it's possible to detect this using JavaScript. I would recommend looking into that before making CEF/Chromium changes.

Re: API for getting an event when to open a virtual keyboard

PostPosted: Fri Feb 22, 2019 11:20 am
by riku
You mean by injecting some JS code to all websites? That sounds somewhat dangerous operation.

This was a trivial patch to CEF: https://bitbucket.org/riku_palomaki/cef ... 8a975b93db - this basically mirrors the functionality already in RenderWidgetHostViewAura.

Re: API for getting an event when to open a virtual keyboard

PostPosted: Fri Feb 22, 2019 11:32 am
by magreenblatt
What happens if you don't implement OnUpdateTextInputStateCalled? Is no virtual keyboard displayed?

Re: API for getting an event when to open a virtual keyboard

PostPosted: Fri Feb 22, 2019 11:42 am
by riku
Not sure what you mean. OnUpdateTextInputStateCalled comes from TextInputManager::Observer. I added CefRenderWidgetHostViewOSR as a new observer to TextInputManager. If you don't implement it, there are no side effects.

Re: API for getting an event when to open a virtual keyboard

PostPosted: Fri Feb 22, 2019 11:45 am
by magreenblatt
OK, I see. What is your use case for this callback?

Re: API for getting an event when to open a virtual keyboard

PostPosted: Fri Feb 22, 2019 11:58 am
by riku
We have our custom virtual keyboard implementation in our OpenGL based application running on a huge touch-enabled video wall. Users can interact with lots of UI elements, including web browsers. All the browsers have their own virtual keyboards, but to space screen estate, they are hidden by default. When they tap on some input field on the browser, or do some other action that Chromium thinks needs text input, we spawn a new virtual keyboard nearby the user.

For instance, user goes to google.com, and OnVirtualKeyboardRequested will be called with TEXT_INPUT_MODE_DEFAULT and we will open a new keyboard. Then user writes the search query and taps on enter, and then OnVirtualKeyboardRequested will be called with TEXT_INPUT_MODE_NONE and we will hide the keyboard.

Re: API for getting an event when to open a virtual keyboard

PostPosted: Fri Feb 22, 2019 12:32 pm
by magreenblatt
What happens in a touch-enabled OSR application if you don't provide your own custom virtual keyboard implementation? Will a virtual keyboard be displayed by Chromium or the system?

Re: API for getting an event when to open a virtual keyboard

PostPosted: Fri Feb 22, 2019 2:00 pm
by riku
I don't think CEF opens any kind of virtual keyboard by default in OSR mode. RenderWidgetHostViewAura triggers the keyboard on Windows using InputMethodKeyboardController, but CefRenderWidgetHostViewOSR doesn't do anything like that. And I think that's all correct. In our case we never want to see any native UI.

Re: API for getting an event when to open a virtual keyboard

PostPosted: Fri Feb 22, 2019 2:08 pm
by magreenblatt
If I'm understanding correctly your new callback is needed for the client to display a virtual keyboard on touch event. That seems quite reasonable. Please create an issue and submit your change as a PR.