提交 cb0ed89e 编写于 作者: A alitvinov

8199748: Touch keyboard is not shown, if text component gets focus from other text component

Reviewed-by: serb, aivanov
上级 a07dc1f2
...@@ -37,6 +37,7 @@ import java.awt.datatransfer.Clipboard; ...@@ -37,6 +37,7 @@ import java.awt.datatransfer.Clipboard;
import java.awt.TextComponent; import java.awt.TextComponent;
import java.awt.TrayIcon; import java.awt.TrayIcon;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.lang.ref.WeakReference;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
...@@ -1111,48 +1112,59 @@ public final class WToolkit extends SunToolkit implements Runnable { ...@@ -1111,48 +1112,59 @@ public final class WToolkit extends SunToolkit implements Runnable {
// The following code is used for support of automatic showing of the touch // The following code is used for support of automatic showing of the touch
// keyboard for text components and is accessed only from EDT. // keyboard for text components and is accessed only from EDT.
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
private volatile Component compOnTouchDownEvent; private static final WeakReference<Component> NULL_COMPONENT_WR =
private volatile Component compOnMousePressedEvent; new WeakReference<>(null);
private volatile WeakReference<Component> compOnTouchDownEvent =
NULL_COMPONENT_WR;
private volatile WeakReference<Component> compOnMousePressedEvent =
NULL_COMPONENT_WR;
private boolean isComponentValidForTouchKeyboard(Component comp) {
if ((comp != null) && comp.isEnabled() && comp.isFocusable() &&
(((comp instanceof TextComponent) &&
((TextComponent) comp).isEditable()) ||
((comp instanceof JTextComponent) &&
((JTextComponent) comp).isEditable()))) {
return true;
}
return false;
}
@Override @Override
public void showOrHideTouchKeyboard(Component comp, AWTEvent e) { public void showOrHideTouchKeyboard(Component comp, AWTEvent e) {
if ((comp == null) || (e == null) || if (!(comp instanceof TextComponent) &&
(!(comp instanceof TextComponent) && !(comp instanceof JTextComponent)) {
!(comp instanceof JTextComponent))) {
return; return;
} }
if ((e instanceof MouseEvent) && comp.isEnabled() && if ((e instanceof MouseEvent) && isComponentValidForTouchKeyboard(comp)) {
comp.isFocusable() && MouseEvent me = (MouseEvent) e;
(((comp instanceof TextComponent) &&
((TextComponent)comp).isEditable()) ||
((comp instanceof JTextComponent) &&
((JTextComponent)comp).isEditable()))) {
MouseEvent me = (MouseEvent)e;
if (me.getID() == MouseEvent.MOUSE_PRESSED) { if (me.getID() == MouseEvent.MOUSE_PRESSED) {
if (AWTAccessor.getMouseEventAccessor() if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
.isCausedByTouchEvent(me)) { compOnTouchDownEvent = new WeakReference<>(comp);
compOnTouchDownEvent = comp;
} else { } else {
compOnMousePressedEvent = comp; compOnMousePressedEvent = new WeakReference<>(comp);
} }
} else if (me.getID() == MouseEvent.MOUSE_RELEASED) { } else if (me.getID() == MouseEvent.MOUSE_RELEASED) {
if (AWTAccessor.getMouseEventAccessor() if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
.isCausedByTouchEvent(me)) { if (compOnTouchDownEvent.get() == comp) {
if (compOnTouchDownEvent == comp) {
showTouchKeyboard(true); showTouchKeyboard(true);
} }
compOnTouchDownEvent = null; compOnTouchDownEvent = NULL_COMPONENT_WR;
} else { } else {
if (compOnMousePressedEvent == comp) { if (compOnMousePressedEvent.get() == comp) {
showTouchKeyboard(false); showTouchKeyboard(false);
} }
compOnMousePressedEvent = null; compOnMousePressedEvent = NULL_COMPONENT_WR;
} }
} }
} else if (e instanceof FocusEvent) { } else if (e instanceof FocusEvent) {
if (e.getID() == FocusEvent.FOCUS_LOST) { FocusEvent fe = (FocusEvent) e;
hideTouchKeyboard(); if (fe.getID() == FocusEvent.FOCUS_LOST) {
// Hide the touch keyboard, if not a text component gains focus.
if (!isComponentValidForTouchKeyboard(fe.getOppositeComponent())) {
hideTouchKeyboard();
}
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册