Bug 1294536 part.1 KeyboardLayout::InitNativeKey() shouldn't initialize Native key with WM_CHAR whose wParam isn't a printable character r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 22 Aug 2016 14:23:59 +0900
changeset 405258 d971f53c919de9ea678e16b0675186b3f45ed941
parent 404651 bd7645928990649c84609d3f531e803c2d41f269
child 405259 917a12bfaaa915db4e8bcb9139c55e9b1bf5ca45
push id27449
push usermasayuki@d-toybox.com
push dateThu, 25 Aug 2016 06:10:59 +0000
reviewersm_kato
bugs1294536
milestone51.0a1
Bug 1294536 part.1 KeyboardLayout::InitNativeKey() shouldn't initialize Native key with WM_CHAR whose wParam isn't a printable character r?m_kato KeyboardEvent::InitNativeKey() should initialize NativeKey if it's created for handling an orphan WM_CHAR message, however, if it the charCode isn't a printable character such as 0x0D for Enter key, it shouldn't refer it because focused editor shouldn't handle keyboard event as inputting the non-printable character. MozReview-Commit-ID: FwTdGqhPEld
widget/windows/KeyboardLayout.cpp
widget/windows/KeyboardLayout.h
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -1024,18 +1024,19 @@ NativeKey::InitWithAppCommand()
   mDOMKeyCode =
     KeyboardLayout::GetInstance()->
       ConvertNativeKeyCodeToDOMKeyCode(mOriginalVirtualKeyCode);
   mCodeNameIndex =
     KeyboardLayout::ConvertScanCodeToCodeNameIndex(
       GetScanCodeWithExtendedFlag());
 }
 
+// static
 bool
-NativeKey::IsControlChar(char16_t aChar) const
+NativeKey::IsControlChar(char16_t aChar)
 {
   static const char16_t U_SPACE = 0x20;
   return aChar < U_SPACE;
 }
 
 bool
 NativeKey::IsFollowedByDeadCharMessage() const
 {
@@ -2528,25 +2529,25 @@ KeyboardLayout::InitNativeKey(NativeKey&
   if (mIsPendingToRestoreKeyboardLayout) {
     LoadLayout(::GetKeyboardLayout(0));
   }
 
   // If the aNativeKey is initialized with WM_CHAR, the key information
   // should be discarded because mKeyValue should have the string to be
   // inputted.
   if (aNativeKey.mMsg.message == WM_CHAR) {
-    aNativeKey.mKeyNameIndex = KEY_NAME_INDEX_USE_STRING;
-    if (aNativeKey.mMsg.wParam) {
-      aNativeKey.mCommittedCharsAndModifiers.Append(
-        static_cast<char16_t>(aNativeKey.mMsg.wParam),
-        aModKeyState.GetModifiers());
-    } else {
-      aNativeKey.mCommittedCharsAndModifiers.Clear();
+    char16_t ch = static_cast<char16_t>(aNativeKey.mMsg.wParam);
+    // But don't set key value as printable key if the character is a control
+    // character such as 0x0D at pressing Enter key.
+    if (!NativeKey::IsControlChar(ch)) {
+      aNativeKey.mKeyNameIndex = KEY_NAME_INDEX_USE_STRING;
+      aNativeKey.mCommittedCharsAndModifiers.
+        Append(ch, aModKeyState.GetModifiers());
+      return;
     }
-    return;
   }
 
   uint8_t virtualKey = aNativeKey.mOriginalVirtualKeyCode;
   int32_t virtualKeyIndex = GetKeyIndex(virtualKey);
 
   if (virtualKeyIndex < 0) {
     // Does not produce any printable characters, but still preserves the
     // dead-key state.
--- a/widget/windows/KeyboardLayout.h
+++ b/widget/windows/KeyboardLayout.h
@@ -239,16 +239,22 @@ public:
 
   /**
    * Callback of TextEventDispatcherListener::WillDispatchKeyboardEvent().
    * This method sets alternative char codes of aKeyboardEvent.
    */
   void WillDispatchKeyboardEvent(WidgetKeyboardEvent& aKeyboardEvent,
                                  uint32_t aIndex);
 
+  /**
+   * Returns true if aChar is a control character which shouldn't be inputted
+   * into focused text editor.
+   */
+  static bool IsControlChar(char16_t aChar);
+
 private:
   RefPtr<nsWindowBase> mWidget;
   RefPtr<TextEventDispatcher> mDispatcher;
   HKL mKeyboardLayout;
   MSG mMsg;
 
   uint32_t mDOMKeyCode;
   KeyNameIndex mKeyNameIndex;
@@ -311,22 +317,16 @@ private:
   NativeKey()
   {
     MOZ_CRASH("The default constructor of NativeKey isn't available");
   }
 
   void InitWithAppCommand();
 
   /**
-   * Returns true if aChar is a control character which shouldn't be inputted
-   * into focused text editor.
-   */
-  bool IsControlChar(char16_t aChar) const;
-
-  /**
    * Returns true if the key event is caused by auto repeat.
    */
   bool IsRepeat() const
   {
     switch (mMsg.message) {
       case WM_KEYDOWN:
       case WM_SYSKEYDOWN:
       case WM_CHAR: