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
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -3634,21 +3634,23 @@ KeyboardLayout::InitNativeKey(NativeKey&
aNativeKey.mKeyNameIndex = KEY_NAME_INDEX_USE_STRING;
aNativeKey.mCommittedCharsAndModifiers.
Append(ch, aModKeyState.GetModifiers());
return;
}
}
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;
}
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");
@@ -3660,17 +3662,17 @@ KeyboardLayout::InitNativeKey(NativeKey&
// First dead key event doesn't generate characters.
if (isKeyDown) {
// Dead-key state activated at keydown.
mActiveDeadKey = virtualKey;
mDeadKeyShiftState =
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;
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
@@ -3795,16 +3797,30 @@ KeyboardLayout::GetUniCharsAndModifiers(
UniCharsAndModifiers result;
int32_t key = GetKeyIndex(aVirtualKey);
if (key < 0) {
return result;
}
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)
{
mIsPendingToRestoreKeyboardLayout = false;
if (mKeyboardLayout == aLayout) {
return;
}
--- a/widget/windows/KeyboardLayout.h
+++ b/widget/windows/KeyboardLayout.h
@@ -694,31 +694,41 @@ public:
* proper composite character when dead key produces a composite character.
* Otherwise, just returns false.
*/
bool MaybeInitNativeKeyWithCompositeChar(
NativeKey& aNativeKey,
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.
*/
UniCharsAndModifiers GetUniCharsAndModifiers(
uint8_t aVirtualKey,
const ModifierKeyState& aModKeyState) const
{
VirtualKey::ShiftState shiftState =
VirtualKey::ModifierKeyStateToShiftState(aModKeyState);
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
* dead key state. Therefore, we need to load the layout before the first
* keydown message.
*/
void OnLayoutChange(HKL aKeyboardLayout)
{
MOZ_ASSERT(!mIsOverridden);