зеркало из https://github.com/mozilla/pjs.git
This correctly implements the keyListener logic. I had the mapping
between mozilla concepts and java concepts wrong before. The correct mapping is: Mozilla concept Java concept KeyDown keyPressed KeyUp keyReleased KeyPress keyTyped KeyCode keyCode CharCode keyChar M webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/EventRegistrationImpl.java - Force the keyCode to be VK_UNDEFINED if this is a KEY_TYPED event. - For security, log any exceptions thrown during ctor of KeyEvent. M webclient/src_moz/EmbedEventListener.cpp - remove unused automatic vars. M webclient/src_moz/NavigationImpl.cpp - roll back change done by Brian Ryner, since it doesn't make sense under mozilla 1.7. M webclient/src_share/jni_util.cpp - reverse mapping of CHAR_CODE and KEY_CODE to their java counterparts. M webclient/test/automated/src/classes/org/mozilla/webclient/KeyListenerTest.java - Add in some code to make it easier to run this testcase in a manual fashion.
This commit is contained in:
Родитель
514f6880e1
Коммит
1726aadd2c
|
@ -444,7 +444,12 @@ private EventObject createKeyEvent(long eventType, Object eventData) {
|
|||
}
|
||||
}
|
||||
if (null != (str = props.getProperty("KeyCode"))) {
|
||||
keyCode = Integer.valueOf(str).intValue();
|
||||
if (0 == str.length() || KeyEvent.KEY_TYPED == eventType) {
|
||||
keyCode = KeyEvent.VK_UNDEFINED;
|
||||
}
|
||||
else {
|
||||
keyCode = Integer.valueOf(str).intValue();
|
||||
}
|
||||
}
|
||||
if (null != (str = props.getProperty("KeyChar"))) {
|
||||
if (0 == str.length()) {
|
||||
|
@ -458,7 +463,6 @@ private EventObject createKeyEvent(long eventType, Object eventData) {
|
|||
|
||||
long when = System.currentTimeMillis();
|
||||
if (KeyEvent.KEY_TYPED == eventType) {
|
||||
keyCode = KeyEvent.VK_UNDEFINED;
|
||||
// swalow events where the event is KEY_TYPED, but the keyChar
|
||||
// is undefined, since these would throw an
|
||||
// IllegalArgumentException.
|
||||
|
@ -466,8 +470,17 @@ private EventObject createKeyEvent(long eventType, Object eventData) {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
keyEvent = new KeyEvent((Component) browserControlCanvas, (int) eventType,
|
||||
when, modifiers, keyCode, keyChar);
|
||||
try {
|
||||
keyEvent = new KeyEvent((Component) browserControlCanvas, (int) eventType,
|
||||
when, modifiers, keyCode, keyChar);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
String msg = e.getMessage();
|
||||
System.out.println(e.toString() + " " + e.getMessage() +
|
||||
" eventType: " + eventType +
|
||||
" keyCode: " + keyCode +
|
||||
" keyChar: " + keyChar);
|
||||
}
|
||||
|
||||
WebclientEvent event = new WebclientEvent(browserControlCanvas, eventType,
|
||||
keyEvent);
|
||||
|
|
|
@ -494,9 +494,7 @@ nsresult EmbedEventListener::addKeyEventDataToProperties(nsCOMPtr<nsIDOMKeyEvent
|
|||
|
||||
// Add modifiers, keys, etc, to the mProperties table
|
||||
|
||||
PRInt32 intVal;
|
||||
PRUint32 int32Val;
|
||||
PRUint16 int16Val;
|
||||
PRBool boolVal;
|
||||
char buf[20];
|
||||
jstring strVal;
|
||||
|
|
|
@ -30,7 +30,9 @@
|
|||
|
||||
#include "org_mozilla_webclient_impl_wrapper_0005fnative_NavigationImpl.h"
|
||||
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIServiceManagerUtils.h" // PENDING(edburns): when moving
|
||||
// past 1.7, this changes to
|
||||
// nsServiceManagerUtils.h
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsString.h"
|
||||
|
|
|
@ -165,12 +165,12 @@ jboolean util_InitStringConstants()
|
|||
}
|
||||
if (nsnull == (CHAR_CODE =
|
||||
::util_NewGlobalRef(env, (jobject)
|
||||
::util_NewStringUTF(env, "KeyCode")))) {
|
||||
::util_NewStringUTF(env, "KeyChar")))) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
if (nsnull == (KEY_CODE =
|
||||
::util_NewGlobalRef(env, (jobject)
|
||||
::util_NewStringUTF(env, "KeyChar")))) {
|
||||
::util_NewStringUTF(env, "KeyCode")))) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
if (nsnull == (ALT_KEY =
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Id: KeyListenerTest.java,v 1.1 2004-12-01 03:21:23 edburns%acm.org Exp $
|
||||
* $Id: KeyListenerTest.java,v 1.2 2004-12-01 15:46:23 edburns%acm.org Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -119,6 +119,19 @@ public class KeyListenerTest extends WebclientTestCase {
|
|||
}
|
||||
});
|
||||
final BitSet bitSet = new BitSet();
|
||||
|
||||
KeyListener manualExitKeyListener = new KeyListener() {
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
public void keyReleased(KeyEvent e) {
|
||||
}
|
||||
public void keyTyped(KeyEvent e) {
|
||||
if ('z' == e.getKeyChar()) {
|
||||
KeyListenerTest.keepWaiting = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
canvas.addKeyListener(manualExitKeyListener);
|
||||
|
||||
KeyListener keyListener = new KeyListener() {
|
||||
public void keyPressed(KeyEvent e) {
|
||||
|
@ -158,6 +171,17 @@ public class KeyListenerTest extends WebclientTestCase {
|
|||
robot.mousePress(InputEvent.BUTTON1_MASK);
|
||||
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
||||
|
||||
|
||||
// uncomment to enable manual testing
|
||||
/*************
|
||||
KeyListenerTest.keepWaiting = true;
|
||||
|
||||
// keep waiting until the previous load completes
|
||||
while (KeyListenerTest.keepWaiting) {
|
||||
Thread.currentThread().sleep(1000);
|
||||
}
|
||||
******************/
|
||||
|
||||
robot.keyPress(KeyEvent.VK_A);
|
||||
robot.keyRelease(KeyEvent.VK_A);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче