Bug 1306549 part.8 Get rid of |virtualKey| and |isKeyDown| from KeyboardLayout::InitNativeKey() and KeyboardLayout::MaybeInitNativeKeyAsDeadKey() r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 30 Sep 2016 15:40:40 +0900
changeset 420508 91797ac8856baa332f14c5c9d6b84cb21ef94563
parent 420507 109f99fe41eeaf739665af8497fee40b31b0a695
child 420509 bdb4eb549f6b94f7b62453ef43dad98857d125c2
push id31215
push usermasayuki@d-toybox.com
push dateTue, 04 Oct 2016 07:44:41 +0000
reviewersm_kato
bugs1306549
milestone52.0a1
Bug 1306549 part.8 Get rid of |virtualKey| and |isKeyDown| from KeyboardLayout::InitNativeKey() and KeyboardLayout::MaybeInitNativeKeyAsDeadKey() r?m_kato For preventing wrapping long lines, old KeyboardLayout::InitNativeKey() uses two variables |virtualKey| and |isKeyDown| which are never modified. However, they may be not clear for some developers where they came from. Additionally, preceding patches reduced a lot of users of them and indent level. Therefore, even if we remove these variables, we don't need additional line breaks in most cases. So, removing them is better for easier to understand. MozReview-Commit-ID: 680bYVINPAE
widget/windows/KeyboardLayout.cpp
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -3633,49 +3633,45 @@ KeyboardLayout::InitNativeKey(NativeKey&
     if (!NativeKey::IsControlChar(ch)) {
       aNativeKey.mKeyNameIndex = KEY_NAME_INDEX_USE_STRING;
       aNativeKey.mCommittedCharsAndModifiers.
         Append(ch, aModKeyState.GetModifiers());
       return;
     }
   }
 
-  uint8_t virtualKey = aNativeKey.mOriginalVirtualKeyCode;
-
   // If the key is not a usual printable key, KeyboardLayout class assume that
   // it's not cause dead char nor printable char.  Therefore, there are nothing
   // to do here fore such keys (e.g., function keys).
   // However, this should keep dead key state even if non-printable key is
   // pressed during a dead key sequence.
-  if (!IsPrintableCharKey(virtualKey)) {
+  if (!IsPrintableCharKey(aNativeKey.mOriginalVirtualKeyCode)) {
     return;
   }
 
-  MOZ_ASSERT(virtualKey != VK_PACKET,
+  MOZ_ASSERT(aNativeKey.mOriginalVirtualKeyCode != 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();
-
   // If it's a dead key, aNativeKey will be initialized by
   // MaybeInitNativeKeyAsDeadKey().
   if (MaybeInitNativeKeyAsDeadKey(aNativeKey, aModKeyState)) {
     return;
   }
 
   // If it's in dead key handling and the pressed key causes a composite
   // character, aNativeKey will be initialized by
   // MaybeInitNativeKeyWithCompositeChar().
   if (MaybeInitNativeKeyWithCompositeChar(aNativeKey, aModKeyState)) {
     return;
   }
 
   UniCharsAndModifiers baseChars =
-    GetUniCharsAndModifiers(virtualKey, aModKeyState);
+    GetUniCharsAndModifiers(aNativeKey.mOriginalVirtualKeyCode, aModKeyState);
 
   // If the key press isn't related to any dead keys, initialize aNativeKey
   // with the characters which should be caused by the key.
   if (mActiveDeadKey < 0) {
     aNativeKey.mCommittedCharsAndModifiers = baseChars;
     return;
   }
 
@@ -3688,40 +3684,41 @@ KeyboardLayout::InitNativeKey(NativeKey&
   }
 
   // If the key doesn't cause a composite character with preceding dead key,
   // initialize aNativeKey with the dead-key character followed by current
   // key's character.
   UniCharsAndModifiers deadChars =
     GetUniCharsAndModifiers(mActiveDeadKey, mDeadKeyShiftState);
   aNativeKey.mCommittedCharsAndModifiers = deadChars + baseChars;
-  if (isKeyDown) {
+  if (aNativeKey.IsKeyDownMessage()) {
     DeactivateDeadKeyState();
   }
 }
 
 bool
 KeyboardLayout::MaybeInitNativeKeyAsDeadKey(
                   NativeKey& aNativeKey,
                   const ModifierKeyState& aModKeyState)
 {
-  uint8_t virtualKey = aNativeKey.mOriginalVirtualKeyCode;
-  if (!IsDeadKey(virtualKey, aModKeyState)) {
+  if (!IsDeadKey(aNativeKey.mOriginalVirtualKeyCode, aModKeyState)) {
     return false;
   }
 
   // If it's a keydown event but not in dead key sequence or it's a keyup
   // event of a dead key which activated current dead key sequence,
   // initialize aNativeKey as a dead key event.
   if ((aNativeKey.IsKeyDownMessage() && mActiveDeadKey < 0) ||
-      (!aNativeKey.IsKeyDownMessage() && mActiveDeadKey == virtualKey)) {
+      (!aNativeKey.IsKeyDownMessage() &&
+       mActiveDeadKey == aNativeKey.mOriginalVirtualKeyCode)) {
     ActivateDeadKeyState(aNativeKey, aModKeyState);
 #ifdef DEBUG
     UniCharsAndModifiers deadChars =
-      GetNativeUniCharsAndModifiers(virtualKey, aModKeyState);
+      GetNativeUniCharsAndModifiers(aNativeKey.mOriginalVirtualKeyCode,
+                                    aModKeyState);
     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;
@@ -3730,27 +3727,27 @@ KeyboardLayout::MaybeInitNativeKeyAsDead
 
   // 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 =
-      GetUniCharsAndModifiers(virtualKey, aModKeyState);
+      GetUniCharsAndModifiers(aNativeKey.mOriginalVirtualKeyCode, aModKeyState);
     return true;
   }
 
   if (NS_WARN_IF(!IsPrintableCharKey(mActiveDeadKey))) {
 #if defined(DEBUG) || defined(MOZ_CRASHREPORTER)
     nsPrintfCString warning("The virtual key index (%d) of mActiveDeadKey "
-                            "(0x%02X) is not a printable key (virtualKey="
-                            "0x%02X)",
+                            "(0x%02X) is not a printable key "
+                            "(aNativeKey.mOriginalVirtualKeyCode=0x%02X)",
                             GetKeyIndex(mActiveDeadKey), mActiveDeadKey,
-                            virtualKey);
+                            aNativeKey.mOriginalVirtualKeyCode);
     NS_WARNING(warning.get());
 #ifdef MOZ_CRASHREPORTER
     CrashReporter::AppendAppNotesToCrashReport(
                      NS_LITERAL_CSTRING("\n") + warning);
 #endif // #ifdef MOZ_CRASHREPORTER
 #endif // #if defined(DEBUG) || defined(MOZ_CRASHREPORTER)
     MOZ_CRASH("Trying to reference out of range of mVirtualKeys");
   }
@@ -3761,17 +3758,17 @@ KeyboardLayout::MaybeInitNativeKeyAsDead
     return true;
   }
 
   // Otherwise, dead key followed by another dead key causes inputting both
   // character.
   UniCharsAndModifiers prevDeadChars =
     GetUniCharsAndModifiers(mActiveDeadKey, mDeadKeyShiftState);
   UniCharsAndModifiers newChars =
-    GetUniCharsAndModifiers(virtualKey, aModKeyState);
+    GetUniCharsAndModifiers(aNativeKey.mOriginalVirtualKeyCode, aModKeyState);
   // But keypress events should be fired for each committed character.
   aNativeKey.mCommittedCharsAndModifiers = prevDeadChars + newChars;
   if (aNativeKey.IsKeyDownMessage()) {
     DeactivateDeadKeyState();
   }
   return true;
 }