Bug 1306549 part.9 Create KeyboardLayout::IsInDeadKeySequence() which returns true while it's in a dead key sequence r?m_kato
Currently, checking if it's in dead key sequence directly refers mActiveDeadKey. However, this isn't clear for most developers. So, let's create a helper method, IsInDeadKeySequence(), and wrap the nonintuitive check.
MozReview-Commit-ID: 7qTer9R8Gfs
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -3665,17 +3665,17 @@ KeyboardLayout::InitNativeKey(NativeKey&
return;
}
UniCharsAndModifiers baseChars =
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) {
+ if (!IsInDeadKeySequence()) {
aNativeKey.mCommittedCharsAndModifiers = baseChars;
return;
}
// Although, this shouldn't occur, if active dead key isn't a printable
// key, we cannot handle it because KeyboardLayout assumes that dead key
// is never mapped to non-printable keys (e.g., F4, etc). Please be aware,
// it's possible, but we've not known such special keyboard layout yet.
@@ -3701,17 +3701,17 @@ KeyboardLayout::MaybeInitNativeKeyAsDead
{
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) ||
+ if ((aNativeKey.IsKeyDownMessage() && !IsInDeadKeySequence()) ||
(!aNativeKey.IsKeyDownMessage() &&
mActiveDeadKey == aNativeKey.mOriginalVirtualKeyCode)) {
ActivateDeadKeyState(aNativeKey, aModKeyState);
#ifdef DEBUG
UniCharsAndModifiers deadChars =
GetNativeUniCharsAndModifiers(aNativeKey.mOriginalVirtualKeyCode,
aModKeyState);
MOZ_ASSERT(deadChars.mLength == 1,
@@ -3725,17 +3725,17 @@ KeyboardLayout::MaybeInitNativeKeyAsDead
return true;
}
// 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) {
+ if (!IsInDeadKeySequence()) {
aNativeKey.mCommittedCharsAndModifiers =
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 "
@@ -3772,17 +3772,17 @@ KeyboardLayout::MaybeInitNativeKeyAsDead
return true;
}
bool
KeyboardLayout::MaybeInitNativeKeyWithCompositeChar(
NativeKey& aNativeKey,
const ModifierKeyState& aModKeyState)
{
- if (mActiveDeadKey < 0) {
+ if (!IsInDeadKeySequence()) {
return false;
}
if (NS_WARN_IF(!IsPrintableCharKey(mActiveDeadKey)) ||
NS_WARN_IF(!IsPrintableCharKey(aNativeKey.mOriginalVirtualKeyCode))) {
return false;
}
--- a/widget/windows/KeyboardLayout.h
+++ b/widget/windows/KeyboardLayout.h
@@ -716,16 +716,23 @@ public:
/**
* IsDeadKey() returns true if aVirtualKey is a dead key with aModKeyState.
* This method isn't stateful.
*/
bool IsDeadKey(uint8_t aVirtualKey,
const ModifierKeyState& aModKeyState) const;
/**
+ * IsInDeadKeySequence() returns true when it's in a dead key sequence.
+ * It starts when a dead key is down and ends when another key down causes
+ * inactivating the dead key state.
+ */
+ bool IsInDeadKeySequence() const { return mActiveDeadKey >= 0; }
+
+ /**
* IsSysKey() returns true if aVirtualKey with aModKeyState causes WM_SYSKEY*
* or WM_SYS*CHAR messages.
*/
bool IsSysKey(uint8_t aVirtualKey,
const ModifierKeyState& aModKeyState) const;
/**
* GetUniCharsAndModifiers() returns characters which are inputted by