Bug 751881 Set keycode to keypress event at WM_CHAR handler when charcode is 0 r=jimm

This commit is contained in:
Masayuki Nakano 2012-05-05 07:47:46 +09:00
Родитель f05ee5c7a9
Коммит 07a475fdf1
4 изменённых файлов: 45 добавлений и 35 удалений

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

@ -38,6 +38,8 @@
#include "mozilla/Util.h"
#include "KeyboardLayout.h"
#include "nsWindow.h"
#include "nsIMM32Handler.h"
#include "nsMemory.h"
#include "nsToolkit.h"
@ -227,9 +229,9 @@ VirtualKey::GetNativeUniChars(PRUint8 aShiftState,
}
NativeKey::NativeKey(HKL aKeyboardLayout,
HWND aWnd,
nsWindow* aWindow,
const MSG& aKeyOrCharMessage) :
mVirtualKeyCode(0), mOriginalVirtualKeyCode(0)
mDOMKeyCode(0), mVirtualKeyCode(0), mOriginalVirtualKeyCode(0)
{
mScanCode = WinUtils::GetScanCode(aKeyOrCharMessage.lParam);
mIsExtended = WinUtils::IsExtendedScanCode(aKeyOrCharMessage.lParam);
@ -249,7 +251,8 @@ NativeKey::NativeKey(HKL aKeyboardLayout,
break;
case VK_PROCESSKEY:
mVirtualKeyCode = mOriginalVirtualKeyCode =
static_cast<PRUint8>(::ImmGetVirtualKey(aWnd));
static_cast<PRUint8>(
::ImmGetVirtualKey(aWindow->GetWindowHandle()));
break;
default:
mVirtualKeyCode = mOriginalVirtualKeyCode;
@ -276,6 +279,26 @@ NativeKey::NativeKey(HKL aKeyboardLayout,
if (!mVirtualKeyCode) {
mVirtualKeyCode = mOriginalVirtualKeyCode;
}
mDOMKeyCode = mOriginalVirtualKeyCode;
if (nsIMM32Handler::IsComposingOn(aWindow)) {
return;
}
switch (mOriginalVirtualKeyCode) {
// 0xBA, For the US standard keyboard, the ';:' key
case VK_OEM_1:
mDOMKeyCode = NS_VK_SEMICOLON;
break;
// 0xBB, For any country/region, the '+' key
case VK_OEM_PLUS:
mDOMKeyCode = NS_VK_ADD;
break;
// 0xBD, For any country/region, the '-' key
case VK_OEM_MINUS:
mDOMKeyCode = NS_VK_SUBTRACT;
break;
}
}
UINT

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

@ -47,6 +47,8 @@
#define VK_OEM_PLUS 0xBB // '+' any country
#define VK_OEM_MINUS 0xBD // '-' any country
class nsWindow;
namespace mozilla {
namespace widget {
@ -134,21 +136,25 @@ public:
class NativeKey {
public:
NativeKey() :
mVirtualKeyCode(0), mOriginalVirtualKeyCode(0),
mDOMKeyCode(0), mVirtualKeyCode(0), mOriginalVirtualKeyCode(0),
mScanCode(0), mIsExtended(false)
{
}
NativeKey(HKL aKeyboardLayout,
HWND aWnd,
nsWindow* aWindow,
const MSG& aKeyOrCharMessage);
PRUint32 GetDOMKeyCode() const { return mDOMKeyCode; }
// The result is one of nsIDOMKeyEvent::DOM_KEY_LOCATION_*.
PRUint32 GetKeyLocation() const;
WORD GetScanCode() const { return mScanCode; }
PRUint8 GetVirtualKeyCode() const { return mVirtualKeyCode; }
PRUint8 GetOriginalVirtualKeyCode() const { return mOriginalVirtualKeyCode; }
private:
PRUint32 mDOMKeyCode;
// mVirtualKeyCode distinguishes left key or right key of modifier key.
PRUint8 mVirtualKeyCode;
// mOriginalVirtualKeyCode doesn't distinguish left key or right key of

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

@ -5569,7 +5569,7 @@ LRESULT nsWindow::ProcessCharMessage(const MSG &aMsg, bool *aEventDispatched)
// These must be checked here too as a lone WM_CHAR could be received
// if a child window didn't handle it (for example Alt+Space in a content window)
nsModifierKeyState modKeyState;
NativeKey nativeKey(gKbdLayout.GetLayout(), mWnd, aMsg);
NativeKey nativeKey(gKbdLayout.GetLayout(), this, aMsg);
return OnChar(aMsg, nativeKey, modKeyState, aEventDispatched);
}
@ -6226,16 +6226,6 @@ StringCaseInsensitiveEquals(const PRUnichar* aChars1, const PRUint32 aNumChars1,
return comp(aChars1, aChars2, aNumChars1, aNumChars2) == 0;
}
UINT nsWindow::MapFromNativeToDOM(UINT aNativeKeyCode)
{
switch (aNativeKeyCode) {
case VK_OEM_1: return NS_VK_SEMICOLON; // 0xBA, For the US standard keyboard, the ';:' key
case VK_OEM_PLUS: return NS_VK_ADD; // 0xBB, For any country/region, the '+' key
case VK_OEM_MINUS: return NS_VK_SUBTRACT; // 0xBD, For any country/region, the '-' key
}
return aNativeKeyCode;
}
/* static */
bool nsWindow::IsRedirectedKeyDownMessage(const MSG &aMsg)
{
@ -6258,14 +6248,13 @@ LRESULT nsWindow::OnKeyDown(const MSG &aMsg,
bool *aEventDispatched,
nsFakeCharMessage* aFakeCharMessage)
{
NativeKey nativeKey(gKbdLayout.GetLayout(), mWnd, aMsg);
NativeKey nativeKey(gKbdLayout.GetLayout(), this, aMsg);
UINT virtualKeyCode = nativeKey.GetOriginalVirtualKeyCode();
gKbdLayout.OnKeyDown(virtualKeyCode);
// Use only DOMKeyCode for XP processing.
// Use virtualKeyCode for gKbdLayout and native processing.
UINT DOMKeyCode = nsIMM32Handler::IsComposingOn(this) ?
virtualKeyCode : MapFromNativeToDOM(virtualKeyCode);
PRUint32 DOMKeyCode = nativeKey.GetDOMKeyCode();
#ifdef DEBUG
//PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("In OnKeyDown virt: %d\n", DOMKeyCode));
@ -6608,20 +6597,14 @@ LRESULT nsWindow::OnKeyUp(const MSG &aMsg,
nsModifierKeyState &aModKeyState,
bool *aEventDispatched)
{
UINT virtualKeyCode = aMsg.wParam;
PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
("nsWindow::OnKeyUp VK=%d\n", virtualKeyCode));
if (!nsIMM32Handler::IsComposingOn(this)) {
virtualKeyCode = MapFromNativeToDOM(virtualKeyCode);
}
("nsWindow::OnKeyUp wParam(VK)=%d\n", aMsg.wParam));
if (aEventDispatched)
*aEventDispatched = true;
nsKeyEvent keyupEvent(true, NS_KEY_UP, this);
keyupEvent.keyCode = virtualKeyCode;
NativeKey nativeKey(gKbdLayout.GetLayout(), mWnd, aMsg);
NativeKey nativeKey(gKbdLayout.GetLayout(), this, aMsg);
keyupEvent.keyCode = nativeKey.GetDOMKeyCode();
InitKeyEvent(keyupEvent, nativeKey, aModKeyState);
return DispatchKeyEvent(keyupEvent, &aMsg);
}
@ -6650,19 +6633,17 @@ LRESULT nsWindow::OnChar(const MSG &aMsg,
if (aModKeyState.mIsAltDown && aModKeyState.mIsControlDown)
aModKeyState.mIsAltDown = aModKeyState.mIsControlDown = false;
wchar_t uniChar;
if (nsIMM32Handler::IsComposingOn(this)) {
ResetInputState();
}
wchar_t uniChar;
if (aModKeyState.mIsControlDown && charCode <= 0x1A) { // Ctrl+A Ctrl+Z, see Programming Windows 3.1 page 110 for details
// need to account for shift here. bug 16486
if (aModKeyState.mIsShiftDown)
uniChar = charCode - 1 + 'A';
else
uniChar = charCode - 1 + 'a';
charCode = 0;
}
else if (aModKeyState.mIsControlDown && charCode <= 0x1F) {
// Fix for 50255 - <ctrl><[> and <ctrl><]> are not being processed.
@ -6670,20 +6651,18 @@ LRESULT nsWindow::OnChar(const MSG &aMsg,
// for some reason the keypress handler need to have the uniChar code set
// with the addition of a upper case A not the lower case.
uniChar = charCode - 1 + 'A';
charCode = 0;
} else { // 0x20 - SPACE, 0x3D - EQUALS
if (charCode < 0x20 || (charCode == 0x3D && aModKeyState.mIsControlDown)) {
uniChar = 0;
} else {
uniChar = charCode;
charCode = 0;
}
}
// Keep the characters unshifted for shortcuts and accesskeys and make sure
// that numbers are always passed as such (among others: bugs 50255 and 351310)
if (uniChar && (aModKeyState.mIsControlDown || aModKeyState.mIsAltDown)) {
UINT virtualKeyCode = ::MapVirtualKeyEx(WinUtils::GetScanCode(aMsg.lParam),
UINT virtualKeyCode = ::MapVirtualKeyEx(aNativeKey.GetScanCode(),
MAPVK_VSC_TO_VK,
gKbdLayout.GetLayout());
UINT unshiftedCharCode =
@ -6706,6 +6685,9 @@ LRESULT nsWindow::OnChar(const MSG &aMsg,
nsKeyEvent keypressEvent(true, NS_KEY_PRESS, this);
keypressEvent.flags |= aFlags;
keypressEvent.charCode = uniChar;
if (!keypressEvent.charCode) {
keypressEvent.keyCode = aNativeKey.GetDOMKeyCode();
}
InitKeyEvent(keypressEvent, aNativeKey, aModKeyState);
bool result = DispatchKeyEvent(keypressEvent, &aMsg);
if (aEventDispatched)

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

@ -477,7 +477,6 @@ protected:
/**
* Misc.
*/
UINT MapFromNativeToDOM(UINT aNativeKeyCode);
void StopFlashing();
static bool IsTopLevelMouseExit(HWND aWnd);
nsresult SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,