Bug 892606 part.1 Add debug logs to KeyboardLayout.cpp r=jimm, a=akeybl
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 19 Aug 2013 14:16:55 +0900
changeset 153782 17163b62e57cbc272ae1aa8cf1517a949963fccc
parent 153781 34daf22f7fb24cecc06c41ba3c58775c75bd8232
child 153783 d1c0efe3bdee7162e15656e0504bf9b212d77975
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, akeybl
bugs892606
milestone25.0a2
Bug 892606 part.1 Add debug logs to KeyboardLayout.cpp r=jimm, a=akeybl
widget/windows/KeyboardLayout.cpp
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -323,16 +323,25 @@ VirtualKey::GetUniChars(ShiftState aShif
   }
   return result;
 }
 
 
 UniCharsAndModifiers
 VirtualKey::GetNativeUniChars(ShiftState aShiftState) const
 {
+#ifdef DEBUG
+  if (aShiftState < 0 || aShiftState >= ArrayLength(mShiftStates)) {
+    nsPrintfCString warning("Shift state is out of range: "
+                            "aShiftState=%d, ArrayLength(mShiftState)=%d",
+                            aShiftState, ArrayLength(mShiftStates));
+    NS_WARNING(warning.get());
+  }
+#endif
+
   UniCharsAndModifiers result;
   Modifiers modifiers = ShiftStateToModifiers(aShiftState);
   if (IsDeadKey(aShiftState)) {
     result.Append(mShiftStates[aShiftState].DeadKey.DeadChar, modifiers);
     return result;
   }
 
   uint32_t index;
@@ -542,16 +551,17 @@ NativeKey::NativeKey(nsWindowBase* aWidg
     case WM_SYSCHAR:
       // We cannot compute the virtual key code from WM_CHAR message on WinXP
       // if it's caused by an extended key.
       if (!canComputeVirtualKeyCodeFromScanCode) {
         break;
       }
       mVirtualKeyCode = mOriginalVirtualKeyCode =
         ComputeVirtualKeyCodeFromScanCodeEx();
+      NS_ASSERTION(mVirtualKeyCode, "Failed to compute virtual keycode");
       break;
     default:
       MOZ_CRASH("Unsupported message");
   }
 
   if (!mVirtualKeyCode) {
     mVirtualKeyCode = mOriginalVirtualKeyCode;
   }
@@ -1480,16 +1490,25 @@ KeyboardLayout::InitNativeKey(NativeKey&
       aNativeKey.mKeyNameIndex =
         WidgetUtils::GetDeadKeyNameIndex(deadChars.mChars[0]);
       return;
     }
 
     // Dead-key followed by another dead-key. Reset dead-key state and
     // return both dead-key characters.
     int32_t activeDeadKeyIndex = GetKeyIndex(mActiveDeadKey);
+#ifdef DEBUG
+    if (activeDeadKeyIndex < 0 || activeDeadKeyIndex >= NS_NUM_OF_KEYS) {
+      nsPrintfCString warning("The virtual key index (%d) of mActiveDeadKey "
+                              "(0x%02X) is not a printable key (virtualKey="
+                              "0x%02X)",
+                              activeDeadKeyIndex, mActiveDeadKey, virtualKey);
+      NS_WARNING(warning.get());
+    }
+#endif
     UniCharsAndModifiers prevDeadChars =
       mVirtualKeys[activeDeadKeyIndex].GetUniChars(mDeadKeyShiftState);
     UniCharsAndModifiers newChars =
       mVirtualKeys[virtualKeyIndex].GetUniChars(shiftState);
     // But keypress events should be fired for each committed character.
     aNativeKey.mCommittedCharsAndModifiers = prevDeadChars + newChars;
     if (isKeyDown) {
       DeactivateDeadKeyState();
@@ -2056,19 +2075,28 @@ KeyboardLayout::ConvertNativeKeyCodeToDO
 
     // VK_PROCESSKEY means IME already consumed the key event.
     case VK_PROCESSKEY:
       return 0;
     // VK_PACKET is generated by SendInput() API, we don't need to
     // care this message as key event.
     case VK_PACKET:
       return 0;
+    // If a key is not mapped to a virtual keycode, 0xFF is used.
+    case 0xFF:
+      NS_WARNING("The key is failed to be converted to a virtual keycode");
+      return 0;
   }
-  NS_WARNING("Unknown key code comes, please check latest MSDN document,"
-             " there may be some new keycodes we have not known.");
+#ifdef DEBUG
+  nsPrintfCString warning("Unknown virtual keycode (0x%08X), please check the "
+                          "latest MSDN document, there may be some new "
+                          "keycodes we've never known.",
+                          aNativeKeyCode);
+  NS_WARNING(warning.get());
+#endif
   return 0;
 }
 
 KeyNameIndex
 KeyboardLayout::ConvertNativeKeyCodeToKeyNameIndex(uint8_t aVirtualKey) const
 {
 #define NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX(aNativeKey, aKeyNameIndex)
 #define NS_JAPANESE_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX(aNativeKey, aKeyNameIndex)