Bug 757688 part.6 Add numpad keys to printable key table and remove KeyboardLayout::IsNumpadKey() r=jimm
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 15 Jun 2012 18:52:50 +0900
changeset 99535 d3bed04319ab696f102d6ebe0399d5c7c55fdc3e
parent 99534 fd9de8d2e181c3ff95b756ee9967d5e7808eb664
child 99536 f5b8c6a545cf633d50b390b07bbf3da3b79023d3
push idunknown
push userunknown
push dateunknown
reviewersjimm
bugs757688
milestone16.0a1
Bug 757688 part.6 Add numpad keys to printable key table and remove KeyboardLayout::IsNumpadKey() r=jimm
widget/windows/KeyboardLayout.cpp
widget/windows/KeyboardLayout.h
widget/windows/nsWindow.cpp
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -529,22 +529,16 @@ KeyboardLayout::~KeyboardLayout()
 
 bool
 KeyboardLayout::IsPrintableCharKey(PRUint8 aVirtualKey)
 {
   return GetKeyIndex(aVirtualKey) >= 0;
 }
 
 bool
-KeyboardLayout::IsNumpadKey(PRUint8 aVirtualKey)
-{
-  return VK_NUMPAD0 <= aVirtualKey && aVirtualKey <= VK_DIVIDE;
-}
-
-bool
 KeyboardLayout::IsDeadKey(PRUint8 aVirtualKey,
                           const ModifierKeyState& aModKeyState) const
 {
   PRInt32 virtualKeyIndex = GetKeyIndex(aVirtualKey);
   if (virtualKeyIndex < 0) {
     return false;
   }
 
@@ -719,21 +713,27 @@ KeyboardLayout::LoadLayout(HKL aLayout)
   }
 
   ::SetKeyboardState(originalKbdState);
 }
 
 inline PRInt32
 KeyboardLayout::GetKeyIndex(PRUint8 aVirtualKey)
 {
-// Currently these 54 (NS_NUM_OF_KEYS) virtual keys are assumed
+// Currently these 68 (NS_NUM_OF_KEYS) virtual keys are assumed
 // to produce visible representation:
 // 0x20 - VK_SPACE          ' '
 // 0x30..0x39               '0'..'9'
 // 0x41..0x5A               'A'..'Z'
+// 0x60..0x69               '0'..'9' on numpad
+// 0x6A - VK_MULTIPLY       '*' on numpad
+// 0x6B - VK_ADD            '+' on numpad
+// 0x6D - VK_SUBTRACT       '-' on numpad
+// 0x6E - VK_DECIMAL        '.' on numpad
+// 0x6F - VK_DIVIDE         '/' on numpad
 // 0x6E - VK_DECIMAL        '.'
 // 0xBA - VK_OEM_1          ';:' for US
 // 0xBB - VK_OEM_PLUS       '+' any country
 // 0xBC - VK_OEM_COMMA      ',' any country
 // 0xBD - VK_OEM_MINUS      '-' any country
 // 0xBE - VK_OEM_PERIOD     '.' any country
 // 0xBF - VK_OEM_2          '/?' for US
 // 0xC0 - VK_OEM_3          '`~' for US
@@ -752,25 +752,25 @@ KeyboardLayout::GetKeyIndex(PRUint8 aVir
   // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
   //-----------------------------------------------------------------------
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,   // 00
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,   // 10
      0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,   // 20
      1,  2,  3,  4,  5,  6,  7,  8,  9, 10, -1, -1, -1, -1, -1, -1,   // 30
     -1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,   // 40
     26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, -1, -1, -1, -1, -1,   // 50
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 37, -1,   // 60
+    37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, -1, 49, 50, 51,   // 60
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,   // 70
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,   // 80
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,   // 90
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,   // A0
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 38, 39, 40, 41, 42, 43,   // B0
-    44, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,   // C0
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 45, 46, 47, 48, 49,   // D0
-    -1, 50, 51, 52, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,   // E0
+    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 52, 53, 54, 55, 56, 57,   // B0
+    58, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,   // C0
+    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 59, 60, 61, 62, 63,   // D0
+    -1, 64, 65, 66, 67, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,   // E0
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1    // F0
   };
 
   return xlat[aVirtualKey];
 }
 
 int
 KeyboardLayout::CompareDeadKeyEntries(const void* aArg1,
--- a/widget/windows/KeyboardLayout.h
+++ b/widget/windows/KeyboardLayout.h
@@ -5,17 +5,17 @@
 
 #ifndef KeyboardLayout_h__
 #define KeyboardLayout_h__
 
 #include "nscore.h"
 #include "nsEvent.h"
 #include <windows.h>
 
-#define NS_NUM_OF_KEYS          54
+#define NS_NUM_OF_KEYS          68
 
 #define VK_OEM_1                0xBA   // ';:' for US
 #define VK_OEM_PLUS             0xBB   // '+' any country
 #define VK_OEM_COMMA            0xBC
 #define VK_OEM_MINUS            0xBD   // '-' any country
 #define VK_OEM_PERIOD           0xBE
 #define VK_OEM_2                0xBF
 #define VK_OEM_3                0xC0
@@ -328,17 +328,16 @@ class KeyboardLayout
                                       PRUint32 aEntries);
   void ReleaseDeadKeyTables();
 
 public:
   KeyboardLayout();
   ~KeyboardLayout();
 
   static bool IsPrintableCharKey(PRUint8 aVirtualKey);
-  static bool IsNumpadKey(PRUint8 aVirtualKey);
 
   /**
    * IsDeadKey() returns true if aVirtualKey is a dead key with aModKeyState.
    * This method isn't stateful.
    */
   bool IsDeadKey(PRUint8 aVirtualKey,
                  const ModifierKeyState& aModKeyState) const;
 
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -6381,129 +6381,93 @@ LRESULT nsWindow::OnKeyDown(const MSG &a
     BOOL result = OnChar(msg, nativeKey, aModKeyState, nsnull, extraFlags);
     // If a syschar keypress wasn't processed, Windows may want to
     // handle it to activate a native menu.
     if (!result && msg.message == WM_SYSCHAR)
       ::DefWindowProcW(mWnd, msg.message, msg.wParam, msg.lParam);
     return result;
   }
   else if (!aModKeyState.IsControl() && !aModKeyState.IsAlt() &&
-             (KeyboardLayout::IsPrintableCharKey(virtualKeyCode) ||
-              KeyboardLayout::IsNumpadKey(virtualKeyCode)))
-  {
+           KeyboardLayout::IsPrintableCharKey(virtualKeyCode)) {
     // If this is simple KeyDown event but next message is not WM_CHAR,
     // this event may not input text, so we should ignore this event.
     // See bug 314130.
     return PluginHasFocus() && noDefault;
   }
 
   if (isDeadKey) {
     return PluginHasFocus() && noDefault;
   }
 
   UniCharsAndModifiers shiftedChars;
   UniCharsAndModifiers unshiftedChars;
   PRUint32 shiftedLatinChar = 0;
   PRUint32 unshiftedLatinChar = 0;
 
-  switch (virtualKeyCode) {
-    // keys to be sent as characters
-    case VK_ADD:
-      inputtingChars.Clear();
-      inputtingChars.Append('+', aModKeyState.GetModifiers());
-      break;
-    case VK_SUBTRACT:
-      inputtingChars.Clear();
-      inputtingChars.Append('-', aModKeyState.GetModifiers());
-      break;
-    case VK_DIVIDE:
-      inputtingChars.Clear();
-      inputtingChars.Append('/', aModKeyState.GetModifiers());
-      break;
-    case VK_MULTIPLY:
-      inputtingChars.Clear();
-      inputtingChars.Append('*', aModKeyState.GetModifiers());
-      break;
-    case VK_NUMPAD0:
-    case VK_NUMPAD1:
-    case VK_NUMPAD2:
-    case VK_NUMPAD3:
-    case VK_NUMPAD4:
-    case VK_NUMPAD5:
-    case VK_NUMPAD6:
-    case VK_NUMPAD7:
-    case VK_NUMPAD8:
-    case VK_NUMPAD9:
-      inputtingChars.Clear();
-      inputtingChars.Append(virtualKeyCode - VK_NUMPAD0 + '0',
-                            aModKeyState.GetModifiers());
-      break;
-    default:
-      if (!KeyboardLayout::IsPrintableCharKey(virtualKeyCode)) {
-        inputtingChars.Clear();
+  if (!KeyboardLayout::IsPrintableCharKey(virtualKeyCode)) {
+    inputtingChars.Clear();
+  }
+
+  if (aModKeyState.IsControl() ^ aModKeyState.IsAlt()) {
+    widget::ModifierKeyState capsLockState(
+      aModKeyState.GetModifiers() & MODIFIER_CAPSLOCK);
+    unshiftedChars =
+      gKbdLayout.GetUniCharsAndModifiers(virtualKeyCode, capsLockState);
+    capsLockState.Set(MODIFIER_SHIFT);
+    shiftedChars =
+      gKbdLayout.GetUniCharsAndModifiers(virtualKeyCode, capsLockState);
+
+    // The current keyboard cannot input alphabets or numerics,
+    // we should append them for Shortcut/Access keys.
+    // E.g., for Cyrillic keyboard layout.
+    capsLockState.Unset(MODIFIER_SHIFT);
+    WidgetUtils::GetLatinCharCodeForKeyCode(DOMKeyCode,
+                                            capsLockState.GetModifiers(),
+                                            &unshiftedLatinChar,
+                                            &shiftedLatinChar);
+
+    // If the shiftedLatinChar isn't 0, the key code is NS_VK_[A-Z].
+    if (shiftedLatinChar) {
+      // If the produced characters of the key on current keyboard layout
+      // are same as computed Latin characters, we shouldn't append the
+      // Latin characters to alternativeCharCode.
+      if (unshiftedLatinChar == unshiftedChars.mChars[0] &&
+          shiftedLatinChar == shiftedChars.mChars[0]) {
+        shiftedLatinChar = unshiftedLatinChar = 0;
       }
-
-      if (aModKeyState.IsControl() ^ aModKeyState.IsAlt()) {
-        widget::ModifierKeyState capsLockState(
-          aModKeyState.GetModifiers() & MODIFIER_CAPSLOCK);
-        unshiftedChars =
-          gKbdLayout.GetUniCharsAndModifiers(virtualKeyCode, capsLockState);
-        capsLockState.Set(MODIFIER_SHIFT);
-        shiftedChars =
-          gKbdLayout.GetUniCharsAndModifiers(virtualKeyCode, capsLockState);
-
-        // The current keyboard cannot input alphabets or numerics,
-        // we should append them for Shortcut/Access keys.
-        // E.g., for Cyrillic keyboard layout.
-        capsLockState.Unset(MODIFIER_SHIFT);
-        WidgetUtils::GetLatinCharCodeForKeyCode(DOMKeyCode,
-                                                capsLockState.GetModifiers(),
-                                                &unshiftedLatinChar,
-                                                &shiftedLatinChar);
-
-        // If the shiftedLatinChar isn't 0, the key code is NS_VK_[A-Z].
-        if (shiftedLatinChar) {
-          // If the produced characters of the key on current keyboard layout
-          // are same as computed Latin characters, we shouldn't append the
-          // Latin characters to alternativeCharCode.
-          if (unshiftedLatinChar == unshiftedChars.mChars[0] &&
-              shiftedLatinChar == shiftedChars.mChars[0]) {
-            shiftedLatinChar = unshiftedLatinChar = 0;
-          }
-        } else if (unshiftedLatinChar) {
-          // If the shiftedLatinChar is 0, the keyCode doesn't produce
-          // alphabet character.  At that time, the character may be produced
-          // with Shift key.  E.g., on French keyboard layout, NS_VK_PERCENT
-          // key produces LATIN SMALL LETTER U WITH GRAVE (U+00F9) without
-          // Shift key but with Shift key, it produces '%'.
-          // If the unshiftedLatinChar is produced by the key on current
-          // keyboard layout, we shouldn't append it to alternativeCharCode.
-          if (unshiftedLatinChar == unshiftedChars.mChars[0] ||
-              unshiftedLatinChar == shiftedChars.mChars[0]) {
-            unshiftedLatinChar = 0;
-          }
-        }
-
-        // If the charCode is not ASCII character, we should replace the
-        // charCode with ASCII character only when Ctrl is pressed.
-        // But don't replace the charCode when the charCode is not same as
-        // unmodified characters. In such case, Ctrl is sometimes used for a
-        // part of character inputting key combination like Shift.
-        if (aModKeyState.IsControl()) {
-          PRUint32 ch =
-            aModKeyState.IsShift() ? shiftedLatinChar : unshiftedLatinChar;
-          if (ch &&
-              (!inputtingChars.mLength ||
-               inputtingChars.UniCharsCaseInsensitiveEqual(
-                 aModKeyState.IsShift() ? shiftedChars : unshiftedChars))) {
-            inputtingChars.Clear();
-            inputtingChars.Append(ch, aModKeyState.GetModifiers());
-          }
-        }
+    } else if (unshiftedLatinChar) {
+      // If the shiftedLatinChar is 0, the keyCode doesn't produce
+      // alphabet character.  At that time, the character may be produced
+      // with Shift key.  E.g., on French keyboard layout, NS_VK_PERCENT
+      // key produces LATIN SMALL LETTER U WITH GRAVE (U+00F9) without
+      // Shift key but with Shift key, it produces '%'.
+      // If the unshiftedLatinChar is produced by the key on current
+      // keyboard layout, we shouldn't append it to alternativeCharCode.
+      if (unshiftedLatinChar == unshiftedChars.mChars[0] ||
+          unshiftedLatinChar == shiftedChars.mChars[0]) {
+        unshiftedLatinChar = 0;
       }
+    }
+
+    // If the charCode is not ASCII character, we should replace the
+    // charCode with ASCII character only when Ctrl is pressed.
+    // But don't replace the charCode when the charCode is not same as
+    // unmodified characters. In such case, Ctrl is sometimes used for a
+    // part of character inputting key combination like Shift.
+    if (aModKeyState.IsControl()) {
+      PRUint32 ch =
+        aModKeyState.IsShift() ? shiftedLatinChar : unshiftedLatinChar;
+      if (ch &&
+          (!inputtingChars.mLength ||
+           inputtingChars.UniCharsCaseInsensitiveEqual(
+             aModKeyState.IsShift() ? shiftedChars : unshiftedChars))) {
+        inputtingChars.Clear();
+        inputtingChars.Append(ch, aModKeyState.GetModifiers());
+      }
+    }
   }
 
   if (inputtingChars.mLength ||
       shiftedChars.mLength || unshiftedChars.mLength) {
     PRUint32 num = NS_MAX(inputtingChars.mLength,
                           NS_MAX(shiftedChars.mLength, unshiftedChars.mLength));
     PRUint32 skipUniChars = num - inputtingChars.mLength;
     PRUint32 skipShiftedChars = num - shiftedChars.mLength;