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

Difference between Mac and Windows in how focus is handled #320

Open
magreenblatt opened this issue Jan 22, 2019 · 5 comments
Open

Difference between Mac and Windows in how focus is handled #320

magreenblatt opened this issue Jan 22, 2019 · 5 comments
Labels
bug Bug report

Comments

@magreenblatt
Copy link
Collaborator

Original report by Jonathan Kwang (Bitbucket: jonathankwangMW).


There seems to be a difference with how jcef handles mouse clicks between the Windows and Mac environments. The issue is specifically on a Mac where if there is a mouse click that occurs outside of the browser window, the browser loses focus even if focus was not transferred to any other element in the UI.

This can be reproduced in the test app by adding a unfocusable JLabel to the content pane of MainFrame.java in place of the ControlPanel of the detailed app. (I've attached a modified MainFrame.java file which does this) When running the app, on Windows clicking on the JLabel will keep focus in the browser window (i.e you can still type into the google search box) and on a Mac clicking on the JLabel causes the browser to lose focus and you need to manually click into the browser window to type into the google search box.

@magreenblatt
Copy link
Collaborator Author

Mouse clicks outside of the browser are handled somewhat differently on macOS and Windows. On macOS the events are sent to the superview via NSApplication.load in native code. On Windows the events are passed to onMouseEvent in Java code. Perhaps we should use the Java code path on both platforms.

@magreenblatt
Copy link
Collaborator Author

The attached mac_mouse.patch converts util_mac.mm to use the same mouse handling code path as Windows (via the onMouseEvent method in Java). However, that doesn't resolve the reported focus issue.

@magreenblatt
Copy link
Collaborator Author

  • set attachment to "mac_mouse.patch"

@magreenblatt
Copy link
Collaborator Author

Below is the callstack for [RenderWidgetHostViewCocoa resignFirstResponder] when clicking outside of the browser window. It looks AWTWindow_Normal in the JVM implementation is becoming first responder, which removes focus from the browser window. I'm not sure what, if anything, we could do to fix this from JCEF code.

* thread #1, name = 'CrBrowserMain', queue = 'com.apple.main-thread', stop reason = breakpoint 2.1 3.1 4.1 5.1 6.1
  * frame #0: 0x0000000127a4997d Chromium Embedded Framework`::-[RenderWidgetHostViewCocoa resignFirstResponder](self=0x0000000165a21f70, _cmd="resignFirstResponder") at render_widget_host_view_cocoa.mm:1286 [opt]
    frame #1: 0x00007fff468a2c9f AppKit`-[NSWindow _realMakeFirstResponder:] + 258
    frame #2: 0x00007fff47129987 AppKit`-[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 4893
    frame #3: 0x00007fff471269c4 AppKit`-[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359
    frame #4: 0x00007fff47125c70 AppKit`-[NSWindow(NSEventRouting) sendEvent:] + 497
    frame #5: 0x0000000121ba900b libawt_lwawt.dylib`-[AWTWindow_Normal sendEvent:] + 86
    frame #6: 0x00007fff46f87236 AppKit`-[NSApplication(NSEvent) sendEvent:] + 2462
    frame #7: 0x0000000121c5c2aa libosxapp.dylib`-[NSApplicationAWT sendEvent:] + 378
    frame #8: 0x00007fff467e78b5 AppKit`-[NSApplication run] + 812
    frame #9: 0x0000000121c5bf72 libosxapp.dylib`+[NSApplicationAWT runAWTLoopWithApp:] + 156
    frame #10: 0x0000000121be711f libawt_lwawt.dylib`-[AWTStarter starter:] + 905
    frame #11: 0x00007fff4b38e2b5 Foundation`__NSThreadPerformPerform + 334
    frame #12: 0x00007fff49275a61 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    frame #13: 0x00007fff4932f47c CoreFoundation`__CFRunLoopDoSource0 + 108
    frame #14: 0x00007fff492584c0 CoreFoundation`__CFRunLoopDoSources0 + 208
    frame #15: 0x00007fff4925793d CoreFoundation`__CFRunLoopRun + 1293
    frame #16: 0x00007fff492571a3 CoreFoundation`CFRunLoopRunSpecific + 483
    frame #17: 0x00000001000d38fe libjli.dylib`CreateExecutionEnvironment + 871
    frame #18: 0x00000001000cf508 libjli.dylib`JLI_Launch + 1952
    frame #19: 0x00000001000040d3 JavaAppLauncher`launch + 9859
    frame #20: 0x0000000100001908 JavaAppLauncher`main + 152
    frame #21: 0x0000000100001864 JavaAppLauncher`start + 52

@magreenblatt
Copy link
Collaborator Author

Original comment by Klemen Pevec (Bitbucket: Klemen Pevec).


I am not sure if this is related, but I have a case where I put multiple CefBrowser UI components in Swing Tabbed Pane and only the last CefBrowser added to the tabs responds to mouse events.

This only happens on Mac, Windows is unaffected by this. JCEF is not running in OSR mode.

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

No branches or pull requests

1 participant