Skip to content

Edge: Focus is lost when Browser is made the focus control immediately after construction #1640

@sratz

Description

@sratz

Describe the bug
When setting the focus to a Browser based on Edge, before the underlying WebView2 runtime is fully initialized, the SWT layer thinks the browser is the focus control, but WebView2 does not.

As a result, e.g., tabbing is broken.

To Reproduce

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class FocusProblem {

	public static void main(String[] args) {
		Shell shell = new Shell(Display.getDefault());
		shell.setLayout(new GridLayout(1, true));
		Browser browser = new Browser(shell, SWT.EDGE);
		GridDataFactory.fillDefaults().grab(true, false).applyTo(browser);
		browser.setText("browser");
		Button button = new Button(shell, SWT.PUSH);
		button.setText("button - try to reach me via keyboard!");
		Text text = new Text(shell, SWT.NONE);
		text.setText("text - try to reach me via keyboard!");
		GridDataFactory.fillDefaults().grab(true, false).applyTo(text);
		shell.open();
		browser.forceFocus();
		while (!shell.isDisposed()) {
			if (!shell.getDisplay().readAndDispatch()) {
				shell.getDisplay().sleep();
			}
		}
	}

}

Pressing TAB / Shift-TAB to reach other controls is broken.

Expected behavior
Pressing TAB / Shift-TAB should allow navigation to other controls.

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS

Version since
Eclipse 4.33

Workaround (or) Additional context
WebView2 runtime is initialized with delay.
Once initialized, we should consistently apply any focus request we got to the SWT control during that initialization phase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    edgeEdge Browser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions