# HG changeset patch # User pchelko # Date 1365589690 -14400 # Node ID 1d48c0d0a0a2d955b234f128404d6472abc2cf37 # Parent dad642e0105e4474557508b0681150970e5c2923 8010009: [macosx] Unable type into online word games on MacOSX Reviewed-by: anthony, dcherepanov, yan diff -r dad642e0105e -r 1d48c0d0a0a2 src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java --- a/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java Wed Jun 26 22:27:10 2013 -0500 +++ b/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java Wed Apr 10 14:28:10 2013 +0400 @@ -91,13 +91,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 dad642e0105e -r 1d48c0d0a0a2 src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java --- a/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java Wed Jun 26 22:27:10 2013 -0500 +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java Wed Apr 10 14:28:10 2013 +0400 @@ -43,6 +43,7 @@ private final PlatformEventNotifier eventNotifier; private final boolean isNpapiCallback; + private int lastKeyPressCode = KeyEvent.VK_UNDEFINED; CPlatformResponder(final PlatformEventNotifier eventNotifier, final boolean isNpapiCallback) { @@ -126,7 +127,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); @@ -178,7 +179,9 @@ int jmodifiers = NSEvent.nsToJavaKeyModifiers(modifierFlags); long when = System.currentTimeMillis(); - + if (jeventType == KeyEvent.KEY_PRESSED) { + lastKeyPressCode = jkeyCode; + } eventNotifier.notifyKeyEvent(jeventType, when, jmodifiers, jkeyCode, javaChar, jkeyLocation); @@ -191,18 +194,29 @@ // 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; + } eventNotifier.notifyKeyEvent(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) { + eventNotifier.notifyKeyEvent(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); eventNotifier.notifyKeyEvent(KeyEvent.KEY_TYPED, @@ -211,6 +225,10 @@ KeyEvent.KEY_LOCATION_UNKNOWN); index++; } + eventNotifier.notifyKeyEvent(KeyEvent.KEY_RELEASED, + System.currentTimeMillis(), + 0, lastKeyPressCode, c, + KeyEvent.KEY_LOCATION_UNKNOWN); } } diff -r dad642e0105e -r 1d48c0d0a0a2 src/macosx/classes/sun/lwawt/macosx/CPlatformView.java --- a/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java Wed Jun 26 22:27:10 2013 -0500 +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java Wed Apr 10 14:28:10 2013 +0400 @@ -212,7 +212,7 @@ private void deliverKeyEvent(NSEvent event) { responder.handleKeyEvent(event.getType(), event.getModifierFlags(), - event.getCharactersIgnoringModifiers(), event.getKeyCode(), true); + event.getCharactersIgnoringModifiers(), event.getKeyCode(), true, false); } private void deliverWindowDidExposeEvent() { diff -r dad642e0105e -r 1d48c0d0a0a2 test/java/awt/event/KeyEvent/KeyReleasedInAppletTest/KeyReleasedInAppletTest.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/event/KeyEvent/KeyReleasedInAppletTest/KeyReleasedInAppletTest.html Wed Apr 10 14:28:10 2013 +0400 @@ -0,0 +1,22 @@ + + +
+See the dialog box (usually in upper left corner) for instructions
+ + + + diff -r dad642e0105e -r 1d48c0d0a0a2 test/java/awt/event/KeyEvent/KeyReleasedInAppletTest/KeyReleasedInAppletTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/event/KeyEvent/KeyReleasedInAppletTest/KeyReleasedInAppletTest.java Wed Apr 10 14:28:10 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.