Skip to content

Commit 442f217

Browse files
committed
Edge: Set focus after WebView2 initialization of runtime if necessary
Fixes eclipse-platform#1640.
1 parent f8cbe80 commit 442f217

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,12 @@ void setupBrowser(int hr, long pv) {
695695
// initialized, nothing is drawn on the shell. We need browserResize to force
696696
// the shell to draw itself again.
697697
browserResize(new Event());
698+
699+
// Check whether the browser was made the focus control while we were
700+
// initializing the runtime and apply it accordingly.
701+
if (browser.isFocusControl()) {
702+
browserFocusIn(new Event());
703+
}
698704
}
699705

700706
void browserDispose(Event event) {

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java

+38
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,13 @@
7373
import org.eclipse.swt.browser.VisibilityWindowAdapter;
7474
import org.eclipse.swt.browser.VisibilityWindowListener;
7575
import org.eclipse.swt.browser.WindowEvent;
76+
import org.eclipse.swt.events.FocusListener;
7677
import org.eclipse.swt.graphics.Point;
7778
import org.eclipse.swt.layout.FillLayout;
7879
import org.eclipse.swt.widgets.Display;
80+
import org.eclipse.swt.widgets.Event;
7981
import org.eclipse.swt.widgets.Shell;
82+
import org.eclipse.swt.widgets.Text;
8083
import org.junit.Before;
8184
import org.junit.FixMethodOrder;
8285
import org.junit.Rule;
@@ -2575,6 +2578,41 @@ public void completed(ProgressEvent event) {
25752578
browser2.dispose();
25762579
}
25772580

2581+
@Test
2582+
public void test_TabTraversalOutOfBrowser() {
2583+
assumeFalse("Not currently working on macOS, see https://github.com/eclipse-platform/eclipse.platform.swt/issues/1644", SwtTestUtil.isCocoa);
2584+
assumeFalse("Not currently working on Linux, see https://github.com/eclipse-platform/eclipse.platform.swt/issues/1644", SwtTestUtil.isGTK);
2585+
2586+
Text text = new Text(shell, SWT.NONE);
2587+
2588+
// open and immediately set focus. this test therefore also covers
2589+
// https://github.com/eclipse-platform/eclipse.platform.swt/issues/1640
2590+
shell.open();
2591+
browser.forceFocus();
2592+
2593+
// wait for browser to fully load
2594+
AtomicBoolean changedFired = new AtomicBoolean(false);
2595+
browser.addLocationListener(changedAdapter(e -> changedFired.set(true)));
2596+
browser.setText("Hello world");
2597+
assertTrue("LocationListener.changed() event was never fired", waitForPassCondition(changedFired::get));
2598+
2599+
// browser should have focus
2600+
assertTrue(browser.isFocusControl());
2601+
assertFalse(text.isFocusControl());
2602+
2603+
// send tab key via low-level event -> focus should move to Text control
2604+
AtomicBoolean textGainedFocus = new AtomicBoolean(false);
2605+
text.addFocusListener(FocusListener.focusGainedAdapter(e -> textGainedFocus.set(true)));
2606+
Event event = new Event();
2607+
event.type = SWT.KeyDown;
2608+
event.keyCode = SWT.TAB;
2609+
Display.getDefault().post(event);
2610+
2611+
// focus should move to Text
2612+
assertTrue("Text did not gain focus", waitForPassCondition(textGainedFocus::get));
2613+
assertFalse(browser.isFocusControl());
2614+
assertTrue(text.isFocusControl());
2615+
}
25782616

25792617
/* custom */
25802618
/**

0 commit comments

Comments
 (0)