7124286: [macosx] Option modifier should work like AltGr as in Apple jdk
authorleonidr
Wed, 18 Apr 2012 21:08:38 +0400
changeset 12418 f749f1ed92ca
parent 12417 3a2e4787eae5
child 12419 b81249542f14
child 12523 a3c0565476da
7124286: [macosx] Option modifier should work like AltGr as in Apple jdk Reviewed-by: anthony
jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
jdk/src/share/classes/javax/swing/text/DefaultEditorKit.java
jdk/src/share/classes/sun/awt/SunToolkit.java
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Wed Apr 18 09:29:09 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Wed Apr 18 21:08:38 2012 +0400
@@ -647,6 +647,15 @@
         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 {
--- a/jdk/src/share/classes/javax/swing/text/DefaultEditorKit.java	Wed Apr 18 09:29:09 2012 +0400
+++ b/jdk/src/share/classes/javax/swing/text/DefaultEditorKit.java	Wed Apr 18 21:08:38 2012 +0400
@@ -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 @@
                 }
                 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);
+                        }
                     }
                 }
             }
--- a/jdk/src/share/classes/sun/awt/SunToolkit.java	Wed Apr 18 09:29:09 2012 +0400
+++ b/jdk/src/share/classes/sun/awt/SunToolkit.java	Wed Apr 18 21:08:38 2012 +0400
@@ -1126,6 +1126,16 @@
     }
 
     /**
+     * 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}.
      * If the inputContext is not null, the window should return it from its