Hi all,
Could you please review a fix for 8001633
<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8001633>: Wrong alt
processing during switching between windows.
Bug:http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8001633
<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8001633>
Webrev:
http://cr.openjdk.java.net/~bagiras/8/7082294.1/
To prevent wrong focus traversing to menu was added additional check to
AltProcessor.
It checks that original source of 'alt' event belongs to
AltProcessor.winAncestor
or its component.
Patch is attached.
Thanks,
Mikhail.
diff --git
a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsRootPaneUI.java
b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsRootPaneUI.java
--- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsRootPaneUI.java
+++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsRootPaneUI.java
@@ -31,6 +31,8 @@
import java.awt.KeyEventPostProcessor;
import java.awt.Window;
import java.awt.Toolkit;
+
+import sun.awt.AWTAccessor;
import sun.awt.SunToolkit;
import java.awt.event.ActionEvent;
@@ -138,6 +140,13 @@
if (tk instanceof SunToolkit) {
skip = ev.getWhen() <=
((SunToolkit)tk).getWindowDeactivationTime(winAncestor);
}
+ // We must insure that original source of key event belongs to
the same window object as winAncestor.
+ if (!skip) {
+ Component originalSource =
AWTAccessor.getKeyEventAccessor()
+ .getOriginalSource(ev);
+ skip = !(originalSource == winAncestor ||
+ SwingUtilities.getWindowAncestor(originalSource)
== winAncestor);
+ }
if (menu != null && !skip) {
MenuElement[] path = new MenuElement[2];
diff --git a/src/share/classes/java/awt/event/KeyEvent.java
b/src/share/classes/java/awt/event/KeyEvent.java
--- a/src/share/classes/java/awt/event/KeyEvent.java
+++ b/src/share/classes/java/awt/event/KeyEvent.java
@@ -930,6 +930,10 @@
long extendedKeyCode) {
ev.extendedKeyCode = extendedKeyCode;
}
+
+ public Component getOriginalSource( KeyEvent ev ) {
+ return ev.originalSource;
+ }
});
}
@@ -939,10 +943,19 @@
*/
private static native void initIDs();
+ /**
+ * The original event source.
+ *
+ * Event source can be changed during processing, but in some cases
+ * we need to able to obtain original source.
+ */
+ private Component originalSource;
+
private KeyEvent(Component source, int id, long when, int modifiers,
int keyCode, char keyChar, int keyLocation, boolean
isProxyActive) {
this(source, id, when, modifiers, keyCode, keyChar, keyLocation);
this.isProxyActive = isProxyActive;
+ originalSource = source;
}
/**
@@ -1023,6 +1036,7 @@
} else if ((getModifiers() == 0) && (getModifiersEx() != 0)) {
setOldModifiers();
}
+ originalSource = source;
}
/**
@@ -1069,6 +1083,7 @@
int keyCode, char keyChar) {
this(source, id, when, modifiers, keyCode, keyChar,
KEY_LOCATION_UNKNOWN);
+ originalSource = source;
}
/**
@@ -1078,6 +1093,7 @@
public KeyEvent(Component source, int id, long when, int modifiers,
int keyCode) {
this(source, id, when, modifiers, keyCode, (char)keyCode);
+ originalSource = source;
}
/**
diff --git a/src/share/classes/sun/awt/AWTAccessor.java
b/src/share/classes/sun/awt/AWTAccessor.java
--- a/src/share/classes/sun/awt/AWTAccessor.java
+++ b/src/share/classes/sun/awt/AWTAccessor.java
@@ -629,6 +629,11 @@
* Sets extendedKeyCode field for KeyEvent
*/
void setExtendedKeyCode(KeyEvent ev, long extendedKeyCode);
+
+ /**
+ * Gets original source for KeyEvent
+ */
+ Component getOriginalSource(KeyEvent ev);
}
/**