Bug 1306549 part.3 KeyboardLayout::InitNativeKey() should use GetUniCharsAndModifiers() instead of using VirtualKey::GetUniChars() directly r=m_kato

When InitNativeKey() retrieves UniCharsAndModifiers for a key, it needs key index for the given virtual keycode.  Therefore, wrapping the code with GetUniCharsAndModifiers() makes InitNativeKey() code simpler since each call specifies the virtual keycode to the method instead of key index.

MozReview-Commit-ID: Azy8chXexaz

--HG--
extra : rebase_source : 98da43e7f542037f952206cd3db731f6cbb097e7
This commit is contained in:
Masayuki Nakano 2016-09-16 18:22:12 +09:00
Родитель 1559d32969
Коммит 49ebeb51f0
2 изменённых файлов: 28 добавлений и 17 удалений

Просмотреть файл

@ -3679,17 +3679,17 @@ KeyboardLayout::InitNativeKey(NativeKey& aNativeKey,
// set only a character for current key for keyup event.
if (mActiveDeadKey < 0) {
aNativeKey.mCommittedCharsAndModifiers =
mVirtualKeys[virtualKeyIndex].GetUniChars(aModKeyState);
GetUniCharsAndModifiers(virtualKey, aModKeyState);
return;
}
int32_t activeDeadKeyIndex = GetKeyIndex(mActiveDeadKey);
if (activeDeadKeyIndex < 0 || activeDeadKeyIndex >= NS_NUM_OF_KEYS) {
if (NS_WARN_IF(!IsPrintableCharKey(mActiveDeadKey))) {
#if defined(DEBUG) || defined(MOZ_CRASHREPORTER)
nsPrintfCString warning("The virtual key index (%d) of mActiveDeadKey "
"(0x%02X) is not a printable key (virtualKey="
"0x%02X)",
activeDeadKeyIndex, mActiveDeadKey, virtualKey);
GetKeyIndex(mActiveDeadKey), mActiveDeadKey,
virtualKey);
NS_WARNING(warning.get());
#ifdef MOZ_CRASHREPORTER
CrashReporter::AppendAppNotesToCrashReport(
@ -3708,9 +3708,9 @@ KeyboardLayout::InitNativeKey(NativeKey& aNativeKey,
// Otherwise, dead key followed by another dead key causes inputting both
// character.
UniCharsAndModifiers prevDeadChars =
mVirtualKeys[activeDeadKeyIndex].GetUniChars(mDeadKeyShiftState);
GetUniCharsAndModifiers(mActiveDeadKey, mDeadKeyShiftState);
UniCharsAndModifiers newChars =
mVirtualKeys[virtualKeyIndex].GetUniChars(aModKeyState);
GetUniCharsAndModifiers(virtualKey, aModKeyState);
// But keypress events should be fired for each committed character.
aNativeKey.mCommittedCharsAndModifiers = prevDeadChars + newChars;
if (isKeyDown) {
@ -3724,22 +3724,21 @@ KeyboardLayout::InitNativeKey(NativeKey& aNativeKey,
}
UniCharsAndModifiers baseChars =
mVirtualKeys[virtualKeyIndex].GetUniChars(aModKeyState);
GetUniCharsAndModifiers(virtualKey, aModKeyState);
if (mActiveDeadKey < 0) {
// No dead-keys are active. Just return the produced characters.
aNativeKey.mCommittedCharsAndModifiers = baseChars;
return;
}
int32_t activeDeadKeyIndex = GetKeyIndex(mActiveDeadKey);
if (NS_WARN_IF(activeDeadKeyIndex < 0)) {
if (NS_WARN_IF(!IsPrintableCharKey(mActiveDeadKey))) {
return;
}
// There is no valid dead-key and base character combination.
// Return dead-key character followed by base character.
UniCharsAndModifiers deadChars =
mVirtualKeys[activeDeadKeyIndex].GetUniChars(mDeadKeyShiftState);
GetUniCharsAndModifiers(mActiveDeadKey, mDeadKeyShiftState);
// But keypress events should be fired for each committed character.
aNativeKey.mCommittedCharsAndModifiers = deadChars + baseChars;
if (isKeyDown) {
@ -3761,13 +3760,12 @@ KeyboardLayout::MaybeInitNativeKeyWithCompositeChar(
return false;
}
int32_t virtualKeyIndex = GetKeyIndex(aNativeKey.mOriginalVirtualKeyCode);
if (NS_WARN_IF(virtualKeyIndex < 0)) {
if (NS_WARN_IF(!IsPrintableCharKey(aNativeKey.mOriginalVirtualKeyCode))) {
return false;
}
UniCharsAndModifiers baseChars =
mVirtualKeys[virtualKeyIndex].GetUniChars(aModKeyState);
GetUniCharsAndModifiers(aNativeKey.mOriginalVirtualKeyCode, aModKeyState);
if (baseChars.IsEmpty() || !baseChars.mChars[0]) {
return false;
}
@ -3792,15 +3790,14 @@ KeyboardLayout::MaybeInitNativeKeyWithCompositeChar(
UniCharsAndModifiers
KeyboardLayout::GetUniCharsAndModifiers(
uint8_t aVirtualKey,
const ModifierKeyState& aModKeyState) const
VirtualKey::ShiftState aShiftState) const
{
UniCharsAndModifiers result;
int32_t key = GetKeyIndex(aVirtualKey);
if (key < 0) {
return result;
}
return mVirtualKeys[key].
GetUniChars(VirtualKey::ModifiersToShiftState(aModKeyState.GetModifiers()));
return mVirtualKeys[key].GetUniChars(aShiftState);
}
void

Просмотреть файл

@ -661,6 +661,13 @@ private:
void InitNativeKey(NativeKey& aNativeKey,
const ModifierKeyState& aModKeyState);
/**
* See the comment of GetUniCharsAndModifiers() below.
*/
UniCharsAndModifiers GetUniCharsAndModifiers(
uint8_t aVirtualKey,
VirtualKey::ShiftState aShiftState) const;
public:
static KeyboardLayout* GetInstance();
static void Shutdown();
@ -694,10 +701,17 @@ public:
/**
* GetUniCharsAndModifiers() returns characters which is inputted by the
* 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;
const ModifierKeyState& aModKeyState) const
{
VirtualKey::ShiftState shiftState =
VirtualKey::ModifierKeyStateToShiftState(aModKeyState);
return GetUniCharsAndModifiers(aVirtualKey, shiftState);
}
/**
* OnLayoutChange() must be called before the first keydown message is