Skip to content

Commit

Permalink
Edge: Set focus after WebView2 initialization of runtime if necessary
Browse files Browse the repository at this point in the history
Fixes #1640.
  • Loading branch information
sratz committed Dec 10, 2024
1 parent 2ece1af commit 335108e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,12 @@ void setupBrowser(int hr, long pv) {
// initialized, nothing is drawn on the shell. We need browserResize to force
// the shell to draw itself again.
browserResize(new Event());

// Check whether the browser was made the focus control while we were
// initializing the runtime and apply it accordingly.
if (browser.isFocusControl()) {
browserFocusIn(new Event());
}
}

void browserDispose(Event event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@
import org.eclipse.swt.browser.VisibilityWindowAdapter;
import org.eclipse.swt.browser.VisibilityWindowListener;
import org.eclipse.swt.browser.WindowEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Rule;
Expand Down Expand Up @@ -2575,6 +2578,41 @@ public void completed(ProgressEvent event) {
browser2.dispose();
}

@Test
public void test_TabTraversalOutOfBrowser() {
assumeFalse("Not currently working on macOS, see https://github.com/eclipse-platform/eclipse.platform.swt/issues/1644", SwtTestUtil.isCocoa);
assumeFalse("Not currently working on Linux, see https://github.com/eclipse-platform/eclipse.platform.swt/issues/1644", SwtTestUtil.isGTK);

Text text = new Text(shell, SWT.NONE);

// open and immediately set focus. this test therefore also covers
// https://github.com/eclipse-platform/eclipse.platform.swt/issues/1640
shell.open();
browser.forceFocus();

// wait for browser to fully load
AtomicBoolean changedFired = new AtomicBoolean(false);
browser.addLocationListener(changedAdapter(e -> changedFired.set(true)));
browser.setText("Hello world");
assertTrue("LocationListener.changed() event was never fired", waitForPassCondition(changedFired::get));

// browser should have focus
assertTrue(browser.isFocusControl());
assertFalse(text.isFocusControl());

// send tab key via low-level event -> focus should move to Text control
AtomicBoolean textGainedFocus = new AtomicBoolean(false);
text.addFocusListener(FocusListener.focusGainedAdapter(e -> textGainedFocus.set(true)));
Event event = new Event();
event.type = SWT.KeyDown;
event.keyCode = SWT.TAB;
Display.getDefault().post(event);

// focus should move to Text
assertTrue("Text did not gain focus", waitForPassCondition(textGainedFocus::get));
assertFalse(browser.isFocusControl());
assertTrue(text.isFocusControl());
}

/* custom */
/**
Expand Down

0 comments on commit 335108e

Please sign in to comment.