Description
Original report by Matt Lilley (Bitbucket: Matt Lilley).
What steps will reproduce the problem?
Simple test case: Creates a JFrame with a CEF component and a Swing component. Once the CEF component has loaded, clicking into the Swing component and typing has no effect. If a textarea is focused in the CEF component, the keystrokes go to CEF and appear in the textarea even though the Swing component is focused and has a flashing caret.
#!Java
import javax.swing.*;
import org.cef.*;
import java.awt.*;
public class XX extends JFrame
{
static CefApp cefApp;
public static void main(String[] args) throws Exception
{
CefApp.startup();
CefSettings settings = new CefSettings();
settings.windowless_rendering_enabled = false;
cefApp = CefApp.getInstance(settings);
new XX();
}
public XX() throws Exception
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(new JTextField(), BorderLayout.NORTH);
getContentPane().add(cefApp.createClient().createBrowser("http://www.google.com", false, true).getUIComponent(), BorderLayout.CENTER);
setSize(1024, 768);
setVisible(true);
}
}
What is the expected output? What do you see instead?
I expect that if a Swing component has focus and I type characters that they appear in the Swing component, not in the (unfocused) CEF component.
What version of the product are you using? On what operating system?
I'm using a build using the source code as of 2018-12-06 (ie commit d64cd6c266d5a (bb)). The problem reproduces on Windows 7 and Windows 10. The issue does not occur on macOS High Sierra, so this looks like a Windows-specific problem. I've also tried it with a few older versions back to mid 2018 with no change in the symptoms
Does the problem reproduce with the JCEF simple or detailed sample application at the same version? How about with a newer or older version?
Yes - the problem seems to reproduce on the JCEF simple version. Running the
#!sh
run win64 Release simple
and then focusing the Google search field and typing 'foo', then selecting the URL bar at the top and typing 'bar' results in 'foobar' appearing in the Google search field, even though the caret is showing and blinking in the URL bar
Does the problem reproduce with the cefclient or cefsimple application at the same version? How about with a newer or older version?
This isn't really relevant - the problem relates to embedding CEF into Java explicitly.
Additional information:
I've read a few bug reports about focus and JCEF. Many of them relate to the opposite problem (that Swing components get the focus and that the CEF component won't receive it). Others suggested adding a CefFocusHandler to the client and overriding onSetFocus to return true. This doesn't solve the issue. I've also tried commenting out the calls to FocusParent in the native code (after reading issue 297), but the problem persists.
My actual use case is quite different to the example - I have a JTabbedPane where one tab is a JPanel containing a CEF component, and the other tabs contain various other components. The problem I'm facing in reality is that once I load the CEF component, switching tabs to modify the other fields becomes impossible. The example was just a much simpler demonstration of the issue.
Am I doing something obviously wrong? Is there something wrong with my build? Or is this an actual bug that others are seeing too?