Bug 842013 - Don't add extra modifiers to key press events; r=cpeterson

This commit is contained in:
Jim Chen 2013-03-29 10:54:01 -04:00
parent bf161904b0
commit 45eeb64f4d
4 changed files with 28 additions and 12 deletions

View File

@ -122,6 +122,7 @@ public class GeckoEvent {
private int mFlags;
private int mKeyCode;
private int mUnicodeChar;
private int mBaseUnicodeChar; // mUnicodeChar without meta states applied
private int mRepeatCount;
private int mCount;
private int mStart;
@ -198,11 +199,10 @@ public class GeckoEvent {
mMetaState = k.getMetaState() | metaState;
mFlags = k.getFlags();
mKeyCode = k.getKeyCode();
mUnicodeChar = k.getUnicodeChar();
if (mUnicodeChar == 0) {
// e.g. for Ctrl+A, Android returns 0, but Gecko expects 'a' as mUnicodeChar
mUnicodeChar = k.getUnicodeChar(0);
}
mUnicodeChar = k.getUnicodeChar(mMetaState);
// e.g. for Ctrl+A, Android returns 0 for mUnicodeChar,
// but Gecko expects 'a', so we return that in mBaseUnicodeChar
mBaseUnicodeChar = k.getUnicodeChar(0);
mRepeatCount = k.getRepeatCount();
mCharacters = k.getCharacters();
mDomKeyLocation = isJoystickButton(mKeyCode) ? DOM_KEY_LOCATION_JOYSTICK : DOM_KEY_LOCATION_MOBILE;

View File

@ -33,6 +33,7 @@ jfieldID AndroidGeckoEvent::jMetaStateField = 0;
jfieldID AndroidGeckoEvent::jDomKeyLocationField = 0;
jfieldID AndroidGeckoEvent::jFlagsField = 0;
jfieldID AndroidGeckoEvent::jUnicodeCharField = 0;
jfieldID AndroidGeckoEvent::jBaseUnicodeCharField = 0;
jfieldID AndroidGeckoEvent::jRepeatCountField = 0;
jfieldID AndroidGeckoEvent::jCountField = 0;
jfieldID AndroidGeckoEvent::jStartField = 0;
@ -227,6 +228,7 @@ AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
jDomKeyLocationField = getField("mDomKeyLocation", "I");
jFlagsField = getField("mFlags", "I");
jUnicodeCharField = getField("mUnicodeChar", "I");
jBaseUnicodeCharField = getField("mBaseUnicodeChar", "I");
jRepeatCountField = getField("mRepeatCount", "I");
jCountField = getField("mCount", "I");
jStartField = getField("mStart", "I");
@ -521,6 +523,7 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
mFlags = jenv->GetIntField(jobj, jFlagsField);
mKeyCode = jenv->GetIntField(jobj, jKeyCodeField);
mUnicodeChar = jenv->GetIntField(jobj, jUnicodeCharField);
mBaseUnicodeChar = jenv->GetIntField(jobj, jBaseUnicodeCharField);
mRepeatCount = jenv->GetIntField(jobj, jRepeatCountField);
ReadCharactersField(jenv);
break;

View File

@ -640,6 +640,7 @@ public:
bool IsMetaPressed() const { return (mMetaState & AndroidKeyEvent::META_META_MASK) != 0; }
int Flags() { return mFlags; }
int UnicodeChar() { return mUnicodeChar; }
int BaseUnicodeChar() { return mBaseUnicodeChar; }
int RepeatCount() const { return mRepeatCount; }
int Count() { return mCount; }
int Start() { return mStart; }
@ -673,7 +674,7 @@ protected:
nsIntRect mRect;
int mFlags, mMetaState;
int mDomKeyLocation;
int mKeyCode, mUnicodeChar;
int mKeyCode, mUnicodeChar, mBaseUnicodeChar;
int mRepeatCount;
int mCount;
int mStart, mEnd;
@ -734,6 +735,7 @@ protected:
static jfieldID jEndField;
static jfieldID jPointerIndexField;
static jfieldID jUnicodeCharField;
static jfieldID jBaseUnicodeCharField;
static jfieldID jRepeatCountField;
static jfieldID jRangeTypeField;
static jfieldID jRangeStylesField;

View File

@ -1482,8 +1482,12 @@ nsWindow::InitKeyEvent(nsKeyEvent& event, AndroidGeckoEvent& key,
if (event.message == NS_KEY_PRESS) {
// Android gives us \n, so filter out some control characters.
event.isChar = (key.UnicodeChar() >= ' ');
event.charCode = event.isChar ? key.UnicodeChar() : 0;
int charCode = key.UnicodeChar();
if (!charCode) {
charCode = key.BaseUnicodeChar();
}
event.isChar = (charCode >= ' ');
event.charCode = event.isChar ? charCode : 0;
event.keyCode = (event.charCode > 0) ? 0 : domKeyCode;
event.pluginEvent = NULL;
} else {
@ -1505,10 +1509,17 @@ nsWindow::InitKeyEvent(nsKeyEvent& event, AndroidGeckoEvent& key,
event.pluginEvent = pluginEvent;
}
event.InitBasicModifiers(gMenu || key.IsCtrlPressed(),
key.IsAltPressed(),
key.IsShiftPressed(),
key.IsMetaPressed());
if (event.message != NS_KEY_PRESS ||
!key.UnicodeChar() || !key.BaseUnicodeChar() ||
key.UnicodeChar() == key.BaseUnicodeChar()) {
// For keypress, if the unicode char already has modifiers applied, we
// don't specify extra modifiers. If UnicodeChar() != BaseUnicodeChar()
// it means UnicodeChar() already has modifiers applied.
event.InitBasicModifiers(gMenu || key.IsCtrlPressed(),
key.IsAltPressed(),
key.IsShiftPressed(),
key.IsMetaPressed());
}
event.location = key.DomKeyLocation();
event.time = key.Time();