Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public WebViewEnvironment(ICoreWebView2Environment environment) {
static boolean inCallback;
boolean inNewWindow;
HashMap<Long, LocationEvent> navigations = new HashMap<>();
private boolean ignoreFocus;
private boolean ignoreGotFocus;
private boolean ignoreFocusIn;
private String lastCustomText;

private static record CursorPosition(Point location, boolean isInsideBrowser) {};
Expand Down Expand Up @@ -829,8 +830,17 @@ void browserDispose(Event event) {
}

void browserFocusIn(Event event) {
if (ignoreFocus) return;
if (ignoreFocusIn) return;
// TODO: directional traversals

// https://github.com/eclipse-platform/eclipse.platform.swt/issues/1848
// When we call ICoreWebView2Controller.MoveFocus(int) here,
// WebView2 will call us back in handleGotFocus() asynchronously.
// We need to ignore that next event, as in the meantime the user might
// have moved focus to some other control and reacting on that event
// would bring us back to the Browser.
ignoreGotFocus = true;

controller.MoveFocus(COM.COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC);
}

Expand Down Expand Up @@ -1350,16 +1360,21 @@ int handleNewWindowRequested(long pView, long pArgs) {
}

int handleGotFocus(long pView, long pArg) {
if (ignoreGotFocus) {
ignoreGotFocus = false;
return COM.S_OK;
}
// https://github.com/eclipse-platform/eclipse.platform.swt/issues/1139
// browser.forceFocus() does not result in
// Shell#setActiveControl(Control)
// being called and therefore no SWT.FocusIn event being dispatched,
// causing active part, etc. not to be updated correctly.
// The solution is to explicitly send a WM_SETFOCUS
// to the browser, and, while doing so, ignoring any recursive
// calls in #browserFocusIn(Event).
ignoreFocus = true;
ignoreFocusIn = true;
OS.SendMessage (browser.handle, OS.WM_SETFOCUS, 0, 0);
ignoreFocus = false;
ignoreFocusIn = false;
return COM.S_OK;
}

Expand Down
Loading