Bug 1306549 part.6 Create KeyboardLayout::ActivateDeadKeyState() r?m_kato
There is DeactivateDeadKeyState() but not ActivateDeadKeyState(). There should be both of them and hides the dead key state management into them.
MozReview-Commit-ID: JvAPE5f2HVy
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -3654,27 +3654,27 @@ KeyboardLayout::InitNativeKey(NativeKey&
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 (IsDeadKey(virtualKey, aModKeyState)) {
if ((isKeyDown && mActiveDeadKey < 0) ||
(!isKeyDown && mActiveDeadKey == virtualKey)) {
- // First dead key event doesn't generate characters.
- if (isKeyDown) {
- // Dead-key state activated at keydown.
- mActiveDeadKey = virtualKey;
- mDeadKeyShiftState =
- VirtualKey::ModifierKeyStateToShiftState(aModKeyState);
- }
+ ActivateDeadKeyState(aNativeKey, aModKeyState);
+#ifdef DEBUG
UniCharsAndModifiers deadChars =
GetNativeUniCharsAndModifiers(virtualKey, aModKeyState);
- NS_ASSERTION(deadChars.mLength == 1,
- "dead key must generate only one character");
+ 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;
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
// key before next WM_KEYDOWN. E.g., due to auto key repeat or pressing
// another dead key before releasing current key. Therefore, we can
@@ -4073,16 +4073,31 @@ KeyboardLayout::EnsureDeadKeyActive(bool
// >1 - Previous pressed key does not produce any composite characters.
// Return dead-key character followed by base character(s).
} while ((ret < 0) != aIsActive);
return (ret < 0);
}
void
+KeyboardLayout::ActivateDeadKeyState(const NativeKey& aNativeKey,
+ const ModifierKeyState& aModKeyState)
+{
+ // Dead-key state should be activated at keydown.
+ if (!aNativeKey.IsKeyDownMessage()) {
+ return;
+ }
+
+ MOZ_RELEASE_ASSERT(IsPrintableCharKey(aNativeKey.mOriginalVirtualKeyCode));
+
+ mActiveDeadKey = aNativeKey.mOriginalVirtualKeyCode;
+ mDeadKeyShiftState = VirtualKey::ModifierKeyStateToShiftState(aModKeyState);
+}
+
+void
KeyboardLayout::DeactivateDeadKeyState()
{
if (mActiveDeadKey < 0) {
return;
}
BYTE kbdState[256];
memset(kbdState, 0, sizeof(kbdState));
--- a/widget/windows/KeyboardLayout.h
+++ b/widget/windows/KeyboardLayout.h
@@ -636,17 +636,23 @@ private:
DeadKeyEntry* aDeadKeyArray, uint32_t aEntries);
bool EnsureDeadKeyActive(bool aIsActive, uint8_t aDeadKey,
const PBYTE aDeadKeyKbdState);
uint32_t GetDeadKeyCombinations(uint8_t aDeadKey,
const PBYTE aDeadKeyKbdState,
uint16_t aShiftStatesWithBaseChars,
DeadKeyEntry* aDeadKeyArray,
uint32_t aMaxEntries);
+ /**
+ * Activates or deactivates dead key state.
+ */
+ void ActivateDeadKeyState(const NativeKey& aNativeKey,
+ const ModifierKeyState& aModKeyState);
void DeactivateDeadKeyState();
+
const DeadKeyTable* AddDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
uint32_t aEntries);
void ReleaseDeadKeyTables();
/**
* Loads the specified keyboard layout. This method always clear the dead key
* state.
*/