提交 23e0b025 编写于 作者: L leonidr

7124286: [macosx] Option modifier should work like AltGr as in Apple jdk

Reviewed-by: anthony
上级 e933aefe
...@@ -647,6 +647,15 @@ public class LWCToolkit extends LWToolkit { ...@@ -647,6 +647,15 @@ public class LWCToolkit extends LWToolkit {
return InputEvent.CTRL_MASK | InputEvent.ALT_MASK; return InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
} }
/**
* Tests whether specified key modifiers mask can be used to enter a printable
* character.
*/
@Override
public boolean isPrintableCharacterModifiersMask(int mods) {
return ((mods & (InputEvent.META_MASK | InputEvent.CTRL_MASK)) == 0);
}
// Extends PeerEvent because we want to pass long an ObjC mediator object and because we want these events to be posted early // Extends PeerEvent because we want to pass long an ObjC mediator object and because we want these events to be posted early
// Typically, rather than relying on the notifier to call notifyAll(), we use the mediator to stop the runloop // Typically, rather than relying on the notifier to call notifyAll(), we use the mediator to stop the runloop
public static class CPeerEvent extends PeerEvent { public static class CPeerEvent extends PeerEvent {
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
*/ */
package javax.swing.text; package javax.swing.text;
import sun.awt.SunToolkit;
import java.io.*; import java.io.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
...@@ -869,11 +871,18 @@ public class DefaultEditorKit extends EditorKit { ...@@ -869,11 +871,18 @@ public class DefaultEditorKit extends EditorKit {
} }
String content = e.getActionCommand(); String content = e.getActionCommand();
int mod = e.getModifiers(); int mod = e.getModifiers();
if ((content != null) && (content.length() > 0) && if ((content != null) && (content.length() > 0)) {
((mod & ActionEvent.ALT_MASK) == (mod & ActionEvent.CTRL_MASK))) { boolean isPrintableMask = true;
char c = content.charAt(0); Toolkit tk = Toolkit.getDefaultToolkit();
if ((c >= 0x20) && (c != 0x7F)) { if (tk instanceof SunToolkit) {
target.replaceSelection(content); isPrintableMask = ((SunToolkit)tk).isPrintableCharacterModifiersMask(mod);
}
if (isPrintableMask) {
char c = content.charAt(0);
if ((c >= 0x20) && (c != 0x7F)) {
target.replaceSelection(content);
}
} }
} }
} }
......
...@@ -1125,6 +1125,16 @@ public abstract class SunToolkit extends Toolkit ...@@ -1125,6 +1125,16 @@ public abstract class SunToolkit extends Toolkit
return InputEvent.ALT_MASK; return InputEvent.ALT_MASK;
} }
/**
* Tests whether specified key modifiers mask can be used to enter a printable
* character. This is a default implementation of this method, which reflects
* the way things work on Windows: here, pressing ctrl + alt allows user to enter
* characters from the extended character set (like euro sign or math symbols)
*/
public boolean isPrintableCharacterModifiersMask(int mods) {
return ((mods & InputEvent.ALT_MASK) == (mods & InputEvent.CTRL_MASK));
}
/** /**
* Returns a new input method window, with behavior as specified in * Returns a new input method window, with behavior as specified in
* {@link java.awt.im.spi.InputMethodContext#createInputMethodWindow}. * {@link java.awt.im.spi.InputMethodContext#createInputMethodWindow}.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册