Bug 1306549 part.2 Create overload methods which take ModifierKeyState instead of VirtualKey::ShiftState r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 30 Sep 2016 15:32:10 +0900
changeset 420502 771247191a87e9388dfa1841a3aaf9a91ceb22b0
parent 420501 52db3256c73603fd3b4b36d3b4ade14228575ac0
child 420503 5a24c8c4bfaa75ffd7c9c5a72ed2476699a94291
push id31215
push usermasayuki@d-toybox.com
push dateTue, 04 Oct 2016 07:44:41 +0000
reviewersm_kato
bugs1306549
milestone52.0a1
Bug 1306549 part.2 Create overload methods which take ModifierKeyState instead of VirtualKey::ShiftState r?m_kato This patch gets rid of |shiftState| from KeyboardLayout::InitNativeKey() and make each caller clearer. This must make other developers understand what modifier state is used at each call. MozReview-Commit-ID: 6zydP1jkffv
widget/windows/KeyboardLayout.cpp
widget/windows/KeyboardLayout.h
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -3648,44 +3648,43 @@ KeyboardLayout::InitNativeKey(NativeKey&
   }
 
   MOZ_ASSERT(virtualKey != VK_PACKET,
     "At handling VK_PACKET, we shouldn't refer keyboard layout");
   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();
-  uint8_t shiftState =
-    VirtualKey::ModifiersToShiftState(aModKeyState.GetModifiers());
 
   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 = shiftState;
+        mDeadKeyShiftState =
+          VirtualKey::ModifierKeyStateToShiftState(aModKeyState);
       }
       UniCharsAndModifiers deadChars =
-        mVirtualKeys[virtualKeyIndex].GetNativeUniChars(shiftState);
+        mVirtualKeys[virtualKeyIndex].GetNativeUniChars(aModKeyState);
       NS_ASSERTION(deadChars.mLength == 1,
                    "dead key must generate only one character");
       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
     // set only a character for current key for keyup event.
     if (mActiveDeadKey < 0) {
       aNativeKey.mCommittedCharsAndModifiers =
-        mVirtualKeys[virtualKeyIndex].GetUniChars(shiftState);
+        mVirtualKeys[virtualKeyIndex].GetUniChars(aModKeyState);
       return;
     }
 
     int32_t activeDeadKeyIndex = GetKeyIndex(mActiveDeadKey);
     if (activeDeadKeyIndex < 0 || activeDeadKeyIndex >= NS_NUM_OF_KEYS) {
 #if defined(DEBUG) || defined(MOZ_CRASHREPORTER)
       nsPrintfCString warning("The virtual key index (%d) of mActiveDeadKey "
                               "(0x%02X) is not a printable key (virtualKey="
@@ -3706,31 +3705,31 @@ KeyboardLayout::InitNativeKey(NativeKey&
       return;
     }
 
     // Otherwise, dead key followed by another dead key causes inputting both
     // character.
     UniCharsAndModifiers prevDeadChars =
       mVirtualKeys[activeDeadKeyIndex].GetUniChars(mDeadKeyShiftState);
     UniCharsAndModifiers newChars =
-      mVirtualKeys[virtualKeyIndex].GetUniChars(shiftState);
+      mVirtualKeys[virtualKeyIndex].GetUniChars(aModKeyState);
     // But keypress events should be fired for each committed character.
     aNativeKey.mCommittedCharsAndModifiers = prevDeadChars + newChars;
     if (isKeyDown) {
       DeactivateDeadKeyState();
     }
     return;
   }
 
   if (MaybeInitNativeKeyWithCompositeChar(aNativeKey, aModKeyState)) {
     return;
   }
 
   UniCharsAndModifiers baseChars =
-    mVirtualKeys[virtualKeyIndex].GetUniChars(shiftState);
+    mVirtualKeys[virtualKeyIndex].GetUniChars(aModKeyState);
   if (mActiveDeadKey < 0) {
     // No dead-keys are active. Just return the produced characters.
     aNativeKey.mCommittedCharsAndModifiers = baseChars;
     return;
   }
 
   int32_t activeDeadKeyIndex = GetKeyIndex(mActiveDeadKey);
   if (NS_WARN_IF(activeDeadKeyIndex < 0)) {
@@ -3741,18 +3740,16 @@ KeyboardLayout::InitNativeKey(NativeKey&
   // Return dead-key character followed by base character.
   UniCharsAndModifiers deadChars =
     mVirtualKeys[activeDeadKeyIndex].GetUniChars(mDeadKeyShiftState);
   // But keypress events should be fired for each committed character.
   aNativeKey.mCommittedCharsAndModifiers = deadChars + baseChars;
   if (isKeyDown) {
     DeactivateDeadKeyState();
   }
-
-  return;
 }
 
 bool
 KeyboardLayout::MaybeInitNativeKeyWithCompositeChar(
                   NativeKey& aNativeKey,
                   const ModifierKeyState& aModKeyState)
 {
   if (mActiveDeadKey < 0) {
@@ -3764,21 +3761,18 @@ KeyboardLayout::MaybeInitNativeKeyWithCo
     return false;
   }
 
   int32_t virtualKeyIndex = GetKeyIndex(aNativeKey.mOriginalVirtualKeyCode);
   if (NS_WARN_IF(virtualKeyIndex < 0)) {
     return false;
   }
 
-  uint8_t shiftState =
-    VirtualKey::ModifiersToShiftState(aModKeyState.GetModifiers());
-
   UniCharsAndModifiers baseChars =
-    mVirtualKeys[virtualKeyIndex].GetUniChars(shiftState);
+    mVirtualKeys[virtualKeyIndex].GetUniChars(aModKeyState);
   if (baseChars.IsEmpty() || !baseChars.mChars[0]) {
     return false;
   }
 
   char16_t compositeChar =
     mVirtualKeys[activeDeadKeyIndex].GetCompositeChar(mDeadKeyShiftState,
                                                       baseChars.mChars[0]);
   if (!compositeChar) {
--- a/widget/windows/KeyboardLayout.h
+++ b/widget/windows/KeyboardLayout.h
@@ -113,16 +113,21 @@ public:
     STATE_CONTROL  = 0x02,
     STATE_ALT      = 0x04,
     STATE_CAPSLOCK = 0x08
   };
 
   typedef uint8_t ShiftState;
 
   static ShiftState ModifiersToShiftState(Modifiers aModifiers);
+  static ShiftState ModifierKeyStateToShiftState(
+                      const ModifierKeyState& aModKeyState)
+  {
+    return ModifiersToShiftState(aModKeyState.GetModifiers());
+  }
   static Modifiers ShiftStateToModifiers(ShiftState aShiftState);
 
 private:
   union KeyShiftState
   {
     struct
     {
       char16_t Chars[4];
@@ -162,18 +167,33 @@ public:
 
   void SetNormalChars(ShiftState aShiftState, const char16_t* aChars,
                       uint32_t aNumOfChars);
   void SetDeadChar(ShiftState aShiftState, char16_t aDeadChar);
   const DeadKeyTable* MatchingDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
                                            uint32_t aEntries) const;
   inline char16_t GetCompositeChar(ShiftState aShiftState,
                                     char16_t aBaseChar) const;
+  char16_t GetCompositeChar(const ModifierKeyState& aModKeyState,
+                            char16_t aBaseChar) const
+  {
+    return GetCompositeChar(ModifierKeyStateToShiftState(aModKeyState),
+                            aBaseChar);
+  }
   UniCharsAndModifiers GetNativeUniChars(ShiftState aShiftState) const;
+  UniCharsAndModifiers GetNativeUniChars(
+                         const ModifierKeyState& aModKeyState) const
+  {
+    return GetNativeUniChars(ModifierKeyStateToShiftState(aModKeyState));
+  }
   UniCharsAndModifiers GetUniChars(ShiftState aShiftState) const;
+  UniCharsAndModifiers GetUniChars(const ModifierKeyState& aModKeyState) const
+  {
+    return GetUniChars(ModifierKeyStateToShiftState(aModKeyState));
+  }
 };
 
 class MOZ_STACK_CLASS NativeKey final
 {
   friend class KeyboardLayout;
 
 public:
   struct FakeCharMsg