Bug 842927 part.6 Implement D3E KeyboardEvent.key on GTK r=smaug+karlt
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 24 Apr 2013 12:49:47 +0900
changeset 140654 e8e2a7e4ab5fd0936acffe937f7d9c4dccd2dc4f
parent 140653 e4b70c31bc9e19ee0f1ea616c61111ab874c9c95
child 140655 2c7dc9880f78cf6cb51affa4f380226c18645add
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs842927
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 842927 part.6 Implement D3E KeyboardEvent.key on GTK r=smaug+karlt
widget/gtk2/compat/gdk/gdkkeysyms.h
widget/gtk2/nsGtkKeyUtils.cpp
widget/gtk2/nsGtkKeyUtils.h
new file mode 100644
--- /dev/null
+++ b/widget/gtk2/compat/gdk/gdkkeysyms.h
@@ -0,0 +1,74 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef GDKKEYSYMS_WRAPPER_H
+#define GDKKEYSYMS_WRAPPER_H
+
+#include_next <gdk/gdkkeysyms.h>
+
+#ifndef GDK_ISO_Level5_Shift
+#define GDK_ISO_Level5_Shift    0xFE11
+#endif
+
+#ifndef GDK_ISO_Level5_Latch
+#define GDK_ISO_Level5_Latch    0xFE12
+#endif
+
+#ifndef GDK_ISO_Level5_Lock
+#define GDK_ISO_Level5_Lock     0xFE13
+#endif
+
+#ifndef GDK_dead_greek
+#define GDK_dead_greek          0xFE8C
+#endif
+
+#ifndef GDK_ch
+#define GDK_ch                  0xFEA0
+#endif
+
+#ifndef GDK_Ch
+#define GDK_Ch                  0xFEA1
+#endif
+
+#ifndef GDK_CH
+#define GDK_CH                  0xFEA2
+#endif
+
+#ifndef GDK_c_h
+#define GDK_c_h                 0xFEA3
+#endif
+
+#ifndef GDK_C_h
+#define GDK_C_h                 0xFEA4
+#endif
+
+#ifndef GDK_C_H
+#define GDK_C_H                 0xFEA5
+#endif
+
+#ifndef GDK_TouchpadToggle
+#define GDK_TouchpadToggle      0x1008FFA9
+#endif
+
+#ifndef GDK_TouchpadOn
+#define GDK_TouchpadOn          0x1008FFB0
+#endif
+
+#ifndef GDK_TouchpadOff
+#define GDK_TouchpadOff         0x1008ffb1
+#endif
+
+#ifndef GDK_LogWindowTree
+#define GDK_LogWindowTree       0x1008FE24
+#endif
+
+#ifndef GDK_LogGrabInfo
+#define GDK_LogGrabInfo         0x1008FE25
+#endif
+
+#ifndef GDK_Sleep
+#define GDK_Sleep               0x1008FF2F
+#endif
+
+#endif /* GDKKEYSYMS_WRAPPER_H */
--- a/widget/gtk2/nsGtkKeyUtils.cpp
+++ b/widget/gtk2/nsGtkKeyUtils.cpp
@@ -6,20 +6,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "prlog.h"
 
 #include "nsGtkKeyUtils.h"
 
 #include <gdk/gdkkeysyms.h>
 #include <algorithm>
-#ifndef GDK_Sleep
-#define GDK_Sleep 0x1008ff2f
-#endif
-
 #include <gdk/gdk.h>
 #ifdef MOZ_X11
 #include <gdk/gdkx.h>
 #endif /* MOZ_X11 */
 #if (MOZ_WIDGET_GTK == 3)
 #include <gdk/gdkkeysyms-compat.h>
 #endif
 #include "nsGUIEvent.h"
@@ -816,16 +812,36 @@ KeymapWrapper::ComputeDOMKeyCode(const G
     // shifted character.
     if (!unmodifiedChar && !shiftedChar) {
         return 0;
     }
     return WidgetUtils::ComputeKeyCodeFromChar(
                 unmodifiedChar ? unmodifiedChar : shiftedChar);
 }
 
+KeyNameIndex
+KeymapWrapper::ComputeDOMKeyNameIndex(const GdkEventKey* aGdkKeyEvent)
+{
+    switch (aGdkKeyEvent->keyval) {
+
+#define NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX(aNativeKey, aKeyNameIndex) \
+        case aNativeKey: return aKeyNameIndex;
+
+#include "NativeKeyToDOMKeyName.h"
+
+#undef NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX
+
+        default:
+            break;
+    }
+
+    uint32_t ch = GetCharCodeFor(aGdkKeyEvent);
+    return ch ? KEY_NAME_INDEX_PrintableKey : KEY_NAME_INDEX_Unidentified;
+}
+
 /* static */ guint
 KeymapWrapper::GuessGDKKeyval(uint32_t aDOMKeyCode)
 {
     // First, try to handle alphanumeric input, not listed in nsKeycodes:
     // most likely, more letters will be getting typed in than things in
     // the key list, so we will look through these first.
 
     if (aDOMKeyCode >= NS_VK_A && aDOMKeyCode <= NS_VK_Z) {
@@ -904,16 +920,18 @@ KeymapWrapper::GuessGDKKeyval(uint32_t a
 }
 
 /* static */ void
 KeymapWrapper::InitKeyEvent(nsKeyEvent& aKeyEvent,
                             GdkEventKey* aGdkKeyEvent)
 {
     KeymapWrapper* keymapWrapper = GetInstance();
 
+    aKeyEvent.mKeyNameIndex =
+        keymapWrapper->ComputeDOMKeyNameIndex(aGdkKeyEvent);
     aKeyEvent.keyCode = ComputeDOMKeyCode(aGdkKeyEvent);
 
     // NOTE: The state of given key event indicates adjacent state of
     // modifier keys.  E.g., even if the event is Shift key press event,
     // the bit for Shift is still false.  By the same token, even if the
     // event is Shift key release event, the bit for Shift is still true.
     // Unfortunately, gdk_keyboard_get_modifiers() returns current modifier
     // state.  It means if there're some pending modifier key press or
--- a/widget/gtk2/nsGtkKeyUtils.h
+++ b/widget/gtk2/nsGtkKeyUtils.h
@@ -8,23 +8,16 @@
 #ifndef __nsGdkKeyUtils_h__
 #define __nsGdkKeyUtils_h__
 
 #include "nsEvent.h"
 #include "nsTArray.h"
 
 #include <gdk/gdk.h>
 
-// ISO level5 shift is supported on GTK3
-#ifndef GDK_ISO_Level5_Shift
-#define GDK_ISO_Level5_Shift 0xFE11
-#define GDK_ISO_Level5_Latch 0xFE12
-#define GDK_ISO_Level5_Lock  0xFE13
-#endif // #ifndef GDK_ISO_Level5_Shift
-
 namespace mozilla {
 namespace widget {
 
 /**
  *  KeymapWrapper is a wrapper class of GdkKeymap.  GdkKeymap doesn't support
  *  all our needs, therefore, we need to access lower level APIs.
  *  But such code is usually complex and might be slow.  Against such issues,
  *  we should cache some information.
@@ -38,16 +31,21 @@ class KeymapWrapper
 {
 public:
     /**
      * Compute an our DOM keycode from a GDK keyval.
      */
     static uint32_t ComputeDOMKeyCode(const GdkEventKey* aGdkKeyEvent);
 
     /**
+     * Compute a DOM key name index from aGdkKeyEvent.
+     */
+    KeyNameIndex ComputeDOMKeyNameIndex(const GdkEventKey* aGdkKeyEvent);
+
+    /**
      * Returns a GDK keyval which is related to the aDOMKeyCode.  However,
      * it may not be same as original value since there are some lost
      * information.
      */
     static guint GuessGDKKeyval(uint32_t aDOMKeyCode);
 
     /**
      * Modifier is list of modifiers which we support in widget level.