Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Issue with Browser and TraverseListener(Verifying an issue with the Browser and using a TraverseListener upon it)
Issue with Browser and TraverseListener [message #498673] Wed, 18 November 2009 00:58 Go to next message
Ricky Patel is currently offline Ricky PatelFriend
Messages: 33
Registered: July 2009
Member
Hi everyone,
I'm programming a nice little html tooltip type window of which you should be able to close by the click of the escape button and came upon this issue.

From what I can tell, the browser control eats all the traverse events (tab, escape) and never passes it to a following traverse listener. An example of this is the code provided below. First click on the Text composite and press escape, you will notice the window closes. Then open it and click on the browser so it has focus and press escape. You will notice it wont close.

	public static void main(String [] args) {
		Display display = new Display();
		final Shell shell = new Shell(display);
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 1;
		shell.setLayout(gridLayout);
		
		GridData data = new GridData();
		data.horizontalSpan = 1;
		
		final Text label = new Text (shell, SWT.NONE);
		label.setText("Click here and press escape");
		data = new GridData();
		data.horizontalAlignment = GridData.FILL;
		data.horizontalSpan = 1;
		data.grabExcessHorizontalSpace = true;
		label.setLayoutData(data);

		final Browser browser;
		try {
			browser = new Browser(shell, SWT.NONE);
		} catch (SWTError e) {
			System.out.println("Could not instantiate Browser: " + e.getMessage());
			display.dispose();
			return;
		}
		data = new GridData();
		data.horizontalAlignment = GridData.FILL;
		data.verticalAlignment = GridData.FILL;
		data.horizontalSpan = 1;
		data.grabExcessHorizontalSpace = true;
		data.grabExcessVerticalSpace = true;
		browser.setLayoutData(data);
		
		TraverseListener t = new TraverseListener () {
			@Override
			public void keyTraversed (TraverseEvent e)
			{
				System.out.println(e.detail);
				if (e.detail == SWT.TRAVERSE_ESCAPE)
				{
					shell.close();
				}
			}
		};
		
		shell.addTraverseListener(t);
		browser.addTraverseListener(t);
		label.addTraverseListener(t);
		
		shell.open();
		browser.setUrl("http://eclipse.org");
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
Re: Issue with Browser and TraverseListener [message #498809 is a reply to message #498673] Wed, 18 November 2009 16:50 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
This is logged as https://bugs.eclipse.org/bugs/show_bug.cgi?id=231311 .

Grant


"Ricky Patel" <k2snowman69@yahoo.com> wrote in message
news:hdvgsf$8mn$1@build.eclipse.org...
> Hi everyone,
> I'm programming a nice little html tooltip type window of which you should
be able to close by the click of the escape button and came upon this issue.
>
> From what I can tell, the browser control eats all the traverse events
(tab, escape) and never passes it to a following traverse listener. An
example of this is the code provided below. First click on the Text
composite and press escape, you will notice the window closes. Then open it
and click on the browser so it has focus and press escape. You will notice
it wont close.
>
> public static void main(String [] args) {
> Display display = new Display();
> final Shell shell = new Shell(display);
> GridLayout gridLayout = new GridLayout();
> gridLayout.numColumns = 1;
> shell.setLayout(gridLayout);
>
> GridData data = new GridData();
> data.horizontalSpan = 1;
>
> final Text label = new Text (shell, SWT.NONE);
> label.setText("Click here and press escape");
> data = new GridData();
> data.horizontalAlignment = GridData.FILL;
> data.horizontalSpan = 1;
> data.grabExcessHorizontalSpace = true;
> label.setLayoutData(data);
>
> final Browser browser;
> try {
> browser = new Browser(shell, SWT.NONE);
> } catch (SWTError e) {
> System.out.println("Could not instantiate Browser: " + e.getMessage());
> display.dispose();
> return;
> }
> data = new GridData();
> data.horizontalAlignment = GridData.FILL;
> data.verticalAlignment = GridData.FILL;
> data.horizontalSpan = 1;
> data.grabExcessHorizontalSpace = true;
> data.grabExcessVerticalSpace = true;
> browser.setLayoutData(data);
>
> TraverseListener t = new TraverseListener () {
> @Override
> public void keyTraversed (TraverseEvent e)
> {
> System.out.println(e.detail);
> if (e.detail == SWT.TRAVERSE_ESCAPE)
> {
> shell.close();
> }
> }
> };
>
> shell.addTraverseListener(t);
> browser.addTraverseListener(t);
> label.addTraverseListener(t);
>
> shell.open();
> browser.setUrl("http://eclipse.org");
>
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
Re: Issue with Browser and TraverseListener [message #500729 is a reply to message #498809] Fri, 27 November 2009 18:55 Go to previous message
Ricky Patel is currently offline Ricky PatelFriend
Messages: 33
Registered: July 2009
Member
Oh thanks, sorry about that then Smile
Previous Topic:Table#getTopIndex returns negative value
Next Topic:PGroup leak problem
Goto Forum:
  


Current Time: Thu Mar 28 18:57:39 GMT 2024

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

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

Back to the top