Bug 339723 Ctrl++ doesn't work with JIS keyboard (second patch, this fixes Bug 341308 Tilde (~) key broken when using German keyboard layout, Bug 342197 Can't type '}' with a french keyboard) r=ere, sr=roc

This commit is contained in:
masayuki%d-toybox.com 2006-07-17 14:08:27 +00:00
Родитель bf7f65b370
Коммит e64d53f989
1 изменённых файлов: 54 добавлений и 38 удалений

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

@ -3324,18 +3324,21 @@ PRBool nsWindow::DispatchKeyEvent(PRUint32 aEventType, WORD aCharCode, UINT aVir
BOOL nsWindow::OnKeyDown(UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyData) BOOL nsWindow::OnKeyDown(UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyData)
{ {
gKbdLayout.OnKeyDown (aVirtualKeyCode); gKbdLayout.OnKeyDown (aVirtualKeyCode);
UINT virtualKeyCode = sIMEIsComposing ? aVirtualKeyCode : MapFromNativeToDOM(aVirtualKeyCode); // Use only DOMKeyCode for XP processing.
// Use aVirtualKeyCode for gKbdLayout and native processing.
UINT DOMKeyCode = sIMEIsComposing ?
aVirtualKeyCode : MapFromNativeToDOM(aVirtualKeyCode);
#ifdef DEBUG #ifdef DEBUG
//printf("In OnKeyDown virt: %d scan: %d\n", virtualKeyCode, aScanCode); //printf("In OnKeyDown virt: %d scan: %d\n", DOMKeyCode, aScanCode);
#endif #endif
BOOL noDefault = DispatchKeyEvent(NS_KEY_DOWN, 0, virtualKeyCode, aKeyData); BOOL noDefault = DispatchKeyEvent(NS_KEY_DOWN, 0, DOMKeyCode, aKeyData);
// If we won't be getting a WM_CHAR, WM_SYSCHAR or WM_DEADCHAR, synthesize a keypress // If we won't be getting a WM_CHAR, WM_SYSCHAR or WM_DEADCHAR, synthesize a keypress
// for almost all keys // for almost all keys
switch (virtualKeyCode) { switch (DOMKeyCode) {
case NS_VK_SHIFT: case NS_VK_SHIFT:
case NS_VK_CONTROL: case NS_VK_CONTROL:
case NS_VK_ALT: case NS_VK_ALT:
@ -3345,25 +3348,21 @@ BOOL nsWindow::OnKeyDown(UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyData)
} }
PRUint32 extraFlags = (noDefault ? NS_EVENT_FLAG_NO_DEFAULT : 0); PRUint32 extraFlags = (noDefault ? NS_EVENT_FLAG_NO_DEFAULT : 0);
MSG msg; MSG msg;
BOOL gotMsg = ::PeekMessageW(&msg, mWnd, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE | PM_NOYIELD); BOOL gotMsg = ::PeekMessageW(&msg, mWnd, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE | PM_NOYIELD);
PRBool anyCharMessagesRemoved = PR_FALSE;
// Enter and backspace are always handled here to avoid for example the // Enter and backspace are always handled here to avoid for example the
// confusion between ctrl-enter and ctrl-J. // confusion between ctrl-enter and ctrl-J.
// Ctrl+[Add, Subtract] are always handled here to make text zoom shortcuts work if (DOMKeyCode == NS_VK_RETURN || DOMKeyCode == NS_VK_BACK ||
// on different keyboard layouts. ((mIsControlDown || mIsAltDown) &&
if (virtualKeyCode == NS_VK_RETURN || virtualKeyCode == NS_VK_BACK || KeyboardLayout::IsPrintableCharKey(aVirtualKeyCode)))
(mIsControlDown && !mIsAltDown && !mIsShiftDown &&
(virtualKeyCode == NS_VK_ADD || virtualKeyCode == NS_VK_SUBTRACT)) ||
((mIsControlDown || mIsAltDown) && KeyboardLayout::IsPrintableCharKey (aVirtualKeyCode)))
{ {
// Remove a possible WM_CHAR or WM_SYSCHAR messages from the message queue. // Remove a possible WM_CHAR or WM_SYSCHAR messages from the message queue.
// They can be more than one because of: // They can be more than one because of:
// * Dead-keys not pairing with base character // * Dead-keys not pairing with base character
// * Some keyboard layouts may map up to 4 characters to the single key // * Some keyboard layouts may map up to 4 characters to the single key
PRBool anyCharMessagesRemoved = PR_FALSE;
while (gotMsg && (msg.message == WM_CHAR || msg.message == WM_SYSCHAR)) while (gotMsg && (msg.message == WM_CHAR || msg.message == WM_SYSCHAR))
{ {
::GetMessageW(&msg, mWnd, WM_KEYFIRST, WM_KEYLAST); ::GetMessageW(&msg, mWnd, WM_KEYFIRST, WM_KEYLAST);
@ -3372,7 +3371,7 @@ BOOL nsWindow::OnKeyDown(UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyData)
gotMsg = ::PeekMessageW (&msg, mWnd, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE | PM_NOYIELD); gotMsg = ::PeekMessageW (&msg, mWnd, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE | PM_NOYIELD);
} }
if (!anyCharMessagesRemoved && virtualKeyCode == NS_VK_BACK) { if (!anyCharMessagesRemoved && DOMKeyCode == NS_VK_BACK) {
MSG imeStartCompositionMsg, imeCompositionMsg; MSG imeStartCompositionMsg, imeCompositionMsg;
if (::PeekMessageW(&imeStartCompositionMsg, mWnd, WM_IME_STARTCOMPOSITION, WM_IME_STARTCOMPOSITION, PM_NOREMOVE | PM_NOYIELD) if (::PeekMessageW(&imeStartCompositionMsg, mWnd, WM_IME_STARTCOMPOSITION, WM_IME_STARTCOMPOSITION, PM_NOREMOVE | PM_NOYIELD)
&& ::PeekMessageW(&imeCompositionMsg, mWnd, WM_IME_COMPOSITION, WM_IME_COMPOSITION, PM_NOREMOVE | PM_NOYIELD) && ::PeekMessageW(&imeCompositionMsg, mWnd, WM_IME_COMPOSITION, WM_IME_COMPOSITION, PM_NOREMOVE | PM_NOYIELD)
@ -3435,23 +3434,25 @@ BOOL nsWindow::OnKeyDown(UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyData)
PRUint32 numOfUniChars = 0; PRUint32 numOfUniChars = 0;
PRUint32 numOfShiftStates = 0; PRUint32 numOfShiftStates = 0;
switch (virtualKeyCode) { switch (aVirtualKeyCode) {
// keys to be sent as characters // keys to be sent as characters
case NS_VK_ADD: uniChars [0] = '+'; numOfUniChars = 1; break; case VK_ADD: uniChars [0] = '+'; numOfUniChars = 1; break;
case NS_VK_SUBTRACT: uniChars [0] = '-'; numOfUniChars = 1; break; case VK_SUBTRACT: uniChars [0] = '-'; numOfUniChars = 1; break;
case NS_VK_DIVIDE: uniChars [0] = '/'; numOfUniChars = 1; break; case VK_DIVIDE: uniChars [0] = '/'; numOfUniChars = 1; break;
case NS_VK_MULTIPLY: uniChars [0] = '*'; numOfUniChars = 1; break; case VK_MULTIPLY: uniChars [0] = '*'; numOfUniChars = 1; break;
case NS_VK_NUMPAD0: case VK_NUMPAD0:
case NS_VK_NUMPAD1: case VK_NUMPAD1:
case NS_VK_NUMPAD2: case VK_NUMPAD2:
case NS_VK_NUMPAD3: case VK_NUMPAD3:
case NS_VK_NUMPAD4: case VK_NUMPAD4:
case NS_VK_NUMPAD5: case VK_NUMPAD5:
case NS_VK_NUMPAD6: case VK_NUMPAD6:
case NS_VK_NUMPAD7: case VK_NUMPAD7:
case NS_VK_NUMPAD8: case VK_NUMPAD8:
case NS_VK_NUMPAD9: uniChars [0] = virtualKeyCode - NS_VK_NUMPAD0 + '0'; numOfUniChars = 1; break; case VK_NUMPAD9:
uniChars [0] = aVirtualKeyCode - VK_NUMPAD0 + '0';
numOfUniChars = 1;
break;
default: default:
if (KeyboardLayout::IsPrintableCharKey (aVirtualKeyCode)) if (KeyboardLayout::IsPrintableCharKey (aVirtualKeyCode))
numOfUniChars = numOfShiftStates = gKbdLayout.GetUniChars (uniChars, shiftStates, NS_ARRAY_LENGTH (uniChars)); numOfUniChars = numOfShiftStates = gKbdLayout.GetUniChars (uniChars, shiftStates, NS_ARRAY_LENGTH (uniChars));
@ -3463,20 +3464,35 @@ BOOL nsWindow::OnKeyDown(UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyData)
// numbers 0..9, ignoring the real characters returned by active keyboard layout. // numbers 0..9, ignoring the real characters returned by active keyboard layout.
// This is required to make sure that all shortcut keys (e.g. Ctrl+c, Ctrl+1, Alt+f) // This is required to make sure that all shortcut keys (e.g. Ctrl+c, Ctrl+1, Alt+f)
// work the same way no matter what keyboard layout you are using. // work the same way no matter what keyboard layout you are using.
// Currently it is impossible to use non-latin characters for keyboard shortcuts.
if ((NS_VK_0 <= virtualKeyCode && virtualKeyCode <= NS_VK_9) || if ((NS_VK_0 <= DOMKeyCode && DOMKeyCode <= NS_VK_9) ||
(NS_VK_A <= virtualKeyCode && virtualKeyCode <= NS_VK_Z)) (NS_VK_A <= DOMKeyCode && DOMKeyCode <= NS_VK_Z))
{ {
uniChars [0] = virtualKeyCode; uniChars [0] = DOMKeyCode;
numOfUniChars = 1; numOfUniChars = 1;
numOfShiftStates = 0; numOfShiftStates = 0;
// For letters take the Shift state into account // For letters take the Shift state into account
if (!mIsShiftDown && if (!mIsShiftDown &&
NS_VK_A <= virtualKeyCode && virtualKeyCode <= NS_VK_Z) NS_VK_A <= DOMKeyCode && DOMKeyCode <= NS_VK_Z)
uniChars [0] += 0x20; uniChars [0] += 0x20;
} }
else if (!anyCharMessagesRemoved && DOMKeyCode != aVirtualKeyCode) {
switch (DOMKeyCode) {
case NS_VK_ADD:
uniChars [0] = '+'; numOfUniChars = 1; break;
case NS_VK_SUBTRACT:
uniChars [0] = '-'; numOfUniChars = 1; break;
case NS_VK_SEMICOLON:
// XXXmnakano I don't know whether this is correct.
uniChars [0] = ';';
uniChars [1] = ':';
numOfUniChars = 2;
break;
default:
NS_ERROR("implement me!");
}
}
} }
} }
@ -3498,7 +3514,7 @@ BOOL nsWindow::OnKeyDown(UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyData)
DispatchKeyEvent(NS_KEY_PRESS, uniChars [cnt], 0, aKeyData, extraFlags); DispatchKeyEvent(NS_KEY_PRESS, uniChars [cnt], 0, aKeyData, extraFlags);
} }
} else } else
DispatchKeyEvent(NS_KEY_PRESS, 0, virtualKeyCode, aKeyData, extraFlags); DispatchKeyEvent(NS_KEY_PRESS, 0, DOMKeyCode, aKeyData, extraFlags);
return noDefault; return noDefault;
} }