Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard input doesn't work when Browser is hosted in WPF Popup. #1590

Closed
SiddharthMishraPersonal opened this issue Feb 12, 2016 · 25 comments
Closed
Labels

Comments

@SiddharthMishraPersonal

We have hosted CefSharp (version: 47.0.2.0) browser in a WPF Popup control. Once our webpage loads and we try to enter something in textbox (html input tag), which doesn't work.

Please find dummy project example to reproduce the issue. Please use latest CefSharp binaries. (I removed "bin/debug" folder as it was getting too big to attach.
For this example we have used google search page to reproduce the issue.

Reproducing steps:

  1. Run the application.
  2. Click on on “Open Popup” button.
  3. Wait till Google.com opens.
  4. Try to type and search keyword provided by Google.

**Expected: _User should be able to enter search keywords.
_Actual:
Cannot type single character.

Please provide me any inputs on this.

@amaitland amaitland added the wpf label Feb 12, 2016
@amaitland
Copy link
Member

I have removed the link to your zip, as per Contributing.md no binaries, thanks!

https://github.com/cefsharp/CefSharp/blob/master/CONTRIBUTING.md#help-us-help-you

When posting code, either fork the MinimalExample and push to GitHub, provide a complete Gist or anther open code sharing option.

https://github.com/cefsharp/CefSharp.MinimalExample

You'll have to debug this one yourself if it's important to you. The low level source hook for the keyboard handling mustn't be called correctly when hosted in a Popup.

I'd suggest you use a Window instead.

@rlmcneary2
Copy link
Contributor

We use an onscreen keyboard and I found there were problems with focus and input like you have described (we use winforms but I think the same problem could occur in wpf too). If the browser is hosted in another control - say a Panel - focusing the panel won't necessarily focus the browser. I found that when I focused the hosting control I also needed to call the Focus() method on the CefSharp browser. After your secondary window finishes loading try focusing the browser control.

@SiddharthMishraPersonal
Copy link
Author

I moved my code at https://github.com/SiddharthMishraPersonal/CefSharpWithPopup

In our application we are using Telerik RadPane Control. We raised a ticket to Telerik for the same issue and found that the AutoHide and AutoShow feature of RadPane is not only but the Popup control. Hence, we tried to test it with simple Popup control and it is reproducible.

I have downloaded latest CefSharp code and built it. Used the build binaries and tried to debug the issue. While debugging we found that that event "PresentationSourceChangedHandler()" is not getting fired, if we are using Popup control to host Cef browser. The method is at line no 846 in file ChromiumWebBrowser.cs under CefSharp.Wpf project.

As per current situation, we cannot get rid of RadPane, so, we have to fix Popup related issue to move on.
Any kind of pointer/solution in this regard would be highly appreciated.
Thanks!

@amaitland
Copy link
Member

amaitland commented Feb 12, 2016

I moved my code at https://github.com/SiddharthMishraPersonal/CefSharpWithPopup

Thanks 👍 Probably best to remove the binaries though 😄

I have downloaded latest CefSharp code and built it. Used the build binaries and tried to debug the issue. While debugging we found that that event "PresentationSourceChangedHandler()" is not getting fired, if we are using Popup control to host Cef browser.

Yep, that's pretty much what I was expecting.

The method is at line no 846 in file ChromiumWebBrowser.cs under CefSharp.Wpf project.

Linking to the file directly e.g. https://github.com/cefsharp/CefSharp/blob/cefsharp/49/CefSharp.Wpf/ChromiumWebBrowser.cs#L844 is much easier for others to follow then just providing a link number.

Any kind of pointer/solution in this regard would be highly appreciated.

Two options that I can think of

  • Rewrite the keyboard handling to use OnPreviewKeyUp/Down (I've tried, never got a full working implementation happening).
  • Add your own source hook at the relevant point.

https://msdn.microsoft.com/en-us/library/system.windows.presentationsource.fromvisual%28v=vs.110%29.aspx
http://stackoverflow.com/questions/11204251/presentationsource-fromvisualthis-returns-null-value-in-wpf

Next version will have IBrowserHost.SendKeyEvent that takes in the three message params.
https://github.com/cefsharp/CefSharp/blob/master/CefSharp/IBrowserHost.cs#L150

In the current version there is only a version that wraps the underlying CEF implementation exposed, doesn't parse the raw message.

https://github.com/cefsharp/CefSharp/blob/cefsharp/47/CefSharp/IBrowserHost.cs#L130

@SiddharthMishraPersonal
Copy link
Author

For 41.0.0 version I found the resolution of this issue here.
https://github.com/cefsharp/CefSharp/blob/cefsharp/41/CefSharp.Wpf/ChromiumWebBrowser.cs#L1484

But, we found that the method is not available in later versions of CefSharp.Wpf.
Do we have any alternate method for that?

@amaitland
Copy link
Member

Next version will have IBrowserHost.SendKeyEvent that takes in the three message params.
https://github.com/cefsharp/CefSharp/blob/master/CefSharp/IBrowserHost.cs#L150

As I've already said, the next version will have that option. For now you may need to make some changes and build the source yourself.

@SiddharthMishraPersonal
Copy link
Author

I downloaded latest 47.0.3.0 from NuGet but the method SendKey() is missing. Am I missing anything or it is going to release in another version?

@amaitland
Copy link
Member

Am I missing anything or it is going to release in another version?

49.0.0

@amaitland
Copy link
Member

Thinking about this again, you can use the current release version as ChromiumWebBrowser.SourceHook is protected, so just subclass ChromiumWebBrowser and attach the hook.

Would look something like this:

var window = Window.GetWindow(this);

HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(window).Handle);
source.AddHook(new HwndSourceHook(SourceHook));

@amaitland
Copy link
Member

Or something like

HwndSource source = (HwndSource)HwndSource.FromVisual(this);
source.AddHook(new HwndSourceHook(SourceHook));

@amaitland
Copy link
Member

49.0.0-pre01 is out

@nagesh2501
Copy link

Hi @amaitland

I am facing the same issue. Need your help on this.
I went through this thread and tried these options but it did not click for me.
I am using 49.0.1.0 version and I couldnt find SendKey() method.

@amaitland
Copy link
Member

amaitland commented Jun 16, 2016

Need your help on this.

A simple Please would be nice

I am using 49.0.1.0 version and I couldnt find SendKey() method.

Read my comments again, it's not called SendKey

@nagesh2501
Copy link

@amaitland

Hey I am sorry to keep bothering you on this man.
I am in a new project and my very first assignment requires me to integrate CEFSharp into the existing project on which I am struggling at the moment.

I have been working on this issue for last two days and tried going through thread and the other one which also has similar issue but I couldnt solve. So finally I have come to you.

Can you please help me get over this hurdle?

I am not sure if I am seraching it correctly. It should be WebBroswer.SendKey() right?
I am not able to find this method.

@amaitland
Copy link
Member

Can you please help me get over this hurdle?

It's 2am and I need to sleep. All the relevant information is above.

It should be WebBroswer.SendKey() right?

Incorrect. Read over my notes carefully.

@nagesh2501
Copy link

I guess i got it. IbrowserHost.SendKeyEvent.

Thanks alot...

@nagesh2501
Copy link

Hey when you see my message tomorrow can you please give a little advice on when should I call IBrowserHost.SendKeyEvent().

I tried calling this inside OnGotKeyboardFocus(). But it did not work.

@amaitland
Copy link
Member

Hey when you see my message tomorrow can you please give a little advice on when should I call IBrowserHost.SendKeyEvent().

Use the other suggestion, sub class and attach the SourceHook. If you need more info on source hooks then look up MSDN.

I tried calling this inside OnGotKeyboardFocus(). But it did not work.

Not sure how keyboard focus relates to a key press?

@amaitland
Copy link
Member

Hey when you see my message tomorrow can you please give a little advice on when should I call

Also I don't have time to write this for you, I'm confident there is enough information provided that you can figure this out on your own.

@nagesh2501
Copy link

@amaitland

Hey thank you for your response.

I just found a fix for this.

Actually am using the browser control inside a grid which is enclosed within a scrollViewer control.
so when debugging the code, I placed break points in onLostFocus method and found the e.nextFocus was pointing to ScrollViewer control.

So what i did is, I jus made focussable for the ScrollViewer to false and it started working. I am able to enter values in to the textboxes within browser.

Although am not sure why the focus is automatically moving to scrollviewer when am trying to focus within the browser.

@amaitland
Copy link
Member

Actually am using the browser control inside a grid which is enclosed within a scrollViewer control.

Did you search the issue tracker??? An issue already exists for that problem see #1002

@nagesh2501
Copy link

@amaitland

No I did not see that thread before. thing is I just explored the application and found that they are having a generic control which has a scrollviewer and all other xamls are enclosed within that.

I just kind of guessed that setting focussable false for scroll might fix and it worked. anyway now i found other workarounds in below thread.

https://ghttps://groups.google.com/forum/#!topic/cefsharp/KgUoEMHIfxMroups.google.com/forum/#!topic/cefsharp/KgUoEMHIfxM

Thanks so much!!! really appreciate your effort and response.

@amaitland
Copy link
Member

https://ghttps://groups.google.com/forum/#!topic/cefsharp/KgUoEMHIfxMroups.google.com/forum/#!topic/cefsharp/KgUoEMHIfxM

Your link is malformed.

Thanks so much!!! really appreciate your effort and response.

I'll be honest, interacting with you is a very frustrating experience. I feel that you've unnecessarily wasted quite a bit of my time in the last week. This is my personal time, nobody is paying me to answer questions! If you continue to ask questions without demonstrating a reasonable amount of effort, I will ignore you, just so you know! Research before posting 👍

@nagesh2501
Copy link

Dude.. I know you got frustrated. I researched as much as I could in the last 2 days. when I do not know the root cause of the issue It is really difficult to look for a specific solution.

In this case, I didnt know there is a scroll viewer control in the application and its impact on webbrowser.

I understand your point, spending your free time on this. I really do not have words.
Thank you man. I am completely new to this next time I will try to research more.

And sorry again for bothering you!!

@amaitland
Copy link
Member

In this case, I didnt know there is a scroll viewer control in the application and its impact on webbrowser.

ScrollViewer is besides the point, this issue quite clearly lists the problem as being when hosted in a Popup........

And sorry again for bothering you!!

I've though about this more, and before I'll help you again you'd need to contribute something to the project, implement a feature request, improve the xml doco, contribute to the wiki, answer some support questions (not a monetary contribution). If that doesn't work for you then there are other CEF base wrappers out there. I'll be making the same demands of others that negatively contribute to the project, so it's not personal!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants