提交 0a6ebff0 编写于 作者: L leonidr

7160951: ActionListener called twice for JMenuItem using ScreenMenuBar

Reviewed-by: anthony, serb
Contributed-by: NMarco Dinacci <marco.dinacci@gmail.com>
上级 c6552bbb
......@@ -33,5 +33,7 @@ void DeliverJavaKeyEvent(JNIEnv *env, NSEvent *event, jobject peer);
void DeliverJavaMouseEvent(JNIEnv *env, NSEvent *event, jobject peer);
void SendAdditionalJavaEvents(JNIEnv *env, NSEvent *nsEvent, jobject peer);
jint GetJavaMouseModifiers(NSInteger button, NSUInteger modifierFlags);
jint NsKeyModifiersToJavaModifiers(NSUInteger nsFlags, BOOL isExtMods);
NSUInteger JavaModifiersToNsKeyModifiers(jint javaModifiers, BOOL isExtMods);
#endif /* __AWTEVENT_H */
......@@ -245,6 +245,7 @@ static struct _nsKeyToJavaModifier
//NSUInteger cgsRightMask;
unsigned short leftKeyCode;
unsigned short rightKeyCode;
jint javaExtMask;
jint javaMask;
jint javaKey;
}
......@@ -255,6 +256,7 @@ const nsKeyToJavaModifierTable[] =
0,
0,
0, // no Java equivalent
0, // no Java equivalent
java_awt_event_KeyEvent_VK_CAPS_LOCK
},
{
......@@ -264,6 +266,7 @@ const nsKeyToJavaModifierTable[] =
56,
60,
java_awt_event_InputEvent_SHIFT_DOWN_MASK,
java_awt_event_InputEvent_SHIFT_MASK,
java_awt_event_KeyEvent_VK_SHIFT
},
{
......@@ -273,6 +276,7 @@ const nsKeyToJavaModifierTable[] =
59,
62,
java_awt_event_InputEvent_CTRL_DOWN_MASK,
java_awt_event_InputEvent_CTRL_MASK,
java_awt_event_KeyEvent_VK_CONTROL
},
{
......@@ -282,6 +286,7 @@ const nsKeyToJavaModifierTable[] =
58,
61,
java_awt_event_InputEvent_ALT_DOWN_MASK,
java_awt_event_InputEvent_ALT_MASK,
java_awt_event_KeyEvent_VK_ALT
},
{
......@@ -291,6 +296,7 @@ const nsKeyToJavaModifierTable[] =
55,
54,
java_awt_event_InputEvent_META_DOWN_MASK,
java_awt_event_InputEvent_META_MASK,
java_awt_event_KeyEvent_VK_META
},
// NSNumericPadKeyMask
......@@ -299,10 +305,11 @@ const nsKeyToJavaModifierTable[] =
0,
0,
0, // no Java equivalent
0, // no Java equivalent
java_awt_event_KeyEvent_VK_HELP
},
// NSFunctionKeyMask
{0, 0, 0, 0, 0}
{0, 0, 0, 0, 0, 0}
};
/*
......@@ -533,25 +540,51 @@ NsKeyModifiersToJavaKeyInfo(NSUInteger nsFlags, unsigned short eventKeyCode,
/*
* This returns the java modifiers for a key NSEvent.
*/
static jint
NsKeyModifiersToJavaModifiers(NSUInteger nsFlags)
jint NsKeyModifiersToJavaModifiers(NSUInteger nsFlags, BOOL isExtMods)
{
jint javaModifiers = 0;
const struct _nsKeyToJavaModifier* cur;
for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
if ((cur->nsMask & nsFlags) != 0) {
javaModifiers |= cur->javaMask;
javaModifiers |= isExtMods? cur->javaExtMask : cur->javaMask;
}
}
return javaModifiers;
}
/*
* This returns the NSEvent flags for java key modifiers.
*/
NSUInteger JavaModifiersToNsKeyModifiers(jint javaModifiers, BOOL isExtMods)
{
NSUInteger nsFlags = 0;
const struct _nsKeyToJavaModifier* cur;
for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
jint mask = isExtMods? cur->javaExtMask : cur->javaMask;
if ((mask & javaModifiers) != 0) {
nsFlags |= cur->nsMask;
}
}
// special case
jint mask = isExtMods? java_awt_event_InputEvent_ALT_GRAPH_DOWN_MASK :
java_awt_event_InputEvent_ALT_GRAPH_MASK;
if ((mask & javaModifiers) != 0) {
nsFlags |= NSAlternateKeyMask;
}
return nsFlags;
}
jint GetJavaMouseModifiers(NSInteger button, NSUInteger modifierFlags)
{
// Mousing needs the key modifiers
jint modifiers = NsKeyModifiersToJavaModifiers(modifierFlags);
jint modifiers = NsKeyModifiersToJavaModifiers(modifierFlags, YES);
/*
......@@ -632,7 +665,7 @@ Java_sun_lwawt_macosx_event_NSEvent_nsToJavaKeyModifiers
JNF_COCOA_ENTER(env);
jmodifiers = NsKeyModifiersToJavaModifiers(modifierFlags);
jmodifiers = NsKeyModifiersToJavaModifiers(modifierFlags, YES);
JNF_COCOA_EXIT(env);
......
......@@ -460,7 +460,7 @@ static BOOL sNeedsEnter;
}
// Convert fModifiers (extModifiers) to NS:
NSUInteger modifiers = [DnDUtilities mapJavaExtModifiersToNSKeyModifiers:fModifiers];
NSUInteger modifiers = JavaModifiersToNsKeyModifiers(fModifiers, TRUE);
// Just a dummy value ...
NSInteger eventNumber = 0;
......@@ -658,7 +658,7 @@ JNF_COCOA_ENTER(env);
}
// b) drag actions (key modifiers) have changed:
jint modifiers = [DnDUtilities currentJavaExtKeyModifiers];
jint modifiers = NsKeyModifiersToJavaModifiers([NSEvent modifierFlags], YES);
if (fDragKeyModifiers != modifiers) {
NSDragOperation currentOp = [DnDUtilities nsDragOperationForModifiers:[NSEvent modifierFlags]];
NSDragOperation allowedOp = [DnDUtilities mapJavaDragOperationToNS:fSourceActions] & currentOp;
......
......@@ -70,6 +70,18 @@ AWT_ASSERT_APPKIT_THREAD;
JNIEnv *env = [ThreadUtilities getJNIEnv];
JNF_COCOA_ENTER(env);
// If we are called as a result of user pressing a shorcut, do nothing,
// because AVTView has already sent corresponding key event to the Java
// layer from performKeyEquivalent
NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
if ([currEvent type] == NSKeyDown) {
NSString *menuKey = [sender keyEquivalent];
NSString *eventKey = [currEvent characters];
if ([menuKey isEqualToString:eventKey]) {
return;
}
}
if (fIsCheckbox) {
static JNF_CLASS_CACHE(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem");
static JNF_MEMBER_CACHE(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V");
......@@ -83,14 +95,8 @@ JNF_COCOA_ENTER(env);
static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event)
NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
NSUInteger modifiers = [currEvent modifierFlags];
jint javaModifiers = 0;
if ((modifiers & NSCommandKeyMask) != 0) javaModifiers |= java_awt_Event_META_MASK;
if ((modifiers & NSShiftKeyMask) != 0) javaModifiers |= java_awt_Event_SHIFT_MASK;
if ((modifiers & NSControlKeyMask) != 0) javaModifiers |= java_awt_Event_CTRL_MASK;
if ((modifiers & NSAlternateKeyMask) != 0) javaModifiers |= java_awt_Event_ALT_MASK;
jint javaModifiers = NsKeyModifiersToJavaModifiers(modifiers, NO);
JNFCallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
}
......@@ -117,10 +123,7 @@ AWT_ASSERT_NOT_APPKIT_THREAD;
modifiers &= ~java_awt_event_KeyEvent_SHIFT_MASK;
}
if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) != 0) modifierMask |= NSShiftKeyMask;
if ((modifiers & java_awt_event_KeyEvent_CTRL_MASK) != 0) modifierMask |= NSControlKeyMask;
if ((modifiers & java_awt_event_KeyEvent_ALT_MASK) != 0) modifierMask |= NSAlternateKeyMask;
if ((modifiers & java_awt_event_KeyEvent_META_MASK) != 0) modifierMask |= NSCommandKeyMask;
modifierMask = JavaModifiersToNsKeyModifiers(modifiers, NO);
}
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
......
......@@ -42,7 +42,6 @@
+ (jint)narrowJavaDropActions:(jint)actions;
// Mouse and key modifiers mapping:
+ (NSUInteger)mapJavaExtModifiersToNSKeyModifiers:(jint)modifiers;
+ (NSUInteger)mapJavaExtModifiersToNSMouseDownButtons:(jint)modifiers;
+ (NSUInteger)mapJavaExtModifiersToNSMouseUpButtons:(jint)modifiers;
......@@ -50,9 +49,6 @@
+ (jint)extractJavaExtKeyModifiersFromJavaExtModifiers:(jint)modifiers;
+ (jint)extractJavaExtMouseModifiersFromJavaExtModifiers:(jint)modifiers;
// Get the current keyboard modifier keys as java modifiers (for operationChanged)
+ (jint)currentJavaExtKeyModifiers;
// Getting the state of the current Drag
+ (NSDragOperation)nsDragOperationForModifiers:(NSUInteger)modifiers;
+ (jint) javaKeyModifiersForNSDragOperation:(NSDragOperation)dragOp;
......
......@@ -161,28 +161,6 @@ There are several problems with Drag and Drop - notably, the mismatch between Ja
}
// Mouse and key modifiers mapping:
+ (NSUInteger)mapJavaExtModifiersToNSKeyModifiers:(jint)modifiers
{
NSUInteger result = 0;
if ((modifiers & java_awt_event_InputEvent_SHIFT_DOWN_MASK) != 0)
result |= NSShiftKeyMask;
if ((modifiers & java_awt_event_InputEvent_CTRL_DOWN_MASK) != 0)
result |= NSControlKeyMask;
if ((modifiers & java_awt_event_InputEvent_META_DOWN_MASK) != 0)
result |= NSCommandKeyMask;
if ((modifiers & java_awt_event_InputEvent_ALT_DOWN_MASK) != 0)
result |= NSAlternateKeyMask;
if ((modifiers & java_awt_event_InputEvent_ALT_GRAPH_DOWN_MASK) != 0)
result |= NSAlternateKeyMask;
return result;
}
+ (NSUInteger)mapJavaExtModifiersToNSMouseDownButtons:(jint)modifiers
{
NSUInteger result = NSLeftMouseDown;
......@@ -245,32 +223,6 @@ There are several problems with Drag and Drop - notably, the mismatch between Ja
return modifiers & mask;
}
+ (jint)currentJavaExtKeyModifiers
{
NSUInteger modifiers = [NSEvent modifierFlags];
jint jmodifiers = 0;
if(modifiers & NSShiftKeyMask) {
jmodifiers |= java_awt_event_InputEvent_SHIFT_DOWN_MASK;
}
if(modifiers & NSControlKeyMask) {
jmodifiers |= java_awt_event_InputEvent_CTRL_DOWN_MASK;
}
if(modifiers & NSAlternateKeyMask) {
jmodifiers |= java_awt_event_InputEvent_ALT_DOWN_MASK;
}
if(modifiers & NSCommandKeyMask) {
jmodifiers |= java_awt_event_InputEvent_META_DOWN_MASK;
}
return jmodifiers;
}
+ (NSDragOperation) nsDragOperationForModifiers:(NSUInteger)modifiers {
// Java first
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册