From 44dee2b0b02c24d8fd45e7dbc6ff35465075e2d9 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Thu, 17 May 2012 16:04:16 +0900 Subject: [PATCH] Bug 447757 part.4 Clean up modifier keycode mapping on GTK r=karlt, sr=smaug --- content/events/public/nsVKList.h | 3 ++- dom/interfaces/events/nsIDOMKeyEvent.idl | 1 + widget/gtk2/nsGtkKeyUtils.cpp | 30 +++++++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/content/events/public/nsVKList.h b/content/events/public/nsVKList.h index 6c3b82c4305..fca97647ab7 100644 --- a/content/events/public/nsVKList.h +++ b/content/events/public/nsVKList.h @@ -184,7 +184,8 @@ DEFINE_VK_INTERNAL(_BACK_SLASH), DEFINE_VK_INTERNAL(_CLOSE_BRACKET), DEFINE_VK_INTERNAL(_QUOTE), -DEFINE_VK_INTERNAL(_META) +DEFINE_VK_INTERNAL(_META), +DEFINE_VK_INTERNAL(_ALTGR) #undef DEFINE_VK_INTERNAL #undef DEFINE_VK_INTERNAL2 diff --git a/dom/interfaces/events/nsIDOMKeyEvent.idl b/dom/interfaces/events/nsIDOMKeyEvent.idl index b77da56332d..2aaa0e13da0 100644 --- a/dom/interfaces/events/nsIDOMKeyEvent.idl +++ b/dom/interfaces/events/nsIDOMKeyEvent.idl @@ -210,6 +210,7 @@ interface nsIDOMKeyEvent : nsIDOMUIEvent const unsigned long DOM_VK_QUOTE = 0xDE; // Apostrophe const unsigned long DOM_VK_META = 0xE0; + const unsigned long DOM_VK_ALTGR = 0xE1; readonly attribute unsigned long charCode; readonly attribute unsigned long keyCode; diff --git a/widget/gtk2/nsGtkKeyUtils.cpp b/widget/gtk2/nsGtkKeyUtils.cpp index a95a8fbe89d..b60bc391e87 100644 --- a/widget/gtk2/nsGtkKeyUtils.cpp +++ b/widget/gtk2/nsGtkKeyUtils.cpp @@ -89,8 +89,31 @@ static const KeyPair kKeyPairs[] = { { NS_VK_CONTROL, GDK_Control_R }, { NS_VK_ALT, GDK_Alt_L }, { NS_VK_ALT, GDK_Alt_R }, - { NS_VK_META, GDK_Meta_L }, - { NS_VK_META, GDK_Meta_R }, + + // NS_VK_META is used for Command key of Mac. It's a modifier key for + // shortcut keys like Ctrl key on GTK or Windows. So, it's really different + // from GTK's META key, we shouldn't use it on GTK. + // { NS_VK_META, GDK_Meta_L }, + // { NS_VK_META, GDK_Meta_R }, + + // Assume that Super or Hyper is always mapped to physical Win key. + { NS_VK_WIN, GDK_Super_L }, + { NS_VK_WIN, GDK_Super_R }, + { NS_VK_WIN, GDK_Hyper_L }, + { NS_VK_WIN, GDK_Hyper_R }, + + // GTK's AltGraph key is similar to Mac's Option (Alt) key. However, + // unfortunately, browsers on Mac are using NS_VK_ALT for it even though + // it's really different from Alt key on Windows. + // On the other hand, GTK's AltGrapsh keys are really different from + // Alt key. However, there is no AltGrapsh key on Windows. On Windows, + // both Ctrl and Alt keys are pressed internally when AltGr key is pressed. + // For some languages' users, AltGraph key is important, so, web + // applications on such locale may want to know AltGraph key press. + // Therefore, we should map AltGr keycode for them only on GTK. + { NS_VK_ALTGR, GDK_ISO_Level3_Shift }, + { NS_VK_ALTGR, GDK_Mode_switch }, + { NS_VK_PAUSE, GDK_Pause }, { NS_VK_CAPS_LOCK, GDK_Caps_Lock }, { NS_VK_KANA, GDK_Kana_Lock }, @@ -1261,8 +1284,9 @@ KeymapWrapper::IsKeyPressEventNecessary(GdkEventKey* aGdkKeyEvent) switch (ComputeDOMKeyCode(aGdkKeyEvent)) { case NS_VK_SHIFT: case NS_VK_CONTROL: - case NS_VK_META: case NS_VK_ALT: + case NS_VK_ALTGR: + case NS_VK_WIN: case NS_VK_CAPS_LOCK: case NS_VK_NUM_LOCK: case NS_VK_SCROLL_LOCK: