Bug 156456 - [Forms] widgets accept focus even though they can't do anything with it
Summary: [Forms] widgets accept focus even though they can't do anything with it
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: User Assistance (show other bugs)
Version: 3.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.4 M4   Edit
Assignee: Adam Archer CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2006-09-06 20:26 EDT by Stefan Xenos CLA
Modified: 2007-12-03 15:14 EST (History)
5 users (show)

See Also:


Attachments
Patch that fixes the problem (2.37 KB, patch)
2006-09-06 20:33 EDT, Stefan Xenos CLA
no flags Details | Diff
patch for when we re-apply (3.24 KB, patch)
2007-03-22 11:55 EDT, Curtis d'Entremont CLA
no flags Details | Diff
resynched patch (3.17 KB, patch)
2007-12-03 11:48 EST, Adam Archer CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Xenos CLA 2006-09-06 20:26:52 EDT
Many of the widgets in the Forms library (Section, BusyIndicator, FormHeading) will accept keyboard focus even though they can't do anything with it.

The impact is that when someone calls setFocus on a Form that contains a FormHeading at its top (which is quite common), keyboard focus ends up nowhere.

Looking at the patterns in SWT, it appears that the correct protocol is for controls to return false from setFocus if they can't do anything with the focus so  that the caller can try assigning focus somewhere else.
Comment 1 Stefan Xenos CLA 2006-09-06 20:33:20 EDT
Created attachment 49575 [details]
Patch that fixes the problem

This patch fixes the problem by overriding forceFocus() to return false in all subclasses of Composite that can't do anything with focus directly, but might have children that can.

This appears to fix the problem for me, but someone should probably consult with Steve Northover to ensure that this is a valid reason for overloading forceFocus.

Another possible solution may be to set the NO_FOCUS flag whenever one of these classes is instantiated, but this wouldn't catch places where they are instantiated in 3rd-party code.
Comment 2 Chris Goldthorpe CLA 2006-09-07 12:21:46 EDT
Will this change affect context sensitive help at all? If the dynamic help view is open it determines the help context from the control that has focus and does this whenever a part activation event is generated (such as when a view gains focus).

Are there any situations where this patch would change the behavior so that a control which would have had focus no longer does so? If so we should look at whether that is going tocause any existing views to not show the right context help.
Comment 3 Stefan Xenos CLA 2006-09-07 19:22:54 EDT
The patch should only affect widgets that don't accept any form of user input (such as labels, titles, progress bars, etc)... and it should not affect part activation in any way.

The only way this would change the initial focus within a part would be if the initial focus had been going to a control that couldn't accept it. The part would open with no visible cursor, no widget showing the affordance for keyboard focus, and the user would be unable to type anywhere until they click on something or hit tab. Since this would be a bug, it is unlikely that anyone would be relying on it to correctly compute their help contexts.
Comment 4 Jan Lohre CLA 2006-12-11 06:06:10 EST
While seeing users might prefer to have the focus in the first editable control, a blind user would like the screenreader to read the sections title and description first.

Maybe there should be a workbench-wide option for such issues.
Comment 5 Stefan Xenos CLA 2007-02-27 14:38:36 EST
I have no disagreement that screen readers should read the text in the order it appears, however the screen reader should not be relying on keyboard focus in order to determine what text to read.

Keyboard focus is intended for determining where input goes, not where output comes from. A screen reader that could not read text unless it has keyboard focus would be quite badly broken already.
Comment 6 Curtis d'Entremont CLA 2007-02-28 13:34:30 EST
Patch applied.

Note: Instead of overriding forceFocus on Section, I did it on ExpandableComposite (a Section is an ExpandableComposite). Also, I omitted the SWT.NO_FOCUS flag on the Text widget because:

- It is not a valid flag for a Text widget. I also cannot subclass Text, so I see no straightforward way to prevent focus from going to it.
- You actually can do something with focus.. you get a cursor and can select text and copy it to the clipboard. Not that useful, but still, not useless either.
Comment 7 Curtis d'Entremont CLA 2007-03-22 11:54:43 EDT
Had to roll back this fix in M6 as it surfaced a new problem, bug 178704, which we don't have time to fix in M6. Will re-apply after M6.
Comment 8 Curtis d'Entremont CLA 2007-03-22 11:55:06 EDT
Created attachment 61695 [details]
patch for when we re-apply
Comment 9 Curtis d'Entremont CLA 2007-04-25 16:37:17 EDT
Not enough time to review and test this for M7.
Comment 10 Adam Archer CLA 2007-12-03 11:43:29 EST
I believe the patch is safe to apply. It tested well for me. The issue reported in bug 178704 will no longer occur with this patch due to the fix for bug 178821.
Comment 11 Adam Archer CLA 2007-12-03 11:48:29 EST
Created attachment 84331 [details]
resynched patch

The patch had conflicts when I tried to pull it in. Here is the up-to-date version.
Comment 12 Chris Goldthorpe CLA 2007-12-03 15:14:11 EST
Fixed in HEAD.