Skip to content

Commit 7900413

Browse files
committed
Edge: Fix focus handling to emit SWT.FocusIn events
Follow-up on #1187. Fixes #1139. Fixes #1417.
1 parent d9159c0 commit 7900413

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public WebViewEnvironment(ICoreWebView2Environment environment) {
6363
static boolean inCallback;
6464
boolean inNewWindow;
6565
HashMap<Long, LocationEvent> navigations = new HashMap<>();
66+
private boolean ignoreFocus;
6667

6768
static {
6869
NativeClearSessions = () -> {
@@ -480,6 +481,7 @@ void browserDispose(Event event) {
480481
}
481482

482483
void browserFocusIn(Event event) {
484+
if (ignoreFocus) return;
483485
// TODO: directional traversals
484486
controller.MoveFocus(COM.COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC);
485487
}
@@ -793,7 +795,16 @@ int handleNewWindowRequested(long pView, long pArgs) {
793795
}
794796

795797
int handleGotFocus(long pView, long pArg) {
796-
this.browser.forceFocus();
798+
// browser.forceFocus() does not result in
799+
// Shell#setActiveControl(Control)
800+
// being called and therefore no SWT.FocusIn event being dispatched,
801+
// causing active part, etc. not to be updated correctly.
802+
// The solution is to explicitly send a WM_SETFOCUS
803+
// to the browser, and, while doing so, ignoring any recursive
804+
// calls in #browserFocusIn(Event).
805+
ignoreFocus = true;
806+
OS.SendMessage (browser.handle, OS.WM_SETFOCUS, 0, 0);
807+
ignoreFocus = false;
797808
return COM.S_OK;
798809
}
799810

0 commit comments

Comments
 (0)