Skip to content

Commit 1037e91

Browse files
committed
Edge: Set focus after WebView2 initialization of runtime if necessary
Fixes #1640.
1 parent 2ece1af commit 1037e91

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 35 additions & 0 deletions
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,38 @@ public void completed(ProgressEvent event) {
25752578
browser2.dispose();
25762579
}
25772580

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

25792614
/* custom */
25802615
/**

0 commit comments

Comments
 (0)