Bug 1294536 KeyboardLayout::InitNativeKey() shouldn't initialize NativeKey with WM_CHAR whose wParam isn't a printable character r=m_kato a=lizzard
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 22 Aug 2016 14:23:59 +0900
changeset 347965 97c87f3e3854a925376ceab268e37df796cd574d
parent 347964 29375a8f7973425e1e1759fe5608e7a18e4e1f01
child 347966 b0726c0c5d3000060985db919150ccd991c879b5
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato, lizzard
bugs1294536
milestone50.0a2
Bug 1294536 KeyboardLayout::InitNativeKey() shouldn't initialize NativeKey with WM_CHAR whose wParam isn't a printable character r=m_kato a=lizzard 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: