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

Reviewed-by: anthony
This commit is contained in:
Leonid Romanov 2012-04-18 21:08:38 +04:00
parent 3f50074142
commit 846b62bbd6
3 changed files with 33 additions and 5 deletions
jdk/src
macosx/classes/sun/lwawt/macosx
share/classes

@ -647,6 +647,15 @@ public class LWCToolkit extends LWToolkit {
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
// Typically, rather than relying on the notifier to call notifyAll(), we use the mediator to stop the runloop
public static class CPeerEvent extends PeerEvent {

@ -24,6 +24,8 @@
*/
package javax.swing.text;
import sun.awt.SunToolkit;
import java.io.*;
import java.awt.*;
import java.awt.event.ActionEvent;
@ -869,11 +871,18 @@ public class DefaultEditorKit extends EditorKit {
}
String content = e.getActionCommand();
int mod = e.getModifiers();
if ((content != null) && (content.length() > 0) &&
((mod & ActionEvent.ALT_MASK) == (mod & ActionEvent.CTRL_MASK))) {
char c = content.charAt(0);
if ((c >= 0x20) && (c != 0x7F)) {
target.replaceSelection(content);
if ((content != null) && (content.length() > 0)) {
boolean isPrintableMask = true;
Toolkit tk = Toolkit.getDefaultToolkit();
if (tk instanceof SunToolkit) {
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
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
* {@link java.awt.im.spi.InputMethodContext#createInputMethodWindow}.