# HG changeset patch # User pchelko # Date 1365761343 -14400 # Node ID ea714f11d40d24353ebf0cfb48affbe5cd5c1f20 # Parent 1af9ab28cf6d803ee6ba511ad3e480cab4136549 8010009: [macosx] Unable type into online word games on MacOSX Reviewed-by: anthony, dcherepanov diff -r 1af9ab28cf6d -r ea714f11d40d jdk/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java Thu Apr 11 19:12:59 2013 +0400 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java Fri Apr 12 14:09:03 2013 +0400 @@ -97,13 +97,7 @@ public void handleKeyEvent(int eventType, int modifierFlags, String characters, String charsIgnoringMods, boolean isRepeat, short keyCode, boolean needsKeyTyped) { - responder.handleKeyEvent(eventType, modifierFlags, charsIgnoringMods, keyCode, needsKeyTyped); - } - - // REMIND: delete this method once 'deploy' changes for 7156194 is pushed - public void handleKeyEvent(int eventType, int modifierFlags, String characters, - String charsIgnoringMods, boolean isRepeat, short keyCode) { - handleKeyEvent(eventType, modifierFlags, characters, charsIgnoringMods, isRepeat, keyCode, true); + responder.handleKeyEvent(eventType, modifierFlags, charsIgnoringMods, keyCode, needsKeyTyped, isRepeat); } public void handleInputEvent(String text) { diff -r 1af9ab28cf6d -r ea714f11d40d jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java Thu Apr 11 19:12:59 2013 +0400 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java Fri Apr 12 14:09:03 2013 +0400 @@ -41,6 +41,7 @@ private final LWWindowPeer peer; private final boolean isNpapiCallback; + private int lastKeyPressCode = KeyEvent.VK_UNDEFINED; CPlatformResponder(final LWWindowPeer peer, final boolean isNpapiCallback) { this.peer = peer; @@ -123,7 +124,7 @@ * Handles key events. */ void handleKeyEvent(int eventType, int modifierFlags, String chars, - short keyCode, boolean needsKeyTyped) { + short keyCode, boolean needsKeyTyped, boolean needsKeyReleased) { boolean isFlagsChangedEvent = isNpapiCallback ? (eventType == CocoaConstants.NPCocoaEventFlagsChanged) : (eventType == CocoaConstants.NSFlagsChanged); @@ -183,6 +184,9 @@ int jmodifiers = NSEvent.nsToJavaKeyModifiers(modifierFlags); long when = System.currentTimeMillis(); + if (jeventType == KeyEvent.KEY_PRESSED) { + lastKeyPressCode = jkeyCode; + } peer.dispatchKeyEvent(jeventType, when, jmodifiers, jkeyCode, javaChar, jkeyLocation); @@ -195,26 +199,41 @@ // Modifier keys (shift, etc) don't want to send TYPED events. // On the other hand we don't want to generate keyTyped events // for clipboard related shortcuts like Meta + [CVX] - boolean isMetaDown = (jmodifiers & KeyEvent.META_DOWN_MASK) != 0; - if (jeventType == KeyEvent.KEY_PRESSED && postsTyped && !isMetaDown) { + if (jeventType == KeyEvent.KEY_PRESSED && postsTyped && + (jmodifiers & KeyEvent.META_DOWN_MASK) == 0) { + // Enter and Space keys finish the input method processing, + // KEY_TYPED and KEY_RELEASED events for them are synthesized in handleInputEvent. + if (needsKeyReleased && (jkeyCode == KeyEvent.VK_ENTER || jkeyCode == KeyEvent.VK_SPACE)) { + return; + } peer.dispatchKeyEvent(KeyEvent.KEY_TYPED, when, jmodifiers, KeyEvent.VK_UNDEFINED, javaChar, KeyEvent.KEY_LOCATION_UNKNOWN); + //If events come from Firefox, released events should also be generated. + if (needsKeyReleased) { + peer.dispatchKeyEvent(KeyEvent.KEY_RELEASED, when, jmodifiers, + jkeyCode, javaChar, + KeyEvent.KEY_LOCATION_UNKNOWN); + } } } void handleInputEvent(String text) { if (text != null) { int index = 0, length = text.length(); - char c; + char c = 0; while (index < length) { c = text.charAt(index); peer.dispatchKeyEvent(KeyEvent.KEY_TYPED, - System.currentTimeMillis(), - 0, KeyEvent.VK_UNDEFINED, c, - KeyEvent.KEY_LOCATION_UNKNOWN); + System.currentTimeMillis(), + 0, KeyEvent.VK_UNDEFINED, c, + KeyEvent.KEY_LOCATION_UNKNOWN); index++; } + peer.dispatchKeyEvent(KeyEvent.KEY_RELEASED, + System.currentTimeMillis(), + 0, lastKeyPressCode, c, + KeyEvent.KEY_LOCATION_UNKNOWN); } } diff -r 1af9ab28cf6d -r ea714f11d40d jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java Thu Apr 11 19:12:59 2013 +0400 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java Fri Apr 12 14:09:03 2013 +0400 @@ -202,7 +202,7 @@ private void deliverKeyEvent(NSEvent event) { responder.handleKeyEvent(event.getType(), event.getModifierFlags(), - event.getCharactersIgnoringModifiers(), event.getKeyCode(), true); + event.getCharactersIgnoringModifiers(), event.getKeyCode(), true, false); } /** diff -r 1af9ab28cf6d -r ea714f11d40d jdk/test/java/awt/event/KeyEvent/KeyReleasedInAppletTest/KeyReleasedInAppletTest.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/event/KeyEvent/KeyReleasedInAppletTest/KeyReleasedInAppletTest.html Fri Apr 12 14:09:03 2013 +0400 @@ -0,0 +1,22 @@ + + +
+See the dialog box (usually in upper left corner) for instructions
+ + + + diff -r 1af9ab28cf6d -r ea714f11d40d jdk/test/java/awt/event/KeyEvent/KeyReleasedInAppletTest/KeyReleasedInAppletTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/event/KeyEvent/KeyReleasedInAppletTest/KeyReleasedInAppletTest.java Fri Apr 12 14:09:03 2013 +0400 @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.*; +import javax.swing.JLabel; +import javax.swing.JTextArea; +import java.awt.*; +import java.awt.FileDialog; +import java.awt.Label; +import java.awt.event.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.io.FileWriter; +import java.lang.*; +import java.lang.Override; +import java.lang.String; +import java.lang.System; +import java.lang.Throwable; +import java.util.Hashtable; + +/* +@test +@bug 8010009 +@summary [macosx] Unable type into online word games on MacOSX +@author petr.pchelko : area=awt.keyboard +@run clean * +@run build TestApplet +@run applet/manual=yesno KeyReleasedInAppletTest.html +*/ + +public class KeyReleasedInAppletTest extends JApplet { + private static final String TEST_HTML_NAME = "TestApplet.html"; + + public void init() { + //Create instructions for the user here, as well as set up + // the environment -- set the layout manager, add buttons, + // etc. + this.setLayout(new BorderLayout()); + + try { + String testFilePath = System.getProperty("test.classes"); + FileWriter testHTML = null; + try { + testHTML = new FileWriter(testFilePath + "/" + TEST_HTML_NAME); + testHTML.write("\n" + + "\n" + + "Make sure the applet is focuced and type any character on the keyboard.
"+
+ "The applet should show keyPressed, keyTyped and keyReleased messages.