Bug 1306549 part.5 Create KeyboardLayout::GetCompositeChar() for wrapping VirtualKey::GetCompositeChar() r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 16 Sep 2016 18:54:48 +0900
changeset 316362 adba65212c35be06d1fb6a46303f1583525fe9bd
parent 316361 fd077161e636ef594f21b1c541f01c7a6701780b
child 316363 9be247c306a1250c8416feb2f68d284a5e3f4942
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.5 Create KeyboardLayout::GetCompositeChar() for wrapping VirtualKey::GetCompositeChar() r=m_kato VirtualKey::GetCompositeChar() needs index of virtual keycode which may make around the caller messy. So, KeyboardLayout::GetCompositeChar() should wrap it and KeyboardLayout::MaybeInitNativeKeyWithCompositeChar() should use it. MozReview-Commit-ID: 8KLTJpCFZ8u
widget/windows/KeyboardLayout.cpp
widget/windows/KeyboardLayout.h
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -3752,34 +3752,29 @@ bool
 KeyboardLayout::MaybeInitNativeKeyWithCompositeChar(
                   NativeKey& aNativeKey,
                   const ModifierKeyState& aModKeyState)
 {
   if (mActiveDeadKey < 0) {
     return false;
   }
 
-  int32_t activeDeadKeyIndex = GetKeyIndex(mActiveDeadKey);
-  if (NS_WARN_IF(activeDeadKeyIndex < 0)) {
-    return false;
-  }
-
-  if (NS_WARN_IF(!IsPrintableCharKey(aNativeKey.mOriginalVirtualKeyCode))) {
+  if (NS_WARN_IF(!IsPrintableCharKey(mActiveDeadKey)) ||
+      NS_WARN_IF(!IsPrintableCharKey(aNativeKey.mOriginalVirtualKeyCode))) {
     return false;
   }
 
   UniCharsAndModifiers baseChars =
     GetUniCharsAndModifiers(aNativeKey.mOriginalVirtualKeyCode, aModKeyState);
   if (baseChars.IsEmpty() || !baseChars.mChars[0]) {
     return false;
   }
 
   char16_t compositeChar =
-    mVirtualKeys[activeDeadKeyIndex].GetCompositeChar(mDeadKeyShiftState,
-                                                      baseChars.mChars[0]);
+    GetCompositeChar(mActiveDeadKey, mDeadKeyShiftState, baseChars.mChars[0]);
   if (!compositeChar) {
     return false;
   }
 
   // Active dead-key and base character does produce exactly one composite
   // character.
   aNativeKey.mCommittedCharsAndModifiers.Append(compositeChar,
                                                 baseChars.mModifiers[0]);
@@ -3811,16 +3806,28 @@ KeyboardLayout::GetNativeUniCharsAndModi
   if (key < 0) {
     return UniCharsAndModifiers();
   }
   VirtualKey::ShiftState shiftState =
     VirtualKey::ModifierKeyStateToShiftState(aModKeyState);
   return mVirtualKeys[key].GetNativeUniChars(shiftState);
 }
 
+char16_t
+KeyboardLayout::GetCompositeChar(uint8_t aVirtualKeyOfDeadKey,
+                                 VirtualKey::ShiftState aShiftStateOfDeadKey,
+                                 char16_t aBaseChar) const
+{
+  int32_t key = GetKeyIndex(aVirtualKeyOfDeadKey);
+  if (key < 0) {
+    return 0;
+  }
+  return mVirtualKeys[key].GetCompositeChar(aShiftStateOfDeadKey, aBaseChar);
+}
+
 void
 KeyboardLayout::LoadLayout(HKL aLayout)
 {
   mIsPendingToRestoreKeyboardLayout = false;
 
   if (mKeyboardLayout == aLayout) {
     return;
   }
--- a/widget/windows/KeyboardLayout.h
+++ b/widget/windows/KeyboardLayout.h
@@ -663,16 +663,27 @@ private:
 
   /**
    * See the comment of GetUniCharsAndModifiers() below.
    */
   UniCharsAndModifiers GetUniCharsAndModifiers(
                          uint8_t aVirtualKey,
                          VirtualKey::ShiftState aShiftState) const;
 
+  /**
+   * GetCompositeChar() returns a composite character with dead character
+   * caused by aVirtualKeyOfDeadKey and aShiftStateOfDeadKey and a base
+   * character (aBaseChar).
+   * If the combination of the dead character and the base character doesn't
+   * cause a composite character, this returns 0.
+   */
+  char16_t GetCompositeChar(uint8_t aVirtualKeyOfDeadKey,
+                            VirtualKey::ShiftState aShiftStateOfDeadKey,
+                            char16_t aBaseChar) const;
+
 public:
   static KeyboardLayout* GetInstance();
   static void Shutdown();
   static void NotifyIdleServiceOfUserActivity();
 
   static bool IsPrintableCharKey(uint8_t aVirtualKey);
 
   /**