Bug 1306549 part.6 Create KeyboardLayout::ActivateDeadKeyState() r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 16 Sep 2016 19:09:12 +0900
changeset 316363 9be247c306a1250c8416feb2f68d284a5e3f4942
parent 316362 adba65212c35be06d1fb6a46303f1583525fe9bd
child 316364 489e11449d8e62b1eee742090ad177762d9dab2d
push id30770
push userkwierso@gmail.com
push dateWed, 05 Oct 2016 00:00:48 +0000
treeherdermozilla-central@3470e326025c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1306549
milestone52.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 1306549 part.6 Create KeyboardLayout::ActivateDeadKeyState() r=m_kato There is DeactivateDeadKeyState() but not ActivateDeadKeyState(). There should be both of them and hides the dead key state management into them. MozReview-Commit-ID: JvAPE5f2HVy
widget/windows/KeyboardLayout.cpp
widget/windows/KeyboardLayout.h
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -3654,27 +3654,27 @@ KeyboardLayout::InitNativeKey(NativeKey&
   MOZ_ASSERT(aNativeKey.mKeyNameIndex == KEY_NAME_INDEX_USE_STRING,
     "Printable key's key name index must be KEY_NAME_INDEX_USE_STRING");
 
   bool isKeyDown = aNativeKey.IsKeyDownMessage();
 
   if (IsDeadKey(virtualKey, aModKeyState)) {
     if ((isKeyDown && mActiveDeadKey < 0) ||
         (!isKeyDown && mActiveDeadKey == virtualKey)) {
-      //  First dead key event doesn't generate characters.
-      if (isKeyDown) {
-        // Dead-key state activated at keydown.
-        mActiveDeadKey = virtualKey;
-        mDeadKeyShiftState =
-          VirtualKey::ModifierKeyStateToShiftState(aModKeyState);
-      }
+      ActivateDeadKeyState(aNativeKey, aModKeyState);
+#ifdef DEBUG
       UniCharsAndModifiers deadChars =
         GetNativeUniCharsAndModifiers(virtualKey, aModKeyState);
-      NS_ASSERTION(deadChars.mLength == 1,
-                   "dead key must generate only one character");
+      MOZ_ASSERT(deadChars.mLength == 1,
+                 "dead key must generate only one character");
+#endif
+      // First dead key event doesn't generate characters.  Dead key should
+      // cause only keydown event and keyup event whose KeyboardEvent.key
+      // values are "Dead".
+      aNativeKey.mCommittedCharsAndModifiers.Clear();
       aNativeKey.mKeyNameIndex = KEY_NAME_INDEX_Dead;
       return;
     }
 
     // At keydown message handling, we need to forget the first dead key
     // because there is no guarantee coming WM_KEYUP for the second dead
     // key before next WM_KEYDOWN.  E.g., due to auto key repeat or pressing
     // another dead key before releasing current key.  Therefore, we can
@@ -4073,16 +4073,31 @@ KeyboardLayout::EnsureDeadKeyActive(bool
     // >1 - Previous pressed key does not produce any composite characters.
     //      Return dead-key character followed by base character(s).
   } while ((ret < 0) != aIsActive);
 
   return (ret < 0);
 }
 
 void
+KeyboardLayout::ActivateDeadKeyState(const NativeKey& aNativeKey,
+                                     const ModifierKeyState& aModKeyState)
+{
+  // Dead-key state should be activated at keydown.
+  if (!aNativeKey.IsKeyDownMessage()) {
+    return;
+  }
+
+  MOZ_RELEASE_ASSERT(IsPrintableCharKey(aNativeKey.mOriginalVirtualKeyCode));
+
+  mActiveDeadKey = aNativeKey.mOriginalVirtualKeyCode;
+  mDeadKeyShiftState = VirtualKey::ModifierKeyStateToShiftState(aModKeyState);
+}
+
+void
 KeyboardLayout::DeactivateDeadKeyState()
 {
   if (mActiveDeadKey < 0) {
     return;
   }
 
   BYTE kbdState[256];
   memset(kbdState, 0, sizeof(kbdState));
--- a/widget/windows/KeyboardLayout.h
+++ b/widget/windows/KeyboardLayout.h
@@ -636,17 +636,23 @@ private:
                                 DeadKeyEntry* aDeadKeyArray, uint32_t aEntries);
   bool EnsureDeadKeyActive(bool aIsActive, uint8_t aDeadKey,
                              const PBYTE aDeadKeyKbdState);
   uint32_t GetDeadKeyCombinations(uint8_t aDeadKey,
                                   const PBYTE aDeadKeyKbdState,
                                   uint16_t aShiftStatesWithBaseChars,
                                   DeadKeyEntry* aDeadKeyArray,
                                   uint32_t aMaxEntries);
+  /**
+   * Activates or deactivates dead key state.
+   */
+  void ActivateDeadKeyState(const NativeKey& aNativeKey,
+                            const ModifierKeyState& aModKeyState);
   void DeactivateDeadKeyState();
+
   const DeadKeyTable* AddDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
                                       uint32_t aEntries);
   void ReleaseDeadKeyTables();
 
   /**
    * Loads the specified keyboard layout. This method always clear the dead key
    * state.
    */