Bug 1306549 part.8 Get rid of |virtualKey| and |isKeyDown| from KeyboardLayout::InitNativeKey() and KeyboardLayout::MaybeInitNativeKeyAsDeadKey() r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 30 Sep 2016 15:40:40 +0900
changeset 316365 7dbd5e61db3794bfbe2c4bc0679ce565146bb90d
parent 316364 489e11449d8e62b1eee742090ad177762d9dab2d
child 316366 be15fd5862d35175c6d70db7a1e2e924aa4d05f3
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.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;
 }