Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Parent container of SWT Browser on XULRunner 10.0.2 is handling Enter and Escape key presses(For example, when I press the enter key in a browser page text field, the key press goes to my parent dialog, resulting in Dialog::okPressed())
Parent container of SWT Browser on XULRunner 10.0.2 is handling Enter and Escape key presses [message #946506] Tue, 16 October 2012 08:51 Go to next message
Stella Lok is currently offline Stella LokFriend
Messages: 10
Registered: September 2012
Junior Member
Hi,

I discovered a major difference in behaviour between using the SWT Browser with XULRunner 10.0.2 and XULRunner 3.6.x, encountered on Windows XP 32-bit.

When I use an SWT Browser widget in a Dialog, with XULRunner 10.0.2, the "Enter" and "Escape" key press events are still handled by the parent container (i.e. the Dialog), even though the focus is on the SWT Browser widget. For example, when I press "Enter" in a browser page text field, the parent container will handle it, resulting in Dialog::okPressed() and subsequently Dialog::close(). Likewise, when I press the "Escape" key in a browser page text field, Dialog::close() will be triggered.

Is this a bug? I do not encounter this in XULRunner 3.6.x, nor in an SWT Browser using Internet Explorer.

Here is my test code, that can reproduce this behaviour when run in XULRunner 10.0.2, when "Enter" is pressed in the browser page text field:


import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class TestDialog extends Dialog {

	@Override
	public boolean close() {
		System.out.println("close()");
		return super.close();
	}

	@Override
	protected void okPressed() {
		System.out.println("ok pressed");
		super.okPressed();
	}

	public static void main(String args[]) {
		Display display = Display.getDefault();
		Shell shell = new Shell();
		TestDialog d = new TestDialog(shell);
		d.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();

	}

	public TestDialog(Shell parentShell) {
		super(parentShell);
	}

	@Override
	protected Control createDialogArea(Composite parent) {
		Display.DEBUG = true;
		Composite container = (Composite) super.createDialogArea(parent);
		container.setLayout(new GridLayout(1, false));

		Composite composite = new Composite(container, SWT.NONE);
		composite.setLayout(new GridLayout(1, false));
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1,
				1));

		Browser mozBrowser = new Browser(composite, SWT.MOZILLA);
		mozBrowser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
				1, 1));
		mozBrowser.setUrl("google.com");
		return container;
	}

	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
				true);
		createButton(parent, IDialogConstants.CANCEL_ID,
				IDialogConstants.CANCEL_LABEL, false);
	}

	@Override
	protected Point getInitialSize() {
		return new Point(801, 582);
	}
}
Re: Parent container of SWT Browser on XULRunner 10.0.2 is handling Enter and Escape key presses [message #950325 is a reply to message #946506] Fri, 19 October 2012 20:25 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
This looks like a bug introduced by a change in XULRunner 10. I've
logged https://bugs.eclipse.org/bugs/show_bug.cgi?id=392488 .

Grant


On 10/16/2012 4:51 AM, Stella Lok wrote:
> Hi,
>
> I discovered a major difference in behaviour between using the SWT
> Browser with XULRunner 10.0.2 and XULRunner 3.6.x, encountered on
> Windows XP 32-bit.
>
> When I use an SWT Browser widget in a Dialog, with XULRunner 10.0.2, the
> "Enter" and "Escape" key press events are still handled by the parent
> container (i.e. the Dialog), even though the focus is on the SWT Browser
> widget. For example, when I press "Enter" in a browser page text field,
> the parent container will handle it, resulting in Dialog::okPressed()
> and subsequently Dialog::close(). Likewise, when I press the "Escape"
> key in a browser page text field, Dialog::close() will be triggered.
>
> Is this a bug? I do not encounter this in XULRunner 3.6.x, nor in an SWT
> Browser using Internet Explorer.
>
> Here is my test code, that can reproduce this behaviour when run in
> XULRunner 10.0.2, when "Enter" is pressed in the browser page text field:
>
>
>
> import org.eclipse.jface.dialogs.Dialog;
> import org.eclipse.jface.dialogs.IDialogConstants;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.browser.*;
> import org.eclipse.swt.graphics.*;
> import org.eclipse.swt.layout.*;
> import org.eclipse.swt.widgets.*;
> public class TestDialog extends Dialog {
>
> @Override
> public boolean close() {
> System.out.println("close()");
> return super.close();
> }
>
> @Override
> protected void okPressed() {
> System.out.println("ok pressed");
> super.okPressed();
> }
>
> public static void main(String args[]) {
> Display display = Display.getDefault();
> Shell shell = new Shell();
> TestDialog d = new TestDialog(shell);
> d.open();
>
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> display.dispose();
>
> }
>
> public TestDialog(Shell parentShell) {
> super(parentShell);
> }
>
> @Override
> protected Control createDialogArea(Composite parent) {
> Display.DEBUG = true;
> Composite container = (Composite) super.createDialogArea(parent);
> container.setLayout(new GridLayout(1, false));
>
> Composite composite = new Composite(container, SWT.NONE);
> composite.setLayout(new GridLayout(1, false));
> composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
> true, 1,
> 1));
>
> Browser mozBrowser = new Browser(composite, SWT.MOZILLA);
> mozBrowser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
> true,
> 1, 1));
> mozBrowser.setUrl("google.com");
> return container;
> }
>
> @Override
> protected void createButtonsForButtonBar(Composite parent) {
> createButton(parent, IDialogConstants.OK_ID,
> IDialogConstants.OK_LABEL,
> true);
> createButton(parent, IDialogConstants.CANCEL_ID,
> IDialogConstants.CANCEL_LABEL, false);
> }
>
> @Override
> protected Point getInitialSize() {
> return new Point(801, 582);
> }
> }
>
Re: Parent container of SWT Browser on XULRunner 10.0.2 is handling Enter and Escape key presses [message #953537 is a reply to message #950325] Mon, 22 October 2012 10:26 Go to previous messageGo to next message
Stella Lok is currently offline Stella LokFriend
Messages: 10
Registered: September 2012
Junior Member
I see, thank you for looking into it!
Re: Parent container of SWT Browser on XULRunner 10.0.2 is handling Enter and Escape key presses [message #953902 is a reply to message #953537] Mon, 22 October 2012 16:18 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
This is now fixed in the Eclipse/SWT 4.3 stream.

You can work around it with earlier versions with a traverse listener like:

browser.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if ((e.detail & (SWT.TRAVERSE_RETURN | SWT.TRAVERSE_ESCAPE)) !=
0) {
e.doit = false;
}
}
});

Grant


On 10/22/2012 6:26 AM, Stella Lok wrote:
> I see, thank you for looking into it!
Re: Parent container of SWT Browser on XULRunner 10.0.2 is handling Enter and Escape key presses [message #954432 is a reply to message #953902] Tue, 23 October 2012 02:07 Go to previous message
Stella Lok is currently offline Stella LokFriend
Messages: 10
Registered: September 2012
Junior Member
I will try that workaround, thanks!
Previous Topic:SWT Checkbox
Next Topic:SWT message queue clogged by browser messages
Goto Forum:
  


Current Time: Thu Apr 18 18:07:54 GMT 2024

Powered by FUDForum. Page generated in 0.03294 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top