Bug 757688 part.6 Add numpad keys to printable key table and remove KeyboardLayout::IsNumpadKey() r=jimm

This commit is contained in:
Masayuki Nakano 2012-06-15 18:52:50 +09:00
Родитель 085496f7f8
Коммит 8dd94156c6
3 изменённых файлов: 73 добавлений и 110 удалений

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

@ -533,12 +533,6 @@ KeyboardLayout::IsPrintableCharKey(PRUint8 aVirtualKey)
return GetKeyIndex(aVirtualKey) >= 0;
}
bool
KeyboardLayout::IsNumpadKey(PRUint8 aVirtualKey)
{
return VK_NUMPAD0 <= aVirtualKey && aVirtualKey <= VK_DIVIDE;
}
bool
KeyboardLayout::IsDeadKey(PRUint8 aVirtualKey,
const ModifierKeyState& aModKeyState) const
@ -724,11 +718,17 @@ KeyboardLayout::LoadLayout(HKL aLayout)
inline PRInt32
KeyboardLayout::GetKeyIndex(PRUint8 aVirtualKey)
{
// Currently these 54 (NS_NUM_OF_KEYS) virtual keys are assumed
// Currently these 68 (NS_NUM_OF_KEYS) virtual keys are assumed
// to produce visible representation:
// 0x20 - VK_SPACE ' '
// 0x30..0x39 '0'..'9'
// 0x41..0x5A 'A'..'Z'
// 0x60..0x69 '0'..'9' on numpad
// 0x6A - VK_MULTIPLY '*' on numpad
// 0x6B - VK_ADD '+' on numpad
// 0x6D - VK_SUBTRACT '-' on numpad
// 0x6E - VK_DECIMAL '.' on numpad
// 0x6F - VK_DIVIDE '/' on numpad
// 0x6E - VK_DECIMAL '.'
// 0xBA - VK_OEM_1 ';:' for US
// 0xBB - VK_OEM_PLUS '+' any country
@ -757,15 +757,15 @@ KeyboardLayout::GetKeyIndex(PRUint8 aVirtualKey)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, // 30
-1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // 40
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, -1, -1, -1, -1, -1, // 50
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 37, -1, // 60
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, -1, 49, 50, 51, // 60
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 70
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 80
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 90
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // A0
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 38, 39, 40, 41, 42, 43, // B0
44, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // C0
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 45, 46, 47, 48, 49, // D0
-1, 50, 51, 52, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // E0
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 52, 53, 54, 55, 56, 57, // B0
58, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // C0
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 59, 60, 61, 62, 63, // D0
-1, 64, 65, 66, 67, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // E0
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // F0
};

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

@ -10,7 +10,7 @@
#include "nsEvent.h"
#include <windows.h>
#define NS_NUM_OF_KEYS 54
#define NS_NUM_OF_KEYS 68
#define VK_OEM_1 0xBA // ';:' for US
#define VK_OEM_PLUS 0xBB // '+' any country
@ -333,7 +333,6 @@ public:
~KeyboardLayout();
static bool IsPrintableCharKey(PRUint8 aVirtualKey);
static bool IsNumpadKey(PRUint8 aVirtualKey);
/**
* IsDeadKey() returns true if aVirtualKey is a dead key with aModKeyState.

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

@ -6386,9 +6386,7 @@ LRESULT nsWindow::OnKeyDown(const MSG &aMsg,
return result;
}
else if (!aModKeyState.IsControl() && !aModKeyState.IsAlt() &&
(KeyboardLayout::IsPrintableCharKey(virtualKeyCode) ||
KeyboardLayout::IsNumpadKey(virtualKeyCode)))
{
KeyboardLayout::IsPrintableCharKey(virtualKeyCode)) {
// If this is simple KeyDown event but next message is not WM_CHAR,
// this event may not input text, so we should ignore this event.
// See bug 314130.
@ -6404,101 +6402,67 @@ LRESULT nsWindow::OnKeyDown(const MSG &aMsg,
PRUint32 shiftedLatinChar = 0;
PRUint32 unshiftedLatinChar = 0;
switch (virtualKeyCode) {
// keys to be sent as characters
case VK_ADD:
inputtingChars.Clear();
inputtingChars.Append('+', aModKeyState.GetModifiers());
break;
case VK_SUBTRACT:
inputtingChars.Clear();
inputtingChars.Append('-', aModKeyState.GetModifiers());
break;
case VK_DIVIDE:
inputtingChars.Clear();
inputtingChars.Append('/', aModKeyState.GetModifiers());
break;
case VK_MULTIPLY:
inputtingChars.Clear();
inputtingChars.Append('*', aModKeyState.GetModifiers());
break;
case VK_NUMPAD0:
case VK_NUMPAD1:
case VK_NUMPAD2:
case VK_NUMPAD3:
case VK_NUMPAD4:
case VK_NUMPAD5:
case VK_NUMPAD6:
case VK_NUMPAD7:
case VK_NUMPAD8:
case VK_NUMPAD9:
inputtingChars.Clear();
inputtingChars.Append(virtualKeyCode - VK_NUMPAD0 + '0',
aModKeyState.GetModifiers());
break;
default:
if (!KeyboardLayout::IsPrintableCharKey(virtualKeyCode)) {
if (!KeyboardLayout::IsPrintableCharKey(virtualKeyCode)) {
inputtingChars.Clear();
}
if (aModKeyState.IsControl() ^ aModKeyState.IsAlt()) {
widget::ModifierKeyState capsLockState(
aModKeyState.GetModifiers() & MODIFIER_CAPSLOCK);
unshiftedChars =
gKbdLayout.GetUniCharsAndModifiers(virtualKeyCode, capsLockState);
capsLockState.Set(MODIFIER_SHIFT);
shiftedChars =
gKbdLayout.GetUniCharsAndModifiers(virtualKeyCode, capsLockState);
// The current keyboard cannot input alphabets or numerics,
// we should append them for Shortcut/Access keys.
// E.g., for Cyrillic keyboard layout.
capsLockState.Unset(MODIFIER_SHIFT);
WidgetUtils::GetLatinCharCodeForKeyCode(DOMKeyCode,
capsLockState.GetModifiers(),
&unshiftedLatinChar,
&shiftedLatinChar);
// If the shiftedLatinChar isn't 0, the key code is NS_VK_[A-Z].
if (shiftedLatinChar) {
// If the produced characters of the key on current keyboard layout
// are same as computed Latin characters, we shouldn't append the
// Latin characters to alternativeCharCode.
if (unshiftedLatinChar == unshiftedChars.mChars[0] &&
shiftedLatinChar == shiftedChars.mChars[0]) {
shiftedLatinChar = unshiftedLatinChar = 0;
}
} else if (unshiftedLatinChar) {
// If the shiftedLatinChar is 0, the keyCode doesn't produce
// alphabet character. At that time, the character may be produced
// with Shift key. E.g., on French keyboard layout, NS_VK_PERCENT
// key produces LATIN SMALL LETTER U WITH GRAVE (U+00F9) without
// Shift key but with Shift key, it produces '%'.
// If the unshiftedLatinChar is produced by the key on current
// keyboard layout, we shouldn't append it to alternativeCharCode.
if (unshiftedLatinChar == unshiftedChars.mChars[0] ||
unshiftedLatinChar == shiftedChars.mChars[0]) {
unshiftedLatinChar = 0;
}
}
// If the charCode is not ASCII character, we should replace the
// charCode with ASCII character only when Ctrl is pressed.
// But don't replace the charCode when the charCode is not same as
// unmodified characters. In such case, Ctrl is sometimes used for a
// part of character inputting key combination like Shift.
if (aModKeyState.IsControl()) {
PRUint32 ch =
aModKeyState.IsShift() ? shiftedLatinChar : unshiftedLatinChar;
if (ch &&
(!inputtingChars.mLength ||
inputtingChars.UniCharsCaseInsensitiveEqual(
aModKeyState.IsShift() ? shiftedChars : unshiftedChars))) {
inputtingChars.Clear();
inputtingChars.Append(ch, aModKeyState.GetModifiers());
}
if (aModKeyState.IsControl() ^ aModKeyState.IsAlt()) {
widget::ModifierKeyState capsLockState(
aModKeyState.GetModifiers() & MODIFIER_CAPSLOCK);
unshiftedChars =
gKbdLayout.GetUniCharsAndModifiers(virtualKeyCode, capsLockState);
capsLockState.Set(MODIFIER_SHIFT);
shiftedChars =
gKbdLayout.GetUniCharsAndModifiers(virtualKeyCode, capsLockState);
// The current keyboard cannot input alphabets or numerics,
// we should append them for Shortcut/Access keys.
// E.g., for Cyrillic keyboard layout.
capsLockState.Unset(MODIFIER_SHIFT);
WidgetUtils::GetLatinCharCodeForKeyCode(DOMKeyCode,
capsLockState.GetModifiers(),
&unshiftedLatinChar,
&shiftedLatinChar);
// If the shiftedLatinChar isn't 0, the key code is NS_VK_[A-Z].
if (shiftedLatinChar) {
// If the produced characters of the key on current keyboard layout
// are same as computed Latin characters, we shouldn't append the
// Latin characters to alternativeCharCode.
if (unshiftedLatinChar == unshiftedChars.mChars[0] &&
shiftedLatinChar == shiftedChars.mChars[0]) {
shiftedLatinChar = unshiftedLatinChar = 0;
}
} else if (unshiftedLatinChar) {
// If the shiftedLatinChar is 0, the keyCode doesn't produce
// alphabet character. At that time, the character may be produced
// with Shift key. E.g., on French keyboard layout, NS_VK_PERCENT
// key produces LATIN SMALL LETTER U WITH GRAVE (U+00F9) without
// Shift key but with Shift key, it produces '%'.
// If the unshiftedLatinChar is produced by the key on current
// keyboard layout, we shouldn't append it to alternativeCharCode.
if (unshiftedLatinChar == unshiftedChars.mChars[0] ||
unshiftedLatinChar == shiftedChars.mChars[0]) {
unshiftedLatinChar = 0;
}
}
// If the charCode is not ASCII character, we should replace the
// charCode with ASCII character only when Ctrl is pressed.
// But don't replace the charCode when the charCode is not same as
// unmodified characters. In such case, Ctrl is sometimes used for a
// part of character inputting key combination like Shift.
if (aModKeyState.IsControl()) {
PRUint32 ch =
aModKeyState.IsShift() ? shiftedLatinChar : unshiftedLatinChar;
if (ch &&
(!inputtingChars.mLength ||
inputtingChars.UniCharsCaseInsensitiveEqual(
aModKeyState.IsShift() ? shiftedChars : unshiftedChars))) {
inputtingChars.Clear();
inputtingChars.Append(ch, aModKeyState.GetModifiers());
}
}
}
}
}
if (inputtingChars.mLength ||