Bug 321274 - Compound Custom Widget Focus
Summary: Compound Custom Widget Focus
Status: ASSIGNED
Alias: None
Product: RAP
Classification: RT
Component: RWT (show other bugs)
Version: 1.3   Edit
Hardware: All All
: P3 normal with 4 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
: 346471 365442 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-07-29 18:43 EDT by Jesus Luna Quiroga CLA
Modified: 2019-02-04 16:56 EST (History)
6 users (show)

See Also:


Attachments
Snippet to reproduce (1.28 KB, text/plain)
2010-08-05 09:51 EDT, Ralf Sternberg CLA
no flags Details
Patch proposal (4.12 KB, patch)
2012-11-08 11:49 EST, Claudio Guglielmo CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jesus Luna Quiroga CLA 2010-07-29 18:43:14 EDT
Hi,
 I'm creating a compound custom widget in RWT just like SWT, a Composite with a control inside it. Like this:

public class CustomText extends Composite {
	private Text text;
        public CustomText(Composite parent, int style) {
	    super(parent, SWT.NONE);
	    setLayout(new FillLayout());
            text = new Text(this, style);
            this.setTabList(new Control[]{text });
        }
....

In SWT the TAB and SHIFT-TAB navigation in custom widgets is just like any other control, it gains the focus and puts it in the inner control in the example above it would be the Text control the one that gains it and puts the cursor on it.       
But in RWT this behavior is different when a compound custom widget gains the focus, the one that is receiving it, is the container and it doesn't pass the focus to the inner control. 
In the example above would be the CustomText control, so in order to the inner control (Text) gains the focus the TAB key should be typed twice. 

I realize of this behavior putting focus listeners in the container control.

I cannot do a work around since the traverse(int traversal) has been removed from the RWT API.
Comment 1 Ralf Sternberg CLA 2010-08-05 09:51:47 EDT
Created attachment 175936 [details]
Snippet to reproduce

I can reproduce this bug with the attached snippet. There are no key or traverse listeners involved, so it's just a client issue. The fix should be to let the client Composite implementation not take the keyboard focus.

On the other hand, this brings up the question if we could support custom Control#setFocus() implementations ...
Comment 2 Ralf Sternberg CLA 2010-08-05 10:44:39 EDT
Turns out that it works for Composite but not for subclasses of Composite. For Composites, a tabIndex of -1 is rendered.
The problem is that Composite is hard-wired in ControlLCAUtil#takesFocus().

As a workaround, you can call the super constructor with the SWT.NO_FOCUS style flag like so:
-  super(parent, SWT.NONE);
+  super(parent, SWT.NO_FOCUS);
Comment 3 Ivan Furnadjiev CLA 2011-11-07 07:59:50 EST
*** Bug 346471 has been marked as a duplicate of this bug. ***
Comment 4 Ivan Furnadjiev CLA 2011-11-07 08:03:24 EST
(In reply to comment #3)
> *** Bug 346471 has been marked as a duplicate of this bug. ***
Andreas, does the workaround in comment #2 work for you? Using:
Composite c1 = new FormToolkit(parent.getDisplay()).createComposite(parent, SWT.NO_FOCUS);
Comment 5 Ivan Furnadjiev CLA 2011-12-02 12:05:56 EST
*** Bug 365442 has been marked as a duplicate of this bug. ***
Comment 6 Claudio Guglielmo CLA 2012-11-08 11:48:05 EST
The workaround in comment #2 does not always work. When using a ScrolledComposite, only certain styles are accepted, not including SWT.NO_FOCUS (see ScrolledComposite.checkStyle). When using eclipse forms, a LayoutComposite gets created but I have no influence on that.

I experienced the issue with following widgets:
- ScrolledComposite
- Form
- FormHeading
- TitleRegion
- LayoutComposite

In my opinion, these components should automatically add the no_focus flag, or at least give the possibility to do so.
Comment 7 Claudio Guglielmo CLA 2012-11-08 11:49:27 EST
Created attachment 223359 [details]
Patch proposal