From da22fd3b2b670dcc33028c9796a7a2839d06fc2c Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Fri, 16 Sep 2016 18:38:53 +0900 Subject: [PATCH] Bug 1306549 part.4 Create KeyboardLayout::GetNativeUniCharsAndModifiers() for wrapping VirtualKey::GetNativeUniChars() r=m_kato Similar to VirtualKey::GetUniChars(), VirtualKey::GetNativeUniChars() needs key index. So, it should be wrapped by a new helper method, KeyboardLayout::GetNativeUniCharsAndModifiers(), and KeyboardEvent::InitNativeKey() should use this instead of accessing its member's GetNativeUniChars(). MozReview-Commit-ID: 7M9OlNF698Y --HG-- extra : rebase_source : e19a5c99014a8f0a0ed7cc3a86fe0c4ee10cebb5 --- widget/windows/KeyboardLayout.cpp | 26 +++++++++++++++++++++----- widget/windows/KeyboardLayout.h | 12 +++++++++++- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/widget/windows/KeyboardLayout.cpp b/widget/windows/KeyboardLayout.cpp index a416d09e02f7..27b0c94e96c7 100644 --- a/widget/windows/KeyboardLayout.cpp +++ b/widget/windows/KeyboardLayout.cpp @@ -3639,11 +3639,13 @@ KeyboardLayout::InitNativeKey(NativeKey& aNativeKey, } uint8_t virtualKey = aNativeKey.mOriginalVirtualKeyCode; - int32_t virtualKeyIndex = GetKeyIndex(virtualKey); - if (virtualKeyIndex < 0) { - // Does not produce any printable characters, but still preserves the - // dead-key state. + // 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)) { return; } @@ -3665,7 +3667,7 @@ KeyboardLayout::InitNativeKey(NativeKey& aNativeKey, VirtualKey::ModifierKeyStateToShiftState(aModKeyState); } UniCharsAndModifiers deadChars = - mVirtualKeys[virtualKeyIndex].GetNativeUniChars(aModKeyState); + GetNativeUniCharsAndModifiers(virtualKey, aModKeyState); NS_ASSERTION(deadChars.mLength == 1, "dead key must generate only one character"); aNativeKey.mKeyNameIndex = KEY_NAME_INDEX_Dead; @@ -3800,6 +3802,20 @@ KeyboardLayout::GetUniCharsAndModifiers( return mVirtualKeys[key].GetUniChars(aShiftState); } +UniCharsAndModifiers +KeyboardLayout::GetNativeUniCharsAndModifiers( + uint8_t aVirtualKey, + const ModifierKeyState& aModKeyState) const +{ + int32_t key = GetKeyIndex(aVirtualKey); + if (key < 0) { + return UniCharsAndModifiers(); + } + VirtualKey::ShiftState shiftState = + VirtualKey::ModifierKeyStateToShiftState(aModKeyState); + return mVirtualKeys[key].GetNativeUniChars(shiftState); +} + void KeyboardLayout::LoadLayout(HKL aLayout) { diff --git a/widget/windows/KeyboardLayout.h b/widget/windows/KeyboardLayout.h index 6f3e089a0522..380177e4a2c0 100644 --- a/widget/windows/KeyboardLayout.h +++ b/widget/windows/KeyboardLayout.h @@ -699,7 +699,7 @@ public: const ModifierKeyState& aModKeyState); /** - * GetUniCharsAndModifiers() returns characters which is inputted by the + * GetUniCharsAndModifiers() returns characters which are inputted by * aVirtualKey with aModKeyState. This method isn't stateful. * Note that if the combination causes text input, the result's Ctrl and * Alt key state are never active. @@ -713,6 +713,16 @@ public: return GetUniCharsAndModifiers(aVirtualKey, shiftState); } + /** + * GetNativeUniCharsAndModifiers() returns characters which are inputted by + * aVirtualKey with aModKeyState. The method isn't stateful. + * Note that different from GetUniCharsAndModifiers(), this returns + * actual modifier state of Ctrl and Alt. + */ + UniCharsAndModifiers GetNativeUniCharsAndModifiers( + uint8_t aVirtualKey, + const ModifierKeyState& aModKeyState) const; + /** * OnLayoutChange() must be called before the first keydown message is * received. LoadLayout() changes the keyboard state, that causes breaking