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
--- 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);
/**