JBR-2847 Always dispatch KEY_TYPED event to the same component as KEY_PRESSED event

also fixes JBR-2834, IDEA-254466, IDEA-254466
squashed with fixes for JBR-3291, JBR-3307, JBR-3598

(cherry picked from commits e94f6057a4, ba6b9c085e, 2ccf6b65a7, 3b0708af7d, 3674766d65)
This commit is contained in:
Dmitry Batrak
2020-11-08 19:45:14 +03:00
committed by jbrbot
parent ad213e853c
commit 4fc5ac44e2
3 changed files with 24 additions and 10 deletions

View File

@@ -79,6 +79,7 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
private LinkedList<TypeAheadMarker> typeAheadMarkers = new LinkedList<TypeAheadMarker>();
private boolean consumeNextKeyTyped;
private Component restoreFocusTo;
private WeakReference<Component> lastKeyPressedOrReleasedTarget = NULL_COMPONENT_WR;
private static boolean fxAppThreadIsDispatchThread;
@@ -874,7 +875,9 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
* @see Component#dispatchEvent
*/
public boolean dispatchKeyEvent(KeyEvent e) {
Component focusOwner = (((AWTEvent)e).isPosted) ? getFocusOwner() : e.getComponent();
Component focusOwner = (((AWTEvent)e).isPosted &&
!(e.getID() == KeyEvent.KEY_TYPED && SunToolkit.isSystemGenerated(e)))
? getFocusOwner() : e.getComponent();
if (focusOwner != null && focusOwner.isShowing() && focusOwner.canBeFocusOwner()) {
if (!e.isConsumed()) {
@@ -1099,8 +1102,21 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
@SuppressWarnings("deprecation")
private boolean preDispatchKeyEvent(KeyEvent ke) {
if (((AWTEvent) ke).isPosted) {
Component focusOwner = getFocusOwner();
ke.setSource(((focusOwner != null) ? focusOwner : getFocusedWindow()));
boolean typedEvent = ke.getID() == KeyEvent.KEY_TYPED;
boolean systemEvent = SunToolkit.isSystemGenerated(ke);
Component focusOwner;
if (typedEvent && systemEvent) {
focusOwner = lastKeyPressedOrReleasedTarget.get();
} else {
focusOwner = getFocusOwner();
if (focusOwner == null) {
focusOwner = getFocusedWindow();
}
}
if (!typedEvent && systemEvent) {
lastKeyPressedOrReleasedTarget = new WeakReference<>(focusOwner);
}
ke.setSource(focusOwner);
}
if (ke.getSource() == null) {
return true;

View File

@@ -5329,7 +5329,6 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
// Start editing when a key is typed. UI classes can disable this behavior
// by setting the client property JTable.autoStartsEdit to Boolean.FALSE.
if (!retValue && condition == WHEN_ANCESTOR_OF_FOCUSED_COMPONENT &&
isFocusOwner() &&
!Boolean.FALSE.equals(getClientProperty("JTable.autoStartsEdit"))) {
// We do not have a binding for the event.
Component editorComponent = getEditorComponent();
@@ -5358,11 +5357,6 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
if (editorComponent == null) {
return false;
}
}
// If the editorComponent is a JComponent, pass the event to it.
if (editorComponent instanceof JComponent) {
retValue = ((JComponent)editorComponent).processKeyBinding
(ks, e, WHEN_FOCUSED, pressed);
// If we have started an editor as a result of the user
// pressing a key and the surrendersFocusOnKeystroke property
// is true, give the focus to the new editor.
@@ -5372,6 +5366,11 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
editorComponent.requestFocus();
}
}
// If the editorComponent is a JComponent, pass the event to it.
if (editorComponent instanceof JComponent) {
retValue = ((JComponent)editorComponent).processKeyBinding
(ks, e, WHEN_FOCUSED, pressed);
}
}
return retValue;
}

View File

@@ -884,7 +884,6 @@ javax/swing/JComboBox/6607130/bug6607130.java
javax/swing/JComboBox/4199622/bug4199622.java nobug windows-all
javax/swing/JComboBox/4515752/DefaultButtonTest.java nobug windows-all
javax/swing/JComboBox/8032878/bug8032878.java nobug windows-all
javax/swing/JComboBox/8057893/bug8057893.java nobug windows-all
javax/swing/JList/6462008/bug6462008.java nobug windows-all