[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[albireo-dev] Bug fix to remember proper focus position
|
Late last week, I committed a bug fix to the focus handling code. That
code was treating activations of a particular Swing control as tab
traversals, even when (in some situations) they were not. As a result
focus position within the activated Swing control was often reset to the
first or last child of the Swing control.
In the global focus handler, we track whether or not there is a current
traversal pending and the type of the pending traversal. That value was
not being properly reset when the traversal ends. (We consider the
traversal to be complete at the end of the activation of a particular
control.)
This bug was introduced during my refactoring of the focus handler into
global parts and per-SwingControl parts.
--- GlobalFocusHandler.java 2008/10/31 15:11:20 1.2
+++ GlobalFocusHandler.java 2008/10/31 21:52:44 1.3
@@ -56,11 +56,6 @@
return swtEventFilter.activeEmbedded;
}
- public int getLastSwtTraversal() {
- assert Display.getCurrent() != null; // On SWT event thread
- return swtEventFilter.lastSwtTraversal;
- }
-
public Widget getLastActiveWidget() {
assert Display.getCurrent() != null; // On SWT event thread
return swtEventFilter.lastActiveWidget;
@@ -178,7 +173,6 @@
Shell activeShell;
SwingControl activeEmbedded;
- int lastSwtTraversal = SWT.TRAVERSE_NONE;
Widget lastActiveWidget = null;
SwingControl lastActiveEmbedded = null;
boolean lastActiveFocusCleared = false;
@@ -204,11 +198,6 @@
activeShell = (Shell)widget;
}
- if (currentSwtTraversal != SWT.TRAVERSE_NONE) {
- lastSwtTraversal = currentSwtTraversal;
- }
- currentSwtTraversal = SWT.TRAVERSE_NONE;
-
// If we have moved from a SwingControl to another control in the same
// shell, clear its current focus owner so that a permanent focus
// lost event is generated.
@@ -256,6 +245,13 @@
// Propagate to any listeners
fireEvent(event);
+
+ // If there is a current traversal, it is now complete
+ // with the activation of a control. Reset the value
+ // to indicate no current traversal.
+ if (event.type == SWT.Activate) {
+ currentSwtTraversal = SWT.TRAVERSE_NONE;
+ }
}
}
}
--- FocusHandler.java 2008/08/04 20:23:07 1.24
+++ FocusHandler.java 2008/10/31 21:52:44 1.25
@@ -499,7 +499,7 @@
switch (event.type) {
case SWT.Activate:
// The lastSwtTraversal may change before it is used. Save its value for the asyncExecs
- final int swtTraversal = globalHandler.getLastSwtTraversal();
+ final int swtTraversal = globalHandler.getCurrentSwtTraversal();
// We use asyncExec to defer the activation and focus setting in the underlying AWT frame.
// This allows proper handling of the case where focus is briefly